root / ase / visualize / vtk / volume.py @ 7
Historique | Voir | Annoter | Télécharger (2,33 ko)
| 1 |
|
|---|---|
| 2 |
import numpy as np |
| 3 |
|
| 4 |
from vtk import vtkContourFilter, vtkDepthSortPolyData |
| 5 |
from ase.visualize.vtk.grid import vtkVolumeGrid |
| 6 |
from ase.visualize.vtk.module import vtkPolyDataModule |
| 7 |
from ase.visualize.vtk.pipeline import vtkSurfaceSmootherPipeline, \ |
| 8 |
vtkDepthSortPipeline
|
| 9 |
|
| 10 |
# -------------------------------------------------------------------
|
| 11 |
|
| 12 |
class vtkIsoSurfaceModule(vtkVolumeGrid, vtkPolyDataModule): |
| 13 |
def __init__(self, data, cell, vtk_renderer, contours=1, depthsort=True): |
| 14 |
#TODO don't require vtk_renderer... implement vtkScene
|
| 15 |
#TODO contour values from list or autocontours if int
|
| 16 |
|
| 17 |
# Make sure data argument is a valid array
|
| 18 |
if not isinstance(data, np.ndarray): |
| 19 |
data = np.array(data) |
| 20 |
|
| 21 |
vtkVolumeGrid.__init__(self, data.shape, cell)
|
| 22 |
|
| 23 |
self.vtk_iso = vtkContourFilter() #vtkMarchingContourFilter? |
| 24 |
self.vtk_iso.SetInput(self.get_structured_points()) #TODO non-orthogonal |
| 25 |
|
| 26 |
self.vtk_iso.SetValue(0, 0.25) |
| 27 |
self.vtk_iso.SetValue(1, -0.25) |
| 28 |
|
| 29 |
self.smoothpipe = vtkSurfaceSmootherPipeline(self, vtk_iso) |
| 30 |
|
| 31 |
#TODO use vtkDepthSortPipeline - but vtkPolyDataModule isn't a pipeline
|
| 32 |
|
| 33 |
self.depthsort = depthsort
|
| 34 |
|
| 35 |
if self.depthsort: |
| 36 |
# The depht sort object is set up to generate scalars representing
|
| 37 |
# the sort depth. A camera is assigned for the sorting. The camera
|
| 38 |
# defines the sort vector (position and focal point).
|
| 39 |
self.vtk_ds = vtkDepthSortPolyData()
|
| 40 |
self.vtk_ds.SetCamera(vtk_renderer.GetActiveCamera())
|
| 41 |
self.vtk_ds.SetInputConnection(self.vtk_iso.GetOutputPort()) |
| 42 |
self.vtk_ds.SetDirectionToBackToFront()
|
| 43 |
#vtk_ds.SetVector(1, 1, 1)
|
| 44 |
#vtk_ds.SortScalarsOn()
|
| 45 |
#vtk_ds.Update()
|
| 46 |
|
| 47 |
vtk_renderer.ResetCamera() |
| 48 |
|
| 49 |
vtkPolyDataModule.__init__(self, self.vtk_ds) |
| 50 |
else:
|
| 51 |
vtkPolyDataModule.__init__(self, self.vtk_iso) |
| 52 |
|
| 53 |
#TODO add color function
|
| 54 |
"""
|
| 55 |
vtk_dmap = vtk.vtkPolyDataMapper()
|
| 56 |
vtk_dmap.ScalarVisibilityOn()
|
| 57 |
vtk_dmap.SetScalarRange(0, vtk_sda_x.GetMaxNorm()) #TODO GetMinNorm non-existing!
|
| 58 |
vtk_dmap.SetScalarModeToUsePointFieldData()
|
| 59 |
vtk_dmap.SelectColorArray("x")
|
| 60 |
#vtk_dmap.ColorByArrayComponent("x", 0)
|
| 61 |
"""
|
| 62 |
|