ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkCuberilleImageToMeshFilter.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
19#ifndef itkCuberilleImageToMeshFilter_h
20#define itkCuberilleImageToMeshFilter_h
21
22#include "itkMacro.h"
23#include "itkMesh.h"
25#include "itkCellInterface.h"
26#include "itkTriangleCell.h"
34
35#include <tuple>
36#include <type_traits>
37
38namespace itk
39{
40
112template <typename TInputImage,
113 typename TOutputMesh,
114 typename TInterpolator = itk::LinearInterpolateImageFunction<TInputImage>>
115class CuberilleImageToMeshFilter : public ImageToMeshFilter<TInputImage, TOutputMesh>
116{
117public:
118 ITK_DISALLOW_COPY_AND_MOVE(CuberilleImageToMeshFilter);
119
125
127 itkNewMacro(Self);
128
130 itkOverrideGetNameOfClassMacro(CuberilleImageToMeshFilter);
131
137 static constexpr bool UseGradientRecursiveGaussian = false;
138 static constexpr bool UseAdvancedProjection = false;
139 static constexpr bool UseLineSearchProjection = false;
141
143 using OutputMeshType = TOutputMesh;
144 using OutputMeshPointer = typename OutputMeshType::Pointer;
145 using OutputMeshTraits = typename OutputMeshType::MeshTraits;
146 using OutputPointType = typename OutputMeshType::PointType;
147 using OutputPixelType = typename OutputMeshTraits::PixelType;
148 using CellTraits = typename OutputMeshType::CellTraits;
149 using PointsContainerPointer = typename OutputMeshType::PointsContainerPointer;
150 using PointsContainer = typename OutputMeshType::PointsContainer;
151 using CellsContainerPointer = typename OutputMeshType::CellsContainerPointer;
152 using CellsContainer = typename OutputMeshType::CellsContainer;
153 using PointIdentifier = typename OutputMeshType::PointIdentifier;
154 using PointVectorType = typename std::vector<PointIdentifier>;
155 using CellIdentifier = typename OutputMeshType::CellIdentifier;
158 using TriangleAutoPointer = typename TriangleCellType::SelfAutoPointer;
159 using TriangleCellAutoPointer = typename TriangleCellType::CellAutoPointer;
161 using QuadrilateralAutoPointer = typename QuadrilateralCellType::SelfAutoPointer;
162 using QuadrilateralCellAutoPointer = typename QuadrilateralCellType::CellAutoPointer;
163
164 using InputImageType = TInputImage;
165 using InputImagePointer = typename InputImageType::Pointer;
166 using InputImageConstPointer = typename InputImageType::ConstPointer;
167 using InputPixelType = typename InputImageType::PixelType;
168 using SizeType = typename InputImageType::SizeType;
169 using SpacingType = typename InputImageType::SpacingType;
170 using SpacingValueType = typename InputImageType::SpacingValueType;
171 using IndexType = typename InputImageType::IndexType;
172 static_assert(InputImageType::ImageDimension == 3, "CuberilleImageToMeshFilter supports only 3D images.");
173 using PointType = typename OutputMeshType::PointType;
174
175 using InterpolatorType = TInterpolator;
176 using InterpolatorPointer = typename InterpolatorType::Pointer;
177 using InterpolatorOutputType = typename InterpolatorType::OutputType;
178
184 using GradientFilterPointer = typename GradientFilterType::Pointer;
185 using GradientImageType = typename GradientFilterType::OutputImageType;
186 using GradientImagePointer = typename GradientImageType::Pointer;
187 using GradientPixelType = typename GradientFilterType::OutputPixelType;
190
196 itkGetMacro(IsoSurfaceValue, InputPixelType);
197 itkSetMacro(IsoSurfaceValue, InputPixelType);
198
201 virtual void
202 SetInput(const InputImageType * inputImage);
203
205 itkGetConstObjectMacro(Interpolator, InterpolatorType);
206 itkSetObjectMacro(Interpolator, InterpolatorType);
207
211 itkGetMacro(GenerateTriangleFaces, bool);
212 itkSetMacro(GenerateTriangleFaces, bool);
213 itkBooleanMacro(GenerateTriangleFaces);
214
217 itkGetMacro(ProjectVerticesToIsoSurface, bool);
218 itkSetMacro(ProjectVerticesToIsoSurface, bool);
219 itkBooleanMacro(ProjectVerticesToIsoSurface);
220
223 itkGetMacro(SavePixelAsCellData, bool);
224 itkSetMacro(SavePixelAsCellData, bool);
225 itkBooleanMacro(SavePixelAsCellData);
226
233 itkGetMacro(ProjectVertexSurfaceDistanceThreshold, double);
234 itkSetClampMacro(ProjectVertexSurfaceDistanceThreshold, double, 0.0, NumericTraits<InputPixelType>::max());
235
239 itkGetMacro(ProjectVertexStepLength, double);
240 itkSetClampMacro(ProjectVertexStepLength, double, 0.0, 100000.0);
241
246 itkGetMacro(ProjectVertexStepLengthRelaxationFactor, double);
247 itkSetClampMacro(ProjectVertexStepLengthRelaxationFactor, double, 0.0, 1.0);
248
251 itkGetMacro(ProjectVertexMaximumNumberOfSteps, unsigned int);
252 itkSetMacro(ProjectVertexMaximumNumberOfSteps, unsigned int);
253
255 void
257
258protected:
261 void
262 PrintSelf(std::ostream & os, Indent indent) const override;
263
264 void
265 GenerateData() override;
266 void
267 GenerateOutputInformation() override {}; // do nothing
268
269private:
273 {
274 public:
277
279 VertexLookupNode() = default;
280 VertexLookupNode(unsigned long x, unsigned long y, unsigned long z)
281 : m_X(x)
282 , m_Y(y)
283 , m_Z(z)
284 {}
285
287 unsigned long
289 {
290 return m_X;
291 }
292 unsigned long
294 {
295 return m_Y;
296 }
297 unsigned long
299 {
300 return m_Z;
301 }
302
307 bool
308 operator>(const Self & node) const
309 {
310 return std::tie(m_Z, m_Y, m_X) > std::tie(node.m_Z, node.m_Y, node.m_X);
311 }
312 bool
313 operator>=(const Self & node) const
314 {
315 return std::tie(m_Z, m_Y, m_X) >= std::tie(node.m_Z, node.m_Y, node.m_X);
316 }
317 bool
318 operator<(const Self & node) const
319 {
320 return std::tie(m_Z, m_Y, m_X) < std::tie(node.m_Z, node.m_Y, node.m_X);
321 }
322 bool
323 operator<=(const Self & node) const
324 {
325 return std::tie(m_Z, m_Y, m_X) <= std::tie(node.m_Z, node.m_Y, node.m_X);
326 }
327
328 private:
329 unsigned long m_X{ 0 };
330 unsigned long m_Y{ 0 };
331 unsigned long m_Z{ 0 };
332 };
333
336 template <typename TMeshType>
338 {
339 public:
342 using MapType = std::map<VertexLookupNode, PointVectorType>;
343
345 VertexLookupMap() = default;
346
348 void
350 {
351 m_Map.clear();
352 }
353
355 void
356 AddVertex(unsigned int x, unsigned int y, unsigned int z, PointVectorType ids)
357 {
358 VertexLookupNode node(x, y, z);
359 m_Map.insert(typename MapType::value_type(node, ids));
360 }
361
365 bool
366 GetVertex(unsigned int x, unsigned int y, unsigned int z, const size_t component, PointIdentifier & id)
367 {
368 bool result = false;
369 VertexLookupNode node(x, y, z);
370 auto it = m_Map.find(node);
371 if (it != m_Map.end())
372 {
373 result = true;
374 id = it->second.at(component);
375 }
376 return result;
377 }
378
379 private:
381 };
382
385
387
389 inline void
391
393 inline void
394 SetVerticesFromFace(unsigned int face, std::array<bool, 8> & vertexHasQuad);
395
397 inline IndexType
398 GetVertexLookupIndex(unsigned int vertex, IndexType index);
399
401 inline void
403
405 inline PointVectorType
407 IndexType index,
408 const InputImageType * image,
409 OutputMeshType * mesh,
410 const size_t numComponents);
411
413 inline void
415 std::array<PointIdentifier, 4> f,
416 OutputMeshType * mesh,
417 const InputPixelType & pixel);
418
420 size_t
422
423 using TLabel = signed char;
424 using TLabels = std::array<TLabel, 8>;
425 using TLabelsArray = std::array<TLabels, 256>;
426
428
440};
441
442} // end namespace itk
443
444#ifndef ITK_MANUAL_INSTANTIATION
445# include "itkCuberilleImageToMeshFilter.hxx"
446#endif
447
448#endif
An abstract interface for cells.
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
void AddVertex(unsigned int x, unsigned int y, unsigned int z, PointVectorType ids)
std::map< VertexLookupNode, PointVectorType > MapType
bool GetVertex(unsigned int x, unsigned int y, unsigned int z, const vcl_size_t component, PointIdentifier &id)
VertexLookupNode(unsigned long x, unsigned long y, unsigned long z)
typename GradientFilterType::OutputImageType GradientImageType
virtual void SetInput(const InputImageType *inputImage)
std::conditional_t< UseGradientRecursiveGaussian, GradientRecursiveGaussianImageFilter< InputImageType >, GradientImageFilter< InputImageType > > GradientFilterType
typename TriangleCellType::CellAutoPointer TriangleCellAutoPointer
typename OutputMeshTraits::PixelType OutputPixelType
typename std::vector< PointIdentifier > PointVectorType
typename OutputMeshType::Pointer OutputMeshPointer
typename InputImageType::Pointer InputImagePointer
void SetVerticesFromFace(unsigned int face, std::array< bool, 8 > &vertexHasQuad)
typename InputImageType::ConstPointer InputImageConstPointer
void AddQuadFace(CellIdentifier &id, std::array< PointIdentifier, 4 > f, OutputMeshType *mesh, const InputPixelType &pixel)
PointVectorType AddVertex(PointIdentifier &id, IndexType index, const InputImageType *image, OutputMeshType *mesh, const vcl_size_t numComponents)
typename QuadrilateralCellType::CellAutoPointer QuadrilateralCellAutoPointer
typename InputImageType::SizeType SizeType
typename OutputMeshType::PointIdentifier PointIdentifier
vcl_size_t CalculateBitmaskIDForVertexIndex(const IndexType &vindex)
typename OutputMeshType::CellsContainerPointer CellsContainerPointer
typename OutputMeshType::CellsContainer CellsContainer
ImageToMeshFilter< TInputImage, TOutputMesh > Superclass
typename GradientFilterType::Pointer GradientFilterPointer
typename InputImageType::SpacingType SpacingType
typename OutputMeshType::PointType OutputPointType
TriangleCell< CellInterfaceType > TriangleCellType
CellInterface< OutputPixelType, CellTraits > CellInterfaceType
typename GradientInterpolatorType::Pointer GradientInterpolatorPointer
typename OutputMeshType::MeshTraits OutputMeshTraits
typename GradientImageType::Pointer GradientImagePointer
typename InputImageType::IndexType IndexType
VertexLookupMap< OutputMeshType > VertexLookupMapType
typename OutputMeshType::CellIdentifier CellIdentifier
typename GradientFilterType::OutputPixelType GradientPixelType
typename OutputMeshType::CellTraits CellTraits
typename OutputMeshType::PointsContainerPointer PointsContainerPointer
typename OutputMeshType::PointType PointType
typename InterpolatorType::Pointer InterpolatorPointer
typename InterpolatorType::OutputType InterpolatorOutputType
IndexType GetVertexLookupIndex(unsigned int vertex, IndexType index)
typename InputImageType::SpacingValueType SpacingValueType
void ProjectVertexToIsoSurface(PointType &vertex)
QuadrilateralCell< CellInterfaceType > QuadrilateralCellType
typename OutputMeshType::PointsContainer PointsContainer
typename TriangleCellType::SelfAutoPointer TriangleAutoPointer
ConstShapedNeighborhoodIterator< InputImageType > InputImageIteratorType
GradientInterpolatorPointer m_GradientInterpolator
itk::VectorLinearInterpolateImageFunction< GradientImageType > GradientInterpolatorType
typename InputImageType::PixelType InputPixelType
typename QuadrilateralCellType::SelfAutoPointer QuadrilateralAutoPointer
void PrintSelf(std::ostream &os, Indent indent) const override
Computes the gradient of an image using directional derivatives.
Computes the gradient of an image by convolution with the first derivative of a Gaussian.
void SetInput(unsigned int idx, const InputImageType *input)
Control indentation during Print() invocation.
Definition itkIndent.h:53
static constexpr T max(const T &)
Represents a quadrilateral for a Mesh.
Implements transparent reference counting.
Linearly interpolate a vector image at specified positions.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
#define itkSetMacro(name, type)