Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

mitk::PlanarFigureWriter Class Reference
[Process Classes]

#include <mitkPlanarFigureWriter.h>

Inheritance diagram for mitk::PlanarFigureWriter:
Inheritance graph
[legend]
Collaboration diagram for mitk::PlanarFigureWriter:
Collaboration graph
[legend]

List of all members.

Public Types

typedef PlanarFigureWriter Self
typedef mitk::FileWriter Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer
typedef mitk::PlanarFigure InputType
typedef InputType::Pointer InputTypePointer

Public Member Functions

virtual const char * GetClassName () const
virtual void Write ()
virtual void Update ()
virtual void SetFileName (const char *_arg)
virtual const char * GetFileName () const
virtual void SetFilePrefix (const char *_arg)
virtual const char * GetFilePrefix () const
virtual void SetFilePattern (const char *_arg)
virtual const char * GetFilePattern () const
void SetInput (InputType *input)
void SetInput (const unsigned int &num, InputType *input)
PlanarFigureGetInput ()
PlanarFigureGetInput (const unsigned int &num)
virtual std::vector< std::string > GetPossibleFileExtensions ()
 Return the possible file extensions for the data type associated with the writer.
virtual std::string GetFileExtension ()
 Return the extension to be added to the filename.
virtual bool CanWriteDataType (DataNode *)
 Check if the Writer can write the Content of the.
virtual std::string GetWritenMIMEType ()
 Return the MimeType of the saved File.
virtual void SetInput (DataNode *)
 Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function.
virtual bool GetSuccess () const

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 PlanarFigureWriter ()
virtual ~PlanarFigureWriter ()
virtual void GenerateData ()
virtual void ResizeInputs (const unsigned int &num)
TiXmlElementCreateXMLVectorElement (const char *name, itk::FixedArray< mitk::ScalarType, 3 > v)
 creates a TinyXML element that contains x, y, and z values

Protected Attributes

std::string m_FileName
std::string m_FilePrefix
std::string m_FilePattern
std::string m_Extension
std::string m_MimeType
bool m_Success

Detailed Description

XML-based writer for mitk::PlanarFigures.

Definition at line 37 of file mitkPlanarFigureWriter.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::PlanarFigureWriter::ConstPointer

Reimplemented from mitk::FileWriter.

Definition at line 41 of file mitkPlanarFigureWriter.h.

Definition at line 45 of file mitkPlanarFigureWriter.h.

Definition at line 49 of file mitkPlanarFigureWriter.h.

typedef itk::SmartPointer<Self> mitk::PlanarFigureWriter::Pointer

Reimplemented from mitk::FileWriter.

Definition at line 41 of file mitkPlanarFigureWriter.h.

Reimplemented from mitk::FileWriter.

Definition at line 41 of file mitkPlanarFigureWriter.h.

Reimplemented from mitk::FileWriter.

Definition at line 41 of file mitkPlanarFigureWriter.h.


Constructor & Destructor Documentation

mitk::PlanarFigureWriter::PlanarFigureWriter (  ) [protected]

Constructor.

Definition at line 24 of file mitkPlanarFigureWriter.cpp.

: m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Extension(".pf"),
  m_MimeType("application/MITK.PlanarFigure"), m_Success(false)
{
  this->SetNumberOfRequiredInputs( 1 );
  this->SetNumberOfOutputs( 0 );
  //this->SetNthOutput( 0, mitk::PlanarFigure::New().GetPointer() );
}
mitk::PlanarFigureWriter::~PlanarFigureWriter (  ) [protected, virtual]

Virtual destructor.

Definition at line 34 of file mitkPlanarFigureWriter.cpp.

{}

Member Function Documentation

bool mitk::PlanarFigureWriter::CanWriteDataType ( DataNode input ) [virtual]

Check if the Writer can write the Content of the.

Reimplemented from mitk::FileWriter.

Definition at line 234 of file mitkPlanarFigureWriter.cpp.

References mitk::DataNode::GetData().

{
  if ( input == NULL )
    return false;

  mitk::BaseData* data = input->GetData();
  if ( data  == NULL)
    return false;

  mitk::PlanarFigure::Pointer PlanarFigure = dynamic_cast<mitk::PlanarFigure*>( data );
  if( PlanarFigure.IsNull() )
    return false;
  // add code for special subclasses here
  return true;
}
TiXmlElement * mitk::PlanarFigureWriter::CreateXMLVectorElement ( const char *  name,
itk::FixedArray< mitk::ScalarType, 3 >  v 
) [protected]

