Exemple #1
0
def points_to_unstructured(x,y,z):
  nx = len(x)
  # points
  xyz = np.zeros(3*nx, dtype=np.float32)
  xyz[::3] = x[:]
  xyz[1::3] = y[:]
  xyz[2::3] = z[:]
  vxyz = svtknp.numpy_to_svtk(xyz, deep=1)
  vxyz.SetNumberOfComponents(3)
  vxyz.SetNumberOfTuples(nx)
  pts = svtk.svtkPoints()
  pts.SetData(vxyz)
  # cells
  ct = svtknp.numpy_to_svtk(np.full(nx, svtk.SVTK_VERTEX, dtype=np.uint8),
                            deep=1, array_type=svtk.SVTK_UNSIGNED_CHAR)

  cc = np.empty(nx,dtype=np.int64)
  cc[:] = np.arange(0,nx,dtype=np.int64)

  co = np.empty(nx+1,dtype=np.int64)
  co[:] = np.arange(0,nx+1,dtype=np.int64)

  ca = svtk.svtkCellArray()
  ca.SetData(svtknp.numpy_to_svtk(co, deep=1, array_type=svtk.SVTK_ID_TYPE),
             svtknp.numpy_to_svtk(cc, deep=1, array_type=svtk.SVTK_ID_TYPE))
  # package it all up in a poly data set
  ug = svtk.svtkUnstructuredGrid()
  ug.SetPoints(pts)
  ug.SetCells(ct, ca)
  # add some scalar data
  get_data_arrays(nx, ug.GetPointData())
  get_data_arrays(nx, ug.GetCellData())


  return ug
Exemple #2
0
def points_to_polydata(x,y,z):
  nx = len(x)
  # points
  xyz = np.zeros(3*nx, dtype=np.float32)
  xyz[::3] = x[:]
  xyz[1::3] = y[:]
  xyz[2::3] = z[:]
  vxyz = svtknp.numpy_to_svtk(xyz, deep=1)
  vxyz.SetNumberOfComponents(3)
  vxyz.SetNumberOfTuples(nx)
  pts = svtk.svtkPoints()
  pts.SetData(vxyz)
  # cells
  cc = np.empty(nx,dtype=np.int64)
  cc[:] = np.arange(0,nx,dtype=np.int64)

  co = np.empty(nx+1,dtype=np.int64)
  co[:] = np.arange(0,nx+1,dtype=np.int64)

  ca = svtk.svtkCellArray()
  ca.SetData(svtknp.numpy_to_svtk(co, deep=1, array_type=svtk.SVTK_ID_TYPE),
             svtknp.numpy_to_svtk(cc, deep=1, array_type=svtk.SVTK_ID_TYPE))
  # package it all up in a poly data set
  pd = svtk.svtkPolyData()
  pd.SetPoints(pts)
  pd.SetVerts(ca)
  # add some scalar data
  get_data_arrays(nx, pd.GetPointData())
  get_data_arrays(nx, pd.GetCellData())
  return pd
Exemple #3
0
 def testPoints(self):
     """Test the index limits for svtkPoints
     """
     points = svtk.svtkPoints()
     p = (1.0, 2.0, 3.0)
     points.InsertNextPoint(p)
     self.assertEqual(points.GetPoint(0), p)
     with self.assertRaises(ValueError):
         points.GetPoint(-1)
     with self.assertRaises(ValueError):
         points.GetPoint(1)
     with self.assertRaises(ValueError):
         points.SetPoint(-1, p)
     with self.assertRaises(ValueError):
         points.SetPoint(1, p)
#!/usr/bin/env python
import svtk

poly = svtk.svtkPolyData()
pts = svtk.svtkPoints()
pts.InsertNextPoint(0, 0, 0)
pts.InsertNextPoint(1, 0, 0)
pts.InsertNextPoint(1, 1, 0)
pts.InsertNextPoint(0, 1, 0)
scalars = svtk.svtkFloatArray()
scalars.SetName('foo')
for i in range(0, 4):
    scalars.InsertNextValue(float(i + 1))
