1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/************************************************************************
*
* Copyright (C) 2009-2023 IRCAD France
* Copyright (C) 2012-2020 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "structure_traits_dictionary_test.hpp"
#include <data/structure_traits.hpp>
#include <data/structure_traits_dictionary.hpp>
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION(sight::data::ut::structure_traits_dictionary_test);
namespace sight::data::ut
{
//------------------------------------------------------------------------------
void structure_traits_dictionary_test::setUp()
{
// Set up context before running a test.
}
//------------------------------------------------------------------------------
void structure_traits_dictionary_test::tearDown()
{
// Clean up after the test run.
}
//------------------------------------------------------------------------------
void structure_traits_dictionary_test::test_adding_structure()
{
data::structure_traits_dictionary::sptr struct_dico = std::make_shared<data::structure_traits_dictionary>();
data::structure_traits::sptr skin = std::make_shared<data::structure_traits>();
std::string skin_type = "Skin";
skin->set_type(skin_type);
skin->set_class(data::structure_traits::environment);
data::color::sptr skin_color = std::make_shared<data::color>(1.0F, 179.0F / 255.0F, 140.0F / 255.0F, 1.0F);
skin->set_color(skin_color);
data::structure_traits::category_container_t skin_cat(1);
skin_cat[0] = data::structure_traits::body;
skin->set_categories(skin_cat);
CPPUNIT_ASSERT_EQUAL(skin_type, skin->type());
CPPUNIT_ASSERT_EQUAL(data::structure_traits::environment, skin->get_class());
CPPUNIT_ASSERT(skin_color == skin->get_color());
CPPUNIT_ASSERT_NO_THROW(struct_dico->add_structure(skin));
data::structure_traits::sptr liver = std::make_shared<data::structure_traits>();
liver->set_type("Liver");
liver->set_class(data::structure_traits::organ);
liver->set_color(std::make_shared<data::color>(204.0F / 255.0F, 51.0F / 255.0F, 51.0F / 255.0F, 1.0F));
data::structure_traits::category_container_t liver_cat(1);
liver_cat[0] = data::structure_traits::abdomen;
liver->set_categories(liver_cat);
std::string native_exp = "inter(world(type(Skin)),not(class(Organ)))";
liver->set_native_exp(native_exp);
CPPUNIT_ASSERT_EQUAL(native_exp, liver->get_native_exp());
CPPUNIT_ASSERT_NO_THROW(struct_dico->add_structure(liver));
data::structure_traits::sptr liver_tumor = std::make_shared<data::structure_traits>();
liver_tumor->set_type("Liver_Tumor");
liver_tumor->set_class(data::structure_traits::lesion);
liver_tumor->set_color(std::make_shared<data::color>(0.0F, 179.0F / 255.0F, 0.0F, 1.0F));
data::structure_traits::category_container_t liver_tumor_cat(1);
liver_tumor_cat[0] = data::structure_traits::abdomen;
liver_tumor->set_categories(liver_tumor_cat);
liver_tumor->set_attachment_type("Liver");
CPPUNIT_ASSERT_NO_THROW(struct_dico->add_structure(liver_tumor));
data::structure_traits::sptr tumor = std::make_shared<data::structure_traits>();
tumor->set_type("Tumor");
tumor->set_class(data::structure_traits::lesion);
tumor->set_color(std::make_shared<data::color>(0.0F, 0.0F, 1.0F, 1.0F));
data::structure_traits::category_container_t tumor_cat(8);
tumor_cat[0] = data::structure_traits::body;
tumor_cat[1] = data::structure_traits::head;
tumor_cat[2] = data::structure_traits::neck;
tumor_cat[3] = data::structure_traits::thorax;
tumor_cat[4] = data::structure_traits::abdomen;
tumor_cat[5] = data::structure_traits::pelvis;
tumor_cat[6] = data::structure_traits::arm;
tumor_cat[7] = data::structure_traits::leg;
tumor->set_categories(tumor_cat);
CPPUNIT_ASSERT_NO_THROW(struct_dico->add_structure(tumor));
CPPUNIT_ASSERT(skin == struct_dico->get_structure("Skin"));
CPPUNIT_ASSERT(liver == struct_dico->get_structure("Liver"));
CPPUNIT_ASSERT(liver_tumor == struct_dico->get_structure("Liver_Tumor"));
// check exception is raised if wrong structure
data::structure_traits::sptr bad_class_structure = std::make_shared<data::structure_traits>();
bad_class_structure->set_type("my_structure");
bad_class_structure->set_class(data::structure_traits::organ);
bad_class_structure->set_color(std::make_shared<data::color>(0.0F, 179.0F / 255.0F, 0.0F, 1.0F));
data::structure_traits::category_container_t struct_cat(1);
struct_cat[0] = data::structure_traits::abdomen;
bad_class_structure->set_categories(struct_cat);
bad_class_structure->set_attachment_type("Liver");
CPPUNIT_ASSERT_THROW(struct_dico->add_structure(bad_class_structure), core::exception);
data::structure_traits::sptr bad_attachment_structure = std::make_shared<data::structure_traits>();
bad_attachment_structure->set_type("my_structure");
bad_attachment_structure->set_class(data::structure_traits::lesion);
bad_attachment_structure->set_color(std::make_shared<data::color>(0.0F, 179.0F / 255.0F, 0.0F, 1.0F));
bad_attachment_structure->set_categories(struct_cat);
bad_attachment_structure->set_attachment_type("Unknown");
CPPUNIT_ASSERT_THROW(struct_dico->add_structure(bad_attachment_structure), core::exception);
// check exception is raised if structure already exist
data::structure_traits::sptr liver2 = std::make_shared<data::structure_traits>();
liver2->set_type("Liver");
liver2->set_class(data::structure_traits::organ);
liver2->set_color(std::make_shared<data::color>(204.0F / 255.0F, 51.0F / 255.0F, 51.0F / 255.0F, 1.0F));
data::structure_traits::category_container_t liver2_cat(1);
liver2_cat[0] = data::structure_traits::abdomen;
liver2->set_categories(liver2_cat);
CPPUNIT_ASSERT_THROW(struct_dico->add_structure(liver2), core::exception);
}
} // namespace sight::data::ut
|