creates a TinyXML element that contains x, y, and z values

Documentation

Parameters:
[in]namethe name of the XML element
[in]vthe vector or point that contains the x, y and z values
Returns:
returns a TiXmlElement named name and three attributes x, y and z.

Definition at line 184 of file mitkPlanarFigureWriter.cpp.

References TiXmlElement::SetDoubleAttribute().

{
  TiXmlElement* vElement = new TiXmlElement(name);
  vElement->SetDoubleAttribute("x", v.GetElement(0));
  vElement->SetDoubleAttribute("y", v.GetElement(1));
  vElement->SetDoubleAttribute("z", v.GetElement(2));
  return vElement;
}
void mitk::PlanarFigureWriter::GenerateData (  ) [protected, virtual]

Writes the a .pf file in xml format that contains all input planar figures

Definition at line 38 of file mitkPlanarFigureWriter.cpp.

References TiXmlDocument::ErrorDesc(), mitk::Geometry3D::GetBounds(), mitk::Geometry3D::GetIndexToWorldTransform(), mitk::Geometry3D::GetOrigin(), mitk::Geometry3D::GetSpacing(), TiXmlNode::LinkEndChild(), MITK_ERROR, TiXmlDocument::SaveFile(), mitk::BasePropertySerializer::Serialize(), TiXmlElement::SetAttribute(), TiXmlElement::SetDoubleAttribute(), and mitk::BasePropertySerializer::SetProperty().

{
  m_Success = false;

  if (m_FileName.empty())
  {
    MITK_ERROR << "Could not write planar figures. File name is invalid";
    throw std::invalid_argument("file name is empty");
  }
 
  TiXmlDocument document;
  TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" ); // TODO what to write here? encoding? etc....
  document.LinkEndChild( decl );

  TiXmlElement* version = new TiXmlElement("Version");
  version->SetAttribute("Writer",  __FILE__ );
  version->SetAttribute("CVSRevision",  "$Revision: 17055 $" );
  version->SetAttribute("FileVersion",  1 );
  document.LinkEndChild(version);

  
  /* create xml element for each input */
  for ( unsigned int i = 0 ; i < this->GetNumberOfInputs(); ++i )
  {
    // Create root element for this PlanarFigure
    InputType::Pointer pf = this->GetInput( i );
    if (pf.IsNull())
      continue;
    TiXmlElement* pfElement = new TiXmlElement("PlanarFigure");
    pfElement->SetAttribute("type", pf->GetNameOfClass());
    document.LinkEndChild(pfElement);

    PlanarFigure::VertexContainerType* vertices = pf->GetControlPoints();
    if (vertices == NULL)
      continue;

    // Serialize property list of PlanarFigure
    mitk::PropertyList::Pointer propertyList = pf->GetPropertyList();
    mitk::PropertyList::PropertyMap::const_iterator it;
    for ( it = propertyList->GetMap()->begin(); it != propertyList->GetMap()->end(); ++it )
    {
      // Create seralizer for this property
      const mitk::BaseProperty* prop = it->second.first;
      std::string serializerName = std::string( prop->GetNameOfClass() ) + "Serializer";
      std::list< itk::LightObject::Pointer > allSerializers = itk::ObjectFactoryBase::CreateAllInstance(
        serializerName.c_str() );

      if ( allSerializers.size() != 1 )
      {
        // No or too many serializer(s) found, skip this property
        continue;
      }

      mitk::BasePropertySerializer* serializer = dynamic_cast< mitk::BasePropertySerializer* >(
        allSerializers.begin()->GetPointer() );
      if ( serializer == NULL )
      {
        // Serializer not valid; skip this property
      }

      TiXmlElement* keyElement = new TiXmlElement( "property" );
      keyElement->SetAttribute( "key", it->first );
      keyElement->SetAttribute( "type", prop->GetNameOfClass() );

        serializer->SetProperty( prop );
      TiXmlElement* valueElement = NULL;
      try
      {
        valueElement = serializer->Serialize();
      }
      catch (...)
      {
      }

      if ( valueElement == NULL )
      {
        // Serialization failed; skip this property
        continue;
      }

      // Add value to property element
      keyElement->LinkEndChild( valueElement );

      // Append serialized property to property list
      pfElement->LinkEndChild( keyElement );
    }

    // Serialize control points of PlanarFigure
    TiXmlElement* controlPointsElement = new TiXmlElement("ControlPoints");
    pfElement->LinkEndChild(controlPointsElement);
    for (unsigned int i = 0; i < pf->GetNumberOfControlPoints(); i++)
    {
      TiXmlElement* vElement = new TiXmlElement("Vertex");
      vElement->SetAttribute("id", i);
      vElement->SetDoubleAttribute("x", pf->GetControlPoint(i)[0]);
      vElement->SetDoubleAttribute("y", pf->GetControlPoint(i)[1]);
      controlPointsElement->LinkEndChild(vElement);
    }
    TiXmlElement* geoElement = new TiXmlElement("Geometry");
    const PlaneGeometry* planeGeo = dynamic_cast<const PlaneGeometry*>(pf->GetGeometry2D());
    if (planeGeo != NULL)
    {
      // Write parameters of IndexToWorldTransform of the PlaneGeometry
      typedef mitk::AffineGeometryFrame3D::TransformType TransformType;
      const TransformType* affineGeometry = planeGeo->GetIndexToWorldTransform();
      const TransformType::ParametersType& parameters = affineGeometry->GetParameters();
      TiXmlElement* vElement = new TiXmlElement( "transformParam" );
      for ( unsigned int i = 0; i < affineGeometry->GetNumberOfParameters(); ++i )
      {
        std::stringstream paramName; 
        paramName << "param" << i;
        vElement->SetDoubleAttribute( paramName.str().c_str(), parameters.GetElement( i ) );
      }
      geoElement->LinkEndChild( vElement );

      // Write bounds of the PlaneGeometry
      typedef mitk::Geometry3D::BoundsArrayType BoundsArrayType;
      const BoundsArrayType& bounds = planeGeo->GetBounds();
      vElement = new TiXmlElement( "boundsParam" );
      for ( unsigned int i = 0; i < 6; ++i )
      {
        std::stringstream boundName; 
        boundName << "bound" << i;
        vElement->SetDoubleAttribute( boundName.str().c_str(), bounds.GetElement( i ) );
      }
      geoElement->LinkEndChild( vElement );

      // Write spacing and origin of the PlaneGeometry
      Vector3D spacing = planeGeo->GetSpacing();
      Point3D origin = planeGeo->GetOrigin();
      geoElement->LinkEndChild(this->CreateXMLVectorElement("Spacing", spacing));
      geoElement->LinkEndChild(this->CreateXMLVectorElement("Origin", origin));

      pfElement->LinkEndChild(geoElement);
    }
  }

  if (document.SaveFile( m_FileName) == false)
  {
    MITK_ERROR << "Could not write planar figures to " << m_FileName << "\nTinyXML reports '" << document.ErrorDesc() << "'";
    throw std::ios_base::failure("Error during writing of planar figure xml file.");
  }
  m_Success = true;
}
virtual const char* mitk::PlanarFigureWriter::GetClassName (  ) const [virtual]

