ITK  5.0.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 "itkMath.h"
26 
27 namespace itk
28 {
36 template< typename TInputMesh, typename TOutputMesh=TInputMesh >
37 class ITK_TEMPLATE_EXPORT DelaunayConformingQuadEdgeMeshFilter:
38  public QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh, TOutputMesh >
39 {
40 public:
41 
44  using Superclass = QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh,
45  TOutputMesh >;
48 
50  using InputMeshType = TInputMesh;
51  using InputMeshPointer = typename InputMeshType::Pointer;
52  using InputCoordRepType = typename InputMeshType::CoordRepType;
55  using InputPointIdentifier = typename InputMeshType::PointIdentifier;
56  using InputQEType = typename InputMeshType::QEType;
58  using InputEdgeListType = typename InputMeshType::EdgeListType;
59  using InputPixelType = typename InputMeshType::PixelType;
60  using InputTraits = typename InputMeshType::Traits;
61 
62  static constexpr unsigned int InputVDimension = InputMeshType::PointDimension;
63 
64  using InputPointsContainer = typename InputMeshType::PointsContainer;
65  using InputPointsContainerConstIterator = typename InputMeshType::PointsContainerConstIterator;
66  using InputCellsContainerConstIterator = typename InputMeshType::CellsContainerConstIterator;
67  using InputEdgeCellType = typename InputMeshType::EdgeCellType;
68  using InputPolygonCellType = typename InputMeshType::PolygonCellType;
69  using InputPointIdList = typename InputMeshType::PointIdList;
70 
71  using InputQEIterator = typename InputQEType::IteratorGeom;
72 
74  using OutputMeshType = TOutputMesh;
75  using OutputMeshPointer = typename OutputMeshType::Pointer;
76  using OutputCoordRepType = typename OutputMeshType::CoordRepType;
78  using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
79  using OutputCellType = typename OutputMeshType::CellType;
80  using OutputCellIdentifier = typename OutputMeshType::CellIdentifier;
81  using OutputEdgeCellType = typename OutputMeshType::EdgeCellType;
82  using OutputQEType = typename OutputMeshType::QEType;
83  using OutputLineCellIdentifier = typename OutputQEType::LineCellIdentifier;
85  using OutputQEIterator = typename OutputQEType::IteratorGeom;
86  using OutputPointsContainerPointer = typename OutputMeshType::PointsContainerPointer;
87  using OutputPointsContainerIterator = typename OutputMeshType::PointsContainerIterator;
88  using OutputCellsContainer = typename OutputMeshType::CellsContainer;
89  using OutputCellsContainerIterator = typename OutputMeshType::CellsContainerIterator;
90 
91  static constexpr unsigned int OutputVDimension = OutputMeshType::PointDimension;
92 
93  itkNewMacro(Self);
95 
96  itkGetConstMacro(NumberOfEdgeFlips, SizeValueType);
97 
98 public:
99  using OutputEdgeCellListType = std::list< OutputEdgeCellType * >;
100  using OutputEdgeCellListIterator = typename OutputEdgeCellListType::iterator;
101 
102  using CriterionValueType = double;
103  using PriorityType = std::pair< bool, CriterionValueType >;
104 
107 
110  PriorityType,
111  long >;
112 
114  using QueueMapType = std::map< OutputEdgeCellType *, PriorityQueueItemType * >;
115  using QueueMapIterator = typename QueueMapType::iterator;
116 
120 
122  {
123  m_ListOfConstrainedEdges = iList;
124  }
125 
126 protected:
129  void PrintSelf(std::ostream & os, Indent indent) const override;
130 
134 
137 
138  void GenerateData() override;
139 
140  void InitializePriorityQueue();
141 
142  void Process();
143 
144  inline CriterionValueType
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  auto dotA = static_cast< CriterionValueType >( v1A * v2A );
169  auto dotB = static_cast< CriterionValueType >( v1B * v2B );
170  auto den = static_cast< CriterionValueType >( sq_norm1A * sq_norm2A );
171 
172  if ( den != 0. )
173  {
174  dotA /= std::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 /= std::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 ( std::acos(dotA) + std::acos(dotB) - itk::Math::pi );
205  }
206 
207 private:
208 
209  DelaunayConformingQuadEdgeMeshFilter(const Self &) = delete;
210  void operator=(const Self &) = delete;
211 };
212 } // end namespace itk
213 
214 #include "itkDelaunayConformingQuadEdgeMeshFilter.hxx"
215 
216 #endif
typename InputMeshType::CoordRepType InputCoordRepType
typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator
Light weight base class for most itk classes.
TOutputMesh OutputMeshType
Definition: itkMeshSource.h:68
typename InputQEPrimal::IteratorGeom InputQEIterator
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename FlipEdgeFunctionType::Pointer FlipEdgeFunctionPointer
typename InputMeshType::PointIdentifier InputPointIdentifier
static constexpr double pi
Definition: itkMath.h:63
std::map< OutputEdgeCellType *, PriorityQueueItemType * > QueueMapType
typename InputMeshType::PolygonCellType InputPolygonCellType
typename OutputMeshType::PointIdentifier OutputPointIdentifier
typename OutputMeshType::CoordRepType OutputCoordRepType
typename InputMeshType::Pointer InputMeshPointer
typename OutputMeshType::CellsContainer OutputCellsContainer
typename InputMeshType::PointsContainerConstIterator InputPointsContainerConstIterator
CriterionValueType Dyer07Criterion(OutputMeshType *iMesh, OutputQEType *iEdge) const
typename OutputMeshType::CellIdentifier OutputCellIdentifier
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkMeshSource.h:69
typename OutputEdgeCellListType::iterator OutputEdgeCellListIterator
typename InputMeshType::EdgeCellType InputEdgeCellType
typename OutputQEType::LineCellIdentifier OutputLineCellIdentifier
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename InputMeshType::PointsContainer InputPointsContainer
typename OutputMeshType::VectorType OutputVectorType
typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer
typename InputMeshType::CellsContainerConstIterator InputCellsContainerConstIterator
typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator
void SetListOfConstrainedEdges(const OutputEdgeCellListType &iList)
typename InputMeshType::PointIdList InputPointIdList
typename OutputQEPrimal::IteratorGeom OutputQEIterator