diff --git a/Modules/MitkExt/IO/mitkPropertyListExportToXmlFile.cpp b/Modules/MitkExt/IO/mitkPropertyListExportToXmlFile.cpp new file mode 100644 index 0000000000..0e7e807ef3 --- /dev/null +++ b/Modules/MitkExt/IO/mitkPropertyListExportToXmlFile.cpp @@ -0,0 +1,175 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#include "mitkPropertyListExportToXmlFile.h" +#include +#include +#include "mitkProperties.h" +#include "mitkStringProperty.h" +#include "mitkEnumerationProperty.h" +#include +#include +#include +#include "usServiceReference.h" +#include +#include + +namespace mitk +{ + struct PropertyListExportToXmlFileData + { + const std::string* m_FileName; + const PropertyList* m_PropertyList; + }; + + PropertyListExportToXmlFile::PropertyListExportToXmlFile(const std::string* _FileName, + const PropertyList* _PropertyList) + : d( new PropertyListExportToXmlFileData ) + { + d->m_FileName = _FileName; + d->m_PropertyList = _PropertyList; + } + + PropertyListExportToXmlFile::~PropertyListExportToXmlFile() + { + delete d; + } + + void PropertyListExportToXmlFile::Update() + { + std::string _FileName = *d->m_FileName; + PropertyList::Pointer propList = PropertyList::New(); + + TiXmlDocument doc( _FileName.c_str() ); + TiXmlElement* root = 0; + TiXmlElement* elem = 0; + + std::string className; + d->m_PropertyList->GetStringProperty("ClassName", className); + // check if element is already available + if(doc.LoadFile()) + { + root = doc.FirstChildElement(); + if(!root) + { + MITK_WARN("PropertyListExportToXml") << "No root element found"; + return; + } + elem = root->FirstChildElement( className ); + std::string id; + d->m_PropertyList->GetStringProperty("Id", id); + if( !id.empty() ) + { + std::string foundId; + while(elem) + { + elem->QueryStringAttribute("Id", &foundId); + if( foundId == id ) + break; + elem = elem->NextSiblingElement( className ); + } + } + } + else + { + // document did not exist, create new one with declration + TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" ); + doc.LinkEndChild( decl ); + // create root + root = new TiXmlElement( "data" ); + doc.LinkEndChild( root ); + } + + // create elem if not existent + TiXmlElement* newElem = 0; + if(!elem) + { + elem = new TiXmlElement( className ); + newElem = elem; + } + + const std::map< std::string, BaseProperty::Pointer>* propMap = d->m_PropertyList->GetMap(); + std::map< std::string, BaseProperty::Pointer>::const_iterator propMapIt = propMap->begin(); + while( propMapIt != propMap->end() ) + { + if( propMapIt->first.find_first_of(".") != std::string::npos ) + { + MITK_DEBUG << "meta property found. will not write."; + ++propMapIt; + continue; + } + mitk::IntProperty* intProp = 0; + mitk::FloatProperty* floatProp = 0; + mitk::DoubleProperty* doubleProp = 0; + mitk::BoolProperty* boolProp = 0; + mitk::StringProperty* stringProp = 0; + mitk::EnumerationProperty* enumProp = 0; + + if( (boolProp = dynamic_cast( propMapIt->second.GetPointer() ) ) ) + { + elem->SetAttribute( propMapIt->first, boolProp->GetValue() ? 1 : 0 ); + } + else if( (stringProp = dynamic_cast( propMapIt->second.GetPointer() ) ) ) + { + elem->SetAttribute( propMapIt->first, stringProp->GetValue() ); + } + else if( (intProp = dynamic_cast( propMapIt->second.GetPointer() ) ) ) + { + elem->SetAttribute( propMapIt->first, intProp->GetValue() ); + } + else if( (enumProp = dynamic_cast( propMapIt->second.GetPointer() ) ) ) + { + elem->SetAttribute( propMapIt->first, enumProp->GetValueAsId() ); + } + else if( (doubleProp = dynamic_cast( propMapIt->second.GetPointer() ) ) ) + { + elem->SetDoubleAttribute( propMapIt->first, doubleProp->GetValue() ); + } + else if( (floatProp = dynamic_cast( propMapIt->second.GetPointer() ) ) ) + { + elem->SetDoubleAttribute( propMapIt->first, static_cast( floatProp->GetValue() ) ); + } + else + { + MITK_DEBUG << "trying to look up serializer for baseproperty in AlgorithmRegistry"; + + { + MITK_WARN("PropertyListExportToXmlFile") << "Base property " << propMapIt->first << " is unknown"; + } + } + ++propMapIt; + } + + // add the element node as child + if( newElem ) + root->LinkEndChild(elem); + + if( !doc.SaveFile( _FileName ) ) + { + MITK_DEBUG << "File " << _FileName << " could not be written. Please check permissions."; + MITK_WARN("PropertyListExportToXmlFile") << "Cannot write file"; + } + } + + void PropertyListExportToXmlFile::SetFileName(const std::string* _FileName) + { + d->m_FileName = _FileName; + } + + void PropertyListExportToXmlFile::SetPropertyList(const PropertyList* _PropertyList) + { + d->m_PropertyList = _PropertyList; + } +} // namespace mitk diff --git a/Modules/MitkExt/IO/mitkPropertyListExportToXmlFile.h b/Modules/MitkExt/IO/mitkPropertyListExportToXmlFile.h new file mode 100644 index 0000000000..6bc4ef6d87 --- /dev/null +++ b/Modules/MitkExt/IO/mitkPropertyListExportToXmlFile.h @@ -0,0 +1,63 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#ifndef mitkPropertyListExportToXmlFile_h +#define mitkPropertyListExportToXmlFile_h + +#include "MitkExtExports.h" +#include + +namespace mitk +{ + /// + /// d pointer forward declaration + /// + struct PropertyListExportToXmlFileData; + /// + /// writes a 2d cv point to an xml file + /// + class MitkExt_EXPORT PropertyListExportToXmlFile + { + public: + /// + /// init default values and save references + /// + PropertyListExportToXmlFile( const std::string* _FileName = 0, + const PropertyList* _PropertyList = 0); + /// + /// executes the algorithm if inputs changed + /// + void Update(); + /// + /// delete d pointer + /// + virtual ~PropertyListExportToXmlFile(); + /// + /// setter for field FileName + /// + void SetFileName(const std::string* _FileName); + /// + /// setter for field PropertyList + /// + void SetPropertyList(const PropertyList* _PropertyList); + private: + /// + /// d pointer + /// + PropertyListExportToXmlFileData* d; + }; +} // namespace mitk + +#endif // mitkPropertyListExportToXmlFile_h diff --git a/Modules/MitkExt/IO/mitkPropertyListImportFromXmlFile.cpp b/Modules/MitkExt/IO/mitkPropertyListImportFromXmlFile.cpp new file mode 100644 index 0000000000..aa70e625e1 --- /dev/null +++ b/Modules/MitkExt/IO/mitkPropertyListImportFromXmlFile.cpp @@ -0,0 +1,203 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#include "mitkPropertyListImportFromXmlFile.h" +#include +#include +#include +#include "mitkProperties.h" +#include "mitkStringProperty.h" +#include "mitkEnumerationProperty.h" +#include "mitkGenericProperty.h" +//#include "mitkBasePropertyFromString.h" +#include +#include +#include +#include "usServiceReference.h" + +namespace mitk +{ + struct PropertyListImportFromXmlFileData + { + const std::string* m_FileName; + PropertyList* m_PropertyList; + + //private + long int m_FileModifiedTime; + }; + + PropertyListImportFromXmlFile::PropertyListImportFromXmlFile( + const std::string* _FileName, + PropertyList* _PropertyList) + : d( new PropertyListImportFromXmlFileData ) + { + d->m_FileName = _FileName; + d->m_PropertyList = _PropertyList; + d->m_FileModifiedTime = 0; + } + + PropertyListImportFromXmlFile::~PropertyListImportFromXmlFile() + { + delete d; + } + + void GetPropertyListFromXMLFile ( const TiXmlElement* elem, const std::string* _FileName, PropertyList* _PropertyList ) + { + const std::map< std::string, BaseProperty::Pointer>* propMap = _PropertyList->GetMap(); + std::map< std::string, BaseProperty::Pointer>::const_iterator propMapIt = propMap->begin(); + while( propMapIt != propMap->end() ) + { + std::string key = propMapIt->first; + mitk::BaseProperty* prop = propMapIt->second.GetPointer(); + mitk::IntProperty* intProp = 0; + mitk::FloatProperty* floatProp = 0; + mitk::DoubleProperty* doubleProp = 0; + mitk::BoolProperty* boolProp = 0; + mitk::StringProperty* stringProp = 0; + mitk::EnumerationProperty* enumProp = 0; + bool found = false; + + if( (boolProp = dynamic_cast( prop ) ) ) + { + int val = false; + found = elem->QueryIntAttribute(key, &val) == TIXML_SUCCESS; + if( found ) + boolProp->SetValue( val==0 ? false : true ); + } + else if( (stringProp = dynamic_cast( prop ) ) ) + { + std::string val = ""; + found = elem->QueryStringAttribute(key.c_str(), &val) == TIXML_SUCCESS; + if( found ) + stringProp->SetValue( val ); + } + else if( (intProp = dynamic_cast( prop ) ) ) + { + int val = 0; + found = elem->QueryIntAttribute(key, &val) == TIXML_SUCCESS; + if( found ) + intProp->SetValue( val ); + } + else if( (enumProp = dynamic_cast( prop ) ) ) + { + int val = 0; + found = elem->QueryIntAttribute(key, &val) == TIXML_SUCCESS; + if( found && enumProp->IsValidEnumerationValue( val ) ) + enumProp->SetValue( static_cast ( val ) ); + else + { + std::string strval = ""; + found = elem->QueryStringAttribute(key.c_str(), &strval); + if( found && enumProp->IsValidEnumerationValue( strval ) ) + enumProp->SetValue( strval ); + } + } + else if( (doubleProp = dynamic_cast( prop ) ) ) + { + double val = 0; + found = elem->QueryDoubleAttribute(key, &val) == TIXML_SUCCESS; + doubleProp->SetValue( val ); + } + else if( (floatProp = dynamic_cast( prop ) ) ) + { + double val = 0; + found = elem->QueryDoubleAttribute(key, &val) == TIXML_SUCCESS; + floatProp->SetValue( static_cast( val ) ); + } + else + { + MITK_WARN("PropertyListImportFromXmlFile") << "Base property " << key << " is unknown"; + } + + if(!found) + { + MITK_DEBUG << "Attribute " << key << " not found"; + } + + ++propMapIt; + } + } + + void PropertyListImportFromXmlFile::Update() + { + + std::string _FileName = *d->m_FileName; + + MITK_DEBUG << "extracting real path (complete path)"; + _FileName = itksys::SystemTools::GetRealPath( _FileName.c_str() ); + + if( !itksys::SystemTools::FileExists(_FileName.c_str()) ) + { + MITK_WARN("PropertyListFromXml") << " Cannot open file"; + } + + long int _FileModifiedTime = itksys::SystemTools::ModifiedTime( _FileName.c_str() ); + // file has not changed: we know that version... -> do nothing + if( d->m_FileModifiedTime >= _FileModifiedTime ) + return; + + // reread + TiXmlDocument doc( _FileName ); + doc.LoadFile(); + + MITK_DEBUG << "searching for element with classname"; + std::string className; + d->m_PropertyList->GetStringProperty("ClassName", className); + + TiXmlHandle docHandle( &doc ); + TiXmlElement* elem = docHandle.FirstChildElement().FirstChildElement( className ).ToElement(); + + if(!elem) + { + MITK_WARN("PropertyListFromXml") << "Cannot find element"; + return; + } + + std::string id; + d->m_PropertyList->GetStringProperty("Id", id); + if( !id.empty() ) + { + std::string foundId; + while(elem) + { + elem->QueryStringAttribute("Id", &foundId); + if( foundId == id ) + break; + elem = elem->NextSiblingElement( className ); + } + if(!elem) + { + MITK_WARN("PropertyListFromXml") << "Cannot find element by id"; + return; + } + } + + MITK_DEBUG << "element found. now reading attributes into propertylist"; + GetPropertyListFromXMLFile( elem, &_FileName, d->m_PropertyList ); + + MITK_DEBUG << "save that modified time"; + d->m_FileModifiedTime = _FileModifiedTime; + } + + void PropertyListImportFromXmlFile::SetFileName(const std::string* _FileName) + { + d->m_FileName = _FileName; + } + + void PropertyListImportFromXmlFile::SetPropertyList(PropertyList* _PropertyList) + { + d->m_PropertyList = _PropertyList; + } +} // namespace mitk diff --git a/Modules/MitkExt/IO/mitkPropertyListImportFromXmlFile.h b/Modules/MitkExt/IO/mitkPropertyListImportFromXmlFile.h new file mode 100644 index 0000000000..e4e983876e --- /dev/null +++ b/Modules/MitkExt/IO/mitkPropertyListImportFromXmlFile.h @@ -0,0 +1,64 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#ifndef mitkPropertyListImportFromXmlFile_h +#define mitkPropertyListImportFromXmlFile_h + +#include +#include "MitkExtExports.h" + +namespace mitk +{ + /// + /// d pointer forward declaration + /// + struct PropertyListImportFromXmlFileData; + /// + /// DOCUMENTATION + /// + class MitkExt_EXPORT PropertyListImportFromXmlFile + { + public: + /// + /// init default values and save references + /// + PropertyListImportFromXmlFile( const std::string* _FileName = 0, + PropertyList* _PropertyList = 0 ); + + /// + /// executes the algorithm if inputs changed + /// + void Update(); + /// + /// delete d pointer + /// + virtual ~PropertyListImportFromXmlFile(); + /// + /// setter for field FileName + /// + void SetFileName(const std::string* _FileName); + /// + /// setter for field PropertyList + /// + void SetPropertyList(PropertyList* _PropertyList); + private: + /// + /// d pointer + /// + PropertyListImportFromXmlFileData* d; + }; +} // namespace mitk + +#endif // mitkPropertyListImportFromXmlFile_h diff --git a/Modules/MitkExt/files.cmake b/Modules/MitkExt/files.cmake index 4061c11ef5..98831db789 100644 --- a/Modules/MitkExt/files.cmake +++ b/Modules/MitkExt/files.cmake @@ -1,151 +1,153 @@ set(CPP_FILES Algorithms/mitkMaskAndCutRoiImageFilter.cpp Algorithms/mitkBoundingObjectToSegmentationFilter.cpp Algorithms/vtkPointSetSlicer.cxx Algorithms/mitkCoreExtObjectFactory.cpp Algorithms/mitkAngleCorrectByPointFilter.cpp Algorithms/mitkAutoCropImageFilter.cpp Algorithms/mitkBoundingObjectCutter.cpp Algorithms/mitkCylindricToCartesianFilter.cpp Algorithms/mitkDopplerToStrainRateFilter.cpp Algorithms/mitkGeometryClipImageFilter.cpp Algorithms/mitkGeometryDataSource.cpp Algorithms/mitkHeightFieldSurfaceClipImageFilter.cpp Algorithms/mitkImageToLookupTableFilter.cpp Algorithms/mitkImageToSurfaceFilter.cpp Algorithms/mitkInterpolateLinesFilter.cpp Algorithms/mitkLabeledImageToSurfaceFilter.cpp Algorithms/mitkLabeledImageVolumeCalculator.cpp Algorithms/mitkLookupTableSource.cpp Algorithms/mitkMaskImageFilter.cpp Algorithms/mitkMeshSource.cpp Algorithms/mitkNonBlockingAlgorithm.cpp Algorithms/mitkPadImageFilter.cpp Algorithms/mitkPlaneCutFilter.cpp Algorithms/mitkPlaneFit.cpp Algorithms/mitkPlanesPerpendicularToLinesFilter.cpp Algorithms/mitkPointLocator.cpp Algorithms/mitkPointSetToCurvedGeometryFilter.cpp Algorithms/mitkPointSetToGeometryDataFilter.cpp Algorithms/mitkPointSetIndexToWorldTransformFilter.cpp Algorithms/mitkSurfaceIndexToWorldTransformFilter.cpp Algorithms/mitkPolygonToRingFilter.cpp Algorithms/mitkProbeFilter.cpp Algorithms/mitkSimpleHistogram.cpp Algorithms/mitkSimpleUnstructuredGridHistogram.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkUnstructuredGridHistogram.cpp Algorithms/mitkUnstructuredGridSource.cpp Algorithms/mitkVolumeVisualizationImagePreprocessor.cpp Controllers/mitkIPythonService.cpp Controllers/mitkMovieGenerator.cpp Controllers/mitkMultiStepper.cpp Controllers/mitkToolManager.cpp DataManagement/mitkAffineTransformationOperation.cpp DataManagement/mitkApplyDiffImageOperation.cpp DataManagement/mitkBoundingObject.cpp DataManagement/mitkBoundingObjectGroup.cpp DataManagement/mitkCellOperation.cpp DataManagement/mitkColorConversions.cpp DataManagement/mitkColorSequence.cpp DataManagement/mitkColorSequenceCycleH.cpp DataManagement/mitkColorSequenceHalfTones.cpp DataManagement/mitkColorSequenceRainbow.cpp DataManagement/mitkCompressedImageContainer.cpp DataManagement/mitkCone.cpp DataManagement/mitkCuboid.cpp DataManagement/mitkCylinder.cpp DataManagement/mitkDataStorageSelection.cpp DataManagement/mitkDelegateManager.cpp DataManagement/mitkDrawOperation.cpp DataManagement/mitkEllipsoid.cpp DataManagement/mitkExternAbstractTransformGeometry.cpp DataManagement/mitkFrameOfReferenceUIDManager.cpp DataManagement/mitkGridRepresentationProperty.cpp DataManagement/mitkGridVolumeMapperProperty.cpp DataManagement/mitkItkBaseDataAdapter.cpp DataManagement/mitkLabeledImageLookupTable.cpp DataManagement/mitkLineOperation.cpp DataManagement/mitkMesh.cpp DataManagement/mitkObjectSet.cpp DataManagement/mitkOrganTypeProperty.cpp DataManagement/mitkPlaneLandmarkProjector.cpp DataManagement/mitkPlane.cpp DataManagement/mitkPropertyManager.cpp DataManagement/mitkPropertyObserver.cpp DataManagement/mitkSeedsImage.cpp DataManagement/mitkSeedsImageLookupTableSource.cpp DataManagement/mitkSphereLandmarkProjector.cpp # DataManagement/mitkUSLookupTableSource.cpp DataManagement/mitkUnstructuredGrid.cpp DataManagement/mitkVideoSource.cpp DataManagement/vtkObjectSet.cpp IO/mitkObjFileIOFactory.cpp IO/mitkObjFileReader.cpp IO/mitkPACSPlugin.cpp IO/mitkParRecFileIOFactory.cpp IO/mitkParRecFileReader.cpp + IO/mitkPropertyListExportToXmlFile.cpp + IO/mitkPropertyListImportFromXmlFile.cpp IO/mitkStlVolumeTimeSeriesIOFactory.cpp IO/mitkStlVolumeTimeSeriesReader.cpp IO/mitkUnstructuredGridVtkWriter.cpp IO/mitkUnstructuredGridVtkWriterFactory.cpp IO/mitkVtkUnstructuredGridIOFactory.cpp IO/mitkVtkUnstructuredGridReader.cpp IO/mitkVtkVolumeTimeSeriesIOFactory.cpp IO/mitkVtkVolumeTimeSeriesReader.cpp Interactions/mitkConferenceEventMapper.cpp Interactions/mitkConnectPointsInteractor.cpp #Interactions/mitkCoordinateSupplier.cpp #Interactions/mitkDisplayCoordinateOperation.cpp #Interactions/mitkDisplayInteractor.cpp Interactions/mitkAffineInteractor3D.cpp Interactions/mitkDisplayPointSetInteractor.cpp #Interactions/mitkDisplayVectorInteractor.cpp Interactions/mitkInteractionDebug.cpp Interactions/mitkInteractionDebugger.cpp Interactions/mitkPointInteractor.cpp Interactions/mitkPointSelectorInteractor.cpp #Interactions/mitkPositionTracker.cpp Interactions/mitkSeedsInteractor.cpp Interactions/mitkSocketClient.cpp Interactions/mitkSurfaceDeformationInteractor3D.cpp Interactions/mitkSurfaceInteractor.cpp Interactions/mitkTool.cpp # Interactions/mitkCreateSurfaceTool.cpp Interactions/mitkMorphologicTool.cpp Interactions/mitkErodeTool.cpp Interactions/mitkDilateTool.cpp Interactions/mitkOpeningTool.cpp Interactions/mitkClosingTool.cpp Interactions/mitkPixelManipulationTool.cpp Rendering/mitkEnhancedPointSetVtkMapper3D.cpp Rendering/mitkImageBackground2D.cpp Rendering/mitkLineMapper2D.cpp # Rendering/mitkLineVtkMapper3D.cpp Rendering/mitkMeshMapper2D.cpp Rendering/mitkMeshVtkMapper3D.cpp Rendering/mitkNativeRenderWindowInteractor.cpp Rendering/mitkSplineMapper2D.cpp Rendering/mitkSplineVtkMapper3D.cpp Rendering/mitkUnstructuredGridMapper2D.cpp Rendering/mitkUnstructuredGridVtkMapper3D.cpp Rendering/mitkVectorImageMapper2D.cpp Rendering/vtkUnstructuredGridMapper.cpp Rendering/vtkMaskedGlyph2D.cpp Rendering/vtkMaskedGlyph3D.cpp Rendering/vtkMitkVolumeTextureMapper3D.cpp Rendering/vtkMitkOpenGLVolumeTextureMapper3D.cpp Rendering/mitkGPUVolumeMapper3D.cpp Rendering/vtkMitkGPUVolumeRayCastMapper.cpp ) if(WIN32 AND NOT MINGW) set(CPP_FILES Controllers/mitkMovieGeneratorWin32.cpp ${CPP_FILES} ) endif(WIN32 AND NOT MINGW)