Index: Core/Code/DataManagement/mitkGenericLookupTable.h =================================================================== --- Core/Code/DataManagement/mitkGenericLookupTable.h (revision 19499) +++ Core/Code/DataManagement/mitkGenericLookupTable.h (working copy) @@ -45,16 +45,25 @@ * tables to mappers to configure the rendering process. */ template -class GenericLookupTable : public itk::DataObject +class GenericLookupTable { public: typedef unsigned int IdentifierType; typedef T ValueType; typedef std::map< IdentifierType, ValueType > LookupTableType; - mitkClassMacro(GenericLookupTable, itk::DataObject); - itkNewMacro(Self); - + typedef GenericLookupTable Self; + + GenericLookupTable() {} + virtual ~GenericLookupTable() + { + } + + virtual const char *GetNameOfClass() const + { + return "GenericLookupTable"; + } + void SetTableValue( IdentifierType id, ValueType value ) { m_LookupTable[id] = value; @@ -75,17 +84,21 @@ throw std::range_error("id does not exist in the lookup table"); } - //const LookupTableType& GetLookupTable() const - //{ - // return m_LookupTable; - //} + const LookupTableType& GetLookupTable() const + { + return m_LookupTable; + } bool operator==( const Self& lookupTable ) const { return (m_LookupTable == lookupTable.m_LookupTable); } + bool operator!=( const Self& lookupTable ) const + { + return !(m_LookupTable == lookupTable.m_LookupTable); + } - virtual Self& operator=(const Self& other) + virtual Self& operator=(const Self& other) // \TODO: this needs to be unit tested! { if ( this == &other ) { @@ -93,17 +106,12 @@ } else { - //TODO: implement copying of values + m_LookupTable.clear(); + m_LookupTable = other.m_LookupTable; return *this; } } - protected: - GenericLookupTable() {} - virtual ~GenericLookupTable() - { - } - LookupTableType m_LookupTable; }; } // namespace mitk @@ -119,11 +127,23 @@ class MITK_CORE_EXPORT LookupTableName: public GenericLookupTable< Type > \ { \ public: \ - mitkClassMacro(LookupTableName, GenericLookupTable< Type >); \ - itkNewMacro(LookupTableName); \ -protected: \ +typedef LookupTableName Self; \ + typedef GenericLookupTable< Type > Superclass; \ + virtual const char *GetNameOfClass() const \ + {return #LookupTableName;} \ LookupTableName() {} \ virtual ~LookupTableName() {} \ +}; \ +std::ostream& operator<<(std::ostream& stream, const LookupTableName& l); + +/** +* Generates the ostream << operator for the lookuptable. This definition +* of a global function must be in a cpp file, therefore it is split from the +* class declaration macro mitkSpecializeGenericLookupTable. +*/ +#define mitkSpecializeGenericLookupTableOperator(LookupTableName) \ +std::ostream& mitk::operator<<(std::ostream& stream, const LookupTableName& l) \ +{ \ + return stream; \ }; - #endif Index: Core/Code/DataManagement/mitkLookupTables.cpp =================================================================== --- Core/Code/DataManagement/mitkLookupTables.cpp (revision 19499) +++ Core/Code/DataManagement/mitkLookupTables.cpp (working copy) @@ -22,3 +22,9 @@ template class mitk::GenericLookupTable; template class mitk::GenericLookupTable; template class mitk::GenericLookupTable; + + +mitkSpecializeGenericLookupTableOperator(mitk::BoolLookupTable); +mitkSpecializeGenericLookupTableOperator(mitk::FloatLookupTable); +mitkSpecializeGenericLookupTableOperator(mitk::IntLookupTable); +mitkSpecializeGenericLookupTableOperator(mitk::StringLookupTable); Index: Core/Code/DataManagement/mitkLookupTables.h =================================================================== --- Core/Code/DataManagement/mitkLookupTables.h (revision 19499) +++ Core/Code/DataManagement/mitkLookupTables.h (working copy) @@ -26,6 +26,9 @@ * * This file contains specializations of mitk::GenericLookupTable * for bool, float, int and std::string lookuptables +* \WARN: you have to call the mitkSpecializeGenericLookupTableOperator macro +* in mitkLookupTables.cpp with each specialization to add an ostream << operator +* for that lookuptable specialization. */ namespace mitk { mitkSpecializeGenericLookupTable(BoolLookupTable, bool); Index: Core/Code/DataManagement/mitkProperties.cpp =================================================================== --- Core/Code/DataManagement/mitkProperties.cpp (revision 19499) +++ Core/Code/DataManagement/mitkProperties.cpp (working copy) @@ -26,7 +26,7 @@ template class mitk::GenericProperty >; template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; -template class mitk::GenericProperty; +template class mitk::GenericProperty; +template class mitk::GenericProperty; +template class mitk::GenericProperty; +template class mitk::GenericProperty; Index: Core/Code/DataManagement/mitkProperties.h =================================================================== --- Core/Code/DataManagement/mitkProperties.h (revision 19499) +++ Core/Code/DataManagement/mitkProperties.h (working copy) @@ -41,11 +41,10 @@ mitkSpecializeGenericProperty(Point3iProperty,Point3I,Point3I::BaseArray::Filled(0).GetDataPointer() ); - mitkSpecializeGenericProperty(FloatLookupTableProperty, FloatLookupTable::Pointer , FloatLookupTable::New()); - mitkSpecializeGenericProperty(BoolLookupTableProperty, BoolLookupTable::Pointer , BoolLookupTable::New()); - mitkSpecializeGenericProperty(IntLookupTableProperty, IntLookupTable::Pointer , IntLookupTable::New()); - mitkSpecializeGenericProperty(StringLookupTableProperty, StringLookupTable::Pointer , StringLookupTable::New()); - + mitkSpecializeGenericProperty(FloatLookupTableProperty, FloatLookupTable, FloatLookupTable()); + mitkSpecializeGenericProperty(BoolLookupTableProperty, BoolLookupTable, BoolLookupTable()); + mitkSpecializeGenericProperty(IntLookupTableProperty, IntLookupTable, IntLookupTable()); + mitkSpecializeGenericProperty(StringLookupTableProperty, StringLookupTable, StringLookupTable()); /** * \warning If you add more specialization of GenericProperty, you must also add these to the * templated GetPropertyValue() method in mitkPropertyList.cpp! Index: Modules/MitkExt/Rendering/mitkEnhancedPointSetVtkMapper3D.cpp =================================================================== --- Modules/MitkExt/Rendering/mitkEnhancedPointSetVtkMapper3D.cpp (revision 19499) +++ Modules/MitkExt/Rendering/mitkEnhancedPointSetVtkMapper3D.cpp (working copy) @@ -232,18 +232,18 @@ mitk::BoolLookupTableProperty* visLTProp = dynamic_cast(visProp); if (visLTProp != NULL) { - mitk::BoolLookupTable* visLookupTable = visLTProp->GetValue(); - if (visLookupTable != NULL) - { + mitk::BoolLookupTable visLookupTable = visLTProp->GetValue(); + //if (visLookupTable != NULL) + //{ try { - pointVisibility = visLookupTable->GetTableValue(pointID); + pointVisibility = visLookupTable.GetTableValue(pointID); visValueFound = true; } catch (...) { } - } + //} } if (visValueFound == false) { @@ -258,18 +258,18 @@ mitk::FloatLookupTableProperty* opLTProp = dynamic_cast(opProp); if (opLTProp != NULL) { - mitk::FloatLookupTable* opLookupTable = opLTProp->GetValue(); - if (opLookupTable != NULL) - { + mitk::FloatLookupTable opLookupTable = opLTProp->GetValue(); + //if (opLookupTable != NULL) + //{ try { - opacity = opLookupTable->GetTableValue(pointID); + opacity = opLookupTable.GetTableValue(pointID); opValueFound = true; } catch (...) { } - } + //} } if (opValueFound == false) { Index: Modules/SceneSerialization/BasePropertyDeserializer/mitkBoolLookupTablePropertyDeserializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertyDeserializer/mitkBoolLookupTablePropertyDeserializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertyDeserializer/mitkBoolLookupTablePropertyDeserializer.cpp (revision 0) @@ -0,0 +1,66 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:07:40 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkBoolLookupTablePropertyDeserializer_h_included +#define mitkBoolLookupTablePropertyDeserializer_h_included + +#include "mitkBasePropertyDeserializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT BoolLookupTablePropertyDeserializer : public BasePropertyDeserializer +{ + public: + + mitkClassMacro( BoolLookupTablePropertyDeserializer, BasePropertyDeserializer ); + itkNewMacro(Self); + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) + return NULL; + + BoolLookupTable lut; + for( TiXmlElement* child = element->FirstChildElement("LUTValue"); child != NULL; child = child->NextSiblingElement("LUTValue")) + { + + int xmlID; + if (child->QueryIntAttribute("id", &xmlID) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + BoolLookupTable::IdentifierType id = static_cast(xmlID); + BoolLookupTable::ValueType val = std::string(child->Attribute("value")) == std::string("true"); + lut.SetTableValue(id, val); + } + return BoolLookupTableProperty::New(lut).GetPointer(); + } + + protected: + BoolLookupTablePropertyDeserializer() {} + virtual ~BoolLookupTablePropertyDeserializer() {} +}; + +} // namespace + +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(BoolLookupTablePropertyDeserializer); + +#endif + Index: Modules/SceneSerialization/BasePropertyDeserializer/mitkFloatLookupTablePropertyDeserializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertyDeserializer/mitkFloatLookupTablePropertyDeserializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertyDeserializer/mitkFloatLookupTablePropertyDeserializer.cpp (revision 0) @@ -0,0 +1,64 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:07:40 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkFloatLookupTablePropertyDeserializer_h_included +#define mitkFloatLookupTablePropertyDeserializer_h_included + +#include "mitkBasePropertyDeserializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT FloatLookupTablePropertyDeserializer : public BasePropertyDeserializer +{ + public: + + mitkClassMacro( FloatLookupTablePropertyDeserializer, BasePropertyDeserializer ); + itkNewMacro(Self); + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) + return NULL; + + FloatLookupTable lut; + for( TiXmlElement* child = element->FirstChildElement("LUTValue"); child != NULL; child = child->NextSiblingElement("LUTValue")) + { + + int tempID; + if (child->QueryIntAttribute("id", &tempID) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + FloatLookupTable::IdentifierType id = static_cast(tempID); + float tempVal; + if (child->QueryFloatAttribute("value", &tempVal) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + FloatLookupTable::ValueType val = static_cast(tempVal); + lut.SetTableValue(id, val); + } + return FloatLookupTableProperty::New(lut).GetPointer(); + } + protected: + FloatLookupTablePropertyDeserializer() {} + virtual ~FloatLookupTablePropertyDeserializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(FloatLookupTablePropertyDeserializer); +#endif Index: Modules/SceneSerialization/BasePropertyDeserializer/mitkIntLookupTablePropertyDeserializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertyDeserializer/mitkIntLookupTablePropertyDeserializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertyDeserializer/mitkIntLookupTablePropertyDeserializer.cpp (revision 0) @@ -0,0 +1,63 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:07:40 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkIntLookupTablePropertyDeserializer_h_included +#define mitkIntLookupTablePropertyDeserializer_h_included + +#include "mitkBasePropertyDeserializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT IntLookupTablePropertyDeserializer : public BasePropertyDeserializer +{ + public: + + mitkClassMacro( IntLookupTablePropertyDeserializer, BasePropertyDeserializer ); + itkNewMacro(Self); + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) + return NULL; + + IntLookupTable lut; + for( TiXmlElement* child = element->FirstChildElement("LUTValue"); child != NULL; child = child->NextSiblingElement("LUTValue")) + { + + int temp; + if (child->QueryIntAttribute("id", &temp) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + IntLookupTable::IdentifierType id = static_cast(temp); + if (child->QueryIntAttribute("value", &temp) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + IntLookupTable::ValueType val = static_cast(temp); + lut.SetTableValue(id, val); + } + return IntLookupTableProperty::New(lut).GetPointer(); + } + protected: + IntLookupTablePropertyDeserializer() {} + virtual ~IntLookupTablePropertyDeserializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(IntLookupTablePropertyDeserializer); +#endif Index: Modules/SceneSerialization/BasePropertyDeserializer/mitkStringLookupTablePropertyDeserializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertyDeserializer/mitkStringLookupTablePropertyDeserializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertyDeserializer/mitkStringLookupTablePropertyDeserializer.cpp (revision 0) @@ -0,0 +1,64 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:07:40 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkStringLookupTablePropertyDeserializer_h_included +#define mitkStringLookupTablePropertyDeserializer_h_included + +#include "mitkBasePropertyDeserializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT StringLookupTablePropertyDeserializer : public BasePropertyDeserializer +{ + public: + + mitkClassMacro( StringLookupTablePropertyDeserializer, BasePropertyDeserializer ); + itkNewMacro(Self); + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) + return NULL; + + StringLookupTable lut; + for( TiXmlElement* child = element->FirstChildElement("LUTValue"); child != NULL; child = child->NextSiblingElement("LUTValue")) + { + + int temp; + if (child->QueryIntAttribute("id", &temp) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + StringLookupTable::IdentifierType id = static_cast(temp); + + if (child->Attribute("value") == NULL) + return NULL; // TODO: can we do a better error handling? + StringLookupTable::ValueType val = child->Attribute("value"); + lut.SetTableValue(id, val); + } + return StringLookupTableProperty::New(lut).GetPointer(); + } + protected: + StringLookupTablePropertyDeserializer() {} + virtual ~StringLookupTablePropertyDeserializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(StringLookupTablePropertyDeserializer); +#endif Index: Modules/SceneSerialization/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp (revision 0) @@ -0,0 +1,66 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:10:12 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkBoolLookupTablePropertySerializer_h_included +#define mitkBoolLookupTablePropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT BoolLookupTablePropertySerializer : public BasePropertySerializer +{ + public: + + mitkClassMacro( BoolLookupTablePropertySerializer, BasePropertySerializer ); + itkNewMacro(Self); + + virtual TiXmlElement* Serialize() + { + const BoolLookupTableProperty* prop = dynamic_cast(m_Property.GetPointer()); + if (prop == NULL) + return NULL; + BoolLookupTable& lut = prop->GetValue(); + //if (lut.IsNull()) + // return NULL; // really? + const BoolLookupTable::LookupTableType& map = lut.GetLookupTable(); + + TiXmlElement* element = new TiXmlElement("BoolLookupTable"); + for (BoolLookupTable::LookupTableType::const_iterator it = map.begin(); it != map.end(); ++it) + { + TiXmlElement* tableEntry = new TiXmlElement("LUTValue"); + tableEntry->SetAttribute("id", it->first); + if (it->second == true) + tableEntry->SetAttribute("value", "true"); + else + tableEntry->SetAttribute("value", "false"); + element->LinkEndChild( tableEntry ); + } + return element; + } + protected: + BoolLookupTablePropertySerializer() {} + virtual ~BoolLookupTablePropertySerializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(BoolLookupTablePropertySerializer); +#endif Index: Modules/SceneSerialization/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp (revision 0) @@ -0,0 +1,63 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:10:12 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkFloatLookupTablePropertySerializer_h_included +#define mitkFloatLookupTablePropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT FloatLookupTablePropertySerializer : public BasePropertySerializer +{ + public: + + mitkClassMacro( FloatLookupTablePropertySerializer, BasePropertySerializer ); + itkNewMacro(Self); + + virtual TiXmlElement* Serialize() + { + const FloatLookupTableProperty* prop = dynamic_cast(m_Property.GetPointer()); + if (prop == NULL) + return NULL; + FloatLookupTable& lut = prop->GetValue(); + //if (lut.IsNull()) + // return NULL; // really? + const FloatLookupTable::LookupTableType& map = lut.GetLookupTable(); + + TiXmlElement* element = new TiXmlElement("FloatLookupTableTable"); + for (FloatLookupTable::LookupTableType::const_iterator it = map.begin(); it != map.end(); ++it) + { + TiXmlElement* tableEntry = new TiXmlElement("LUTValue"); + tableEntry->SetAttribute("id", it->first); + tableEntry->SetDoubleAttribute("value", static_cast(it->second)); + element->LinkEndChild( tableEntry ); + } + return element; + } + protected: + FloatLookupTablePropertySerializer() {} + virtual ~FloatLookupTablePropertySerializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(FloatLookupTablePropertySerializer); +#endif Index: Modules/SceneSerialization/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp (revision 0) @@ -0,0 +1,63 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:10:12 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkIntLookupTablePropertySerializer_h_included +#define mitkIntLookupTablePropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT IntLookupTablePropertySerializer : public BasePropertySerializer +{ + public: + + mitkClassMacro( IntLookupTablePropertySerializer, BasePropertySerializer ); + itkNewMacro(Self); + + virtual TiXmlElement* Serialize() + { + const IntLookupTableProperty* prop = dynamic_cast(m_Property.GetPointer()); + if (prop == NULL) + return NULL; + IntLookupTable& lut = prop->GetValue(); + //if (lut.IsNull()) + // return NULL; // really? + const IntLookupTable::LookupTableType& map = lut.GetLookupTable(); + + TiXmlElement* element = new TiXmlElement("IntLookupTableTable"); + for (IntLookupTable::LookupTableType::const_iterator it = map.begin(); it != map.end(); ++it) + { + TiXmlElement* tableEntry = new TiXmlElement("LUTValue"); + tableEntry->SetAttribute("id", it->first); + tableEntry->SetAttribute("value", it->second); + element->LinkEndChild( tableEntry ); + } + return element; + } + protected: + IntLookupTablePropertySerializer() {} + virtual ~IntLookupTablePropertySerializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(IntLookupTablePropertySerializer); +#endif Index: Modules/SceneSerialization/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp =================================================================== --- Modules/SceneSerialization/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp (revision 0) +++ Modules/SceneSerialization/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp (revision 0) @@ -0,0 +1,63 @@ +/*========================================================================= + +Program: Medical Imaging & LookupTableeraction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date: 2009-10-08 17:10:12 +0200 (Do, 08. Okt 2009) $ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkFloatLookupTablePropertySerializer_h_included +#define mitkFloatLookupTablePropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkProperties.h" + +namespace mitk +{ + +class SceneSerialization_EXPORT FloatLookupTablePropertySerializer : public BasePropertySerializer +{ + public: + + mitkClassMacro( FloatLookupTablePropertySerializer, BasePropertySerializer ); + itkNewMacro(Self); + + virtual TiXmlElement* Serialize() + { + const FloatLookupTableProperty* prop = dynamic_cast(m_Property.GetPointer()); + if (prop == NULL) + return NULL; + FloatLookupTable& lut = prop->GetValue(); + //if (lut.IsNull()) + // return NULL; // really? + const FloatLookupTable::LookupTableType& map = lut.GetLookupTable(); + + TiXmlElement* element = new TiXmlElement("FloatLookupTableTable"); + for (FloatLookupTable::LookupTableType::const_iterator it = map.begin(); it != map.end(); ++it) + { + TiXmlElement* tableEntry = new TiXmlElement("LUTValue"); + tableEntry->SetAttribute("id", it->first); + tableEntry->SetAttribute("value", it->second); + element->LinkEndChild( tableEntry ); + } + return element; + } + protected: + FloatLookupTablePropertySerializer() {} + virtual ~FloatLookupTablePropertySerializer() {} +}; +} // namespace +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(FloatLookupTablePropertySerializer); +#endif Index: Modules/SceneSerialization/mitkPropertyListSerializer.cpp =================================================================== --- Modules/SceneSerialization/mitkPropertyListSerializer.cpp (revision 19499) +++ Modules/SceneSerialization/mitkPropertyListSerializer.cpp (working copy) @@ -109,19 +109,19 @@ std::string serializername(property->GetNameOfClass()); serializername += "Serializer"; - std::list thingsThatCanSerializeThis = itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str()); - if (thingsThatCanSerializeThis.size() < 1) + std::list allSerializers = itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str()); + if (allSerializers.size() < 1) { LOG_ERROR << "No serializer found for " << property->GetNameOfClass() << ". Skipping object"; m_FailedProperties->ReplaceProperty( key, const_cast(property) ); } - if (thingsThatCanSerializeThis.size() > 1) + if (allSerializers.size() > 1) { - LOG_ERROR << "Multiple serializers found for " << property->GetNameOfClass() << "Using arbitrary first one."; + LOG_WARN << "Multiple serializers found for " << property->GetNameOfClass() << "Using arbitrarily the first one."; } - for ( std::list::iterator iter = thingsThatCanSerializeThis.begin(); - iter != thingsThatCanSerializeThis.end(); + for ( std::list::iterator iter = allSerializers.begin(); + iter != allSerializers.end(); ++iter ) { if (BasePropertySerializer* serializer = dynamic_cast( iter->GetPointer() ) ) @@ -133,6 +133,7 @@ if (valueelement) { keyelement->LinkEndChild( valueelement ); + // \TODO: put 'return keyelement;' here? } else { @@ -143,11 +144,11 @@ { LOG_ERROR << "Serializer " << serializer->GetNameOfClass() << " failed: " << e.what(); m_FailedProperties->ReplaceProperty( key, const_cast(property) ); + // \TODO: log only if all potential serializers fail? } break; } } - return keyelement; } Index: Modules/SceneSerialization/Testing/files.cmake =================================================================== --- Modules/SceneSerialization/Testing/files.cmake (revision 19499) +++ Modules/SceneSerialization/Testing/files.cmake (working copy) @@ -1,5 +1,6 @@ SET(MODULE_TESTS + mitkPropertySerializationTest.cpp mitkSceneIOTest.cpp ) Index: Modules/SceneSerialization/Testing/mitkPropertySerializationTest.cpp =================================================================== --- Modules/SceneSerialization/Testing/mitkPropertySerializationTest.cpp (revision 0) +++ Modules/SceneSerialization/Testing/mitkPropertySerializationTest.cpp (revision 0) @@ -0,0 +1,276 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile: mitkPropertyManager.cpp,v $ +Language: C++ +Date: $Date$ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkTestingMacros.h" + +#include "mitkDataTreeNodeFactory.h" +#include "mitkCoreObjectFactory.h" + +#include "mitkBaseProperty.h" +#include "mitkProperties.h" +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mitkPropertyList.h" +#include "mitkBasePropertySerializer.h" +#include "mitkBasePropertyDeserializer.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include + + +void TestAllProperties(const mitk::PropertyList* propList); + +/**Documentation +* \brief Test for all PropertySerializer and PropertyDeserializer classes. +* +*/ +int mitkPropertySerializationTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("PropertySerializationTest"); + + itk::ObjectFactoryBase::RegisterFactory(mitk::CoreObjectFactory::New()); + + + /* build list of properties that will be serialized and deserialized */ + mitk::PropertyList::Pointer propList = mitk::PropertyList::New(); + propList->SetProperty("bool", mitk::BoolProperty::New(true)); + propList->SetProperty("int", mitk::IntProperty::New(-32)); + propList->SetProperty("float", mitk::FloatProperty::New(-31.337)); + propList->SetProperty("double", mitk::DoubleProperty::New(-31.337)); + propList->SetProperty("string", mitk::StringProperty::New("Hello MITK")); + mitk::Point3D p3d; + mitk::FillVector3D(p3d, 1.0, 2.2, -3.3); + propList->SetProperty("p3d", mitk::Point3dProperty::New(p3d)); + mitk::Point3I p3i; + mitk::FillVector3D(p3i, 1, 2, -3); + propList->SetProperty("p3i", mitk::Point3iProperty::New(p3i)); + mitk::Point4D p4d; + mitk::FillVector4D(p4d, 1.5, 2.6, -3.7, 4.44); + propList->SetProperty("p4d", mitk::Point4dProperty::New(p4d)); + mitk::Vector3D v3d; + mitk::FillVector3D(v3d, 1.0, 2.2, -3.3); + propList->SetProperty("v3d", mitk::Vector3DProperty::New(v3d)); + propList->SetProperty("annotation", mitk::AnnotationProperty::New("My Annotation", p3d)); + propList->SetProperty("clipping", mitk::ClippingProperty::New(p3d, v3d)); + propList->SetProperty("color", mitk::ColorProperty::New(1.0, 0.2, 0.2)); + mitk::EnumerationProperty::Pointer en = mitk::EnumerationProperty::New(); + en->AddEnum("PC", 1); en->AddEnum("Playstation", 2); en->AddEnum("Wii", 111); en->AddEnum("XBox", 7); + en->SetValue("XBox"); + propList->SetProperty("enum", en); + propList->SetProperty("gridrep", mitk::GridRepresentationProperty::New(2)); + propList->SetProperty("gridvol", mitk::GridVolumeMapperProperty::New(0)); + propList->SetProperty("modality", mitk::ModalityProperty::New("Color Doppler")); + //propList->SetProperty("OdfNormalizationMethodProperty", mitk::OdfNormalizationMethodProperty::New("Global Maximum")); + //propList->SetProperty("OdfScaleByProperty", mitk::OdfScaleByProperty::New("Principal Curvature")); + propList->SetProperty("OrganTypeProperty", mitk::OrganTypeProperty::New("Larynx")); + propList->SetProperty("PlaneDecorationProperty", mitk::PlaneDecorationProperty::New("Arrows in positive direction")); + propList->SetProperty("ShaderEnumProperty", mitk::ShaderEnumProperty::New("fixed")); + propList->SetProperty("VtkInterpolationProperty", mitk::VtkInterpolationProperty::New("Gouraud")); + propList->SetProperty("VtkRepresentationProperty", mitk::VtkRepresentationProperty::New("Surface")); + propList->SetProperty("VtkResliceInterpolationProperty", mitk::VtkResliceInterpolationProperty::New("Cubic")); + propList->SetProperty("VtkScalarModeProperty", mitk::VtkScalarModeProperty::New("PointFieldData")); + propList->SetProperty("VtkVolumeRenderingProperty", mitk::VtkVolumeRenderingProperty::New("COMPOSITE")); + mitk::BoolLookupTable blt; + blt.SetTableValue(0, true); blt.SetTableValue(1, false); blt.SetTableValue(2, true); + propList->SetProperty("BoolLookupTableProperty", mitk::BoolLookupTableProperty::New(blt)); + mitk::FloatLookupTable flt; + flt.SetTableValue(0, 3.1); flt.SetTableValue(1, 3.3); flt.SetTableValue(2, 7.0); + propList->SetProperty("FloatLookupTableProperty", mitk::FloatLookupTableProperty::New(flt)); + mitk::IntLookupTable ilt; + ilt.SetTableValue(0, 3); ilt.SetTableValue(1, 2); ilt.SetTableValue(2, 11); + propList->SetProperty("IntLookupTableProperty", mitk::IntLookupTableProperty::New(ilt)); + mitk::StringLookupTable slt; + slt.SetTableValue(0, "Hello"); slt.SetTableValue(1, "MITK"); slt.SetTableValue(2, "world"); + propList->SetProperty("StringLookupTableProperty", mitk::StringLookupTableProperty::New(slt)); + propList->SetProperty("GroupTagProperty", mitk::GroupTagProperty::New()); + propList->SetProperty("LevelWindowProperty", mitk::LevelWindowProperty::New(mitk::LevelWindow(100.0, 50.0))); + mitk::LookupTable::Pointer lt = mitk::LookupTable::New(); + lt->ChangeOpacityForAll(0.25); + lt->ChangeOpacity(17, 0.88); + propList->SetProperty("LookupTableProperty", mitk::LookupTableProperty::New(lt)); + propList->SetProperty("StringProperty", mitk::StringProperty::New("Oh why, gruel world")); + propList->SetProperty("DelegateProperty", mitk::DelegateProperty::New("Do it!")); + mitk::TransferFunction::Pointer tf = mitk::TransferFunction::New(); + tf->SetTransferFunctionMode(1); + propList->SetProperty("TransferFunctionProperty", mitk::TransferFunctionProperty::New(tf)); + + + MITK_TEST_CONDITION_REQUIRED(propList->GetMap()->size() > 0, "Initialize PropertyList"); + + TestAllProperties(propList); + + /* test default property lists of basedata objects */ + mitk::DataTreeNode::Pointer node = mitk::DataTreeNode::New(); + node->SetData(mitk::Contour::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::ContourSet::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::PointData::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::PointSet::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Mesh::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Image::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Surface::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Cone::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Cuboid::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Cylinder::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Ellipsoid::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::ExtrudedContour::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::Plane::New()); + TestAllProperties(node->GetPropertyList()); + //node->SetData(mitk::TrackingVolume::New()); // TrackingVolume is in IGT Module, it does not have special properties, therefore we skip it here + //TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::UnstructuredGrid::New()); + TestAllProperties(node->GetPropertyList()); + node->SetData(mitk::VtkWidgetRendering::New()); + TestAllProperties(node->GetPropertyList()); + + +/* not tested: + BaseDataImplementation + ColoredRectangleRendering + mitk::DiffusionVolumes< TPixelType > + GeometryData + mitk::Geometry2DData + GradientBackground + ItkBaseDataAdapter + LogoRendering + SlicedData + QBallImage + SeedsImage + TensorImage + BoundingObject + BoundingObjectGroup + */ + + MITK_TEST_END(); +} + +void TestAllProperties(const mitk::PropertyList* propList) +{ + assert(propList); + + /* try to serialize each property in the list, then deserialize again and check for equality */ + for (mitk::PropertyList::PropertyMap::const_iterator it = propList->GetMap()->begin(); it != propList->GetMap()->end(); ++it) + { + const mitk::BaseProperty* prop = it->second.first; + // construct name of serializer class + std::string serializername = std::string(prop->GetNameOfClass()) + "Serializer"; + std::list allSerializers = itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str()); + MITK_TEST_CONDITION(allSerializers.size() > 0, std::string("Creating serializers for ") + serializername); + if (allSerializers.size() == 0) + { + MITK_TEST_OUTPUT( << "serialization not possible, skipping " << prop->GetNameOfClass()); + continue; + } + if (allSerializers.size() > 1) + { + MITK_TEST_OUTPUT (<< "Warning: " << allSerializers.size() << " serializers found for " << prop->GetNameOfClass() << "testing only the first one."); + } + mitk::BasePropertySerializer* serializer = dynamic_cast( allSerializers.begin()->GetPointer()); + MITK_TEST_CONDITION(serializer != NULL, serializername + std::string(" is valid")); + if (serializer != NULL) + { + serializer->SetProperty(prop); + TiXmlElement* valueelement = NULL; + try + { + valueelement = serializer->Serialize(); + } + catch (...) + { + } + MITK_TEST_CONDITION(valueelement != NULL, std::string("Serialize property with ") + serializername); + + if (valueelement == NULL) + { + MITK_TEST_OUTPUT( << "serialization failed, skipping deserialization"); + continue; + } + /* build deserializer and try to deserialize property */ + std::string deserializerName = std::string(prop->GetNameOfClass()) + std::string("Deserializer"); + std::list allDeserializers = itk::ObjectFactoryBase::CreateAllInstance(deserializerName.c_str()); + MITK_TEST_CONDITION(allDeserializers.size() > 0, std::string("Creating deserializers for ") + deserializerName); + if (allDeserializers.size() == 0) + { + MITK_TEST_OUTPUT( << "deserialization not possible, skipping deserialization of " << prop->GetNameOfClass()); + continue; + } + if (allDeserializers.size() > 1) + { + MITK_TEST_OUTPUT (<< "Warning: " << allDeserializers.size() << " deserializers found for " << prop->GetNameOfClass() << "testing only the first one."); + } + mitk::BasePropertyDeserializer* deserializer = dynamic_cast( allDeserializers.begin()->GetPointer()); + MITK_TEST_CONDITION(deserializer != NULL, deserializerName + std::string(" is valid")); + if (deserializer != NULL) + { + mitk::BaseProperty::Pointer deserializedProp = deserializer->Deserialize( valueelement ); + MITK_TEST_CONDITION(deserializedProp.IsNotNull(), "deserializer created valid property"); + if (deserializedProp.IsNotNull()) + { + MITK_TEST_CONDITION(*(deserializedProp.GetPointer()) == *prop, "deserialized property equals initial property for type " << prop->GetNameOfClass()); + } + } + } + } // for all properties +}