コード例 #1
0
def save_one_file(infilename, outfilename):

    df1 = read_file( infilename )

    if df1.shape[0]==0:
      return

    pts = vtk.vtkPoints()
    x = df1['COORX']
    y = df1['COORY']
    z = df1['COORZ']
    tp = df1['ITYPE']
    il = df1['ILAGR']
    ex = df1['EXIST']
    tt = df1['T']
    pts.SetNumberOfPoints(df1.shape[0])

    for j in range(df1.shape[0]):         
        pts.SetPoint(j, (x.iloc[j],y.iloc[j],z.iloc[j]))

    types = vtk.vtkShortArray()
    types.SetNumberOfComponents(1)
    types.SetNumberOfTuples(pts.GetNumberOfPoints())
    types.SetName('ITYPE')
  
    ilagr = vtk.vtkIntArray()
    ilagr.SetNumberOfComponents(1)
    ilagr.SetNumberOfTuples(pts.GetNumberOfPoints())
    ilagr.SetName('ILAGR')

    exist = vtk.vtkShortArray()
    exist.SetNumberOfComponents(1)
    exist.SetNumberOfTuples(pts.GetNumberOfPoints())
    exist.SetName('EXIST')

    T = vtk.vtkFloatArray()
    T.SetNumberOfComponents(1)
    T.SetNumberOfTuples(pts.GetNumberOfPoints())
    T.SetName('T')

    for j in range(df1.shape[0]):         
        types.SetTuple1(j, tp.iloc[j])
        ilagr.SetTuple1(j, il.iloc[j])
        exist.SetTuple1(j, ex.iloc[j])
        T.SetTuple1(j, tt.iloc[j])

    pd = vtk.vtkPolyData()
    pd.SetPoints(pts)
    pd.GetPointData().AddArray(types)
    pd.GetPointData().AddArray(ilagr)
    pd.GetPointData().AddArray(exist)
    pd.GetPointData().AddArray(T)

    wr= vtk.vtkXMLPolyDataWriter()
    wr.SetInputData(pd)
    wr.SetDataModeToBinary()
    wr.SetFileName(outfilename)
    wr.Write()
コード例 #2
0
ファイル: save_particles_pvd.py プロジェクト: skyoum00/tools
def save_one_file(i):
    pts = vtk.vtkPoints()
    df1 = df[df['T'] == unique_times[i]]
    x = df1['COORX']
    y = df1['COORY']
    z = df1['COORZ']
    tp = df1['ITYPE']
    pts.SetNumberOfPoints(df1.shape[0])

    if df1.shape[0] == 0:
        empty_file[i] = 1
    else:
        for j in range(df1.shape[0]):
            pts.SetPoint(j, (x.iloc[j], y.iloc[j], z.iloc[j]))

        types = vtk.vtkShortArray()
        types.SetNumberOfComponents(1)
        types.SetNumberOfTuples(pts.GetNumberOfPoints())
        types.SetName('Type')

        for j in range(df1.shape[0]):
            types.SetTuple1(j, tp.iloc[j])

        pd = vtk.vtkPolyData()
        pd.SetPoints(pts)
        pd.GetPointData().AddArray(types)

        wr = vtk.vtkXMLPolyDataWriter()
        wr.SetInputData(pd)
        wr.SetDataModeToBinary()
        filename = "pts_{:010d}.vtp".format(i)
        wr.SetFileName(filename)
        wr.Write()
コード例 #3
0
ファイル: save_particles_pvd.py プロジェクト: cbutakoff/tools
def save_one_file(i):
    pts = vtk.vtkPoints()
    df1 = df[df['T']==unique_times[i]]
    x = df1['COORX']
    y = df1['COORY']
    z = df1['COORZ']
    tp = df1['ITYPE']
    pts.SetNumberOfPoints(df1.shape[0])

    if df1.shape[0]==0:
        empty_file[i]=1
    else:
        for j in range(df1.shape[0]):         
            pts.SetPoint(j, (x.iloc[j],y.iloc[j],z.iloc[j]))

        types = vtk.vtkShortArray()
        types.SetNumberOfComponents(1)
        types.SetNumberOfTuples(pts.GetNumberOfPoints())
        types.SetName('Type')
        
        for j in range(df1.shape[0]):         
            types.SetTuple1(j, tp.iloc[j])

        pd = vtk.vtkPolyData()
        pd.SetPoints(pts)
        pd.GetPointData().AddArray(types)

        wr= vtk.vtkXMLPolyDataWriter()
        wr.SetInputData(pd)
        wr.SetDataModeToBinary()
        filename = "pts_{:010d}.vtp".format(i)
        wr.SetFileName(filename)
        wr.Write()
