Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSurfaceVtkIO.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkSurfaceVtkIO.h"
18 
19 #include "mitkSurface.h"
20 
21 #include <vtkLinearTransform.h>
22 #include <vtkPolyData.h>
23 #include <vtkSmartPointer.h>
24 #include <vtkTransformPolyDataFilter.h>
25 
26 #include <itksys/SystemTools.hxx>
27 
28 namespace mitk
29 {
30  SurfaceVtkIO::SurfaceVtkIO(const std::string &baseDataType,
31  const CustomMimeType &mimeType,
32  const std::string &description)
33  : AbstractFileIO(baseDataType, mimeType, description)
34  {
35  }
36 
37  vtkSmartPointer<vtkPolyData> SurfaceVtkIO::GetPolyData(unsigned int t, std::string &fileName)
38  {
39  const Surface *input = dynamic_cast<const Surface *>(this->GetInput());
40 
41  vtkSmartPointer<vtkTransformPolyDataFilter> transformPolyData = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
42 
43  // surfaces do not have to exist in all timesteps; therefor, only write valid surfaces
44  if (input->GetVtkPolyData(t) == NULL)
45  return vtkSmartPointer<vtkPolyData>();
46 
47  std::string baseName = this->GetOutputLocation();
48  std::string extension = itksys::SystemTools::GetFilenameExtension(baseName);
49  if (!extension.empty())
50  {
51  baseName = baseName.substr(0, baseName.size() - extension.size());
52  }
53 
54  std::ostringstream ss;
55  ss.imbue(::std::locale::classic());
56 
57  BaseGeometry *geometry = input->GetGeometry(t);
58  if (input->GetTimeGeometry()->IsValidTimeStep(t))
59  {
60  if (input->GetTimeGeometry()->CountTimeSteps() > 1)
61  {
62  const TimeBounds &timebounds = input->GetTimeGeometry()->GetTimeBounds(t);
63  ss << baseName << "_S" << std::setprecision(0) << timebounds[0] << "_E" << std::setprecision(0) << timebounds[1]
64  << "_T" << t << extension;
65  }
66  else
67  {
68  // use the original file name
69  ss << this->GetOutputLocation();
70  }
71  }
72  else
73  {
74  MITK_WARN << "Error on write: TimeGeometry invalid of surface " << fileName << ".";
75  return vtkSmartPointer<vtkPolyData>();
76  }
77 
78  fileName = ss.str();
79 
80  transformPolyData->SetInputData(input->GetVtkPolyData(t));
81  transformPolyData->SetTransform(geometry->GetVtkTransform());
82  transformPolyData->UpdateWholeExtent();
83 
84  vtkSmartPointer<vtkPolyData> polyData = transformPolyData->GetOutput();
85  return polyData;
86  }
87 
89  {
91  return Unsupported;
92  if (this->GetInput()->GetTimeGeometry()->CountTimeSteps() > 1)
93  {
94  // The VTK formats don't support multiple time points.
95  // During writing, we write each time step into a separate file.
96  // For output streams, we only write the first time-step and print a warning.
97  return PartiallySupported;
98  }
99  return Supported;
100  }
101 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
DataCollection - Class to facilitate loading/accessing structured data.
vtkSmartPointer< vtkPolyData > GetPolyData(unsigned int t, std::string &fileName)
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:52
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual TimeBounds GetTimeBounds() const =0
Get the time bounds (in ms)
virtual const BaseData * GetInput() const override
Get the input data set via SetInput().
virtual ConfidenceLevel GetWriterConfidenceLevel() const override
SurfaceVtkIO(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
virtual std::string GetOutputLocation() const override
Get the current output location.
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:49
virtual ConfidenceLevel GetWriterConfidenceLevel() const override
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:129
Abstract class for implementing a reader and writer.
virtual bool IsValidTimeStep(TimeStepType timeStep) const =0
Test for the given time step if a geometry is availible.
BaseGeometry Describes the geometry of a data object.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.