Commit 24ec0909 authored by Will Schroeder's avatar Will Schroeder Committed by Kitware Robot

Merge topic 'MeshSizingWidget'

7420dcf5 Resamples point data and arbitray polygons
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !6207
parents c2548dd7 7420dcf5
Pipeline #152942 running with stage
b070ca36cf90a94385f0726af6c6b2cdb358aefa5b80596c7c25de72f8df7302967d4cd03f68315016d09b501e4a02aeaf79ae0b1127d24392179063adbeaf66
......@@ -18,6 +18,7 @@ vtk_add_test_python(
TestFitToHeightMapFilter2.py
TestImageMarchingCubes.py
TestOutlineFilter.py
TestPointSampler.py
TestRibbonAndTube.py
TestRuledSurface.py
TestRuledSurface2.py
......
#!/usr/bin/env python
import vtk
# Create the RenderWindow, Renderer and interactive renderer
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.SetMultiSamples(0)
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Create a synthetic polydata with two triangles, a quad, a general polygon,
# and a triangle strip. The polydata also has point attributes.
#
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(11)
pts.SetPoint(0, 0.0,0.0,0.0)
pts.SetPoint(1, 1.0,0.0,0.0)
pts.SetPoint(2, 0.0,1.0,0.0)
pts.SetPoint(3, 1.0,1.0,0.0)
pts.SetPoint(4, 0.0,2.0,0.0)
pts.SetPoint(5, 1.0,2.0,0.0)
pts.SetPoint(6, 0.0,3.0,0.0)
pts.SetPoint(7, 1.0,3.0,0.0)
pts.SetPoint(8, 0.5,3.5,0.0)
pts.SetPoint(9, 0.0,-1,0.0)
pts.SetPoint(10, 1.0,-1,0.0)
cells = vtk.vtkCellArray()
cells.InsertNextCell(3)
cells.InsertCellPoint(0)
cells.InsertCellPoint(1)
cells.InsertCellPoint(2)
cells.InsertNextCell(3)
cells.InsertCellPoint(2)
cells.InsertCellPoint(1)
cells.InsertCellPoint(3)
cells.InsertNextCell(4)
cells.InsertCellPoint(2)
cells.InsertCellPoint(3)
cells.InsertCellPoint(5)
cells.InsertCellPoint(4)
cells.InsertNextCell(5)
cells.InsertCellPoint(4)
cells.InsertCellPoint(5)
cells.InsertCellPoint(7)
cells.InsertCellPoint(8)
cells.InsertCellPoint(6)
strip = vtk.vtkCellArray()
strip.InsertNextCell(4)
strip.InsertCellPoint(10)
strip.InsertCellPoint(1)
strip.InsertCellPoint(9)
strip.InsertCellPoint(0)
scalars = vtk.vtkFloatArray()
scalars.SetNumberOfTuples(11)
scalars.SetTuple1(0,0.0)
scalars.SetTuple1(1,1.0)
scalars.SetTuple1(2,0.0)
scalars.SetTuple1(3,1.0)
scalars.SetTuple1(4,0.0)
scalars.SetTuple1(5,1.0)
scalars.SetTuple1(6,0.0)
scalars.SetTuple1(7,1.0)
scalars.SetTuple1(8,0.5)
scalars.SetTuple1(9,0.0)
scalars.SetTuple1(10,1.0)
# Assemble the polydata
pd = vtk.vtkPolyData()
pd.SetPoints(pts)
pd.SetPolys(cells)
pd.SetStrips(strip)
pd.GetPointData().SetScalars(scalars)
# Finally test the point sampler
sampler = vtk.vtkPolyDataPointSampler()
sampler.SetInputData(pd)
sampler.SetDistance(0.05)
sampler.InterpolatePointDataOn()
# Mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(sampler.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Setup graphics stuff
ren1.AddActor(actor)
ren1.SetBackground(0,0,0)
renWin.SetSize(300,300)
renWin.Render()
iren.Start()
# --- end of script --
......@@ -17,15 +17,23 @@
* @brief generate points from vtkPolyData
*
* vtkPolyDataPointSampler generates points from input vtkPolyData. The
* points are placed approximately a specified distance apart.
* points are placed approximately a specified distance apart. Optionally,
* the points attributes can be interpolated from the generating vertices,
* edges, and polygons.
*
* This filter functions as follows. First, it regurgitates all input points,
* then samples all lines, plus edges associated with the input polygons and
* triangle strips to produce edge points. Finally, the interiors of polygons
* and triangle strips are subsampled to produce points. All of these
* functiona can be enabled or disabled separately. Note that this algorithm
* only approximately generates points the specified distance apart.
* Generally the point density is finer than requested.
* then it samples all lines, plus edges associated with the input polygons
* and triangle strips to produce edge points. Finally, the interiors of
* polygons and triangle strips are subsampled to produce points. All of
* these operations can be enabled or disabled separately. Note that this
* algorithm only approximately generates points the specified distance
* apart. Generally the point density is finer than requested.
*
* @warning
* While this algorithm processes general polygons. it does so by performing
* a fan triangulation. This may produce poor results, especially for convave
* polygons. For better results, use a triangle filter to pre-tesselate
* polygons.
*
* @warning
* Point generation can be useful in a variety of applications. For example,
......@@ -34,14 +42,20 @@
* cases implicit models can be more efficiently generated from points than
* from polygons or other primitives.
*
* @warning
* When sampling polygons of 5 sides or more, the polygon is triangulated.
* This can result in variations in point density near tesselation boudaries.
*
* @sa
* vtkImplicitModeller
* vtkTriangleFilter vtkImplicitModeller
*/
#ifndef vtkPolyDataPointSampler_h
#define vtkPolyDataPointSampler_h
#include "vtkEdgeTable.h" // for sampling edges
#include "vtkFiltersModelingModule.h" // For export macro
#include "vtkNew.h" // for data members
#include "vtkPolyDataAlgorithm.h"
class VTKFILTERSMODELING_EXPORT vtkPolyDataPointSampler : public vtkPolyDataAlgorithm
......@@ -74,9 +88,9 @@ public:
* Specify/retrieve a boolean flag indicating whether cell vertex points should
* be output.
*/
vtkGetMacro(GenerateVertexPoints, vtkTypeBool);
vtkSetMacro(GenerateVertexPoints, vtkTypeBool);
vtkBooleanMacro(GenerateVertexPoints, vtkTypeBool);
vtkGetMacro(GenerateVertexPoints, bool);
vtkSetMacro(GenerateVertexPoints, bool);
vtkBooleanMacro(GenerateVertexPoints, bool);
//@}
//@{
......@@ -84,9 +98,9 @@ public:
* Specify/retrieve a boolean flag indicating whether cell edges should
* be sampled to produce output points. The default is true.
*/
vtkGetMacro(GenerateEdgePoints, vtkTypeBool);
vtkSetMacro(GenerateEdgePoints, vtkTypeBool);
vtkBooleanMacro(GenerateEdgePoints, vtkTypeBool);
vtkGetMacro(GenerateEdgePoints, bool);
vtkSetMacro(GenerateEdgePoints, bool);
vtkBooleanMacro(GenerateEdgePoints, bool);
//@}
//@{
......@@ -94,9 +108,9 @@ public:
* Specify/retrieve a boolean flag indicating whether cell interiors should
* be sampled to produce output points. The default is true.
*/
vtkGetMacro(GenerateInteriorPoints, vtkTypeBool);
vtkSetMacro(GenerateInteriorPoints, vtkTypeBool);
vtkBooleanMacro(GenerateInteriorPoints, vtkTypeBool);
vtkGetMacro(GenerateInteriorPoints, bool);
vtkSetMacro(GenerateInteriorPoints, bool);
vtkBooleanMacro(GenerateInteriorPoints, bool);
//@}
//@{
......@@ -104,12 +118,26 @@ public:
* Specify/retrieve a boolean flag indicating whether cell vertices should
* be generated. Cell vertices are useful if you actually want to display
* the points (that is, for each point generated, a vertex is generated).
* Recall that VTK only renders vertices and not points.
* The default is true.
* Recall that VTK only renders vertices and not points. The default is
* true.
*/
vtkGetMacro(GenerateVertices, bool);
vtkSetMacro(GenerateVertices, bool);
vtkBooleanMacro(GenerateVertices, bool);
//@}
//@{
/**
* Specify/retrieve a boolean flag indicating whether point data should be
* interpolated onto the newly generated points. If enabled, points
* generated from existing vertices will carry the vertex point data;
* points generated from edges will interpolate point data along each edge;
* and interior point data (inside triangles, polygons cells) will be
* interpolated from the cell vertices. By default this is off.
*/
vtkGetMacro(GenerateVertices, vtkTypeBool);
vtkSetMacro(GenerateVertices, vtkTypeBool);
vtkBooleanMacro(GenerateVertices, vtkTypeBool);
vtkGetMacro(InterpolatePointData, bool);
vtkSetMacro(InterpolatePointData, bool);
vtkBooleanMacro(InterpolatePointData, bool);
//@}
protected:
......@@ -121,14 +149,28 @@ protected:
double Distance;
double Distance2;
vtkTypeBool GenerateVertexPoints;
vtkTypeBool GenerateEdgePoints;
vtkTypeBool GenerateInteriorPoints;
vtkTypeBool GenerateVertices;
void SampleEdge(vtkPoints* pts, double x0[3], double x1[3]);
void SampleTriangle(vtkPoints* newPts, vtkPoints* inPts, const vtkIdType* pts);
void SamplePolygon(vtkPoints* newPts, vtkPoints* inPts, vtkIdType npts, const vtkIdType* pts);
bool GenerateVertexPoints;
bool GenerateEdgePoints;
bool GenerateInteriorPoints;
bool GenerateVertices;
bool InterpolatePointData;
// Internal scratch arrays supporting point data interpolation, and
// sampling edges.
vtkNew<vtkEdgeTable> EdgeTable;
double TriWeights[3];
vtkNew<vtkIdList> TriIds;
double QuadWeights[4];
vtkNew<vtkIdList> QuadIds;
// Internal methods for sampling edges, triangles, and polygons
void SampleEdge(
vtkPoints* pts, vtkIdType p0, vtkIdType p1, vtkPointData* inPD, vtkPointData* outPD);
void SampleTriangle(vtkPoints* newPts, vtkPoints* inPts, const vtkIdType* pts, vtkPointData* inPD,
vtkPointData* outPD);
void SamplePolygon(vtkPoints* newPts, vtkPoints* inPts, vtkIdType npts, const vtkIdType* pts,
vtkPointData* inPD, vtkPointData* outPD);
private:
vtkPolyDataPointSampler(const vtkPolyDataPointSampler&) = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment