本文整理汇总了Python中vtk.vtkDecimatePro函数的典型用法代码示例。如果您正苦于以下问题:Python vtkDecimatePro函数的具体用法?Python vtkDecimatePro怎么用?Python vtkDecimatePro使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkDecimatePro函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Execute
def Execute(self):
if self.Surface == None:
self.PrintError('Error: No input surface.')
triangleFilter = vtk.vtkTriangleFilter()
triangleFilter.SetInput(self.Surface)
triangleFilter.Update()
decimationFilter = vtk.vtkDecimatePro()
decimationFilter.SetInput(triangleFilter.GetOutput())
decimationFilter.SetTargetReduction(self.TargetReduction)
decimationFilter.SetBoundaryVertexDeletion(self.BoundaryVertexDeletion)
decimationFilter.PreserveTopologyOn()
decimationFilter.Update()
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInput(decimationFilter.GetOutput())
cleaner.Update()
triangleFilter = vtk.vtkTriangleFilter()
triangleFilter.SetInput(cleaner.GetOutput())
triangleFilter.Update()
self.Surface = triangleFilter.GetOutput()
if self.Surface.GetSource():
self.Surface.GetSource().UnRegisterAllOutputs()
示例2: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkDecimatePro(), 'Processing.',
('vtkPolyData',), ('vtkPolyData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例3: decimation_pro
def decimation_pro(data,ratio):
sim = vtk.vtkDecimatePro();
sim.SetTargetReduction(ratio);
sim.SetInputData(data);
sim.PreserveTopologyOn();
sim.SplittingOff();
sim.BoundaryVertexDeletionOff();
sim.Update()
return sim.GetOutput();0
示例4: get_actor
def get_actor(vtk_source, color=color_diffuse, opacity=1.0,
has_scalar_visibility=False, has_decimator=False):
"""
Set `scalar_visibility` be `True` makes `color` unavailable.
:return: a vtkActor
"""
if has_decimator:
# Reduce the number of triangles
decimator = vtk.vtkDecimatePro()
decimator.SetInputConnection(vtk_source.GetOutputPort())
# decimator.SetInputData(vtk_source)
decimator.SetFeatureAngle(60)
decimator.MaximumIterations = 1
decimator.PreserveTopologyOn()
decimator.SetMaximumError(0.0002)
decimator.SetTargetReduction(1)
decimator.SetErrorIsAbsolute(1)
decimator.SetAbsoluteError(0.0002)
decimator.ReleaseDataFlagOn()
# Generate Normals
normals = vtk.vtkPolyDataNormals()
if has_decimator:
normals.SetInputConnection(decimator.GetOutputPort())
else:
normals.SetInputConnection(vtk_source.GetOutputPort())
normals.SetFeatureAngle(60.0)
normals.ReleaseDataFlagOn()
stripper = vtk.vtkStripper()
stripper.SetInputConnection(normals.GetOutputPort())
stripper.ReleaseDataFlagOn()
mapper = vtk.vtkPolyDataMapper()
# mapper.SetInputConnection(vtk_source.GetOutputPort())
mapper.SetInputConnection(stripper.GetOutputPort())
mapper.SetScalarVisibility(has_scalar_visibility)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetDiffuseColor(color)
actor.GetProperty().SetSpecular(0.3)
actor.GetProperty().SetSpecularPower(20)
actor.GetProperty().SetInterpolation(2)
# actor.GetProperty().SetRepresentation(2)
# actor.GetProperty().SetEdgeVisibility(True)
# actor.GetProperty().SetOpacity(opacity)
if opacity < 1.0:
if is_depth_peeling_supported(render_window, renderer, True):
setup_evn_for_depth_peeling(render_window, renderer, max_peels, occlusion)
actor.GetProperty().SetOpacity(opacity)
else:
print "Depth Peeling is not supported."
return actor
示例5: applyFilters
def applyFilters(self, state):
surface = None
surface = state.inputModelNode.GetPolyDataConnection()
if state.decimation:
triangle = vtk.vtkTriangleFilter()
triangle.SetInputConnection(surface)
decimation = vtk.vtkDecimatePro()
decimation.SetTargetReduction(state.reduction)
decimation.SetBoundaryVertexDeletion(state.boundaryDeletion)
decimation.PreserveTopologyOn()
decimation.SetInputConnection(triangle.GetOutputPort())
surface = decimation.GetOutputPort()
if state.smoothing:
if state.smoothingMethod == "Laplace":
smoothing = vtk.vtkSmoothPolyDataFilter()
smoothing.SetBoundarySmoothing(state.boundarySmoothing)
smoothing.SetNumberOfIterations(state.laplaceIterations)
smoothing.SetRelaxationFactor(state.laplaceRelaxation)
smoothing.SetInputConnection(surface)
surface = smoothing.GetOutputPort()
elif state.smoothingMethod == "Taubin":
smoothing = vtk.vtkWindowedSincPolyDataFilter()
smoothing.SetBoundarySmoothing(state.boundarySmoothing)
smoothing.SetNumberOfIterations(state.taubinIterations)
smoothing.SetPassBand(state.taubinPassBand)
smoothing.SetInputConnection(surface)
surface = smoothing.GetOutputPort()
if state.normals:
normals = vtk.vtkPolyDataNormals()
normals.AutoOrientNormalsOn()
normals.SetFlipNormals(state.flipNormals)
normals.SetSplitting(state.splitting)
normals.SetFeatureAngle(state.featureAngle)
normals.ConsistencyOn()
normals.SetInputConnection(surface)
surface = normals.GetOutputPort()
if state.cleaner:
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInputConnection(surface)
surface = cleaner.GetOutputPort()
if state.connectivity:
connectivity = vtk.vtkPolyDataConnectivityFilter()
connectivity.SetExtractionModeToLargestRegion()
connectivity.SetInputConnection(surface)
surface = connectivity.GetOutputPort()
state.outputModelNode.SetPolyDataConnection(surface)
return True
示例6: decimatePolygon
def decimatePolygon(polyObject,reduceFactor=0.5):
'''
'''
deci = vtk.vtkDecimatePro()
deci.SetInputData(polyObject)
deci.SetTargetReduction(reduceFactor)
deci.BoundaryVertexDeletionOff()
deci.PreserveTopologyOn()
deci.SetSplitting(0)
deci.Update()
return deci.GetOutput()
示例7: __init__
def __init__(self, inputs = (1,1)):
"""
Initialization
"""
self.defaultLower = 0
self.defaultUpper = 255
lib.ProcessingFilter.ProcessingFilter.__init__(self,(1,1))
self.contour = vtk.vtkMarchingCubes()
self.decimate = vtk.vtkDecimatePro()
self.descs = {"Simplify": "Simplify surface", "IsoValue":"Iso-surface value",
"PreserveTopology":"PreserveTopology"}
self.filterDesc = "Creates iso-surface as polygons\nInput: Binary image (Grayscale image)\nOutput: Surface mesh";
示例8: vtk_smooth
def vtk_smooth(iso, iter=20, relax=0.5, decimate=0.0):
isoSmooth = vtk.vtkSmoothPolyDataFilter()
if decimate>0:
deci = vtk.vtkDecimatePro()
deci.SetInput(iso.GetOutput())
deci.SetTargetReduction(decimate)
deci.PreserveTopologyOn()
isoSmooth.SetInputConnection(deci.GetOutputPort())
else:
isoSmooth.SetInputConnection(iso.GetOutputPort())
isoSmooth.SetNumberOfIterations(100)
isoSmooth.BoundarySmoothingOn()
isoSmooth.FeatureEdgeSmoothingOff()
isoSmooth.SetFeatureAngle(45)
isoSmooth.SetEdgeAngle(15)
isoSmooth.SetRelaxationFactor(relax)
return isoSmooth
示例9: __init__
def __init__(self, parent, visualizer, **kws):
"""
Initialization
"""
self.init = False
VisualizationModule.__init__(self, parent, visualizer, numberOfInputs=(2, 2), **kws)
# self.name = "Surface Rendering"
self.normals = vtk.vtkPolyDataNormals()
self.smooth = None
self.volumeModule = None
self.scalarRange = (0, 255)
for i in range(1, 3):
self.setInputChannel(i, i)
self.eventDesc = "Rendering iso-surface"
self.decimate = vtk.vtkDecimatePro()
self.mapper = vtk.vtkPolyDataMapper()
self.mapper2 = vtk.vtkPolyDataMapper()
self.contour = vtk.vtkMarchingCubes()
self.contour2 = vtk.vtkDiscreteMarchingCubes()
self.descs = {
"Normals": "Smooth surface with normals",
"FeatureAngle": "Feature angle of normals\n",
"Simplify": "Simplify surface",
"PreserveTopology": "Preserve topology",
"Transparency": "Surface transparency",
"Distance": "Distance to consider inside",
"MarkColor": "Mark in/outside objects with colors",
}
self.actor = self.lodActor = vtk.vtkLODActor()
self.lodActor.SetMapper(self.mapper)
self.lodActor.SetNumberOfCloudPoints(10000)
self.actor2 = vtk.vtkLODActor()
self.actor2.SetMapper(self.mapper2)
self.actor2.SetNumberOfCloudPoints(10000)
self.renderer = self.parent.getRenderer()
self.renderer.AddActor(self.lodActor)
self.renderer.AddActor(self.actor2)
lib.messenger.connect(None, "highlight_object", self.onHighlightObject)
示例10: GeneratePolyData
def GeneratePolyData(self):
if self._imagemask:
contour_filter = vtk.vtkMarchingCubes()
contour_filter.ReleaseDataFlagOn()
contour_filter.SetNumberOfContours(1)
contour_filter.SetComputeScalars(0)
contour_filter.SetComputeNormals(0)
if vtk.vtkVersion().GetVTKMajorVersion() > 5:
contour_filter.SetInputData(self._imagemask)
else:
contour_filter.SetInput(self._imagemask)
contour_filter.SetValue(0, 128.0)
try:
contour_filter.Update()
except:
print sys.exc_type, sys.exc_value
return False
decimate = vtk.vtkDecimatePro()
decimate.ReleaseDataFlagOn()
decimate.SetInputConnection(contour_filter.GetOutputPort())
decimate.PreserveTopologyOn()
decimate.SetTargetReduction(0)
try:
decimate.Update()
except:
print sys.exc_type, sys.exc_value
return False
if self._polydata is None:
self._polydata = GeometryObject(
self._name, self._name, decimate.GetOutputPort())
else:
self._polydata.SetInputConnection(decimate.GetOutputPort())
if self._wireframe:
self._polydata.SetWireFrameOn()
else:
self._polydata.SetWireFrameOff()
self._polydata.SetVisibilityOff()
示例11: __init__
def __init__(self, parent, visualizer, **kws):
"""
Initialization
"""
VisualizationModule.__init__(self, parent, visualizer, **kws)
# self.name = "Surface Rendering"
# for i in range(1, 3):
# self.setInputChannel(i, i)
self.normals = vtk.vtkPolyDataNormals()
self.smooth = None
self.volumeModule = None
self.scalarRange = (0, 255)
self.eventDesc = "Rendering iso-surface"
self.decimate = vtk.vtkDecimatePro()
self.setMethod(1)
self.init = 0
self.mapper = vtk.vtkPolyDataMapper()
self.descs = {
"Method": "Surface rendering method",
"Gaussian": "Smooth surface with gaussian smoothing",
"Normals": "Smooth surface with normals",
"FeatureAngle": "Feature angle of normals\n",
"Simplify": "Simplify surface",
"PreserveTopology": "Preserve topology",
"IsoValue": "Iso value",
"SurfaceRangeBegin": "Generate surfaces in range:\n",
"SurfaceAmnt": "Number of surfaces",
"Transparency": "Surface transparency",
"MultipleSurfaces": "Visualize multiple surfaces",
"SolidColor": "Color surface with max. intensity",
}
self.actor = self.lodActor = vtk.vtkLODActor()
self.lodActor.SetMapper(self.mapper)
self.lodActor.SetNumberOfCloudPoints(10000)
self.renderer = self.parent.getRenderer()
self.renderer.AddActor(self.lodActor)
# self.updateRendering()
self.filterDesc = "Create and visualize iso-surface"
示例12: decimateSurface
def decimateSurface(self, polyData):
'''
'''
decimationFilter = vtk.vtkDecimatePro()
decimationFilter.SetInputData(polyData)
decimationFilter.SetTargetReduction(0.99)
decimationFilter.SetBoundaryVertexDeletion(0)
decimationFilter.PreserveTopologyOn()
decimationFilter.Update()
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInputData(decimationFilter.GetOutput())
cleaner.Update()
triangleFilter = vtk.vtkTriangleFilter()
triangleFilter.SetInputData(cleaner.GetOutput())
triangleFilter.Update()
outPolyData = vtk.vtkPolyData()
outPolyData.DeepCopy(triangleFilter.GetOutput())
return outPolyData
示例13: __init__
def __init__(self, module_manager):
# call parent constructor
ModuleBase.__init__(self, module_manager)
# the decimator only works on triangle data, so we make sure
# that it only gets triangle data
self._triFilter = vtk.vtkTriangleFilter()
self._decimate = vtk.vtkDecimatePro()
self._decimate.PreserveTopologyOn()
self._decimate.SetInput(self._triFilter.GetOutput())
module_utils.setup_vtk_object_progress(self, self._triFilter, "Converting to triangles")
module_utils.setup_vtk_object_progress(self, self._decimate, "Decimating mesh")
# now setup some defaults before our sync
self._config.target_reduction = self._decimate.GetTargetReduction() * 100.0
config_list = [
(
"Target reduction (%):",
"target_reduction",
"base:float",
"text",
"Decimate algorithm will attempt to reduce by this much.",
)
]
ScriptedConfigModuleMixin.__init__(
self,
config_list,
{"Module (self)": self, "vtkDecimatePro": self._decimate, "vtkTriangleFilter": self._triFilter},
)
self.sync_module_logic_with_config()
示例14: execute
#.........这里部分代码省略.........
data = labelShape.GetOutput()
data.Update()
numberOfLabels = labelShape.GetNumberOfLabels()
if self.parameters["AvgInt"]:
avgintCalc = itk.LabelStatisticsImageFilter[origITK,labelITK].New()
avgintCalc.SetInput(origITK)
avgintCalc.SetLabelInput(labelITK)
avgintCalc.Update()
self.progressObj.setProgress(0.2)
self.updateProgress(None, "ProgressEvent")
# Area calculation pipeline
if self.parameters["Area"]:
voxelArea = x*y*2 + x*z*2 + y*z*2
largestSize = labelITK.GetLargestPossibleRegion().GetSize()
# if 2D image, calculate area using volume
if largestSize.GetSizeDimension() > 2 and largestSize.GetElement(2) > 1:
areaSpacing = labelVTK.GetSpacing()
objectThreshold = vtk.vtkImageThreshold()
objectThreshold.SetInput(labelVTK)
objectThreshold.SetOutputScalarTypeToUnsignedChar()
objectThreshold.SetInValue(255)
objectThreshold.SetOutValue(0)
marchingCubes = vtk.vtkMarchingCubes()
#marchingCubes.SetInput(labelVTK)
marchingCubes.SetInput(objectThreshold.GetOutput())
massProperties = vtk.vtkMassProperties()
massProperties.SetInput(marchingCubes.GetOutput())
areaDiv = (areaSpacing[0] / x)**2
if self.parameters["Smoothness"]:
smoothDecimate = vtk.vtkDecimatePro()
smoothProperties = vtk.vtkMassProperties()
smoothDecimate.SetTargetReduction(0.9)
smoothDecimate.PreserveTopologyOff()
smoothDecimate.SetInput(marchingCubes.GetOutput())
smoothProperties.SetInput(smoothDecimate.GetOutput())
# Filter needed for axes calculations
if self.parameters["Axes"] and newITKStatistics:
labelGeometry = itk.LabelGeometryImageFilter[labelITK,labelITK].New()
labelGeometry.SetCalculateOrientedBoundingBox(1)
labelGeometry.SetInput(labelITK)
labelGeometry.Update()
# Get results and do some calculations for each object
tott = 0
voxelSize = voxelSizes[0] * voxelSizes[1] * voxelSizes[2]
for i in range(startIntensity, numberOfLabels+1):
areaInUm = 0.0
avgInt = 0
avgIntStdErr = 0.0
roundness = 0.0
objIntSum = 0.0
minorLength = 0.0
majorLength = 0.0
elongation = 0.0
angleMinX = 0.0
angleMinY = 0.0
angleMinZ = 0.0
angleMajX = 0.0
angleMajY = 0.0
angleMajZ = 0.0
smoothness = 0.0
示例15: __init__
def __init__(self, filename, renderer):
self.renderer = renderer
reader = vtk.vtkStructuredPointsReader()
#reader.SetFileName('/home/mcc/src/devel/extract_mri_slices/braintest2.vtk')
reader.SetFileName(filename)
# we want to move this from its (.87 .92 .43) esque position to something more like 'the center'
# how to do this?!?
# ALTERNATIVELY: we want to use vtkInteractorStyleTrackballActor
# somewhere instead of the interactor controlling the main window and 3 planes
imagedata = reader.GetOutput()
#reader.SetFileName(filename)
cf = vtk.vtkContourFilter()
cf.SetInput(imagedata)
# ???
cf.SetValue(0, 1)
deci = vtk.vtkDecimatePro()
deci.SetInput(cf.GetOutput())
deci.SetTargetReduction(.1)
deci.PreserveTopologyOn()
smoother = vtk.vtkSmoothPolyDataFilter()
smoother.SetInput(deci.GetOutput())
smoother.SetNumberOfIterations(100)
# XXX try to call SetScale directly on actor..
#self.scaleTransform = vtk.vtkTransform()
#self.scaleTransform.Identity()
#self.scaleTransform.Scale(.1, .1, .1)
#transformFilter = vtk.vtkTransformPolyDataFilter()
#transformFilter.SetTransform(self.scaleTransform)
#transformFilter.SetInput(smoother.GetOutput())
#cf.SetValue(1, 2)
#cf.SetValue(2, 3)
#cf.GenerateValues(0, -1.0, 1.0)
#deci = vtk.vtkDecimatePro()
#deci.SetInput(cf.GetOutput())
#deci.SetTargetReduction(0.8) # decimate_value
normals = vtk.vtkPolyDataNormals()
#normals.SetInput(transformFilter.GetOutput())
normals.SetInput(smoother.GetOutput())
normals.FlipNormalsOn()
"""
tags = vtk.vtkFloatArray()
tags.InsertNextValue(1.0)
tags.InsertNextValue(0.5)
tags.InsertNextValue(0.7)
tags.SetName("tag")
"""
lut = vtk.vtkLookupTable()
lut.SetHueRange(0, 0)
lut.SetSaturationRange(0, 0)
lut.SetValueRange(0.2, 0.55)
contourMapper = vtk.vtkPolyDataMapper()
contourMapper.SetInput(normals.GetOutput())
contourMapper.SetLookupTable(lut)
###contourMapper.SetColorModeToMapScalars()
###contourMapper.SelectColorArray("tag")
self.contours = vtk.vtkActor()
self.contours.SetMapper(contourMapper)
#if (do_wireframe):
#self.contours.GetProperty().SetRepresentationToWireframe()
#elif (do_surface):
self.contours.GetProperty().SetRepresentationToSurface()
self.contours.GetProperty().SetInterpolationToGouraud()
self.contours.GetProperty().SetOpacity(1.0)
self.contours.GetProperty().SetAmbient(0.1)
self.contours.GetProperty().SetDiffuse(0.1)
self.contours.GetProperty().SetSpecular(0.1)
self.contours.GetProperty().SetSpecularPower(0.1)
# XXX arbitrarily setting scale to this
#self.contours.SetScale(.1, .1,.1)
renderer.AddActor(self.contours)
#.........这里部分代码省略.........