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  OutputQEType * qe = iEdge;
226  OutputQEType * qe_it = qe->GetOnext();
227 
228  std::list<OutputCellIdentifier> r1;
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  std::list<OutputCellIdentifier> r2;
239  do
240  {
241  r2.push_back(qe_it->GetLeft());
242  qe_it = qe_it->GetOnext();
243  } while (qe_it != qe);
244 
245  r1.sort();
246  r2.sort();
247 
248  std::list<OutputCellIdentifier> elements_to_be_tested;
249  std::set_symmetric_difference(
250  r1.begin(), r1.end(), r2.begin(), r2.end(), std::back_inserter(elements_to_be_tested));
251 
252  typename std::list<OutputCellIdentifier>::iterator it = elements_to_be_tested.begin();
253 
254  using TriangleType = TriangleHelper<OutputPointType>;
255 
256  bool orientation_ok(true);
257  OutputCellIdentifier c_id(0);
258  OutputPolygonType * poly;
260 
261  int k(0);
262  int replace_k(0);
263  OutputPointType pt[3];
264 
265  while ((it != elements_to_be_tested.end()) && orientation_ok)
266  {
267  c_id = *it;
268  poly = dynamic_cast<OutputPolygonType *>(cells->GetElement(c_id));
269 
270  qe = poly->GetEdgeRingEntry();
271  qe_it = qe;
272  k = 0;
273 
274  do
275  {
276  p_id = qe_it->GetOrigin();
277  if (p_id == iId)
278  {
279  replace_k = k;
280  }
281  pt[k++] = output->GetPoint(p_id);
282  qe_it = qe_it->GetLnext();
283  } while (qe_it != qe);
284 
285  OutputVectorType n_bef = TriangleType::ComputeNormal(pt[0], pt[1], pt[2]);
286  OutputVectorType n_aft;
287  switch (replace_k)
288  {
289  default:
290  case 0:
291  n_aft = TriangleType::ComputeNormal(iPt, pt[1], pt[2]);
292  break;
293  case 1:
294  n_aft = TriangleType::ComputeNormal(pt[0], iPt, pt[2]);
295  break;
296  case 2:
297  n_aft = TriangleType::ComputeNormal(pt[0], pt[1], iPt);
298  break;
299  }
300 
301  orientation_ok = (n_bef * n_aft) < 0.;
302  ++it;
303  }
304 
305  return orientation_ok;
306  }
307 
312  bool
313  IsCriterionSatisfied() override;
314 };
315 } // namespace itk
316 
317 #include "itkEdgeDecimationQuadEdgeMeshFilter.hxx"
318 #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