1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #!/usr/bin/env python
import vtk
voxelSizeX = 1
voxelSizeY = 1
voxelSizeZ = 1
mapSizeX = 4
mapSizeY = 8
mapSizeZ = 2
nbPoints = mapSizeX*mapSizeY*mapSizeZ
voxelPoints = vtk.vtkPoints()
voxelPoints.SetNumberOfPoints(8*nbPoints)
aVoxel = vtk.vtkVoxel()
aVoxelGrid = vtk.vtkUnstructuredGrid()
aVoxelGrid.Allocate(nbPoints, 1)
for q in range(mapSizeZ):
for p in range(mapSizeY):
for k in range(mapSizeX):
print k+p*mapSizeX+q*mapSizeX*mapSizeY
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8, k, p, q)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+1, k+voxelSizeX, p, q)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+2, k, p+voxelSizeY, q)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+3, k+voxelSizeX, p+voxelSizeY, q)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+4, k, p, q+voxelSizeZ)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+5, k+voxelSizeX, p, q+voxelSizeZ)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+6, k, p+voxelSizeY, q+voxelSizeZ)
voxelPoints.InsertPoint((k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+7, k+voxelSizeX, p+voxelSizeY, q+voxelSizeZ)
aVoxel.GetPointIds().SetId(0, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8)
aVoxel.GetPointIds().SetId(1, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+1)
aVoxel.GetPointIds().SetId(2, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+2)
aVoxel.GetPointIds().SetId(3, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+3)
aVoxel.GetPointIds().SetId(4, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+4)
aVoxel.GetPointIds().SetId(5, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+5)
aVoxel.GetPointIds().SetId(6, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+6)
aVoxel.GetPointIds().SetId(7, (k+p*mapSizeX+q*mapSizeX*mapSizeY)*8+7)
aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds())
# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300, 150)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren.SetBackground(.1, .2, .4)
aVoxelGrid.SetPoints(voxelPoints)
aVoxelMapper = vtk.vtkDataSetMapper()
aVoxelMapper.SetInput(aVoxelGrid)
aVoxelActor = vtk.vtkActor()
aVoxelActor.SetMapper(aVoxelMapper)
ren.AddActor(aVoxelActor)
ren.ResetCamera()
ren.GetActiveCamera().Azimuth(30)
ren.GetActiveCamera().Elevation(20)
ren.GetActiveCamera().Dolly(1)
ren.ResetCameraClippingRange()
# Render the scene and start interaction.
iren.Initialize()
renWin.Render()
iren.Start() |
Partager