ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkCuberilleImageToMeshFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkCuberilleImageToMeshFilter_h
19 #define itkCuberilleImageToMeshFilter_h
20 
21 #define DEBUG_PRINT 0
22 #define USE_GRADIENT_RECURSIVE_GAUSSIAN 0
23 #define USE_ADVANCED_PROJECTION 0
24 #define USE_LINESEARCH_PROJECTION 0
25 
26 #include "itkMacro.h"
27 #include "itkMesh.h"
28 #include "itkImageToMeshFilter.h"
29 #include "itkCellInterface.h"
30 #include "itkTriangleCell.h"
31 #include "itkQuadrilateralCell.h"
35 #include "itkGradientImageFilter.h"
38 
39 namespace itk
40 {
41 
113 template < class TInputImage, class TOutputMesh, class TInterpolator=itk::LinearInterpolateImageFunction<TInputImage> >
114 class CuberilleImageToMeshFilter : public ImageToMeshFilter< TInputImage, TOutputMesh >
115 {
116 public:
122 
124  itkNewMacro(Self);
125 
128 
130  typedef TOutputMesh OutputMeshType;
131  typedef typename OutputMeshType::Pointer OutputMeshPointer;
132  typedef typename OutputMeshType::MeshTraits OutputMeshTraits;
133  typedef typename OutputMeshType::PointType OutputPointType;
134  typedef typename OutputMeshTraits::PixelType OutputPixelType;
135  typedef typename OutputMeshType::CellTraits CellTraits;
136  typedef typename OutputMeshType::PointsContainerPointer PointsContainerPointer;
137  typedef typename OutputMeshType::PointsContainer PointsContainer;
138  typedef typename OutputMeshType::CellsContainerPointer CellsContainerPointer;
139  typedef typename OutputMeshType::CellsContainer CellsContainer;
140  typedef typename OutputMeshType::PointIdentifier PointIdentifier;
141  typedef typename OutputMeshType::CellIdentifier CellIdentifier;
144  typedef typename TriangleCellType::SelfAutoPointer TriangleAutoPointer;
145  typedef typename TriangleCellType::CellAutoPointer TriangleCellAutoPointer;
147  typedef typename QuadrilateralCellType::SelfAutoPointer QuadrilateralAutoPointer;
148  typedef typename QuadrilateralCellType::CellAutoPointer QuadrilateralCellAutoPointer;
149 
150  typedef TInputImage InputImageType;
151  typedef typename InputImageType::Pointer InputImagePointer;
152  typedef typename InputImageType::ConstPointer InputImageConstPointer;
153  typedef typename InputImageType::PixelType InputPixelType;
154  typedef typename InputImageType::SizeType SizeType;
155  typedef typename InputImageType::SpacingType SpacingType;
156  typedef typename InputImageType::SpacingValueType SpacingValueType;
157  typedef typename InputImageType::IndexType IndexType;
158  typedef typename OutputMeshType::PointType PointType;
159 
160  typedef TInterpolator InterpolatorType;
161  typedef typename InterpolatorType::Pointer InterpolatorPointer;
162  typedef typename InterpolatorType::OutputType InterpolatorOutputType;
163 
166 #if USE_GRADIENT_RECURSIVE_GAUSSIAN
168 #else
170 #endif
173  typedef typename GradientImageType::Pointer GradientImagePointer;
177 
183  itkGetMacro( IsoSurfaceValue, InputPixelType );
184  itkSetMacro( IsoSurfaceValue, InputPixelType );
186 
188  using Superclass::SetInput;
189  virtual void SetInput( const InputImageType * inputImage );
190 
192  itkGetObjectMacro( Interpolator, InterpolatorType );
193  itkSetObjectMacro( Interpolator, InterpolatorType );
195 
199  itkGetMacro( GenerateTriangleFaces, bool );
200  itkSetMacro( GenerateTriangleFaces, bool );
201  itkBooleanMacro( GenerateTriangleFaces );
203 
206  itkGetMacro( ProjectVerticesToIsoSurface, bool );
207  itkSetMacro( ProjectVerticesToIsoSurface, bool );
208  itkBooleanMacro( ProjectVerticesToIsoSurface );
210 
217  itkGetMacro( ProjectVertexSurfaceDistanceThreshold, double );
218  itkSetClampMacro( ProjectVertexSurfaceDistanceThreshold, double, 0.0, NumericTraits<InputPixelType>::max() );
220 
224  itkGetMacro( ProjectVertexStepLength, double );
225  itkSetClampMacro( ProjectVertexStepLength, double, 0.0, 100000.0 );
227 
232  itkGetMacro( ProjectVertexStepLengthRelaxationFactor, double );
233  itkSetClampMacro( ProjectVertexStepLengthRelaxationFactor, double, 0.0, 1.0 );
235 
238  itkGetMacro( ProjectVertexMaximumNumberOfSteps, unsigned int );
239  itkSetMacro( ProjectVertexMaximumNumberOfSteps, unsigned int );
241 
242 protected:
245  void PrintSelf(std::ostream& os, Indent indent) const;
246 
247  void GenerateData();
248  virtual void GenerateOutputInformation(){ }; // do nothing
249 
250 private:
251  CuberilleImageToMeshFilter(const Self&); //purposely not implemented
252  void operator=(const Self&); //purposely not implemented
253 
257  {
258  public:
261 
263  VertexLookupNode() : m_X( 0 ), m_Y( 0 ) { }
264  VertexLookupNode(unsigned long x, unsigned long y) : m_X( x ), m_Y( y ) { }
266 
268  unsigned long GetX() { return m_X; }
269  unsigned long GetY() { return m_Y; }
271 
273  bool operator> ( const Self& node ) const
274  { return (m_Y > node.m_Y) || ( (m_Y == node.m_Y) && (m_X > node.m_X) ); }
275  bool operator>= ( const Self& node ) const
276  { return (m_Y >= node.m_Y) || ( (m_Y == node.m_Y) && (m_X >= node.m_X) ); }
277  bool operator< ( const Self& node ) const
278  { return (m_Y < node.m_Y) || ( (m_Y == node.m_Y) && (m_X < node.m_X) ); }
279  bool operator<= ( const Self& node ) const
280  { return (m_Y <= node.m_Y) || ( (m_Y == node.m_Y) && (m_X <= node.m_X) ); }
282 
283  private:
284  unsigned long m_X;
285  unsigned long m_Y;
286  };
287 
290  template< class TMeshType >
292  {
293  public:
296  typedef typename TMeshType::PointIdentifier PointIdentifier;
297  typedef std::map< VertexLookupNode, PointIdentifier > MapType;
298 
301 
303  void Clear() { m_Map.clear(); }
304 
306  void AddVertex( unsigned int x, unsigned int y, PointIdentifier id )
307  {
308  VertexLookupNode node( x, y );
309  m_Map.insert( typename MapType::value_type(node, id) );
310  }
312 
316  bool GetVertex( unsigned int x, unsigned int y, PointIdentifier &id )
317  {
318  bool result = false;
319  VertexLookupNode node( x, y );
320  typename MapType::iterator it = m_Map.find( node );
321  if ( it != m_Map.end() )
322  {
323  result = true;
324  id = it->second;
325  }
326  return result;
327  }
329 
330  private:
332  };
333 
336 
338  inline void ComputeGradientImage();
339  inline void SetVerticesFromFace( unsigned int face, bool *vertexHasQuad );
340  inline IndexType GetVertexLookupIndex( unsigned int vertex, IndexType index );
341  inline void ProjectVertexToIsoSurface( PointType &vertex );
342  inline void AddVertex( PointIdentifier &id, IndexType index, const InputImageType* image, OutputMeshType* mesh );
343  inline void AddQuadFace( CellIdentifier &id, PointIdentifier f[4], OutputMeshType* mesh );
345 
356 #if DEBUG_PRINT
357  unsigned int m_ProjectVertexTerminate[3];
358 #endif
359 };
360 
361 } // end namespace itk
362 
363 #ifndef ITK_MANUAL_INSTANTIATION
364 #include "itkCuberilleImageToMeshFilter.hxx"
365 #endif
366 
367 #endif
void PrintSelf(std::ostream &os, Indent indent) const
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
GradientFilterType::Pointer GradientFilterPointer
VertexLookupMap< OutputMeshType > VertexLookupMapType
Light weight base class for most itk classes.
itkGetObjectMacro(Interpolator, InterpolatorType)
QuadrilateralCellType::SelfAutoPointer QuadrilateralAutoPointer
void operator=(const Self &)
GradientInterpolatorPointer m_GradientInterpolator
CellInterface< OutputPixelType, CellTraits > CellInterfaceType
InterpolatorType::OutputType InterpolatorOutputType
GradientInterpolatorType::Pointer GradientInterpolatorPointer
TriangleCell< CellInterfaceType > TriangleCellType
GradientFilterType::OutputImageType GradientImageType
Computes the gradient of an image by convolution with the first derivative of a Gaussian.
QuadrilateralCellType::CellAutoPointer QuadrilateralCellAutoPointer
An abstract interface for cells.
void SetVerticesFromFace(unsigned int face, bool *vertexHasQuad)
virtual void SetInput(const InputImageType *inputImage)
QuadrilateralCell< CellInterfaceType > QuadrilateralCellType
OutputMeshType::CellsContainerPointer CellsContainerPointer
OutputMeshType::PointIdentifier PointIdentifier
ImageToMeshFilter is the base class for all process objects that output Mesh data and require image d...
GradientFilterType::OutputPixelType GradientPixelType
GradientImageType::Pointer GradientImagePointer
void ProjectVertexToIsoSurface(PointType &vertex)
OutputMeshType::CellIdentifier CellIdentifier
GradientImageFilter< InputImageType > GradientFilterType
TriangleCellType::CellAutoPointer TriangleCellAutoPointer
void AddVertex(PointIdentifier &id, IndexType index, const InputImageType *image, OutputMeshType *mesh)
std::map< VertexLookupNode, PointIdentifier > MapType
ConstShapedNeighborhoodIterator< InputImageType > InputImageIteratorType
IndexType GetVertexLookupIndex(unsigned int vertex, IndexType index)
itk::VectorLinearInterpolateImageFunction< GradientImageType > GradientInterpolatorType
InputImageType::ConstPointer InputImageConstPointer
TriangleCellType::SelfAutoPointer TriangleAutoPointer
OutputImageType::PixelType OutputPixelType
void AddQuadFace(CellIdentifier &id, PointIdentifier f[4], OutputMeshType *mesh)
ImageToMeshFilter< TInputImage, TOutputMesh > Superclass
InputImageType::SpacingValueType SpacingValueType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetInput(unsigned int idx, const InputImageType *input)
OutputMeshType::CellsContainer CellsContainer
Define additional traits for native types such as int or float.
bool GetVertex(unsigned int x, unsigned int y, PointIdentifier &id)
Represents a quadrilateral for a Mesh.
OutputMeshType::PointsContainer PointsContainer
void AddVertex(unsigned int x, unsigned int y, PointIdentifier id)
OutputMeshType::PointsContainerPointer PointsContainerPointer
Linearly interpolate a vector image at specified positions.
Computes the gradient of an image using directional derivatives.