ITK  4.13.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;
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;
155  typedef typename InputImageType::SpacingType SpacingType;
156  typedef typename InputImageType::SpacingValueType SpacingValueType;
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  ITK_DISALLOW_COPY_AND_ASSIGN(CuberilleImageToMeshFilter);
252 
256  {
257  public:
260 
262  VertexLookupNode() : m_X( 0 ), m_Y( 0 ) { }
263  VertexLookupNode(unsigned long x, unsigned long y) : m_X( x ), m_Y( y ) { }
265 
267  unsigned long GetX() { return m_X; }
268  unsigned long GetY() { return m_Y; }
270 
272  bool operator> ( const Self& node ) const
273  { return (m_Y > node.m_Y) || ( (m_Y == node.m_Y) && (m_X > node.m_X) ); }
274  bool operator>= ( const Self& node ) const
275  { return (m_Y >= node.m_Y) || ( (m_Y == node.m_Y) && (m_X >= node.m_X) ); }
276  bool operator< ( const Self& node ) const
277  { return (m_Y < node.m_Y) || ( (m_Y == node.m_Y) && (m_X < node.m_X) ); }
278  bool operator<= ( const Self& node ) const
279  { return (m_Y <= node.m_Y) || ( (m_Y == node.m_Y) && (m_X <= node.m_X) ); }
281 
282  private:
283  unsigned long m_X;
284  unsigned long m_Y;
285  };
286 
289  template< class TMeshType >
291  {
292  public:
295  typedef typename TMeshType::PointIdentifier PointIdentifier;
296  typedef std::map< VertexLookupNode, PointIdentifier > MapType;
297 
300 
302  void Clear() { m_Map.clear(); }
303 
305  void AddVertex( unsigned int x, unsigned int y, PointIdentifier id )
306  {
307  VertexLookupNode node( x, y );
308  m_Map.insert( typename MapType::value_type(node, id) );
309  }
311 
315  bool GetVertex( unsigned int x, unsigned int y, PointIdentifier &id )
316  {
317  bool result = false;
318  VertexLookupNode node( x, y );
319  typename MapType::iterator it = m_Map.find( node );
320  if ( it != m_Map.end() )
321  {
322  result = true;
323  id = it->second;
324  }
325  return result;
326  }
328 
329  private:
331  };
332 
335 
337  inline void ComputeGradientImage();
338  inline void SetVerticesFromFace( unsigned int face, bool *vertexHasQuad );
339  inline IndexType GetVertexLookupIndex( unsigned int vertex, IndexType index );
340  inline void ProjectVertexToIsoSurface( PointType &vertex );
341  inline void AddVertex( PointIdentifier &id, IndexType index, const InputImageType* image, OutputMeshType* mesh );
342  inline void AddQuadFace( CellIdentifier &id, PointIdentifier f[4], OutputMeshType* mesh );
344 
355 #if DEBUG_PRINT
356  unsigned int m_ProjectVertexTerminate[3];
357 #endif
358 };
359 
360 } // end namespace itk
361 
362 #ifndef ITK_MANUAL_INSTANTIATION
363 #include "itkCuberilleImageToMeshFilter.hxx"
364 #endif
365 
366 #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
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.