コード例 #4
0
    def createArray(self, grid):
        n = grid.GetNumberOfPoints()

        array = vtkShortArray()
        array.SetNumberOfComponents(1)
        array.SetNumberOfTuples(n)

        log.debug("Created an array with %d points" % n)
        return array
コード例 #5
0
def array_to_vtk(inarray, name='from_numpy'):
    vol = vtk.vtkImageData()
    dims = inarray.shape
    vol.SetDimensions(dims[0], dims[1], dims[2])
    vol.SetOrigin(0, 0, 0)
    #vol.SetSpacing(gridSpacing,gridSpacing,gridSpacing)
    sc = vtk.vtkShortArray()
    sc.SetNumberOfValues(dims[0] * dims[1] * dims[2])
    sc.SetNumberOfComponents(1)
    sc.SetName(name)
    for ii, tmp in enumerate(inarray.flatten()):
        sc.SetValue(ii, round((numpy.abs(tmp)) * 100))
    vol.GetPointData().SetScalars(sc)
    return vol
コード例 #6
0
def array_to_vtk(inarray, name='from_numpy'):
    vol = vtk.vtkImageData()
    dims = inarray.shape
    vol.SetDimensions(dims[0], dims[1], dims[2])
    vol.SetOrigin(0,0,0)
    #vol.SetSpacing(gridSpacing,gridSpacing,gridSpacing)
    sc = vtk.vtkShortArray()
    sc.SetNumberOfValues(dims[0] * dims[1] * dims[2])
    sc.SetNumberOfComponents(1)
    sc.SetName(name)
    for ii,tmp in enumerate(inarray.flatten()):
	sc.SetValue(ii,round((numpy.abs(tmp))*100))
    vol.GetPointData().SetScalars(sc)
    return vol
コード例 #7
0
def createShortArray(name,
                     n_components=1,
                     n_tuples=0,
                     init_to_zero=0,
                     verbose=0):

    array = vtk.vtkShortArray()
    array.SetName(name)
    array.SetNumberOfComponents(n_components)
    array.SetNumberOfTuples(n_tuples)

    if (init_to_zero):
        for k_component in range(n_components):
            array.FillComponent(k_component, 0)

    return array
コード例 #8
0
def createShortArray(name,
                     n_components=1,
                     n_tuples=0,
                     init_to_zero=0,
                     verbose=0):

    sarray = vtk.vtkShortArray()
    sarray.SetName(name)
    sarray.SetNumberOfComponents(n_components)
    sarray.SetNumberOfTuples(n_tuples)

    if (init_to_zero):
        for k_tuple in xrange(n_tuples):
            iarray.SetTuple(k_tuple, [0] * n_components)

    return sarray
コード例 #9
0
def createShortArray(
        name,
        n_components=1,
        n_tuples=0,
        init_to_zero=0,
        verbose=1):

    sarray = vtk.vtkShortArray()
    sarray.SetName(name)
    sarray.SetNumberOfComponents(n_components)
    sarray.SetNumberOfTuples(n_tuples)

    if (init_to_zero):
        for k_tuple in xrange(n_tuples):
            iarray.SetTuple(k_tuple, [0]*n_components)

    return sarray
