Esempio n. 1
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
#!/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 ---
Esempio n. 3
0
assert na[:, 0] is na
assert algs.where(na[:, 0] > 0) is na
assert (na > 0) is na

# Test ufunc
assert algs.cos(na) is na

# Various numerical ops implemented in SVTK
assert algs.gradient(na) is na
assert algs.cross(na, na) is na
assert algs.cross(v.Arrays[0], na) is na
assert algs.cross(na, v.Arrays[0]) is na

assert algs.make_vector(na, g[:, 0], elev) is na

pd = svtk.svtkPolyData()
pdw = dsa.WrapDataObject(pd)
pdw.PointData.append(na, 'foo')
assert pdw.PointData.GetNumberOfArrays() == 0

# --------------------------------------

na2 = dsa.SVTKCompositeDataArray([randomVec.Arrays[0], na])

# Test operators
assert (1 + na2 - 1 - randomVec).Arrays[1] is na

# Test slicing and indexing
assert na2[:, 0].Arrays[1] is na
assert algs.where(na2[:, 0] > 0).Arrays[1] is na
assert (na2 > 0).Arrays[1] is na
Esempio n. 4
0
tris.InsertCellPoint(1)
tris.InsertCellPoint(2)
tris.InsertNextCell(3)
tris.InsertCellPoint(0)
tris.InsertCellPoint(2)
tris.InsertCellPoint(3)
tris.InsertNextCell(3)
tris.InsertCellPoint(0)
tris.InsertCellPoint(3)
tris.InsertCellPoint(1)
tris.InsertNextCell(3)
tris.InsertCellPoint(1)
tris.InsertCellPoint(2)
tris.InsertCellPoint(3)

polys = svtk.svtkPolyData()
polys.SetPoints(pts)
polys.SetPolys(tris)

mesh = svtk.svtkQuadricClustering()
mesh.SetInputConnection(sphere.GetOutputPort())
mesh.SetNumberOfXDivisions(10)
mesh.SetNumberOfYDivisions(10)
mesh.SetNumberOfZDivisions(10)

mapper = svtk.svtkPolyDataMapper()
mapper.SetInputConnection(mesh.GetOutputPort())

actor = svtk.svtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetDiffuseColor(GetRGBColor('tomato'))
Esempio n. 5
0
"svtkAMREnzoReader"  # core dump
])

# In the case of Windows, these classes cause a crash.
classWindowsExceptions = set([
"svtkWin32VideoSource",  # Update() works the first time but a subsequent run calls up the webcam which crashes on close.

"svtkCMLMoleculeReader",
"svtkCPExodusIIInSituReader",
"svtkMINCImageWriter",
"svtkQtInitialization"
])

classExceptions = set()

emptyPD = svtk.svtkPolyData()
emptyID = svtk.svtkImageData()
emptySG = svtk.svtkStructuredGrid()
emptyUG = svtk.svtkUnstructuredGrid()
emptyRG = svtk.svtkRectilinearGrid()

# This will hold the classes to be tested.
svtkClasses = set()
classNames = None
classesTested = set()

# Keep a record of the classes tested.
nonexistentClasses = set()
abstractClasses = set()
noConcreteImplementation = set()
noShutdown = set()
Esempio n. 6
0
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()
probePoints.SetNumberOfPoints(numProbes)
math.RandomSeed(314159)
for i in range(0, numProbes):
    probePoints.SetPoint(i, math.Random(-1, 1), math.Random(-1, 1),
                         math.Random(-1, 1))
closest = svtk.svtkIdList()
closest.SetNumberOfIds(numProbes)
actorR.GetProperty().SetAmbient(1)

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)