本文整理汇总了Python中vtk.vtkDecimatePro函数的典型用法代码示例。如果您正苦于以下问题:Python vtkDecimatePro函数的具体用法?Python vtkDecimatePro怎么用?Python vtkDecimatePro使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkDecimatePro函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:ChaliZhg,项目名称:vmtk,代码行数:28,代码来源:vmtksurfacedecimation.py
示例2: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkDecimatePro(), 'Processing.',
('vtkPolyData',), ('vtkPolyData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkDecimatePro.py
示例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
开发者ID:avontd2868,项目名称:OU_Final_Year,代码行数:9,代码来源:vtkOperations.py
示例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
开发者ID:quentan,项目名称:Algorithms,代码行数:56,代码来源:ImplicitFitting.py
示例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
开发者ID:LucasGandel,项目名称:Slicer,代码行数:54,代码来源:SurfaceToolbox.py
示例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()
开发者ID:grosenkj,项目名称:telluricpy,代码行数:11,代码来源:polydata.py
示例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";
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:12,代码来源:CreatePolydata.py
示例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
开发者ID:cni,项目名称:Psych204A_OLD,代码行数:17,代码来源:vtk_render.py
示例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)
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:44,代码来源:PolydataVisualization.py
示例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()
开发者ID:andyTsing,项目名称:MicroView,代码行数:42,代码来源:ROIObject.py
示例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"
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:41,代码来源:NewSurface.py
示例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
开发者ID:vmtk,项目名称:SlicerExtension-VMTK,代码行数:23,代码来源:CenterlineComputation.py
示例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()
开发者ID:sanguinariojoe,项目名称:devide,代码行数:36,代码来源:decimate.py
示例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
开发者ID:chalkie666,项目名称:bioimagexd-svn-import-from-sourceforge,代码行数:67,代码来源:AnalyzeObjectsFilter.py
示例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)
#.........这里部分代码省略.........
开发者ID:alexsavio,项目名称:nidoodles,代码行数:101,代码来源:vtksurface.py
示例16: decimate_file
def decimate_file(input_vtk, reduction=0.5, smooth_steps=100, output_vtk=''):
"""
Decimate vtk triangular mesh file with vtk.vtkDecimatePro.
Parameters
----------
input_vtk : string
input vtk file with triangular surface mesh
reduction : float
fraction of mesh faces to remove
do_smooth : Boolean
smooth after decimation?
output_vtk : string
output decimated vtk file
Returns
-------
output_vtk : string
output decimated vtk file
Examples
--------
>>> import os
>>> from mindboggle.utils.mesh import decimate_file
>>> path = os.environ['MINDBOGGLE_DATA']
>>> input_vtk = os.path.join(path, 'arno', 'labels', 'label22.vtk')
>>> output_vtk = 'decimated_file.vtk'
>>> reduction = 0.9
>>> smooth_steps = 0
>>> decimate_file(input_vtk, reduction=reduction,
>>> smooth_steps=smooth_steps, output_vtk=output_vtk)
>>> # View:
>>> os.system('mayavi2 -d ' + output_vtk + ' -m Surface &')
"""
import os
import vtk
from mindboggle.utils.io_vtk import read_vtk
# Read VTK surface mesh file:
faces, u1, u2, points, u4, labels, u5, u6 = read_vtk(input_vtk)
# vtk points:
vtk_points = vtk.vtkPoints()
[vtk_points.InsertPoint(i, x[0], x[1], x[2]) for i,x in enumerate(points)]
# vtk faces:
vtk_faces = vtk.vtkCellArray()
for face in faces:
vtk_face = vtk.vtkPolygon()
vtk_face.GetPointIds().SetNumberOfIds(3)
vtk_face.GetPointIds().SetId(0, face[0])
vtk_face.GetPointIds().SetId(1, face[1])
vtk_face.GetPointIds().SetId(2, face[2])
vtk_faces.InsertNextCell(vtk_face)
# vtkPolyData:
polydata = vtk.vtkPolyData()
polydata.SetPoints(vtk_points)
polydata.SetPolys(vtk_faces)
# We want to preserve topology (not let any cracks form).
# This may limit the total reduction possible.
decimate = vtk.vtkDecimatePro()
decimate.SetInput(polydata)
decimate.SetTargetReduction(reduction)
decimate.PreserveTopologyOn()
# Export output:
if not output_vtk:
output_vtk = os.path.join(os.getcwd(), 'decimated_file.vtk')
exporter = vtk.vtkPolyDataWriter()
if smooth_steps > 0:
smoother = vtk.vtkSmoothPolyDataFilter()
smoother.SetInputConnection(decimate.GetOutputPort())
smoother.SetNumberOfIterations(smooth_steps)
exporter.SetInput(smoother.GetOutput())
else:
exporter.SetInput(decimate.GetOutput())
exporter.SetFileName(output_vtk)
exporter.Write()
return output_vtk
开发者ID:TankThinkLabs,项目名称:mindboggle,代码行数:84,代码来源:mesh.py
示例17: decimate
def decimate(points, faces, reduction=0.5, smooth_steps=100, output_vtk=''):
"""
Decimate vtk triangular mesh with vtk.vtkDecimatePro.
Parameters
----------
points : list of lists of floats
each element is a list of 3-D coordinates of a vertex on a surface mesh
faces : list of lists of integers
each element is list of 3 indices of vertices that form a face
on a surface mesh
reduction : float
fraction of mesh faces to remove
smooth_steps : integer
number of smoothing steps
output_vtk : string
output decimated vtk file
Returns
-------
points : list of lists of floats
decimated points
faces : list of lists of integers
decimated faces
output_vtk : string
output decimated vtk file
Examples
--------
>>> import os
>>> from mindboggle.utils.io_vtk import read_vtk, write_vtk
>>> from mindboggle.utils.mesh import decimate
>>> path = os.environ['MINDBOGGLE_DATA']
>>> input_vtk = os.path.join(path, 'arno', 'labels', 'label22.vtk')
>>> reduction = 0.5
>>> smooth_steps = 100
>>> output_vtk = ''
>>> faces, lines, indices, points, npoints, scalars, scalar_names,
... o2 = read_vtk(input_vtk)
>>> points, faces, output_vtk = decimate(points, faces, reduction,
>>> smooth_steps, output_vtk)
>>> len(points) == 4567
True
>>> len(points)
4567
>>> # View:
>>> write_vtk('decimated.vtk', points, indices, lines, faces, scalars,
>>> scalar_names) # doctest: +SKIP
>>> os.system('mayavi2 -d decimated.vtk -m Surface &') # doctest: +SKIP
"""
import os
import vtk
from mindboggle.utils.io_vtk import read_vtk
# vtk points:
vtk_points = vtk.vtkPoints()
[vtk_points.InsertPoint(i, x[0], x[1], x[2]) for i,x in enumerate(points)]
# vtk faces:
vtk_faces = vtk.vtkCellArray()
for face in faces:
vtk_face = vtk.vtkPolygon()
vtk_face.GetPointIds().SetNumberOfIds(3)
vtk_face.GetPointIds().SetId(0, face[0])
vtk_face.GetPointIds().SetId(1, face[1])
vtk_face.GetPointIds().SetId(2, face[2])
vtk_faces.InsertNextCell(vtk_face)
# vtkPolyData:
polydata = vtk.vtkPolyData()
polydata.SetPoints(vtk_points)
polydata.SetPolys(vtk_faces)
# We want to preserve topology (not let any cracks form).
# This may limit the total reduction possible.
decimate = vtk.vtkDecimatePro()
decimate.SetInput(polydata)
decimate.SetTargetReduction(reduction)
decimate.PreserveTopologyOn()
# Export output:
if not output_vtk:
output_vtk = os.path.join(os.getcwd(), 'decimated_file.vtk')
#exporter = vtk.vtkPolyDataWriter()
if smooth_steps > 0:
smoother = vtk.vtkSmoothPolyDataFilter()
smoother.SetInput(decimate.GetOutput())
smoother.SetNumberOfIterations(smooth_steps)
smoother.Update()
out = smoother.GetOutput()
#exporter.SetInput(smoother.GetOutput())
else:
decimate.Update()
out = decimate.GetOutput()
#exporter.SetInput(decimate.GetOutput())
#exporter.SetFileName(output_vtk)
#exporter.Write()
## Extract points and faces:
#.........这里部分代码省略.........
开发者ID:TankThinkLabs,项目名称:mindboggle,代码行数:101,代码来源:mesh.py
示例18: topology
# vtk faces:
vtk_faces = vtk.vtkCellArray()
for face in faces:
vtk_face = vtk.vtkPolygon()
vtk_face.GetPointIds().SetNumberOfIds(3)
vtk_face.GetPointIds().SetId(0, face[0])
vtk_face.GetPointIds().SetId(1, face[1])
vtk_face.GetPointIds().SetId(2, face[2])
vtk_faces.InsertNextCell(vtk_face)
# vtkPolyData:
polydata = vtk.vtkPolyData()
polydata.SetPoints(vtk_points)
polydata.SetPolys(vtk_faces)
# We want to preserve topology (not let any cracks form).
# This may limit the total reduction possible.
decimate = vtk.vtkDecimatePro()
decimate.SetInput(polydata)
decimate.SetTargetReduction(reduction)
decimate.PreserveTopologyOn()
if smooth_steps > 0:
smoother = vtk.vtkSmoothPolyDataFilter()
smoother.SetInputConnection(decimate.GetOutputPort())
smoother.SetNumberOfIterations(smooth_steps)
output = smoother.GetOutput()
else:
output = decimate.GetOutput()
开发者ID:TankThinkLabs,项目名称:mindboggle,代码行数:29,代码来源:mesh.py
示例19: ALGORITHM
polydata = contour.GetOutput() #export the 3D image as a polygon data file
algordata = contour.GetOutputPort() #export the 3D image as an algorithm file
"""
"""
#VOXEL CONTOURING ALGORITHM (doesnt work yet)
vcsf = vtk.vtkVoxelContoursToSurfaceFilter()
vcsf.SetInputConnection(imgThreshold)
vcsf.Update()
polydata = vcsf.GetOutput() #export the 3D image as a polygon data file
algordata = vcsf.GetOutputPort() #export the 3D image as an algorithm file
"""
#############################
#Reduce Number of Triangles
decimator = vtk.vtkDecimatePro()
decimator.SetInputConnection(algordata)
decimator.SetTargetReduction(0.5)
decimator.SetPreserveTopology(1)
decimator.Update()
reducetri = decimator.GetOutputPort()
#
#Smooth
smooth = vtk.vtkSmoothPolyDataFilter()
smooth.SetInputConnection(filhol)
smooth.SetNumberOfIterations(15)
smooth.SetFeatureAngle(10)
smooth.SetRelaxationFactor(0.05)
smooth.FeatureEdgeSmoothingOn()
开发者ID:abhishektha,项目名称:SpaceFlightAdaptedBoneStrength,代码行数:31,代码来源:VTK.py
示例20: surface
def surface(points, triangles, labels, ctab=None, opacity=1, set_lut=True,
decimation_ratio=1):
""" Create a colored triangular surface.
Parameters
----------
points: array (n_vertices, 3)
the surface vertices.
triangles: array
nfaces x 3 array defining mesh triangles.
labels: array (n_vertices)
Annotation id at each vertex.
If a vertex does not belong to any label its id must be negative.
ctab: ndarray (n_labels, 5) (optional, default None)
RGBA + label id color table array. If None a default blue to red
256 levels lookup table is used.
opacity: float (optional, default 1)
the actor global opacity.
set_lut: bool (optional, default True)
if True set a tuned lut.
decimation_ratio: float (optional, default 1)
how many triangles should reduced by specifying the percentage
([0,1]) of triangles to be removed.
Returns
-------
actor: vtkActor
one actor handling the surface.
"""
# First setup points, triangles and colors
vtk_points = vtk.vtkPoints()
vtk_triangles = vtk.vtkCellArray()
vtk_colors = vtk.vtkUnsignedCharArray()
vtk_colors.SetNumberOfComponents(1)
labels[numpy.where(labels < 0)] = 0
for index in range(len(points)):
vtk_points.InsertNextPoint(points[index])
vtk_colors.InsertNextTuple1(labels[index])
for cnt, triangle in enumerate(triangles):
vtk_triangle = vtk.vtkTriangle()
vtk_triangle.GetPointIds().SetId(0, triangle[0])
vtk_triangle.GetPointIds().SetId(1, triangle[1])
vtk_triangle.GetPointIds().SetId(2, triangle[2])
vtk_triangles.InsertNextCell(vtk_triangle)
# Make a lookup table using vtkColorSeries
lut = vtk.vtkLookupTable()
if ctab is not None:
nb_of_labels = len(ctab)
lut.SetNumberOfColors(nb_of_labels)
lut.Build()
for cnt, lut_element in enumerate(ctab):
lut.SetTableValue(
cnt, lut_element[0] / 255., lut_element[1] / 255.,
lut_element[2] / 255., lut_element[3] / 255.)
lut.SetNanColor(1, 0, 0, 1)
# This creates a blue to red lut.
else:
nb_of_labels = 255
lut.SetHueRange(0.667, 0.0)
lut.SetNumberOfColors(nb_of_labels)
lut.Build()
# Create (geometry and topology) the associated polydata
polydata = vtk.vtkPolyData()
polydata.SetPoints(vtk_points)
polydata.GetPointData().SetScalars(vtk_colors)
polydata.SetPolys(vtk_triangles)
# Decimate the mesh
decimate = vtk.vtkDecimatePro()
decimate.SetInputConnection(polydata.GetProducerPort())
decimate.SetTargetReduction(decimation_ratio)
# Create the mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(decimate.GetOutput())
if set_lut:
mapper.SetLookupTable(lut)
mapper.SetColorModeToMapScalars()
mapper.SetScalarRange(0, nb_of_labels)
mapper.SetScalarModeToUsePointData()
else:
mapper.ScalarVisibilityOff()
# Create the actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(opacity)
actor.GetProperty().SetColor(0.9, 0.9, 0.9)
return actor
开发者ID:gareaut,项目名称:caps-clindmri,代码行数:92,代码来源:pvtk.py
注:本文中的vtk.vtkDecimatePro函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论