poly.GetPointData().SetScalars(scalars)

cells = svtk.svtkCellArray()
cells.InsertNextCell(0)
cells.InsertNextCell(1)
for i in range(0, 4):
    cells.InsertCellPoint(i)

poly.SetPoints(pts)
poly.SetPolys(cells)
print('PolyData has {} points and {} cells'.format(poly.GetNumberOfPoints(),
                                                   poly.GetNumberOfCells()))

celldata = svtk.svtkPointDataToCellData()
celldata.SetInputData(poly)
celldata.Update()
# --- end of script ---
Exemple #5
0
table.SetTableRange(0, 1)
table.SetValueRange(1.0, 0.0)
table.SetSaturationRange(0.0, 0.0)
table.SetHueRange(0.0, 0.0)
table.SetAlphaRange(0.0, 1.0)
table.Build()
alpha = svtk.svtkImageMapToColors()
alpha.SetInputConnection(imageGrid.GetOutputPort())
alpha.SetLookupTable(table)
reader1 = svtk.svtkBMPReader()
reader1.SetFileName("" + str(SVTK_DATA_ROOT) + "/Data/masonry.bmp")
blend = svtk.svtkImageBlend()
blend.AddInputConnection(0, reader1.GetOutputPort())
blend.AddInputConnection(0, alpha.GetOutputPort())
# next, create a ThinPlateSpline transform
p1 = svtk.svtkPoints()
p1.SetNumberOfPoints(8)
p1.SetPoint(0, 0, 0, 0)
p1.SetPoint(1, 0, 255, 0)
p1.SetPoint(2, 255, 0, 0)
p1.SetPoint(3, 255, 255, 0)
p1.SetPoint(4, 96, 96, 0)
p1.SetPoint(5, 96, 159, 0)
p1.SetPoint(6, 159, 159, 0)
p1.SetPoint(7, 159, 96, 0)
p2 = svtk.svtkPoints()
p2.SetNumberOfPoints(8)
p2.SetPoint(0, 0, 0, 0)
p2.SetPoint(1, 0, 255, 0)
p2.SetPoint(2, 255, 0, 0)
p2.SetPoint(3, 255, 255, 0)
# --------------------------------------

mb = svtk.svtkMultiBlockDataSet()
mb.SetBlock(0, svtk.svtkImageData())
mb.SetBlock(1, svtk.svtkImageData())
assert dsa.WrapDataObject(mb).Points is na

mb = svtk.svtkMultiBlockDataSet()
mb.SetBlock(0, svtk.svtkStructuredGrid())
mb.SetBlock(1, svtk.svtkImageData())
assert dsa.WrapDataObject(mb).Points is na

mb = svtk.svtkMultiBlockDataSet()
sg = svtk.svtkStructuredGrid()
sg.SetPoints(svtk.svtkPoints())
mb.SetBlock(0, sg)
mb.SetBlock(1, svtk.svtkImageData())
assert dsa.WrapDataObject(mb).Points.Arrays[0] is not na
assert dsa.WrapDataObject(mb).Points.Arrays[1] is na

# --------------------------------------
# try appending scalars
ssource = svtk.svtkSphereSource()
ssource.Update()
output = ssource.GetOutput()
pdw = dsa.WrapDataObject(output)
original_arrays = pdw.PointData.GetNumberOfArrays()
pdw.PointData.append(12, "twelve")
pdw.PointData.append(12.12, "twelve-point-twelve")
assert pdw.PointData.GetNumberOfArrays() == (2 + original_arrays)
Exemple #7
0
    rgb = [0.0, 0.0, 0.0]  # black
    svtk.svtkNamedColors().GetColorRGB(colorName, rgb)
    return rgb


