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
32namespace itk
33{
39template <typename TInput, typename TOutput, typename TCriterion>
40class ITK_TEMPLATE_EXPORT EdgeDecimationQuadEdgeMeshFilter
41 : public DecimationQuadEdgeMeshFilter<TInput, TOutput, TCriterion>
42{
43public:
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
89protected:
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
109
113 void
115
120 void
122
128 bool
130
134 void
135 Extract() override;
136
141 void
143
144 virtual void
145 DeletePoint(const OutputPointIdentifier & iIdToBeDeleted, const OutputPointIdentifier & iRemaining);
146
152 virtual void
154
158 virtual void
160
164 bool
166
171 virtual unsigned int
173
178 bool
180
186
190 void
192
197 void
199
203 void
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
312};
313} // namespace itk
314
315#include "itkEdgeDecimationQuadEdgeMeshFilter.hxx"
316#endif
typename CriterionType::Pointer CriterionPointer
typename CriterionType::PriorityQueueWrapperType PriorityQueueItemType
typename InputMeshType::Pointer InputMeshPointer
typename CriterionType::PriorityType PriorityType
typename CriterionType::MeasureType MeasureType
typename OutputMeshType::Pointer OutputMeshPointer
typename PriorityQueueType::Pointer PriorityQueuePointer
typename OutputPointType::VectorType OutputVectorType
bool ProcessWithTopologicalGuarantee() override
virtual unsigned int CheckQEProcessingStatus()
void TagElementOut(OutputQEType *iEdge)
void DeleteElement(OutputQEType *iEdge)
Delete a given edge in the priority queue.
bool CheckOrientation(OutputQEType *iEdge, const OutputPointIdentifier &iId, const OutputPointType &iPt)
typename QueueMapType::const_iterator QueueMapConstIterator
typename OutputMeshType::PointIdentifier OutputPointIdentifier
void FillPriorityQueue() override
Fill the priority queue.
virtual void PushOrUpdateElement(OutputQEType *iEdge)
Push iEdge in the priority queue if it is not already, else its corresponding priority value is updat...
void Extract() override
Extract the edge to be processed.
typename OutputMeshType::EdgeCellType OutputEdgeCellType
void PushElement(OutputQEType *iEdge)
Push one edge in the priority queue.
typename OutputMeshType::CellsContainerPointer OutputCellsContainerPointer
std::map< OutputQEType *, PriorityQueueItemType * > QueueMapType
typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator
bool ProcessWithoutAnyTopologicalGuarantee() override
virtual void DeletePoint(const OutputPointIdentifier &iIdToBeDeleted, const OutputPointIdentifier &iRemaining)
bool IsEdgeOKToBeProcessed(OutputQEType *iEdge)
Check if iEdge is valid and then can be processed.
virtual OutputPointType Relocate(OutputQEType *iEdge)=0
virtual MeasureType MeasureEdge(OutputQEType *iEdge)=0
Compute the measure value for iEdge.
typename OutputMeshType::CellIdentifier OutputCellIdentifier
SizeValueType NumberOfCommonVerticesIn0Ring() const
Light weight base class for most itk classes.
Collapse a given edge by joining its dest and its org.
A convenience class for computation of various triangle elements in 2D or 3D.
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86