selxItkImageSink.h 4.19 KB
Newer Older
Floris Berendsen's avatar
Floris Berendsen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*=========================================================================
 *
 *  Copyright Leiden University Medical Center, Erasmus University Medical 
 *  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.
 *
 *=========================================================================*/

20
21
22
#ifndef selxItkImageSink_h
#define selxItkImageSink_h

23
24
#include "selxComponentBase.h"
#include "selxInterfaces.h"
25
#include <string.h>
26
#include "selxMacro.h"
27
#include "itkImageFileWriter.h"
FBerendsen's avatar
FBerendsen committed
28
#include "itkSmartPointer.h"
29
30
#include "selxAnyFileWriter.h"
#include "selxFileWriterDecorator.h"
31
32
33
34
35
36

namespace selx
{
  template<int Dimensionality, class TPixel>
  class ItkImageSinkComponent :
    public Implements <
37
    Accepting< itkImageInterface<Dimensionality, TPixel> >,
38
    Providing < SinkInterface >
39
40
41
    >
  {
  public:
42
    selxNewMacro(ItkImageSinkComponent, ComponentBase);
43

FBerendsen's avatar
FBerendsen committed
44
    //itkStaticConstMacro(Dimensionality, unsigned int, Dimensionality);
45
46
47
48

    ItkImageSinkComponent();
    virtual ~ItkImageSinkComponent();

49
50
51
    typedef itkImageInterface<Dimensionality, TPixel> AcceptingImageInterfaceType;
    typedef typename AcceptingImageInterfaceType::ItkImageType ItkImageType;
    typedef typename ItkImageType::Pointer ItkImagePointer;
52
    typedef typename itk::ImageFileWriter<ItkImageType> ItkImageWriterType;
53
    typedef FileWriterDecorator<ItkImageWriterType>  DecoratedWriterType;
54
55

    virtual int Set(AcceptingImageInterfaceType*) override;
56
    virtual void SetMiniPipelineOutput(itk::DataObject::Pointer) override;
57
    virtual itk::DataObject::Pointer GetMiniPipelineOutput(void) override;
58
    virtual AnyFileWriter::Pointer GetOutputFileWriter(void) override;
59
    virtual itk::DataObject::Pointer GetInitializedOutput(void) override;
60

61

FBerendsen's avatar
FBerendsen committed
62
    virtual bool MeetsCriterion(const ComponentBase::CriterionType &criterion) override;
63
64
    static const char * GetDescription() { return "ItkImageSink Component"; };
  private:
65
66
67
    typename ItkImageType::Pointer m_MiniPipelineOutputImage;
    typename ItkImageType::Pointer m_OverlordOutputImage;

68
    protected:
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
    /* The following struct returns the string name of computation type */
    /* default implementation */

    static inline const std::string GetTypeNameString()
    {
      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
    }

    static inline const std::string GetPixelTypeNameString()
    {
      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
    }

  };



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


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

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

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

} //end namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "selxItkImageSink.hxx"
#endif
#endif // #define selxItkImageSink_h