コード例 #10
0
ファイル: mricorrector.py プロジェクト: cbutakoff/tools
def Points2Shape(pts):
    """
    Creates vtkPolyData from points and adds array 'colors' for slice highlighting.
    Assigns 0 to every point
    
    pts Nx3 numpy array of points

    Return vtkPolyData
    """
    shape = mytools.VTKPoints2PolyData( pts )
    scalars = vtk.vtkShortArray()
    scalars.SetName('colors')
    scalars.SetNumberOfComponents(1)
    scalars.SetNumberOfTuples(shape.GetNumberOfPoints())
    
    for i in range(scalars.GetNumberOfTuples()):
        scalars.SetValue(i,0)
        
    shape.GetPointData().AddArray(scalars)
    shape.GetPointData().SetActiveScalars('colors')    
    return shape
    def build_nc_array(self, nc_var):
        vtk_array = None

        if nc_var.dtype.type is np.float64:
            vtk_array = vtk.vtkDoubleArray()
        if nc_var.dtype.type is np.float32:
            vtk_array = vtk.vtkFloatArray()
        if nc_var.dtype.type is np.int8 or nc_var.dtype.type is np.int16:
            vtk_array = vtk.vtkShortArray()
        if nc_var.dtype.type is np.int32 or nc_var.dtype.type is np.int64:
            vtk_array = vtk.vtkIntArray()

        #extract actual data from the data set
        nc_var_data = nc_var[:]

        vtk_array.SetName(nc_var.name)
        vtk_array.SetNumberOfComponents(1)
        vtk_array.SetNumberOfTuples(nc_var_data.size)
        vtk_array.SetArray(nc_var_data.data, nc_var_data.size, True)
        vtk_array.array = nc_var_data.data

        return vtk_array
コード例 #12
0
    pts.SetDataTypeToDouble()
    print('Extracting points', flush=True)
    with progressbar.ProgressBar(max_value=nodes_df.shape[0]) as bar:
        for idx, row in enumerate(nodes_df.itertuples(index=False, name='Pandas')):
            pts.InsertNextPoint( getattr(row, "x")*args.scale, getattr(row, "y")*args.scale, getattr(row, "z")*args.scale)
        


    # ====================================
    #
    #        process the boundary
    #
    # ================================
    bound_df.sort_values(by='newFaceId', ascending=True, inplace=True)

    boundary_id = vtk.vtkShortArray()
    boundary_id.SetName('BoundaryId')
    boundary_id.SetNumberOfComponents(1)
    boundary_id.SetNumberOfTuples(bound_df.shape[0])


    cells = vtk.vtkCellArray()
    #celltypes = np.zeros(bound_df.shape[0], dtype=np.uint64)

    print('Extracting boundary faces', flush=True)
    with progressbar.ProgressBar(max_value=bound_df.shape[0]) as bar:
        for idx, row in enumerate(bound_df.itertuples(index=False, name='Pandas')):
            nodes = getattr(row, "nodes")
            cells.InsertNextCell( len(nodes) )
            for node in nodes:
                cells.InsertCellPoint( int(node)-1 )
コード例 #13
0
def save_one_file(i):
    #df1 = df[df['T']==unique_times[i]]
    df1 = df_global[(df['T'] >= times[i] - halfstep)
                    & (df['T'] < times[i] + halfstep)]

    if df1.shape[0] == 0:
        return

    filename = "pts_{:010d}.vtp".format(i)

    if isfile(filename):
        dft = read_vtk_file(filename)
        df1 = dft.append(df1, ignore_index=True,
                         sort=False)  #add df to the end of the read data

    pts = vtk.vtkPoints()
    x = df1['COORX']
    y = df1['COORY']
    z = df1['COORZ']
    tp = df1['ITYPE']
    il = df1['ILAGR']
    ex = df1['EXIST']
    tt = df1['T']
    pts.SetNumberOfPoints(df1.shape[0])

    if df1.shape[0] != 0:
        for j in range(df1.shape[0]):
            pts.SetPoint(j, (x.iloc[j], y.iloc[j], z.iloc[j]))

        types = vtk.vtkShortArray()
        types.SetNumberOfComponents(1)
        types.SetNumberOfTuples(pts.GetNumberOfPoints())
        types.SetName('ITYPE')

        ilagr = vtk.vtkIntArray()
        ilagr.SetNumberOfComponents(1)
        ilagr.SetNumberOfTuples(pts.GetNumberOfPoints())
        ilagr.SetName('ILAGR')

        exist = vtk.vtkShortArray()
        exist.SetNumberOfComponents(1)
        exist.SetNumberOfTuples(pts.GetNumberOfPoints())
        exist.SetName('EXIST')

        T = vtk.vtkFloatArray()
        T.SetNumberOfComponents(1)
        T.SetNumberOfTuples(pts.GetNumberOfPoints())
        T.SetName('T')

        for j in range(df1.shape[0]):
            types.SetTuple1(j, tp.iloc[j])
            ilagr.SetTuple1(j, il.iloc[j])
            exist.SetTuple1(j, ex.iloc[j])
            T.SetTuple1(j, tt.iloc[j])

        pd = vtk.vtkPolyData()
        pd.SetPoints(pts)
        pd.GetPointData().AddArray(types)
        pd.GetPointData().AddArray(ilagr)
        pd.GetPointData().AddArray(exist)
        pd.GetPointData().AddArray(T)

        wr = vtk.vtkXMLPolyDataWriter()
        wr.SetInputData(pd)
        wr.SetDataModeToBinary()
        wr.SetFileName(filename)
        wr.Write()
