ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSimplexMeshAdaptTopologyFilter.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 itkSimplexMeshAdaptTopologyFilter_h
19#define itkSimplexMeshAdaptTopologyFilter_h
20
21#include "itkPolygonCell.h"
23
24#include "itkSimplexMesh.h"
25#include "itkMeshToMeshFilter.h"
26#include "itkVectorContainer.h"
27
28#include "vxl_version.h"
29#include "vnl/vnl_cross.h"
30
31namespace itk
32{
44template <typename TInputMesh, typename TOutputMesh>
45class ITK_TEMPLATE_EXPORT SimplexMeshAdaptTopologyFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
46{
47public:
48 ITK_DISALLOW_COPY_AND_MOVE(SimplexMeshAdaptTopologyFilter);
49
52
55
58
61
63 itkNewMacro(Self);
64
66 itkOverrideGetNameOfClassMacro(SimplexMeshAdaptTopologyFilter);
67
68 using InputMeshType = TInputMesh;
69 using InputMeshPointer = typename InputMeshType::Pointer;
70 using InputPointType = typename InputMeshType::PointType;
71 using InputVectorType = typename InputMeshType::VectorType;
72 using InputPixelType = typename InputMeshType::PixelType;
73 using InputCellTraitsType = typename InputMeshType::MeshTraits::CellTraits;
74 using InputCellType = typename InputMeshType::CellType;
75 using PointIdentifier = typename InputMeshType::PointIdentifier;
76 using CellIdentifier = typename InputMeshType::CellIdentifier;
77 using InputCellPointIdIterator = typename InputCellType::PointIdIterator;
78 using InputCellAutoPointer = typename InputCellType::CellAutoPointer;
79 using CellAutoPointer = typename InputMeshType::CellAutoPointer;
81 using InputPolygonPointIdIterator = typename InputPolygonType::PointIdIterator;
83 using OutputMeshType = TOutputMesh;
84 using OutputMeshPointer = typename OutputMeshType::Pointer;
85 using OutputCellType = typename OutputMeshType::CellType;
87
89 using DoubleContainerIterator = typename DoubleValueMapType::Iterator;
90
99 {
100 public:
102 double totalArea{ 0 };
103 double totalCurvature{ 0 };
105 double maxCellSize{ 0 };
106 typename DoubleValueMapType::Pointer areaMap;
107 typename DoubleValueMapType::Pointer curvatureMap;
108
110 double maxCurvature{ 0 };
111
113 : minCellSize(NumericTraits<double>::max())
116 , minCurvature(NumericTraits<double>::max())
117
118 {}
119
123 void
125 {
126 typename InputPolygonType::PointIdIterator it = poly->PointIdsBegin();
127
128 double meanCurvature = 0;
129 const PointIdentifier refPoint = *it;
130 double val = mesh->GetMeanCurvature(*it++);
131 meanCurvature += itk::Math::abs(val);
132
133 PointIdentifier id1 = *it;
134 val = mesh->GetMeanCurvature(*it++);
135 meanCurvature += itk::Math::abs(val);
136
137 double area = 0;
138
139 int cnt = 0;
140
141 while (it != poly->PointIdsEnd())
142 {
143 const PointIdentifier id2 = *it;
144 area += ComputeArea(refPoint, id1, id2);
145 id1 = id2;
146 val = mesh->GetMeanCurvature(*it);
147 meanCurvature += itk::Math::abs(val);
148 ++cnt;
149 ++it;
150 }
151
152 meanCurvature /= static_cast<double>(cnt);
153 totalArea += area;
154 totalCurvature += meanCurvature;
155
156 areaMap->InsertElement(cellId, area);
157 curvatureMap->InsertElement(cellId, meanCurvature);
158
159 if (area > maxCellSize)
160 {
161 maxCellSize = area;
162 }
163 if (area < minCellSize)
164 {
165 minCellSize = area;
166 }
167 if (meanCurvature > maxCurvature)
168 {
169 maxCurvature = meanCurvature;
170 }
171 if (meanCurvature < minCurvature)
172 {
173 minCurvature = meanCurvature;
174 }
175 }
176
177 double
179 {
180 InputPointType v1{};
181 InputPointType v2{};
183
184 mesh->GetPoint(p1, &v1);
185 mesh->GetPoint(p2, &v2);
186 mesh->GetPoint(p3, &v3);
187 return itk::Math::abs(vnl_cross_3d((v2 - v1).GetVnlVector(), (v3 - v1).GetVnlVector()).two_norm() / 2.0);
188 }
189
190 typename DoubleValueMapType::Pointer
192 {
193 return areaMap;
194 }
195
196 typename DoubleValueMapType::Pointer
198 {
199 return curvatureMap;
200 }
201
202 double
204 {
205 return totalArea;
206 }
207
208 double
210 {
211 return totalCurvature / (curvatureMap->Size());
212 }
213
214 double
216 {
217 return maxCellSize;
218 }
219
220 double
222 {
223 return minCellSize;
224 }
225
226 double
228 {
229 return maxCurvature;
230 }
231
232 double
234 {
235 return minCurvature;
236 }
237 };
238
239 // cell visitor stuff
242
244 using CellMultiVisitorType = typename InputCellType::MultiVisitor;
245 using CellMultiVisitorPointer = typename CellMultiVisitorType::Pointer;
246
247 itkSetMacro(Threshold, double);
248 itkGetConstMacro(Threshold, double);
249
250 itkSetMacro(SelectionMethod, int);
251 itkGetConstMacro(SelectionMethod, int);
252
253 itkGetConstMacro(ModifiedCount, int);
254
255protected:
258
259 void
260 PrintSelf(std::ostream & os, Indent indent) const override;
261
262 void
263 GenerateData() override;
264
268 void
270
276 void
278
280 void
282
288 void
290
296
301
306 double m_Threshold{ 0.5 };
307
312
318
324
326};
327} // namespace itk
328
329#ifndef ITK_MANUAL_INSTANTIATION
330# include "itkSimplexMeshAdaptTopologyFilter.hxx"
331#endif
332
333#endif // itkSimplexMeshAdaptTopologyFilter_h
A template class used to implement a visitor object.
A templated class holding a n-Dimensional covariant vector.
Control indentation during Print() invocation.
Definition itkIndent.h:50
A wrapper of the STL "map" container.
Define additional traits for native types such as int or float.
Represents a polygon in a Mesh.
PointIdIterator PointIdsEnd() override
PointIdIterator PointIdsBegin() override
void Visit(CellIdentifier cellId, InputPolygonType *poly)
visits all polygon cells and computes the area, NOTE: works for convex polygons only!...
double ComputeArea(PointIdentifier p1, PointIdentifier p2, PointIdentifier p3)
itk::PolygonCell< OutputCellType > OutputPolygonType
typename InputCellType::PointIdIterator InputCellPointIdIterator
typename InputCellType::MultiVisitor CellMultiVisitorType
itk::PolygonCell< InputCellType > InputPolygonType
CovariantVector< typename InputVectorType::ValueType, 3 > CovariantVectorType
void ModifyNeighborCells(CellIdentifier id1, CellIdentifier id2, PointIdentifier insertPointId)
MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass
typename InputCellType::CellAutoPointer InputCellAutoPointer
typename InputMeshType::VectorType InputVectorType
OutputMeshPointer m_Output
member for accessing the filter result during creation
typename InputMeshType::CellIdentifier CellIdentifier
typename InputMeshType::MeshTraits::CellTraits InputCellTraitsType
void PrintSelf(std::ostream &os, Indent indent) const override
typename DoubleValueMapType::Iterator DoubleContainerIterator
typename InputMeshType::PointIdentifier PointIdentifier
typename CellMultiVisitorType::Pointer CellMultiVisitorPointer
typename SimplexVisitorInterfaceType::Pointer SimplexVisitorInterfacePointer
typename InputMeshType::CellAutoPointer CellAutoPointer
~SimplexMeshAdaptTopologyFilter() override=default
typename itk::MapContainer< CellIdentifier, double > DoubleValueMapType
itk::CellInterfaceVisitorImplementation< InputPixelType, InputCellTraitsType, InputPolygonType, SimplexCellVisitor > SimplexVisitorInterfaceType
typename InputPolygonType::PointIdIterator InputPolygonPointIdIterator
InputPointType ComputeCellCenter(InputCellAutoPointer &simplexCell)
Implements transparent reference counting.
bool abs(bool x)
Definition itkMath.h:833
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....