VTK学习笔记(二十六)Python vtkMassProperties示例
- 1、Python vtkMassProperties示例
-
- 1.1、 utility.py 项目: gmaher/tcl_code
- 1.2、文件: CellMech_bkup.py 项目: siboles/pyCellAnalyst
- 1.3、文件: ClosedSurfaceSegmentStatisticsPlugin.py 项目: BRAINSia/Slicer
- 1.4、文件: MassProperties.py 项目: jlec/VTK
- 1.5、文件: vtkMassProperties.py 项目: fvpolpeta/devide
- 1.6、CalculateSurfaceArea
- 1.7、文件: CellMech.py 项目: siboles/pyCellAnalyst
- 1.8、文件: createMassProperties.py 项目: gacevedobolton/myVTKPythonLibrary
- 1.9、文件: getMassProperties.py 项目: mgenet/myVTKPythonLibrary
1、Python vtkMassProperties示例
Python vtkMassProperties - 已找到30个示例。这些是从开源项目中提取的最受好评的vtk.vtkMassProperties现实Python示例。
1.1、 utility.py 项目: gmaher/tcl_code
def jaccard3D_pd(pd1,pd2):
"""
computes the jaccard distance error for two polydata objects
returns (error) float
"""
union = vtk.vtkBooleanOperationPolyDataFilter()
union.SetOperationToUnion()
union.SetInputData(0,pd1)
union.SetInputData(1,pd2)
union.Update()
u = union.GetOutput()
massUnion = vtk.vtkMassProperties()
massUnion.SetInputData(u)
intersection = vtk.vtkBooleanOperationPolyDataFilter()
intersection.SetOperationToIntersection()
intersection.SetInputData(0,pd1)
intersection.SetInputData(1,pd2)
intersection.Update()
i = intersection.GetOutput()
massIntersection = vtk.vtkMassProperties()
massIntersection.SetInputData(i)
return 1 - massIntersection.GetVolume()/massUnion.GetVolume()
1.2、文件: CellMech_bkup.py 项目: siboles/pyCellAnalyst
def obj(x,sF,devF,R,sv,mv,tv,material,spatial,rc,sc):
nF = np.dot(R,x[0]*sF)+np.dot(R,x[1]*devF)
#Make a copy of material configuration and deform this with nF
nm = vtk.vtkPolyData()
nm.DeepCopy(material)
pcoords = vtk.vtkFloatArray()
pcoords.SetNumberOfComponents(3)
pcoords.SetNumberOfTuples(nm.GetNumberOfPoints())
for i in xrange(nm.GetNumberOfPoints()):
p = [0.,0.,0.]
nm.GetPoint(i,p)
p = np.dot(nF,p-rc)
p.flatten()
pcoords.SetTuple3(i,p[0]+sc[0],p[1]+sc[1],p[2]+sc[2])
points = vtk.vtkPoints()
points.SetData(pcoords)
nm.SetPoints(points)
nm.GetPoints().Modified()
#calculate both the intersection and the union of the two polydata
intersect = vtk.vtkBooleanOperationPolyDataFilter()
intersect.SetOperation(1)
intersect.SetInputData(0,nm)
intersect.SetInputData(1,spatial)
intersect.Update()
union = vtk.vtkBooleanOperationPolyDataFilter()
union.SetOperation(0)
union.SetInputData(0,nm)
union.SetInputData(1,spatial)
union.Update()
unionmass = vtk.vtkMassProperties()
unionmass.SetInputConnection(union.GetOutputPort())
vol_union = unionmass.GetVolume()
if intersect.GetOutput().GetNumberOfPoints() > 0:
intmass = vtk.vtkMassProperties()
intmass.SetInputConnection(intersect.GetOutputPort())
vol_int = intmass.GetVolume()
else:
#penalize with distance between centroids
w = sc.T-np.dot(nF,rc.T)
c = np.linalg.norm(w)
vol_int = c*vol_union
diff = max([abs(sv-vol_int),abs(sv-vol_union)])
return diff
1.3、文件: ClosedSurfaceSegmentStatisticsPlugin.py 项目: BRAINSia/Slicer
def computeStatistics(self, segmentID):
import vtkSegmentationCorePython as vtkSegmentationCore
requestedKeys = self.getRequestedKeys()
segmentationNode = slicer.mrmlScene.GetNodeByID(self.getParameterNode().GetParameter("Segmentation"))
if len(requestedKeys)==0:
return {
}
containsClosedSurfaceRepresentation = segmentationNode.GetSegmentation().ContainsRepresentation(
vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName())
if not containsClosedSurfaceRepresentation:
return {
}
segment = segmentationNode.GetSegmentation().GetSegment(segmentID)
closedSurfaceName = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationClosedSurfaceRepresentationName()
segmentClosedSurface = segment.GetRepresentation(closedSurfaceName)
# Compute statistics
massProperties = vtk.vtkMassProperties()
massProperties.SetInputData(segmentClosedSurface)
# Add data to statistics list
ccPerCubicMM = 0.001
stats = {
}
if "surface_mm2" in requestedKeys:
stats["surface_mm2"] = massProperties.GetSurfaceArea()
if "volume_mm3" in requestedKeys:
stats["volume_mm3"] = massProperties.GetVolume()
if "volume_cm3" in requestedKeys:
stats["volume_cm3"] = massProperties.GetVolume() * ccPerCubicMM
return stats
1.4、文件: MassProperties.py 项目: jlec/VTK
def MakeText(primitive):
tf.update({
primitive: vtk.vtkTriangleFilter()})
tf[primitive].SetInputConnection(primitive.GetOutputPort())
mp.update({
primitive: vtk.vtkMassProperties()})
mp[primitive].SetInputConnection(tf[primitive].GetOutputPort())
# here we capture stdout and write it to a variable for processing.
summary = StringIO.StringIO()
# save the original stdout
old_stdout = sys.stdout
sys.stdout = summary
print mp[primitive]
summary = summary.getvalue()
startSum = summary.find(" VolumeX")
endSum = len(summary)
print summary[startSum:]
# Restore stdout
sys.stdout = old_stdout
vt.update({
primitive: vtk.vtkVectorText()})
vt[primitive].SetText(summary[startSum:])
pdm.update({
primitive: vtk.vtkPolyDataMapper()})
pdm[primitive].SetInputConnection(vt[primitive].GetOutputPort())
ta.update({
primitive: vtk.vtkActor()})
ta[primitive].SetMapper(pdm[primitive])
ta[primitive].SetScale(0.2, 0.2, 0.2)
return ta[primitive]
1.5、文件: vtkMassProperties.py 项目: fvpolpeta/devide
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkMassProperties(), 'Processing.',
('vtkPolyData',), (),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
1.6、CalculateSurfaceArea
def CalculateSurfaceArea(polydata):
"""
Calculate the volume from the given polydata
"""
# Filter used to calculate volume and area from a polydata
measured_polydata = vtk.vtkMassProperties()
measured_polydata.SetInputData(polydata)
return measured_polydata.GetSurfaceArea()
1.7、文件: CellMech.py 项目: siboles/pyCellAnalyst
def _readstls(self):
"""
Reads in all STL files contained in directories indicated by **ref_dir** and **def_dir**.
Also calls **_make3Dmesh()** to create 3-D tetrahedral meshes.
Returns
-------
rsurfs, dsurfs
"""
for fname in sorted(os.listdir(self._ref_dir)):
if '.stl' in fname.lower():
reader = vtk.vtkSTLReader()
reader.SetFileName(
str(os.path.normpath(self._ref_dir + os.sep + fname)))
reader.Update()
triangles = vtk.vtkTriangleFilter()
triangles.SetInputConnection(reader.GetOutputPort())
triangles.Update()
self.rsurfs.append(triangles.GetOutput())
massProps = vtk.vtkMassProperties()
massProps.SetInputData(self.rsurfs[-1])
massProps.Update()
print(("Generating tetrahedral mesh from {:s}".format(fname)))
self._make3Dmesh(
str(os.path.normpath(self._ref_dir + os.sep + fname)),
'MATERIAL', massProps.GetVolume())
for fname in sorted(os.listdir(self._def_dir)):
if '.stl' in fname.lower():
reader = vtk.vtkSTLReader()
reader.SetFileName(
str(os.path.normpath(self._def_dir + os.sep + fname)))
reader.Update()
triangles = vtk.vtkTriangleFilter()
triangles.SetInputConnection(reader.GetOutputPort())
triangles.Update()
self.dsurfs.append(triangles.GetOutput())
massProps = vtk.vtkMassProperties()
massProps.SetInputData(self.dsurfs[-1])
massProps.Update()
print(("Generating tetrahedral mesh from {:s}".format(fname)))
self._make3Dmesh(
str(os.path.normpath(self._def_dir + os.sep + fname)),
'SPATIAL', massProps.GetVolume())
1.8、文件: createMassProperties.py 项目: gacevedobolton/myVTKPythonLibrary
def createMassProperties(
pdata,
verbose=1):
myVTK.myPrint(verbose, "*** createMassProperties ***")
mass_properties = vtk.vtkMassProperties()
mass_properties.SetInputData(pdata)
return mass_properties
1.9、文件: getMassProperties.py 项目: mgenet/myVTKPythonLibrary
def getMassProperties(
pdata,
verbose=0):
mypy.my_print(verbose, "*** getMassProperties ***")
mass_properties = vtk.vtkMassProperties()
if (vtk.vtkVersion.GetVTKMajorVersion() >= 6):
mass_properties.SetInputData(pdata)
else:
mass_properties.SetInput(pdata)
return mass_properties