コード例 #14
0
ファイル: define_activation.py プロジェクト: cbutakoff/tools
    # In[38]:


    f = open(out_table,'w')
    for ptid in activation_ptids:
        f.write(f'{ptid} {CURDENSITY} 0 {LAPSE}\n')

    f.close()


    # In[37]:


    #save the points with the oriinal mesh for validation
    if save_mesh:
        a = vtk.vtkShortArray()
        a.SetName('activation_points')
        a.SetNumberOfComponents(1)
        a.SetNumberOfTuples(mesh.GetNumberOfPoints())
        a.Fill(0);

        for ptid in activation_ptids:
            a.SetTuple1(ptid-1,1)

        mesh.GetPointData().AddArray(a)
        
        wr = vtk.vtkUnstructuredGridWriter()
        wr.SetFileName(outmesh_filename)
        wr.SetInputData(mesh)
        wr.Write()
コード例 #15
0
ファイル: save_particles_vtk.py プロジェクト: skyoum00/tools
print('Parsing ', pts_filename)
df = pd.read_csv(pts_filename, delim_whitespace=True)

pts = vtk.vtkPoints()
T = df['T']
x = df['COORX']
y = df['COORY']
z = df['COORZ']
tp = df['ITYPE']
ilagr = df['ILAGR']
exist = df['EXIST']

N = df.shape[0]
pts.SetNumberOfPoints(N)

types = vtk.vtkShortArray()
types.SetNumberOfComponents(1)
types.SetNumberOfTuples(pts.GetNumberOfPoints())
types.SetName('Type')

times = vtk.vtkFloatArray()
times.SetNumberOfComponents(1)
times.SetNumberOfTuples(pts.GetNumberOfPoints())
times.SetName('Time')

vtkilagr = vtk.vtkIdTypeArray()
vtkilagr.SetNumberOfComponents(1)
vtkilagr.SetNumberOfTuples(pts.GetNumberOfPoints())
vtkilagr.SetName('ILAGR')

vtkexist = vtk.vtkShortArray()
コード例 #16
0
boundaries = vtk.vtkCellArray()

with open(boundary_file, 'r') as f:
    for line in f:
        data = line.strip().split()

        boundaries.InsertNextCell(len(data) - 2)
        for i in range(1, len(data) - 1):
            boundaries.InsertCellPoint(int(data[i]) - 1)

# In[26]:

print('Creating vtk array of boundary codes')

arr = vtk.vtkShortArray()
arr.SetName('Code')
arr.SetNumberOfComponents(1)
arr.SetNumberOfTuples(boundaries.GetNumberOfCells())

vv = codes.values

for i in range(arr.GetNumberOfTuples()):
    arr.SetTuple1(i, vv[i, 1])

# In[28]:

print('Saving  vtk boundary to ', vtk_boundary_file)

