DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkMeshFromImageImageFilter.h
Go to the documentation of this file.
1 
18 #ifndef __itkMeshFromImageImageFilter_h
19 #define __itkMeshFromImageImageFilter_h
20 
21 #include "vtkPoints.h"
22 #include "vtkPolyData.h"
23 #include "vtkCellArray.h"
24 #include "vtkPolyDataWriter.h"
25 #include "vtkDoubleArray.h"
26 #include "vtkUnsignedCharArray.h"
27 #include "vtkPointData.h"
28 #include "vtkCellData.h"
29 #include "vtkTypeTraits.h"
30 #include "vtkType.h"
31 #include "vtkSmartPointer.h"
32 
33 #include "utlNDArray.h"
34 #include "itkImageSource.h"
36 #include "utlCore.h"
37 
38 namespace itk
39 {
40 
48 template < class TInputImage, class TOutputMesh=vtkPolyData>
49 class ITK_EXPORT MeshFromImageImageFilter
50  : public MaskedImageToImageFilter<TInputImage, TInputImage>
51 {
52 public:
56  typedef SmartPointer<Self> Pointer;
57  typedef SmartPointer<const Self> ConstPointer;
58 
60  itkNewMacro(Self);
61 
64 
66  static const unsigned int OrientationDimension = 3;
67 
68  //** Convenient typedefs */
69  typedef TInputImage InputImageType;
70  typedef typename InputImageType::Pointer InputImagePointer;
71  typedef typename InputImageType::ConstPointer InputImageConstPointer;
72  typedef typename InputImageType::IndexType InputImageIndexType;
73  typedef typename InputImageType::SizeType InputImageSizeType;
74  typedef typename InputImageType::SizeValueType InputImageSizeValueType;
75  typedef typename InputImageType::SpacingType InputImageSpacingType;
76  typedef typename InputImageType::PixelType InputImagePixelType;
77  typedef typename InputImageType::RegionType InputImageRegionType;
78  typedef typename InputImageType::PointType InputImagePointType;
79 
80  typedef TOutputMesh OutputMeshPolyDataType;
81 
82  typedef vtkPoints OutputMeshPointsType;
83  typedef vtkCellArray OutputMeshCellArrayType;
84  // typedef vtkPolyData OutputMeshPolyDataType;
85  typedef vtkSmartPointer<OutputMeshPolyDataType> OutputMeshPolyDataPointer;
86  typedef vtkDoubleArray OutputMeshScalarType;
87  typedef vtkUnsignedCharArray OutputMeshRGBType;
88 
92  typedef utl_shared_ptr<MatrixType> MatrixPointer;
93  typedef utl_shared_ptr<VectorType> VectorPointer;
94  typedef std::vector<double> STDVectorType;
95  typedef utl_shared_ptr<STDVectorType > STDVectorPointer;
96 
97  typedef enum {UNKNOWN=0, FIXED, DIRECTION, MAGNITUDE} ColorSchemeType;
98 
99  itkSetMacro(ColorScheme, ColorSchemeType);
100  itkGetMacro(ColorScheme, ColorSchemeType);
101 
102  // virtual void SetInput(const InputImageType *image)
103  // {
104  // this->ProcessObject::SetNthInput( 0,const_cast< InputImageType * >( image ) );
105  // }
106 
107  // const InputImageType * GetInput(void) const
108  // {
109  // return itkDynamicCastInDebugMode< const TInputImage * >( this->GetPrimaryInput() );
110  // }
111 
112 
113  void SetBoxView(const int x0, const int x1, const int y0, const int y1, const int z0, const int z1 )
114  {
115  m_BoxView[0]=x0;
116  m_BoxView[1]=x1;
117  m_BoxView[2]=y0;
118  m_BoxView[3]=y1;
119  m_BoxView[4]=z0;
120  m_BoxView[5]=z1;
121  }
122  std::vector<int> GetBoxView() const
123  {
124  return m_BoxView;
125  }
126 
127  void SetSliceView(const int coronal, const int sagittal, const int transverse )
128  {
129  m_SliceView[0]=coronal, m_SliceView[1]=sagittal, m_SliceView[2]=transverse;
130  }
131  std::vector<int> GetSliceView() const
132  {
133  return m_SliceView;
134  }
135 
136  void SetFlip(const int flipx, const int flipy, const int flipz )
137  {
138  m_Flip[0]=flipx, m_Flip[1]=flipy, m_Flip[2]=flipz;
139  }
140  std::vector<int> GetFlip() const
141  {
142  return m_Flip;
143  }
144 
146  itkSetMacro(Scale, double);
147  itkGetMacro(Scale, double);
148 
149 
151  OutputMeshPolyDataPointer GetOutput()
152  {
153  return m_Mesh;
154  }
155 
156 protected:
158  {
159  this->SetNumberOfRequiredInputs(1);
160  // TODO: multi-thread
161  this->SetNumberOfThreads(1);
162  }
164  {
165  if (m_Mesh)
166  m_Mesh->Delete();
167  }
168 
169  virtual bool IsPixelIndexVisible(const InputImageIndexType& index )
170  {
171  if (this->IsMaskUsed() && this->m_MaskImage->GetPixel(index)==0)
172  return false;
173 
174  if ( (m_BoxView[0]>=0 || m_BoxView[1]>=0) && (index[0]<m_BoxView[0] || index[0]>m_BoxView[1]) )
175  return false;
176  if ( (m_BoxView[2]>=0 || m_BoxView[3]>=0) && (index[1]<m_BoxView[2] || index[1]>m_BoxView[3]) )
177  return false;
178  if ( (m_BoxView[4]>=0 || m_BoxView[5]>=0) && (index[2]<m_BoxView[4] || index[2]>m_BoxView[5]) )
179  return false;
180 
181  if ( (m_SliceView[0]>=0 || m_SliceView[1]>=0 || m_SliceView[2]>=0) && index[0]!=m_SliceView[0] && index[1]!=m_SliceView[1] && index[2]!=m_SliceView[2])
182  return false;
183 
184  return true;
185  }
186 
187  virtual void VerifyInputParameters() const ITK_OVERRIDE
188  {
189  }
190 
191  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE
192  {
193  PrintVar(true, os<<indent, m_Scale );
194  utl::PrintVector(m_BoxView, "m_BoxView");
195  utl::PrintVector(m_SliceView, "m_SliceView");
196  utl::PrintVector(m_Flip, "m_Flip");
197  PrintVar(true, os<<indent, m_ColorScheme);
198  m_Mesh->Print(std::cout<<"m_Mesh=");
199  }
200 
201  typename LightObject::Pointer InternalClone() const ITK_OVERRIDE
202  {
203  typename LightObject::Pointer loPtr = Superclass::InternalClone();
204 
205  typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
206  if(rval.IsNull())
207  {
208  itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass()<< " failed.");
209  }
210  rval->m_Scale = m_Scale;
211  rval->m_ColorScheme = m_ColorScheme;
212 
213  rval->m_BoxView = m_BoxView;
214  rval->m_SliceView = m_SliceView;
215 
216  rval->m_Flip = m_Flip;
217 
218  return loPtr;
219  }
220 
221 
224  {
225  typename TInputImage::Pointer outputPtr = itkDynamicCastInDebugMode< TInputImage * >( this->GetPrimaryOutput() );
226  InputImagePointer inputPtr = const_cast<InputImageType *>(this->GetInput());
227  itk::CopyImageInformation(inputPtr, outputPtr);
228  outputPtr->SetNumberOfComponentsPerPixel(1);
229  }
230 
233  {
234  }
235 
236  OutputMeshPolyDataPointer m_Mesh = OutputMeshPolyDataType::New();
237 
238  double m_Scale=1.0;
239 
240  ColorSchemeType m_ColorScheme=UNKNOWN;
241 
243  std::vector<int> m_BoxView = std::vector<int>(6,-1);
244 
246  std::vector<int> m_SliceView = std::vector<int>(3,-1);
247 
249  std::vector<int> m_Flip = std::vector<int>(3, 0);
250 
251 private:
252  MeshFromImageImageFilter(const Self&); //purposely not implemented
253  void operator=(const Self&);//purposely not implemented
254 };
255 
256 } // end namespace itk
257 
258 
259 #endif
utl_shared_ptr< MatrixType > MatrixPointer
void SetBoxView(const int x0, const int x1, const int y0, const int y1, const int z0, const int z1)
virtual void GenerateOutputInformation() ITK_OVERRIDE
LightObject::Pointer InternalClone() const ITK_OVERRIDE
void SetFlip(const int flipx, const int flipy, const int flipz)
InputImageType::RegionType InputImageRegionType
SmartPointer< const Self > ConstPointer
MaskedImageToImageFilter< TInputImage, TInputImage > Superclass
virtual void VerifyInputParameters() const ITK_OVERRIDE
InputImageType::PointType InputImagePointType
InputImageType::SizeValueType InputImageSizeValueType
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
utl_shared_ptr< STDVectorType > STDVectorPointer
Compute mesh from SH coefficients.
void CopyImageInformation(const SmartPointer< ImageWithInfoType > &imageFrom, SmartPointer< ImageType > &imageTo)
Definition: utlITK.h:552
OutputMeshPolyDataPointer GetOutput()
InputImageType::ConstPointer InputImageConstPointer
ImageToImageFilter with mask and threaded logger support.
#define PrintVar(cond, os,...)
Definition: utlCoreMacro.h:242
std::vector< int > GetSliceView() const
vtkSmartPointer< OutputMeshPolyDataType > OutputMeshPolyDataPointer
virtual void AllocateOutputs() ITK_OVERRIDE
InputImageType::PixelType InputImagePixelType
void PrintVector(const std::vector< T > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
Definition: utlCore.h:1002
void SetSliceView(const int coronal, const int sagittal, const int transverse)
InputImageType::SpacingType InputImageSpacingType
virtual bool IsPixelIndexVisible(const InputImageIndexType &index)
InputImageType::IndexType InputImageIndexType
utl_shared_ptr< VectorType > VectorPointer
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
std::vector< int > GetBoxView() const
InputImageType::SizeType InputImageSizeType