Reimplemented from mitk::FileWriter.

std::string mitk::PlanarFigureWriter::GetFileExtension (  ) [virtual]

Return the extension to be added to the filename.

Reimplemented from mitk::FileWriter.

Definition at line 272 of file mitkPlanarFigureWriter.cpp.

{
  return m_Extension;
}
virtual const char* mitk::PlanarFigureWriter::GetFileName (  ) const [virtual]
Returns:
the name of the file to be written to disk.

Implements mitk::FileWriter.

virtual const char* mitk::PlanarFigureWriter::GetFilePattern (  ) const [virtual]
Warning:
multiple write not (yet) supported

Implements mitk::FileWriter.

virtual const char* mitk::PlanarFigureWriter::GetFilePrefix (  ) const [virtual]
Warning:
multiple write not (yet) supported

Implements mitk::FileWriter.

mitk::PlanarFigure * mitk::PlanarFigureWriter::GetInput ( void   )
Returns:
the 0'th input object of the filter.

Definition at line 219 of file mitkPlanarFigureWriter.cpp.

{
  if ( this->GetNumberOfInputs() < 1 )
    return NULL;
  else
    return dynamic_cast<InputType*> ( this->GetInput( 0 ) );
}
mitk::PlanarFigure * mitk::PlanarFigureWriter::GetInput ( const unsigned int &  num )
Parameters:
numthe index of the desired output object.
Returns:
the n'th input object of the filter.

Definition at line 228 of file mitkPlanarFigureWriter.cpp.

{
  return dynamic_cast<InputType*> ( this->ProcessObject::GetInput( num ) );
}
std::vector< std::string > mitk::PlanarFigureWriter::GetPossibleFileExtensions (  ) [virtual]