pd = vtk.vtkPolyData()
pd.SetPoints(pts)
コード例 #17
0
def save_one_file(i):
    #df1 = df[df['T']==unique_times[i]]
    df1 = df_global[ (df['T']>=times[i]-halfstep) & (df['T']<times[i]+halfstep) ]

    if df1.shape[0]==0:
      return

    filename = "pts_{:010d}.vtp".format(i)

    if isfile(filename):
        dft = read_vtk_file(filename)
        df1 = dft.append(df1, ignore_index=True, sort=False) #add df to the end of the read data

    pts = vtk.vtkPoints()
    x = df1['COORX']
    y = df1['COORY']
    z = df1['COORZ']
    tp = df1['ITYPE']
    il = df1['ILAGR']
    ex = df1['EXIST']
    tt = df1['T']
    pts.SetNumberOfPoints(df1.shape[0])

    if df1.shape[0]!=0:
        for j in range(df1.shape[0]):         
            pts.SetPoint(j, (x.iloc[j],y.iloc[j],z.iloc[j]))

        types = vtk.vtkShortArray()
        types.SetNumberOfComponents(1)
        types.SetNumberOfTuples(pts.GetNumberOfPoints())
        types.SetName('ITYPE')
      
        ilagr = vtk.vtkIntArray()
        ilagr.SetNumberOfComponents(1)
        ilagr.SetNumberOfTuples(pts.GetNumberOfPoints())
        ilagr.SetName('ILAGR')

        exist = vtk.vtkShortArray()
        exist.SetNumberOfComponents(1)
        exist.SetNumberOfTuples(pts.GetNumberOfPoints())
        exist.SetName('EXIST')

        T = vtk.vtkFloatArray()
        T.SetNumberOfComponents(1)
        T.SetNumberOfTuples(pts.GetNumberOfPoints())
        T.SetName('T')

        for j in range(df1.shape[0]):         
            types.SetTuple1(j, tp.iloc[j])
            ilagr.SetTuple1(j, il.iloc[j])
            exist.SetTuple1(j, ex.iloc[j])
            T.SetTuple1(j, tt.iloc[j])

        pd = vtk.vtkPolyData()
        pd.SetPoints(pts)
        pd.GetPointData().AddArray(types)
        pd.GetPointData().AddArray(ilagr)
        pd.GetPointData().AddArray(exist)
        pd.GetPointData().AddArray(T)

        wr= vtk.vtkXMLPolyDataWriter()
        wr.SetInputData(pd)
        wr.SetDataModeToBinary()
        wr.SetFileName(filename)
        wr.Write()
コード例 #18
0
ファイル: save_particles_vtk.py プロジェクト: cbutakoff/tools
df = pd.read_csv(pts_filename, delim_whitespace=True)


pts = vtk.vtkPoints()
T = df['T']
x = df['COORX']
y = df['COORY']
z = df['COORZ']
tp = df['ITYPE']
ilagr = df['ILAGR']
exist = df['EXIST']

N=df.shape[0]
pts.SetNumberOfPoints(N)

types = vtk.vtkShortArray()
types.SetNumberOfComponents(1)
types.SetNumberOfTuples(pts.GetNumberOfPoints())
types.SetName('Type')

times = vtk.vtkFloatArray()
times.SetNumberOfComponents(1)
times.SetNumberOfTuples(pts.GetNumberOfPoints())
times.SetName('Time')

vtkilagr = vtk.vtkIdTypeArray()
vtkilagr.SetNumberOfComponents(1)
vtkilagr.SetNumberOfTuples(pts.GetNumberOfPoints())
vtkilagr.SetName('ILAGR')

vtkexist = vtk.vtkShortArray()
コード例 #19
0
import pytest
import vtk

from pytestvtk.assert_vtk import assert_vtk


@pytest.fixture(params=[
    vtk.vtkDoubleArray(),
    vtk.vtkFloatArray(),
    vtk.vtkIntArray(),
    vtk.vtkIdTypeArray(),
    vtk.vtkLongArray(),
    vtk.vtkShortArray(),
    vtk.vtkUnsignedCharArray(),
    vtk.vtkUnsignedIntArray(),
    vtk.vtkUnsignedLongArray(),
    vtk.vtkUnsignedLongLongArray(),
    vtk.vtkUnsignedShortArray(),
    vtk.vtkCharArray(),
])
def vtk_array(request):
    array = request.param
    array.SetName('testing_array')
    array.SetNumberOfTuples(3)
    array.SetNumberOfComponents(3)
    array.InsertTuple3(0, 1, 2, 3)
    array.InsertTuple3(1, 4, 5, 6)
    array.InsertTuple3(2, 7, 8, 9)
    return array

