Exemplo n.º 1
0
  void TestGetLabelSet()
  {
    // Test get non existing lset
    mitk::LabelSet::ConstPointer lset = m_LabelSetImage->GetLabelSet(10000);
    CPPUNIT_ASSERT_MESSAGE("Non existing labelset is not nullptr", lset.IsNull());

    lset = m_LabelSetImage->GetLabelSet(0);
    CPPUNIT_ASSERT_MESSAGE("Existing labelset is nullptr", lset.IsNotNull());
  }
Exemplo n.º 2
0
  void TestGetLabel()
  {
    mitk::Label::Pointer label1 = mitk::Label::New();
    label1->SetName("Label1");
    mitk::Label::PixelType value1 = 1;
    label1->SetValue(value1);

    mitk::Label::Pointer label2 = mitk::Label::New();
    label2->SetName("Label2");
    mitk::Label::PixelType value2 = 200;
    label2->SetValue(value2);

    m_LabelSetImage->GetActiveLabelSet()->AddLabel(label1);
    m_LabelSetImage->AddLayer();
    m_LabelSetImage->GetLabelSet(1)->AddLabel(label2);

    CPPUNIT_ASSERT_MESSAGE("Wrong label retrieved for active layer",
                           mitk::Equal(*m_LabelSetImage->GetLabel(1), *label1, 0.0001, true));
    CPPUNIT_ASSERT_MESSAGE("Wrong label retrieved for layer 1",
                           mitk::Equal(*m_LabelSetImage->GetLabel(200, 1), *label2, 0.0001, true));

    // Try to get a non existing label
    mitk::Label *label3 = m_LabelSetImage->GetLabel(1000);
    CPPUNIT_ASSERT_MESSAGE("Non existing label should be nullptr", label3 == nullptr);

    // Try to get a label from a non existing layer
    label3 = m_LabelSetImage->GetLabel(200, 1000);
    CPPUNIT_ASSERT_MESSAGE("Label from non existing layer should be nullptr", label3 == nullptr);
  }
Exemplo n.º 3
0
void LabelSetImageIO::LoadLabelSetImagePreset(const std::string & presetFilename, mitk::LabelSetImage::Pointer& inputImage )
{
  std::unique_ptr<TiXmlDocument> presetXmlDoc(new TiXmlDocument());

  bool ok = presetXmlDoc->LoadFile(presetFilename);
  if ( !ok )
    return;

  TiXmlElement * presetElem = presetXmlDoc->FirstChildElement("LabelSetImagePreset");
  if(!presetElem)
  {
    MITK_INFO << "No valid preset XML";
    return;
  }

  int numberOfLayers;
  presetElem->QueryIntAttribute("layers", &numberOfLayers);

  for(int i = 0 ; i < numberOfLayers; i++)
  {
    TiXmlElement * layerElem = presetElem->FirstChildElement("Layer");
    int numberOfLabels;
    layerElem->QueryIntAttribute("labels", &numberOfLabels);

    if(inputImage->GetLabelSet(i) == NULL) inputImage->AddLayer();

    TiXmlElement * labelElement = layerElem->FirstChildElement("Label");
    if(labelElement == NULL) break;
    for(int j = 0 ; j < numberOfLabels; j++)
    {

      mitk::Label::Pointer label = mitk::LabelSetImageIO::LoadLabelFromTiXmlDocument(labelElement);
      inputImage->GetLabelSet()->AddLabel(label);

      labelElement = labelElement->NextSiblingElement("Label");
      if(labelElement == NULL) break;
    }
  }
}
Exemplo n.º 4
0
  void TestExistsLabel()
  {
    mitk::Label::Pointer label = mitk::Label::New();
    label->SetName("Label2");
    mitk::Label::PixelType value = 200;
    label->SetValue(value);

    m_LabelSetImage->AddLayer();
    m_LabelSetImage->GetLabelSet(1)->AddLabel(label);
    m_LabelSetImage->SetActiveLayer(0);
    CPPUNIT_ASSERT_MESSAGE("Existing label was not found", m_LabelSetImage->ExistLabel(value) == true);

    CPPUNIT_ASSERT_MESSAGE("Non existing label was found", m_LabelSetImage->ExistLabel(10000) == false);
  }
Exemplo n.º 5
0
  void TestGetTotalNumberOfLabels()
  {
    mitk::Label::Pointer label1 = mitk::Label::New();
    label1->SetName("Label1");
    mitk::Label::PixelType value1 = 1;
    label1->SetValue(value1);

    mitk::Label::Pointer label2 = mitk::Label::New();
    label2->SetName("Label2");
    mitk::Label::PixelType value2 = 200;
    label2->SetValue(value2);

    m_LabelSetImage->GetActiveLabelSet()->AddLabel(label1);
    m_LabelSetImage->AddLayer();
    m_LabelSetImage->GetLabelSet(1)->AddLabel(label2);
    CPPUNIT_ASSERT_MESSAGE("Wrong total number of labels", m_LabelSetImage->GetTotalNumberOfLabels() == 4); // added 2 labels + 2 exterior default labels
  }