diff --git a/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp b/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp index 01afd55ffa..6071943627 100644 --- a/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp +++ b/Modules/PlanarFigure/Algorithms/mitkPlanarFigureObjectFactory.cpp @@ -1,125 +1,130 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-04-16 16:53:19 +0200 (Fr, 16 Apr 2010) $ Version: $Revision: 16916 $ 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 "mitkPlanarFigureObjectFactory.h" +#include "mitkPlanarFigureWriter.h" #include "mitkCoreObjectFactory.h" #include "mitkPlanarFigureIOFactory.h" #include "mitkPlanarFigureWriterFactory.h" #include "mitkPlanarFigure.h" #include "mitkPlanarFigureMapper2D.h" typedef std::multimap MultimapType; mitk::PlanarFigureObjectFactory::PlanarFigureObjectFactory() { static bool alreadyDone = false; if ( !alreadyDone ) { MITK_INFO << "PlanarFigureObjectFactory c'tor" << std::endl; RegisterIOFactories(); itk::ObjectFactoryBase::RegisterFactory( PlanarFigureIOFactory::New() ); PlanarFigureWriterFactory::RegisterOneFactory(); + m_FileWriters.push_back( PlanarFigureWriter::New().GetPointer() ); + + mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(this); + CreateFileExtensionsMap(); alreadyDone = true; } } mitk::Mapper::Pointer mitk::PlanarFigureObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; mitk::BaseData *data = node->GetData(); if ( id == mitk::BaseRenderer::Standard2D ) { if ( dynamic_cast(data) != NULL ) { newMapper = mitk::PlanarFigureMapper2D::New(); newMapper->SetDataNode(node); } } else if ( id == mitk::BaseRenderer::Standard3D ) { } return newMapper; } void mitk::PlanarFigureObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if ( node == NULL ) { return; } mitk::DataNode::Pointer nodePointer = node; mitk::PlanarFigure::Pointer pf = dynamic_cast( node->GetData() ); if ( pf.IsNotNull() ) { mitk::PlanarFigureMapper2D::SetDefaultProperties(node); } } const char* mitk::PlanarFigureObjectFactory::GetFileExtensions() { return ""; }; mitk::CoreObjectFactoryBase::MultimapType mitk::PlanarFigureObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } const char* mitk::PlanarFigureObjectFactory::GetSaveFileExtensions() { //return ";;Planar Figures (*.pf)"; // for mitk::PlanarFigure and derived classes std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::PlanarFigureObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::PlanarFigureObjectFactory::CreateFileExtensionsMap() { m_SaveFileExtensionsMap.insert(std::pair("*.pf", "Planar Figure Files")); } void mitk::PlanarFigureObjectFactory::RegisterIOFactories() { } void RegisterPlanarFigureObjectFactory() { static bool oneObjectFactoryRegistered = false; if ( !oneObjectFactoryRegistered ) { MITK_INFO << "Registering PlanarFigureObjectFactory..." << std::endl; mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( mitk::PlanarFigureObjectFactory::New() ); oneObjectFactoryRegistered = true; } } diff --git a/Modules/PlanarFigure/IO/mitkPlanarFigureWriter.h b/Modules/PlanarFigure/IO/mitkPlanarFigureWriter.h index 63f0085123..0ecc9f692e 100644 --- a/Modules/PlanarFigure/IO/mitkPlanarFigureWriter.h +++ b/Modules/PlanarFigure/IO/mitkPlanarFigureWriter.h @@ -1,188 +1,206 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12. Mai 2009) $ Version: $Revision: 17179 $ 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_PlanarFigure_WRITER__H_ #define _MITK_PlanarFigure_WRITER__H_ #include #include "PlanarFigureExports.h" -#include +#include #include class TiXmlElement; namespace mitk { /** * @brief XML-based writer for mitk::PlanarFigures * * XML-based writer for mitk::PlanarFigures. * @ingroup Process */ - class PlanarFigure_EXPORT PlanarFigureWriter : public mitk::FileWriter + class PlanarFigure_EXPORT PlanarFigureWriter : public mitk::FileWriterWithInformation { public: mitkClassMacro( PlanarFigureWriter, mitk::FileWriter ); mitkWriterMacro; itkNewMacro( Self ); typedef mitk::PlanarFigure InputType; typedef InputType::Pointer InputTypePointer; /** * Sets the filename of the file to write. * @param FileName the name of the file to write. */ itkSetStringMacro( FileName ); /** * @returns the name of the file to be written to disk. */ itkGetStringMacro( FileName ); /** * @warning multiple write not (yet) supported */ itkSetStringMacro( FilePrefix ); /** * @warning multiple write not (yet) supported */ itkGetStringMacro( FilePrefix ); /** * @warning multiple write not (yet) supported */ itkSetStringMacro( FilePattern ); /** * @warning multiple write not (yet) supported */ itkGetStringMacro( FilePattern ); /** * Sets the 0'th input object for the filter. * @param input the first input for the filter. */ void SetInput( InputType* input ); /** * Sets the n'th input object for the filter. If num is * larger than GetNumberOfInputs() the number of inputs is * resized appropriately. * @param input the n'th input for the filter. */ void SetInput( const unsigned int& num, InputType* input); /** * @returns the 0'th input object of the filter. */ PlanarFigure* GetInput(); /** * @param num the index of the desired output object. * @returns the n'th input object of the filter. */ PlanarFigure* GetInput( const unsigned int& num ); /** * @brief Return the possible file extensions for the data type associated with the writer */ virtual std::vector GetPossibleFileExtensions(); /** * @brief Return the extension to be added to the filename. */ virtual std::string GetFileExtension(); /** * @brief Check if the Writer can write the Content of the */ virtual bool CanWriteDataType( DataNode* ); /** * @brief Return the MimeType of the saved File. */ virtual std::string GetWritenMIMEType(); /** * @brief Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function. */ virtual void SetInput( DataNode* ); /** * @returns whether the last write attempt was successful or not. */ itkGetConstMacro(Success, bool); + + virtual const char * GetDefaultFilename() { return "PlanarFigure.pf"; } + virtual const char * GetFileDialogPattern() { return "Planar Figure Files (*.pf)"; } + virtual const char * GetDefaultExtension() { return ".pf"; } + virtual bool CanWriteDataType(BaseData::Pointer data) + { + mitk::DataNode::Pointer node = mitk::DataNode::New(); + node->SetData(data); + return CanWriteDataType(node); + } + virtual void DoWrite(BaseData::Pointer data) { + if (CanWriteDataType(data)) { + this->SetInput(dynamic_cast(data.GetPointer())); + this->Update(); + } + } + + /** @brief CAUTION: It's up to the user to call this function to release the memory buffer after use in case the file writer has written to its memory array. See mitkFileWriter base class. */ virtual void ReleaseMemory(); protected: /** * Constructor. */ PlanarFigureWriter(); /** * Virtual destructor. */ virtual ~PlanarFigureWriter(); /** * Writes the a .pf file in xml format that contains all input planar figures */ virtual void GenerateData(); /** * Resizes the number of inputs of the writer. * The inputs are initialized by empty PlanarFigures * @param num the new number of inputs */ virtual void ResizeInputs( const unsigned int& num ); /**Documentation * \brief creates a TinyXML element that contains x, y, and z values * * \param[in] name the name of the XML element * \param[in] v the vector or point that contains the x, y and z values * \return returns a TiXmlElement named name and three attributes x, y and z. */ TiXmlElement* CreateXMLVectorElement(const char* name, itk::FixedArray v); std::string m_FileName; std::string m_FilePrefix; std::string m_FilePattern; std::string m_Extension; std::string m_MimeType; bool m_Success; }; } #endif