diff --git a/Modules/Core/include/mitkPropertyList.h b/Modules/Core/include/mitkPropertyList.h index 7e056e9358..94eb67f780 100644 --- a/Modules/Core/include/mitkPropertyList.h +++ b/Modules/Core/include/mitkPropertyList.h @@ -1,254 +1,257 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D #define PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D #include "mitkBaseProperty.h" #include "mitkGenericProperty.h" #include "mitkUIDGenerator.h" #include "mitkIPropertyOwner.h" #include #include #include #include namespace mitk { class XMLWriter; /** * @brief Key-value list holding instances of BaseProperty * * This list is meant to hold an arbitrary list of "properties", * which should describe the object associated with this list. * * Usually you will use PropertyList as part of a DataNode * object - in this context the properties describe the data object * held by the DataNode (e.g. whether the object is rendered at * all, which color is used for rendering, what name should be * displayed for the object, etc.) * * The values in the list are not fixed, you may introduce any kind * of property that seems useful - all you have to do is inherit * from BaseProperty. * * The list is organized as a key-value pairs, i.e. * * \li "name" : pointer to a StringProperty * \li "visible" : pointer to a BoolProperty * \li "color" : pointer to a ColorProperty * \li "volume" : pointer to a FloatProperty * * Please see the documentation of SetProperty and ReplaceProperty for two * quite different semantics. Normally SetProperty is what you want - this * method will try to change the value of an existing property and will * not allow you to replace e.g. a ColorProperty with an IntProperty. * + * Please also regard, that the key of a property must be a none empty string. + * This is a precondition. Setting properties with empty keys will raise an exception. + * * @ingroup DataManagement */ class MITKCORE_EXPORT PropertyList : public itk::Object, public IPropertyOwner { public: mitkClassMacroItkParent(PropertyList, itk::Object) /** * Method for creation through the object factory. */ itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** * Map structure to hold the properties: the map key is a string, * the value consists of the actual property object (BaseProperty). */ typedef std::map PropertyMap; typedef std::pair PropertyMapElementType; // IPropertyProvider BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override; std::vector GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override; std::vector GetPropertyContextNames() const override; // IPropertyOwner BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override; void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override; void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override; /** * @brief Get a property by its name. */ mitk::BaseProperty *GetProperty(const std::string &propertyKey) const; /** * @brief Set a property object in the list/map by reference. * * The actual OBJECT holding the value of the property is replaced by this function. * This is useful if you want to change the type of the property, like from BoolProperty to StringProperty. * Another use is to share one and the same property object among several ProperyList/DataNode objects, which * makes them appear synchronized. */ void ReplaceProperty(const std::string &propertyKey, BaseProperty *property); /** * @brief Set a property object in the list/map by reference. */ void ConcatenatePropertyList(PropertyList *pList, bool replace = false); //##Documentation //## @brief Convenience access method for GenericProperty properties //## (T being the type of the second parameter) //## @return @a true property was found template bool GetPropertyValue(const char *propertyKey, T &value) const { GenericProperty *gp = dynamic_cast *>(GetProperty(propertyKey)); if (gp != nullptr) { value = gp->GetValue(); return true; } return false; } /** * @brief Convenience method to access the value of a BoolProperty */ bool GetBoolProperty(const char *propertyKey, bool &boolValue) const; /** * @brief ShortCut for the above method */ bool Get(const char *propertyKey, bool &boolValue) const; /** * @brief Convenience method to set the value of a BoolProperty */ void SetBoolProperty(const char *propertyKey, bool boolValue); /** * @brief ShortCut for the above method */ void Set(const char *propertyKey, bool boolValue); /** * @brief Convenience method to access the value of an IntProperty */ bool GetIntProperty(const char *propertyKey, int &intValue) const; /** * @brief ShortCut for the above method */ bool Get(const char *propertyKey, int &intValue) const; /** * @brief Convenience method to set the value of an IntProperty */ void SetIntProperty(const char *propertyKey, int intValue); /** * @brief ShortCut for the above method */ void Set(const char *propertyKey, int intValue); /** * @brief Convenience method to access the value of a FloatProperty */ bool GetFloatProperty(const char *propertyKey, float &floatValue) const; /** * @brief ShortCut for the above method */ bool Get(const char *propertyKey, float &floatValue) const; /** * @brief Convenience method to set the value of a FloatProperty */ void SetFloatProperty(const char *propertyKey, float floatValue); /** * @brief ShortCut for the above method */ void Set(const char *propertyKey, float floatValue); /** * @brief Convenience method to access the value of a DoubleProperty */ bool GetDoubleProperty(const char *propertyKey, double &doubleValue) const; /** * @brief ShortCut for the above method */ bool Get(const char *propertyKey, double &doubleValue) const; /** * @brief Convenience method to set the value of a DoubleProperty */ void SetDoubleProperty(const char *propertyKey, double doubleValue); /** * @brief ShortCut for the above method */ void Set(const char *propertyKey, double doubleValue); /** * @brief Convenience method to access the value of a StringProperty */ bool GetStringProperty(const char *propertyKey, std::string &stringValue) const; /** * @brief ShortCut for the above method */ bool Get(const char *propertyKey, std::string &stringValue) const; /** * @brief Convenience method to set the value of a StringProperty */ void SetStringProperty(const char *propertyKey, const char *stringValue); /** * @brief ShortCut for the above method */ void Set(const char *propertyKey, const char *stringValue); /** * @brief ShortCut for the above method */ void Set(const char *propertyKey, const std::string &stringValue); /** * @brief Get the timestamp of the last change of the map or the last change of one of * the properties store in the list (whichever is later). */ unsigned long GetMTime() const override; /** * @brief Remove a property from the list/map. */ bool DeleteProperty(const std::string &propertyKey); const PropertyMap *GetMap() const { return &m_Properties; } bool IsEmpty() const { return m_Properties.empty(); } virtual void Clear(); protected: PropertyList(); PropertyList(const PropertyList &other); ~PropertyList() override; /** * @brief Map of properties. */ PropertyMap m_Properties; private: itk::LightObject::Pointer InternalClone() const override; }; } // namespace mitk #endif /* PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D */ diff --git a/Modules/Core/test/mitkPropertyListTest.cpp b/Modules/Core/test/mitkPropertyListTest.cpp index f4fb875fdf..b11dbb5ac6 100644 --- a/Modules/Core/test/mitkPropertyListTest.cpp +++ b/Modules/Core/test/mitkPropertyListTest.cpp @@ -1,262 +1,292 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkLookupTables.h" #include "mitkProperties.h" #include "mitkPropertyList.h" #include "mitkStringProperty.h" +#include "mitkExceptionMacro.h" + #include int mitkPropertyListTest(int /*argc*/, char * /*argv*/ []) { mitk::PropertyList::Pointer propList; std::cout << "Testing mitk::PropertyList::New(): "; propList = mitk::PropertyList::New(); if (propList.IsNull()) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } else { std::cout << "[PASSED]" << std::endl; } mitk::BoolProperty::Pointer boolProp = mitk::BoolProperty::New(false); mitk::BoolProperty::Pointer boolProp2 = mitk::BoolProperty::New(false); std::cout << "Testing BoolProperty ==: "; if (!(*boolProp2 == *boolProp)) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; unsigned long tBefore, tAfter; std::cout << "Testing SetProperty() with new key value: "; tBefore = propList->GetMTime(); propList->SetProperty("test", boolProp); tAfter = propList->GetMTime(); if (!(tAfter > tBefore)) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "Testing SetProperty() with changed property value: "; tBefore = propList->GetMTime(); propList->SetProperty("test", mitk::BoolProperty::New(true)); tAfter = propList->GetMTime(); if (!(tAfter > tBefore)) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "Testing SetProperty() with unchanged property value: "; tBefore = propList->GetMTime(); propList->SetProperty("test", mitk::BoolProperty::New(true)); tAfter = propList->GetMTime(); if (tBefore != tAfter) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "Testing MTime correctness when changing property value: "; boolProp = mitk::BoolProperty::New(true); propList->ReplaceProperty("test", boolProp); tBefore = propList->GetMTime(); boolProp->SetValue(true); tAfter = propList->GetMTime(); boolProp->SetValue(false); unsigned long tAfterAll = propList->GetMTime(); if (tBefore != tAfter || tAfterAll <= tAfter) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "Testing MTime correctness when calling SetProperty twice: "; boolProp = mitk::BoolProperty::New(true); propList->SetProperty("test", boolProp); tBefore = propList->GetMTime(); propList->SetProperty("test", boolProp); tAfter = propList->GetMTime(); if (tBefore != tAfter) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "Testing if existing properties survive SetProperty: "; propList->SetProperty("test", boolProp); mitk::BaseProperty *bpBefore = propList->GetProperty("test"); propList->SetProperty("test", boolProp2); mitk::BaseProperty *bpAfter = propList->GetProperty("test"); if (bpBefore != bpAfter || bpAfter == nullptr) { std::cout << std::endl; std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; std::cout << "Testing if existing properties survive ReplaceProperty: "; propList->SetProperty("test", boolProp); bpBefore = propList->GetProperty("test"); propList->ReplaceProperty("test", boolProp2); bpAfter = propList->GetProperty("test"); if (bpBefore == bpAfter || bpAfter == nullptr) { std::cout << std::endl; std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; // std::cout << "Testing output of PropertyList to file: "; // if ( TestXMLWriter() ) // std::cout << "[PASSED]" << std::endl; // else // return EXIT_FAILURE; std::cout << "Testing GetPropertyValue(bool): "; mitk::BoolProperty::Pointer gpvTest = mitk::BoolProperty::New(true); propList->SetProperty("gpvBool", gpvTest); bool b = false; bool getPropertyValueReturnValue = propList->GetPropertyValue("gpvBool", b); if ((getPropertyValueReturnValue == true) && (b == gpvTest->GetValue())) std::cout << "[PASSED]" << std::endl; else { std::cout << "Oh, not goot:" "\nWe called propList->GetPropertyValue('gpvBool', b) and it returned " << getPropertyValueReturnValue << "\nThen we compared b [" << b << "] and gpvTest->GetValue() [" << gpvTest->GetValue() << "]" << std::endl; std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "Testing GetPropertyValue(float): "; mitk::FloatProperty::Pointer gpvTest2 = mitk::FloatProperty::New(3.1337); propList->SetProperty("gpvfloat", gpvTest2); float v = -1.23; if ((propList->GetPropertyValue("gpvfloat", v) == true) && (v == gpvTest2->GetValue())) std::cout << "[PASSED]" << std::endl; else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "Testing GetPropertyValue(BoolLookupTable): "; mitk::BoolLookupTable blt; blt.SetTableValue(17, true); propList->SetProperty("blutprop", mitk::BoolLookupTableProperty::New(blt)); try { mitk::BoolLookupTable blut; if ((propList->GetPropertyValue("blutprop", blut) == true) && (blut.GetTableValue(17) == true)) std::cout << "[PASSED]" << std::endl; else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } } catch (...) { std::cout << "Exception thrown! [FAILED]" << std::endl; return EXIT_FAILURE; } { std::cout << "Testing GetBoolProperty(): "; mitk::BoolProperty::Pointer prop = mitk::BoolProperty::New(true); propList->ReplaceProperty("test", prop); bool v = false; if ((propList->GetBoolProperty("test", v) == true) && (v == prop->GetValue())) std::cout << "[PASSED]" << std::endl; else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } } { std::cout << "Testing GetIntProperty(): "; mitk::IntProperty::Pointer prop = mitk::IntProperty::New(31337); propList->ReplaceProperty("test", prop); int v = 1; if ((propList->GetIntProperty("test", v) == true) && (v == prop->GetValue())) std::cout << "[PASSED]" << std::endl; else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } } { std::cout << "Testing GetFloatProperty(): "; mitk::FloatProperty::Pointer prop = mitk::FloatProperty::New(31.337); propList->ReplaceProperty("test", prop); float v = 1.2; if ((propList->GetFloatProperty("test", v) == true) && (v == prop->GetValue())) std::cout << "[PASSED]" << std::endl; else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } } { std::cout << "Testing GetStringProperty(): "; mitk::StringProperty::Pointer prop = mitk::StringProperty::New("MITK"); propList->ReplaceProperty("test", prop); std::string v = ""; if ((propList->GetStringProperty("test", v) == true) && (v == prop->GetValue())) std::cout << "[PASSED]" << std::endl; else { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } } { std::cout << "Testing RemoveProperty(): "; propList->RemoveProperty("test"); if (propList->GetProperty("test")!=nullptr) { std::cout << "[FAILED]" << std::endl; return EXIT_FAILURE; } std::cout << "[PASSED]" << std::endl; } + std::cout << "Testing SetProperty() with no property (nullptr): "; + tBefore = propList->GetMTime(); + propList->SetProperty("nullprop", nullptr); + tAfter = propList->GetMTime(); + if (!(tAfter == tBefore)) + { + std::cout << "[FAILED]" << std::endl; + return EXIT_FAILURE; + } + std::cout << "[PASSED]" << std::endl; + + std::cout << "Testing SetProperty() with invalid (empty) name: "; + try + { + propList->SetProperty("", boolProp); + std::cout << "[FAILED]" << std::endl; + return EXIT_FAILURE; + } + catch (const mitk::Exception& /*e*/) + { + std::cout << "[PASSED]" << std::endl; + } + catch (...) + { + std::cout << "[FAILED]" << std::endl; + return EXIT_FAILURE; + } + std::cout << "[TEST DONE]" << std::endl; return EXIT_SUCCESS; } diff --git a/Modules/SceneSerialization/test/mitkSceneIOTestScenarioProvider.cpp b/Modules/SceneSerialization/test/mitkSceneIOTestScenarioProvider.cpp index a8ae42ec00..328f3b6d23 100644 --- a/Modules/SceneSerialization/test/mitkSceneIOTestScenarioProvider.cpp +++ b/Modules/SceneSerialization/test/mitkSceneIOTestScenarioProvider.cpp @@ -1,439 +1,438 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkSceneIOTestScenarioProvider.h" #include "mitkGeometryData.h" #include "mitkImage.h" #include "mitkImageGenerator.h" #include "mitkPointSet.h" #include "mitkProperties.h" #include "mitkSurface.h" #include #include #include namespace { std::string VeryLongText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.Donec a diam lectus.Sed sit amet ipsum mauris.Maecenas " "congue ligula ac quam viverra nec consectetur ante hendrerit.Donec et mollis dolor.Praesent et diam eget libero " "egestas mattis sit amet vitae augue.Nam tincidunt congue enim, ut porta lorem lacinia consectetur.Donec ut libero " "sed arcu vehicula ultricies a non tortor.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Aenean ut " "gravida lorem.Ut turpis felis, pulvinar a semper sed, adipiscing id dolor.Pellentesque auctor nisi id magna " "consequat sagittis.Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet.Ut convallis " "libero in urna ultrices accumsan.Donec sed odio eros.Donec viverra mi quis quam pulvinar at malesuada arcu " "rhoncus.Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.In rutrum accumsan " "ultricies.Mauris vitae nisi at sem facilisis semper ac in est.\n" "Vivamus fermentum semper porta.Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio.Maecenas " "convallis ullamcorper ultricies.Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id " "fringilla sem nunc vel mi.Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna " "et turpis.Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci.Fusce eget orci a orci congue " "vestibulum.Ut dolor diam, elementum et vestibulum eu, porttitor vel elit.Curabitur venenatis pulvinar tellus " "gravida ornare.Sed et erat faucibus nunc euismod ultricies ut id justo.Nullam cursus suscipit nisi, et ultrices " "justo sodales nec.Fusce venenatis facilisis lectus ac semper.Aliquam at massa ipsum.Quisque bibendum purus " "convallis nulla ultrices ultricies.Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra " "pretium nisi quam vitae mi.Fusce vel volutpat elit.Nam sagittis nisi dui.\r\n" "Suspendisse lectus leo, consectetur in tempor sit amet, placerat quis neque.Etiam luctus porttitor lorem, sed " "suscipit est rutrum non.Curabitur lobortis nisl a enim congue semper.Aenean commodo ultrices imperdiet.Vestibulum " "ut justo vel sapien venenatis tincidunt.Phasellus eget dolor sit amet ipsum dapibus condimentum vitae quis " "lectus.Aliquam ut massa in turpis dapibus convallis.Praesent elit lacus, vestibulum at malesuada et, ornare et " "est.Ut augue nunc, sodales ut euismod non, adipiscing vitae orci.Mauris ut placerat justo.Mauris in ultricies " "enim.Quisque nec est eleifend nulla ultrices egestas quis ut quam.Donec sollicitudin lectus a mauris pulvinar id " "aliquam urna cursus.Cras quis ligula sem, vel elementum mi.Phasellus non ullamcorper urna.\t\n" "Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.In euismod ultrices " "facilisis.Vestibulum porta sapien adipiscing augue congue id pretium lectus molestie.Proin quis dictum nisl.Morbi " "id quam sapien, sed vestibulum sem.Duis elementum rutrum mauris sed convallis.Proin vestibulum magna mi.Aenean " "tristique hendrerit magna, ac facilisis nulla hendrerit ut.Sed non tortor sodales quam auctor elementum.Donec " "hendrerit nunc eget elit pharetra pulvinar.Suspendisse id tempus tortor.Aenean luctus, elit commodo laoreet " "commodo, justo nisi consequat massa, sed vulputate quam urna quis eros.Donec vel."; } // --------------- SceneIOTestScenarioProvider::Scenario --------------- mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::Scenario::BuildDataStorage() const { return (*m_ScenarioProvider.*m_ProviderMethod)(); // calls function } mitk::SceneIOTestScenarioProvider::Scenario::Scenario(const std::string &_key, const SceneIOTestScenarioProvider *_scenarioProvider, SceneIOTestScenarioProvider::BuilderMethodPointer _providerMethod, bool _isSerializable, const std::string &_referenceArchiveFilename, bool _isReferenceLoadable, double _comparisonPrecision) : key(_key), serializable(_isSerializable), referenceArchiveFilename(_referenceArchiveFilename), referenceArchiveLoadable(_isReferenceLoadable), comparisonPrecision(_comparisonPrecision), m_ScenarioProvider(_scenarioProvider), m_ProviderMethod(_providerMethod) { } // --------------- SceneIOTestScenarioProvider --------------- mitk::SceneIOTestScenarioProvider::ScenarioList mitk::SceneIOTestScenarioProvider::GetAllScenarios() const { return m_Scenarios; } void mitk::SceneIOTestScenarioProvider::AddScenario(const std::string &key, BuilderMethodPointer creator, bool isSerializable, const std::string &referenceArchiveFilename, bool isReferenceLoadable, double comparisonPrecision) { Scenario newScenario( key, this, creator, isSerializable, referenceArchiveFilename, isReferenceLoadable, comparisonPrecision); m_Scenarios.push_back(newScenario); } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::EmptyStorage() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::OneEmptyNode() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); mitk::DataNode::Pointer node = DataNode::New(); storage->Add(node); return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::OneEmptyNamedNode() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); mitk::DataNode::Pointer node = DataNode::New(); node->SetName("Urmel"); storage->Add(node); return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::ManyTopLevelNodes() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); for (auto i = 0; i < m_HowMuchIsMany; ++i) { mitk::DataNode::Pointer node = DataNode::New(); std::stringstream s; s << "Node #" << i; node->SetName(s.str()); storage->Add(node); } return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::LineOfManyOnlyChildren() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); mitk::DataNode::Pointer parent; for (auto i = 0; i < m_HowMuchIsMany; ++i) { mitk::DataNode::Pointer node = DataNode::New(); std::stringstream s; s << "Node #" << i; node->SetName(s.str()); storage->Add(node, parent); parent = node; } return storage; } #define AddNode(name) storage->Add(name); #define DefineNode(name) \ mitk::DataNode::Pointer name = mitk::DataNode::New(); \ name->SetName(#name); #define DefNode0(name) DefineNode(name) AddNode(name) #define DefNode1(source, name) DefineNode(name) storage->Add(name, source); #define DefNode2(source1, source2, name) \ DefineNode(name) \ { \ mitk::DataStorage::SetOfObjects::Pointer sources = mitk::DataStorage::SetOfObjects::New(); \ sources->push_back(source1); \ sources->push_back(source2); \ storage->Add(name, sources); \ } #define DefNode3(source1, source2, source3, name) \ DefineNode(name) \ { \ mitk::DataStorage::SetOfObjects::Pointer sources = mitk::DataStorage::SetOfObjects::New(); \ sources->push_back(source1); \ sources->push_back(source2); \ sources->push_back(source3); \ storage->Add(name, sources); \ } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::ComplicatedFamilySituation() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); // constructing a hierarchy with multiple levels // and a couple of multiple parent relations. // Anybody, feel free to make this something // meaningful and/or visualize it :-) DefNode0(Color) DefNode0(White) DefNode1(Color, Green) DefNode1(Color, Election) DefNode1(Color, Red) DefNode1(Green, Yellow) DefNode1(Election, Looser) DefNode1(Election, FreeBeer) DefNode1(Election, Winner) DefNode1(Looser, Tears) DefNode1(Looser, Anger) DefNode1(FreeBeer, OpenSource); DefNode1(White, Sweet) DefNode2(White, Sweet, Sugar) DefNode2(Red, Sweet, Tomatoe) DefNode2(Tomatoe, Sugar, Ketchup) DefNode1(Ketchup, BBQSauce) DefNode1(Tomatoe, ATLAS) DefNode0(Fish) DefNode0(OperatingSystem) DefNode1(Fish, Bird) DefNode1(Bird, Penguin) DefNode3(Penguin, OperatingSystem, OpenSource, Linux) return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::Image() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); { // Image of ints mitk::Image::Pointer image3Dints = mitk::ImageGenerator::GenerateRandomImage(10, 5, 7, // dim 1, 0.5, 0.5, // spacing 1, // time steps 3000, -1000); // random max / min mitk::DataNode::Pointer node = DataNode::New(); node->SetName("Image-Int"); node->SetData(image3Dints); storage->Add(node); } { // Image of doubles mitk::Image::Pointer image3Ddouble = mitk::ImageGenerator::GenerateRandomImage(5, 10, 8, // dim 1, 0.5, 0.5, // spacing 2, // time steps 3000, -1000); // random max / min mitk::DataNode::Pointer node = DataNode::New(); node->SetName("Image-Double"); node->SetData(image3Ddouble); storage->Add(node); } return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::Surface() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); { // Surface vtkSmartPointer points1 = vtkSmartPointer::New(); points1->InsertNextPoint(0.0, 0.0, 0.0); points1->InsertNextPoint(1.0, 0.0, 0.0); points1->InsertNextPoint(0.0, 1.0, 0.0); points1->InsertNextPoint(1.0, 1.0, 0.0); vtkSmartPointer polygon1 = vtkSmartPointer::New(); polygon1->GetPointIds()->SetNumberOfIds(4); polygon1->GetPointIds()->SetId(0, 0); polygon1->GetPointIds()->SetId(1, 1); polygon1->GetPointIds()->SetId(2, 2); polygon1->GetPointIds()->SetId(3, 3); vtkSmartPointer polygon2 = vtkSmartPointer::New(); polygon2->GetPointIds()->SetNumberOfIds(4); polygon2->GetPointIds()->SetId(0, 3); polygon2->GetPointIds()->SetId(1, 2); polygon2->GetPointIds()->SetId(2, 0); polygon2->GetPointIds()->SetId(3, 1); // generate polydatas vtkSmartPointer polygonArray1 = vtkSmartPointer::New(); polygonArray1->InsertNextCell(polygon1); vtkSmartPointer polydata1 = vtkSmartPointer::New(); polydata1->SetPoints(points1); polydata1->SetPolys(polygonArray1); vtkSmartPointer polygonArray2 = vtkSmartPointer::New(); polygonArray2->InsertNextCell(polygon2); vtkSmartPointer polyDataTwo = vtkSmartPointer::New(); polyDataTwo->SetPoints(points1); polyDataTwo->SetPolys(polygonArray2); // generate surfaces mitk::Surface::Pointer surface = mitk::Surface::New(); surface->SetVtkPolyData(polydata1); mitk::DataNode::Pointer node = DataNode::New(); node->SetName("Surface"); node->SetData(surface); storage->Add(node); } return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::PointSet() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); { // PointSet mitk::PointSet::Pointer ps = mitk::PointSet::New(); mitk::PointSet::PointType p; mitk::FillVector3D(p, 1.0, -2.0, 33.0); ps->SetPoint(0, p); mitk::FillVector3D(p, 100.0, -200.0, 3300.0); ps->SetPoint(1, p); mitk::FillVector3D(p, 2.0, -3.0, 22.0); ps->SetPoint(2, p, mitk::PTCORNER); // add point spec mitk::DataNode::Pointer node = DataNode::New(); node->SetName("PointSet"); node->SetData(ps); storage->Add(node); } return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::GeometryData() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); { // GeometryData mitk::GeometryData::Pointer gdata = mitk::GeometryData::New(); // define Geometry3D parameters mitk::AffineTransform3D::MatrixType matrix; matrix[0][0] = 1.1; matrix[1][1] = 2.2; matrix[2][2] = 3.3; mitk::AffineTransform3D::OffsetType offset; mitk::FillVector3D(offset, 0.1, 0.2, 0.3); bool isImageGeometry(false); unsigned int frameOfReferenceID(47); mitk::BaseGeometry::BoundsArrayType bounds; bounds[0] = std::numeric_limits::min(); bounds[1] = -52.723; bounds[2] = -0.002; bounds[3] = 918273645.18293746; bounds[4] = -0.002; bounds[5] = +52.723; mitk::Point3D origin; mitk::FillVector3D(origin, 5.1, 5.2, 5.3); mitk::Vector3D spacing; mitk::FillVector3D(spacing, 2.1, 2.2, 2.3); // build GeometryData from matrix/offset/etc. mitk::AffineTransform3D::Pointer newTransform = mitk::AffineTransform3D::New(); newTransform->SetMatrix(matrix); newTransform->SetOffset(offset); mitk::Geometry3D::Pointer newGeometry = mitk::Geometry3D::New(); newGeometry->SetFrameOfReferenceID(frameOfReferenceID); newGeometry->SetImageGeometry(isImageGeometry); newGeometry->SetIndexToWorldTransform(newTransform); newGeometry->SetBounds(bounds); newGeometry->SetOrigin(origin); newGeometry->SetSpacing(spacing); mitk::GeometryData::Pointer geometryData = mitk::GeometryData::New(); geometryData->SetGeometry(newGeometry); mitk::DataNode::Pointer node = DataNode::New(); node->SetName("GeometryData"); node->SetData(geometryData); storage->Add(node); } return storage; } mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::SpecialProperties() const { mitk::DataStorage::Pointer storage = StandaloneDataStorage::New().GetPointer(); mitk::DataNode::Pointer node = DataNode::New(); node->SetName("Camion"); - node->SetProperty("", StringProperty::New("Colis")); // no name! node->SetProperty("Livre", StringProperty::New(VeryLongText)); // defined at the top of this file node->SetProperty(VeryLongText.c_str(), StringProperty::New("Shorty")); node->GetPropertyList("Chapitre1")->SetProperty("Page 1", StringProperty::New(VeryLongText)); node->GetPropertyList("Chapitre1")->SetProperty("Page 2", StringProperty::New(VeryLongText)); node->GetPropertyList("Chapitre 2")->SetProperty("Page", StringProperty::New(VeryLongText)); node->GetPropertyList("Chapitre 3")->SetProperty("Page", StringProperty::New(VeryLongText)); node->GetPropertyList(VeryLongText)->SetProperty("Page", StringProperty::New(VeryLongText)); // not working (NaN etc.) // node->SetProperty("NotAFloat", FloatProperty::New( sqrt(-1.0) ) ); node->SetProperty("sqrt(2)", FloatProperty::New(-sqrt(2.0))); node->SetProperty("sqrt(3)", FloatProperty::New(sqrt(3.0))); // most values work fine, just min/max double produces serialization precision errors node->SetProperty("sqrt(4)", DoubleProperty::New(-sqrt(4.0))); node->SetProperty("sqrt(5)", DoubleProperty::New(sqrt(5.0))); // node->SetProperty("maxd", DoubleProperty::New( std::numeric_limits::max() ) ); node->SetProperty("zero", DoubleProperty::New(0.0)); node->SetProperty("minzero", DoubleProperty::New(-0.0)); // node->SetProperty("mind", DoubleProperty::New( std::numeric_limits::min() ) ); storage->Add(node); return storage; }