ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkDelaunayConformingQuadEdgeMeshFilter.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 __itkDelaunayConformingQuadEdgeMeshFilter_h
19 #define __itkDelaunayConformingQuadEdgeMeshFilter_h
20 
21 #include "itkIntTypes.h"
25 #include "vcl_cmath.h"
26 #include "vnl/vnl_math.h"
27 
28 namespace itk
29 {
37 template< class TInputMesh, class TOutputMesh=TInputMesh >
39  public QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh, TOutputMesh >
40 {
41 public:
42 
45  typedef QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh,
46  TOutputMesh > Superclass;
49 
51  typedef TInputMesh InputMeshType;
52  typedef typename InputMeshType::Pointer InputMeshPointer;
53  typedef typename InputMeshType::CoordRepType InputCoordRepType;
54  typedef typename InputMeshType::PointType InputPointType;
55  typedef typename InputPointType::VectorType InputPointVectorType;
56  typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
57  typedef typename InputMeshType::QEType InputQEType;
58  typedef typename InputMeshType::VectorType InputVectorType;
59  typedef typename InputMeshType::EdgeListType InputEdgeListType;
60  typedef typename InputMeshType::PixelType InputPixelType;
61  typedef typename InputMeshType::Traits InputTraits;
62 
63  itkStaticConstMacro(InputVDimension, unsigned int, InputMeshType::PointDimension);
64 
65  typedef typename InputMeshType::PointsContainer InputPointsContainer;
66  typedef typename InputMeshType::PointsContainerConstIterator InputPointsContainerConstIterator;
67  typedef typename InputMeshType::CellsContainerConstIterator InputCellsContainerConstIterator;
68  typedef typename InputMeshType::EdgeCellType InputEdgeCellType;
69  typedef typename InputMeshType::PolygonCellType InputPolygonCellType;
70  typedef typename InputMeshType::PointIdList InputPointIdList;
71 
72  typedef typename InputQEType::IteratorGeom InputQEIterator;
73 
75  typedef TOutputMesh OutputMeshType;
76  typedef typename OutputMeshType::Pointer OutputMeshPointer;
77  typedef typename OutputMeshType::CoordRepType OutputCoordRepType;
78  typedef typename OutputMeshType::PointType OutputPointType;
79  typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
80  typedef typename OutputMeshType::CellType OutputCellType;
81  typedef typename OutputMeshType::CellIdentifier OutputCellIdentifier;
82  typedef typename OutputMeshType::EdgeCellType OutputEdgeCellType;
83  typedef typename OutputMeshType::QEType OutputQEType;
84  typedef typename OutputQEType::LineCellIdentifier OutputLineCellIdentifier;
85  typedef typename OutputMeshType::VectorType OutputVectorType;
86  typedef typename OutputQEType::IteratorGeom OutputQEIterator;
87  typedef typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer;
88  typedef typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator;
89  typedef typename OutputMeshType::CellsContainer OutputCellsContainer;
90  typedef typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator;
91 
92  itkStaticConstMacro(OutputVDimension, unsigned int, OutputMeshType::PointDimension);
93 
94  itkNewMacro(Self);
96 
97  itkGetConstMacro(NumberOfEdgeFlips, SizeValueType);
98 
99 public:
100  typedef std::list< OutputEdgeCellType * > OutputEdgeCellListType;
101  typedef typename OutputEdgeCellListType::iterator OutputEdgeCellListIterator;
102 
103  typedef double CriterionValueType;
104  typedef std::pair< bool, CriterionValueType > PriorityType;
105 
108 
111  PriorityType,
113 
115  typedef std::map< OutputEdgeCellType *, PriorityQueueItemType * > QueueMapType;
116  typedef typename QueueMapType::iterator QueueMapIterator;
117 
121 
122  void SetListOfConstrainedEdges(const OutputEdgeCellListType & iList)
123  {
124  m_ListOfConstrainedEdges = iList;
125  }
126 
127 protected:
130  void PrintSelf(std::ostream & os, Indent indent) const;
131 
135 
138 
139  void GenerateData();
140 
141  void InitializePriorityQueue();
142 
143  void Process();
144 
145  inline CriterionValueType
146  Dyer07Criterion(OutputMeshType *iMesh, OutputQEType *iEdge) const
147  {
148  OutputPointIdentifier id1 = iEdge->GetOrigin();
149  OutputPointIdentifier id2 = iEdge->GetDestination();
150 
151  OutputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
152  OutputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
153 
154  OutputPointType pt1 = iMesh->GetPoint(id1);
155  OutputPointType pt2 = iMesh->GetPoint(id2);
156  OutputPointType ptA = iMesh->GetPoint(idA);
157  OutputPointType ptB = iMesh->GetPoint(idB);
158 
159  OutputVectorType v1A = ptA - pt1;
160  OutputVectorType v1B = ptB - pt1;
161  OutputVectorType v2A = ptA - pt2;
162  OutputVectorType v2B = ptB - pt2;
163 
164  OutputCoordRepType sq_norm1A = v1A * v1A;
165  OutputCoordRepType sq_norm1B = v1B * v1B;
166  OutputCoordRepType sq_norm2A = v2A * v2A;
167  OutputCoordRepType sq_norm2B = v2B * v2B;
168 
169  CriterionValueType dotA = static_cast< CriterionValueType >( v1A * v2A );
170  CriterionValueType dotB = static_cast< CriterionValueType >( v1B * v2B );
171  CriterionValueType den = static_cast< CriterionValueType >( sq_norm1A * sq_norm2A );
172 
173  if ( den != 0. )
174  {
175  dotA /= vcl_sqrt(den);
176  }
177 
178  if ( dotA > 1. )
179  {
180  dotA = 1.;
181  }
182 
183  if ( dotA < -1. )
184  {
185  dotA = -1.;
186  }
187 
188  den = static_cast< CriterionValueType >( sq_norm1B * sq_norm2B );
189 
190  if ( den != 0. )
191  {
192  dotB /= vcl_sqrt(den);
193  }
194 
195  if ( dotB > 1. )
196  {
197  dotB = 1.;
198  }
199 
200  if ( dotB < -1. )
201  {
202  dotB = -1.;
203  }
204 
205  return ( vcl_acos(dotA) + vcl_acos(dotB) - vnl_math::pi );
206  }
207 
208 private:
209 
210  DelaunayConformingQuadEdgeMeshFilter(const Self &); // Purposely not
211  // implemented
212  void operator=(const Self &); // Purposely not
213  // implemented
214 }; //
215 } // end namespace itk
216 
217 #include "itkDelaunayConformingQuadEdgeMeshFilter.hxx"
218 
219 #endif
220