コード例 #20
0
ファイル: lorenz.py プロジェクト: gnastacast/fruiting_bodies
def main():
    colors = vtk.vtkNamedColors()

    Pr = 10.0  # The Lorenz parameters
    b = 2.667
    r = 28.0
    # x = 0.0
    # y = 0.0
    # z = 0.0  # starting (and current) x, y, z
    h = 0.01  # integration step size
    resolution = 200  # slice resolution
    iterations = 10000000  # number of iterations
    xmin = -30.0  # x, y, z range for voxels
    xmax = 30.0
    ymin = -30.0
    ymax = 30.0
    zmin = -10.0
    zmax = 60.0

    # Take a stab at an integration step size.
    xIncr = resolution / (xmax - xmin)
    yIncr = resolution / (ymax - ymin)
    zIncr = resolution / (zmax - zmin)

    print("The Lorenz Attractor\n")
    print(" Pr =", Pr)
    print(" b =", b)
    print(" r =", r)
    print(" integration step size =", h)
    print(" slice resolution =", resolution)
    print(" # of iterations =", iter)
    print(" specified range:")
    print("     x: {:f}, {:f}".format(xmin, xmax))
    print("     y: {:f}, {:f}".format(ymin, ymax))
    print("     z: {:f}, {:f}".format(zmin, zmax))

    x = vtk.vtkMath.Random(xmin, xmax)
    y = vtk.vtkMath.Random(ymin, ymax)
    z = vtk.vtkMath.Random(zmin, zmax)
    print(" starting at {:f}, {:f}, {:f}".format(x, y, z))
    # allocate memory for the slices
    sliceSize = resolution * resolution
    numPts = sliceSize * resolution
    scalars = vtk.vtkShortArray()
    for i in range(0, numPts):
        scalars.InsertTuple1(i, 0)
    for j in range(0, iterations):
        # Integrate to the next time step.
        xx = x + h * Pr * (y - x)
        yy = y + h * (x * (r - z) - y)
        zz = z + h * (x * y - (b * z))

        x = xx
        y = yy
        z = zz

        # Calculate the voxel index.
        if xmax > x > xmin and ymax > y > ymin and zmax > z > zmin:
            xxx = int(float(xx - xmin) * xIncr)
            yyy = int(float(yy - ymin) * yIncr)
            zzz = int(float(zz - zmin) * zIncr)
            index = xxx + yyy * resolution + zzz * sliceSize
            scalars.SetTuple1(index, scalars.GetTuple1(index) + 1)

    volume = vtk.vtkStructuredPoints()
    volume.GetPointData().SetScalars(scalars)
    volume.SetDimensions(resolution, resolution, resolution)
    volume.SetOrigin(xmin, ymin, zmin)
    volume.SetSpacing((xmax - xmin) / resolution, (ymax - ymin) / resolution,
                      (zmax - zmin) / resolution)

    print(" contouring...")
    # Do the graphics dance.
    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Create iso-surface
    contour = vtk.vtkContourFilter()
    contour.SetInputData(volume)
    contour.SetValue(0, 50)

    # Create mapper.
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(contour.GetOutputPort())
    mapper.ScalarVisibilityOff()

    # Create actor.
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d("PaleTurquoise"))

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("PeachPuff"))

    renWin.SetSize(640, 480)

    # interact with data
    renWin.Render()

    iren.Start()
