20 #ifndef MIRTK_PointSetUtils_H 21 #define MIRTK_PointSetUtils_H 23 #include "mirtk/UnorderedSet.h" 24 #include "mirtk/Array.h" 25 #include "mirtk/List.h" 26 #include "mirtk/Pair.h" 28 #include "mirtk/Math.h" 29 #include "mirtk/Vtk.h" 30 #include "mirtk/VtkMath.h" 33 class vtkDataSetAttributes;
37 class vtkImageStencilData;
45 struct ImageAttributes;
54 typedef List<Pair<int, int>>
EdgeList;
158 vtkDataSetAttributes *src,
189 double v[3] = {n[1], n[2], n[0]};
190 vtkMath::Cross(n, v, e1);
191 if (vtkMath::Dot(e1, e1) < 1e-6) {
193 vtkMath::Cross(n, v, e1);
194 if (vtkMath::Dot(e1, e1) < 1e-6)
return false;
196 vtkMath::Cross(n, e1, e2);
197 vtkMath::Normalize(e1);
198 vtkMath::Normalize(e2);
204 inline bool ComputeTangents(
const double n[3],
double e1[3],
double e2[3],
double e3[3],
double e4[3])
207 const double sqrt2 = sqrt(2.0);
208 e2[0] = (e1[0] + e3[0]) / sqrt2;
209 e2[1] = (e1[1] + e3[1]) / sqrt2;
210 e2[2] = (e1[2] + e3[2]) / sqrt2;
211 e4[0] = (e1[0] - e3[0]) / sqrt2;
212 e4[1] = (e1[1] - e3[1]) / sqrt2;
213 e4[2] = (e1[2] - e3[2]) / sqrt2;
228 vtkSmartPointer<vtkPolyData>
DataSetSurface(vtkSmartPointer<vtkDataSet> dataset,
229 bool passPtIds =
false,
230 bool passCellIds =
false);
233 void Center(vtkSmartPointer<vtkPointSet> pointset);
236 void Scale(vtkSmartPointer<vtkPointSet> pointset,
double);
245 return 0.25 * sqrt(3.0) * l * l;
306 int *npoints =
nullptr,
307 int *nedges =
nullptr,
308 int *nfaces =
nullptr);
312 int *npoints =
nullptr,
313 int *nedges =
nullptr,
314 int *nfaces =
nullptr);
317 double Genus(vtkDataSet *dataset,
319 int *npoints =
nullptr,
320 int *nedges =
nullptr,
321 int *nfaces =
nullptr,
322 int *nbounds =
nullptr,
323 int *ncomps =
nullptr,
324 int *euler =
nullptr);
327 double Genus(vtkDataSet *dataset,
328 int *npoints =
nullptr,
329 int *nedges =
nullptr,
330 int *nfaces =
nullptr,
331 int *nbounds =
nullptr,
332 int *ncomps =
nullptr,
333 int *euler =
nullptr);
336 double Area(vtkPolyData *,
bool per_cell =
false);
339 inline double Area(vtkSmartPointer<vtkPolyData> surface,
bool per_cell =
false)
341 return Area(surface.GetPointer(), per_cell);
346 double Area(vtkSmartPointer<vtkPointSet>);
436 double Volume(vtkSmartPointer<vtkPolyData>);
444 vtkSmartPointer<vtkPolyData>
ConvexHull(vtkSmartPointer<vtkPointSet> pointset,
int levels = 3);
447 vtkSmartPointer<vtkPolyData>
Triangulate(vtkSmartPointer<vtkPolyData>);
450 vtkSmartPointer<vtkPointSet>
Tetrahedralize(vtkSmartPointer<vtkPointSet>);
457 vtkSmartPointer<vtkImageData>
NewVtkMask(
int nx,
int ny,
int nz);
460 vtkSmartPointer<vtkPointSet>
WorldToImage(vtkSmartPointer<vtkPointSet> pointset,
464 vtkSmartPointer<vtkImageStencilData>
ImageStencil(vtkSmartPointer<vtkImageData> image,
465 vtkSmartPointer<vtkPointSet> pointset);
472 vtkSmartPointer<vtkImageData> image);
477 #endif // MIRTK_PointSetUtils_H bool ComputeTangents(const double n[3], double e1[3], double e2[3])
EdgeList PopPointEdges(EdgeList &edges, int ptId)
double MinEdgeLength(vtkSmartPointer< vtkPoints > points, const EdgeTable &edgeTable)
Vector SquaredEdgeLengths(vtkSmartPointer< vtkPoints >, const EdgeTable &)
Compute squared edge lengths of point set given a precomputed edge table.
double EdgeLengthToTriangleArea(double l)
Calculate are of triangle with given edge length.
bool IsTetrahedralMesh(vtkDataSet *)
Check whether given point set is a tetrahedral mesh.
double RobustAverageEdgeLength(vtkSmartPointer< vtkPoints >, const EdgeTable &)
UnorderedSet< int > BoundaryPoints(vtkDataSet *, const EdgeTable *=nullptr)
Get IDs of end points of boundary edges.
double ComputeVolume(vtkCell *cell)
void ImageStencilToMask(vtkSmartPointer< vtkImageStencilData > stencil, vtkSmartPointer< vtkImageData > image)
double Genus(vtkDataSet *dataset, const EdgeTable &, int *npoints=nullptr, int *nedges=nullptr, int *nfaces=nullptr, int *nbounds=nullptr, int *ncomps=nullptr, int *euler=nullptr)
Genus of surface mesh.
bool IsCategoricalArrayName(const string &name)
vtkSmartPointer< vtkPolyData > DataSetSurface(vtkSmartPointer< vtkDataSet > dataset, bool passPtIds=false, bool passCellIds=false)
int NumberOfEmptyCells(vtkDataSet *)
Number of empty/deleted cells.
int NumberOfEdges(vtkDataSet *, const EdgeTable *=nullptr)
Number of edges.
vtkSmartPointer< vtkImageData > NewVtkMask(int nx, int ny, int nz)
List< Pair< int, int > > EdgeList
List of pairs of edge end point IDs.
void Scale(vtkSmartPointer< vtkPointSet > pointset, double)
Scale point set around center.
double Volume(vtkSmartPointer< vtkPolyData >)
Get approximate volume enclosed by polygonal mesh.
vtkSmartPointer< vtkPointSet > Tetrahedralize(vtkSmartPointer< vtkPointSet >)
Tetrahedralize the interior of a piecewise linear complex (PLC)
int EulerCharacteristic(vtkDataSet *dataset, const EdgeTable &, int *npoints=nullptr, int *nedges=nullptr, int *nfaces=nullptr)
Euler characeteristic, i.e., V - E + F.
vtkSmartPointer< vtkImageStencilData > ImageStencil(vtkSmartPointer< vtkImageData > image, vtkSmartPointer< vtkPointSet > pointset)
Get inside surface image stencil.
Array< Array< int > > BoundarySegments(vtkDataSet *, const EdgeTable *=nullptr)
Get connected boundary segments as (closed) line strips.
vtkSmartPointer< vtkPolyData > Triangulate(vtkSmartPointer< vtkPolyData >)
Triangulate surface mesh.
double ComputeArea(vtkCell *cell)
ImageAttributes PolyDataDomain(vtkPolyData *data, double dx=-1, double dy=-1, double dz=-1)
int Dimension(vtkDataSet *)
Determine dimension of data set.
void EdgeLengthNormalDistribution(vtkSmartPointer< vtkPoints > points, const EdgeTable &edgeTable, double &mean, double &sigma)
int DeepCopyArrayUsingCaseInsensitiveName(vtkDataSetAttributes *dst, vtkDataSetAttributes *src, const char *name)
vtkSmartPointer< vtkPolyData > ConvexHull(vtkSmartPointer< vtkPointSet > pointset, int levels=3)
EdgeList BoundaryEdges(vtkDataSet *)
Get list of all boundary edges.
void Center(vtkSmartPointer< vtkPointSet > pointset)
Translate point set such that center is at origin.
vtkDataArray * GetArrayByCaseInsensitiveName(vtkDataSetAttributes *data, const char *name, int *loc=NULL)
Vector EdgeLengths(vtkSmartPointer< vtkPoints >, const EdgeTable &)
Compute edge lengths of point set given a precomputed edge table.
double MaxEdgeLength(vtkSmartPointer< vtkPoints > points, const EdgeTable &edgeTable)
int NumberOfFaces(vtkDataSet *)
Number of faces.
vtkSmartPointer< vtkPointSet > WorldToImage(vtkSmartPointer< vtkPointSet > pointset, const BaseImage *image)
Map point set points to voxel coordinates.
double MedianEdgeLength(vtkSmartPointer< vtkPoints >, const EdgeTable &)
Determine median edge length of point set given a precomputed edge table.
double Area(vtkPolyData *, bool per_cell=false)
Area of surface mesh.
int NumberOfConnectedComponents(vtkDataSet *)
Number of connected components.
void AddPoints(PointSet &oset, vtkPointSet *iset)
void GetMinMaxEdgeLength(vtkSmartPointer< vtkPoints > points, const EdgeTable &edgeTable, double &min, double &max)
EdgeList GetPointEdges(const EdgeList &edges, int ptId)
int NumberOfPoints(vtkDataSet *)
Number of points.
bool IsSurfaceMesh(vtkDataSet *)
Determine whether a point set is a surface mesh.
int PolyDataAttributeType(const char *type)
bool IsTriangularMesh(vtkDataSet *)
Check whether given point set is a triangular mesh.
ImageAttributes PointSetDomain(vtkPointSet *data, double dx=-1, double dy=-1, double dz=-1)
double AverageEdgeLength(vtkSmartPointer< vtkPoints >, const EdgeTable &)
Determine average edge length of point set given a precomputed edge table.
int NumberOfBoundarySegments(vtkDataSet *, const EdgeTable *=nullptr)
Number of connected boundary components.