diff --git a/Modules/Core/test/mitkImageGeneratorTest.cpp b/Modules/Core/test/mitkImageGeneratorTest.cpp index 8dfd22dea4..57dc747de6 100644 --- a/Modules/Core/test/mitkImageGeneratorTest.cpp +++ b/Modules/Core/test/mitkImageGeneratorTest.cpp @@ -1,327 +1,327 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ // Testing #include "mitkTestFixture.h" #include // MITK includes #include #include "mitkImage.h" #include "mitkImageGenerator.h" #include "mitkImageReadAccessor.h" #include "mitkImageStatisticsHolder.h" class mitkImageGeneratorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkImageGeneratorTestSuite); MITK_TEST(SetSpacingX2D_Success); MITK_TEST(SetDefaultSpacingX2D_Success); MITK_TEST(SetSpacingX3D_Success); MITK_TEST(SetSpacingY2D_Success); MITK_TEST(SetDefaultSpacingY2D_Success); MITK_TEST(SetSpacingY3D_Success); MITK_TEST(SetSpacingZ2D_Success); MITK_TEST(SetDefaultSpacingZ2D_Success); MITK_TEST(SetSpacingZ3D_Success); MITK_TEST(SetDimension2D_Success); MITK_TEST(SetDimension3D_Success); MITK_TEST(SetDimension4D_Success); MITK_TEST(SetDimensionX2D_Success); MITK_TEST(SetDimensionY2D_Success); MITK_TEST(SetDimensionZ3D_Success); MITK_TEST(SetDimensionT4D_Success); MITK_TEST(SetDimensions3Dc_Success); MITK_TEST(SetDataTypeFloat2D_Success); MITK_TEST(SetDataTypeUChar2D_Success); MITK_TEST(SetDataTypeInt3D_Success); MITK_TEST(SetDataTypeDouble3D_Success); MITK_TEST(SetDataTypeFloat4D_Success); MITK_TEST(SetDataTypeUChar4D_Success); MITK_TEST(SetDataTypeUInt3D_Success); MITK_TEST(SetPixelTypeFloat2D_Success); MITK_TEST(SetPixelTypeUChar2D_Success); MITK_TEST(SetPixelTypeInt3D_Success); MITK_TEST(SetPixelTypeDouble3D_Success); MITK_TEST(SetPixelTypeFloat4D_Success); MITK_TEST(SetPixelTypeUChar4D_Success); MITK_TEST(SetPixelTypeUInt3D_Success); MITK_TEST(MaxValueHolds_Success); MITK_TEST(MinValueHolds_Success); MITK_TEST(DefaultMaxValueHolds_Success); MITK_TEST(DefaultMinValueHolds_Success); MITK_TEST(SetGradientImageValues_Success); CPPUNIT_TEST_SUITE_END(); private: // create some images with arbitrary parameters (corner cases) mitk::Image::Pointer m_Image2Da; mitk::Image::Pointer m_Image2Db; mitk::Image::Pointer m_Image3Da; mitk::Image::Pointer m_Image3Db; mitk::Image::Pointer m_Image4Da; mitk::Image::Pointer m_Image4Db; mitk::Image::Pointer m_Image3Dc; public: void setUp() { - m_Image2Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 0, 0, 0.1, 0.2, 0.3, 577, 23); + m_Image2Da = mitk::ImageGenerator::GenerateRandomImage(2, 4, 0, 0, 0.1, 0.2, 0.3, 577, 23); m_Image2Db = mitk::ImageGenerator::GenerateRandomImage(1, 1, 0, 0); - m_Image3Da = mitk::ImageGenerator::GenerateRandomImage(512, 205, 1, 0); - m_Image3Db = mitk::ImageGenerator::GenerateRandomImage(512, 532, 112, 0); - m_Image4Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 78, 1); - m_Image4Db = mitk::ImageGenerator::GenerateRandomImage(550, 33, 78, 150); + m_Image3Da = mitk::ImageGenerator::GenerateRandomImage(2, 4, 1, 0); + m_Image3Db = mitk::ImageGenerator::GenerateRandomImage(2, 4, 8, 0); + m_Image4Da = mitk::ImageGenerator::GenerateRandomImage(2, 4, 8, 1); + m_Image4Db = mitk::ImageGenerator::GenerateRandomImage(2, 4, 8, 2); m_Image3Dc = mitk::ImageGenerator::GenerateGradientImage(1, 2, 3, 4, 5, 6); } void tearDown() { m_Image2Da = nullptr; m_Image2Db = nullptr; m_Image3Da = nullptr; m_Image3Db = nullptr; m_Image4Da = nullptr; m_Image4Db = nullptr; m_Image3Dc = nullptr; } void SetSpacingX2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if spacing 2D x is set correctly.", fabs(m_Image2Da->GetGeometry()->GetSpacing()[0] - 0.1) < 0.0001); } void SetDefaultSpacingX2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if default spacing 2D x is set correctly.", fabs(m_Image2Db->GetGeometry()->GetSpacing()[0] - 1.0) < 0.0001); } void SetSpacingX3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if spacing 3D x is set correctly.", fabs(m_Image3Dc->GetGeometry()->GetSpacing()[0] - 4) < 0.0001); } void SetSpacingY2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if spacing 2D y is set correctly.", fabs(m_Image2Da->GetGeometry()->GetSpacing()[1] - 0.2) < 0.0001); } void SetDefaultSpacingY2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if default spacing 2D y is set correctly.", fabs(m_Image2Db->GetGeometry()->GetSpacing()[1] - 1.0) < 0.0001); } void SetSpacingY3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if spacing 3D y is set correctly.", fabs(m_Image3Dc->GetGeometry()->GetSpacing()[1] - 5) < 0.0001); } void SetSpacingZ2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if spacing 2D z is set correctly.", fabs(m_Image2Da->GetGeometry()->GetSpacing()[2] - 0.3) < 0.0001); } void SetDefaultSpacingZ2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if default spacing 2D z is set correctly.", fabs(m_Image2Db->GetGeometry()->GetSpacing()[2] - 1.0) < 0.0001); } void SetSpacingZ3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if spacing z is set correctly.", fabs(m_Image3Dc->GetGeometry()->GetSpacing()[2] - 6) < 0.0001); } void SetDimension2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 2D is set correctly.", m_Image2Da->GetDimension() == 2); CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 2D is set correctly.", m_Image2Db->GetDimension() == 2); } void SetDimension3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 3D is set correctly.",m_Image3Da->GetDimension() == 2); CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 3D is set correctly.", m_Image3Db->GetDimension() == 3); } void SetDimension4D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 4D is set correctly.", m_Image4Da->GetDimension() == 3); CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 4D is set correctly.", m_Image4Db->GetDimension() == 4); } void SetDimensionX2D_Success() { - CPPUNIT_ASSERT_MESSAGE("Testing if the X dimension of the 2D image is set correctly.", m_Image2Da->GetDimension(0) == 120); + CPPUNIT_ASSERT_MESSAGE("Testing if the X dimension of the 2D image is set correctly.", m_Image2Da->GetDimension(0) == 2); } void SetDimensionY2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the Y dimension of the 2D image is set correctly.", m_Image2Db->GetDimension(1) == 1); } void SetDimensionZ3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the Z dimension of the 3D image is set correctly.", m_Image3Da->GetDimension(2) == 1); - CPPUNIT_ASSERT_MESSAGE("Testing if the Z dimension of the 3D image is set correctly.", m_Image3Db->GetDimension(2) == 112); + CPPUNIT_ASSERT_MESSAGE("Testing if the Z dimension of the 3D image is set correctly.", m_Image3Db->GetDimension(2) == 8); } void SetDimensionT4D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the T dimension of the 4D image is set correctly.", m_Image4Da->GetDimension(3) == 1); - CPPUNIT_ASSERT_MESSAGE("Testing if the T dimension of the 4D image is set correctly.", m_Image4Db->GetDimension(3) == 150); + CPPUNIT_ASSERT_MESSAGE("Testing if the T dimension of the 4D image is set correctly.", m_Image4Db->GetDimension(3) == 2); } void SetDimensions3Dc_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if image3Dc dimension x is set correctly.", m_Image3Dc->GetDimension(0) == 1); CPPUNIT_ASSERT_MESSAGE("Testing if image3Dc dimension y is set correctly.", m_Image3Dc->GetDimension(1) == 2); CPPUNIT_ASSERT_MESSAGE("Testing if image3Dc dimension z is set correctly.", m_Image3Dc->GetDimension(2) == 3); } void SetDataTypeFloat2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a float 3D image is set correctly.", m_Image2Da->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT); } void SetDataTypeUChar2D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a UChar 2D image is set correctly.", m_Image2Db->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR); } void SetDataTypeInt3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a Int 3D image is set correctly.", m_Image3Da->GetPixelType().GetComponentType() == itk::ImageIOBase::INT); } void SetDataTypeDouble3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a Double 3D image is set correctly.", m_Image3Db->GetPixelType().GetComponentType() == itk::ImageIOBase::DOUBLE); } void SetDataTypeFloat4D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a Float 4D image is set correctly.", m_Image4Da->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT); } void SetDataTypeUChar4D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a UChar 4D image is set correctly.", m_Image4Db->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR); } void SetDataTypeUInt3D_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a UInt 3D image is set correctly.", m_Image3Dc->GetPixelType().GetComponentType() == itk::ImageIOBase::UINT); } void SetPixelTypeFloat2D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Float 2D image is set correctly.", m_Image2Da->GetPixelType().GetPixelType() == scalarType); } void SetPixelTypeUChar2D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a UChar 2D image is set correctly.", m_Image2Db->GetPixelType().GetPixelType() == scalarType); } void SetPixelTypeInt3D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Int 3D image is set correctly.", m_Image3Da->GetPixelType().GetPixelType() == scalarType); } void SetPixelTypeDouble3D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Double 3D image is set correctly.", m_Image3Db->GetPixelType().GetPixelType() == scalarType); } void SetPixelTypeFloat4D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Float 4D image is set correctly.", m_Image4Da->GetPixelType().GetPixelType() == scalarType); } void SetPixelTypeUChar4D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a UChar 4D image is set correctly.", m_Image4Db->GetPixelType().GetPixelType() == scalarType); } void SetPixelTypeUInt3D_Success() { itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a UInt 3D image is set correctly.", m_Image3Dc->GetPixelType().GetPixelType() == scalarType); } void MaxValueHolds_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if max value holds", m_Image2Da->GetStatistics()->GetScalarValueMax() <= 577); } void MinValueHolds_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if min value holds", m_Image2Da->GetStatistics()->GetScalarValueMin() >= 23); } void DefaultMaxValueHolds_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if default max value holds", m_Image3Da->GetStatistics()->GetScalarValueMax() <= 1000); } void DefaultMinValueHolds_Success() { CPPUNIT_ASSERT_MESSAGE("Testing if default min value holds", m_Image3Da->GetStatistics()->GetScalarValueMin() >= 0); } void SetGradientImageValues_Success() { const unsigned int *image3DcBuffer = nullptr; try { mitk::ImageReadAccessor readAccess(m_Image3Dc); image3DcBuffer = static_cast(readAccess.GetData()); } catch (...) { MITK_ERROR << "Read access not granted on mitk::Image."; } for (unsigned int i = 0; i < 2 * 3; i++) { CPPUNIT_ASSERT_MESSAGE("Testing if gradient image values are set correctly", image3DcBuffer[i] == i); } } }; MITK_TEST_SUITE_REGISTRATION(mitkImageGenerator) diff --git a/Modules/Multilabel/Testing/mitkLabelSetTest.cpp b/Modules/Multilabel/Testing/mitkLabelSetTest.cpp index e170361698..d4c71fc23e 100644 --- a/Modules/Multilabel/Testing/mitkLabelSetTest.cpp +++ b/Modules/Multilabel/Testing/mitkLabelSetTest.cpp @@ -1,177 +1,170 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include #include #include #include #include class mitkLabelSetTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkLabelSetTestSuite); MITK_TEST(TestSetLayer); MITK_TEST(TestSetActiveLabel); MITK_TEST(TestRemoveLabel); MITK_TEST(TestAddLabel); MITK_TEST(TestRenameLabel); MITK_TEST(TestSetAllLabelsVisible); MITK_TEST(TestSetAllLabelsLocked); MITK_TEST(TestRemoveAllLabels); CPPUNIT_TEST_SUITE_END(); private: mitk::LabelSet::Pointer m_LabelSet; mitk::LabelSet::PixelType m_InitialNumberOfLabels; void AddLabels(mitk::LabelSet::PixelType numOfLabels) { + mitk::Label::Pointer label; + const std::string namePrefix = "Label_"; + const mitk::Color gray(0.5f); + for (mitk::Label::PixelType i = 0; i < numOfLabels; ++i) { - mitk::Label::Pointer label = mitk::Label::New(); - std::stringstream nameStream; - nameStream << "Label_"; - nameStream << i; - label->SetName(nameStream.str()); + label = mitk::Label::New(); + label->SetName(namePrefix + std::to_string(i)); label->SetValue(i); - label->SetVisible((i % 20 == 0)); - label->SetLayer(i % 5); - mitk::Color color; - color.Set(0.3f, 0.25f, 1.0f); - label->SetColor(color); + label->SetVisible((i % 2 == 0)); + label->SetLayer(i % 3); + label->SetColor(gray); m_LabelSet->AddLabel(label); } } public: void setUp() override { - m_InitialNumberOfLabels = 200; + m_InitialNumberOfLabels = 6; m_LabelSet = mitk::LabelSet::New(); this->AddLabels(m_InitialNumberOfLabels); m_LabelSet->SetLayer(0); m_LabelSet->SetActiveLabel(0); } void tearDown() override { - // Reset label set m_LabelSet = nullptr; } void TestSetLayer() { CPPUNIT_ASSERT_MESSAGE("Wrong initial layer", m_LabelSet->GetLayer() == 0); - m_LabelSet->SetLayer(3); - CPPUNIT_ASSERT_MESSAGE("Wrong layer", m_LabelSet->GetLayer() == 3); + + m_LabelSet->SetLayer(1); + CPPUNIT_ASSERT_MESSAGE("Wrong layer", m_LabelSet->GetLayer() == 1); } void TestSetActiveLabel() { CPPUNIT_ASSERT_MESSAGE("Wrong initial active label", m_LabelSet->GetActiveLabel()->GetValue() == 0); - m_LabelSet->SetActiveLabel(145); - CPPUNIT_ASSERT_MESSAGE("Wrong layer", m_LabelSet->GetActiveLabel()->GetValue() == 145); + + m_LabelSet->SetActiveLabel(1); + CPPUNIT_ASSERT_MESSAGE("Wrong layer", m_LabelSet->GetActiveLabel()->GetValue() == 1); } void TestRemoveLabel() { - CPPUNIT_ASSERT_MESSAGE("Wrong initial number of label", - static_cast(m_LabelSet->GetNumberOfLabels()) == m_InitialNumberOfLabels); + CPPUNIT_ASSERT_MESSAGE("Wrong initial number of label", m_LabelSet->GetNumberOfLabels() == m_InitialNumberOfLabels); // Remove a label that is not the active label - m_LabelSet->SetActiveLabel(12); - m_LabelSet->RemoveLabel(56); - unsigned int numLabels = m_InitialNumberOfLabels - 1; - CPPUNIT_ASSERT_MESSAGE("Label was not removed", m_LabelSet->ExistLabel(56) == false); + m_LabelSet->SetActiveLabel(2); + m_LabelSet->RemoveLabel(1); + + mitk::LabelSet::PixelType numLabels = m_InitialNumberOfLabels - 1; + + CPPUNIT_ASSERT_MESSAGE("Label was not removed", m_LabelSet->ExistLabel(1) == false); CPPUNIT_ASSERT_MESSAGE("Wrong number of label", m_LabelSet->GetNumberOfLabels() == numLabels); - CPPUNIT_ASSERT_MESSAGE("Wrong active label", m_LabelSet->GetActiveLabel()->GetValue() == 12); + CPPUNIT_ASSERT_MESSAGE("Wrong active label", m_LabelSet->GetActiveLabel()->GetValue() == 2); // Remove active label - now the succeeding label should be active - m_LabelSet->RemoveLabel(12); - CPPUNIT_ASSERT_MESSAGE("Wrong layer", m_LabelSet->GetActiveLabel()->GetValue() == 13); - CPPUNIT_ASSERT_MESSAGE("Label was not removed", m_LabelSet->ExistLabel(12) == false); - numLabels = m_InitialNumberOfLabels - 2; - CPPUNIT_ASSERT_MESSAGE("Wrong initial number of label", m_LabelSet->GetNumberOfLabels() == numLabels); + m_LabelSet->RemoveLabel(2); + CPPUNIT_ASSERT_MESSAGE("Wrong layer", m_LabelSet->GetActiveLabel()->GetValue() == 3); + CPPUNIT_ASSERT_MESSAGE("Label was not removed", m_LabelSet->ExistLabel(2) == false); + CPPUNIT_ASSERT_MESSAGE("Wrong initial number of label", m_LabelSet->GetNumberOfLabels() == --numLabels); } void TestAddLabel() { - CPPUNIT_ASSERT_MESSAGE("Wrong initial number of label", m_LabelSet->GetNumberOfLabels() == m_InitialNumberOfLabels); - mitk::Label::Pointer newLabel = mitk::Label::New(); - newLabel->SetValue(199); + auto newLabel = mitk::Label::New(); + newLabel->SetValue(1); m_LabelSet->AddLabel(newLabel); - // Since label with value 199 already exists the new label will get the value 200 - CPPUNIT_ASSERT_MESSAGE("Wrong label value", m_LabelSet->GetActiveLabel()->GetValue() == 200); - unsigned int numLabels = m_InitialNumberOfLabels + 1; - CPPUNIT_ASSERT_MESSAGE("Wrong number of label", m_LabelSet->GetNumberOfLabels() == numLabels); - // Add new labels until the maximum number of labels is reached. - // Adding more labels should have no effect. - this->AddLabels(mitk::Label::MAX_LABEL_VALUE); - CPPUNIT_ASSERT_MESSAGE("Wrong number of label", m_LabelSet->GetNumberOfLabels() == 65536); - mitk::Label *activeLabel = m_LabelSet->GetActiveLabel(); - CPPUNIT_ASSERT_MESSAGE("Wrong value of active label", activeLabel->GetValue() == mitk::Label::MAX_LABEL_VALUE); + // Since label with value 1 already exists the new label will get the value m_InitialNumberOfValues + CPPUNIT_ASSERT_MESSAGE("Wrong label value", m_LabelSet->GetActiveLabel()->GetValue() == m_InitialNumberOfLabels); + CPPUNIT_ASSERT_MESSAGE("Wrong number of label", m_LabelSet->GetNumberOfLabels() == static_castGetNumberOfLabels())>(m_InitialNumberOfLabels + 1)); } void TestRenameLabel() { - mitk::Color color; - color.Set(1.0f, 1.0f, 1.0f); - std::string name("MyAwesomeLabel"); - m_LabelSet->RenameLabel(0, name, color); - mitk::Label *label = m_LabelSet->GetLabel(0); - CPPUNIT_ASSERT_MESSAGE("Wrong label name", label->GetName().compare("MyAwesomeLabel") == 0); - mitk::Color color2 = label->GetColor(); - CPPUNIT_ASSERT_MESSAGE("Wrong color", - (color2.GetBlue() == 1.0f && color2.GetGreen() == 1.0f && color2.GetRed() == 1.0f)); + const mitk::Color white(1.0f); + const std::string name = "MyAwesomeLabel"; + + m_LabelSet->RenameLabel(0, name, white); + + const auto* label = m_LabelSet->GetLabel(0); + CPPUNIT_ASSERT_MESSAGE("Wrong label name", label->GetName() == name ); + + const auto& color = label->GetColor(); + CPPUNIT_ASSERT_MESSAGE("Wrong color", color == white); } void TestSetAllLabelsVisible() { + const auto numLabels = static_cast(m_LabelSet->GetNumberOfLabels()); + m_LabelSet->SetAllLabelsVisible(true); - for (mitk::LabelSet::PixelType i = 0; i < m_LabelSet->GetNumberOfLabels(); ++i) - { + + for (mitk::LabelSet::PixelType i = 0; i < numLabels; ++i) CPPUNIT_ASSERT_MESSAGE("Label not visible", m_LabelSet->GetLabel(i)->GetVisible() == true); - } m_LabelSet->SetAllLabelsVisible(false); - for (mitk::LabelSet::PixelType i = 0; i < m_LabelSet->GetNumberOfLabels(); ++i) - { + + for (mitk::LabelSet::PixelType i = 0; i < numLabels; ++i) CPPUNIT_ASSERT_MESSAGE("Label visible", m_LabelSet->GetLabel(i)->GetVisible() == false); - } } void TestSetAllLabelsLocked() { + const auto numLabels = static_cast(m_LabelSet->GetNumberOfLabels()); + m_LabelSet->SetAllLabelsLocked(true); - for (mitk::LabelSet::PixelType i = 0; i < m_LabelSet->GetNumberOfLabels(); ++i) - { + + for (mitk::LabelSet::PixelType i = 0; i < numLabels; ++i) CPPUNIT_ASSERT_MESSAGE("Label not locked", m_LabelSet->GetLabel(i)->GetLocked() == true); - } m_LabelSet->SetAllLabelsLocked(false); - for (mitk::LabelSet::PixelType i = 0; i < m_LabelSet->GetNumberOfLabels(); ++i) - { + + for (mitk::LabelSet::PixelType i = 0; i < numLabels; ++i) CPPUNIT_ASSERT_MESSAGE("Label locked", m_LabelSet->GetLabel(i)->GetLocked() == false); - } } void TestRemoveAllLabels() { m_LabelSet->RemoveAllLabels(); CPPUNIT_ASSERT_MESSAGE("Not all labels were removed", m_LabelSet->GetNumberOfLabels() == 0); } }; MITK_TEST_SUITE_REGISTRATION(mitkLabelSet)