diff --git a/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.cpp b/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.cpp index f997a425de..ab0c53167e 100644 --- a/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.cpp +++ b/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.cpp @@ -1,101 +1,100 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:31:16 +0200 (Di, 12 Mai 2009) $ Version: $Revision: $ 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 "mitkOdfNormalizationMethodProperty.h" // ODFN_MINMAX, ODFN_MAX, ODFN_NONE ODFN_GLOBAL_MAX mitk::OdfNormalizationMethodProperty::OdfNormalizationMethodProperty( ) { this->AddInterpolationTypes(); this->SetValue( static_cast( ODFN_MINMAX ) ); } mitk::OdfNormalizationMethodProperty::OdfNormalizationMethodProperty( const IdType& value ) { this->AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else { this->SetValue( static_cast( ODFN_MINMAX ) ); } } mitk::OdfNormalizationMethodProperty::OdfNormalizationMethodProperty( const std::string& value ) { this->AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else { this->SetValue( static_cast( ODFN_MINMAX ) ); } } int mitk::OdfNormalizationMethodProperty::GetNormalization() { return static_cast( this->GetValueAsId() ); } void mitk::OdfNormalizationMethodProperty::SetNormalizationToMinMax() { this->SetValue( static_cast( ODFN_MINMAX ) ); } void mitk::OdfNormalizationMethodProperty::SetNormalizationToMax() { this->SetValue( static_cast( ODFN_MAX ) ); } void mitk::OdfNormalizationMethodProperty::SetNormalizationToNone() { this->SetValue( static_cast( ODFN_NONE ) ); } void mitk::OdfNormalizationMethodProperty::SetNormalizationToGlobalMax() { this->SetValue( static_cast( ODFN_GLOBAL_MAX ) ); } void mitk::OdfNormalizationMethodProperty::AddInterpolationTypes() { AddEnum( "Min-Max", static_cast( ODFN_MINMAX ) ); AddEnum( "Maximum", static_cast( ODFN_MAX ) ); AddEnum( "None", static_cast( ODFN_NONE ) ); AddEnum( "Global Maximum", static_cast( ODFN_GLOBAL_MAX ) ); } bool mitk::OdfNormalizationMethodProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } MITK_REGISTER_SERIALIZER( OdfNormalizationMethodPropertySerializer ) -MITK_REGISTER_SERIALIZER( OdfNormalizationMethodPropertyDeserializer ) diff --git a/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.h b/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.h index 296222b138..aa3eae0b93 100644 --- a/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.h +++ b/Modules/DiffusionImaging/Rendering/mitkOdfNormalizationMethodProperty.h @@ -1,153 +1,136 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:31:16 +0200 (Di, 12 Mai 2009) $ Version: $Revision: $ 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 _MITK_OdfNormalizationMethodProperty__H_ #define _MITK_OdfNormalizationMethodProperty__H_ #include "mitkEnumerationProperty.h" #include "mitkEnumerationPropertySerializer.h" #include "MitkDiffusionImagingExports.h" -#include "mitkBasePropertyDeserializer.h" -#include "mitkBasePropertySerializer.h" - #include "mitkSerializerMacros.h" namespace mitk { enum OdfNormalizationMethod { ODFN_MINMAX, ODFN_MAX, ODFN_NONE, ODFN_GLOBAL_MAX }; /** * Encapsulates the enumeration for ODF normalization. Valid values are * ODFN_MINMAX, ODFN_MAX, ODFN_NONE ODFN_GLOBAL_MAX * Default is ODFN_MINMAX */ class MitkDiffusionImaging_EXPORT OdfNormalizationMethodProperty : public EnumerationProperty { public: mitkClassMacro( OdfNormalizationMethodProperty, EnumerationProperty ); itkNewMacro(OdfNormalizationMethodProperty); mitkNewMacro1Param(OdfNormalizationMethodProperty, const IdType&); mitkNewMacro1Param(OdfNormalizationMethodProperty, const std::string&); /** * Returns the current interpolation value as defined by VTK constants. */ virtual int GetNormalization(); /** * Sets the interpolation type to ODFN_MINMAX. */ virtual void SetNormalizationToMinMax(); /** * Sets the interpolation type to ODFN_MAX. */ virtual void SetNormalizationToMax(); /** * Sets the interpolation type to ODFN_NONE. */ virtual void SetNormalizationToNone(); /** * Sets the interpolation type to ODFN_GLOBAL_MAX. */ virtual void SetNormalizationToGlobalMax(); protected: /** Sets reslice interpolation mode to default (VTK_RESLICE_NEAREST). */ OdfNormalizationMethodProperty( ); /** * Constructor. Sets reslice interpolation to the given value. */ OdfNormalizationMethodProperty( const IdType& value ); /** * Constructor. Sets reslice interpolation to the given value. */ OdfNormalizationMethodProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid interpolation types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddInterpolationTypes(); }; -class MitkDiffusionImaging_EXPORT OdfNormalizationMethodPropertyDeserializer : public BasePropertyDeserializer +class MitkDiffusionImaging_EXPORT OdfNormalizationMethodPropertySerializer : public EnumerationPropertySerializer { public: - mitkClassMacro( OdfNormalizationMethodPropertyDeserializer, BasePropertyDeserializer ); + mitkClassMacro( OdfNormalizationMethodPropertySerializer, EnumerationPropertySerializer ); itkNewMacro(Self); virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) { if (!element) return NULL; const char* sa( element->Attribute("value") ); std::string s(sa?sa:""); OdfNormalizationMethodProperty::Pointer property = OdfNormalizationMethodProperty::New(); property->SetValue( s ); return property.GetPointer(); } - - protected: - - OdfNormalizationMethodPropertyDeserializer () {} - virtual ~OdfNormalizationMethodPropertyDeserializer () {} -}; - -class MitkDiffusionImaging_EXPORT OdfNormalizationMethodPropertySerializer : public EnumerationPropertySerializer -{ - public: - - mitkClassMacro( OdfNormalizationMethodPropertySerializer, EnumerationPropertySerializer ); - itkNewMacro(Self); - protected: OdfNormalizationMethodPropertySerializer () {} virtual ~OdfNormalizationMethodPropertySerializer () {} }; } // end of namespace mitk #endif diff --git a/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.cpp b/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.cpp index 172bcd76f5..b117b9134f 100644 --- a/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.cpp +++ b/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.cpp @@ -1,89 +1,88 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:31:16 +0200 (Di, 12 Mai 2009) $ Version: $Revision: $ 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 "mitkOdfScaleByProperty.h" // ODFN_NONE, ODFN_GFA, ODFN_PC mitk::OdfScaleByProperty::OdfScaleByProperty( ) { this->AddInterpolationTypes(); this->SetValue( static_cast( ODFSB_NONE ) ); } mitk::OdfScaleByProperty::OdfScaleByProperty( const IdType& value ) { this->AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ) ; } else { this->SetValue( static_cast( ODFSB_NONE ) ); } } mitk::OdfScaleByProperty::OdfScaleByProperty( const std::string& value ) { this->AddInterpolationTypes(); if ( IsValidEnumerationValue( value ) ) { this->SetValue( value ); } else { this->SetValue( static_cast( ODFSB_NONE ) ); } } int mitk::OdfScaleByProperty::GetScaleBy() { return static_cast( this->GetValueAsId() ); } void mitk::OdfScaleByProperty::AddInterpolationTypes() { AddEnum( "None", static_cast( ODFSB_NONE ) ); AddEnum( "GFA", static_cast( ODFSB_GFA ) ); AddEnum( "Principal Curvature", static_cast( ODFSB_PC ) ); } void mitk::OdfScaleByProperty::SetScaleByNothing() { SetValue(ODFSB_NONE); } void mitk::OdfScaleByProperty::SetScaleByGFA() { SetValue(ODFSB_GFA); } void mitk::OdfScaleByProperty::SetScaleByPrincipalCurvature() { SetValue(ODFSB_PC); } bool mitk::OdfScaleByProperty::AddEnum( const std::string& name, const IdType& id ) { return Superclass::AddEnum( name, id ); } MITK_REGISTER_SERIALIZER( OdfScaleByPropertySerializer ) -MITK_REGISTER_SERIALIZER( OdfScaleByPropertyDeserializer ) diff --git a/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.h b/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.h index 985cee527d..f49211cf6d 100644 --- a/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.h +++ b/Modules/DiffusionImaging/Rendering/mitkOdfScaleByProperty.h @@ -1,133 +1,116 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:31:16 +0200 (Di, 12 Mai 2009) $ Version: $Revision: $ 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 _MITK_OdfScaleByProperty__H_ #define _MITK_OdfScaleByProperty__H_ #include "MitkDiffusionImagingExports.h" #include "mitkEnumerationProperty.h" #include "mitkEnumerationPropertySerializer.h" -#include "mitkBasePropertyDeserializer.h" -#include "mitkBasePropertySerializer.h" - namespace mitk { enum OdfScaleBy { ODFSB_NONE, ODFSB_GFA, ODFSB_PC }; /** * Encapsulates the enumeration for ODF normalization. Valid values are * ODFSB_NONE, ODFSB_GFA, ODFSB_PC * Default is ODFSB_NONE */ class MitkDiffusionImaging_EXPORT OdfScaleByProperty : public EnumerationProperty { public: mitkClassMacro( OdfScaleByProperty, EnumerationProperty ); itkNewMacro(OdfScaleByProperty); mitkNewMacro1Param(OdfScaleByProperty, const IdType&); mitkNewMacro1Param(OdfScaleByProperty, const std::string&); /** * Returns the current interpolation value as defined by VTK constants. */ virtual int GetScaleBy(); virtual void SetScaleByNothing(); virtual void SetScaleByGFA(); virtual void SetScaleByPrincipalCurvature(); protected: /** Sets reslice interpolation mode to default (ODFSB_NONE). */ OdfScaleByProperty( ); /** * Constructor. Sets reslice interpolation to the given value. */ OdfScaleByProperty( const IdType& value ); /** * Constructor. Sets reslice interpolation to the given value. */ OdfScaleByProperty( const std::string& value ); /** * this function is overridden as protected, so that the user may not add * additional invalid interpolation types. */ virtual bool AddEnum( const std::string& name, const IdType& id ); /** * Adds the enumeration types as defined by vtk to the list of known * enumeration values. */ virtual void AddInterpolationTypes(); }; -class MitkDiffusionImaging_EXPORT OdfScaleByPropertyDeserializer : public BasePropertyDeserializer +class MitkDiffusionImaging_EXPORT OdfScaleByPropertySerializer : public EnumerationPropertySerializer { public: - mitkClassMacro( OdfScaleByPropertyDeserializer, BasePropertyDeserializer ); + mitkClassMacro( OdfScaleByPropertySerializer, EnumerationPropertySerializer ); itkNewMacro(Self); virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) { if (!element) return NULL; const char* sa( element->Attribute("value") ); std::string s(sa?sa:""); OdfScaleByProperty::Pointer property = OdfScaleByProperty::New(); property->SetValue( s ); return property.GetPointer(); } - - protected: - - OdfScaleByPropertyDeserializer () {} - virtual ~OdfScaleByPropertyDeserializer () {} -}; - -class MitkDiffusionImaging_EXPORT OdfScaleByPropertySerializer : public EnumerationPropertySerializer -{ - public: - - mitkClassMacro( OdfScaleByPropertySerializer, EnumerationPropertySerializer ); - itkNewMacro(Self); - protected: OdfScaleByPropertySerializer () {} virtual ~OdfScaleByPropertySerializer () {} }; } // end of namespace mitk #endif diff --git a/Modules/PlanarFigure/IO/mitkPlanarFigureReader.cpp b/Modules/PlanarFigure/IO/mitkPlanarFigureReader.cpp index 267770d1bb..83a88751a8 100644 --- a/Modules/PlanarFigure/IO/mitkPlanarFigureReader.cpp +++ b/Modules/PlanarFigure/IO/mitkPlanarFigureReader.cpp @@ -1,426 +1,426 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-06-17 14:15:34 +0200 (Mi, 17. Jun 2009) $ Version: $Revision: 17745 $ 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 "mitkPlanarFigureReader.h" #include "mitkPlanarAngle.h" #include "mitkPlanarCircle.h" #include "mitkPlanarLine.h" #include "mitkPlanarArrow.h" #include "mitkPlanarCross.h" #include "mitkPlanarFourPointAngle.h" #include "mitkPlanarPolygon.h" #include "mitkPlanarRectangle.h" #include "mitkPlaneGeometry.h" -#include "mitkBasePropertyDeserializer.h" +#include "mitkBasePropertySerializer.h" #include #include mitk::PlanarFigureReader::PlanarFigureReader() : PlanarFigureSource(), FileReader(), m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false) { this->SetNumberOfRequiredOutputs(1); this->SetNumberOfOutputs(1); this->SetNthOutput(0, this->MakeOutput(0)); m_CanReadFromMemory = true; //this->Modified(); //this->GetOutput()->Modified(); //this->GetOutput()->ReleaseData(); } mitk::PlanarFigureReader::~PlanarFigureReader() {} mitk::PlanarFigureSource::DataObjectPointer mitk::PlanarFigureReader::MakeOutput ( unsigned int ) { return static_cast(PlanarCircle::New().GetPointer()); // just as a stand in for the pipeline update mechanism. This will be overwritten in GenerateData() } void mitk::PlanarFigureReader::GenerateData() { m_Success = false; this->SetNumberOfOutputs(0); // reset all outputs, we add new ones depending on the file content TiXmlDocument document; if(m_ReadFromMemory) { if(m_MemoryBuffer == NULL || m_MemorySize == 0) { //check itkWarningMacro( << "Sorry, memory buffer has not been set!" ); return; } if(m_MemoryBuffer[ m_MemorySize - 1 ] == '\0') { document.Parse(m_MemoryBuffer); } else { char * tmpArray = new char[(int)m_MemorySize+1]; tmpArray[m_MemorySize] = '\0'; memcpy(tmpArray,m_MemoryBuffer,m_MemorySize); document.Parse(m_MemoryBuffer); delete [] tmpArray; } } else { if (m_FileName.empty()) { itkWarningMacro( << "Sorry, filename has not been set!" ); return; } if (this->CanReadFile( m_FileName.c_str()) == false) { itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" ); return; } if (!document.LoadFile(m_FileName)) { MITK_ERROR << "Could not open/read/parse " << m_FileName << ". TinyXML reports: '" << document.ErrorDesc() << "'. " << "The error occurred in row " << document.ErrorRow() << ", column " << document.ErrorCol() << "."; return; } } int fileVersion = 1; TiXmlElement* versionObject = document.FirstChildElement("Version"); if (versionObject != NULL) { if ( versionObject->QueryIntAttribute( "FileVersion", &fileVersion ) != TIXML_SUCCESS ) { MITK_WARN << m_FileName << " does not contain version information! Trying version 1 format." << std::endl; } } else { MITK_WARN << m_FileName << " does not contain version information! Trying version 1 format." << std::endl; } if (fileVersion != 1) // add file version selection and version specific file parsing here, if newer file versions are created { MITK_WARN << "File version > 1 is not supported by this reader."; return; } /* file version 1 reader code */ for( TiXmlElement* pfElement = document.FirstChildElement("PlanarFigure"); pfElement != NULL; pfElement = pfElement->NextSiblingElement("PlanarFigure") ) { if (pfElement == NULL) continue; std::string type = pfElement->Attribute("type"); mitk::PlanarFigure::Pointer planarFigure = NULL; if (type == "PlanarAngle") { planarFigure = mitk::PlanarAngle::New(); } else if (type == "PlanarCircle") { planarFigure = mitk::PlanarCircle::New(); } else if (type == "PlanarCross") { planarFigure = mitk::PlanarCross::New(); } else if (type == "PlanarFourPointAngle") { planarFigure = mitk::PlanarFourPointAngle::New(); } else if (type == "PlanarLine") { planarFigure = mitk::PlanarLine::New(); } else if (type == "PlanarPolygon") { planarFigure = mitk::PlanarPolygon::New(); } else if (type == "PlanarRectangle") { planarFigure = mitk::PlanarRectangle::New(); } else if (type == "PlanarArrow") { planarFigure = mitk::PlanarArrow::New(); } else { // unknown type MITK_WARN << "encountered unknown planar figure type '" << type << "'. Skipping this element."; continue; } // Read properties of the planar figure for( TiXmlElement* propertyElement = pfElement->FirstChildElement("property"); propertyElement != NULL; propertyElement = propertyElement->NextSiblingElement("property") ) { const char* keya = propertyElement->Attribute("key"); std::string key( keya ? keya : ""); const char* typea = propertyElement->Attribute("type"); std::string type( typea ? typea : ""); // hand propertyElement to specific reader std::stringstream propertyDeserializerClassName; - propertyDeserializerClassName << type << "Deserializer"; + propertyDeserializerClassName << type << "Serializer"; std::list readers = itk::ObjectFactoryBase::CreateAllInstance(propertyDeserializerClassName.str().c_str()); if (readers.size() < 1) { MITK_ERROR << "No property reader found for " << type; } if (readers.size() > 1) { MITK_WARN << "Multiple property readers found for " << type << ". Using arbitrary first one."; } for ( std::list::iterator iter = readers.begin(); iter != readers.end(); ++iter ) { - if (BasePropertyDeserializer* reader = dynamic_cast( iter->GetPointer() ) ) + if (BasePropertySerializer* reader = dynamic_cast( iter->GetPointer() ) ) { BaseProperty::Pointer property = reader->Deserialize( propertyElement->FirstChildElement() ); if (property.IsNotNull()) { planarFigure->GetPropertyList()->ReplaceProperty(key, property); } else { MITK_ERROR << "There were errors while loading property '" << key << "' of type " << type << ". Your data may be corrupted"; } break; } } } // Read geometry of containing plane TiXmlElement* geoElement = pfElement->FirstChildElement("Geometry"); if (geoElement != NULL) { try { // Create plane geometry mitk::PlaneGeometry::Pointer planeGeo = mitk::PlaneGeometry::New(); // Extract and set plane transform parameters DoubleList transformList = this->GetDoubleAttributeListFromXMLNode( geoElement->FirstChildElement( "transformParam" ), "param", 12 ); typedef mitk::AffineGeometryFrame3D::TransformType TransformType; TransformType::ParametersType parameters; parameters.SetSize( 12 ); unsigned int i; DoubleList::iterator it; for ( it = transformList.begin(), i = 0; it != transformList.end(); ++it, ++i ) { parameters.SetElement( i, *it ); } typedef mitk::AffineGeometryFrame3D::TransformType TransformType; TransformType::Pointer affineGeometry = TransformType::New(); affineGeometry->SetParameters( parameters ); planeGeo->SetIndexToWorldTransform( affineGeometry ); // Extract and set plane bounds DoubleList boundsList = this->GetDoubleAttributeListFromXMLNode( geoElement->FirstChildElement( "boundsParam" ), "bound", 6 ); typedef mitk::Geometry3D::BoundsArrayType BoundsArrayType; BoundsArrayType bounds; for ( it = boundsList.begin(), i = 0; it != boundsList.end(); ++it, ++i ) { bounds[i] = *it; } planeGeo->SetBounds( bounds ); // Extract and set spacing and origin Vector3D spacing = this->GetVectorFromXMLNode(geoElement->FirstChildElement("Spacing")); planeGeo->SetSpacing( spacing ); Point3D origin = this->GetPointFromXMLNode(geoElement->FirstChildElement("Origin")); planeGeo->SetOrigin( origin ); planarFigure->SetGeometry2D(planeGeo); } catch (...) { } } TiXmlElement* cpElement = pfElement->FirstChildElement("ControlPoints"); bool first = true; if (cpElement != NULL) for( TiXmlElement* vertElement = cpElement->FirstChildElement("Vertex"); vertElement != NULL; vertElement = vertElement->NextSiblingElement("Vertex")) { if (vertElement == NULL) continue; int id = 0; mitk::Point2D::ValueType x = 0.0; mitk::Point2D::ValueType y = 0.0; if (vertElement->QueryIntAttribute("id", &id) == TIXML_WRONG_TYPE) return; // TODO: can we do a better error handling? if (vertElement->QueryFloatAttribute("x", &x) == TIXML_WRONG_TYPE) return; // TODO: can we do a better error handling? if (vertElement->QueryFloatAttribute("y", &y) == TIXML_WRONG_TYPE) return; // TODO: can we do a better error handling? Point2D p; p.SetElement(0, x); p.SetElement(1, y); if (first == true) // needed to set m_FigurePlaced to true { planarFigure->PlaceFigure(p); first = false; } planarFigure->SetControlPoint(id, p, true); } // Calculate feature quantities of this PlanarFigure planarFigure->EvaluateFeatures(); // Make sure that no control point is currently selected planarFigure->DeselectControlPoint(); // \TODO: what about m_FigurePlaced and m_SelectedControlPoint ?? this->SetNthOutput( this->GetNumberOfOutputs(), planarFigure ); // add planarFigure as new output of this filter } m_Success = true; } mitk::Point3D mitk::PlanarFigureReader::GetPointFromXMLNode(TiXmlElement* e) { if (e == NULL) throw std::invalid_argument("node invalid"); // TODO: can we do a better error handling? mitk::Point3D point; mitk::ScalarType p(-1.0); if (e->QueryFloatAttribute("x", &p) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? point.SetElement(0, p); if (e->QueryFloatAttribute("y", &p) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? point.SetElement(1, p); if (e->QueryFloatAttribute("z", &p) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? point.SetElement(2, p); return point; } mitk::Vector3D mitk::PlanarFigureReader::GetVectorFromXMLNode(TiXmlElement* e) { if (e == NULL) throw std::invalid_argument("node invalid"); // TODO: can we do a better error handling? mitk::Vector3D vector; mitk::ScalarType p(-1.0); if (e->QueryFloatAttribute("x", &p) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? vector.SetElement(0, p); if (e->QueryFloatAttribute("y", &p) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? vector.SetElement(1, p); if (e->QueryFloatAttribute("z", &p) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? vector.SetElement(2, p); return vector; } mitk::PlanarFigureReader::DoubleList mitk::PlanarFigureReader::GetDoubleAttributeListFromXMLNode(TiXmlElement* e, const char *attributeNameBase, unsigned int count) { DoubleList list; if (e == NULL) throw std::invalid_argument("node invalid"); // TODO: can we do a better error handling? for ( unsigned int i = 0; i < count; ++i ) { mitk::ScalarType p(-1.0); std::stringstream attributeName; attributeName << attributeNameBase << i; if (e->QueryFloatAttribute( attributeName.str().c_str(), &p ) == TIXML_WRONG_TYPE) throw std::invalid_argument("node malformatted"); // TODO: can we do a better error handling? list.push_back( p ); } return list; } void mitk::PlanarFigureReader::GenerateOutputInformation() { } int mitk::PlanarFigureReader::CanReadFile ( const char *name ) { if (std::string(name).empty()) return false; return (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(name)) == ".pf"); //assume, we can read all .pf files //TiXmlDocument document(name); //if (document.LoadFile() == false) // return false; //return (document.FirstChildElement("PlanarFigure") != NULL); } bool mitk::PlanarFigureReader::CanReadFile(const std::string filename, const std::string, const std::string) { if (filename.empty()) return false; return (itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameLastExtension(filename)) == ".pf"); //assume, we can read all .pf files //TiXmlDocument document(filename); //if (document.LoadFile() == false) // return false; //return (document.FirstChildElement("PlanarFigure") != NULL); } void mitk::PlanarFigureReader::ResizeOutputs( const unsigned int& num ) { unsigned int prevNum = this->GetNumberOfOutputs(); this->SetNumberOfOutputs( num ); for ( unsigned int i = prevNum; i < num; ++i ) { this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() ); } } diff --git a/Modules/QmitkExt/QmitkTransferFunctionGeneratorWidget.cpp b/Modules/QmitkExt/QmitkTransferFunctionGeneratorWidget.cpp index ad82c5d3f3..db98b5b8f8 100644 --- a/Modules/QmitkExt/QmitkTransferFunctionGeneratorWidget.cpp +++ b/Modules/QmitkExt/QmitkTransferFunctionGeneratorWidget.cpp @@ -1,510 +1,509 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ 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 "QmitkTransferFunctionGeneratorWidget.h" #include #include #include #include #include #include #include -#include #include QmitkTransferFunctionGeneratorWidget::QmitkTransferFunctionGeneratorWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f), deltaScale(1.0), deltaMax(1024), deltaMin(1) { histoGramm = NULL; this->setupUi(this); // LevelWindow Tab { connect( m_CrossLevelWindow, SIGNAL( SignalDeltaMove( int, int ) ), this, SLOT( OnDeltaLevelWindow( int, int ) ) ); } // Threshold Tab { connect( m_CrossThreshold, SIGNAL( SignalDeltaMove( int, int ) ), this, SLOT( OnDeltaThreshold( int, int ) ) ); thDelta = 100; } // Presets Tab { m_TransferFunctionComboBox->setVisible(false); connect( m_TransferFunctionComboBox, SIGNAL( activated( int ) ), this, SIGNAL(SignalTransferFunctionModeChanged(int)) ); connect( m_TransferFunctionComboBox, SIGNAL( activated( int ) ), this, SLOT(OnPreset(int)) ); connect( m_SavePreset, SIGNAL( clicked() ), this, SLOT( OnSavePreset() ) ); connect( m_LoadPreset, SIGNAL( clicked() ), this, SLOT( OnLoadPreset() ) ); } presetFileName = "."; } int QmitkTransferFunctionGeneratorWidget::AddPreset(const QString &presetName) { m_TransferFunctionComboBox->setVisible(true); m_TransferFunctionComboBox->addItem( presetName); return m_TransferFunctionComboBox->count()-1; } void QmitkTransferFunctionGeneratorWidget::SetPresetsTabEnabled(bool enable) { m_PresetTab->setEnabled(enable); } void QmitkTransferFunctionGeneratorWidget::SetThresholdTabEnabled(bool enable) { m_ThresholdTab->setEnabled(enable); } void QmitkTransferFunctionGeneratorWidget::SetBellTabEnabled(bool enable) { m_BellTab->setEnabled(enable); } void QmitkTransferFunctionGeneratorWidget::OnSavePreset( ) { if(tfpToChange.IsNull()) return; mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); std::string fileName; std::string fileNameOutput; presetFileName = QFileDialog::getSaveFileName( this,"Choose a filename to save the transferfunction",presetFileName, "Transferfunction (*.xml)" ); fileName=presetFileName.toLocal8Bit().constData(); MITK_INFO << "Saving Transferfunction under path: " << fileName; fileNameOutput= ReduceFileName(fileName); if ( mitk::TransferFunctionPropertySerializer::SerializeTransferFunction( fileName.c_str(), tf )) m_InfoPreset->setText( QString( (std::string("saved ")+ fileNameOutput).c_str() ) ); else m_InfoPreset->setText( QString( std::string("saving failed").c_str() ) ); /* FILE *f=fopen("c:\\temp.txt","w"); // grayvalue -> opacity { mitk::TransferFunction::ControlPoints scalarOpacityPoints = tf->GetScalarOpacityPoints(); fprintf(f,"// grayvalue->opacity \n" "{\n" " vtkPiecewiseFunction *f=tf->GetScalarOpacityFunction();\n" " f->RemoveAllPoints();\n"); for ( mitk::TransferFunction::ControlPoints::iterator iter = scalarOpacityPoints.begin(); iter != scalarOpacityPoints.end(); ++iter ) fprintf(f," f->AddPoint(%f,%f);\n",iter->first, iter->second); fprintf(f," f->Modified();\n" "}\n"); } // gradient { mitk::TransferFunction::ControlPoints gradientOpacityPoints = tf->GetGradientOpacityPoints(); fprintf(f,"// gradient at grayvalue->opacity \n" "{\n" " vtkPiecewiseFunction *f=tf->GetGradientOpacityFunction();\n" " f->RemoveAllPoints();\n"); for ( mitk::TransferFunction::ControlPoints::iterator iter = gradientOpacityPoints.begin(); iter != gradientOpacityPoints.end(); ++iter ) fprintf(f," f->AddPoint(%f,%f);\n",iter->first, iter->second); fprintf(f," f->Modified();\n" "}\n"); } // color { mitk::TransferFunction::RGBControlPoints points = tf->GetRGBPoints(); fprintf(f,"// grayvalue->color \n" "{\n" " vtkColorTransferFunction *f=tf->GetColorTransferFunction();\n" " f->RemoveAllPoints();\n"); for ( mitk::TransferFunction::RGBControlPoints::iterator iter = points.begin(); iter != points.end(); ++iter ) fprintf(f," f->AddRGBPoint(%f,%f,%f,%f);\n",iter->first, iter->second[0], iter->second[1], iter->second[2]); fprintf(f," f->Modified();\n" "}\n"); } fclose(f); MITK_INFO << "saved under C:\\temp.txt"; */ } void QmitkTransferFunctionGeneratorWidget::OnLoadPreset( ) { if(tfpToChange.IsNull()) return; std::string fileName; std::string fileNameOutput; presetFileName = QFileDialog::getOpenFileName( this,"Choose a file to open the transferfunction from",presetFileName, "Transferfunction (*.xml)" ); fileName=presetFileName.toLocal8Bit().constData(); MITK_INFO << "Loading Transferfunction from path: " << fileName; fileNameOutput= ReduceFileName(fileName); - mitk::TransferFunction::Pointer tf = mitk::TransferFunctionPropertyDeserializer::DeserializeTransferFunction(fileName.c_str()); + mitk::TransferFunction::Pointer tf = mitk::TransferFunctionPropertySerializer::DeserializeTransferFunction(fileName.c_str()); if(tf.IsNotNull()) { /* if( histoGramm ) tf->InitializeByItkHistogram( histoGramm ); */ tfpToChange->SetValue( tf ); m_InfoPreset->setText( QString( (std::string("loaded ")+ fileNameOutput).c_str() ) ); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalUpdateCanvas(); /* vtkFloatingPointType* dp = tf->GetScalarOpacityFunction()->GetDataPointer(); for (int i = 0; i < tf->GetScalarOpacityFunction()->GetSize(); i++) { MITK_INFO << "x: " << dp[i * 2] << " y: " << dp[i * 2 + 1]; } */ } } void QmitkTransferFunctionGeneratorWidget::OnPreset(int mode) { //first item is only information if( --mode == -1 ) return; m_InfoPreset->setText(QString("selected ") + m_TransferFunctionComboBox->currentText()); //revert to first item m_TransferFunctionComboBox->setCurrentIndex( 0 ); } static double transformationGlocke ( double x ) { double z = 0.1; double a = 2 - 2 * z; double b = 2 * z - 1; x = a * x + b; return x; } static double stepFunctionGlocke ( double x ) { x = 1-(2*x -1.0); // map [0.5;1] to [0,1] x = x * ( 3*x - 2*x*x ); // apply smoothing function x = x * x; return x; } double QmitkTransferFunctionGeneratorWidget::ScaleDelta(int d) const { //MITK_INFO << "Scaling (int) " << d << "to (double) " << deltaScale*(double)d; return deltaScale*(double)d; } void QmitkTransferFunctionGeneratorWidget::OnDeltaLevelWindow(int dx, int dy) // bell { //std::string infoText; // m_InfoThreshold->setText( QString( x.c_str() ) ); if(tfpToChange.IsNull()) return; thPos += ScaleDelta(dx); thDelta -= ScaleDelta(dy); if(thDelta < deltaMin) thDelta = deltaMin; if(thDelta > deltaMax) thDelta = deltaMax; if(thPos < histoMinimum) thPos = histoMinimum; if(thPos > histoMaximum) thPos = histoMaximum; std::stringstream ss; ss << "Click on the cross and move the mouse"<<"\n" <<"\n" << "center at " << thPos << "\n" << "width " << thDelta * 2; m_InfoLevelWindow->setText( QString( ss.str().c_str() ) ); mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); // grayvalue->opacity { vtkPiecewiseFunction *f=tf->GetScalarOpacityFunction(); f->RemoveAllPoints(); for( int r = 0; r<= 6; r++) { double relPos = (r / 6.0) * 0.5 + 0.5; f->AddPoint(thPos+thDelta*(-transformationGlocke(relPos)),stepFunctionGlocke(relPos)); f->AddPoint(thPos+thDelta*( transformationGlocke(relPos)),stepFunctionGlocke(relPos)); } f->Modified(); } // gradient at grayvalue->opacity { vtkPiecewiseFunction *f=tf->GetGradientOpacityFunction(); f->RemoveAllPoints(); f->AddPoint( 0, 1.0 ); f->Modified(); } /* // grayvalue->color { vtkColorTransferFunction *ctf=tf->GetColorTransferFunction(); ctf->RemoveAllPoints(); ctf->AddRGBPoint( 0, 1.0, 1.0, 1.0 ); ctf->Modified(); } */ tf->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalUpdateCanvas(); } static double stepFunctionThreshold ( double x ) { x = 0.5*x + 0.5; // map [-1;1] to [0,1] x = x * ( 3*x - 2*x*x ); // apply smoothing function x = x * x; return x; } void QmitkTransferFunctionGeneratorWidget::OnDeltaThreshold(int dx, int dy) // LEVELWINDOW { if(tfpToChange.IsNull()) return; thPos += ScaleDelta(dx); thDelta += ScaleDelta(dy); if(thDelta < deltaMin) thDelta = deltaMin; if(thDelta > deltaMax) thDelta = deltaMax; if(thPos < histoMinimum) thPos = histoMinimum; if(thPos > histoMaximum) thPos = histoMaximum; //MITK_INFO << "threshold pos: " << thPos << " delta: " << thDelta; //MITK_INFO << "histoMinimum: " << histoMinimum << " max: " << histoMaximum; std::stringstream ss; ss << "Click on the cross and move the mouse"<<"\n" <<"\n" << "threshold at " << thPos << "\n" << "width " << thDelta * 2; m_InfoThreshold->setText( QString( ss.str().c_str() ) ); mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); // grayvalue->opacity { vtkPiecewiseFunction *f=tf->GetScalarOpacityFunction(); f->RemoveAllPoints(); for( int r = 1; r<= 4; r++) { double relPos = r / 4.0; f->AddPoint(thPos+thDelta*(-relPos),stepFunctionThreshold(-relPos)); f->AddPoint(thPos+thDelta*( relPos),stepFunctionThreshold( relPos)); } f->Modified(); } // gradient at grayvalue->opacity { vtkPiecewiseFunction *f=tf->GetGradientOpacityFunction(); f->RemoveAllPoints(); f->AddPoint( 0, 1.0 ); f->Modified(); } /* // grayvalue->color { vtkColorTransferFunction *ctf=tf->GetColorTransferFunction(); ctf->RemoveAllPoints(); ctf->AddRGBPoint( 0, 1.0, 1.0, 1.0 ); ctf->Modified(); } */ tf->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); emit SignalUpdateCanvas(); } std::string QmitkTransferFunctionGeneratorWidget::ReduceFileName(std::string fileNameLong ) { if (fileNameLong.length()< 40) return fileNameLong; //MITK_INFO <<" fileName > 20 "; std::string fileNameShort; std::string fileNameRevert; for(unsigned int i=0; i< fileNameLong.length(); i++) { if(i<3) { char x= fileNameLong[i]; fileNameShort= fileNameShort+x; } if(i==3) { fileNameShort= fileNameShort+"..."; break; } } //MITK_INFO <<" fileNameShort: " << fileNameShort.c_str(); unsigned int len( fileNameLong.length() ); for(unsigned int i=len-1; i <= len; i--) { std::string x=std::string("")+fileNameLong[i]; if ( x.compare("/")==0 || x.compare("\\")==0) { fileNameRevert= "/" + fileNameRevert; break; } if (i>=fileNameLong.length()-24) { fileNameRevert= x+ fileNameRevert; //MITK_INFO <<" fileNameRevert: " << fileNameRevert.c_str(); } else { fileNameRevert= "/..." + fileNameRevert; break; } } return fileNameShort+fileNameRevert; } QmitkTransferFunctionGeneratorWidget::~QmitkTransferFunctionGeneratorWidget() { } void QmitkTransferFunctionGeneratorWidget::SetDataNode(mitk::DataNode* node) { histoGramm = NULL; if (node) { tfpToChange = dynamic_cast(node->GetProperty("TransferFunction")); if(!tfpToChange) { node->SetProperty("TransferFunction", tfpToChange = mitk::TransferFunctionProperty::New() ); dynamic_cast(node->GetProperty("TransferFunction")); } mitk::TransferFunction::Pointer tf = tfpToChange->GetValue(); if( mitk::Image* image = dynamic_cast( node->GetData() ) ) { // tf->InitializeByItkHistogram( histoGramm = image->GetScalarHistogram() ); histoMinimum= image->GetScalarValueMin(); histoMaximum= image->GetScalarValueMax(); } else if (mitk::UnstructuredGrid* grid = dynamic_cast( node->GetData() ) ) { double* range = grid->GetVtkUnstructuredGrid()->GetScalarRange(); histoMinimum = range[0]; histoMaximum = range[1]; double histoRange = histoMaximum - histoMinimum; deltaMax = histoRange/4.0; deltaMin = histoRange/400.0; deltaScale = histoRange/1024.0; } else { MITK_WARN << "QmitkTransferFunctonGeneratorWidget does not support " << node->GetData()->GetNameOfClass() << " instances"; } thPos = ( histoMinimum + histoMaximum ) / 2.0; } else { tfpToChange = 0; m_InfoPreset->setText( QString( "" ) ); } } diff --git a/Modules/SceneSerialization/mitkPropertyListDeserializerV1.cpp b/Modules/SceneSerialization/mitkPropertyListDeserializerV1.cpp index ff7d924cf1..4115522559 100644 --- a/Modules/SceneSerialization/mitkPropertyListDeserializerV1.cpp +++ b/Modules/SceneSerialization/mitkPropertyListDeserializerV1.cpp @@ -1,91 +1,91 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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 "mitkSerializerMacros.h" #include "mitkPropertyListDeserializerV1.h" -#include "mitkBasePropertyDeserializer.h" +#include "mitkBasePropertySerializer.h" #include MITK_REGISTER_SERIALIZER(PropertyListDeserializerV1) mitk::PropertyListDeserializerV1::PropertyListDeserializerV1() { } mitk::PropertyListDeserializerV1::~PropertyListDeserializerV1() { } bool mitk::PropertyListDeserializerV1::Deserialize() { bool error(false); m_PropertyList = PropertyList::New(); TiXmlDocument document( m_Filename ); if (!document.LoadFile()) { MITK_ERROR << "Could not open/read/parse " << m_Filename << "\nTinyXML reports: " << document.ErrorDesc() << std::endl; return false; } for( TiXmlElement* propertyElement = document.FirstChildElement("property"); propertyElement != NULL; propertyElement = propertyElement->NextSiblingElement("property") ) { const char* keya = propertyElement->Attribute("key"); std::string key( keya ? keya : ""); const char* typea = propertyElement->Attribute("type"); std::string type( typea ? typea : ""); // hand propertyElement to specific reader std::stringstream propertyDeserializerClassName; - propertyDeserializerClassName << type << "Deserializer"; + propertyDeserializerClassName << type << "Serializer"; std::list readers = itk::ObjectFactoryBase::CreateAllInstance(propertyDeserializerClassName.str().c_str()); if (readers.size() < 1) { MITK_ERROR << "No property reader found for " << type; error = true; } if (readers.size() > 1) { MITK_WARN << "Multiple property readers found for " << type << ". Using arbitrary first one."; } for ( std::list::iterator iter = readers.begin(); iter != readers.end(); ++iter ) { - if (BasePropertyDeserializer* reader = dynamic_cast( iter->GetPointer() ) ) + if (BasePropertySerializer* reader = dynamic_cast( iter->GetPointer() ) ) { BaseProperty::Pointer property = reader->Deserialize( propertyElement->FirstChildElement() ); if (property.IsNotNull()) { m_PropertyList->ReplaceProperty(key, property); } else { MITK_ERROR << "There were errors while loding property '" << key << "' of type " << type << ". Your data may be corrupted"; error = true; } break; } } } return !error; } diff --git a/Modules/SceneSerialization/mitkSceneReaderV1.cpp b/Modules/SceneSerialization/mitkSceneReaderV1.cpp index c56442d031..41a1dfdf27 100644 --- a/Modules/SceneSerialization/mitkSceneReaderV1.cpp +++ b/Modules/SceneSerialization/mitkSceneReaderV1.cpp @@ -1,255 +1,255 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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 "mitkSceneReaderV1.h" #include "mitkSerializerMacros.h" #include "mitkDataNodeFactory.h" #include "mitkBaseRenderer.h" #include "mitkPropertyListDeserializer.h" #include "Poco/Path.h" MITK_REGISTER_SERIALIZER(SceneReaderV1) bool mitk::SceneReaderV1::LoadScene( TiXmlDocument& document, const std::string& workingDirectory, DataStorage* storage ) { assert(storage); bool error(false); // TODO prepare to detect errors (such as cycles) from wrongly written or edited xml files // iterate all nodes // first level nodes should be elements for( TiXmlElement* element = document.FirstChildElement("node"); element != NULL; element = element->NextSiblingElement("node") ) { // 1. if there is a element, - // - construct a name for the appropriate deserializer - // - try to instantiate this deserializer via itk object factory - // - if deserializer could be created, use it to read the file into a BaseData object + // - construct a name for the appropriate serializer + // - try to instantiate this serializer via itk object factory + // - if serializer could be created, use it to read the file into a BaseData object // - if successful, call the new node's SetData(..) DataNode::Pointer node = LoadBaseDataFromDataTag( element->FirstChildElement("data"), workingDirectory, error ); // 2. check child nodes const char* uida = element->Attribute("UID"); std::string uid(""); if (uida) { uid = uida; m_NodeForID[uid] = node.GetPointer(); m_IDForNode[ node.GetPointer() ] = uid; } else { MITK_ERROR << "No UID found for current node. Node will have no parents."; error = true; } // remember node for later adding to DataStorage m_Nodes.insert( std::make_pair( node, std::list() ) ); // 3. if there are elements, remember parent objects for( TiXmlElement* source = element->FirstChildElement("source"); source != NULL; source = source->NextSiblingElement("source") ) { const char* sourceUID = source->Attribute("UID"); if (sourceUID) { m_Nodes[node].push_back( std::string(sourceUID) ); } } // 5. if there are nodes, // - instantiate the appropriate PropertyListDeSerializer // - use them to construct PropertyList objects // - add these properties to the node (if necessary, use renderwindow name) bool success = DecorateNodeWithProperties(node, element, workingDirectory); if (!success) { MITK_ERROR << "Could not load properties for node."; error = true; } } // end for all // remove all unknown parent UIDs for (NodesAndParentsMapType::iterator nodesIter = m_Nodes.begin(); nodesIter != m_Nodes.end(); ++nodesIter) { for (std::list::iterator parentsIter = nodesIter->second.begin(); parentsIter != nodesIter->second.end();) { if (m_NodeForID.find( *parentsIter ) == m_NodeForID.end()) { parentsIter = nodesIter->second.erase( parentsIter ); MITK_WARN << "Found a DataNode with unknown parents. Will add it to DataStorage without any parent objects."; error = true; } else { ++parentsIter; } } } // repeat // for all created nodes unsigned int lastMapSize(0); while ( lastMapSize != m_Nodes.size()) // this is to prevent infinite loops; each iteration must at least add one node to DataStorage { lastMapSize = m_Nodes.size(); for (NodesAndParentsMapType::iterator nodesIter = m_Nodes.begin(); nodesIter != m_Nodes.end(); ++nodesIter) { bool addNow(true); // if any parent node is not yet in DataStorage, skip node for now and check later for (std::list::iterator parentsIter = nodesIter->second.begin(); parentsIter != nodesIter->second.end(); ++parentsIter) { if ( !storage->Exists( m_NodeForID[ *parentsIter ] ) ) { addNow = false; break; } } if (addNow) { DataStorage::SetOfObjects::Pointer parents = DataStorage::SetOfObjects::New(); for (std::list::iterator parentsIter = nodesIter->second.begin(); parentsIter != nodesIter->second.end(); ++parentsIter) { parents->push_back( m_NodeForID[ *parentsIter ] ); } // if all parents are found in datastorage (or are unknown), add node to DataStorage storage->Add( nodesIter->first, parents ); // remove this node from m_Nodes m_Nodes.erase( nodesIter ); // break this for loop because iterators are probably invalid break; } } } // All nodes that are still in m_Nodes at this point are not part of a proper directed graph structure. We'll add such nodes without any parent information. for (NodesAndParentsMapType::iterator nodesIter = m_Nodes.begin(); nodesIter != m_Nodes.end(); ++nodesIter) { storage->Add( nodesIter->first ); MITK_WARN << "Encountered node that is not part of a directed graph structure. Will be added to DataStorage without parents."; error = true; } return !error; } mitk::DataNode::Pointer mitk::SceneReaderV1::LoadBaseDataFromDataTag( TiXmlElement* dataElement, const std::string& workingDirectory, bool& error ) { DataNode::Pointer node; if (dataElement) { const char* filename( dataElement->Attribute("file") ); if ( filename ) { DataNodeFactory::Pointer factory = DataNodeFactory::New(); factory->SetFileName( workingDirectory + Poco::Path::separator() + filename ); try { factory->Update(); node = factory->GetOutput(); } catch (std::exception& e) { MITK_ERROR << "Error during attempt to read '" << filename << "'. Exception says: " << e.what(); error = true; } if (node.IsNull()) { MITK_ERROR << "Error during attempt to read '" << filename << "'. Factory returned NULL object."; error = true; } } } // in case there was no element we create a new empty node (for appending a propertylist later) if (node.IsNull()) { node = DataNode::New(); } return node; } bool mitk::SceneReaderV1::DecorateNodeWithProperties(DataNode* node, TiXmlElement* nodeElement, const std::string& workingDirectory) { assert(node); assert(nodeElement); bool error(false); for( TiXmlElement* properties = nodeElement->FirstChildElement("properties"); properties != NULL; properties = properties->NextSiblingElement("properties") ) { const char* propertiesfilea( properties->Attribute("file") ); std::string propertiesfile( propertiesfilea ? propertiesfilea : "" ); const char* renderwindowa( properties->Attribute("renderwindow") ); std::string renderwindow( renderwindowa ? renderwindowa : "" ); BaseRenderer* renderer = BaseRenderer::GetByName( renderwindow ); if (renderer || renderwindow.empty()) { PropertyList::Pointer propertyList = node->GetPropertyList(renderer); // DataNode implementation always returns a propertylist // clear all properties from node that might be set by DataNodeFactory during loading propertyList->Clear(); // use deserializer to construct new properties PropertyListDeserializer::Pointer deserializer = PropertyListDeserializer::New(); deserializer->SetFilename(workingDirectory + Poco::Path::separator() + propertiesfile); bool success = deserializer->Deserialize(); error |= !success; PropertyList::Pointer readProperties = deserializer->GetOutput(); if (readProperties.IsNotNull()) { propertyList->ConcatenatePropertyList( readProperties, true ); // true = replace } else { MITK_ERROR << "Property list reader did not return a property list. This is an implementation error. Please tell your developer."; error = true; } } else { MITK_ERROR << "Found properties for renderer " << renderwindow << " but there is no such renderer in current application. Ignoring those properties"; error = true; } } return !error; } diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkAnnotationPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkAnnotationPropertyDeserializer.cpp deleted file mode 100644 index b50ee1a413..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkAnnotationPropertyDeserializer.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date: 2009-10-08 16:58:56 +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 mitkAnnotationPropertyDeserializer_h_included -#define mitkAnnotationPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkAnnotationProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT AnnotationPropertyDeserializer : public BasePropertyDeserializer -{ - public: - mitkClassMacro( AnnotationPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - const char* label( element->Attribute("label") ); - Point3D p; - if ( element->QueryFloatAttribute( "x", &p[0] ) != TIXML_SUCCESS ) - return NULL; - if ( element->QueryFloatAttribute( "y", &p[1] ) != TIXML_SUCCESS ) - return NULL; - if ( element->QueryFloatAttribute( "z", &p[2] ) != TIXML_SUCCESS ) - return NULL; - return AnnotationProperty::New(label, p).GetPointer(); - } - protected: - AnnotationPropertyDeserializer() {} - virtual ~AnnotationPropertyDeserializer() {} -}; -} // namespace -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(AnnotationPropertyDeserializer); -#endif diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkBoolLookupTablePropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkBoolLookupTablePropertyDeserializer.cpp deleted file mode 100644 index 8456febef7..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkBoolLookupTablePropertyDeserializer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_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 - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkClippingPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkClippingPropertyDeserializer.cpp deleted file mode 100644 index 9c7cb617c8..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkClippingPropertyDeserializer.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date: 2009-10-08 16:58:56 +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 mitkClippingPropertyDeserializer_h_included -#define mitkClippingPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" -#include "mitkClippingProperty.h" -#include "mitkVector.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT ClippingPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( ClippingPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) - return NULL; - bool enabled = std::string(element->Attribute("enabled")) == "true"; - - TiXmlElement* originElement = element->FirstChildElement("origin"); - if (originElement == NULL) - return NULL; - Point3D origin; - if ( originElement->QueryFloatAttribute( "x", &origin[0] ) != TIXML_SUCCESS ) - return NULL; - if ( originElement->QueryFloatAttribute( "y", &origin[1] ) != TIXML_SUCCESS ) - return NULL; - if ( originElement->QueryFloatAttribute( "z", &origin[2] ) != TIXML_SUCCESS ) - return NULL; - TiXmlElement* normalElement = element->FirstChildElement("normal"); - if (normalElement == NULL) - return NULL; - Vector3D normal; - if ( normalElement->QueryFloatAttribute( "x", &normal[0] ) != TIXML_SUCCESS ) - return NULL; - if ( normalElement->QueryFloatAttribute( "y", &normal[1] ) != TIXML_SUCCESS ) - return NULL; - if ( normalElement->QueryFloatAttribute( "z", &normal[2] ) != TIXML_SUCCESS ) - return NULL; - ClippingProperty::Pointer cp = ClippingProperty::New(origin, normal); - cp->SetClippingEnabled(enabled); - return cp.GetPointer(); - } - protected: - ClippingPropertyDeserializer() {} - virtual ~ClippingPropertyDeserializer() {} -}; -} // namespace -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(ClippingPropertyDeserializer); -#endif diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkColorPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkColorPropertyDeserializer.cpp deleted file mode 100644 index 4c481a1ace..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkColorPropertyDeserializer.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkColorPropertyDeserializer_h_included -#define mitkColorPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkColorProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT ColorPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( ColorPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - Color c; - if ( element->QueryFloatAttribute( "r", &c[0] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "g", &c[1] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "b", &c[2] ) != TIXML_SUCCESS ) return NULL; - - return ColorProperty::New( c ).GetPointer(); - } - - protected: - - ColorPropertyDeserializer() {} - virtual ~ColorPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(ColorPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkDoublePropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkDoublePropertyDeserializer.cpp deleted file mode 100644 index 86d0a61635..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkDoublePropertyDeserializer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkDoublePropertyDeserializer_h_included -#define mitkDoublePropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT DoublePropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( DoublePropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - double d; - if ( element->QueryDoubleAttribute( "value", &d ) == TIXML_SUCCESS ) - { - return DoubleProperty::New(d).GetPointer(); - } - else - { - return NULL; - } - } - - protected: - - DoublePropertyDeserializer() {} - virtual ~DoublePropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(DoublePropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkEnumerationPropertySubclassesDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkEnumerationPropertySubclassesDeserializer.cpp deleted file mode 100644 index d612068281..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkEnumerationPropertySubclassesDeserializer.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -// TODO this should be moved to module SceneSerializationExt - -#ifndef mitkEnumerationSubclassesDeserializer_h_included -#define mitkEnumerationSubclassesDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -/* -#include "mitkGridRepresentationProperty.h" -#include "mitkGridVolumeMapperProperty.h" -#include "mitkOrganTypeProperty.h" -*/ -#include "mitkPlaneOrientationProperty.h" -#include "mitkShaderProperty.h" -#include "mitkVtkInterpolationProperty.h" -#include "mitkVtkRepresentationProperty.h" -#include "mitkVtkResliceInterpolationProperty.h" -#include "mitkVtkScalarModeProperty.h" -#include "mitkVtkVolumeRenderingProperty.h" -#include "mitkModalityProperty.h" - -#include "SceneSerializationBaseExports.h" - - -#define MITK_REGISTER_ENUM_SUB_DESERIALIZER(classname) \ - \ -namespace mitk \ -{ \ - \ -class SceneSerializationBase_EXPORT classname ## Deserializer : public BasePropertyDeserializer \ -{ \ - public: \ - \ - mitkClassMacro( classname ## Deserializer, BasePropertyDeserializer ); \ - itkNewMacro(Self); \ -\ - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) \ - { \ - if (!element) return NULL; \ - const char* sa( element->Attribute("value") ); \ - std::string s(sa?sa:""); \ - classname::Pointer property = classname::New(); \ - property->SetValue( s ); \ - return property.GetPointer(); \ - } \ - \ - \ - protected: \ - \ - classname ## Deserializer () {} \ - virtual ~classname ## Deserializer () {} \ -}; \ - \ -} \ - \ -MITK_REGISTER_SERIALIZER( classname ## Deserializer ); - -/* -MITK_REGISTER_ENUM_SUB_DESERIALIZER(GridRepresentationProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(GridVolumeMapperProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(OrganTypeProperty); -*/ -MITK_REGISTER_ENUM_SUB_DESERIALIZER(PlaneOrientationProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(ShaderProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(VtkInterpolationProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(VtkRepresentationProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(VtkResliceInterpolationProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(VtkScalarModeProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(VtkVolumeRenderingProperty); -MITK_REGISTER_ENUM_SUB_DESERIALIZER(ModalityProperty); -#endif diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkFloatLookupTablePropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkFloatLookupTablePropertyDeserializer.cpp deleted file mode 100644 index acbb098ec7..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkFloatLookupTablePropertyDeserializer.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_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 = -1.0; - 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 diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkFloatPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkFloatPropertyDeserializer.cpp deleted file mode 100644 index 1b12d55094..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkFloatPropertyDeserializer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkFloatPropertyDeserializer_h_included -#define mitkFloatPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT FloatPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( FloatPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - float f; - if ( element->QueryFloatAttribute( "value", &f ) == TIXML_SUCCESS ) - { - return FloatProperty::New(f).GetPointer(); - } - else - { - return NULL; - } - } - - protected: - - FloatPropertyDeserializer() {} - virtual ~FloatPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(FloatPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkGroupTagPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkGroupTagPropertyDeserializer.cpp deleted file mode 100644 index 6442ead2ba..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkGroupTagPropertyDeserializer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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 mitkGroupTagPropertyDeserializer_h_included -#define mitkGroupTagPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkGroupTagProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT GroupTagPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( GroupTagPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement*) - { - //if (!element) - // return NULL; - return GroupTagProperty::New().GetPointer(); - } - - protected: - GroupTagPropertyDeserializer() {} - virtual ~GroupTagPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(GroupTagPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkIntLookupTablePropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkIntLookupTablePropertyDeserializer.cpp deleted file mode 100644 index 9d46b2eaf1..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkIntLookupTablePropertyDeserializer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_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 diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkIntPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkIntPropertyDeserializer.cpp deleted file mode 100644 index fd3944c6e2..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkIntPropertyDeserializer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkIntPropertyDeserializer_h_included -#define mitkIntPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT IntPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( IntPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - int integer; - if ( element->QueryIntAttribute( "value", &integer ) == TIXML_SUCCESS ) - { - return IntProperty::New(integer).GetPointer(); - } - else - { - return NULL; - } - } - - protected: - - IntPropertyDeserializer() {} - virtual ~IntPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(IntPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkLevelWindowPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkLevelWindowPropertyDeserializer.cpp deleted file mode 100644 index 5f062d326f..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkLevelWindowPropertyDeserializer.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkLevelWindowPropertyDeserializer_h_included -#define mitkLevelWindowPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkLevelWindowProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT LevelWindowPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( LevelWindowPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - bool isFixed(false); - if (element->Attribute("fixed")) - isFixed = std::string(element->Attribute("fixed")) == "true"; - - float level; - float window; - TiXmlElement* child = element->FirstChildElement("CurrentSettings"); - if ( child->QueryFloatAttribute( "level", &level ) != TIXML_SUCCESS ) return NULL; - if ( child->QueryFloatAttribute( "window", &window ) != TIXML_SUCCESS ) return NULL; - - float defaultLevel; - float defaultWindow; - child = element->FirstChildElement("DefaultSettings"); - if ( child->QueryFloatAttribute( "level", &defaultLevel ) != TIXML_SUCCESS ) return NULL; - if ( child->QueryFloatAttribute( "window", &defaultWindow ) != TIXML_SUCCESS ) return NULL; - - float minRange; - float maxRange; - child = element->FirstChildElement("CurrentRange"); - if ( child->QueryFloatAttribute( "min", &minRange ) != TIXML_SUCCESS ) return NULL; - if ( child->QueryFloatAttribute( "max", &maxRange ) != TIXML_SUCCESS ) return NULL; - - - - LevelWindow lw; - lw.SetRangeMinMax( minRange, maxRange ); - lw.SetDefaultLevelWindow( defaultLevel, defaultWindow ); - lw.SetLevelWindow( level, window ); - lw.SetFixed( isFixed ); - - return LevelWindowProperty::New( lw ).GetPointer(); - } - - protected: - - LevelWindowPropertyDeserializer() {} - virtual ~LevelWindowPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(LevelWindowPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkLookupTablePropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkLookupTablePropertyDeserializer.cpp deleted file mode 100644 index 4b65827598..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkLookupTablePropertyDeserializer.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkLookupTablePropertyDeserializer_h_included -#define mitkLookupTablePropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkLookupTableProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT LookupTablePropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( LookupTablePropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - -#if ( (VTK_MAJOR_VERSION < 5) && (VTK_MINOR_VERSION < 4) ) - typedef float OUR_VTK_FLOAT_TYPE; - float range[2]; - float rgba[4]; -#else - typedef double OUR_VTK_FLOAT_TYPE; - double range[2]; - double rgba[4]; -#endif - - double d; // bec. of tinyXML's interface that takes a pointer to float or double... - - vtkLookupTable* lut = vtkLookupTable::New(); - - int numberOfColors; - int scale; - int ramp; // hope the int values don't change betw. vtk versions... - if ( element->QueryIntAttribute( "NumberOfColors", &numberOfColors ) == TIXML_SUCCESS ) - { - lut->SetNumberOfTableValues( numberOfColors ); - } - else - return NULL; - if ( element->QueryIntAttribute( "Scale", &scale ) == TIXML_SUCCESS ) - { - lut->SetScale( scale ); - } - else - return NULL; - if ( element->QueryIntAttribute( "Ramp", &ramp ) == TIXML_SUCCESS ) - { - lut->SetRamp( ramp ); - } - else - return NULL; - - TiXmlElement* child = element->FirstChildElement("HueRange"); - if (child) - { - if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) - return NULL; - range[0] = static_cast(d); - if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) - return NULL; - range[1] = static_cast(d); - lut->SetHueRange( range ); - } - - child = element->FirstChildElement("ValueRange"); - if (child) - { - if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); - if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); - lut->SetValueRange( range ); - } - - child = element->FirstChildElement("SaturationRange"); - if (child) - { - if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); - if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); - lut->SetSaturationRange( range ); - } - - child = element->FirstChildElement("AlphaRange"); - if (child) - { - if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); - if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); - lut->SetAlphaRange( range ); - } - - child = element->FirstChildElement("TableRange"); - if (child) - { - if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); - if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); - lut->SetTableRange( range ); - } - - child = element->FirstChildElement("Table"); - if (child) - { - unsigned int index(0); - for( TiXmlElement* grandChild = child->FirstChildElement("RgbaColor"); grandChild; grandChild = grandChild->NextSiblingElement("RgbaColor")) - { - if ( grandChild->QueryDoubleAttribute("R", &d) != TIXML_SUCCESS ) return NULL; rgba[0] = static_cast(d); - if ( grandChild->QueryDoubleAttribute("G", &d) != TIXML_SUCCESS ) return NULL; rgba[1] = static_cast(d); - if ( grandChild->QueryDoubleAttribute("B", &d) != TIXML_SUCCESS ) return NULL; rgba[2] = static_cast(d); - if ( grandChild->QueryDoubleAttribute("A", &d) != TIXML_SUCCESS ) return NULL; rgba[3] = static_cast(d); - - lut->SetTableValue( index, rgba ); - ++index; - } - } - - LookupTable::Pointer mitkLut = LookupTable::New(); - mitkLut->SetVtkLookupTable( lut ); - - lut->Delete(); - - return LookupTableProperty::New(mitkLut).GetPointer(); - } - - protected: - - LookupTablePropertyDeserializer() {} - virtual ~LookupTablePropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(LookupTablePropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint3dPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint3dPropertyDeserializer.cpp deleted file mode 100644 index e7a53ddb69..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint3dPropertyDeserializer.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkPoint3dPropertyDeserializer_h_included -#define mitkPoint3dPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT Point3dPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( Point3dPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - Point3D v; - if ( element->QueryFloatAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; - - return Point3dProperty::New( v ).GetPointer(); - } - - protected: - - Point3dPropertyDeserializer() {} - virtual ~Point3dPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(Point3dPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint3iPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint3iPropertyDeserializer.cpp deleted file mode 100644 index eb3d4b9806..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint3iPropertyDeserializer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date: 2009-10-08 16:58:56 +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 mitkPoint3iPropertyDeserializer_h_included -#define mitkPoint3iPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ -class SceneSerializationBase_EXPORT Point3iPropertyDeserializer : public BasePropertyDeserializer -{ - public: - mitkClassMacro( Point3iPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - Point3I v; - if ( element->QueryIntAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryIntAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryIntAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; - return Point3iProperty::New( v ).GetPointer(); - } - protected: - Point3iPropertyDeserializer() {} - virtual ~Point3iPropertyDeserializer() {} -}; -} // namespace -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(Point3iPropertyDeserializer); -#endif diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint4dPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint4dPropertyDeserializer.cpp deleted file mode 100644 index a2404e2347..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkPoint4dPropertyDeserializer.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkPoint4dPropertyDeserializer_h_included -#define mitkPoint4dPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT Point4dPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( Point4dPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - Point4D v; - if ( element->QueryFloatAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "t", &v[3] ) != TIXML_SUCCESS ) return NULL; - - return Point4dProperty::New( v ).GetPointer(); - } - - protected: - - Point4dPropertyDeserializer() {} - virtual ~Point4dPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(Point4dPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkStringLookupTablePropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkStringLookupTablePropertyDeserializer.cpp deleted file mode 100644 index e3f85aea7a..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkStringLookupTablePropertyDeserializer.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_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 diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkStringPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkStringPropertyDeserializer.cpp deleted file mode 100644 index 804d98cb99..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkStringPropertyDeserializer.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkStringPropertyDeserializer_h_included -#define mitkStringPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkStringProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT StringPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( StringPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - const char* s( element->Attribute("value") ); - return StringProperty::New( std::string(s?s:"") ).GetPointer(); - } - - protected: - - StringPropertyDeserializer() {} - virtual ~StringPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(StringPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkTransferFunctionPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkTransferFunctionPropertyDeserializer.cpp deleted file mode 100644 index 8fb56825e6..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkTransferFunctionPropertyDeserializer.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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 "mitkTransferFunctionPropertyDeserializer.h" - -namespace mitk { - -mitk::TransferFunctionPropertyDeserializer::TransferFunctionPropertyDeserializer() -{ -} - -mitk::TransferFunctionPropertyDeserializer::~TransferFunctionPropertyDeserializer() -{ -} - -BaseProperty::Pointer mitk::TransferFunctionPropertyDeserializer::Deserialize(TiXmlElement* element) -{ - if (!element) - return NULL; - - TransferFunction::Pointer tf = TransferFunction::New(); - - // deserialize scalar opacity function - TiXmlElement* scalarOpacityPointlist = element->FirstChildElement("ScalarOpacity"); - if (scalarOpacityPointlist == NULL) - return NULL; - - tf->ClearScalarOpacityPoints(); - - for( TiXmlElement* pointElement = scalarOpacityPointlist->FirstChildElement("point"); pointElement != NULL; pointElement = pointElement->NextSiblingElement("point")) - { - double x; - double y; - if (pointElement->QueryDoubleAttribute("x", &x) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("y", &y) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - tf->AddScalarOpacityPoint(x, y); - } - - TiXmlElement* gradientOpacityPointlist = element->FirstChildElement("GradientOpacity"); - if (gradientOpacityPointlist == NULL) - return NULL; - - tf->ClearGradientOpacityPoints(); - - for( TiXmlElement* pointElement = gradientOpacityPointlist->FirstChildElement("point"); pointElement != NULL; pointElement = pointElement->NextSiblingElement("point")) - { - double x; - double y; - if (pointElement->QueryDoubleAttribute("x", &x) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("y", &y) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - tf->AddGradientOpacityPoint(x, y); - } - - TiXmlElement* rgbPointlist = element->FirstChildElement("Color"); - if (rgbPointlist == NULL) - return NULL; - vtkColorTransferFunction* ctf = tf->GetColorTransferFunction(); - if (ctf == NULL) - return NULL; - - ctf->RemoveAllPoints(); - - for( TiXmlElement* pointElement = rgbPointlist->FirstChildElement("point"); pointElement != NULL; pointElement = pointElement->NextSiblingElement("point")) - { - double x; - double r,g,b, midpoint, sharpness; - if (pointElement->QueryDoubleAttribute("x", &x) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("r", &r) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("g", &g) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("b", &b) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("midpoint", &midpoint) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - if (pointElement->QueryDoubleAttribute("sharpness", &sharpness) == TIXML_WRONG_TYPE) - return NULL; // TODO: can we do a better error handling? - ctf->AddRGBPoint(x, r, g, b, midpoint, sharpness); - } - return TransferFunctionProperty::New(tf).GetPointer(); -} - -mitk::TransferFunction::Pointer mitk::TransferFunctionPropertyDeserializer::DeserializeTransferFunction( const char *filePath ) -{ - TiXmlDocument document( filePath ); - - if (!document.LoadFile()) - { - MITK_ERROR << "Could not open/read/parse " << filePath << "\nTinyXML reports: " << document.ErrorDesc() << std::endl; - return NULL; - } - - // find version node --> note version in some variable - int fileVersion = 1; - TiXmlElement* versionObject = document.FirstChildElement("Version"); - if (versionObject) - { - if ( versionObject->QueryIntAttribute( "TransferfunctionVersion", &fileVersion ) != TIXML_SUCCESS ) - { - MITK_WARN << "Transferfunction file " << filePath << " does not contain version information! Trying version 1 format."; - } - } - - TiXmlElement* input = document.FirstChildElement("TransferFunction"); - - TransferFunctionPropertyDeserializer::Pointer tfpd = TransferFunctionPropertyDeserializer::New(); - BaseProperty::Pointer bp = tfpd->Deserialize(input); - TransferFunctionProperty::Pointer tfp = dynamic_cast(bp.GetPointer()); - - if(tfp.IsNotNull()) - { - TransferFunction::Pointer tf = tfp->GetValue(); - return tf; - } - MITK_WARN << "Can't deserialize transferfunction"; - return NULL; -} -} // namespace -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(TransferFunctionPropertyDeserializer); diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkTransferFunctionPropertyDeserializer.h b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkTransferFunctionPropertyDeserializer.h deleted file mode 100644 index 4f9ee445f1..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkTransferFunctionPropertyDeserializer.h +++ /dev/null @@ -1,48 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date: 2009-10-23 11:12:48 +0200 (Fr, 23 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. - -=========================================================================*/ - -#include "mitkBasePropertyDeserializer.h" -#include "mitkTransferFunctionProperty.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - - class SceneSerializationBase_EXPORT TransferFunctionPropertyDeserializer : public BasePropertyDeserializer - { - public: - - mitkClassMacro( TransferFunctionPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element); - static TransferFunction::Pointer DeserializeTransferFunction( const char *filePath ); - - - protected: - - TransferFunctionPropertyDeserializer(); - virtual ~TransferFunctionPropertyDeserializer(); - }; - -} // namespace - - - - - diff --git a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkVector3DPropertyDeserializer.cpp b/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkVector3DPropertyDeserializer.cpp deleted file mode 100644 index 97518fc0a2..0000000000 --- a/Modules/SceneSerializationBase/BasePropertyDeserializer/mitkVector3DPropertyDeserializer.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkVector3dPropertyDeserializer_h_included -#define mitkVector3dPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT Vector3DPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( Vector3DPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - - Vector3D v; - if ( element->QueryFloatAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; - if ( element->QueryFloatAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; - - return Vector3DProperty::New( v ).GetPointer(); - } - - protected: - - Vector3DPropertyDeserializer() {} - virtual ~Vector3DPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(Vector3DPropertyDeserializer); - -#endif - diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkAnnotationPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkAnnotationPropertySerializer.cpp index 7e905a4ee5..b194ab11d2 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkAnnotationPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkAnnotationPropertySerializer.cpp @@ -1,64 +1,78 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-07 15:56:37 +0200 (Di, 07. Jul 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 mitkAnnotationPropertySerializer_h_included #define mitkAnnotationPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkAnnotationProperty.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT AnnotationPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( AnnotationPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const AnnotationProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("annotation"); element->SetAttribute("label", prop->GetLabel()); Point3D point = prop->GetPosition(); element->SetDoubleAttribute("x", point[0]); element->SetDoubleAttribute("y", point[1]); element->SetDoubleAttribute("z", point[2]); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + const char* label( element->Attribute("label") ); + Point3D p; + if ( element->QueryFloatAttribute( "x", &p[0] ) != TIXML_SUCCESS ) + return NULL; + if ( element->QueryFloatAttribute( "y", &p[1] ) != TIXML_SUCCESS ) + return NULL; + if ( element->QueryFloatAttribute( "z", &p[2] ) != TIXML_SUCCESS ) + return NULL; + return AnnotationProperty::New(label, p).GetPointer(); + } + protected: AnnotationPropertySerializer() {} virtual ~AnnotationPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(AnnotationPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp index d1d458a1bf..cf2a679403 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolLookupTablePropertySerializer.cpp @@ -1,67 +1,86 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_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; } + + 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: BoolLookupTablePropertySerializer() {} virtual ~BoolLookupTablePropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(BoolLookupTablePropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/mitkBoolPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolPropertySerializer.cpp similarity index 89% rename from Modules/SceneSerializationBase/mitkBoolPropertySerializer.cpp rename to Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolPropertySerializer.cpp index 67ec6d9ec3..cf782df281 100644 --- a/Modules/SceneSerializationBase/mitkBoolPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkBoolPropertySerializer.cpp @@ -1,67 +1,73 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkBoolPropertySerializer_h_included #define mitkBoolPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT BoolPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( BoolPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const BoolProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("bool"); if (prop->GetValue() == true) { element->SetAttribute("value", "true"); } else { element->SetAttribute("value", "false"); } return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + return BoolProperty::New( std::string(element->Attribute("value")) == "true" ).GetPointer(); + } + protected: BoolPropertySerializer() {} virtual ~BoolPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(BoolPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkClippingPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkClippingPropertySerializer.cpp index 52ca7ee473..e20f357d8d 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkClippingPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkClippingPropertySerializer.cpp @@ -1,69 +1,100 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-07 15:56:37 +0200 (Di, 07. Jul 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 mitkClippingPropertySerializer_h_included #define mitkClippingPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkClippingProperty.h" #include "mitkVector.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT ClippingPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( ClippingPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const ClippingProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("clipping"); if (prop->GetClippingEnabled()) element->SetAttribute("enabled", "true"); else element->SetAttribute("enabled", "false"); TiXmlElement* originElement = new TiXmlElement("origin"); const Point3D origin = prop->GetOrigin(); originElement->SetDoubleAttribute("x", origin[0]); originElement->SetDoubleAttribute("y", origin[1]); originElement->SetDoubleAttribute("z", origin[2]); element->LinkEndChild(originElement); TiXmlElement* normalElement = new TiXmlElement("normal"); const Vector3D normal = prop->GetNormal(); normalElement->SetDoubleAttribute("x", normal[0]); normalElement->SetDoubleAttribute("y", normal[1]); normalElement->SetDoubleAttribute("z", normal[2]); element->LinkEndChild(normalElement); return element; } else return NULL; } + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) + return NULL; + bool enabled = std::string(element->Attribute("enabled")) == "true"; + + TiXmlElement* originElement = element->FirstChildElement("origin"); + if (originElement == NULL) + return NULL; + Point3D origin; + if ( originElement->QueryFloatAttribute( "x", &origin[0] ) != TIXML_SUCCESS ) + return NULL; + if ( originElement->QueryFloatAttribute( "y", &origin[1] ) != TIXML_SUCCESS ) + return NULL; + if ( originElement->QueryFloatAttribute( "z", &origin[2] ) != TIXML_SUCCESS ) + return NULL; + TiXmlElement* normalElement = element->FirstChildElement("normal"); + if (normalElement == NULL) + return NULL; + Vector3D normal; + if ( normalElement->QueryFloatAttribute( "x", &normal[0] ) != TIXML_SUCCESS ) + return NULL; + if ( normalElement->QueryFloatAttribute( "y", &normal[1] ) != TIXML_SUCCESS ) + return NULL; + if ( normalElement->QueryFloatAttribute( "z", &normal[2] ) != TIXML_SUCCESS ) + return NULL; + ClippingProperty::Pointer cp = ClippingProperty::New(origin, normal); + cp->SetClippingEnabled(enabled); + return cp.GetPointer(); + } protected: ClippingPropertySerializer() {} virtual ~ClippingPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(ClippingPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkColorPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkColorPropertySerializer.cpp index bb6dd7256c..0084ddfa7b 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkColorPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkColorPropertySerializer.cpp @@ -1,63 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkColorPropertySerializer_h_included #define mitkColorPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkColorProperty.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT ColorPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( ColorPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const ColorProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("color"); Color color = prop->GetValue(); element->SetDoubleAttribute("r", color[0]); element->SetDoubleAttribute("g", color[1]); element->SetDoubleAttribute("b", color[2]); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + Color c; + if ( element->QueryFloatAttribute( "r", &c[0] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "g", &c[1] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "b", &c[2] ) != TIXML_SUCCESS ) return NULL; + + return ColorProperty::New( c ).GetPointer(); + } + protected: ColorPropertySerializer() {} virtual ~ColorPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(ColorPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkDoublePropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkDoublePropertySerializer.cpp index 164bbb2cc9..638e5da94f 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkDoublePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkDoublePropertySerializer.cpp @@ -1,60 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkDoublePropertySerializer_h_included #define mitkDoublePropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT DoublePropertySerializer : public BasePropertySerializer { public: mitkClassMacro( DoublePropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const DoubleProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("double"); element->SetDoubleAttribute("value", prop->GetValue()); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + double d; + if ( element->QueryDoubleAttribute( "value", &d ) == TIXML_SUCCESS ) + { + return DoubleProperty::New(d).GetPointer(); + } + else + { + return NULL; + } + } + protected: DoublePropertySerializer() {} virtual ~DoublePropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(DoublePropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkEnumerationSubclassesSerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkEnumerationSubclassesSerializer.cpp index ebf9bed27e..ccfa93f886 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkEnumerationSubclassesSerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkEnumerationSubclassesSerializer.cpp @@ -1,58 +1,76 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkEnumerationSubclassesSerializer_h_included #define mitkEnumerationSubclassesSerializer_h_included #include "mitkEnumerationPropertySerializer.h" +#include "mitkPlaneOrientationProperty.h" +#include "mitkShaderProperty.h" +#include "mitkVtkInterpolationProperty.h" +#include "mitkVtkRepresentationProperty.h" +#include "mitkVtkResliceInterpolationProperty.h" +#include "mitkVtkScalarModeProperty.h" +#include "mitkVtkVolumeRenderingProperty.h" +#include "mitkModalityProperty.h" + #define MITK_REGISTER_ENUM_SUB_SERIALIZER(classname) \ \ namespace mitk \ { \ \ class SceneSerializationBase_EXPORT classname ## Serializer : public EnumerationPropertySerializer \ { \ public: \ \ mitkClassMacro( classname ## Serializer, EnumerationPropertySerializer ); \ itkNewMacro(Self); \ + \ + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) \ + { \ + if (!element) return NULL; \ + const char* sa( element->Attribute("value") ); \ + \ + std::string s(sa?sa:""); \ + classname::Pointer property = classname::New(); \ + property->SetValue( s ); \ + \ + return property.GetPointer(); \ + } \ \ protected: \ \ classname ## Serializer () {} \ virtual ~classname ## Serializer () {} \ }; \ \ } \ \ MITK_REGISTER_SERIALIZER( classname ## Serializer ); -MITK_REGISTER_ENUM_SUB_SERIALIZER(GridRepresentationProperty); -MITK_REGISTER_ENUM_SUB_SERIALIZER(GridVolumeMapperProperty); -MITK_REGISTER_ENUM_SUB_SERIALIZER(OrganTypeProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(PlaneOrientationProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(ShaderProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(VtkInterpolationProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(VtkRepresentationProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(VtkResliceInterpolationProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(VtkScalarModeProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(VtkVolumeRenderingProperty); MITK_REGISTER_ENUM_SUB_SERIALIZER(ModalityProperty); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp index 2231ed86b9..eead55e782 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatLookupTablePropertySerializer.cpp @@ -1,64 +1,86 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_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; } + + 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 = -1.0; + 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: FloatLookupTablePropertySerializer() {} virtual ~FloatLookupTablePropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(FloatLookupTablePropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatPropertySerializer.cpp index 7e419eead1..8c25f346a6 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkFloatPropertySerializer.cpp @@ -1,60 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkFloatPropertySerializer_h_included #define mitkFloatPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT FloatPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( FloatPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const FloatProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("float"); element->SetDoubleAttribute("value", static_cast(prop->GetValue())); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + float f; + if ( element->QueryFloatAttribute( "value", &f ) == TIXML_SUCCESS ) + { + return FloatProperty::New(f).GetPointer(); + } + else + { + return NULL; + } + } + protected: FloatPropertySerializer() {} virtual ~FloatPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(FloatPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkGroupTagPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkGroupTagPropertySerializer.cpp index b10ad3de5a..9be9a05c77 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkGroupTagPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkGroupTagPropertySerializer.cpp @@ -1,59 +1,66 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-07 15:56:37 +0200 (Di, 07. Jul 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 mitkGroupTagPropertySerializer_h_included #define mitkGroupTagPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkGroupTagProperty.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT GroupTagPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( GroupTagPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (dynamic_cast(m_Property.GetPointer()) != NULL) { TiXmlElement* element = new TiXmlElement("GroupTag"); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement*) + { + //if (!element) + // return NULL; + return GroupTagProperty::New().GetPointer(); + } + protected: GroupTagPropertySerializer() {} virtual ~GroupTagPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(GroupTagPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp index 3bc3261126..80ef617aef 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntLookupTablePropertySerializer.cpp @@ -1,64 +1,85 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_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; } + + 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: IntLookupTablePropertySerializer() {} virtual ~IntLookupTablePropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(IntLookupTablePropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntPropertySerializer.cpp index 27c02a2aea..ba129c131b 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkIntPropertySerializer.cpp @@ -1,60 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkIntPropertySerializer_h_included #define mitkIntPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT IntPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( IntPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const IntProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("int"); element->SetAttribute("value", prop->GetValue()); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + int integer; + if ( element->QueryIntAttribute( "value", &integer ) == TIXML_SUCCESS ) + { + return IntProperty::New(integer).GetPointer(); + } + else + { + return NULL; + } + } + protected: IntPropertySerializer() {} virtual ~IntPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(IntPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkLevelWindowPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkLevelWindowPropertySerializer.cpp index 440edbe2df..4a45adb51d 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkLevelWindowPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkLevelWindowPropertySerializer.cpp @@ -1,82 +1,119 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkLevelWindowPropertySerializer_h_included #define mitkLevelWindowPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkLevelWindowProperty.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT LevelWindowPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( LevelWindowPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const LevelWindowProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("LevelWindow"); LevelWindow lw = prop->GetLevelWindow(); std::string boolString("false"); if (lw.IsFixed() == true) boolString = "true"; element->SetAttribute("fixed", boolString.c_str()); TiXmlElement* child = new TiXmlElement("CurrentSettings"); element->LinkEndChild( child ); child->SetDoubleAttribute("level", lw.GetLevel()); child->SetDoubleAttribute("window", lw.GetWindow()); child = new TiXmlElement("DefaultSettings"); element->LinkEndChild( child ); child->SetDoubleAttribute("level", lw.GetDefaultLevel()); child->SetDoubleAttribute("window", lw.GetDefaultWindow()); child = new TiXmlElement("CurrentRange"); element->LinkEndChild( child ); child->SetDoubleAttribute("min", lw.GetRangeMin()); child->SetDoubleAttribute("max", lw.GetRangeMax()); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + bool isFixed(false); + if (element->Attribute("fixed")) + isFixed = std::string(element->Attribute("fixed")) == "true"; + + float level; + float window; + TiXmlElement* child = element->FirstChildElement("CurrentSettings"); + if ( child->QueryFloatAttribute( "level", &level ) != TIXML_SUCCESS ) return NULL; + if ( child->QueryFloatAttribute( "window", &window ) != TIXML_SUCCESS ) return NULL; + + float defaultLevel; + float defaultWindow; + child = element->FirstChildElement("DefaultSettings"); + if ( child->QueryFloatAttribute( "level", &defaultLevel ) != TIXML_SUCCESS ) return NULL; + if ( child->QueryFloatAttribute( "window", &defaultWindow ) != TIXML_SUCCESS ) return NULL; + + float minRange; + float maxRange; + child = element->FirstChildElement("CurrentRange"); + if ( child->QueryFloatAttribute( "min", &minRange ) != TIXML_SUCCESS ) return NULL; + if ( child->QueryFloatAttribute( "max", &maxRange ) != TIXML_SUCCESS ) return NULL; + + + + LevelWindow lw; + lw.SetRangeMinMax( minRange, maxRange ); + lw.SetDefaultLevelWindow( defaultLevel, defaultWindow ); + lw.SetLevelWindow( level, window ); + lw.SetFixed( isFixed ); + + return LevelWindowProperty::New( lw ).GetPointer(); + } + protected: LevelWindowPropertySerializer() {} virtual ~LevelWindowPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(LevelWindowPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkLookupTablePropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkLookupTablePropertySerializer.cpp index 16b7acb1ab..e51ba4e5d8 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkLookupTablePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkLookupTablePropertySerializer.cpp @@ -1,120 +1,228 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkLookupTablePropertySerializer_h_included #define mitkLookupTablePropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkLookupTableProperty.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT LookupTablePropertySerializer : public BasePropertySerializer { public: mitkClassMacro( LookupTablePropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const LookupTableProperty* prop = dynamic_cast(m_Property.GetPointer())) { LookupTable::Pointer mitkLut = const_cast(prop)->GetLookupTable(); if (mitkLut.IsNull()) return NULL; // really? vtkLookupTable* lut = mitkLut->GetVtkLookupTable(); if (!lut) return NULL; TiXmlElement* element = new TiXmlElement("LookupTable"); #if ( (VTK_MAJOR_VERSION < 5) && (VTK_MINOR_VERSION < 4) ) float* range; float* rgba; #else double* range; double* rgba; #endif element->SetAttribute("NumberOfColors", lut->GetNumberOfTableValues()); element->SetAttribute("Scale", lut->GetScale()); element->SetAttribute("Ramp", lut->GetRamp()); range = lut->GetHueRange(); TiXmlElement* child = new TiXmlElement("HueRange"); element->LinkEndChild( child ); child->SetDoubleAttribute("min", range[0]); child->SetDoubleAttribute("max", range[1]); range = lut->GetValueRange(); child = new TiXmlElement("ValueRange"); element->LinkEndChild( child ); child->SetDoubleAttribute("min", range[0]); child->SetDoubleAttribute("max", range[1]); range = lut->GetSaturationRange(); child = new TiXmlElement("SaturationRange"); element->LinkEndChild( child ); child->SetDoubleAttribute("min", range[0]); child->SetDoubleAttribute("max", range[1]); range = lut->GetAlphaRange(); child = new TiXmlElement("AlphaRange"); element->LinkEndChild( child ); child->SetDoubleAttribute("min", range[0]); child->SetDoubleAttribute("max", range[1]); range = lut->GetTableRange(); child = new TiXmlElement("TableRange"); element->LinkEndChild( child ); child->SetDoubleAttribute("min", range[0]); child->SetDoubleAttribute("max", range[1]); child = new TiXmlElement("Table"); element->LinkEndChild( child ); for ( int index = 0; index < lut->GetNumberOfTableValues(); ++index) { TiXmlElement* grandChildNinife = new TiXmlElement("RgbaColor"); rgba = lut->GetTableValue(index); grandChildNinife->SetDoubleAttribute("R", rgba[0]); grandChildNinife->SetDoubleAttribute("G", rgba[1]); grandChildNinife->SetDoubleAttribute("B", rgba[2]); grandChildNinife->SetDoubleAttribute("A", rgba[3]); child->LinkEndChild( grandChildNinife ); } return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + +#if ( (VTK_MAJOR_VERSION < 5) && (VTK_MINOR_VERSION < 4) ) + typedef float OUR_VTK_FLOAT_TYPE; + float range[2]; + float rgba[4]; +#else + typedef double OUR_VTK_FLOAT_TYPE; + double range[2]; + double rgba[4]; +#endif + + double d; // bec. of tinyXML's interface that takes a pointer to float or double... + + vtkLookupTable* lut = vtkLookupTable::New(); + + int numberOfColors; + int scale; + int ramp; // hope the int values don't change betw. vtk versions... + if ( element->QueryIntAttribute( "NumberOfColors", &numberOfColors ) == TIXML_SUCCESS ) + { + lut->SetNumberOfTableValues( numberOfColors ); + } + else + return NULL; + if ( element->QueryIntAttribute( "Scale", &scale ) == TIXML_SUCCESS ) + { + lut->SetScale( scale ); + } + else + return NULL; + if ( element->QueryIntAttribute( "Ramp", &ramp ) == TIXML_SUCCESS ) + { + lut->SetRamp( ramp ); + } + else + return NULL; + + TiXmlElement* child = element->FirstChildElement("HueRange"); + if (child) + { + if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) + return NULL; + range[0] = static_cast(d); + if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) + return NULL; + range[1] = static_cast(d); + lut->SetHueRange( range ); + } + + child = element->FirstChildElement("ValueRange"); + if (child) + { + if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); + if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); + lut->SetValueRange( range ); + } + + child = element->FirstChildElement("SaturationRange"); + if (child) + { + if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); + if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); + lut->SetSaturationRange( range ); + } + + child = element->FirstChildElement("AlphaRange"); + if (child) + { + if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); + if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); + lut->SetAlphaRange( range ); + } + + child = element->FirstChildElement("TableRange"); + if (child) + { + if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast(d); + if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast(d); + lut->SetTableRange( range ); + } + + child = element->FirstChildElement("Table"); + if (child) + { + unsigned int index(0); + for( TiXmlElement* grandChild = child->FirstChildElement("RgbaColor"); grandChild; grandChild = grandChild->NextSiblingElement("RgbaColor")) + { + if ( grandChild->QueryDoubleAttribute("R", &d) != TIXML_SUCCESS ) return NULL; rgba[0] = static_cast(d); + if ( grandChild->QueryDoubleAttribute("G", &d) != TIXML_SUCCESS ) return NULL; rgba[1] = static_cast(d); + if ( grandChild->QueryDoubleAttribute("B", &d) != TIXML_SUCCESS ) return NULL; rgba[2] = static_cast(d); + if ( grandChild->QueryDoubleAttribute("A", &d) != TIXML_SUCCESS ) return NULL; rgba[3] = static_cast(d); + + lut->SetTableValue( index, rgba ); + ++index; + } + } + + LookupTable::Pointer mitkLut = LookupTable::New(); + mitkLut->SetVtkLookupTable( lut ); + + lut->Delete(); + + return LookupTableProperty::New(mitkLut).GetPointer(); + } + protected: LookupTablePropertySerializer() {} virtual ~LookupTablePropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(LookupTablePropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3dPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3dPropertySerializer.cpp index 0479ed8fcc..ff28b6293f 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3dPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3dPropertySerializer.cpp @@ -1,63 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkPoint3dPropertySerializer_h_included #define mitkPoint3dPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT Point3dPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( Point3dPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const Point3dProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("point"); Point3D point = prop->GetValue(); element->SetDoubleAttribute("x", point[0]); element->SetDoubleAttribute("y", point[1]); element->SetDoubleAttribute("z", point[2]); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + Point3D v; + if ( element->QueryFloatAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; + + return Point3dProperty::New( v ).GetPointer(); + } + protected: Point3dPropertySerializer() {} virtual ~Point3dPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(Point3dPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3iPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3iPropertySerializer.cpp index 9097c7c3be..e49a3fbb14 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3iPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint3iPropertySerializer.cpp @@ -1,54 +1,65 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-07 15:56:37 +0200 (Di, 07. Jul 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 mitkPoint3iPropertySerializer_h_included #define mitkPoint3iPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT Point3iPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( Point3iPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const Point3iProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("point"); Point3I point = prop->GetValue(); element->SetAttribute("x", point[0]); element->SetAttribute("y", point[1]); element->SetAttribute("z", point[2]); return element; } else return NULL; } + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + Point3I v; + if ( element->QueryIntAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryIntAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryIntAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; + return Point3iProperty::New( v ).GetPointer(); + } protected: Point3iPropertySerializer() {} virtual ~Point3iPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(Point3iPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint4dPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint4dPropertySerializer.cpp index b4c40fa2a7..b8f89bbaf4 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint4dPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkPoint4dPropertySerializer.cpp @@ -1,64 +1,77 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkPoint4dPropertySerializer_h_included #define mitkPoint4dPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT Point4dPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( Point4dPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const Point4dProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("point"); Point4D point = prop->GetValue(); element->SetDoubleAttribute("x", point[0]); element->SetDoubleAttribute("y", point[1]); element->SetDoubleAttribute("z", point[2]); element->SetDoubleAttribute("t", point[3]); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + Point4D v; + if ( element->QueryFloatAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "t", &v[3] ) != TIXML_SUCCESS ) return NULL; + + return Point4dProperty::New( v ).GetPointer(); + } + protected: Point4dPropertySerializer() {} virtual ~Point4dPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(Point4dPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp index 7a09294337..f6f01eefc0 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringLookupTablePropertySerializer.cpp @@ -1,64 +1,86 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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 mitkStringLookupTablePropertySerializer_h_included #define mitkStringLookupTablePropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT StringLookupTablePropertySerializer : public BasePropertySerializer { public: mitkClassMacro( StringLookupTablePropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { const StringLookupTableProperty* prop = dynamic_cast(m_Property.GetPointer()); if (prop == NULL) return NULL; StringLookupTable lut = prop->GetValue(); //if (lut.IsNull()) // return NULL; // really? const StringLookupTable::LookupTableType& map = lut.GetLookupTable(); TiXmlElement* element = new TiXmlElement("StringLookupTable"); for (StringLookupTable::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; } + + 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: StringLookupTablePropertySerializer() {} virtual ~StringLookupTablePropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(StringLookupTablePropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringPropertySerializer.cpp index 820c0234f0..523dcb4172 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkStringPropertySerializer.cpp @@ -1,60 +1,67 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkStringPropertySerializer_h_included #define mitkStringPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkStringProperty.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT StringPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( StringPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const StringProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("string"); element->SetAttribute("value", prop->GetValue()); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + const char* s( element->Attribute("value") ); + return StringProperty::New( std::string(s?s:"") ).GetPointer(); + } + protected: StringPropertySerializer() {} virtual ~StringPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(StringPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.cpp index 25bee4e628..b1181386c2 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.cpp @@ -1,125 +1,233 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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 "mitkTransferFunctionPropertySerializer.h" namespace mitk { mitk::TransferFunctionPropertySerializer::TransferFunctionPropertySerializer() { } mitk::TransferFunctionPropertySerializer::~TransferFunctionPropertySerializer() { } TiXmlElement* mitk::TransferFunctionPropertySerializer::Serialize() { if (const TransferFunctionProperty* prop = dynamic_cast(mitk::BasePropertySerializer::m_Property.GetPointer())) { TransferFunction* transferfunction = prop->GetValue(); if (!transferfunction) return NULL; TiXmlElement* element = new TiXmlElement("TransferFunction"); // serialize scalar opacity function TiXmlElement* scalarOpacityPointlist = new TiXmlElement( "ScalarOpacity" ); TransferFunction::ControlPoints scalarOpacityPoints = transferfunction->GetScalarOpacityPoints(); for ( TransferFunction::ControlPoints::iterator iter = scalarOpacityPoints.begin(); iter != scalarOpacityPoints.end(); ++iter ) { TiXmlElement* pointel = new TiXmlElement("point"); pointel->SetDoubleAttribute("x", iter->first); pointel->SetDoubleAttribute("y", iter->second); scalarOpacityPointlist->LinkEndChild( pointel ); } element->LinkEndChild( scalarOpacityPointlist ); // serialize gradient opacity function TiXmlElement* gradientOpacityPointlist = new TiXmlElement( "GradientOpacity" ); TransferFunction::ControlPoints gradientOpacityPoints = transferfunction->GetGradientOpacityPoints(); for ( TransferFunction::ControlPoints::iterator iter = gradientOpacityPoints.begin(); iter != gradientOpacityPoints.end(); ++iter ) { TiXmlElement* pointel = new TiXmlElement("point"); pointel->SetDoubleAttribute("x", iter->first); pointel->SetDoubleAttribute("y", iter->second); gradientOpacityPointlist->LinkEndChild( pointel ); } element->LinkEndChild( gradientOpacityPointlist ); // serialize color function vtkColorTransferFunction* ctf = transferfunction->GetColorTransferFunction(); if (ctf == NULL) return NULL; TiXmlElement* pointlist = new TiXmlElement("Color"); for (int i = 0; i < ctf->GetSize(); i++ ) { double myVal[6]; ctf->GetNodeValue(i, myVal); TiXmlElement* pointel = new TiXmlElement("point"); pointel->SetDoubleAttribute("x", myVal[0]); pointel->SetDoubleAttribute("r", myVal[1]); pointel->SetDoubleAttribute("g", myVal[2]); pointel->SetDoubleAttribute("b", myVal[3]); pointel->SetDoubleAttribute("midpoint", myVal[4]); pointel->SetDoubleAttribute("sharpness", myVal[5]); pointlist->LinkEndChild( pointel ); } element->LinkEndChild( pointlist ); return element; } else return NULL; } bool mitk::TransferFunctionPropertySerializer::SerializeTransferFunction( const char * filename, TransferFunction::Pointer tf ) { TransferFunctionPropertySerializer::Pointer tfps=TransferFunctionPropertySerializer::New(); tfps->SetProperty( TransferFunctionProperty::New( tf ) ); TiXmlElement* s=tfps->Serialize(); if(!s) { MITK_ERROR << "cant serialize transfer function"; return false; } TiXmlDocument document; TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "UTF-8", "" ); // TODO what to write here? encoding? standalone would mean that we provide a DTD somewhere... document.LinkEndChild( decl ); TiXmlElement* version = new TiXmlElement("Version"); version->SetAttribute("TransferfunctionVersion", 1 ); document.LinkEndChild(version); document.LinkEndChild(s); if ( !document.SaveFile( filename ) ) { MITK_ERROR << "Could not write scene to " << filename << "\nTinyXML reports '" << document.ErrorDesc() << "'"; return false; } return true; } +BaseProperty::Pointer mitk::TransferFunctionPropertySerializer::Deserialize(TiXmlElement* element) +{ + if (!element) + return NULL; + + TransferFunction::Pointer tf = TransferFunction::New(); + + // deserialize scalar opacity function + TiXmlElement* scalarOpacityPointlist = element->FirstChildElement("ScalarOpacity"); + if (scalarOpacityPointlist == NULL) + return NULL; + + tf->ClearScalarOpacityPoints(); + + for( TiXmlElement* pointElement = scalarOpacityPointlist->FirstChildElement("point"); pointElement != NULL; pointElement = pointElement->NextSiblingElement("point")) + { + double x; + double y; + if (pointElement->QueryDoubleAttribute("x", &x) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("y", &y) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + tf->AddScalarOpacityPoint(x, y); + } + + TiXmlElement* gradientOpacityPointlist = element->FirstChildElement("GradientOpacity"); + if (gradientOpacityPointlist == NULL) + return NULL; + + tf->ClearGradientOpacityPoints(); + + for( TiXmlElement* pointElement = gradientOpacityPointlist->FirstChildElement("point"); pointElement != NULL; pointElement = pointElement->NextSiblingElement("point")) + { + double x; + double y; + if (pointElement->QueryDoubleAttribute("x", &x) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("y", &y) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + tf->AddGradientOpacityPoint(x, y); + } + + TiXmlElement* rgbPointlist = element->FirstChildElement("Color"); + if (rgbPointlist == NULL) + return NULL; + vtkColorTransferFunction* ctf = tf->GetColorTransferFunction(); + if (ctf == NULL) + return NULL; + + ctf->RemoveAllPoints(); + + for( TiXmlElement* pointElement = rgbPointlist->FirstChildElement("point"); pointElement != NULL; pointElement = pointElement->NextSiblingElement("point")) + { + double x; + double r,g,b, midpoint, sharpness; + if (pointElement->QueryDoubleAttribute("x", &x) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("r", &r) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("g", &g) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("b", &b) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("midpoint", &midpoint) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + if (pointElement->QueryDoubleAttribute("sharpness", &sharpness) == TIXML_WRONG_TYPE) + return NULL; // TODO: can we do a better error handling? + ctf->AddRGBPoint(x, r, g, b, midpoint, sharpness); + } + return TransferFunctionProperty::New(tf).GetPointer(); +} + +mitk::TransferFunction::Pointer mitk::TransferFunctionPropertySerializer::DeserializeTransferFunction( const char *filePath ) +{ + TiXmlDocument document( filePath ); + + if (!document.LoadFile()) + { + MITK_ERROR << "Could not open/read/parse " << filePath << "\nTinyXML reports: " << document.ErrorDesc() << std::endl; + return NULL; + } + + // find version node --> note version in some variable + int fileVersion = 1; + TiXmlElement* versionObject = document.FirstChildElement("Version"); + if (versionObject) + { + if ( versionObject->QueryIntAttribute( "TransferfunctionVersion", &fileVersion ) != TIXML_SUCCESS ) + { + MITK_WARN << "Transferfunction file " << filePath << " does not contain version information! Trying version 1 format."; + } + } + + TiXmlElement* input = document.FirstChildElement("TransferFunction"); + + TransferFunctionPropertySerializer::Pointer tfpd = TransferFunctionPropertySerializer::New(); + BaseProperty::Pointer bp = tfpd->Deserialize(input); + TransferFunctionProperty::Pointer tfp = dynamic_cast(bp.GetPointer()); + + if(tfp.IsNotNull()) + { + TransferFunction::Pointer tf = tfp->GetValue(); + return tf; + } + MITK_WARN << "Can't deserialize transferfunction"; + return NULL; +} + } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(TransferFunctionPropertySerializer); \ No newline at end of file diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.h b/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.h index 87c40fae76..a375ea726d 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.h +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkTransferFunctionPropertySerializer.h @@ -1,42 +1,44 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-10-23 11:12:48 +0200 (Fr, 23 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. =========================================================================*/ #include "mitkTransferFunctionProperty.h" #include "mitkBasePropertySerializer.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT TransferFunctionPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( TransferFunctionPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize(); + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element); + static bool SerializeTransferFunction( const char * filename, TransferFunction::Pointer tf ); - + static TransferFunction::Pointer DeserializeTransferFunction( const char *filePath ); protected: TransferFunctionPropertySerializer(); virtual ~TransferFunctionPropertySerializer(); }; } // namespace diff --git a/Modules/SceneSerializationBase/BasePropertySerializer/mitkVector3DPropertySerializer.cpp b/Modules/SceneSerializationBase/BasePropertySerializer/mitkVector3DPropertySerializer.cpp index 85a0717a16..82c86a2885 100644 --- a/Modules/SceneSerializationBase/BasePropertySerializer/mitkVector3DPropertySerializer.cpp +++ b/Modules/SceneSerializationBase/BasePropertySerializer/mitkVector3DPropertySerializer.cpp @@ -1,63 +1,75 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkVector3DPropertySerializer_h_included #define mitkVector3DPropertySerializer_h_included #include "mitkBasePropertySerializer.h" #include "mitkProperties.h" #include "SceneSerializationBaseExports.h" namespace mitk { class SceneSerializationBase_EXPORT Vector3DPropertySerializer : public BasePropertySerializer { public: mitkClassMacro( Vector3DPropertySerializer, BasePropertySerializer ); itkNewMacro(Self); virtual TiXmlElement* Serialize() { if (const Vector3DProperty* prop = dynamic_cast(m_Property.GetPointer())) { TiXmlElement* element = new TiXmlElement("vector"); Vector3D point = prop->GetValue(); element->SetDoubleAttribute("x", point[0]); element->SetDoubleAttribute("y", point[1]); element->SetDoubleAttribute("z", point[2]); return element; } else return NULL; } + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + Vector3D v; + if ( element->QueryFloatAttribute( "x", &v[0] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "y", &v[1] ) != TIXML_SUCCESS ) return NULL; + if ( element->QueryFloatAttribute( "z", &v[2] ) != TIXML_SUCCESS ) return NULL; + + return Vector3DProperty::New( v ).GetPointer(); + } + protected: Vector3DPropertySerializer() {} virtual ~Vector3DPropertySerializer() {} }; } // namespace // important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') MITK_REGISTER_SERIALIZER(Vector3DPropertySerializer); #endif diff --git a/Modules/SceneSerializationBase/CMakeLists.txt b/Modules/SceneSerializationBase/CMakeLists.txt index 849d793a24..0bc639abc2 100644 --- a/Modules/SceneSerializationBase/CMakeLists.txt +++ b/Modules/SceneSerializationBase/CMakeLists.txt @@ -1,6 +1,6 @@ MITK_CREATE_MODULE( SceneSerializationBase - INCLUDE_DIRS BaseDataSerializer BasePropertySerializer BasePropertyDeserializer + INCLUDE_DIRS BaseDataSerializer BasePropertySerializer DEPENDS Mitk ) ADD_SUBDIRECTORY(Testing) diff --git a/Modules/SceneSerializationBase/Testing/mitkPropertySerializationTest.cpp b/Modules/SceneSerializationBase/Testing/mitkPropertySerializationTest.cpp index b41256b0bf..d3789e8242 100644 --- a/Modules/SceneSerializationBase/Testing/mitkPropertySerializationTest.cpp +++ b/Modules/SceneSerializationBase/Testing/mitkPropertySerializationTest.cpp @@ -1,284 +1,267 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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 "mitkDataNodeFactory.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 "mitkPropertyList.h" #include "mitkPropertyListSerializer.h" #include "mitkBasePropertySerializer.h" -#include "mitkBasePropertyDeserializer.h" #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. +* \brief Test for all PropertySerializer classes. * */ int mitkPropertySerializationTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("PropertySerializationTest"); - mitk::PropertyListSerializer::Pointer serializer = mitk::PropertyListSerializer::New(); // make sure something from the lib is actually used (registration of serializers/deserializers) + mitk::PropertyListSerializer::Pointer serializer = mitk::PropertyListSerializer::New(); // make sure something from the lib is actually used (registration of serializers) /* build list of properties that will be serialized and deserialized */ mitk::PropertyList::Pointer propList = mitk::PropertyList::New(); propList->SetProperty("booltrue", mitk::BoolProperty::New(true)); propList->SetProperty("boolfalse", mitk::BoolProperty::New(false)); 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("OrganTypeProperty", mitk::OrganTypeProperty::New("Larynx")); */ 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("PlaneOrientationProperty", mitk::PlaneOrientationProperty::New("Arrows in positive direction")); propList->SetProperty("ShaderProperty", mitk::ShaderProperty::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")); //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 */ // activate the following tests after MaterialProperty is deleted mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetData(mitk::PointSet::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::Image::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::Surface::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::VtkWidgetRendering::New()); TestAllProperties(node->GetPropertyList()); /* node->SetData(mitk::Contour::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::ContourSet::New()); TestAllProperties(node->GetPropertyList()); node->SetData(mitk::Mesh::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()); */ /* untested base data types: BaseDataTestImplementation RenderWindowFrame mitk::DiffusionImage< TPixelType > GeometryData mitk::Geometry2DData GradientBackground ItkBaseDataAdapter ManufacturerLogo 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; // 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::BaseProperty::Pointer deserializedProp = serializer->Deserialize( valueelement ); + MITK_TEST_CONDITION(deserializedProp.IsNotNull(), "serializer created valid property"); + if (deserializedProp.IsNotNull()) { - 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()); - } + MITK_TEST_CONDITION(*(deserializedProp.GetPointer()) == *prop, "deserialized property equals initial property for type " << prop->GetNameOfClass()); } + } else { MITK_TEST_OUTPUT( << "created serializer object is of class " << allSerializers.begin()->GetPointer()->GetNameOfClass()) } } // for all properties } diff --git a/Modules/SceneSerializationBase/files.cmake b/Modules/SceneSerializationBase/files.cmake index 43c4280eea..399a128a1b 100644 --- a/Modules/SceneSerializationBase/files.cmake +++ b/Modules/SceneSerializationBase/files.cmake @@ -1,9 +1,8 @@ # Do not glob files in the Testing directory file(GLOB SRCS *.cpp - BasePropertyDeserializer/*.cpp BasePropertySerializer/*.cpp ) set(CPP_FILES ${SRCS}) diff --git a/Modules/SceneSerializationBase/mitkBasePropertyDeserializer.cpp b/Modules/SceneSerializationBase/mitkBasePropertyDeserializer.cpp deleted file mode 100644 index 0940080d22..0000000000 --- a/Modules/SceneSerializationBase/mitkBasePropertyDeserializer.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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 "mitkBasePropertyDeserializer.h" - -mitk::BasePropertyDeserializer::BasePropertyDeserializer() -{ -} - -mitk::BasePropertyDeserializer::~BasePropertyDeserializer() -{ -} - -mitk::BaseProperty::Pointer mitk::BasePropertyDeserializer::Deserialize(TiXmlElement* /*element*/) -{ - MITK_ERROR << this->GetNameOfClass() << " is asked to deserialize an object but has no implementation. This is bad."; - return NULL; -} - diff --git a/Modules/SceneSerializationBase/mitkBasePropertyDeserializer.h b/Modules/SceneSerializationBase/mitkBasePropertyDeserializer.h deleted file mode 100644 index 0f986a5f31..0000000000 --- a/Modules/SceneSerializationBase/mitkBasePropertyDeserializer.h +++ /dev/null @@ -1,60 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkBasePropertyDeserializer_h_included -#define mitkBasePropertyDeserializer_h_included - -#include "SceneSerializationBaseExports.h" -#include "mitkSerializerMacros.h" - -#include -#include "mitkBaseProperty.h" - -#include - -namespace mitk -{ - -/** - \brief Base class for objects that deserialize BaseProperty types. - - The name of sub-classes must be deduced from the class name of the object that should be constructed from its serialization. - The serialization assumes that - - \verbatim - IF the class derived from BaseProperty is called GreenProperty - THEN the deserializer for this class must be called GreenPropertyDeserializer - \endverbatim -*/ -class SceneSerializationBase_EXPORT BasePropertyDeserializer : public itk::Object -{ - public: - - mitkClassMacro( BasePropertyDeserializer, itk::Object ); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement*); - - protected: - - BasePropertyDeserializer(); - virtual ~BasePropertyDeserializer(); -}; - -} // namespace - -#endif - diff --git a/Modules/SceneSerializationBase/mitkBasePropertySerializer.cpp b/Modules/SceneSerializationBase/mitkBasePropertySerializer.cpp index 0e34921ff9..c957519a74 100644 --- a/Modules/SceneSerializationBase/mitkBasePropertySerializer.cpp +++ b/Modules/SceneSerializationBase/mitkBasePropertySerializer.cpp @@ -1,35 +1,40 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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 "mitkBasePropertySerializer.h" mitk::BasePropertySerializer::BasePropertySerializer() { } mitk::BasePropertySerializer::~BasePropertySerializer() { } TiXmlElement* mitk::BasePropertySerializer::Serialize() { MITK_INFO << this->GetNameOfClass() << " is asked to serialize an object " << (const void*) this->m_Property; return NULL; } +mitk::BaseProperty::Pointer mitk::BasePropertySerializer::Deserialize(TiXmlElement*) +{ + MITK_ERROR << this->GetNameOfClass() << " is asked to deserialize an object but has no implementation. This is bad."; + return NULL; +} diff --git a/Modules/SceneSerializationBase/mitkBasePropertySerializer.h b/Modules/SceneSerializationBase/mitkBasePropertySerializer.h index f5a872ebae..a484411e1c 100644 --- a/Modules/SceneSerializationBase/mitkBasePropertySerializer.h +++ b/Modules/SceneSerializationBase/mitkBasePropertySerializer.h @@ -1,70 +1,79 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit 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. =========================================================================*/ #ifndef mitkSerializeBaseProperty_h_included #define mitkSerializeBaseProperty_h_included #include "SceneSerializationBaseExports.h" #include "mitkSerializerMacros.h" #include #include "mitkBaseProperty.h" #include namespace mitk { /** \brief Base class for objects that serialize BaseProperty types. The name of sub-classes must be deduced from the class name of the object that should be serialized. The serialization assumes that \verbatim If the class derived from BaseProperty is called GreenProperty Then the serializer for this class must be called GreenPropertySerializer \endverbatim */ class SceneSerializationBase_EXPORT BasePropertySerializer : public itk::Object { public: mitkClassMacro( BasePropertySerializer, itk::Object ); itkSetConstObjectMacro(Property, BaseProperty); /** \brief Serializes given BaseProperty object. - \return the filename of the newly created file. + \return The filename of the newly created file. This should be overwritten by specific sub-classes. - */ + */ virtual TiXmlElement* Serialize(); + /** + \brief Deserializes given TiXmlElement. + \return The deserialized Property. + + This should be overwritten by specific sub-classes. + */ + + virtual BaseProperty::Pointer Deserialize(TiXmlElement*); + protected: BasePropertySerializer(); virtual ~BasePropertySerializer(); BaseProperty::ConstPointer m_Property; }; } // namespace #endif diff --git a/Modules/SceneSerializationBase/mitkBoolPropertyDeserializer.cpp b/Modules/SceneSerializationBase/mitkBoolPropertyDeserializer.cpp deleted file mode 100644 index e582e58c9c..0000000000 --- a/Modules/SceneSerializationBase/mitkBoolPropertyDeserializer.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*========================================================================= - -Program: Medical Imaging & Interaction Toolkit -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. - -=========================================================================*/ - -#ifndef mitkBoolPropertyDeserializer_h_included -#define mitkBoolPropertyDeserializer_h_included - -#include "mitkBasePropertyDeserializer.h" - -#include "mitkProperties.h" - -#include "SceneSerializationBaseExports.h" - -namespace mitk -{ - -class SceneSerializationBase_EXPORT BoolPropertyDeserializer : public BasePropertyDeserializer -{ - public: - - mitkClassMacro( BoolPropertyDeserializer, BasePropertyDeserializer ); - itkNewMacro(Self); - - virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) - { - if (!element) return NULL; - return BoolProperty::New( std::string(element->Attribute("value")) == "true" ).GetPointer(); - } - - protected: - - BoolPropertyDeserializer() {} - virtual ~BoolPropertyDeserializer() {} -}; - -} // namespace - -// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') -MITK_REGISTER_SERIALIZER(BoolPropertyDeserializer); - -#endif -