ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkQuadricDecimationQuadEdgeMeshFilter.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 itkQuadricDecimationQuadEdgeMeshFilter_h
19 #define itkQuadricDecimationQuadEdgeMeshFilter_h
20 
23 
24 namespace itk
25 {
31 template< typename TInput, typename TOutput, typename TCriterion >
32 class ITK_TEMPLATE_EXPORT QuadricDecimationQuadEdgeMeshFilter:
33  public EdgeDecimationQuadEdgeMeshFilter< TInput, TOutput, TCriterion >
34 {
35 public:
36  ITK_DISALLOW_COPY_AND_ASSIGN(QuadricDecimationQuadEdgeMeshFilter);
37 
42  TInput, TOutput, TCriterion >;
43 
46 
48  itkNewMacro(Self);
49 
50  using InputMeshType = TInput;
51  using InputMeshPointer = typename InputMeshType::Pointer;
52 
53  using OutputMeshType = TOutput;
54  using OutputMeshPointer = typename OutputMeshType::Pointer;
55  using OutputPointIdentifier = typename OutputMeshType::PointIdentifier;
57  using OutputCoordType = typename OutputPointType::CoordRepType;
58  using OutputQEType = typename OutputMeshType::QEType;
59  using OutputEdgeCellType = typename OutputMeshType::EdgeCellType;
60  using OutputCellsContainerIterator = typename OutputMeshType::CellsContainerIterator;
61  using OutputPointsContainerPointer = typename OutputMeshType::PointsContainerPointer;
62  using OutputPointsContainerIterator = typename OutputMeshType::PointsContainerIterator;
63 
64  static constexpr unsigned int OutputPointDimension = OutputMeshType::PointDimension;
65 
66  using CriterionType = TCriterion;
67  using MeasureType = typename CriterionType::MeasureType;
68 
69  using PriorityType = typename Superclass::PriorityType;
70  using PriorityQueueItemType = typename Superclass::PriorityQueueItemType;
71  using PriorityQueueType = typename Superclass::PriorityQueueType;
72  using PriorityQueuePointer = typename Superclass::PriorityQueuePointer;
73 
74  using QueueMapType = typename Superclass::QueueMapType;
75  using QueueMapIterator = typename Superclass::QueueMapIterator;
76 
77  using OperatorType = typename Superclass::OperatorType;
78  using OperatorPointer = typename Superclass::OperatorPointer;
79 
81 
82  using QuadricElementMapType =
83  std::map< OutputPointIdentifier, QuadricElementType >;
84 
85  using QuadricElementMapIterator = typename QuadricElementMapType::iterator;
86 
87 protected:
90 
92  ~QuadricDecimationQuadEdgeMeshFilter() override = default;
93 
99  inline void QuadricAtOrigin(OutputQEType *iEdge, QuadricElementType & oQ, OutputMeshType *outputMesh)
100  {
101  OutputPointIdentifier id[3];
102 
103  id[0] = iEdge->GetOrigin();
104  id[1] = iEdge->GetDestination();
105  id[2] = iEdge->GetOnext()->GetDestination();
106 
107  OutputPointType p[3];
108 
109  for ( int i = 0; i < 3; i++ )
110  {
111  p[i] = outputMesh->GetPoint(id[i]);
112  }
113 
114  oQ.AddTriangle(p[0], p[1], p[2]);
115  }
116 
122  {
123  OutputPointIdentifier id_org = iEdge->GetOrigin();
124  OutputPointIdentifier id_dest = iEdge->GetDestination();
125  QuadricElementType Q = m_Quadric[id_org] + m_Quadric[id_dest];
126 
127  OutputPointType org = this->m_OutputMesh->GetPoint(id_org);
128  OutputPointType dest = this->m_OutputMesh->GetPoint(id_dest);
129 
130  OutputPointType mid;
131 
132  mid.SetToMidPoint(org, dest);
134 
135  return static_cast< MeasureType >( Q.ComputeError(p) );
136  }
137 
142  void DeletePoint(const OutputPointIdentifier & iIdToBeDeleted,
143  const OutputPointIdentifier & iRemaining) override;
144 
149  OutputPointType Relocate(OutputQEType *iEdge) override;
150 
152  void Initialize() override;
153 
154 private:
156 };
157 }
158 #ifndef ITK_MANUAL_INSTANTIATION
159 #include "itkQuadricDecimationQuadEdgeMeshFilter.hxx"
160 #endif
161 #endif
typename OutputMeshType::CellsContainerIterator OutputCellsContainerIterator
Light weight base class for most itk classes.
void QuadricAtOrigin(OutputQEType *iEdge, QuadricElementType &oQ, OutputMeshType *outputMesh)
Compute the quadric error at the origin of the edge.
std::map< OutputQEType *, PriorityQueueItemType * > QueueMapType
Collapse a given edge by joining its dest and its org.
typename PriorityQueueType::Pointer PriorityQueuePointer
typename QuadricElementMapType::iterator QuadricElementMapIterator
typename CriterionType::PriorityQueueWrapperType PriorityQueueItemType
typename CriterionType::MeasureType MeasureType
typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator
typename CriterionType::PriorityType PriorityType
std::map< OutputPointIdentifier, QuadricElementType > QuadricElementMapType
CoordType ComputeError(const PointType &iP) const
TODO this method should be really optimized!!!
typename OutputMeshType::Pointer OutputMeshPointer
typename OutputMeshType::PointIdentifier OutputPointIdentifier
typename OutputMeshType::PointsContainerPointer OutputPointsContainerPointer
MeasureType MeasureEdge(OutputQEType *iEdge) override
Compute the measure value for iEdge.
void AddTriangle(const PointType &iP1, const PointType &iP2, const PointType &iP3, const CoordType &iWeight=static_cast< CoordType >(1.))
typename InputMeshType::Pointer InputMeshPointer
typename OutputMeshType::EdgeCellType OutputEdgeCellType