ITK  4.2.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 public:
99  typedef std::list< OutputEdgeCellType * > OutputEdgeCellListType;
100  typedef typename OutputEdgeCellListType::iterator OutputEdgeCellListIterator;
101 
102  typedef double CriterionValueType;
103  typedef std::pair< bool, CriterionValueType > PriorityType;
104 
107 
110  PriorityType,
112 
114  typedef std::map< OutputEdgeCellType *, PriorityQueueItemType * > QueueMapType;
115  typedef typename QueueMapType::iterator QueueMapIterator;
116 
120 
121  void SetListOfConstrainedEdges(const OutputEdgeCellListType & iList)
122  {
123  m_ListOfConstrainedEdges = iList;
124  }
125 
126 protected:
129  void PrintSelf(std::ostream & os, Indent indent) const;
130 
134 
137 
138  void GenerateData();
139 
140  void InitializePriorityQueue();
141 
142  void Process();
143 
144  inline CriterionValueType
145  Dyer07Criterion(OutputMeshType *iMesh, OutputQEType *iEdge) const
146  {
147  OutputPointIdentifier id1 = iEdge->GetOrigin();
148  OutputPointIdentifier id2 = iEdge->GetDestination();
149 
150  OutputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
151  OutputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
152 
153  OutputPointType pt1 = iMesh->GetPoint(id1);
154  OutputPointType pt2 = iMesh->GetPoint(id2);
155  OutputPointType ptA = iMesh->GetPoint(idA);
156  OutputPointType ptB = iMesh->GetPoint(idB);
157 
158  OutputVectorType v1A = ptA - pt1;
159  OutputVectorType v1B = ptB - pt1;
160  OutputVectorType v2A = ptA - pt2;
161  OutputVectorType v2B = ptB - pt2;
162 
163  OutputCoordRepType sq_norm1A = v1A * v1A;
164  OutputCoordRepType sq_norm1B = v1B * v1B;
165  OutputCoordRepType sq_norm2A = v2A * v2A;
166  OutputCoordRepType sq_norm2B = v2B * v2B;
167 
168  CriterionValueType dotA = static_cast< CriterionValueType >( v1A * v2A );
169  CriterionValueType dotB = static_cast< CriterionValueType >( v1B * v2B );
170  CriterionValueType den = static_cast< CriterionValueType >( sq_norm1A * sq_norm2A );
171 
172  if ( den != 0. )
173  {
174  dotA /= vcl_sqrt(den);
175  }
176 
177  if ( dotA > 1. )
178  {
179  dotA = 1.;
180  }
181 
182  if ( dotA < -1. )
183  {
184  dotA = -1.;
185  }
186 
187  den = static_cast< CriterionValueType >( sq_norm1B * sq_norm2B );
188 
189  if ( den != 0. )
190  {
191  dotB /= vcl_sqrt(den);
192  }
193 
194  if ( dotB > 1. )
195  {
196  dotB = 1.;
197  }
198 
199  if ( dotB < -1. )
200  {
201  dotB = -1.;
202  }
203 
204  return ( vcl_acos(dotA) + vcl_acos(dotB) - vnl_math::pi );
205  }
206 
207 private:
208 
209  DelaunayConformingQuadEdgeMeshFilter(const Self &); // Purposely not
210  // implemented
211  void operator=(const Self &); // Purposely not
212  // implemented
213 }; //
214 } // end namespace itk
215 
216 #include "itkDelaunayConformingQuadEdgeMeshFilter.hxx"
217 
218 #endif
219