selxItkMeshSink.h 4.08 KB
Newer Older
Floris Berendsen's avatar
Floris Berendsen committed
1
2
/*=========================================================================
 *
3
 *  Copyright Leiden University Medical Center, Erasmus University Medical
Floris Berendsen's avatar
Floris Berendsen committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#ifndef selxItkMeshSink_h
#define selxItkMeshSink_h

23
#include "selxSuperElastixComponent.h"
24
#include "selxInterfaces.h"
Floris Berendsen's avatar
Floris Berendsen committed
25
26
27
#include <string.h>
#include "selxMacro.h"
#include "itkMeshFileWriter.h"
28
29
#include "selxAnyFileWriter.h"
#include "selxFileWriterDecorator.h"
Floris Berendsen's avatar
Floris Berendsen committed
30
31
32

namespace selx
{
33
34
35
template< int Dimensionality, class TPixel >
class ItkMeshSinkComponent :
  public SuperElastixComponent<
36
  Accepting< itkMeshInterface< Dimensionality, TPixel > >,
37
38
39
40
  Providing< SinkInterface, AfterRegistrationInterface >
  >
{
public:
Floris Berendsen's avatar
Floris Berendsen committed
41

42
  selxNewMacro( ItkMeshSinkComponent, ComponentBase );
Floris Berendsen's avatar
Floris Berendsen committed
43

44
  //itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
Floris Berendsen's avatar
Floris Berendsen committed
45

46
47
  ItkMeshSinkComponent();
  virtual ~ItkMeshSinkComponent();
48

49
50
51
  typedef itk::Mesh< TPixel, Dimensionality >         ItkMeshType;
  typedef typename itk::MeshFileWriter< ItkMeshType > ItkMeshWriterType;
  typedef FileWriterDecorator< ItkMeshWriterType >    DecoratedWriterType;
Floris Berendsen's avatar
Floris Berendsen committed
52

53
  virtual int Set( itkMeshInterface< Dimensionality, TPixel > * ) override;
54

55
56
  virtual void SetMiniPipelineOutput( itk::DataObject::Pointer ) override;
  virtual itk::DataObject::Pointer GetMiniPipelineOutput( void ) override;
Floris Berendsen's avatar
Floris Berendsen committed
57

58
  virtual AnyFileWriter::Pointer GetOutputFileWriter( void ) override;
Floris Berendsen's avatar
Floris Berendsen committed
59

60
  virtual itk::DataObject::Pointer GetInitializedOutput( void ) override;
Floris Berendsen's avatar
Floris Berendsen committed
61

62
  virtual void AfterRegistration() override;
Floris Berendsen's avatar
Floris Berendsen committed
63

64
  virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
Floris Berendsen's avatar
Floris Berendsen committed
65

66
  static const char * GetDescription() { return "ItkMeshSink Component"; }
Floris Berendsen's avatar
Floris Berendsen committed
67

68
private:
Floris Berendsen's avatar
Floris Berendsen committed
69

70
71
  typename ItkMeshType::Pointer m_MiniPipelineOutputMesh;
  typename ItkMeshType::Pointer m_OverlordOutputMesh;
Floris Berendsen's avatar
Floris Berendsen committed
72

73
  itkMeshInterface< Dimensionality, TPixel > * m_ProvidingGetItkMeshInterface;
Floris Berendsen's avatar
Floris Berendsen committed
74

75
protected:
Floris Berendsen's avatar
Floris Berendsen committed
76

77
78
  /* The following struct returns the string name of computation type */
  /* default implementation */
Floris Berendsen's avatar
Floris Berendsen committed
79

80
  static inline const std::string GetTypeNameString()
Floris Berendsen's avatar
Floris Berendsen committed
81
  {
82
83
84
    itkGenericExceptionMacro( << "Unknown ScalarType" << typeid( TPixel ).name() );
    // TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
    // We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
Floris Berendsen's avatar
Floris Berendsen committed
85
86
87
  }


88
  static inline const std::string GetPixelTypeNameString()
Floris Berendsen's avatar
Floris Berendsen committed
89
  {
90
91
92
    itkGenericExceptionMacro( << "Unknown PixelType" << typeid( TPixel ).name() );
    // TODO: provide the user instructions how to enable the compilation of the component with the required template types (if desired)
    // We might define an exception object that can communicate various error messages: for simple user, for developer user, etc
Floris Berendsen's avatar
Floris Berendsen committed
93
  }
94
95
96
97
98
99
100
101
102
};

template< >
inline const std::string
ItkMeshSinkComponent< 2, float >
::GetPixelTypeNameString()
{
  return std::string( "float" );
}
Floris Berendsen's avatar
Floris Berendsen committed
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

template< >
inline const std::string
ItkMeshSinkComponent< 2, double >
::GetPixelTypeNameString()
{
  return std::string( "double" );
}


template< >
inline const std::string
ItkMeshSinkComponent< 3, float >
::GetPixelTypeNameString()
{
  return std::string( "float" );
}


template< >
inline const std::string
ItkMeshSinkComponent< 3, double >
::GetPixelTypeNameString()
{
  return std::string( "double" );
}
Floris Berendsen's avatar
Floris Berendsen committed
130
131
132
133
} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkMeshSink.hxx"
#endif
134
#endif // #define selxItkMeshSink_h