Return the possible file extensions for the data type associated with the writer.

Implements mitk::FileWriter.

Definition at line 264 of file mitkPlanarFigureWriter.cpp.

{
  std::vector<std::string> possibleFileExtensions;
  possibleFileExtensions.push_back(m_Extension);
  return possibleFileExtensions;
}
virtual bool mitk::PlanarFigureWriter::GetSuccess (  ) const [virtual]
Returns:
whether the last write attempt was successful or not.
std::string mitk::PlanarFigureWriter::GetWritenMIMEType (  ) [virtual]

Return the MimeType of the saved File.

Reimplemented from mitk::FileWriter.

Definition at line 258 of file mitkPlanarFigureWriter.cpp.

{
  return m_MimeType;
}
static Pointer mitk::PlanarFigureWriter::New (  ) [static]
void mitk::PlanarFigureWriter::ResizeInputs ( const unsigned int &  num ) [protected, virtual]

Resizes the number of inputs of the writer. The inputs are initialized by empty PlanarFigures

Parameters:
numthe new number of inputs

Definition at line 194 of file mitkPlanarFigureWriter.cpp.

{
  //unsigned int prevNum = this->GetNumberOfInputs();
  this->SetNumberOfInputs( num );
  //for ( unsigned int i = prevNum; i < num; ++i )
  //{
  //  this->SetNthInput( i, mitk::PlanarFigure::New().GetPointer() );
  //}
}
virtual void mitk::PlanarFigureWriter::SetFileName ( const char *  _arg ) [virtual]

Sets the filename of the file to write.

Parameters:
FileNamethe name of the file to write.

Implements mitk::FileWriter.

virtual void mitk::PlanarFigureWriter::SetFilePattern ( const char *  _arg ) [virtual]
Warning:
multiple write not (yet) supported

Implements mitk::FileWriter.

virtual void mitk::PlanarFigureWriter::SetFilePrefix ( const char *  _arg ) [virtual]
Warning:
multiple write not (yet) supported

Implements mitk::FileWriter.

void mitk::PlanarFigureWriter::SetInput ( const unsigned int &  num,
InputType input 
)

Sets the n'th input object for the filter. If num is larger than GetNumberOfInputs() the number of inputs is resized appropriately.

Parameters:
inputthe n'th input for the filter.

Definition at line 211 of file mitkPlanarFigureWriter.cpp.

{
  if ( id >= this->GetNumberOfInputs() )
    this->ResizeInputs( id + 1 );
  this->ProcessObject::SetNthInput( id, PlanarFigure );
}
void mitk::PlanarFigureWriter::SetInput ( InputType input )

Sets the 0'th input object for the filter.

Parameters:
inputthe first input for the filter.

Definition at line 205 of file mitkPlanarFigureWriter.cpp.

{
  this->ProcessObject::SetNthInput( 0, PlanarFigure );
}
void mitk::PlanarFigureWriter::SetInput ( DataNode input ) [virtual]

Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function.

Reimplemented from mitk::FileWriter.

Definition at line 251 of file mitkPlanarFigureWriter.cpp.

References mitk::DataNode::GetData().

{
  if (this->CanWriteDataType(input))
    this->ProcessObject::SetNthInput( 0, dynamic_cast<mitk::PlanarFigure*>( input->GetData() ) );
}
virtual void mitk::PlanarFigureWriter::Update (  ) [inline, virtual]

Definition at line 43 of file mitkPlanarFigureWriter.h.

virtual void mitk::PlanarFigureWriter::Write (  ) [inline, virtual]

Implements mitk::FileWriter.

Definition at line 43 of file mitkPlanarFigureWriter.h.


Member Data Documentation

std::string mitk::PlanarFigureWriter::m_Extension [protected]

Definition at line 176 of file mitkPlanarFigureWriter.h.

std::string mitk::PlanarFigureWriter::m_FileName [protected]

Definition at line 173 of file mitkPlanarFigureWriter.h.

std::string mitk::PlanarFigureWriter::m_FilePattern [protected]

Definition at line 175 of file mitkPlanarFigureWriter.h.

std::string mitk::PlanarFigureWriter::m_FilePrefix [protected]

Definition at line 174 of file mitkPlanarFigureWriter.h.

std::string mitk::PlanarFigureWriter::m_MimeType [protected]

Definition at line 177 of file mitkPlanarFigureWriter.h.

Definition at line 178 of file mitkPlanarFigureWriter.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines