本文整理汇总了Python中vtk.vtkPolyDataNormals函数的典型用法代码示例。如果您正苦于以下问题:Python vtkPolyDataNormals函数的具体用法?Python vtkPolyDataNormals怎么用?Python vtkPolyDataNormals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkPolyDataNormals函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OnExportSurface
def OnExportSurface(self, pubsub_evt):
filename, filetype = pubsub_evt.data
if (filetype == const.FILETYPE_STL) or\
(filetype == const.FILETYPE_VTP) or\
(filetype == const.FILETYPE_PLY) or\
(filetype == const.FILETYPE_STL_ASCII):
# First we identify all surfaces that are selected
# (if any)
proj = prj.Project()
polydata_list = []
for index in proj.surface_dict:
surface = proj.surface_dict[index]
if surface.is_shown:
polydata_list.append(surface.polydata)
if len(polydata_list) == 0:
utl.debug("oops - no polydata")
return
elif len(polydata_list) == 1:
polydata = polydata_list[0]
else:
polydata = pu.Merge(polydata_list)
# Having a polydata that represents all surfaces
# selected, we write it, according to filetype
if filetype == const.FILETYPE_STL:
writer = vtk.vtkSTLWriter()
writer.SetFileTypeToBinary()
elif filetype == const.FILETYPE_STL_ASCII:
writer = vtk.vtkSTLWriter()
writer.SetFileTypeToASCII()
elif filetype == const.FILETYPE_VTP:
writer = vtk.vtkXMLPolyDataWriter()
#elif filetype == const.FILETYPE_IV:
# writer = vtk.vtkIVWriter()
elif filetype == const.FILETYPE_PLY:
writer = vtk.vtkPLYWriter()
writer.SetFileTypeToASCII()
writer.SetColorModeToOff()
#writer.SetDataByteOrderToLittleEndian()
#writer.SetColorModeToUniformCellColor()
#writer.SetColor(255, 0, 0)
if filetype in (const.FILETYPE_STL, const.FILETYPE_PLY):
# Invert normals
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(polydata)
normals.SetFeatureAngle(80)
normals.AutoOrientNormalsOn()
# normals.GetOutput().ReleaseDataFlagOn()
normals.UpdateInformation()
normals.Update()
polydata = normals.GetOutput()
filename = filename.encode(wx.GetDefaultPyEncoding())
writer.SetFileName(filename)
writer.SetInputData(polydata)
writer.Write()
示例2: __init__
def __init__(self, mesh):
assert mesh != None
self._mesh = mesh
self._batch = None
self._color = (0.0, 1.0, 0.0, 1.0)
#smooth_loop = vtk.vtkLoopSubdivisionFilter()
#smooth_loop.SetNumberOfSubdivisions(3)
#smooth_loop.SetInput(cleanPolyData.GetOutput())
#self.mesh = smooth_loop.GetOutput()
normals = vtk.vtkPolyDataNormals()
normals.SetInput(self._mesh)
normals.ComputeCellNormalsOn()
output = normals.GetOutput()
output.Update();
cellData = output.GetCellData();
self._normals = cellData.GetNormals();
self._caster = vtk.vtkOBBTree()
#set the 'mesh' as the caster's dataset
self._caster.SetDataSet(self._mesh)
#build a caster locator
self._caster.BuildLocator()
示例3: _initialize
def _initialize (self):
debug ("In TensorGlyphs::_initialize ()")
self.sphere.SetThetaResolution (8)
self.sphere.SetPhiResolution (8)
self.glyphs.SetInput (self.data_out)
self.glyphs.SetSource (self.sphere.GetOutput())
self.glyphs.SetScaleFactor (1.0)
self.glyphs.ClampScalingOn ()
self.glyphs.SetMaxScaleFactor (5.0)
self.normals = vtk.vtkPolyDataNormals ()
self.normals.SetInput (self.glyphs.GetOutput ())
self.mapper.SetInput (self.normals.GetOutput ())
self.actor.SetMapper (self.mapper)
self.actor.GetProperty ().SetLineWidth (2)
self.actor.GetProperty ().BackfaceCullingOff ()
# self.actor.GetProperty ().FrontfaceCullingOff ()
self.actor.GetProperty ().SetColor (*Common.config.fg_color)
self.center = self.data_out.GetCenter ()
self.renwin.add_actors (self.actor)
# used for the pipeline browser
self.pipe_objs = self.actor
示例4: AddPolyData
def AddPolyData(self, polyData, colorMap=None):
"""
colorMap should be a vtkScalarsToColors (or derived class) object
"""
if colorMap is None:
colorMap = VTKViewer.GetDefaultColorMap(polyData.GetScalarRange())
polyDataMapper = vtk.vtkPolyDataMapper()
polyDataMapper.SetLookupTable(colorMap)
if polyData.GetPointData().GetNormals() is None:
polyDataNormals = vtk.vtkPolyDataNormals()
try:
polyDataNormals.SetInputData(polyData)
except:
polyDataNormals.SetInput(polyData)
polyDataNormals.SetFeatureAngle(90.0)
polyDataMapper.SetInputConnection(
polyDataNormals.GetOutputPort())
else:
try:
polyDataMapper.SetInputData(polyData)
except:
polyDataMapper.SetInput(polyData)
actor = vtk.vtkActor()
actor.GetProperty().SetPointSize(3)
actor.SetMapper(polyDataMapper)
self.renderer.AddActor(actor)
示例5: get_isosurface
def get_isosurface(self, iso_value=500):
if not self.flag_read:
sys.stderr.write('No Image Loaded!\n')
return
contour = vtk.vtkContourFilter()
normals = vtk.vtkPolyDataNormals()
stripper = vtk.vtkStripper()
mapper = vtk.vtkPolyDataMapper()
contour.SetInputData(self.reader)
contour.SetValue(0, iso_value)
normals.SetInputConnection(contour.GetOutputPort())
normals.SetFeatureAngle(60.0)
normals.ReleaseDataFlagOn()
stripper.SetInputConnection(normals.GetOutputPort())
stripper.ReleaseDataFlagOn()
mapper.SetInputConnection(stripper.GetOutputPort())
mapper.SetScalarVisibility(False)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Default colour, should be changed.
actor.GetProperty().SetDiffuseColor(
[247.0 / 255.0, 150.0 / 255.0, 155.0 / 255.0]) # Look like red
actor.GetProperty().SetSpecular(0.3)
actor.GetProperty().SetSpecularPower(20)
return actor
示例6: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkPolyDataNormals(), 'Processing.',
('vtkPolyData',), ('vtkPolyData',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例7: MouseMove
def MouseMove(self, data):
print("Load Cache %s" % data )
print ("Iren data")
#print iren
#addcube
#print ren
print ren.GetViewPoint()
print ren.GetDisplayPoint()
print ren.WorldToView()
print ren.ComputeVisiblePropBounds()
ysize = renWin.GetSize()[1]
c.SetValue(0,ysize)
c.Update()
normals = vtk.vtkPolyDataNormals()
normals.SetInputData(c.GetOutput())
normals.SetFeatureAngle(25) #?
normals.Update()
normals.SetFeatureAngle(45) #?
normals.Update()
mapper2 = vtk.vtkPolyDataMapper()
mapper2.SetInputData(normals.GetOutput())
mapper2.ScalarVisibilityOn()
mapper2.SetScalarRange(-.5,1)
mapper2.SetScalarModeToUsePointFieldData()
mapper2.ColorByArrayComponent("Velocity", 0)
actor2 = vtk.vtkActor()
actor2.SetMapper(mapper2)
ren.AddActor(actor2)
示例8: Contours
def Contours(self, num, opacity=0.2):
contour = vtk.vtkMarchingContourFilter()
contour.SetInput(self.vtkgrid)
r = max(abs(self.vmin), abs(self.vmax))
if num % 2 == 0 or self.vmin * self.vmax >= 0:
contour.GenerateValues(
num, (self.vmin + r / num, self.vmax - r / num))
elif num == 1:
contour.SetValue(0, 0)
else:
r = r - r / num
contour.GenerateValues(num, -r, r)
contour.ComputeScalarsOn()
contour.UseScalarTreeOn()
contour.Update()
normals = vtk.vtkPolyDataNormals()
normals.SetInput(contour.GetOutput())
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(normals.GetOutput())
mapper.SetLookupTable(self.lut)
mapper.SetScalarRange(self.vmin, self.vmax)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(opacity)
actor.GetProperty().SetLineWidth(3)
return actor
示例9: __init__
def __init__(self, reader):
self.reader = reader
sg = self.src_glyph = vtk.vtkSphereSource()
sg.SetRadius(0.5)
sg.SetCenter(0.5, 0.0, 0.0)
g = self.glyph = vtk.vtkTensorGlyph()
g.SetInputConnection(self.reader.GetOutputPort())
g.SetSource(self.src_glyph.GetOutput())
g.SetScaleFactor(0.25)
# The normals are needed to generate the right colors and if
# not used some of the glyphs are black.
self.normals = vtk.vtkPolyDataNormals()
self.normals.SetInputConnection(g.GetOutputPort())
self.map = vtk.vtkPolyDataMapper()
self.map.SetInputConnection(self.normals.GetOutputPort())
self.act = vtk.vtkActor()
self.act.SetMapper(self.map)
# An outline.
self.of = vtk.vtkOutlineFilter()
self.of.SetInputConnection(self.reader.GetOutputPort())
self.out_map = vtk.vtkPolyDataMapper()
self.out_map.SetInputConnection(self.of.GetOutputPort())
self.out_act = vtk.vtkActor()
self.out_act.SetMapper(self.out_map)
示例10: vertex_normal
def vertex_normal(dataset):
"Returns the vertex normal of each point in a dataset."
if not dataset:
raise RuntimeError("Need a dataset to compute vertex_normal")
ds = dataset.NewInstance()
ds.UnRegister(None)
ds.CopyStructure(dataset.VTKObject)
filter = vtk.vtkPolyDataNormals()
filter.SetInputData(ds)
filter.ComputeCellNormalsOff()
filter.ComputePointNormalsOn()
filter.SetFeatureAngle(180)
filter.SplittingOff()
filter.ConsistencyOff()
filter.AutoOrientNormalsOff()
filter.FlipNormalsOff()
filter.NonManifoldTraversalOff()
filter.Update()
varray = filter.GetOutput().GetPointData().GetNormals()
ans = dsa.vtkDataArrayToVTKArray(varray, dataset)
# The association information has been lost over the vtk filter
# we must reconstruct it otherwise lower pipeline will be broken.
ans.Association = dsa.ArrayAssociation.POINT
return ans
示例11: polyNorm
def polyNorm(ren,obj):
#@c Add vtkPolyDataNormals to the vtkPolyData viewing pipeline.
#@note there is no proc to perform the reverse operation (i.e. remove
#@note the normals). This is because the caller can presumably just
#@note turn off normal-based properties via the actor's vtkProperty.
#@a ren: renderer
#@a obj: object name
if isinstance(obj,list):
tag = "%s_%s" % (ren[0],obj[0])
objName = obj[0]
elif isinstance(obj,str):
tag = "%s_%s" % (ren[0],obj)
objName = obj
else:
raise ValueError("Argument type unsupported.")
nrm = [None]*2
try:
Map = getattr(vis,"p_map_"+tag)
except:
raise ValueError(objName + " not currently being displayed in " + ren[0])
act = getattr(vis,"p_act_"+tag)
nrm[0] = "p_nrm_" + tag
nrm[1] = vtk.vtkPolyDataNormals()
nrm[1].SetInputDataObject(Map[1].GetInput())
Map[1].SetInputDataObject(nrm[1].GetOutput())
nrm[1].Update()
setattr(vis,Map[0], Map)
setattr(vis,act[0],act)
setattr(vis,nrm[0],nrm)
return act
示例12: AddPolyData
def AddPolyData(self, polyData, colorMap=None):
"""
colorMap should be a vtkScalarsToColors (or derived class) object
"""
if colorMap is None:
colorMap = VTKViewer.GetDefaultColorMap(polyData.GetScalarRange())
polyDataMapper = vtk.vtkPolyDataMapper()
polyDataMapper.SetLookupTable(colorMap)
if polyData.GetPointData().GetNormals() is None:
polyDataNormals = vtk.vtkPolyDataNormals()
# Migrate to VTK6:
# http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput
# Old: polyDataNormals.SetInput(polyData)
polyDataNormals.SetInputData(polyData)
polyDataNormals.SetFeatureAngle(90.0)
polyDataMapper.SetInputConnection(polyDataNormals.GetOutputPort())
else:
# Migrate to VTK6:
# http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput
# Old: polyDataMapper.SetInput(polyData)
polyDataMapper.SetInputData(polyData)
actor = vtk.vtkActor()
actor.GetProperty().SetPointSize(3)
actor.SetMapper(polyDataMapper)
self.renderer.AddActor(actor)
示例13: create_actors_for_skin_and_bone
def create_actors_for_skin_and_bone(reader):
actors_list = []
for contour_val, color, opacity in SKIN_BONE_LIST:
contour = vtk.vtkContourFilter()
contour.SetInput(reader.GetOutput())
contour.SetNumberOfContours(1)
contour.SetValue(contour_val[0], contour_val[1])
normals = vtk.vtkPolyDataNormals()
normals.SetInput(contour.GetOutput())
normals.SetFeatureAngle(60)
normals.ConsistencyOff()
normals.SplittingOff()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(normals.GetOutput())
mapper.ScalarVisibilityOff()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(color)
actor.GetProperty().SetOpacity(opacity)
actor.RotateX(-90)
actors_list.append(actor)
return actors_list
示例14: __init__
def __init__(self, grid, vtkish_polydata=None, angle=15):
vtkPolyDataPipeline.__init__(self, vtkish_polydata)
# Make sure grid argument is correct type
assert isinstance(grid, vtkVolumeGrid)
self.grid = grid
# Split polys with intersection angles greater than angle
vtk_dnorm = vtkPolyDataNormals()
vtk_dnorm.SetFeatureAngle(angle)
vtk_dnorm.SplittingOn()
vtk_dnorm.ComputeCellNormalsOff()
vtk_dnorm.ComputePointNormalsOff()
self.append(vtk_dnorm)
relax = self.grid.get_relaxation_factor()
if relax is not None:
print 'relax=',relax
#vtk_subdiv = vtkButterflySubdivisionFilter()
vtk_subdiv = vtkLinearSubdivisionFilter()
self.append(vtk_subdiv)
# Smooth out some of the sharp points.
vtk_smooth = vtkSmoothPolyDataFilter()
vtk_smooth.SetRelaxationFactor(relax)
self.append(vtk_smooth)
示例15: Execute
def Execute(self):
if self.Surface == None:
self.PrintError('Error: No Surface.')
if self.ReferenceSurface == None:
self.PrintError('Error: No ReferenceSurface.')
if self.SignedDistanceArrayName != '':
normalsFilter = vtk.vtkPolyDataNormals()
normalsFilter.SetInputData(self.ReferenceSurface)
normalsFilter.AutoOrientNormalsOn()
normalsFilter.SetFlipNormals(self.FlipNormals)
normalsFilter.Update()
self.ReferenceSurface.GetPointData().SetNormals(normalsFilter.GetOutput().GetPointData().GetNormals())
if self.DistanceArrayName != '' or self.DistanceVectorsArrayName != '' or self.SignedDistanceArrayName != '':
self.PrintLog('Computing distance.')
surfaceDistance = vtkvmtk.vtkvmtkSurfaceDistance()
surfaceDistance.SetInputData(self.Surface)
surfaceDistance.SetReferenceSurface(self.ReferenceSurface)
if self.DistanceArrayName != '':
surfaceDistance.SetDistanceArrayName(self.DistanceArrayName)
if self.DistanceVectorsArrayName != '':
surfaceDistance.SetDistanceVectorsArrayName(self.DistanceVectorsArrayName)
if self.SignedDistanceArrayName != '':
surfaceDistance.SetSignedDistanceArrayName(self.SignedDistanceArrayName)
surfaceDistance.Update()
self.Surface = surfaceDistance.GetOutput()