ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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;
55 using InputMeshPointer = typename InputMeshType::Pointer;
56
57 using OutputMeshType = TOutput;
58 using OutputMeshPointer = typename OutputMeshType::Pointer;
59 using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
60 using OutputPointType = typename OutputMeshType::PointType;
61 using OutputVectorType = typename OutputPointType::VectorType;
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;
71 using CriterionType = TCriterion;
72 using CriterionPointer = typename CriterionType::Pointer;
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
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
184 [[nodiscard]] SizeValueType
186
190 void
192
197 void
199
203 void
205
211 virtual OutputPointType
212 Relocate(OutputQEType * iEdge) = 0;
213
219 bool
221 {
222 OutputMeshPointer output = this->GetOutput();
223 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 int replace_k(0);
258 OutputPointType pt[3];
259
260 while ((it != elements_to_be_tested.end()) && orientation_ok)
261 {
262 OutputCellIdentifier c_id = *it;
263 auto * poly = dynamic_cast<OutputPolygonType *>(cells->GetElement(c_id));
264
265 qe = poly->GetEdgeRingEntry();
266 qe_it = qe;
267 int k = 0;
268
269 do
270 {
271 OutputPointIdentifier p_id = qe_it->GetOrigin();
272 if (p_id == iId)
273 {
274 replace_k = k;
275 }
276 pt[k++] = output->GetPoint(p_id);
277 qe_it = qe_it->GetLnext();
278 } while (qe_it != qe);
279
280 OutputVectorType n_bef = TriangleType::ComputeNormal(pt[0], pt[1], pt[2]);
281 OutputVectorType n_aft;
282 switch (replace_k)
283 {
284 default:
285 case 0:
286 n_aft = TriangleType::ComputeNormal(iPt, pt[1], pt[2]);
287 break;
288 case 1:
289 n_aft = TriangleType::ComputeNormal(pt[0], iPt, pt[2]);
290 break;
291 case 2:
292 n_aft = TriangleType::ComputeNormal(pt[0], pt[1], iPt);
293 break;
294 }
295
296 orientation_ok = (n_bef * n_aft) < 0.;
297 ++it;
298 }
299
300 return orientation_ok;
301 }
302
307 bool
309};
310} // namespace itk
311
312#include "itkEdgeDecimationQuadEdgeMeshFilter.hxx"
313#endif
typename PriorityQueueType::Pointer PriorityQueuePointer
typename OutputPointType::VectorType OutputVectorType
bool ProcessWithTopologicalGuarantee() override
QuadEdgeMeshPolygonCell< OutputCellType > OutputPolygonType
virtual unsigned int CheckQEProcessingStatus()
void TagElementOut(OutputQEType *iEdge)
void DeleteElement(OutputQEType *iEdge)
Delete a given edge in the priority queue.
DecimationQuadEdgeMeshFilter< TInput, TOutput, TCriterion > Superclass
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...
PriorityQueueContainer< PriorityQueueItemType *, ElementWrapperPointerInterface< PriorityQueueItemType * >, PriorityType > PriorityQueueType
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
QuadEdgeMeshEulerOperatorJoinVertexFunction< OutputMeshType, OutputQEType > OperatorType
typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator
bool ProcessWithoutAnyTopologicalGuarantee() override
typename CriterionType::PriorityQueueWrapperType PriorityQueueItemType
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
OutputMeshType * GetOutput()
Implements transparent reference counting.
A convenience class for computation of various triangle elements in 2D or 3D.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86