ITK  6.0.0
Insight Toolkit
itkEdgeDecimationQuadEdgeMeshFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkEdgeDecimationQuadEdgeMeshFilter_h
19 #define itkEdgeDecimationQuadEdgeMeshFilter_h
20 
21 #include <list>
22 #include <map>
23 #include <algorithm>
24 
27 
30 #include "itkTriangleHelper.h"
31 
32 namespace itk
33 {
39 template <typename TInput, typename TOutput, typename TCriterion>
40 class ITK_TEMPLATE_EXPORT EdgeDecimationQuadEdgeMeshFilter
41  : public DecimationQuadEdgeMeshFilter<TInput, TOutput, TCriterion>
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_MOVE(EdgeDecimationQuadEdgeMeshFilter);
45 
50 
52  itkOverrideGetNameOfClassMacro(EdgeDecimationQuadEdgeMeshFilter);
53 
54  using InputMeshType = TInput;
56 
57  using OutputMeshType = TOutput;
59  using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
62  using OutputQEType = typename OutputMeshType::QEType;
63  using OutputEdgeCellType = typename OutputMeshType::EdgeCellType;
64  using OutputCellType = typename OutputMeshType::CellType;
65  using OutputCellIdentifier = typename OutputMeshType::CellIdentifier;
66  using OutputCellsContainerPointer = typename OutputMeshType::CellsContainerPointer;
67  using OutputCellsContainerIterator = typename OutputMeshType::CellsContainerIterator;
68 
70 
71  using CriterionType = TCriterion;
73  using MeasureType = typename CriterionType::MeasureType;
74  using PriorityType = typename CriterionType::PriorityType;
75  using PriorityQueueItemType = typename CriterionType::PriorityQueueWrapperType;
76 
81 
82  using QueueMapType = std::map<OutputQEType *, PriorityQueueItemType *>;
83  using QueueMapConstIterator = typename QueueMapType::const_iterator;
84  using QueueMapIterator = typename QueueMapType::iterator;
85 
88 
89 protected:
92 
93  bool m_Relocate{ true };
94  bool m_CheckOrientation{ false };
95 
96  PriorityQueuePointer m_PriorityQueue{};
97  QueueMapType m_QueueMapper{};
98  OutputQEType * m_Element{};
99  PriorityType m_Priority{};
100  OperatorPointer m_JoinVertexFunction{};
101 
107  virtual MeasureType
108  MeasureEdge(OutputQEType * iEdge) = 0;
109 
113  void
114  FillPriorityQueue() override;
115 
120  void
121  PushElement(OutputQEType * iEdge);
122 
128  bool
129  IsEdgeOKToBeProcessed(OutputQEType * iEdge);
130 
134  void
135  Extract() override;
136 
141  void
142  DeleteElement(OutputQEType * iEdge);
143 
144  virtual void
145  DeletePoint(const OutputPointIdentifier & iIdToBeDeleted, const OutputPointIdentifier & iRemaining);
146 
152  virtual void
153  PushOrUpdateElement(OutputQEType * iEdge);
154 
158  virtual void
159  JoinVertexFailed();
160 
164  bool
165  ProcessWithoutAnyTopologicalGuarantee() override;
166 
171  virtual unsigned int
172  CheckQEProcessingStatus();
173 
178  bool
179  ProcessWithTopologicalGuarantee() override;
180 
185  NumberOfCommonVerticesIn0Ring() const;
186 
190  void
191  RemoveSamosa();
192 
197  void
198  TagElementOut(OutputQEType * iEdge);
199 
203  void
204  RemoveEye();
205 
211  virtual OutputPointType
212  Relocate(OutputQEType * iEdge) = 0;
213 
218  bool
220  {
221  OutputMeshPointer output = this->GetOutput();
222  OutputCellsContainerPointer cells = output->GetCells();
225  std::list<OutputCellIdentifier> r1, r2, elements_to_be_tested;
226  OutputQEType * qe = iEdge;
227  OutputQEType * qe_it = qe->GetOnext();
228 
229  do
230  {
231  r1.push_back(qe_it->GetLeft());
232  qe_it = qe_it->GetOnext();
233  } while (qe_it != qe);
234 
235  qe = iEdge->GetSym();
236  qe_it = qe->GetOnext();
237 
238  do
239  {
240  r2.push_back(qe_it->GetLeft());
241  qe_it = qe_it->GetOnext();
242  } while (qe_it != qe);
243 
244  r1.sort();
245  r2.sort();
246 
247  std::set_symmetric_difference(
248  r1.begin(), r1.end(), r2.begin(), r2.end(), std::back_inserter(elements_to_be_tested));
249 
250  typename std::list<OutputCellIdentifier>::iterator it = elements_to_be_tested.begin();
251 
252  using TriangleType = TriangleHelper<OutputPointType>;
253 
254  bool orientation_ok(true);
255  OutputCellIdentifier c_id(0);
256  OutputPolygonType * poly;
258 
259  int k(0), replace_k(0);
260  OutputPointType pt[3];
261 
262  OutputVectorType n_bef, n_aft;
263 
264  while ((it != elements_to_be_tested.end()) && orientation_ok)
265  {
266  c_id = *it;
267  poly = dynamic_cast<OutputPolygonType *>(cells->GetElement(c_id));
268 
269  qe = poly->GetEdgeRingEntry();
270  qe_it = qe;
271  k = 0;
272 
273  do
274  {
275  p_id = qe_it->GetOrigin();
276  if (p_id == iId)
277  {
278  replace_k = k;
279  }
280  pt[k++] = output->GetPoint(p_id);
281  qe_it = qe_it->GetLnext();
282  } while (qe_it != qe);
283 
284  n_bef = TriangleType::ComputeNormal(pt[0], pt[1], pt[2]);
285  switch (replace_k)
286  {
287  default:
288  case 0:
289  n_aft = TriangleType::ComputeNormal(iPt, pt[1], pt[2]);
290  break;
291  case 1:
292  n_aft = TriangleType::ComputeNormal(pt[0], iPt, pt[2]);
293  break;
294  case 2:
295  n_aft = TriangleType::ComputeNormal(pt[0], pt[1], iPt);
296  break;
297  }
298 
299  orientation_ok = (n_bef * n_aft) < 0.;
300  ++it;
301  }
302 
303  return orientation_ok;
304  }
305 
310  bool
311  IsCriterionSatisfied() override;
312 };
313 } // namespace itk
314 
315 #include "itkEdgeDecimationQuadEdgeMeshFilter.hxx"
316 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::DecimationQuadEdgeMeshFilter::MeasureType
typename CriterionType::MeasureType MeasureType
Definition: itkDecimationQuadEdgeMeshFilter.h:53
itkQuadEdgeMeshEulerOperatorJoinVertexFunction.h
itk::EdgeDecimationQuadEdgeMeshFilter::OutputCellType
typename OutputMeshType::CellType OutputCellType
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:64
itk::EdgeDecimationQuadEdgeMeshFilter::QueueMapIterator
typename QueueMapType::iterator QueueMapIterator
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:84
itk::EdgeDecimationQuadEdgeMeshFilter::OutputCellsContainerIterator
typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:67
itk::EdgeDecimationQuadEdgeMeshFilter::QueueMapType
std::map< OutputQEType *, PriorityQueueItemType * > QueueMapType
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:82
itkDecimationQuadEdgeMeshFilter.h
itk::QuadEdgeMeshPolygonCell::GetEdgeRingEntry
QuadEdgeType * GetEdgeRingEntry() const
Definition: itkQuadEdgeMeshPolygonCell.h:120
itk::EdgeDecimationQuadEdgeMeshFilter::OutputQEType
typename OutputMeshType::QEType OutputQEType
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:62
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::EdgeDecimationQuadEdgeMeshFilter::OutputEdgeCellType
typename OutputMeshType::EdgeCellType OutputEdgeCellType
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:63
itk::SmartPointer< Self >
itk::DecimationQuadEdgeMeshFilter::CriterionType
TCriterion CriterionType
Definition: itkDecimationQuadEdgeMeshFilter.h:51
itk::EdgeDecimationQuadEdgeMeshFilter::OutputCellIdentifier
typename OutputMeshType::CellIdentifier OutputCellIdentifier
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:65
itk::TriangleHelper
A convenience class for computation of various triangle elements in 2D or 3D.
Definition: itkTriangleHelper.h:31
itk::EdgeDecimationQuadEdgeMeshFilter::OutputPointIdentifier
typename OutputMeshType::PointIdentifier OutputPointIdentifier
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:59
itk::DecimationQuadEdgeMeshFilter::OutputMeshPointer
typename OutputMeshType::Pointer OutputMeshPointer
Definition: itkDecimationQuadEdgeMeshFilter.h:49
itk::DecimationQuadEdgeMeshFilter::InputMeshType
TInput InputMeshType
Definition: itkDecimationQuadEdgeMeshFilter.h:45
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::DecimationQuadEdgeMeshFilter
Definition: itkDecimationQuadEdgeMeshFilter.h:32
itk::EdgeDecimationQuadEdgeMeshFilter::OutputVectorType
typename OutputPointType::VectorType OutputVectorType
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:61
itk::QuadEdgeMeshPolygonCell
Definition: itkQuadEdgeMeshPolygonCell.h:39
itk::DecimationQuadEdgeMeshFilter::PriorityQueueItemType
typename CriterionType::PriorityQueueWrapperType PriorityQueueItemType
Definition: itkDecimationQuadEdgeMeshFilter.h:55
itkPriorityQueueContainer.h
itkQuadEdgeMeshPolygonCell.h
itk::DecimationQuadEdgeMeshFilter::InputMeshPointer
typename InputMeshType::Pointer InputMeshPointer
Definition: itkDecimationQuadEdgeMeshFilter.h:46
itkTriangleHelper.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::QuadEdgeMeshEulerOperatorJoinVertexFunction
Collapse a given edge by joining its dest and its org.
Definition: itkQuadEdgeMeshEulerOperatorJoinVertexFunction.h:57
itk::EdgeDecimationQuadEdgeMeshFilter
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:40
itk::ElementWrapperPointerInterface
Definition: itkPriorityQueueContainer.h:69
itk::EdgeDecimationQuadEdgeMeshFilter::QueueMapConstIterator
typename QueueMapType::const_iterator QueueMapConstIterator
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:83
itk::EdgeDecimationQuadEdgeMeshFilter::OutputPointType
typename OutputMeshType::PointType OutputPointType
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:60
itk::EdgeDecimationQuadEdgeMeshFilter::OperatorPointer
typename OperatorType::Pointer OperatorPointer
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:87
itk::DecimationQuadEdgeMeshFilter::PriorityType
typename CriterionType::PriorityType PriorityType
Definition: itkDecimationQuadEdgeMeshFilter.h:54
itk::DecimationQuadEdgeMeshFilter::CriterionPointer
typename CriterionType::Pointer CriterionPointer
Definition: itkDecimationQuadEdgeMeshFilter.h:52
itk::EdgeDecimationQuadEdgeMeshFilter::CheckOrientation
bool CheckOrientation(OutputQEType *iEdge, const OutputPointIdentifier &iId, const OutputPointType &iPt)
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:219
itk::DecimationQuadEdgeMeshFilter::OutputMeshType
TOutput OutputMeshType
Definition: itkDecimationQuadEdgeMeshFilter.h:48
itk::EdgeDecimationQuadEdgeMeshFilter::PriorityQueuePointer
typename PriorityQueueType::Pointer PriorityQueuePointer
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:80
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::PriorityQueueContainer
Definition: itkPriorityQueueContainer.h:193
itk::EdgeDecimationQuadEdgeMeshFilter::OutputCellsContainerPointer
typename OutputMeshType::CellsContainerPointer OutputCellsContainerPointer
Definition: itkEdgeDecimationQuadEdgeMeshFilter.h:66