Commit 0e06f86c authored by Will Schroeder's avatar Will Schroeder Committed by Kitware Robot

Merge topic 'LouisBergmann/vtk-Quadric-Decimation-Vol-constraint'

189a6b8d Better test image thanks Cory
b93218aa Added test
dbd1dc19 Added Volume Constraint to QuadricDecimation
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Cory Quammen's avatarCory Quammen <cory.quammen@kitware.com>
Merge-request: !1954
parents 82c941ce 189a6b8d
Pipeline #26874 running with stage
in 12 minutes and 57 seconds
......@@ -14,6 +14,7 @@ vtk_add_test_python(
Delaunay3D.py
Delaunay3DAlphaTest.py
QuadricDecimation.py
QuadricDecimation2.py
StreamPolyData.py
TestElevationFilter.py
TestFlyingEdges2D.py
......
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
res = 100
# Test the volume constraint. Create "planar" data with jittery
# z-direction coordinates. Decimate the data with and without
# planar constraints and compare.
#
ps = vtk.vtkPlaneSource()
ps.SetResolution(res,res)
tf = vtk.vtkTriangleFilter()
tf.SetInputConnection(ps.GetOutputPort())
attr = vtk.vtkRandomAttributeGenerator()
attr.SetInputConnection(tf.GetOutputPort())
attr.GeneratePointScalarsOn()
attr.SetMinimumComponentValue(-0.05)
attr.SetMaximumComponentValue(0.05)
# This jitters the geometry
warp = vtk.vtkWarpScalar()
warp.SetInputConnection(attr.GetOutputPort())
warp.SetScaleFactor(0.02)
# Decimator without volume constraint
deci = vtk.vtkQuadricDecimation()
deci.SetInputConnection(warp.GetOutputPort())
deci.SetTargetReduction(.95)
deci.AttributeErrorMetricOn()
deci.VolumePreservationOff()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(warp.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Decimator with volume constraint
deci2 = vtk.vtkQuadricDecimation()
deci2.SetInputConnection(warp.GetOutputPort())
deci2.SetTargetReduction(.95)
deci2.AttributeErrorMetricOn()
deci2.VolumePreservationOn()
mapper2 = vtk.vtkPolyDataMapper()
mapper2.SetInputConnection(deci.GetOutputPort())
actor2 = vtk.vtkActor()
actor2.SetMapper(mapper2)
# Original noisy surface
#
mapper3 = vtk.vtkPolyDataMapper()
mapper3.SetInputConnection(deci2.GetOutputPort())
actor3 = vtk.vtkActor()
actor3.SetMapper(mapper3)
# Create rendering instances
#
ren0 = vtk.vtkRenderer()
ren0.SetViewport(0,0,.33,1)
ren1 = vtk.vtkRenderer()
ren1.SetViewport(0.33,0,0.66,1)
ren2 = vtk.vtkRenderer()
ren2.SetViewport(0.66,0,1,1)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren0)
renWin.AddRenderer(ren1)
renWin.AddRenderer(ren2)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Set up the camera parameters
#
camera = vtk.vtkCamera()
camera.SetFocalPoint(0,0,0)
camera.SetPosition(0,0,1)
camera.Elevation(45.0)
ren0.SetActiveCamera(camera)
ren1.SetActiveCamera(camera)
ren2.SetActiveCamera(camera)
# Add the actors to the renderer, set the background and size
#
ren0.AddActor(actor)
ren1.AddActor(actor2)
ren2.AddActor(actor3)
ren0.SetBackground(0,0,0)
ren1.SetBackground(0,0,0)
ren2.SetBackground(0,0,0)
renWin.SetSize(600,300)
ren0.ResetCamera()
renWin.Render()
iren.Initialize()
# gather some information
print ( "Bounds (volume preserve off): ({0})".format( deci.GetOutput().GetPoints().GetBounds() ) )
print ( "Bounds (volume preserve on): ({0})".format( deci2.GetOutput().GetPoints().GetBounds() ) )
#iren.Start()
# --- end of script --
This diff is collapsed.
......@@ -84,6 +84,16 @@ public:
vtkGetMacro(AttributeErrorMetric, int);
vtkBooleanMacro(AttributeErrorMetric, int);
// Description:
// Decide whether to activate volume preservation which greatly reduces errors
// in triangle normal direction. If off, volume preservation is disabled and
// if AttributeErrorMetric is active, these errors can be large.
// By default VolumePreservation is off
// the attribute errors are off.
vtkSetMacro(VolumePreservation, int);
vtkGetMacro(VolumePreservation, int);
vtkBooleanMacro(VolumePreservation, int);
// Description:
// If attribute errors are to be included in the metric (i.e.,
// AttributeErrorMetric is on), then the following flags control which
......@@ -188,6 +198,7 @@ protected:
double TargetReduction;
double ActualReduction;
int AttributeErrorMetric;
int VolumePreservation;
int ScalarsAttribute;
int VectorsAttribute;
......@@ -215,8 +226,13 @@ protected:
double *Quadric;
};
// One ErrorQuadric per point
ErrorQuadric *ErrorQuadrics;
int AttributeComponents[6];
// Contains 4 doubles per point. Length = nPoints * 4
double *VolumeConstraints;
int AttributeComponents[6];
double AttributeScale[6];
// Temporary variables for performance
......
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