Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkSurfaceVtkIO.h"
14 
15 #include "mitkSurface.h"
16 
17 #include <vtkLinearTransform.h>
18 #include <vtkPolyData.h>
19 #include <vtkSmartPointer.h>
20 #include <vtkTransformPolyDataFilter.h>
21 
22 #include <itksys/SystemTools.hxx>
23 
24 namespace mitk
25 {
26  SurfaceVtkIO::SurfaceVtkIO(const std::string &baseDataType,
27  const CustomMimeType &mimeType,
28  const std::string &description)
29  : AbstractFileIO(baseDataType, mimeType, description)
30  {
31  }
32 
33  vtkSmartPointer<vtkPolyData> SurfaceVtkIO::GetPolyData(unsigned int t, std::string &fileName)
34  {
35  const auto *input = dynamic_cast<const Surface *>(this->GetInput());
36 
37  vtkSmartPointer<vtkTransformPolyDataFilter> transformPolyData = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
38 
39  // surfaces do not have to exist in all timesteps; therefor, only write valid surfaces
40  if (input->GetVtkPolyData(t) == nullptr)
41  return vtkSmartPointer<vtkPolyData>();
42 
43  std::string baseName = this->GetOutputLocation();
44  std::string extension = itksys::SystemTools::GetFilenameExtension(baseName);
45  if (!extension.empty())
46  {
47  baseName = baseName.substr(0, baseName.size() - extension.size());
48  }
49 
50  std::ostringstream ss;
51  ss.imbue(::std::locale::classic());
52 
53  BaseGeometry *geometry = input->GetGeometry(t);
54  if (input->GetTimeGeometry()->IsValidTimeStep(t))
55  {
56  if (input->GetTimeGeometry()->CountTimeSteps() > 1)
57  {
58  const TimeBounds &timebounds = input->GetTimeGeometry()->GetTimeBounds(t);
59  ss << baseName << "_S" << std::setprecision(0) << timebounds[0] << "_E" << std::setprecision(0) << timebounds[1]
60  << "_T" << t << extension;
61  }
62  else
63  {
64  // use the original file name
65  ss << this->GetOutputLocation();
66  }
67  }
68  else
69  {
70  MITK_WARN << "Error on write: TimeGeometry invalid of surface " << fileName << ".";
71  return vtkSmartPointer<vtkPolyData>();
72  }
73 
74  fileName = ss.str();
75 
76  transformPolyData->SetInputData(input->GetVtkPolyData(t));
77  transformPolyData->SetTransform(geometry->GetVtkTransform());
78  transformPolyData->UpdateWholeExtent();
79 
80  vtkSmartPointer<vtkPolyData> polyData = transformPolyData->GetOutput();
81  return polyData;
82  }
83 
85  {
87  return Unsupported;
88  if (this->GetInput()->GetTimeGeometry()->CountTimeSteps() > 1)
89  {
90  // The VTK formats don't support multiple time points.
91  // During writing, we write each time step into a separate file.
92  // For output streams, we only write the first time-step and print a warning.
93  return PartiallySupported;
94  }
95  return Supported;
96  }
97 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:28
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
vtkLinearTransform * GetVtkTransform() const
Get the m_IndexToWorldTransform as a vtkLinearTransform.
DataCollection - Class to facilitate loading/accessing structured data.
vtkSmartPointer< vtkPolyData > GetPolyData(unsigned int t, std::string &fileName)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
#define MITK_WARN
Definition: mitkLogMacros.h:19
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:45
const BaseData * GetInput() const override
Get the input data set via SetInput().
ConfidenceLevel GetWriterConfidenceLevel() const override
SurfaceVtkIO(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
std::string GetOutputLocation() const override
Get the current output location.
ConfidenceLevel GetWriterConfidenceLevel() const override
Abstract class for implementing a reader and writer.
BaseGeometry Describes the geometry of a data object.