コード例 #21
0
ファイル: Lorenz.py プロジェクト: wangsen53/vtk-examples
def main():
    colors = vtk.vtkNamedColors()

    Pr = 10.0  # The Lorenz parameters
    b = 2.667
    r = 28.0
    # x = 0.0
    # y = 0.0
    # z = 0.0  # starting (and current) x, y, z
    h = 0.01  # integration step size
    resolution = 200  # slice resolution
    iterations = 10000000  # number of iterations
    xmin = -30.0  # x, y, z range for voxels
    xmax = 30.0
    ymin = -30.0
    ymax = 30.0
    zmin = -10.0
    zmax = 60.0

    # Take a stab at an integration step size.
    xIncr = resolution / (xmax - xmin)
    yIncr = resolution / (ymax - ymin)
    zIncr = resolution / (zmax - zmin)

    print('The Lorenz Attractor\n')
    print(' Pr =', Pr)
    print(' b =', b)
    print(' r =', r)
    print(' integration step size =', h)
    print(' slice resolution =', resolution)
    print(' # of iterations =', iter)
    print(' specified range:')
    print('     x: {:f}, {:f}'.format(xmin, xmax))
    print('     y: {:f}, {:f}'.format(ymin, ymax))
    print('     z: {:f}, {:f}'.format(zmin, zmax))

    randomSequence = vtk.vtkMinimalStandardRandomSequence()
    randomSequence.SetSeed(8775070)
    x = randomSequence.GetRangeValue(xmin, xmax)
    randomSequence.Next()
    y = randomSequence.GetRangeValue(ymin, ymax)
    randomSequence.Next()
    z = randomSequence.GetRangeValue(zmin, zmax)
    randomSequence.Next()
    print(' starting at {:f}, {:f}, {:f}'.format(x, y, z))
    # allocate memory for the slices
    sliceSize = resolution * resolution
    numPts = sliceSize * resolution
    scalars = vtk.vtkShortArray()
    for i in range(0, numPts):
        scalars.InsertTuple1(i, 0)
    for j in range(0, iterations):
        # Integrate to the next time step.
        xx = x + h * Pr * (y - x)
        yy = y + h * (x * (r - z) - y)
        zz = z + h * (x * y - (b * z))

        x = xx
        y = yy
        z = zz

        # Calculate the voxel index.
        if xmax > x > xmin and ymax > y > ymin and zmax > z > zmin:
            xxx = int(float(xx - xmin) * xIncr)
            yyy = int(float(yy - ymin) * yIncr)
            zzz = int(float(zz - zmin) * zIncr)
            index = xxx + yyy * resolution + zzz * sliceSize
            scalars.SetTuple1(index, scalars.GetTuple1(index) + 1)

    volume = vtk.vtkStructuredPoints()
    volume.GetPointData().SetScalars(scalars)
    volume.SetDimensions(resolution, resolution, resolution)
    volume.SetOrigin(xmin, ymin, zmin)
    volume.SetSpacing((xmax - xmin) / resolution, (ymax - ymin) / resolution,
                      (zmax - zmin) / resolution)

    print(' contouring...')
    # Do the graphics dance.
    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Create iso-surface
    contour = vtk.vtkContourFilter()
    contour.SetInputData(volume)
    contour.SetValue(0, 50)

    # Create mapper.
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(contour.GetOutputPort())
    mapper.ScalarVisibilityOff()

    # Create actor.
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d('DodgerBlue'))

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('PaleGoldenrod'))

    renWin.SetSize(640, 480)

    # interact with data
    renWin.Render()
    renWin.SetWindowName('Lorenz')

    camera = renderer.GetActiveCamera()
    camera.SetPosition(-67.645167, -25.714343, 63.483516)
    camera.SetFocalPoint(3.224902, -4.398594, 29.552112)
    camera.SetViewUp(-0.232264, 0.965078, 0.121151)
    camera.SetDistance(81.414176)
    camera.SetClippingRange(18.428905, 160.896031)

    iren.Start()
コード例 #22
0
ファイル: convert_ansabin.py プロジェクト: HiJasonZou/tools
    # ====================================
    cells_df.sort_values(by='newCellId', ascending=True, inplace=True)

    #number of nodes : type
    vtkcelltypes = {
        4: vtk.VTK_TETRA,
        5: vtk.VTK_PYRAMID,
        6: vtk.VTK_WEDGE,
        8: vtk.VTK_HEXAHEDRON
    }
    #vtkfacetypes = {3:vtk.VTK_TRIANGLE, 4:vtk.VTK_QUAD}

    cells = vtk.vtkCellArray()
    celltypes = np.zeros(cells_df.shape[0], dtype=np.uint64)

    material_id = vtk.vtkShortArray()
    material_id.SetName('Material')
    material_id.SetNumberOfComponents(1)
    material_id.SetNumberOfTuples(cells_df.shape[0])

    print('Extracting volume cells', flush=True)
    with progressbar.ProgressBar(max_value=cells_df.shape[0]) as bar:
        for idx, row in enumerate(
                cells_df.itertuples(index=False, name='Pandas')):
            nodes = getattr(row, "nodes")
            cells.InsertNextCell(len(nodes))
            for node in nodes:
                cells.InsertCellPoint(int(node) - 1)

            celltypes[idx] = vtkcelltypes[len(nodes)]
            material_id.SetTuple1(idx, int(getattr(row, "solidID")))