#
# Demonstrate the use of implicit selection loop as well as closest point
# connectivity
#
# create pipeline
#
sphere = svtk.svtkSphereSource()
sphere.SetRadius(1)
sphere.SetPhiResolution(100)
sphere.SetThetaResolution(100)
selectionPoints = svtk.svtkPoints()
selectionPoints.InsertPoint(0, 0.07325, 0.8417, 0.5612)
selectionPoints.InsertPoint(1, 0.07244, 0.6568, 0.7450)
selectionPoints.InsertPoint(2, 0.1727, 0.4597, 0.8850)
selectionPoints.InsertPoint(3, 0.3265, 0.6054, 0.7309)
selectionPoints.InsertPoint(4, 0.5722, 0.5848, 0.5927)
selectionPoints.InsertPoint(5, 0.4305, 0.8138, 0.4189)
loop = svtk.svtkImplicitSelectionLoop()
loop.SetLoop(selectionPoints)
extract = svtk.svtkExtractGeometry()
extract.SetInputConnection(sphere.GetOutputPort())
extract.SetImplicitFunction(loop)
connect = svtk.svtkConnectivityFilter()
connect.SetInputConnection(extract.GetOutputPort())
connect.SetExtractionModeToClosestPointRegion()
connect.SetClosestPoint(selectionPoints.GetPoint(0))
Exemple #8
0
colors.InsertComponent(0, 1, 99)
colors.InsertComponent(0, 2, 71)
colors.InsertComponent(1, 0, 125)
colors.InsertComponent(1, 1, 255)
colors.InsertComponent(1, 2, 0)
colors.InsertComponent(2, 0, 226)
colors.InsertComponent(2, 1, 207)
colors.InsertComponent(2, 2, 87)
sizes = svtk.svtkUnsignedCharArray()
sizes.SetName("Sizes")
sizes.SetNumberOfComponents(1)
sizes.SetNumberOfTuples(3)
sizes.SetValue(0, 1)
sizes.SetValue(1, 2)
sizes.SetValue(2, 3)
polyVertexPoints = svtk.svtkPoints()
polyVertexPoints.SetNumberOfPoints(3)
polyVertexPoints.InsertPoint(0, 0.0, 0.0, 0.0)
polyVertexPoints.InsertPoint(1, 2.5, 0.0, 0.0)
polyVertexPoints.InsertPoint(2, 5.0, 0.0, 0.0)
aPolyVertex = svtk.svtkPolyVertex()
aPolyVertex.GetPointIds().SetNumberOfIds(3)
aPolyVertex.GetPointIds().SetId(0, 0)
aPolyVertex.GetPointIds().SetId(1, 1)
aPolyVertex.GetPointIds().SetId(2, 2)
aPolyVertexGrid = svtk.svtkUnstructuredGrid()
aPolyVertexGrid.Allocate(1, 1)
aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(),
                               aPolyVertex.GetPointIds())
aPolyVertexGrid.SetPoints(polyVertexPoints)
aPolyVertexGrid.GetPointData().SetScalars(sizes)
Exemple #9
0
import sys
import svtk
from svtk.util.misc import svtkGetDataRoot
SVTK_DATA_ROOT = svtkGetDataRoot()

# Prevent .pyc files being created.
# Stops the svtk source being polluted
# by .pyc files.
sys.dont_write_bytecode = True

import backdrop

# Contour every quadratic cell type
# Create a scene with one of each cell type.
# QuadraticEdge
edgePoints = svtk.svtkPoints()
edgePoints.SetNumberOfPoints(3)
edgePoints.InsertPoint(0, 0, 0, 0)
edgePoints.InsertPoint(1, 1.0, 0, 0)
edgePoints.InsertPoint(2, 0.5, 0.25, 0)
edgeScalars = svtk.svtkFloatArray()
edgeScalars.SetNumberOfTuples(3)
edgeScalars.InsertValue(0, 0.0)
edgeScalars.InsertValue(1, 0.0)
edgeScalars.InsertValue(2, 0.9)
aEdge = svtk.svtkQuadraticEdge()
aEdge.GetPointIds().SetId(0, 0)
aEdge.GetPointIds().SetId(1, 1)
aEdge.GetPointIds().SetId(2, 2)
aEdgeGrid = svtk.svtkUnstructuredGrid()
aEdgeGrid.Allocate(1, 1)
Exemple #10
0
#testSize = "large"
#testSize = "medium"
testSize = "small"

if testSize == "large":
    numPts = 100000000
    numProbes = 1000000
elif testSize == "medium":
    numPts = 2000000
    numProbes = 50000
else:
    numPts = 20000
    numProbes = 5000

# Create an initial set of points and associated dataset
points = svtk.svtkPoints()
points.SetDataTypeToDouble()
points.SetNumberOfPoints(numPts)
for i in range(0, numPts):
    points.SetPoint(i, math.Random(-1, 1), math.Random(-1, 1),
                    math.Random(-1, 1))

polydata = svtk.svtkPolyData()
polydata.SetPoints(points)
points.ComputeBounds()

# Create points array which are positions to probe data with
# FindClosestPoint(), We also create an array to hold the results of this
# probe operation.
probePoints = svtk.svtkPoints()
probePoints.SetDataTypeToDouble()
ren.AddActor(actorL)
ren.AddActor(actorC)
ren.AddActor(actorR)

# Now clip boxes
origin = [0, 0, 0]
xout = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
bds = [0, 0, 0, 0, 0, 0]
clipBox = svtk.svtkBox()

# Left
normal = [1, 1, 1]
origin = boxL.GetCenter()
pdL = svtk.svtkPolyData()
polyL = svtk.svtkCellArray()
ptsL = svtk.svtkPoints()
pdL.SetPoints(ptsL)
pdL.SetPolys(polyL)
ptsL.SetDataTypeToDouble()
boxL.GetBounds(bds)
numInts = clipBox.IntersectWithPlane(bds, origin, normal, xout)
print("Num ints: ", numInts)
ptsL.SetNumberOfPoints(numInts)
polyL.InsertNextCell(numInts)
for i in range(0, numInts):
    ptsL.SetPoint(i, xout[3 * i], xout[3 * i + 1], xout[3 * i + 2])
    polyL.InsertCellPoint(i)
mapperPL = svtk.svtkPolyDataMapper()
mapperPL.SetInputData(pdL)
actorPL = svtk.svtkActor()
actorPL.SetMapper(mapperPL)
Exemple #12
0
#!/usr/bin/env python
import svtk
from svtk.util.misc import svtkGetDataRoot
SVTK_DATA_ROOT = svtkGetDataRoot()

# Remove cullers so single vertex will render
ren1 = svtk.svtkRenderer()
ren1.GetCullers().RemoveAllItems()
renWin = svtk.svtkRenderWindow()
renWin.AddRenderer(ren1)
iren = svtk.svtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
cell = svtk.svtkGenericCell()
ptIds = svtk.svtkIdList()
# 0D
ZeroDPts = svtk.svtkPoints()
ZeroDPts.SetNumberOfPoints(1)
ZeroDPts.SetPoint(0, 0, 0, 0)
ZeroDGrid = svtk.svtkStructuredGrid()
ZeroDGrid.SetDimensions(1, 1, 1)
ZeroDGrid.SetPoints(ZeroDPts)
ZeroDGrid.GetCell(0)
ZeroDGrid.GetCell(0, cell)
ZeroDGrid.GetCellPoints(0, ptIds)
ZeroDGeom = svtk.svtkStructuredGridGeometryFilter()
ZeroDGeom.SetInputData(ZeroDGrid)
ZeroDGeom.SetExtent(0, 2, 0, 2, 0, 2)
ZeroDMapper = svtk.svtkPolyDataMapper()
ZeroDMapper.SetInputConnection(ZeroDGeom.GetOutputPort())
ZeroDActor = svtk.svtkActor()
ZeroDActor.SetMapper(ZeroDMapper)