def __init__(self):
        """
        Initializes VTK objects for rendering.
        """
        # vtk objects for rendering
        self.vtkrenderer = vtk.vtkRenderer()
        
        self.vtkcamera = vtk.vtkCamera()
        self.vtkcamera.SetPosition(self.camera_pos)
        self.vtkcamera.SetFocalPoint(0, 0, 0)
        self.vtkcamera.SetViewUp(self.camera_up)
 
        # lighting
        self.light1 = vtk.vtkLight()
        self.light1.SetIntensity(.4)
        self.light1.SetPosition(10, -10, 10)
        self.light1.SetDiffuseColor(1, 1, 1)
        self.light2 = vtk.vtkLight()
        self.light2.SetIntensity(.4)
        self.light2.SetPosition(-10, -10, 10)
        self.light2.SetDiffuseColor(1, 1, 1)
        self.light3 = vtk.vtkLight()
        self.light3.SetIntensity(.4)
        self.light3.SetPosition(10, -10, -10)
        self.light3.SetDiffuseColor(1, 1, 1)
        self.light4 = vtk.vtkLight()
        self.light4.SetIntensity(.4)
        self.light4.SetPosition(-10, -10, -10)
        self.light4.SetDiffuseColor(1, 1, 1)
        self.vtkrenderer.AddLight(self.light1)
        self.vtkrenderer.AddLight(self.light2)
        self.vtkrenderer.AddLight(self.light3)
        self.vtkrenderer.AddLight(self.light4)
        self.vtkrenderer.SetBackground(0.1, 0.1, 0.1) # Background color

        self.vtkrender_window = vtk.vtkRenderWindow()
        self.vtkrender_window.AddRenderer(self.vtkrenderer)
        self.vtkrender_window.SetSize(self.render_size)
        self.vtkrender_window_interactor = vtk.vtkRenderWindowInteractor()
        self.vtkrender_window_interactor.SetRenderWindow(self.vtkrender_window)

        # vtk objects for reading, and rendering object parts
        self.part_source = vtk.vtkCubeSource()
        self.part_output = self.part_source.GetOutput()
        self.part_mapper = vtk.vtkPolyDataMapper()
        self.part_mapper.SetInput(self.part_output)

        # exporters
        self.vtkvrml_exporter = vtk.vtkVRMLExporter()
        self.vtkobj_exporter = vtk.vtkOBJExporter()
        self.stl_writer = vtk.vtkSTLWriter()
def setup_renderer(renderer, actors, bboxpolydata=None):
    ren = renderer
    for actor in actors:
        # assign actor to the renderer
        ren.AddActor(actor)
    ############################################
    # Create a vtkOutlineFilter to draw the bounding box of the data set.
    # Also create the associated mapper and actor.
    if bboxpolydata is not None:
        outline = vtk.vtkOutlineFilter()
        outline.SetInput(bboxpolydata.GetOutput())
        mapOutline = vtk.vtkPolyDataMapper()
        mapOutline.SetInputConnection(outline.GetOutputPort())
        outlineActor = vtk.vtkActor()
        outlineActor.SetMapper(mapOutline)
        outlineActor.GetProperty().SetColor(100, 100, 100)
        ren.AddViewProp(outlineActor)
        ren.AddActor(outlineActor)
    

    # Create a vtkLight, and set the light parameters.
    light = vtk.vtkLight()
    light.SetFocalPoint(0.21406, 1.5, 0)
    light.SetPosition(8.3761, 4.94858, 4.12505)
    ren.AddLight(light)
    return ren
 def takeScreenShort(self):
     graphics_factory = vtk.vtkGraphicsFactory();
     graphics_factory.SetOffScreenOnlyMode(1);
     graphics_factory.SetUseMesaClasses(1);
     windows = vtk.vtkRenderWindow();
     #Do not open the window!!
     windows.SetOffScreenRendering(True);
     windows.SetSize(self.width,self.height);
     mapper = vtk.vtkPolyDataMapper();
     mapper.SetInputData(self.data);
     for d in ("X","Y",):
         for degree in range(0,100,90):
             actor = vtk.vtkActor()
             actor.SetMapper(mapper);
             getattr(actor,"Rotate{}".format(d))(degree);
             actor.GetProperty().SetColor(0,0,0)
             ren = vtk.vtkRenderer();
             windows.AddRenderer(ren);
             ren.AddActor(actor);
             ren.SetBackground(255.0, 255.0, 255.0);
             ren.ResetCamera();
             cen = ren.GetActiveCamera().GetFocalPoint();
             bounds = actor.GetBounds();
             lightOne = vtk.vtkLight();
             lightOne.SetFocalPoint(cen);
             lightOne.SetPosition(cen);
             lightOne.PositionalOff();
             lightTwo = vtk.vtkLight();
             lightTwo.SetFocalPoint(cen);
             lightTwo.SetPosition(bounds[0],bounds[2],bounds[4]);
             lightTwo.PositionalOn();
             lightThree = vtk.vtkLight();
             lightThree.SetFocalPoint(cen);
             lightThree.SetPosition(bounds[1],bounds[3],bounds[5]);
             lightThree.PositionalOn();
             ren.AddLight(lightOne);
             ren.AddLight(lightTwo);
             ren.AddLight(lightThree);
             windows.Render();
             self.saveToImage(windows,"{}_{}_{}".format(self.fileName,d,degree));
             windows.RemoveRenderer(ren);
Example #4
0
 def importLight(self, l):
     print 'importing light...'
     light = vtk.vtkLight()
     
     a = str(l.get('AmbientColor')).split(" ")
     light.SetAmbientColor(float(a[0]), float(a[1]), float(a[2]))
     a = str(l.get('SpecularColor')).split(" ")
     light.SetSpecularColor(float(a[0]), float(a[1]), float(a[2]))
     a = str(l.get('DiffuseColor')).split(" ")
     light.SetDiffuseColor(float(a[0]), float(a[1]), float(a[2]))
     light.SetIntensity(float(l.get('Intensity')))
     light.SetPositional(int(l.get('Positional')))
     light.SetConeAngle(float(l.get('ConeAngle')))
     
     if(l.get('Type') == "Scene"):
         light.SetLightTypeToSceneLight()
     elif(l.get('Type') == "Head"):
         light.SetLightTypeToHeadlight()
     elif(l.get('Type') == "Camera"):
         light.SetLightTypeToCameraLight()
     
     return light
Example #5
0
    def Light(self, currentElement):
        self.logger.debug('  inside a <Light> element: "%s"' % currentElement.get('name'))
        light = vtk.vtkLight()

        try:
            light.SetPosition( coordsFromString(currentElement.get('SetPosition')) )
        except:
            self.logger.error("  .. <Light> failed to SetPosition")
        try:
            light.SetFocalPoint( coordsFromString(currentElement.get('SetFocalPoint')) )
        except:
            self.logger.error("  .. <Light> failed to SetFocalPoint")
        if 'SetPositional' in currentElement.keys():
            try:
                light.SetPositional( int(currentElement.get('SetPositional')) )
            except:
                self.logger.error("  .. <Light> failed to SetPositional")
        if 'SetColor' in currentElement.keys():
            try:
                light.SetColor( coordsFromString(currentElement.get('SetColor')) )
            except:
                self.logger.error("  .. <Light> failed to SetColor")
        if 'color' in currentElement.keys():  # give people the option of using HTML-style color:
            try:
                light.SetColor( webColorToVtkColor(currentElement.get('color')) )
            except:
                self.logger.error("  .. <Light> failed to set HTML-style color")
        if 'SetConeAngle' in currentElement.keys():
            try:
                light.SetConeAngle( float(currentElement.get('SetConeAngle')) )
            except:
                self.logger.error("  .. <Light> failed to SetConeAngle")
        if 'SetIntensity' in currentElement.keys():
            try:
                light.SetIntensity( float(currentElement.get('SetIntensity')) )
            except:
                self.logger.error("  .. <Light> failed to SetIntensity")
        return light
def main():

    # Read from file
    stlreader = vtk.vtkSTLReader()
    stlreader.SetFileName(
        r"D:\DT-cat_Synthetic_Data_Generation\vtk_generation\mino_3d_model\demo_part\F58001104949503200002.stl"
    )

    tmapper = vtk.vtkTextureMapToCylinder()
    tmapper.SetInputConnection(stlreader.GetOutputPort())
    tmapper.PreventSeamOn()

    xform = vtk.vtkTransformTextureCoords()
    xform.SetInputConnection(tmapper.GetOutputPort())
    xform.SetScale(0.5, 0.5, 0.5)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(xform.GetOutputPort())

    # A texture is loaded using an image reader. Textures are simply images.
    # The texture is eventually associated with an actor.
    #bmpReader = vtk.vtkBMPReader()
    #bmpReader.SetFileName("D:\DT-cat_Synthetic_Data_Generation\\texture\\2.bmp")
    #atext = vtk.vtkTexture()
    #atext.SetInputConnection(bmpReader.GetOutputPort())
    #atext.InterpolateOn()

    cylinderActor = vtk.vtkActor()
    cylinderActor.RotateWXYZ(0, 1, 0, 0)
    cylinderActor.GetProperty().SetColor(0.2, 0.3, 0.7)
    cylinderActor.SetMapper(
        mapper)  # 设置生成几何图元的Mapper。即连接一个Actor到可视化管线的末端(可视化管线的末端就是Mapper)。
    #cylinderActor.SetTexture(atext)

    renderer = vtk.vtkRenderer()  # 负责管理场景的渲染过程
    renderer.AddActor(cylinderActor)
    light = vtk.vtkLight()
    light.SetPosition(400, 0, 00)
    renderer.AddLight(light)
    renderer.SetBackground(0.1, 0.2, 0.4)
    renWin = vtk.vtkRenderWindow()  # 将操作系统与VTK渲染引擎连接到一起。
    renWin.AddRenderer(renderer)
    renWin.SetSize(300, 300)
    iren = vtk.vtkRenderWindowInteractor()  # 提供平台独立的响应鼠标、键盘和时钟事件的交互机制
    iren.SetRenderWindow(renWin)

    # 交互器样式的一种,该样式下,用户是通过控制相机对物体作旋转、放大、缩小等操作
    style = vtk.vtkInteractorStyleTrackballCamera()
    axes = vtk.vtkAxesActor()
    renderer.AddActor(axes)

    iren.SetInteractorStyle(style)
    iren.Initialize()

    iren.Start()

    # Clean up
    # del cylinder
    del stlreader
    del cylinderActor
    del renderer
    del renWin
    del iren
Example #7
0
def main():
    fn = get_program_parameters()
    if fn:
        polyData = ReadPolyData(fn)
    else:
        # Use a sphere
        source = vtk.vtkSphereSource()
        source.SetThetaResolution(100)
        source.SetPhiResolution(100)
        source.Update()
        polyData = source.GetOutput()

    colors = vtk.vtkNamedColors()
    colors.SetColor('HighNoonSun', [255, 255, 251, 255])  # Color temp. 5400°K
    colors.SetColor('100W Tungsten',
                    [255, 214, 170, 255])  # Color temp. 2850°K

    renderer = vtk.vtkRenderer()
    renderer.SetBackground(colors.GetColor3d('Silver'))

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetSize(640, 480)
    renderWindow.AddRenderer(renderer)

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    light1 = vtk.vtkLight()
    light1.SetFocalPoint(0, 0, 0)
    light1.SetPosition(0, 1, 0.2)
    light1.SetColor(colors.GetColor3d('HighNoonSun'))
    light1.SetIntensity(0.3)
    renderer.AddLight(light1)

    light2 = vtk.vtkLight()
    light2.SetFocalPoint(0, 0, 0)
    light2.SetPosition(1.0, 1.0, 1.0)
    light2.SetColor(colors.GetColor3d('100W Tungsten'))
    light2.SetIntensity(0.8)
    renderer.AddLight(light2)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(polyData)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetAmbientColor(colors.GetColor3d('SaddleBrown'))
    actor.GetProperty().SetDiffuseColor(colors.GetColor3d('Sienna'))
    actor.GetProperty().SetSpecularColor(colors.GetColor3d('White'))
    actor.GetProperty().SetSpecular(0.51)
    actor.GetProperty().SetDiffuse(0.7)
    actor.GetProperty().SetAmbient(0.7)
    actor.GetProperty().SetSpecularPower(30.0)
    actor.GetProperty().SetOpacity(1.0)
    renderer.AddActor(actor)

    # Add a plane
    bounds = polyData.GetBounds()

    rnge = [0] * 3
    rnge[0] = bounds[1] - bounds[0]
    rnge[1] = bounds[3] - bounds[2]
    rnge[2] = bounds[5] - bounds[4]
    print('range: ', ', '.join(['{0:0.6f}'.format(i) for i in rnge]))
    expand = 1.0
    thickness = rnge[2] * 0.1
    plane = vtk.vtkCubeSource()
    plane.SetCenter((bounds[1] + bounds[0]) / 2.0, bounds[2] - thickness / 2.0,
                    (bounds[5] + bounds[4]) / 2.0)
    plane.SetXLength(bounds[1] - bounds[0] + (rnge[0] * expand))
    plane.SetYLength(thickness)
    plane.SetZLength(bounds[5] - bounds[4] + (rnge[2] * expand))

    planeMapper = vtk.vtkPolyDataMapper()
    planeMapper.SetInputConnection(plane.GetOutputPort())

    planeActor = vtk.vtkActor()
    planeActor.SetMapper(planeMapper)
    renderer.AddActor(planeActor)

    renderWindow.SetMultiSamples(0)

    shadows = vtk.vtkShadowMapPass()

    seq = vtk.vtkSequencePass()

    passes = vtk.vtkRenderPassCollection()
    passes.AddItem(shadows.GetShadowMapBakerPass())
    passes.AddItem(shadows)
    seq.SetPasses(passes)

    cameraP = vtk.vtkCameraPass()
    cameraP.SetDelegatePass(seq)

    # Tell the renderer to use our render pass pipeline
    glrenderer = renderer
    glrenderer.SetPass(cameraP)

    renderer.GetActiveCamera().SetPosition(-0.2, 0.2, 1)
    renderer.GetActiveCamera().SetFocalPoint(0, 0, 0)
    renderer.GetActiveCamera().SetViewUp(0, 1, 0)
    renderer.ResetCamera()
    renderer.GetActiveCamera().Dolly(2.25)
    renderer.ResetCameraClippingRange()
    renderWindow.SetWindowName('Shadows')
    renderWindow.Render()
    renderWindow.SetWindowName('Shadows')

    interactor.Start()
planeWidgetZ.SetSliceIndex(128)
planeWidgetZ.SetPicker(picker)
planeWidgetZ.SetKeyPressActivationValue("z")

prop3 = planeWidgetZ.GetPlaneProperty()
prop3.SetColor(0, 0, 1)

planeWidgetX.SetInteractor(iact)
planeWidgetX.Off()
planeWidgetY.SetInteractor(iact)
planeWidgetY.Off()
planeWidgetZ.SetInteractor(iact)
planeWidgetZ.Off()

#shadow & DOF
light1 = vtk.vtkLight()
light1.SetFocalPoint(0, 0, 0)
light1.SetPosition(0, 10, 0.2)
light1.SetColor(0.95, 0.97, 1.0)
light1.SetIntensity(0.8)
ren.AddLight(light1)

light2 = vtk.vtkLight()
light2.SetFocalPoint(0, 0, 0)
light2.SetPosition(10.0, 10.0, 10.0)
light2.SetColor(1.0, 0.8, 0.7)
light2.SetIntensity(0.5)
ren.AddLight(light2)

renWin.SetMultiSamples(0)
Example #9
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
lgt = vtk.vtkLight()
# create pipeline
#
locator = vtk.vtkMergePoints()
locator.SetDivisions(32, 32, 46)
locator.SetNumberOfPointsPerBucket(2)
locator.AutomaticOff()
v16 = vtk.vtkVolume16Reader()
v16.SetDataDimensions(64, 64)
v16.GetOutput().SetOrigin(0.0, 0.0, 0.0)
v16.SetDataByteOrderToLittleEndian()
v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter")
v16.SetImageRange(1, 93)
v16.SetDataSpacing(3.2, 3.2, 1.5)
iso = vtk.vtkMarchingCubes()
iso.SetInputConnection(v16.GetOutputPort())
iso.SetValue(0, 1150)
iso.ComputeGradientsOn()
Example #10
0
def test_add_vtk_light():
    pl = pyvista.Plotter(lighting=None)
    pl.add_light(vtk.vtkLight())
    assert len(pl.renderer.lights) == 1
Example #11
0
  def generate(self, name, imDim1, imDim2, imDim3, rotation_azimuth, rotation_elevation):

    #THIS METHOD NEEDS SERIOUS REFACTORING

    FILE = open("/home/jchiang/dev/django/vizlit/generator/vtk_scripts/problem1.txt","r");

    #Define readlist to store non-empty lines from the input.txt file

    readlist = [];

    #Read from the file one line at a time and store it in readlist

    for line in FILE:
      readlist.append(line);line


    #for now we will use 

    #imDimensions = readlist[2].split(' ');
    layerLocs = readlist[4].split(' ');
    layerColors = readlist[6].split(' ');
    originSlice = readlist[8].split(' ');
    point1Slice = readlist[10].split(' ');
    point2Slice = readlist[12].split(' ');
    rotationDiagram = readlist[14].split(' ');
    fileOutput = '/home/jchiang/dev/django/vizlit/generator/images/' + name;

    print originSlice;

    xDim = imDim1 #int(imDimensions[0]);
    yDim = imDim2 #int(imDimensions[1]);
    zDim = imDim3 #int(imDimensions[2]);

    ### End File input ###

    #Image Data definition. Variable declarations are not necessary in python.
    #set imData to an instance of vtkImageData
    imData = vtk.vtkImageData();

    #The dimensions
    imData.SetDimensions(xDim,yDim,zDim);

    #We set the scalar type to unsigned short, scalar components to 1 and allocate it
    imData.SetScalarTypeToUnsignedShort();
    imData.SetNumberOfScalarComponents(1);
    imData.AllocateScalars();

    #Scalars array definition and memory allocation
    scalars = vtk.vtkUnsignedShortArray();
    scalars.SetNumberOfValues(xDim*yDim*zDim);


    #The three 'for' loops to enter the scalar values into the image data

    for i in range(0, zDim):
      z = i;
      iOffset = (i*xDim*yDim);
      for j in range(0,yDim):
        y = j;
        jOffset = (j*xDim);
        for k in range(0,xDim):
          x = k;
          offset = (k+iOffset+jOffset);
          for m in range(0, len(layerLocs)-1):
            if y>=int(layerLocs[m]) and y<int(layerLocs[m+1]):
              scalars.InsertTuple1(offset, m+1);



    (imData.GetPointData()).SetScalars(scalars);

    colorTransferFunction = vtk.vtkColorTransferFunction();

    colorTransferFunction.AddRGBPoint(0,1,1,1);

    for i in range(1, len(layerColors)):
      tempColor = layerColors[i-1].split(',');
      colorTransferFunction.AddRGBPoint(float(i),float(tempColor[0]), float(tempColor[1]), float(tempColor[2]));

    opacityTransferFunction = vtk.vtkPiecewiseFunction();
    opacityTransferFunction.AddPoint(0,0);
    opacityTransferFunction.AddPoint(1,1);

    compositeFunction = vtk.vtkVolumeRayCastCompositeFunction();

    volMapper = vtk.vtkVolumeRayCastMapper();
    volMapper.SetInput(imData);
    volMapper.SetVolumeRayCastFunction(compositeFunction);

    volumeProperty = vtk.vtkVolumeProperty();
    volumeProperty.SetColor(colorTransferFunction);
    volumeProperty.SetScalarOpacity(opacityTransferFunction);
    volumeProperty.ShadeOn();
    volumeProperty.SetDiffuse(0.7);
    volumeProperty.SetAmbient(0.8);
    volumeProperty.SetSpecular(0.5);
    volumeProperty.SetSpecularPower(70.0);

    volVolume = vtk.vtkVolume();
    volVolume.SetMapper(volMapper);
    volVolume.SetProperty(volumeProperty);
    light = vtk.vtkLight();

    light.SetColor(1,1,1);
    light.SetPosition(30,500,150);
    light.SetFocalPoint(50,50,50);
    light.SetIntensity(0.9);

    volMapper2 = vtk.vtkVolumeRayCastMapper();
    volMapper2.SetInput(imData);
    volMapper2.SetVolumeRayCastFunction(compositeFunction);

    plane1 = vtk.vtkPlaneSource();
    plane1.SetOrigin(float(originSlice[0]),float(originSlice[1]),float(originSlice[2]));
    plane1.SetPoint1(float(point1Slice[0]),float(point1Slice[1]),float(point1Slice[2]));
    plane1.SetPoint2(float(point2Slice[0]),float(point2Slice[1]),float(point2Slice[2]));

    planeProperty = vtk.vtkProperty();
    #planeProperty.SetColor(1,1,1);

    planeMapper = vtk.vtkPolyDataMapper();
    planeMapper.SetInputConnection(plane1.GetOutputPort());

    planeProperty = vtk.vtkProperty();
    #planeProperty.SetOpacity(1);
    planeProperty.SetLineWidth(5);

    planeActor = vtk.vtkActor();
    planeActor.SetMapper(planeMapper);
    planeActor.SetProperty(planeProperty);
    (planeActor.GetProperty()).SetColor(0,0,0);

    planeNormal = plane1.GetNormal();
    planeCenter = plane1.GetCenter();
    testNormal = [0,0,0];
    testNormal[0] = planeNormal[0]*-1;
    testNormal[1] = planeNormal[1]*-1;
    testNormal[2] = planeNormal[2]*-1;

    clipPlane1 = vtk.vtkPlane();
    clipPlane1.SetOrigin(float(originSlice[0]),float(originSlice[1]),float(originSlice[2]));
    clipPlane1.SetNormal(plane1.GetNormal());
    volMapper2.AddClippingPlane(clipPlane1);

    print testNormal;

    originSlice2 = [0,0,0];
    originSlice2[0] = float(originSlice[0]) - float(testNormal[0])*3;
    originSlice2[1] = float(originSlice[1]) - float(testNormal[1])*3;
    originSlice2[2] = float(originSlice[2]) - float(testNormal[2])*3;


    print originSlice2;

    clipPlane2 = vtk.vtkPlane();
    clipPlane2.SetOrigin(float(originSlice2[0]),float(originSlice2[1]),float(originSlice2[2]));
    clipPlane2.SetNormal(testNormal);
    volMapper2.AddClippingPlane(clipPlane2);

    volVolume2 = vtk.vtkVolume();
    volVolume2.SetMapper(volMapper2);
    volVolume2.SetProperty(volumeProperty);

    ren = vtk.vtkRenderer();
    ren2 = vtk.vtkRenderer();
    ren2.AddProp(volVolume2);
    renWin = vtk.vtkRenderWindow();
    renWin.SetSize(800,800);
    renWin2 = vtk.vtkRenderWindow();

    renWin2.SetSize(800,800);
    ren.SetViewport(0,0,1,1);
    ren2.SetViewport(0,0,1,1);
    renWin.AddRenderer(ren);
    renWin2.AddRenderer(ren2);

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

    iren = vtk.vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin2);

    (ren.GetActiveCamera()).Azimuth(float(rotation_azimuth));
    (ren.GetActiveCamera()).Elevation(float(rotation_elevation));
    (ren.GetActiveCamera()).SetParallelProjection(0);

    ren.SetBackground(1,1,1);
    ren2.SetBackground(1,1,1);

    ren.AddLight(light);
    ren.AddProp(volVolume);
    ren.AddActor(planeActor);
    ren.ResetCamera();


    (ren2.GetActiveCamera()).SetFocalPoint(planeCenter);

    upDirection = [float(point1Slice[0])-float(originSlice[0]),float(point1Slice[1])-float(originSlice[1]), float(point1Slice[2])-float(originSlice[2])];

    (ren2.GetActiveCamera()).SetViewUp(upDirection);

    camPosition = [planeCenter[0]-planeNormal[0]*300, planeCenter[1]-planeNormal[1]*300, planeCenter[2]-planeNormal[2]*300];
    (ren2.GetActiveCamera()).SetPosition(camPosition);

    win2imageFilter = vtk.vtkWindowToImageFilter();
    win2imageFilter.SetInput(renWin);

    writerJPEG = vtk.vtkJPEGWriter();
    writerJPEG.SetQuality(100);
    writerJPEG.SetInput(win2imageFilter.GetOutput());
    writerJPEG.SetFileName(fileOutput+".jpg");
    writerJPEG.Write();


    for i in range(0,370,20):
      time.sleep(.03);
      (ren.GetActiveCamera()).Azimuth(-20);
      renWin.AddRenderer(ren);
      win2imageFilter = vtk.vtkWindowToImageFilter();
      win2imageFilter.SetInput(renWin);
      writerJPEG = vtk.vtkJPEGWriter();
      writerJPEG.SetInput(win2imageFilter.GetOutput());
      writerJPEG.SetFileName(fileOutput+"_rotate_"+str(i)+".jpg");
      writerJPEG.Write();
Example #12
0
    def __init__( self, parent = None ):
        
        QtGui.QMainWindow.__init__( self, parent)
        
        icon = QtGui.QIcon()
        icon.addPixmap( QtGui.QPixmap( 'icons/application_icon.png' ), QtGui.QIcon.Normal, QtGui.QIcon.Off )
        
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap( 'icons/application_start.png' ), QtGui.QIcon.Normal, QtGui.QIcon.Off )
        
        icon2 = QtGui.QIcon()
        icon2.addPixmap( QtGui.QPixmap( 'icons/application_help.png' ), QtGui.QIcon.Normal, QtGui.QIcon.Off )
        
        icon3 = QtGui.QIcon()
        icon3.addPixmap( QtGui.QPixmap( 'icons/application_exit.png' ), QtGui.QIcon.Normal, QtGui.QIcon.Off )
        
        icon4 = QtGui.QIcon()
        icon4.addPixmap( QtGui.QPixmap( 'icons/application_info.png' ), QtGui.QIcon.Normal, QtGui.QIcon.Off )
        
        # ===
        # MainWindow Eigenschaften
        # ===
        self.setObjectName( 'MainWindow' )
        self.resize( 800, 577 )
        self.setWindowIcon( icon )
        self.setUnifiedTitleAndToolBarOnMac( True )
        
        # ===
        # MainWindow Widgets
        # ===
        self.centralwidget = QtGui.QWidget( self )
        self.centralwidget.setObjectName( 'centralwidget' )
    
        self.tab_widget_pref = QtGui.QTabWidget( self.centralwidget )
        self.tab_widget_pref.setGeometry( QtCore.QRect( 10, 10, 291, 311 ) )
        self.tab_widget_pref.setObjectName( 'tab_widget_pref' )
    
        self.common = QtGui.QWidget()
        self.common.setObjectName( 'common' )
    
        self.layoutWidget = QtGui.QWidget( self.common )
        self.layoutWidget.setGeometry( QtCore.QRect( 10, 10, 261, 92 ) )
        self.layoutWidget.setObjectName( 'layoutWidget' )
    
        self.common_layout = QtGui.QVBoxLayout( self.layoutWidget )
        self.common_layout.setObjectName( 'common_layout' )
    
        self.server_label = QtGui.QLabel( self.layoutWidget )
        self.server_label.setObjectName( 'server_label')
    
        self.common_layout.addWidget( self.server_label )
    
        self.server_box = QtGui.QComboBox( self.layoutWidget )
        self.server_box.setObjectName( 'server_box' )
        self.server_box.addItem( '' )
    
        self.common_layout.addWidget( self.server_box )
    
        self.port_label = QtGui.QLabel( self.layoutWidget )
        self.port_label.setObjectName( 'port_label' )
    
        self.common_layout.addWidget( self.port_label )
    
        self.port_box = QtGui.QComboBox( self.layoutWidget )
        self.port_box.setObjectName( 'port_box' )
        self.port_box.addItem( '' )
        self.port_box.addItem( '' )
    
        self.common_layout.addWidget( self.port_box )
    
        self.tab_widget_pref.addTab( self.common, '' )
    
        self.simdata = QtGui.QWidget()
        self.simdata.setObjectName( 'simdata' )
    
        self.layoutWidget1 = QtGui.QWidget( self.simdata )
        self.layoutWidget1.setGeometry( QtCore.QRect( 10, 10, 261, 261 ) )
        self.layoutWidget1.setObjectName( 'layoutWidget1' )
    
        self.simdata_layout = QtGui.QVBoxLayout( self.layoutWidget1 )
        self.simdata_layout.setObjectName( 'simdata_layout' )
    
        self.simdata_layout_pref = QtGui.QVBoxLayout()
        self.simdata_layout_pref.setObjectName( 'simdata_layout_pref' )
    
        self.koerper_label = QtGui.QLabel( self.layoutWidget1 )
        self.koerper_label.setObjectName( 'koerper_label' )
    
        self.simdata_layout_pref.addWidget( self.koerper_label )
    
        self.koerper_box = QtGui.QSpinBox( self.layoutWidget1 )
        self.koerper_box.setMinimum( 1 )
        self.koerper_box.setMaximum( 999 )
        self.koerper_box.setProperty( 'value', 1 )
        self.koerper_box.setObjectName( 'koerper_box' )
    
        self.simdata_layout_pref.addWidget( self.koerper_box )
        
        self.simduration_label = QtGui.QLabel( self.layoutWidget1 )
        self.simduration_label.setObjectName( 'simduration_label' )
    
        self.simdata_layout_pref.addWidget( self.simduration_label )
    
        self.simduration_box = QtGui.QSpinBox( self.layoutWidget1 )
        self.simduration_box.setMinimum( 1 )
        self.simduration_box.setMaximum( 36500 )
        self.simduration_box.setProperty( 'value', 365 )
        self.simduration_box.setObjectName( 'simduration_box' )
    
        self.simdata_layout_pref.addWidget( self.simduration_box )
    
        self.masskoerper_label = QtGui.QLabel( self.layoutWidget1 )
        self.masskoerper_label.setObjectName( 'masskoerper_label' )
    
        self.simdata_layout_pref.addWidget( self.masskoerper_label )
    
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName( 'horizontalLayout' )
    
        self.masskoerper_box_label = QtGui.QLabel( self.layoutWidget1 )
        self.masskoerper_box_label.setAlignment( QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter )
        self.masskoerper_box_label.setObjectName( 'masskoerper_box_label' )
    
        self.horizontalLayout.addWidget( self.masskoerper_box_label )
    
        self.masskoerper_box = QtGui.QSpinBox( self.layoutWidget1 )
        self.masskoerper_box.setMinimum( 1 )
        self.masskoerper_box.setProperty( 'value', 26 )
        self.masskoerper_box.setObjectName( 'masskoerper_box' )
    
        self.horizontalLayout.addWidget( self.masskoerper_box )
    
        self.simdata_layout_pref.addLayout( self.horizontalLayout )
    
        self.masscentral_label = QtGui.QLabel( self.layoutWidget1 )
        self.masscentral_label.setObjectName( 'masscentral_label' )
    
        self.simdata_layout_pref.addWidget( self.masscentral_label )
    
        self.horizontalLayout_2 = QtGui.QHBoxLayout()
        self.horizontalLayout_2.setObjectName( 'horizontalLayout_2' )
    
        self.masscentral_box_label = QtGui.QLabel( self.layoutWidget1 )
        self.masscentral_box_label.setAlignment( QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter )
        self.masscentral_box_label.setObjectName( 'masscentral_box_label' )
    
        self.horizontalLayout_2.addWidget( self.masscentral_box_label )
    
        self.masscentral_box = QtGui.QSpinBox( self.layoutWidget1 )
        self.masscentral_box.setMinimum( 1 )
        self.masscentral_box.setProperty( 'value', 30 )
        self.masscentral_box.setObjectName( 'masscentral_box' )
    
        self.horizontalLayout_2.addWidget( self.masscentral_box )
    
        self.simdata_layout_pref.addLayout( self.horizontalLayout_2 )
    
        spacerItem = QtGui.QSpacerItem( 20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding )
    
        self.simdata_layout_pref.addItem( spacerItem )
    
        self.simdata_layout.addLayout( self.simdata_layout_pref )
    
        self.simdata_layout_buttons = QtGui.QHBoxLayout()
        self.simdata_layout_buttons.setObjectName( 'simdata_layout_buttons' )
    
        spacerItem1 = QtGui.QSpacerItem( 40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum )
    
        self.simdata_layout_buttons.addItem( spacerItem1 )
    
        self.simdata_layout_buttons_pref = QtGui.QVBoxLayout()
        self.simdata_layout_buttons_pref.setObjectName( 'simdata_layout_buttons_pref' )

        self.start_button = QtGui.QPushButton( self.layoutWidget1 )
        self.start_button.setIcon( icon1 )
        self.start_button.setObjectName( 'start_button' )
    
        self.simdata_layout_buttons_pref.addWidget( self.start_button )
    
        self.default_button = QtGui.QPushButton( self.layoutWidget1 )
        self.default_button.setObjectName( 'default_button' )
    
        self.simdata_layout_buttons_pref.addWidget( self.default_button )
    
        self.simdata_layout_buttons.addLayout( self.simdata_layout_buttons_pref )
    
        self.simdata_layout.addLayout( self.simdata_layout_buttons )
    
        self.tab_widget_pref.addTab( self.simdata, "" )
    
        self.tab_widget_help = QtGui.QTabWidget( self.centralwidget )
        self.tab_widget_help.setGeometry( QtCore.QRect( 10, 330, 291, 171 ) )
        self.tab_widget_help.setObjectName( 'tab_widget_help' )
    
        self.information = QtGui.QWidget()
        self.information.setObjectName( 'information' )
    
        self.layoutWidget2 = QtGui.QWidget( self.information )
        self.layoutWidget2.setGeometry( QtCore.QRect( 10, 10, 270, 121 ) )
        self.layoutWidget2.setObjectName( 'layoutWidget2' )
    
        self.information_layout = QtGui.QVBoxLayout( self.layoutWidget2 )
        self.information_layout.setObjectName( 'information_layout' )
    
        self.information_edit = QtGui.QTextEdit( self.layoutWidget2 )
        self.information_edit.setReadOnly( True )
        self.information_edit.setTabStopWidth( 55 )
        self.information_edit.setObjectName( 'information_edit' )
    
        self.information_layout.addWidget( self.information_edit )
    
        self.impuls_layout = QtGui.QHBoxLayout()
        self.impuls_layout.setObjectName( 'impuls_layout' )
    
        self.impuls_label = QtGui.QLabel( self.layoutWidget2 )
        self.impuls_label.setObjectName( 'impuls_label' )
    
        self.impuls_layout.addWidget( self.impuls_label )
    
        self.impuls_edit = QtGui.QLineEdit( self.layoutWidget2 )
        self.impuls_edit.setObjectName( 'impuls_edit' )
    
        self.impuls_layout.addWidget( self.impuls_edit )
    
        self.information_layout.addLayout( self.impuls_layout )
    
        self.tab_widget_help.addTab( self.information, '' )
    
        self.help = QtGui.QWidget()
        self.help.setObjectName( 'help' )
    
        self.layoutWidget3 = QtGui.QWidget( self.help )
        self.layoutWidget3.setGeometry( QtCore.QRect( 10, 10, 261, 118 ) )
        self.layoutWidget3.setObjectName( 'layoutWidget3' )
    
        self.help_layout = QtGui.QVBoxLayout( self.layoutWidget3 )
        self.help_layout.setObjectName( 'help_layout' )
    
        self.help_label = QtGui.QLabel( self.layoutWidget3 )
        self.help_label.setAlignment( QtCore.Qt.AlignJustify|QtCore.Qt.AlignVCenter )
        self.help_label.setWordWrap( True )
        self.help_label.setObjectName( 'help_label' )
    
        self.help_layout.addWidget( self.help_label )
    
        self.help_button_layout = QtGui.QHBoxLayout()
        self.help_button_layout.setObjectName( 'help_button_layout' )
    
        spacerItem2 = QtGui.QSpacerItem( 40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum )
    
        self.help_button_layout.addItem( spacerItem2 )

        self.help_button = QtGui.QPushButton( self.layoutWidget3 )
        self.help_button.setIcon( icon2 )
        self.help_button.setObjectName( 'help_button' )
    
        self.help_button_layout.addWidget( self.help_button )
    
        self.help_layout.addLayout( self.help_button_layout )
    
        self.tab_widget_help.addTab( self.help, '' )
    
        self.widget = QtGui.QWidget( self.centralwidget )
        self.widget.setGeometry( QtCore.QRect( 310, 0, 481, 501 ) )
        self.widget.setObjectName( 'widget' )
    
        self.sim_layout = QtGui.QVBoxLayout( self.widget )
        self.sim_layout.setObjectName( 'sim_layout' )
    
        self.logo_label = QtGui.QLabel( self.widget )
        self.logo_label.setPixmap( QtGui.QPixmap( 'icons/application_logo.png' ) )
        self.logo_label.setObjectName( 'logo_label' )
    
        self.sim_layout.addWidget( self.logo_label )
    
        self.qvtk_widget = QVTKRenderWindowInteractor.QVTKRenderWindowInteractor( self.widget )
        self.qvtk_widget.setObjectName( 'qvtk_widget' )
        
        self.sphere = vtk.vtkSphereSource()
        self.sphere.SetRadius( 1.0 )
        self.sphere.SetPhiResolution( 100 )
        self.sphere.SetThetaResolution( 100 )
        
        self.sphereMapper = vtk.vtkPolyDataMapper()
        self.sphereMapper.SetInputConnection( self.sphere.GetOutputPort() )
        
        self.sphereActor = vtk.vtkActor()
        self.sphereActor.SetMapper( self.sphereMapper )
        
        self.sphereActorCentral = vtk.vtkActor()
        self.sphereActorCentral.SetMapper( self.sphereMapper )
        
        self.sphereActorCentral.GetProperty().SetDiffuseColor(1, 1, 0)
        
        self.ren1 = vtk.vtkRenderer()
        self.ren1.AddActor( self.sphereActor )
        self.ren1.AddActor( self.sphereActorCentral )
        self.ren1.SetBackground( 0.1, 0.2, 0.4 )
        
        self.light = vtk.vtkLight()
        self.light.SetPosition( - 200, - 200, 200 )
        
        self.ren1.AddLight( self.light )
        
        self.cam = self.ren1.GetActiveCamera()
        self.cam.SetPosition( 0, - 50, 50 )
        self.cam.SetFocalPoint( 0, 0, 0 )
        self.cam.SetViewUp( 0, 1, 0 )
        self.cam.SetViewAngle( 40 )
        
        self.ren1.SetActiveCamera( self.cam )

        self.sphere.SetRadius( 2 )
        
        self.renderWindow = self.qvtk_widget.GetRenderWindow()
        self.renderWindow.AddRenderer( self.ren1 )
    
        self.sim_layout.addWidget( self.qvtk_widget )
    
        self.setCentralWidget( self.centralwidget )
        
        # ===
        # MainWindow MenuBar
        # ===
        self.menubar = QtGui.QMenuBar( self )
        self.menubar.setGeometry( QtCore.QRect( 0, 0, 800, 21 ) )
        self.menubar.setObjectName( 'menubar' )
    
        self.menu_simulation = QtGui.QMenu( self.menubar )
        self.menu_simulation.setObjectName( 'menu_simulation' )
    
        self.menu_help = QtGui.QMenu( self.menubar )
        self.menu_help.setObjectName( 'menu_help' )
    
        self.start = QtGui.QAction( self )
        self.start.setIcon( icon1 )
        self.start.setObjectName( 'start' )

        self.exit = QtGui.QAction( self )
        self.exit.setIcon( icon3 )
        self.exit.setObjectName( 'exit' )
    
        self.handbook = QtGui.QAction( self )
        self.handbook.setIcon( icon2 )
        self.handbook.setObjectName( 'handbook' )

        self.actionInfo = QtGui.QAction( self )
        self.actionInfo.setIcon( icon4 )
        self.actionInfo.setObjectName( 'actionInfo' )
    
        self.menu_simulation.addAction( self.start )
        self.menu_simulation.addSeparator()
        self.menu_simulation.addAction( self.exit )
    
        self.menu_help.addAction( self.handbook )
        self.menu_help.addAction( self.actionInfo )
    
        self.menubar.addAction( self.menu_simulation.menuAction() )
        self.menubar.addAction( self.menu_help.menuAction() )
    
        self.setMenuBar( self.menubar )
        
        # ===
        # MainWindow StatusBar
        # ===
        self.statusbar = QtGui.QStatusBar( self )
        self.statusbar.setObjectName( 'statusbar' )
    
        self.setStatusBar( self.statusbar )
        
        # ===
        # MainWindow ToolBar
        # ===
        self.toolBar = QtGui.QToolBar( self )
        self.toolBar.setObjectName( 'toolBar' )
    
        self.addToolBar( QtCore.Qt.TopToolBarArea, self.toolBar )
    
        self.toolBar.addAction( self.start )
        self.toolBar.addSeparator()
        self.toolBar.addAction( self.handbook )
        self.toolBar.addAction( self.actionInfo )
        self.toolBar.addSeparator()
        self.toolBar.addAction( self.exit )
        
        # ===
        # Übersetzung des MainWindows, Tabreihenfolge festlegen und darstellen
        # ===
        self.retranslateUi( self )
        self.tab_widget_pref.setCurrentIndex( 1 )
        self.tab_widget_help.setCurrentIndex( 0 )
        self.show()
        
        # ===
        # Signal/Slot Mechanismus
        # ===
        self.connect( self.exit, QtCore.SIGNAL( 'triggered()' ), self.onExit )
        self.connect( self.default_button, QtCore.SIGNAL( 'clicked()' ), self.onDefault )
        #self.connect( self.start_button, QtCore.SIGNAL( 'clicked()' ), self.onStart )
        #self.connect( self.start, QtCore.SIGNAL( 'triggered()' ), self.onStart )
        self.connect( self.actionInfo, QtCore.SIGNAL( 'triggered()' ), self.onDialog )
        self.connect( self.start_button, QtCore.SIGNAL( 'clicked()' ), self.displayVtk )
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# 将多边形渲染导入场景渲染器,并设置场景和窗口的初始参数
ren.AddActor(cylinderActor)
ren.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(200, 200)

# 普通的鼠标交互控件
style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)


# 这一段用于设置照明,一共两个,蓝色和绿色
myLight = vtk.vtkLight()
myLight.SetColor(0, 1,0)
myLight.SetPosition(0, 0, 1)
myLight.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
ren.AddLight(myLight)

myLight2 = vtk.vtkLight()
myLight2.SetColor(0, 0, 1)
myLight2.SetPosition(0, 0, -1)
myLight2.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
ren.AddLight(myLight2)


# 开始进行可视化的开始
iren.Initialize()
sphereKeyProperty = vtk.vtkInformation()
sphereKeyProperty.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
sphereKeyProperty.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
sphereActor.SetPropertyKeys(sphereKeyProperty)
sphereActor.SetMapper(sphereMapper)

sphereActor.SetVisibility(1)
sphereActor.SetPosition(2,2,-1)
sphereActor.GetProperty().SetColor(1,1,0)

renderer.AddViewPro(rectActor)
renderer.AddViewPro(boxActor)
renderer.AddViewPro(coneActor)
renderer.AddViewPro(sphereActor)

l1 = vtk.vtkLight()
l1.SetPosition(-4,4,-1)
l1.SetFocalPOint(boxActor.GetPosition())
l1.SetColor(1,1,1)
l1.SetPositional(1)
renderer.AddLight(l1)
l1.SetSwitch(1)

l2 = vtk.vtkLight()
l2.SetPosition(-4,5,1)
l2.SetFocalPOint(sphereActor.GetPosition())
l2.SetColor(1,0,1)
l2.SetPositional(1)
renderer.AddLight(l2)
l2.SetSwitch(1)
Example #15
0
def main():

    fn0 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp"
    fn0c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp"
    fn1 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_l.vtp"
    fn1c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_l_col.vtp"
    fn2 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_r.vtp"
    fn2c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_r_col.vtp"
    fn0t = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Textures/metal.jpg"
    fn3 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Probe/tip.vtp"
    fn3c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp"
    fn4 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/ball.vtp"
    fn4c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/ball_col.vtp"
    fn4d = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/ball_def_c10.vtp"
    fn4t = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Textures/liver.jpg"
    fn5 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/cavity.vtp"
    fn5c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/cavity_col.vtp"
    fn5d = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/cavity_def_c10.vtp"
    fn5t = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Textures/intestine2.jpg"

    # Left Tool (Probe)
    # Visualization model
    vis_stick_l = vtkesqui.vtkVisualizationModel()
    vis_stick_l.SetName("vis_stick_l")
    vis_stick_l.SetFileName(fn0)
    vis_stick_l.SetTextureFileName(fn0t)
    vis_stick_l.SetOpacity(1.0)
    vis_stick_l.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_l = vtkesqui.vtkCollisionModel()
    col_stick_l.SetName("col_stick_l_vtkbioeng")
    col_stick_l.SetFileName(fn0c)
    col_stick_l.SetOpacity(0.0)
    col_stick_l.SetColor(1.0, 1.0, 1.0)

    # First tool element (stick_l)
    stick_l = vtkesqui.vtkScenarioElement()
    stick_l.SetName("stick_l")
    stick_l.SetPosition(-4.0, 0.0, 0.0)
    stick_l.SetOrientation(0, 0, 20)
    stick_l.SetOrigin(0, 0, 6)
    stick_l.SetVisualizationModel(vis_stick_l)
    stick_l.SetCollisionModel(col_stick_l)

    # Visualization model
    vis_tip_l = vtkesqui.vtkVisualizationModel()
    vis_tip_l.SetName("vis_tip_l")
    vis_tip_l.SetFileName(fn3)
    vis_tip_l.SetTextureFileName(fn0t)
    vis_tip_l.SetOpacity(1.0)
    vis_tip_l.SetColor(1.0, 0.0, 0.0)

    # Collision model
    col_tip_l = vtkesqui.vtkCollisionModel()
    col_tip_l.SetName("col_tip_l_vtkbioeng")
    col_tip_l.SetFileName(fn3c)
    col_tip_l.SetOpacity(0.0)
    col_tip_l.SetColor(1.0, 1.0, 1.0)

    # Second tool element (tip_l)
    tip_l = vtkesqui.vtkScenarioElement()
    tip_l.SetName("tip_l")
    tip_l.SetPosition(-4.0, 0.0, 0.0)
    tip_l.SetOrientation(0, 0, 20)
    tip_l.SetOrigin(0, 0, 6)
    tip_l.SetVisualizationModel(vis_tip_l)
    tip_l.SetCollisionModel(col_tip_l)

    probe_l = vtkesqui.vtkToolProbe()
    probe_l.AddElement(stick_l)
    probe_l.AddElement(tip_l)

    # Right tool (Grasper)
    # Visualization model
    vis_stick_r = vtkesqui.vtkVisualizationModel()
    vis_stick_r.SetName("vis_stick_r")
    vis_stick_r.SetFileName(fn0)
    vis_stick_r.SetTextureFileName(fn0t)
    vis_stick_r.SetOpacity(1.0)
    vis_stick_r.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_r = vtkesqui.vtkCollisionModel()
    col_stick_r.SetName("col_stick_r_vtkbioeng")
    col_stick_r.SetFileName(fn0c)
    col_stick_r.SetOpacity(0.0)
    col_stick_r.SetColor(1.0, 1.0, 1.0)

    # First tool element (stick_r)
    stick_r = vtkesqui.vtkScenarioElement()
    stick_r.SetName("stick_r")
    stick_r.SetPosition(4.0, 0.0, 0.0)
    stick_r.SetOrientation(0, 0, -20)
    stick_r.SetOrigin(0, 0, 6)
    stick_r.SetVisualizationModel(vis_stick_r)
    #stick_r.SetCollisionModel(col_stick_r)

    # Visualization model
    vis_l_lever_r = vtkesqui.vtkVisualizationModel()
    vis_l_lever_r.SetName("vis_l_lever_r")
    vis_l_lever_r.SetFileName(fn1)
    vis_l_lever_r.SetTextureFileName(fn0t)
    vis_l_lever_r.SetOpacity(1.0)
    vis_l_lever_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_l_lever_r = vtkesqui.vtkCollisionModel()
    col_l_lever_r.SetName("col_l_lever_r_vtkbioeng")
    col_l_lever_r.SetFileName(fn1c)
    col_l_lever_r.SetOpacity(0.0)
    col_l_lever_r.SetColor(1.0, 1.0, 1.0)

    # Second tool element (l_lever_r)
    l_lever_r = vtkesqui.vtkScenarioElement()
    l_lever_r.SetName("l_lever_r")
    l_lever_r.SetPosition(4.0, 0.0, 0.0)
    l_lever_r.SetOrientation(0, 0, -20)
    l_lever_r.SetOrigin(0, 0, 6)
    l_lever_r.SetVisualizationModel(vis_l_lever_r)
    l_lever_r.SetCollisionModel(col_l_lever_r)

    # Visualization model
    vis_r_lever_r = vtkesqui.vtkVisualizationModel()
    vis_r_lever_r.SetName("vis_r_lever_r")
    vis_r_lever_r.SetFileName(fn2)
    vis_r_lever_r.SetTextureFileName(fn0t)
    vis_r_lever_r.SetOpacity(1.0)
    vis_r_lever_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_r_lever_r = vtkesqui.vtkCollisionModel()
    col_r_lever_r.SetName("col_r_lever_r_vtkbioeng")
    col_r_lever_r.SetFileName(fn2c)
    col_r_lever_r.SetOpacity(0.0)
    col_r_lever_r.SetColor(1.0, 1.0, 1.0)

    # Second tool element (r_lever_r)
    r_lever_r = vtkesqui.vtkScenarioElement()
    r_lever_r.SetName("r_lever_r")
    r_lever_r.SetPosition(4.0, 0.0, 0.0)
    r_lever_r.SetOrientation(0, 0, -20)
    r_lever_r.SetOrigin(0, 0, 6)
    r_lever_r.SetVisualizationModel(vis_r_lever_r)
    r_lever_r.SetCollisionModel(col_r_lever_r)

    grasper_r = vtkesqui.vtkToolGrasper()
    grasper_r.SetStick(stick_r)
    grasper_r.SetLeftLever(l_lever_r)
    grasper_r.SetRightLever(r_lever_r)

    # Add an Organ
    # Visualization model
    vis_ball = vtkesqui.vtkVisualizationModel()
    vis_ball.SetName("vis_ball")
    vis_ball.SetFileName(fn4)
    vis_ball.SetTextureFileName(fn4t)
    vis_ball.SetOpacity(1.0)

    # Collision model
    col_ball = vtkesqui.vtkCollisionModel()
    col_ball.SetName("col_ball_vtkbioeng")
    col_ball.SetFileName(fn4c)
    col_ball.SetOpacity(0.0)

    # Deformation model
    def_ball = vtkesqui.vtkParticleSpringSystemInterface()
    def_ball.SetName("def_ball_particle")
    def_ball.SetFileName(fn4d)
    def_ball.SetOpacity(0.0)
    def_ball.SetSpring(150)
    def_ball.SetDistance(1.0)
    def_ball.SetDamping(3)
    def_ball.SetMass(.1)
    def_ball.SetTimeStep(0.001)

    # Organ element (ball)
    e_ball = vtkesqui.vtkScenarioElement()
    e_ball.SetName("ball")
    e_ball.SetPosition(0.0, 0.0, -2.0)
    e_ball.SetOrientation(0, 0, 0)
    e_ball.SetVisualizationModel(vis_ball)
    e_ball.SetCollisionModel(col_ball)
    e_ball.SetDeformationModel(def_ball)

    ball = vtkesqui.vtkOrgan()
    ball.AddElement(e_ball)

    # Add an Organ (Cavity)
    # Visualization model
    vis_cavity = vtkesqui.vtkVisualizationModel()
    vis_cavity.SetName("vis_cavity")
    vis_cavity.SetFileName(fn5)
    vis_cavity.SetTextureFileName(fn5t)
    vis_cavity.SetOpacity(1.0)

    # Collision model
    col_cavity = vtkesqui.vtkCollisionModel()
    col_cavity.SetName("col_cavity_vtkbioeng")
    col_cavity.SetFileName(fn5c)
    col_cavity.SetOpacity(0.0)

    # Deformation model
    def_cavity = vtkesqui.vtkParticleSpringSystemInterface()
    def_cavity.SetName("def_cavity_particle")
    def_cavity.SetFileName(fn5d)
    def_cavity.SetOpacity(0.0)
    def_cavity.SetSpring(150)
    def_cavity.SetDistance(1.0)
    def_cavity.SetDamping(3)
    def_cavity.SetMass(.1)
    def_cavity.SetTimeStep(0.001)

    # Organ element (cavity)
    e_cavity = vtkesqui.vtkScenarioElement()
    e_cavity.SetName("cavity")
    e_cavity.SetPosition(0.0, 0.0, -2.0)
    e_cavity.SetOrientation(-30, 0, 0)
    e_cavity.SetVisualizationModel(vis_cavity)
    e_cavity.SetCollisionModel(col_cavity)
    e_cavity.SetDeformationModel(def_cavity)

    cavity = vtkesqui.vtkOrgan()
    cavity.AddElement(e_cavity)

    scenario = vtkesqui.vtkScenario()
    scenario.SetName("vtkESQui - Laparoscopy")

    scenario.AddObject(probe_l)
    scenario.AddObject(grasper_r)
    scenario.AddObject(ball)
    scenario.AddObject(cavity)

    # Scenario camera
    camera = vtk.vtkCamera()
    camera.SetPosition(0, 0, 6)
    camera.SetFocalPoint(0, 0, -6)
    camera.Yaw(0)
    camera.Elevation(20)
    camera.Pitch(-15)
    camera.ParallelProjectionOff()
    camera.SetViewAngle(70)
    camera.Dolly(1.2)
    scenario.SetCamera(camera)

    #/********** Lights	**********/
    headLight = vtk.vtkLight()
    headLight.SetLightTypeToHeadlight()
    headLight.PositionalOn()
    headLight.SetIntensity(0.8)
    headLight.SetConeAngle(60)
    scenario.AddLight(headLight)

    ambientLight = vtk.vtkLight()
    ambientLight.SetLightTypeToSceneLight()
    ambientLight.PositionalOff()
    ambientLight.SetPosition(0, 1, 1)
    ambientLight.SetIntensity(0.5)
    scenario.AddLight(ambientLight)

    style = vtkesqui.vtkDefaultInteractorStyle()
    style.SetScenario(scenario)

    simulation = vtkesqui.vtkSimulation()
    simulation.SetScenario(scenario)
    simulation.SetInteractorStyle(style)
    simulation.SetRenderTimerRate(50)
    simulation.SetSimulationTimerRate(50)
    simulation.SetInteractionTimerRate(50)
    simulation.InteractionOn()
    simulation.CollisionOn()
    simulation.Initialize()

    simulation.Run()
Example #16
0
 def __init__(self):
     self.source = vtk.vtkLight()
     self.glyph = LightGlyph()
     self.el = 0
     self.az = 0
     self.saved = []
Example #17
0
def cubeSolutionToImage(input, filename):
    actors = []
    appendFilters = []
    renderers = []

    for i in range(7):
        appendFilters.append(vtk.vtkAppendPolyData())

    nbPieces = 0

    # on génère les cubes et on les ajoute aux polyData des pieces
    for i in range(cubeSize):
        for j in range(cubeSize):
            for k in range(cubeSize):
                cube = vtk.vtkCubeSource()
                cube.SetXLength(1.0)
                cube.SetYLength(1.0)
                cube.SetZLength(1.0)
                cube.SetCenter(i - 1, j - 1, k - 1)
                obj = appendFilters[input[i, j, k]]
                nbPieces = max(nbPieces, input[i, j, k] + 1)
                obj.AddInputConnection(cube.GetOutputPort())

    # cube outline
    cubeFrame = vtk.vtkCubeSource()
    cubeFrame.SetXLength(cubeSize + 0.1)
    cubeFrame.SetYLength(cubeSize + 0.1)
    cubeFrame.SetZLength(cubeSize + 0.1)
    cubeFrame.SetCenter(0, 0, 0)
    cubeFrameMapper = vtk.vtkPolyDataMapper()
    cubeFrameMapper.SetInputConnection(cubeFrame.GetOutputPort())
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(cubeFrame.GetOutputPort())
    mapper2 = vtk.vtkPolyDataMapper()
    mapper2.SetInputConnection(outline.GetOutputPort())
    cubeFrameActor = vtk.vtkActor()
    cubeFrameActor.SetMapper(mapper2)
    cubeFrameActor.GetProperty().SetColor((0, 0, 0))

    # camera
    camera = vtk.vtkCamera()
    camera.SetPosition(8, 8, 8)

    # lumiere directionnelle
    light = vtk.vtkLight()
    light.SetLightTypeToSceneLight()
    light.SetPosition(2, 5, 10)

    # 7 renderers, un pour chaque etape
    for i in range(7):
        renderer = vtk.vtkRenderer()
        renderer.SetActiveCamera(camera)
        renderer.SetBackground(1, 1, 1)

        renderer.AddLight(light)

        renderer.SetUseFXAA(True)
        renderers.append(renderer)

        cubeMapper = vtk.vtkPolyDataMapper()
        cubeMapper.SetInputConnection(appendFilters[i].GetOutputPort())
        cubeActor = vtk.vtkActor()
        cubeActor.SetMapper(cubeMapper)
        cubeActor.GetProperty().SetColor(colors[i])
        cubeActor.GetProperty().SetAmbient(0.4)
        actors.append(cubeActor)

        for a in actors:
            renderer.AddActor(a)

    # rendering offscreen car non nécessaire
    renWin = vtk.vtkRenderWindow()
    renWin.OffScreenRenderingOn()
    renWin.SetSize(600, 900)

    r = 4
    c = 2

    for i in reversed(range(r - 1)):
        for j in range(c):
            index = c * (r - i - 2) + j
            renderers[index].SetViewport(j / c, i / r, (j + 1) / c,
                                         (i + 1) / r)
            renderers[index].AddActor(cubeFrameActor)

    renderers[6].SetViewport(0, 0.75, 1, 1)

    for r in renderers:
        renWin.AddRenderer(r)

    renWin.Render()

    w2i = vtk.vtkWindowToImageFilter()
    w2i.SetInput(renWin)
    w2i.Update()

    writer = vtk.vtkPNGWriter()
    writer.SetFileName(filename)
    writer.SetInputConnection(w2i.GetOutputPort())
    writer.Write()
Example #18
0
    def __init__(self,parent = None):
        super(robotWindow,self).__init__(parent = None)
        self.setupUi(self)
        
        self.robot = palmModel()
               
        self.vtkWidget = QVTKRenderWindowInteractor(self.robotWidget)
        self.ren = vtk.vtkRenderer()
        
        lightPosition = [0,0,1]
        lightFocalPoint = [0,0,0]
        light = vtk.vtkLight()
        light.SetLightTypeToSceneLight()
        light.SetPosition(lightPosition[0], lightPosition[1], lightPosition[2])
        light.SetPositional(True) 
        light.SetConeAngle(10)
        light.SetFocalPoint(lightFocalPoint[0], lightFocalPoint[1], lightFocalPoint[2])
        light.SetDiffuseColor(1,0,0)
        light.SetAmbientColor(0,1,0)
        light.SetSpecularColor(0,0,1)
       

        lightActor = vtk.vtkLightActor()
        lightActor.SetLight(light)
        self.ren.AddViewProp(lightActor)
    
        self.ren.SetBackground(0, 0.6, 0.9)
        self.renderWindow = self.vtkWidget.GetRenderWindow()
        self.renderWindow.AddRenderer(self.ren)
        self.style = vtk.vtkInteractorStyleTrackballCamera()  
        self.vtkWidget.SetInteractorStyle(self.style)
        
        self.checkBox = [self.thumbChectBox,self.foreCheckBox,self.middleCheckBox,
                         self.ringCheckBox,self.littleCheckBox]

        if not self.thumbChectBox.isChecked():
            self.robot = robotModel()
            self.setArmConnect()
        
        self.finger = [self.robot.thumb.finger,self.robot.fingerOne,self.robot.fingerTwo,
                       self.robot.fingerThree,self.robot.fingerFour] 
        
        self.fingerSender = [self.thumbYSlide,self.thumbSlide,self.foreSlide,
                       self.middleSlide,self.ringSlide,self.littleSlide]
        self.setPalmConnect()     
        
        map(self.connectFun,self.checkBox,
            [self.changeCheckBoxConnect for i in range(len(self.checkBox))],
            [SIGNAL("clicked()") for i in range(len(self.checkBox))]) 
        
        self.fingerTogether = []
        self.slideTogether = []
        
        self.connect(self.palmModelCheckBox,SIGNAL("stateChanged(int)"),self.changeRobotModel)
        
        self.ren.AddActor(self.robot.getAssembly())
        self.axes = vtk.vtkAxesActor()
        self.axes.SetTotalLength(100,100,100)
        center = self.ren.GetCenter()
        self.axes.SetPosition(0,0,0)
        #self.ren.AddActor(self.axes)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
        self.iren.Initialize()
    def __init__(self, render_size=DEFAULT_RENDER_SIZE, camera_pos=DEFAULT_CAMERA_POS,
                 offscreen_rendering=True, custom_lighting=True):
        """
        Initializes VTK objects for rendering.
        """
        self.render_size = render_size
        self.camera_pos = camera_pos

        # vtk objects for rendering
        self.vtkrenderer = vtk.vtkRenderer()

        self.camera_view_count = len(self.camera_pos)
        
        self.vtkcamera = vtk.vtkCamera()
        self._setup_camera(self.camera_pos[0])
        # this is the view angle we used for rendering objects in blender.
        self.vtkcamera.SetViewAngle(35.0)

        # if custom_lighting is ON, we use our own lights in the scene. default lighting of vtk is not very good.
        # this is the default (used for our BDAoOSS model and CogSci16 paper).
        # we illuminate the upper hemisphere.
        self.custom_lighting = custom_lighting
        if self.custom_lighting:
            self.light1 = vtk.vtkLight()
            self.light1.SetIntensity(.3)
            self.light1.SetPosition(8, -12, 10)
            self.light1.SetDiffuseColor(1.0, 1.0, 1.0)
            self.light2 = vtk.vtkLight()
            self.light2.SetIntensity(.3)
            self.light2.SetPosition(-12, -10, 8)
            self.light2.SetDiffuseColor(1.0, 1.0, 1.0)
            self.light3 = vtk.vtkLight()
            self.light3.SetIntensity(.3)
            self.light3.SetPosition(10, 10, 12)
            self.light3.SetDiffuseColor(1.0, 1.0, 1.0)
            self.light4 = vtk.vtkLight()
            self.light4.SetIntensity(.3)
            self.light4.SetPosition(-10, 8, 10)
            self.light4.SetDiffuseColor(1.0, 1.0, 1.0)

            self.vtkrenderer.AddLight(self.light1)
            self.vtkrenderer.AddLight(self.light2)
            self.vtkrenderer.AddLight(self.light3)
            self.vtkrenderer.AddLight(self.light4)

        self.vtkrenderer.SetBackground(0.0, 0.0, 0.0)  # Background color

        self.vtkrender_window = vtk.vtkRenderWindow()
        self.vtkrender_window.AddRenderer(self.vtkrenderer)
        self.vtkrender_window.SetSize(self.render_size)
        self.vtkrender_window_interactor = vtk.vtkRenderWindowInteractor()
        self.vtkrender_window_interactor.SetRenderWindow(self.vtkrender_window)

        # turn on off-screen rendering. Note that rendering will be much faster this way
        # HOWEVER, you won't be able to use view etc. methods to look at and interact with
        # the object. You must render the object and use matplotlib etc. to view the
        # rendered image.
        self.offscreen_rendering = offscreen_rendering
        if self.offscreen_rendering:
            self.vtkrender_window.SetOffScreenRendering(1)

        # these below lines are here with the hope of fixing a problem with off-screen rendering.
        # the quality of the offscreen render seems inferior.
        # i'm not sure why this is.
        # 1) it could be because there is a bug and anti-aliasing and multisampling is disabled
        # for offscreen rendering. see the below link (though that applies to vtk6.0)
        # http://public.kitware.com/pipermail/vtk-developers/2015-April/031741.html
        # 2) it might be that offscreen rendering uses software rendering, no hardware
        # acceleration. I don't know how one can check that.
        # still, the quality of the renders are good enough for our purposes
        self.vtkrender_window.SetLineSmoothing(1)
        self.vtkrender_window.SetMultiSamples(8)

        # vtk objects for reading, and rendering object parts
        self.cube_source = vtk.vtkCubeSource()
        self.cube_output = self.cube_source.GetOutput()
        self.cube_mapper = vtk.vtkPolyDataMapper()
        self.cube_mapper.SetInput(self.cube_output)
def main():
    #Importing file
    frontView1 = cv2.imread("4_f_f.jpeg", 1)
    img_side_view1 = cv2.imread("4_s.jpg", 1)

    #kernal definition for preprocessing
    kernel = np.ones((3, 3), np.uint8)
    #converting colorspace for images
    original_image = cv2.cvtColor(frontView1, cv2.COLOR_BGR2GRAY)
    img_side_view = cv2.cvtColor(img_side_view1, cv2.COLOR_BGR2GRAY)

    # Creating a binary image for thresholding
    ret, original_image = cv2.threshold(original_image, 250, 255, cv2.THRESH_BINARY)

    # closing the gaps in the foreground and retaining only the hollow portion
    closing = cv2.morphologyEx(original_image, cv2.MORPH_CLOSE, kernel)
    # gradient = cv2.morphologyEx(closing, cv2.MORPH_GRADIENT, kernel)

    # Median filtering
    gray_image_mf = median_filter(closing, 1)

    # Calculate the Laplacian
    lap = cv2.Laplacian(gray_image_mf, cv2.CV_64F)

    # Calculate the sharpened image
    sharp = closing - 0.7 * lap

    # Saturate the pixels in either direction
    sharp[sharp > 255] = 255
    sharp[sharp < 0] = 0

    # for the main frame
    #Storing the pixel information for the thresholded image of front view
    list = []
    xCoordinate = []
    yCoordinate = []
    sortedYcoordinates = []
    for x in range(sharp.shape[0]):
        for y in range(sharp.shape[1]):
            if sharp[x, y] != 255:
                xCoordinate.append(x)
                yCoordinate.append(y)
                sortedYcoordinates.append(y)
    list.append(xCoordinate)
    list.append(yCoordinate)
    sortedYcoordinates.sort()
    count = 0
    for x in range(150):
        if sortedYcoordinates[x] == sortedYcoordinates[0]:
            count += 1
    count = int(count / 2)
    print(original_image.shape)

    ##Showing the front view image
    cv2.imshow('front', frontView1)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    # process handle image


    # The Preprocessing of sideview
    img_side_view = cv2.resize(img_side_view,(original_image.shape[1],original_image.shape[0]))
    print(img_side_view.shape)
    # Creating a binary image
    ret, img_side_view = cv2.threshold(img_side_view, 200, 255, cv2.THRESH_BINARY)

    # closing the gaps in the foreground and retaining only the hollow portion
    closing1 = cv2.morphologyEx(img_side_view, cv2.MORPH_CLOSE, kernel)
    # gradient = cv2.morphologyEx(closing, cv2.MORPH_GRADIENT, kernel)

    # Median filtering
    gray_image_mf1 = median_filter(closing1, 1)

    # Calculate the Laplacian
    lap1 = cv2.Laplacian(gray_image_mf1, cv2.CV_64F)

    # Calculate the sharpened image
    sharp1 = closing1 - 0.7 * lap1

    # Saturate the pixels in either direction
    sharp1[sharp1 > 255] = 255
    sharp1[sharp1 < 0] = 0

    #Storing the pixel information of the sideview
    xCoordinate_side_view = []
    yCoordinate_side_view = []
    ycoordinateTemp = []
    xcoordinateTemp = []
    for x in range(sharp1.shape[0]):
        for y in range(sharp1.shape[1]):
            if sharp1[x, y] != 255:
                xCoordinate_side_view.append(x)
                yCoordinate_side_view.append(y)
                ycoordinateTemp.append(y)
                xcoordinateTemp.append(x)
    #Sorting the list, which provides very first pixel information in either x-axis or y-axis
    ycoordinateTemp.sort()
    xcoordinateTemp.sort()

    #Getting the distance of the first pixel from top margin
    adjustmentInYdirection = xCoordinate_side_view[0]- xCoordinate[yCoordinate.index(sortedYcoordinates[0])]
    #Showing the sideview of image
    cv2.imshow('side_view', img_side_view1)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    colors = vtk.vtkNamedColors()

    # Defining the points
    points = vtk.vtkPoints()
    idx = 0
    for x in range(len(xCoordinate)):
        points.InsertNextPoint(yCoordinate[x], -xCoordinate[x], 0)
        idx += 1
    #adding points in the polydata
    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)

    # Create anything you want here, we will use a cube for the demo.
    cubeSource = vtk.vtkCubeSource()
    cubeSource.SetZLength(20.0)

    #assigning the cubesorce in the glyph
    glyph3D = vtk.vtkGlyph3D()
    glyph3D.SetSourceConnection(cubeSource.GetOutputPort())
    glyph3D.SetInputData(polydata)
    glyph3D.Update()

    # storing all the pixel information in the side view
    points1 = vtk.vtkPoints()
    idx = 0
    for x in range(len(xCoordinate_side_view)):
        points1.InsertNextPoint(sortedYcoordinates[0], -xCoordinate_side_view[x]+adjustmentInYdirection ,
                                yCoordinate_side_view[x] -ycoordinateTemp[0])
        idx += 1
    #Creating polydata for sideview
    polydata1 = vtk.vtkPolyData()
    polydata1.SetPoints(points1)

    # Create anything you want here, we will use a cube for the demo.
    cubeSource1 = vtk.vtkCubeSource()
    cubeSource1.SetXLength(20.0)
    #Glyph for sideview
    glyph3D1 = vtk.vtkGlyph3D()
    glyph3D1.SetSourceConnection(cubeSource1.GetOutputPort())
    glyph3D1.SetInputData(polydata1)
    glyph3D1.Update()

    # copying information from the same handle to generate the other handle of the sunglass
    points2 = vtk.vtkPoints()
    idx = 0
    for x in range(len(xCoordinate_side_view)):
        points2.InsertNextPoint(sortedYcoordinates[-1] - cubeSource1.GetXLength() / 2,
                                -xCoordinate_side_view[x] + adjustmentInYdirection,
                                yCoordinate_side_view[x]-ycoordinateTemp[0])
        idx += 1

    #Creating polydata for the remaining handle
    polydata2 = vtk.vtkPolyData()
    polydata2.SetPoints(points2)
    glyph3D2 = vtk.vtkGlyph3D()
    glyph3D2.SetSourceConnection(cubeSource1.GetOutputPort())
    glyph3D2.SetInputData(polydata2)
    glyph3D2.Update()

    # Adding mapper for the distinct three polydatas
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(glyph3D.GetOutputPort())
    mapper1 = vtk.vtkPolyDataMapper()
    mapper1.SetInputConnection(glyph3D1.GetOutputPort())
    mapper2 = vtk.vtkPolyDataMapper()
    mapper2.SetInputConnection(glyph3D2.GetOutputPort())

    #Defining actors for the three mappers separately
    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(colors.GetColor3d("alizarin_crimson"))
    actor.SetMapper(mapper)
    actor1 = vtk.vtkActor()
    #actor1.GetProperty().SetColor(colors.GetColor3d("midnight_blue"))
    actor1.SetMapper(mapper1)
    actor2 = vtk.vtkActor()
    actor2.GetProperty().SetColor(colors.GetColor3d("MistyRose"))
    actor2.SetMapper(mapper2)

    #Grouping the three parts and scaling so that it is usable in unity3D or other 3D application
    assembly = vtk.vtkAssembly()
    assembly.AddPart(actor)
    assembly.AddPart(actor1)
    assembly.AddPart(actor2)
    assembly.SetScale(.01,.01,.01)

    #We tried to reduce the size of mesh, apparently it does not work without triangulated surface
    inputPoly = vtk.vtkPolyData()
    inputPoly.ShallowCopy(glyph3D.GetOutput())
    print("Before decimation\n"
          "-----------------\n"
          "There are " + str(inputPoly.GetNumberOfPoints()) + "points.\n"
                                                              "There are " + str(
        inputPoly.GetNumberOfPolys()) + "polygons.\n")
    decimate = vtk.vtkDecimatePro()
    decimate.SetInputData(inputPoly)
    decimate.SetTargetReduction(.10)
    decimate.Update()
    decimatedPoly = vtk.vtkPolyData()
    decimatedPoly.ShallowCopy(decimate.GetOutput())
    print("After decimation \n"
          "-----------------\n"
          "There are " + str(decimatedPoly.GetNumberOfPoints()) + "points.\n"
                                                                  "There are " + str(
        decimatedPoly.GetNumberOfPolys()) + "polygons.\n")

    # Set object properties
    prop = actor.GetProperty()
    prop.SetInterpolationToPhong()  # Set shading to Phong
    prop.ShadingOn()
    # prop.SetColor(0, 15, 26)
    prop.SetDiffuse(0.8)  # 0.8
    prop.SetAmbient(0.3)  # 0.3
    prop.SetSpecular(1.0)  # 1.0
    prop.SetSpecularPower(100.0)  # 100.0

    # Set object properties
    prop = actor1.GetProperty()
    prop.SetInterpolationToPhong()  # Set shading to Phong
    prop.ShadingOn()
    # prop.SetColor(0, 51, 0)
    prop.SetDiffuse(0.8)  # 0.8
    prop.SetAmbient(0.3)  # 0.3
    prop.SetSpecular(1.0)  # 1.0
    prop.SetSpecularPower(100.0)  # 100.0

    # Set object properties
    prop = actor2.GetProperty()
    prop.SetInterpolationToPhong()  # Set shading to Phong
    prop.ShadingOn()
    # prop.SetColor(1, 1, 0)
    prop.SetDiffuse(0.8)  # 0.8
    prop.SetAmbient(0.3)  # 0.3
    prop.SetSpecular(1.0)  # 1.0
    prop.SetSpecularPower(100.0)  # 100.0

    # Define light
    light = vtk.vtkLight()
    light.SetLightTypeToSceneLight()
    light.SetAmbientColor(1, 1, 1)
    light.SetDiffuseColor(1, 1, 1)
    light.SetSpecularColor(1, 1, 1)
    light.SetPosition(-100, 100, 25)
    light.SetFocalPoint(0, 0, 0)
    light.SetIntensity(1.0)  # 0.8

    # Define light
    light1 = vtk.vtkLight()
    light1.SetLightTypeToSceneLight()
    light1.SetAmbientColor(1, 1, 1)
    light1.SetDiffuseColor(1, 1, 1)
    light1.SetSpecularColor(1, 1, 1)
    light1.SetPosition(100, -100, -25)
    light1.SetFocalPoint(0, 0, 0)
    light1.SetIntensity(1.0)

    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetSize(700, 700)
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    renderer.AddActor(actor)
    renderer.AddLight(light)
    renderer.AddLight(light1)
    renderer.AddActor(actor1)
    renderer.AddLight(light)
    renderer.AddActor(actor2)
    renderer.AddLight(light)
    renderer.SetBackground(colors.GetColor3d("slate_grey_light"))
    #Write the Obj file to disk
    objWriter = vtk.vtkOBJExporter()
    objWriter.SetFilePrefix("glass")
    objWriter.SetRenderWindow(renderWindow)
    objWriter.SetInputConnection(renderer)
    objWriter.Write()
    renderWindow.Render()
    renderWindowInteractor.Start()
# actor
actorx = vtk.vtkActor()
actorx.SetMapper(mapperx)
actory = vtk.vtkActor()
actory.SetMapper(mappery)
actorz = vtk.vtkActor()
actorz.SetMapper(mapperz)

# color actor
actorx.GetProperty().SetColor(1,0,0)
actory.GetProperty().SetColor(0,1,0)
actorz.GetProperty().SetColor(0,1,1)

# lighting
light1 = vtk.vtkLight()
light1.SetIntensity(.7)
#light.SetLightTypeToSceneLight()
light1.SetPosition(1, -1, 1)
#light.SetFocalPoint(0, 0, 0)
#light.SetPositional(True)
#light.SetConeAngle(60)
light1.SetDiffuseColor(1, 1, 1)
#light.SetAmbientColor(0, 1, 0)

light2 = vtk.vtkLight()
light2.SetIntensity(.7)
#light.SetLightTypeToSceneLight()
light2.SetPosition(-1, -1, 1)
#light.SetFocalPoint(0, 0, 0)
#light.SetPositional(True)
Example #22
0
    def set_render(self, centroid, only_points, mode, min_max_dist, *args,
                   **kwargs):
        renderer = vtk.vtkRenderer()
        renderer.ResetCamera()

        # '''draw world system'''
        # renderer.AddActor(self.set_axes_actor())
        '''set camera'''
        camera = self.set_camera(
            centroid,
            [[0., 0., 0.],
             [
                 -centroid[0], -centroid[1],
                 centroid[0]**2 / centroid[2] + centroid[1]**2 / centroid[2]
             ]], self.cam_K)
        renderer.SetActiveCamera(camera)
        '''draw scene points'''
        point_size = 4
        colors = np.linalg.norm(self.scene_points[:, :3] - centroid, axis=1)
        colors = self.depth_palette[np.int16(
            (colors - colors.min()) / (colors.max() - colors.min()) * 99)]
        point_actor = self.set_actor(
            self.set_mapper(
                self.set_points_property(self.scene_points[:, :3],
                                         255 * colors), 'box'))
        point_actor.GetProperty().SetPointSize(point_size)
        point_actor.GetProperty().SetOpacity(0.3)
        point_actor.GetProperty().SetInterpolationToPBR()
        renderer.AddActor(point_actor)

        if not only_points:
            '''draw shapenet models'''
            dists = np.linalg.norm(np.array(self.center_list[mode]) - centroid,
                                   axis=1)
            if min_max_dist is None:
                min_max_dist = [min(dists), max(dists)]
            dists = (dists - min_max_dist[0]) / (min_max_dist[1] -
                                                 min_max_dist[0])
            dists = np.clip(dists, 0, 1)
            inst_color_ids = np.round(
                dists * (self.palette_inst.shape[0] - 1)).astype(np.uint8)

            for obj, cls_id, color_id in zip(self.instance_models[mode],
                                             self.class_ids[mode],
                                             inst_color_ids):
                object_actor = self.set_actor(self.set_mapper(obj, 'model'))
                object_actor.GetProperty().SetColor(
                    self.palette_inst[color_id])
                object_actor.GetProperty().SetInterpolationToPBR()
                renderer.AddActor(object_actor)
            '''draw bounding boxes'''
            for center, vectors, cls_id in zip(self.center_list[mode],
                                               self.vector_list[mode],
                                               self.class_ids[mode]):
                box_line_actor = self.get_bbox_line_actor(
                    center, vectors, [64, 64, 64], 1., 3)
                box_line_actor.GetProperty().SetInterpolationToPBR()
                renderer.AddActor(box_line_actor)

                # corners, faces = self.get_box_corners(center, vectors)
                # bbox_actor = self.set_actor(self.set_mapper(self.set_cube_prop(corners, faces, 255*self.palette_cls[cls_id]), 'box'))
                # bbox_actor.GetProperty().SetOpacity(0.2)
                # bbox_actor.GetProperty().SetInterpolationToPBR()
                # renderer.AddActor(bbox_actor)

                # draw orientations
                color = [[1, 0, 0], [0, 1, 0], [0., 0., 1.]]

                for index in range(vectors.shape[0]):
                    arrow_actor = self.set_arrow_actor(center, vectors[index])
                    arrow_actor.GetProperty().SetColor(color[index])
                    renderer.AddActor(arrow_actor)
        '''light'''
        positions = [(10, 10, 10), (-10, 10, 10), (10, -10, 10),
                     (-10, -10, 10)]
        for position in positions:
            light = vtk.vtkLight()
            light.SetIntensity(1.5)
            light.SetPosition(*position)
            light.SetPositional(True)
            light.SetFocalPoint(0, 0, 0)
            light.SetColor(1., 1., 1.)
            renderer.AddLight(light)

        renderer.SetBackground(1., 1., 1.)
        return renderer, min_max_dist
Example #23
0
def main():

  fn0 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp";
  fn0c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp";
  fn1 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_l.vtp";
  fn1c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_l_col.vtp";
  fn2 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_r.vtp";
  fn2c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_r_col.vtp";
  fn0t = "/home/david/vtkESQuiData/Scenario/Textures/metal.jpg";
  fn3 = "/home/david/vtkESQuiData/Scenario/Tools/Probe/tip.vtp";
  fn3c = "/home/david/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp";

  #Create scenario
  scenario = vtkesqui.vtkScenario()
  
  # Left Tool (Probe)
  # Visualization model
  vis_stick_l = vtkesqui.vtkVisualizationModel()
  vis_stick_l.SetName("vis_stick_l")
  vis_stick_l.SetFileName(fn0)
  vis_stick_l.SetTextureFileName(fn0t)
  vis_stick_l.SetOpacity(1.0)
  vis_stick_l.SetColor(1.0, 1.0, 1.0)
  
  # Collision model
  col_stick_l = vtkesqui.vtkCollisionModel()
  col_stick_l.SetName("col_stick_l_vtkbioeng")
  col_stick_l.SetFileName(fn0c)
  col_stick_l.SetOpacity(1.0)
  col_stick_l.SetColor(1.0, 1.0, 1.0)
  
  # First tool element (stick_l)
  stick_l = vtkesqui.vtkScenarioElement()
  stick_l.SetName("stick_l")
  stick_l.SetPosition(-3.0, 0.0, 0.0)
  stick_l.SetOrientation(0, 0, 20)
  stick_l.SetOrigin(0,0,6)
  stick_l.SetVisualizationModel(vis_stick_l)
  stick_l.SetCollisionModel(col_stick_l)
  
  # Visualization model
  vis_tip_l = vtkesqui.vtkVisualizationModel()
  vis_tip_l.SetName("vis_tip_l")
  vis_tip_l.SetFileName(fn3)
  vis_tip_l.SetTextureFileName(fn0t)
  vis_tip_l.SetOpacity(1.0)
  vis_tip_l.SetColor(1.0, 0.0, 0.0)
  
  # Collision model
  col_tip_l = vtkesqui.vtkCollisionModel()
  col_tip_l.SetName("col_tip_l_vtkbioeng")
  col_tip_l.SetFileName(fn3c)
  col_tip_l.SetOpacity(1.0)
  col_tip_l.SetColor(1.0, 1.0, 1.0)
  
  # Second tool element (tip_l)
  tip_l = vtkesqui.vtkScenarioElement()
  tip_l.SetName("tip_l")
  tip_l.SetPosition(-3.0, 0.0, 0.0)
  tip_l.SetOrientation(0, 0, 20)
  tip_l.SetOrigin(0,0,6)
  tip_l.SetVisualizationModel(vis_tip_l)
  tip_l.SetCollisionModel(col_tip_l)
  
  probe_l = vtkesqui.vtkToolProbe()
  probe_l.AddElement(stick_l)
  probe_l.AddElement(tip_l)
  
  # Right tool (Grasper)
  # Visualization model
  vis_stick_r = vtkesqui.vtkVisualizationModel()
  vis_stick_r.SetName("vis_stick_r")
  vis_stick_r.SetFileName(fn0)
  vis_stick_r.SetTextureFileName(fn0t)
  vis_stick_r.SetOpacity(1.0)
  vis_stick_r.SetColor(1.0, 1.0, 1.0)
  
  # Collision model
  col_stick_r = vtkesqui.vtkCollisionModel()
  col_stick_r.SetName("col_stick_r_vtkbioeng")
  col_stick_r.SetFileName(fn0c)
  col_stick_r.SetOpacity(1.0)
  col_stick_r.SetColor(1.0, 1.0, 1.0)
  
  # First tool element (stick_r)
  stick_r = vtkesqui.vtkScenarioElement()
  stick_r.SetName("stick_r")
  stick_r.SetPosition(3.0, 0.0, 0.0)
  stick_r.SetOrientation(0, 0, -20)
  stick_r.SetOrigin(0,0,6)
  stick_r.SetVisualizationModel(vis_stick_r)
  stick_r.SetCollisionModel(col_stick_r)
  
  # Visualization model
  vis_l_lever_r = vtkesqui.vtkVisualizationModel()
  vis_l_lever_r.SetName("vis_l_lever_r")
  vis_l_lever_r.SetFileName(fn1)
  vis_l_lever_r.SetTextureFileName(fn0t)
  vis_l_lever_r.SetOpacity(1.0)
  vis_l_lever_r.SetColor(0.0, 1.0, 0.0)
  
  # Collision model
  col_l_lever_r = vtkesqui.vtkCollisionModel()
  col_l_lever_r.SetName("col_l_lever_r_vtkbioeng")
  col_l_lever_r.SetFileName(fn1c)
  col_l_lever_r.SetOpacity(1.0)
  col_l_lever_r.SetColor(1.0, 1.0, 1.0)
  
  # Second tool element (l_lever_r)
  l_lever_r = vtkesqui.vtkScenarioElement()
  l_lever_r.SetName("l_lever_r")
  l_lever_r.SetPosition(3.0, 0.0, 0.0)
  l_lever_r.SetOrientation(0, 0, -20)
  l_lever_r.SetOrigin(0,0,6)
  l_lever_r.SetVisualizationModel(vis_l_lever_r)
  l_lever_r.SetCollisionModel(col_l_lever_r)
  
    # Visualization model
  vis_r_lever_r = vtkesqui.vtkVisualizationModel()
  vis_r_lever_r.SetName("vis_r_lever_r")
  vis_r_lever_r.SetFileName(fn2)
  vis_r_lever_r.SetTextureFileName(fn0t)
  vis_r_lever_r.SetOpacity(1.0)
  vis_r_lever_r.SetColor(0.0, 1.0, 0.0)
  
  # Collision model
  col_r_lever_r = vtkesqui.vtkCollisionModel()
  col_r_lever_r.SetName("col_r_lever_r_vtkbioeng")
  col_r_lever_r.SetFileName(fn2c)
  col_r_lever_r.SetOpacity(1.0)
  col_r_lever_r.SetColor(1.0, 1.0, 1.0)
  
  # Second tool element (r_lever_r)
  r_lever_r = vtkesqui.vtkScenarioElement()
  r_lever_r.SetName("r_lever_r")
  r_lever_r.SetPosition(3.0, 0.0, 0.0)
  r_lever_r.SetOrientation(0, 0, -20)
  r_lever_r.SetOrigin(0,0,6)
  r_lever_r.SetVisualizationModel(vis_r_lever_r)
  r_lever_r.SetCollisionModel(col_r_lever_r)
  
  grasper_r = vtkesqui.vtkToolGrasper()
  grasper_r.SetStick(stick_r)
  grasper_r.SetLeftLever(l_lever_r)
  grasper_r.SetRightLever(r_lever_r)
  
    # Add objects to the scenario
  scenario.AddObject(probe_l)
  scenario.AddObject(grasper_r)

  #for i in range(2):
  #i = 0
  
  b = createBall(0)
  scenario.AddObject(b)
  
  # Scenario camera
  camera = vtk.vtkCamera()
  camera.SetPosition(0, 0, 6)
  camera.SetFocalPoint(0, 0, -6)
  camera.Yaw(0)
  camera.Elevation(20)
  camera.Pitch(-15)
  camera.ParallelProjectionOff()
  camera.SetViewAngle(70)
  scenario.SetCamera(camera)
  
  #/********** Lights  **********/
  headLight = vtk.vtkLight()
  headLight.SetLightTypeToHeadlight()
  headLight.PositionalOn()
  headLight.SetIntensity(0.8)
  headLight.SetConeAngle(20)
  scenario.AddLight(headLight)
  
  ambientLight = vtk.vtkLight()
  ambientLight.SetIntensity(0.8)
  ambientLight.SetLightTypeToHeadlight()
  ambientLight.PositionalOff()
  scenario.AddLight(ambientLight)

  # Force the scenario to initialize
  scenario.Update()
  
  # Sign up to receive TimerEvent
  iren = scenario.GetRenderWindowInteractor()
  cb = vtkTimerCallback()
  iren.AddObserver('TimerEvent', cb.execute)
  # 1ms timer
  timerId = iren.CreateRepeatingTimer(1);
  cb.scenario = scenario
  
  iren.Start()
Example #24
0
def main():
    colors = vtk.vtkNamedColors()

    # The following lines create a sphere represented by polygons.
    sphere = vtk.vtkSphereSource()
    sphere.SetThetaResolution(100)
    sphere.SetPhiResolution(50)

    # The mapper is responsible for pushing the geometry into the graphics
    # library. It may also do color mapping, if scalars or other attributes
    # are defined.
    #
    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphere.GetOutputPort())

    # The actor is a grouping mechanism: besides the geometry (mapper), it
    # also has a property, transformation matrix, and/or texture map.
    # In this example we create eight different spheres (two rows of four
    # spheres) and set the specular lighting coefficients. A little ambient
    # is turned on so the sphere is not completely black on the back side.
    #
    sphere1 = vtk.vtkActor()
    sphere1.SetMapper(sphereMapper)
    sphere1.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere1.GetProperty().SetAmbient(0.3)
    sphere1.GetProperty().SetDiffuse(0.0)
    sphere1.GetProperty().SetSpecular(1.0)
    sphere1.GetProperty().SetSpecularPower(5.0)

    sphere2 = vtk.vtkActor()
    sphere2.SetMapper(sphereMapper)
    sphere2.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere2.GetProperty().SetAmbient(0.3)
    sphere2.GetProperty().SetDiffuse(0.0)
    sphere2.GetProperty().SetSpecular(1.0)
    sphere2.GetProperty().SetSpecularPower(10.0)
    sphere2.AddPosition(1.25, 0, 0)

    sphere3 = vtk.vtkActor()
    sphere3.SetMapper(sphereMapper)
    sphere3.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere3.GetProperty().SetAmbient(0.3)
    sphere3.GetProperty().SetDiffuse(0.0)
    sphere3.GetProperty().SetSpecular(1.0)
    sphere3.GetProperty().SetSpecularPower(20.0)
    sphere3.AddPosition(2.5, 0, 0)

    sphere4 = vtk.vtkActor()
    sphere4.SetMapper(sphereMapper)
    sphere4.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere4.GetProperty().SetAmbient(0.3)
    sphere4.GetProperty().SetDiffuse(0.0)
    sphere4.GetProperty().SetSpecular(1.0)
    sphere4.GetProperty().SetSpecularPower(40.0)
    sphere4.AddPosition(3.75, 0, 0)

    sphere5 = vtk.vtkActor()
    sphere5.SetMapper(sphereMapper)
    sphere5.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere5.GetProperty().SetAmbient(0.3)
    sphere5.GetProperty().SetDiffuse(0.0)
    sphere5.GetProperty().SetSpecular(0.5)
    sphere5.GetProperty().SetSpecularPower(5.0)
    sphere5.AddPosition(0.0, 1.25, 0)

    sphere6 = vtk.vtkActor()
    sphere6.SetMapper(sphereMapper)
    sphere6.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere6.GetProperty().SetAmbient(0.3)
    sphere6.GetProperty().SetDiffuse(0.0)
    sphere6.GetProperty().SetSpecular(0.5)
    sphere6.GetProperty().SetSpecularPower(10.0)
    sphere6.AddPosition(1.25, 1.25, 0)

    sphere7 = vtk.vtkActor()
    sphere7.SetMapper(sphereMapper)
    sphere7.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere7.GetProperty().SetAmbient(0.3)
    sphere7.GetProperty().SetDiffuse(0.0)
    sphere7.GetProperty().SetSpecular(0.5)
    sphere7.GetProperty().SetSpecularPower(20.0)
    sphere7.AddPosition(2.5, 1.25, 0)

    sphere8 = vtk.vtkActor()
    sphere8.SetMapper(sphereMapper)
    sphere8.GetProperty().SetColor(colors.GetColor3d("Red"))
    sphere8.GetProperty().SetAmbient(0.3)
    sphere8.GetProperty().SetDiffuse(0.0)
    sphere8.GetProperty().SetSpecular(0.5)
    sphere8.GetProperty().SetSpecularPower(40.0)
    sphere8.AddPosition(3.75, 1.25, 0)

    # Create the graphics structure. The renderer renders into the
    # render window. The render window interactor captures mouse events
    # and will perform appropriate camera or actor manipulation
    # depending on the nature of the events.
    #
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the renderer, set the background and size.
    #
    ren.AddActor(sphere1)
    ren.AddActor(sphere2)
    ren.AddActor(sphere3)
    ren.AddActor(sphere4)
    ren.AddActor(sphere5)
    ren.AddActor(sphere6)
    ren.AddActor(sphere7)
    ren.AddActor(sphere8)
    # Set the background color.
    bkg = map(lambda x: x / 255.0, [25, 51, 102])
    colors.SetColor('BkgColor', *bkg)
    ren.SetBackground(colors.GetColor3d("BkgColor"))
    renWin.SetSize(640, 480)

    # Set up the lighting.
    #
    light = vtk.vtkLight()
    light.SetFocalPoint(1.875, 0.6125, 0)
    light.SetPosition(0.875, 1.6125, 1)
    ren.AddLight(light)

    # We want to eliminate perspective effects on the apparent lighting.
    # Parallel camera projection will be used. To zoom in parallel projection
    # mode, the ParallelScale is set.
    #
    ren.GetActiveCamera().SetFocalPoint(0, 0, 0)
    ren.GetActiveCamera().SetPosition(0, 0, 1)
    ren.GetActiveCamera().SetViewUp(0, 1, 0)
    ren.GetActiveCamera().ParallelProjectionOn()
    ren.ResetCamera()
    ren.GetActiveCamera().SetParallelScale(1.5)

    # This starts the event loop and invokes an initial render.
    #
    iren.Initialize()
    iren.Start()
Example #25
0
outline.SetInputConnection(normals.GetOutputPort())
mapOutline = vtk.vtkPolyDataMapper()
mapOutline.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(mapOutline)
outlineActor.GetProperty().SetColor(0, 0, 0)

# Create a vtkCamera, and set the camera parameters.
camera = vtk.vtkCamera()
camera.SetClippingRange(1.60187, 20.0842)
camera.SetFocalPoint(0.21406, 1.5, 0)
camera.SetPosition(8.3761, 4.94858, 4.12505)
camera.SetViewUp(0.180325, 0.549245, -0.815974)

# Create a vtkLight, and set the light parameters.
light = vtk.vtkLight()
light.SetFocalPoint(0.21406, 1.5, 0)
light.SetPosition(8.3761, 4.94858, 4.12505)

# Create the Renderers.  Assign them the appropriate viewport
# coordinates, active camera, and light.
ren = vtk.vtkRenderer()
ren.SetViewport(0, 0, 0.5, 1.0)
ren.SetActiveCamera(camera)
ren.AddLight(light)
ren2 = vtk.vtkRenderer()
ren2.SetViewport(0.5, 0, 1.0, 1.0)
ren2.SetActiveCamera(camera)
ren2.AddLight(light)

# Create the RenderWindow and RenderWindowInteractor.
Example #26
0
def volume_render(field,
                  outfile,
                  maxopacity=1.0,
                  cmap='bone',
                  size=600,
                  elevation=45,
                  azimuth=45,
                  bkg=(0.0, 0.0, 0.0),
                  opacitycut=0.35,
                  offscreen=False,
                  rayfunction='smart'):
    """
    Uses vtk to make render an image of a field, with control over the
    camera angle and colormap.

    Input Parameters
    ----------------
        field : np.ndarray
            3D array of the field to render.
        outfile : string
            The save name of the image.
        maxopacity : Float
            Default is 1.0
        cmap : matplotlib colormap string
            Passed to cmap2colorfunc. Default is bone.
        size : 2-element list-like of ints or Int
            The size of the final rendered image.
        elevation : Numeric
            The elevation of the camera angle, in degrees. Default is 45
        azimuth : Numeric
            The azimuth of the camera angle, in degrees. Default is 45
        bkg : Tuple of floats
            3-element tuple of floats on [0,1] of the background image color.
            Default is (0., 0., 0.).
    """
    sh = field.shape

    dataImporter = vtk.vtkImageImport()
    dataImporter.SetDataScalarTypeToUnsignedChar()
    data_string = field.tostring()
    dataImporter.SetNumberOfScalarComponents(1)
    dataImporter.CopyImportVoidPointer(data_string, len(data_string))

    dataImporter.SetDataExtent(0, sh[2] - 1, 0, sh[1] - 1, 0, sh[0] - 1)
    dataImporter.SetWholeExtent(0, sh[2] - 1, 0, sh[1] - 1, 0, sh[0] - 1)

    alphaChannelFunc = vtk.vtkPiecewiseFunction()
    alphaChannelFunc.AddPoint(0, 0.0)
    alphaChannelFunc.AddPoint(int(255 * opacitycut), maxopacity)

    volumeProperty = vtk.vtkVolumeProperty()
    colorFunc = cmap2colorfunc(cmap)
    volumeProperty.SetColor(colorFunc)
    volumeProperty.SetScalarOpacity(alphaChannelFunc)

    volumeMapper = vtk.vtkVolumeRayCastMapper()
    if rayfunction == 'mip':
        comp = vtk.vtkVolumeRayCastMIPFunction()
        comp.SetMaximizeMethodToOpacity()
    elif rayfunction == 'avg':
        comp = vtk.vtkVolumeRayCastCompositeFunction()
    elif rayfunction == 'iso':
        comp = vtk.vtkVolumeRayCastIsosurfaceFunction()
        comp.SetIsoValue(maxopacity / 2)
    else:
        comp = vtk.vtkVolumeRayCastIsosurfaceFunction()
    volumeMapper.SetSampleDistance(0.1)
    volumeMapper.SetVolumeRayCastFunction(comp)

    if rayfunction == 'smart':
        volumeMapper = vtk.vtkSmartVolumeMapper()
    volumeMapper.SetInputConnection(dataImporter.GetOutputPort())

    volume = vtk.vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)

    light = vtk.vtkLight()
    light.SetLightType(vtk.VTK_LIGHT_TYPE_HEADLIGHT)
    light.SetIntensity(5.5)
    light.SwitchOn()

    renderer = vtk.vtkRenderer()
    renderWin = vtk.vtkRenderWindow()
    renderWin.AddRenderer(renderer)
    renderWin.SetOffScreenRendering(1)

    if not hasattr(size, '__iter__'):
        size = (size, size)

    renderer.AddVolume(volume)
    renderer.AddLight(light)
    renderer.SetBackground(*bkg)
    renderWin.SetSize(*size)

    if offscreen:
        renderWin.SetOffScreenRendering(1)

    def exitCheck(obj, event):
        if obj.GetEventPending() != 0:
            obj.SetAbortRender(1)

    renderWin.AddObserver("AbortCheckEvent", exitCheck)

    renderInteractor = vtk.vtkRenderWindowInteractor()
    renderInteractor.Initialize()
    renderWin.Render()
    renderInteractor.Start()

    #writer = vtk.vtkFFMPEGWriter()
    #writer.SetQuality(2)
    #writer.SetRate(24)
    #w2i = vtk.vtkWindowToImageFilter()
    #w2i.SetInput(renderWin)
    #writer.SetInputConnection(w2i.GetOutputPort())
    #writer.SetFileName('movie.avi')
    #writer.Start()
    #writer.End()

    writer = vtk.vtkPNGWriter()
    w2i = vtk.vtkWindowToImageFilter()
    w2i.SetInput(renderWin)
    writer.SetInputConnection(w2i.GetOutputPort())

    renderWin.Render()
    ac = renderer.GetActiveCamera()
    ac.Elevation(elevation)
    ac.Azimuth(azimuth)
    renderer.ResetCameraClippingRange()
    renderWin.Render()
    w2i.Modified()
    writer.SetFileName(outfile)
    writer.Write()
sphereKeyProperty = vtk.vtkInformation()
sphereKeyProperty.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0)
sphereKeyProperty.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0)
sphereActor.SetPropertyKeys(sphereKeyProperty)
sphereActor.SetMapper(sphereMapper)

sphereActor.SetVisibility(1)
sphereActor.SetPosition(2,2,-1)
sphereActor.GetProperty().SetColor(1,1,0)

renderer.AddViewPro(rectActor)
renderer.AddViewPro(boxActor)
renderer.AddViewPro(coneActor)
renderer.AddViewPro(sphereActor)

l1 = vtk.vtkLight()
l1.SetPosition(-4,4,-1)
l1.SetFocalPOint(boxActor.GetPosition())
l1.SetColor(1,1,1)
l1.SetPositional(1)
renderer.AddLight(l1)
l1.SetSwitch(1)

l2 = vtk.vtkLight()
l2.SetPosition(-4,5,1)
l2.SetFocalPOint(sphereActor.GetPosition())
l2.SetColor(1,0,1)
l2.SetPositional(1)
renderer.AddLight(l2)
l2.SetSwitch(1)
Example #28
0
cameraP.SetDelegatePass(seq)

toneMappingP = vtk.vtkToneMappingPass()
toneMappingP.SetToneMappingType(vtk.vtkToneMappingPass.GenericFilmic)
toneMappingP.SetGenericFilmicDefaultPresets()
toneMappingP.SetDelegatePass(cameraP)
toneMappingP.SetExposure(0.2)
# vtkOpenGLRenderer::SafeDownCast(renderer)->SetPass(toneMappingP);
renderer.SetPass(toneMappingP)

#lights
# view.spotlight_with_idx(0).from_string("1.28357 1.02985 1.09627 -0.219563  0.406239   0.10122 0.881201        0 0.132991        0 40 0.191147 19.1147")
# view.spotlight_with_idx(0).m_power=11
# view.spotlight_with_idx(0).m_color=[160/255, 225/255, 225/255]
#light 0
light_0 = vtk.vtkLight()
light_0.SetFocalPoint(0, 0, 0)
# light_0.SetPositional(1)
light_0.SetPosition(1.28357, 1.02985, 1.09627)
light_0.SetColor(160 / 255, 225 / 255, 225 / 255)
light_0.SetIntensity(11 / 1)
#light 1
# view.spotlight_with_idx(1).from_string("-1.11644  1.35694 0.953531 -0.309229 -0.393641 -0.142557 0.853874        0 0.132991        0 40 0.191147 19.1147")
# view.spotlight_with_idx(1).m_power=11
# view.spotlight_with_idx(1).m_color=[255/255, 225/255, 225/255]
light_1 = vtk.vtkLight()
light_1.SetFocalPoint(0, 0, 0)
# light_1.SetPositional(1)
light_1.SetPosition(-1.11644, 1.35694, 0.953531)
light_1.SetColor(255 / 255, 225 / 255, 225 / 255)
light_1.SetIntensity(11 / 1)
Example #29
0
    def __init__(self,
                 render_size=DEFAULT_RENDER_SIZE,
                 camera_pos=DEFAULT_CAMERA_POS,
                 offscreen_rendering=True,
                 custom_lighting=True):
        """
        Initializes VTK objects for rendering.
        """
        self.render_size = render_size
        self.camera_pos = camera_pos

        # vtk objects for rendering
        self.vtkrenderer = vtk.vtkRenderer()

        self.camera_view_count = len(self.camera_pos)

        self.vtkcamera = vtk.vtkCamera()
        self._setup_camera(self.camera_pos[0])
        # this is the view angle we used for rendering objects in blender.
        self.vtkcamera.SetViewAngle(35.0)

        # if custom_lighting is ON, we use our own lights in the scene. default lighting of vtk is not very good.
        # this is the default (used for our BDAoOSS model and CogSci16 paper).
        # we illuminate the upper hemisphere.
        self.custom_lighting = custom_lighting
        if self.custom_lighting:
            self.light1 = vtk.vtkLight()
            self.light1.SetIntensity(.3)
            self.light1.SetPosition(8, -12, 10)
            self.light1.SetDiffuseColor(1.0, 1.0, 1.0)
            self.light2 = vtk.vtkLight()
            self.light2.SetIntensity(.3)
            self.light2.SetPosition(-12, -10, 8)
            self.light2.SetDiffuseColor(1.0, 1.0, 1.0)
            self.light3 = vtk.vtkLight()
            self.light3.SetIntensity(.3)
            self.light3.SetPosition(10, 10, 12)
            self.light3.SetDiffuseColor(1.0, 1.0, 1.0)
            self.light4 = vtk.vtkLight()
            self.light4.SetIntensity(.3)
            self.light4.SetPosition(-10, 8, 10)
            self.light4.SetDiffuseColor(1.0, 1.0, 1.0)

            self.vtkrenderer.AddLight(self.light1)
            self.vtkrenderer.AddLight(self.light2)
            self.vtkrenderer.AddLight(self.light3)
            self.vtkrenderer.AddLight(self.light4)

        self.vtkrenderer.SetBackground(0.0, 0.0, 0.0)  # Background color

        self.vtkrender_window = vtk.vtkRenderWindow()
        self.vtkrender_window.AddRenderer(self.vtkrenderer)
        self.vtkrender_window.SetSize(self.render_size)
        self.vtkrender_window_interactor = vtk.vtkRenderWindowInteractor()
        self.vtkrender_window_interactor.SetRenderWindow(self.vtkrender_window)

        # turn on off-screen rendering. Note that rendering will be much faster this way
        # HOWEVER, you won't be able to use view etc. methods to look at and interact with
        # the object. You must render the object and use matplotlib etc. to view the
        # rendered image.
        self.offscreen_rendering = offscreen_rendering
        if self.offscreen_rendering:
            self.vtkrender_window.SetOffScreenRendering(1)

        # these below lines are here with the hope of fixing a problem with off-screen rendering.
        # the quality of the offscreen render seems inferior.
        # i'm not sure why this is.
        # 1) it could be because there is a bug and anti-aliasing and multisampling is disabled
        # for offscreen rendering. see the below link (though that applies to vtk6.0)
        # http://public.kitware.com/pipermail/vtk-developers/2015-April/031741.html
        # 2) it might be that offscreen rendering uses software rendering, no hardware
        # acceleration. I don't know how one can check that.
        # still, the quality of the renders are good enough for our purposes
        self.vtkrender_window.SetLineSmoothing(1)
        self.vtkrender_window.SetMultiSamples(8)

        # vtk objects for reading, and rendering object parts
        self.cube_source = vtk.vtkCubeSource()
        self.cube_output = self.cube_source.GetOutput()
        self.cube_mapper = vtk.vtkPolyDataMapper()
        self.cube_mapper.SetInput(self.cube_output)
Example #30
0
    def init_3d(self):
     
        reader_zl1 = vtk.vtkSTLReader()
        reader_zl1.SetFileName("./stl/zl_1.stl")
        reader_zl2 = vtk.vtkSTLReader()
        reader_zl2.SetFileName("./stl/zl_2.stl")
        reader_zl3 = vtk.vtkSTLReader()
        reader_zl3.SetFileName("./stl/zl_3.stl")
        reader_zl4 = vtk.vtkSTLReader()
        reader_zl4.SetFileName("./stl/zl_4.stl")
        reader_zl5 = vtk.vtkSTLReader()
        reader_zl5.SetFileName("./stl/zl_5.stl")
        reader_zl6 = vtk.vtkSTLReader()
        reader_zl6.SetFileName("./stl/zl_6.stl")
        reader_zl7 = vtk.vtkSTLReader()
        reader_zl7.SetFileName("./stl/zl_7.stl")
        reader_zl8 = vtk.vtkSTLReader()
        reader_zl8.SetFileName("./stl/zl_8.stl")
        reader_zl9 = vtk.vtkSTLReader()
        reader_zl9.SetFileName("./stl/zl_9.stl")
        reader_zl10 = vtk.vtkSTLReader()
        reader_zl10.SetFileName("./stl/zl_10.stl")
        reader_zl11 = vtk.vtkSTLReader()
        reader_zl11.SetFileName("./stl/zl_11.stl")

        reader_zz1 = vtk.vtkSTLReader()
        reader_zz1.SetFileName("./stl/zz_1.stl")
        reader_zz2 = vtk.vtkSTLReader()
        reader_zz2.SetFileName("./stl/zz_2.stl")
        reader_zz3 = vtk.vtkSTLReader()
        reader_zz3.SetFileName("./stl/zz_3.stl")
        reader_zz4 = vtk.vtkSTLReader()
        reader_zz4.SetFileName("./stl/zz_4.stl")
        reader_zz5 = vtk.vtkSTLReader()
        reader_zz5.SetFileName("./stl/zz_5.stl")
        reader_zz6 = vtk.vtkSTLReader()
        reader_zz6.SetFileName("./stl/zz_6.stl")
        reader_zz7 = vtk.vtkSTLReader()
        reader_zz7.SetFileName("./stl/zz_7.stl")
        reader_zz8 = vtk.vtkSTLReader()
        reader_zz8.SetFileName("./stl/zz_8.stl")
        reader_zz9 = vtk.vtkSTLReader()
        reader_zz9.SetFileName("./stl/zz_9.stl")
        reader_zz10 = vtk.vtkSTLReader()
        reader_zz10.SetFileName("./stl/zz_10.stl")
        reader_zz11 = vtk.vtkSTLReader()
        reader_zz11.SetFileName("./stl/zz_11.stl")
        reader_zz12 = vtk.vtkSTLReader()
        reader_zz12.SetFileName("./stl/zz_12.stl")

        reader_lg1 = vtk.vtkSTLReader()
        reader_lg1.SetFileName("./stl/lg_1.stl")
        reader_lg2 = vtk.vtkSTLReader()
        reader_lg2.SetFileName("./stl/lg_2.stl")

        reader_bj1 = vtk.vtkSTLReader()
        reader_bj1.SetFileName("./stl/bj_1.stl")
        reader_bj2 = vtk.vtkSTLReader()
        reader_bj2.SetFileName("./stl/bj_2.stl")

        reader_ab1 = vtk.vtkSTLReader()
        reader_ab1.SetFileName("./stl/ab_1.stl")
        reader_ab2 = vtk.vtkSTLReader()
        reader_ab2.SetFileName("./stl/ab_2.stl")
        reader_bz1 = vtk.vtkSTLReader()
        reader_bz1.SetFileName("./stl/bz_1.stl")
        reader_hl1 = vtk.vtkSTLReader()
        reader_hl1.SetFileName("./stl/hl_1.stl")

        #load mapper
        mapper_zl1 = vtk.vtkPolyDataMapper()
        mapper_zl2 = vtk.vtkPolyDataMapper()
        mapper_zl3 = vtk.vtkPolyDataMapper()
        mapper_zl4 = vtk.vtkPolyDataMapper()
        mapper_zl5 = vtk.vtkPolyDataMapper()
        mapper_zl6 = vtk.vtkPolyDataMapper()
        mapper_zl7 = vtk.vtkPolyDataMapper()
        mapper_zl8 = vtk.vtkPolyDataMapper()
        mapper_zl9 = vtk.vtkPolyDataMapper()
        mapper_zl10 = vtk.vtkPolyDataMapper()
        mapper_zl11 = vtk.vtkPolyDataMapper()

        mapper_zz1 = vtk.vtkPolyDataMapper()
        mapper_zz2 = vtk.vtkPolyDataMapper()
        mapper_zz3 = vtk.vtkPolyDataMapper()
        mapper_zz4 = vtk.vtkPolyDataMapper()
        mapper_zz5 = vtk.vtkPolyDataMapper()
        mapper_zz6 = vtk.vtkPolyDataMapper()
        mapper_zz7 = vtk.vtkPolyDataMapper()
        mapper_zz8 = vtk.vtkPolyDataMapper()
        mapper_zz9 = vtk.vtkPolyDataMapper()
        mapper_zz10 = vtk.vtkPolyDataMapper()
        mapper_zz11 = vtk.vtkPolyDataMapper()
        mapper_zz12 = vtk.vtkPolyDataMapper()

        mapper_lg1 = vtk.vtkPolyDataMapper()
        mapper_lg2 = vtk.vtkPolyDataMapper()

        mapper_bj1 = vtk.vtkPolyDataMapper()
        mapper_bj2 = vtk.vtkPolyDataMapper()

        mapper_ab1 = vtk.vtkPolyDataMapper()
        mapper_ab2 = vtk.vtkPolyDataMapper()
        mapper_bz1 = vtk.vtkPolyDataMapper()
        mapper_hl1 = vtk.vtkPolyDataMapper()

        if vtk.VTK_MAJOR_VERSION <= 5:
            mapper_zl1.SetInput(reader_zl1.GetOutput())
            mapper_zl2.SetInput(reader_zl2.GetOutput())
            mapper_zl3.SetInput(reader_zl3.GetOutput())
            mapper_zl4.SetInput(reader_zl4.GetOutput())
            mapper_zl5.SetInput(reader_zl5.GetOutput())
            mapper_zl6.SetInput(reader_zl6.GetOutput())
            mapper_zl7.SetInput(reader_zl7.GetOutput())
            mapper_zl8.SetInput(reader_zl8.GetOutput())
            mapper_zl9.SetInput(reader_zl9.GetOutput())
            mapper_zl10.SetInput(reader_zl10.GetOutput())
            mapper_zl11.SetInput(reader_zl11.GetOutput())

            mapper_zz1.SetInput(reader_zz1.GetOutput())
            mapper_zz2.SetInput(reader_zz2.GetOutput())
            mapper_zz3.SetInput(reader_zz3.GetOutput())
            mapper_zz4.SetInput(reader_zz4.GetOutput())
            mapper_zz5.SetInput(reader_zz5.GetOutput())
            mapper_zz6.SetInput(reader_zz6.GetOutput())
            mapper_zz7.SetInput(reader_zz7.GetOutput())
            mapper_zz8.SetInput(reader_zz8.GetOutput())
            mapper_zz9.SetInput(reader_zz9.GetOutput())
            mapper_zz10.SetInput(reader_zz10.GetOutput())
            mapper_zz11.SetInput(reader_zz11.GetOutput())
            mapper_zz12.SetInput(reader_zz12.GetOutput())

            mapper_lg1.SetInput(reader_lg1.GetOutput())
            mapper_lg2.SetInput(reader_lg2.GetOutput())

            mapper_bj1.SetInput(reader_bj1.GetOutput())
            mapper_bj2.SetInput(reader_bj2.GetOutput())

            mapper_ab1.SetInput(reader_ab1.GetOutput())
            mapper_ab2.SetInput(reader_ab2.GetOutput())
            mapper_bz1.SetInput(reader_bz1.GetOutput())
            mapper_hl1.SetInput(reader_hl1.GetOutput())

        else:
            mapper_zl1.SetInputConnection(reader_zl1.GetOutputPort())
            mapper_zl2.SetInputConnection(reader_zl2.GetOutputPort())
            mapper_zl3.SetInputConnection(reader_zl3.GetOutputPort())
            mapper_zl4.SetInputConnection(reader_zl4.GetOutputPort())
            mapper_zl5.SetInputConnection(reader_zl5.GetOutputPort())
            mapper_zl6.SetInputConnection(reader_zl6.GetOutputPort())
            mapper_zl7.SetInputConnection(reader_zl7.GetOutputPort())
            mapper_zl8.SetInputConnection(reader_zl8.GetOutputPort())
            mapper_zl9.SetInputConnection(reader_zl9.GetOutputPort())
            mapper_zl10.SetInputConnection(reader_zl10.GetOutputPort())
            mapper_zl11.SetInputConnection(reader_zl11.GetOutputPort())

            mapper_zz1.SetInputConnection(reader_zz1.GetOutputPort())
            mapper_zz2.SetInputConnection(reader_zz2.GetOutputPort())
            mapper_zz3.SetInputConnection(reader_zz3.GetOutputPort())
            mapper_zz4.SetInputConnection(reader_zz4.GetOutputPort())
            mapper_zz5.SetInputConnection(reader_zz5.GetOutputPort())
            mapper_zz6.SetInputConnection(reader_zz6.GetOutputPort())
            mapper_zz7.SetInputConnection(reader_zz7.GetOutputPort())
            mapper_zz8.SetInputConnection(reader_zz8.GetOutputPort())
            mapper_zz9.SetInputConnection(reader_zz9.GetOutputPort())
            mapper_zz10.SetInputConnection(reader_zz10.GetOutputPort())
            mapper_zz11.SetInputConnection(reader_zz11.GetOutputPort())
            mapper_zz12.SetInputConnection(reader_zz12.GetOutputPort())

            mapper_lg1.SetInputConnection(reader_lg1.GetOutputPort())
            mapper_lg2.SetInputConnection(reader_lg2.GetOutputPort())

            mapper_bj1.SetInputConnection(reader_bj1.GetOutputPort())
            mapper_bj2.SetInputConnection(reader_bj2.GetOutputPort())

            mapper_ab1.SetInputConnection(reader_ab1.GetOutputPort())
            mapper_ab2.SetInputConnection(reader_ab2.GetOutputPort())
            mapper_bz1.SetInputConnection(reader_bz1.GetOutputPort())
            mapper_hl1.SetInputConnection(reader_hl1.GetOutputPort())

        #create actor
        actor_zl1 = vtk.vtkActor()
        actor_zl2 = vtk.vtkActor()
        actor_zl3 = vtk.vtkActor()
        actor_zl4 = vtk.vtkActor()
        actor_zl5 = vtk.vtkActor()
        actor_zl6 = vtk.vtkActor()
        actor_zl7 = vtk.vtkActor()
        actor_zl8 = vtk.vtkActor()
        actor_zl9 = vtk.vtkActor()
        actor_zl10 = vtk.vtkActor()
        actor_zl11 = vtk.vtkActor()

        actor_zz1 = vtk.vtkActor()
        actor_zz2 = vtk.vtkActor()
        actor_zz3 = vtk.vtkActor()
        actor_zz4 = vtk.vtkActor()
        actor_zz5 = vtk.vtkActor()
        actor_zz6 = vtk.vtkActor()
        actor_zz7 = vtk.vtkActor()
        actor_zz8 = vtk.vtkActor()
        actor_zz9 = vtk.vtkActor()
        actor_zz10 = vtk.vtkActor()
        actor_zz11 = vtk.vtkActor()
        actor_zz12 = vtk.vtkActor()

        actor_lg1 = vtk.vtkActor()
        actor_lg2 = vtk.vtkActor()

        actor_bj1 = vtk.vtkActor()
        actor_bj2 = vtk.vtkActor()

        actor_ab1 = vtk.vtkActor()
        actor_ab2 = vtk.vtkActor()
        actor_bz1 = vtk.vtkActor()
        actor_hl1 = vtk.vtkActor()

        actor_zl1.SetMapper(mapper_zl1)
        actor_zl2.SetMapper(mapper_zl2)
        actor_zl3.SetMapper(mapper_zl3)
        actor_zl4.SetMapper(mapper_zl4)
        actor_zl5.SetMapper(mapper_zl5)
        actor_zl6.SetMapper(mapper_zl6)
        actor_zl7.SetMapper(mapper_zl7)
        actor_zl8.SetMapper(mapper_zl8)
        actor_zl9.SetMapper(mapper_zl9)
        actor_zl10.SetMapper(mapper_zl10)
        actor_zl11.SetMapper(mapper_zl11)

        actor_zz1.SetMapper(mapper_zz1)
        actor_zz2.SetMapper(mapper_zz2)
        actor_zz3.SetMapper(mapper_zz3)
        actor_zz4.SetMapper(mapper_zz4)
        actor_zz5.SetMapper(mapper_zz5)
        actor_zz6.SetMapper(mapper_zz6)
        actor_zz7.SetMapper(mapper_zz7)
        actor_zz8.SetMapper(mapper_zz8)
        actor_zz9.SetMapper(mapper_zz9)
        actor_zz10.SetMapper(mapper_zz10)
        actor_zz11.SetMapper(mapper_zz11)
        actor_zz12.SetMapper(mapper_zz12)

        actor_lg1.SetMapper(mapper_lg1)
        actor_lg2.SetMapper(mapper_lg2)

        actor_bj1.SetMapper(mapper_bj1)
        actor_bj2.SetMapper(mapper_bj2)

        actor_ab1.SetMapper(mapper_ab1)
        actor_ab2.SetMapper(mapper_ab2)
        actor_bz1.SetMapper(mapper_bz1)
        actor_hl1.SetMapper(mapper_hl1)

        #set color
        zl_odd_color_r = 100/255
        zl_odd_color_g = 0/255
        zl_odd_color_b = 230/255

        zl_even_color_r = 0/255
        zl_even_color_g = 255/255
        zl_even_color_b = 0/255

        actor_zl1.GetProperty().SetColor(zl_odd_color_r,zl_odd_color_g,zl_odd_color_b)
        actor_zl3.GetProperty().SetColor(zl_odd_color_r,zl_odd_color_g,zl_odd_color_b)
        actor_zl5.GetProperty().SetColor(zl_odd_color_r,zl_odd_color_g,zl_odd_color_b)
        actor_zl7.GetProperty().SetColor(zl_odd_color_r,zl_odd_color_g,zl_odd_color_b)
        actor_zl9.GetProperty().SetColor(zl_odd_color_r,zl_odd_color_g,zl_odd_color_b)
        actor_zl11.GetProperty().SetColor(zl_odd_color_r,zl_odd_color_g,zl_odd_color_b)

        actor_zl2.GetProperty().SetColor(zl_even_color_r,zl_even_color_g,zl_even_color_b)
        actor_zl4.GetProperty().SetColor(zl_even_color_r,zl_even_color_g,zl_even_color_b)
        actor_zl6.GetProperty().SetColor(zl_even_color_r,zl_even_color_g,zl_even_color_b)
        actor_zl8.GetProperty().SetColor(zl_even_color_r,zl_even_color_g,zl_even_color_b)
        actor_zl10.GetProperty().SetColor(zl_even_color_r,zl_even_color_g,zl_even_color_b)

        actor_lg1.GetProperty().SetColor(255/255,0/255,0/255)
        actor_lg2.GetProperty().SetColor(255/255,0/255,0/255)

        actor_bj1.GetProperty().SetColor(150/255,70/255,50/255)
        actor_bj2.GetProperty().SetColor(150/255,70/255,50/255)

        actor_ab1.GetProperty().SetColor(209/255,170/255,52/255)
        actor_ab2.GetProperty().SetColor(209/255,170/255,52/255)
        actor_bz1.GetProperty().SetColor(225/255,111/255,0/255)
        actor_hl1.GetProperty().SetColor(30/255,144/255,255/255)
        
        # Create a rendering window and renderer
        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(49/255, 54/255, 59/255)
        # self.ren.SetBackground2(25/255, 50/255, 100/255)
        # self.ren.SetGradientBackground(1)

        self.vtk_widget = QVTKWidget(self.page1_widget)
        self.page1_vlayout.addWidget(self.vtk_widget)

        #
        # axes = vtk.vtkAxesActor() 
        # axes.SetTotalLength(100, 100, 100)  # Set the total length of the axes in 3 dimensions 
        # # Set the type of the shaft to a cylinder:0, line:1, or user defined geometry. 
        # axes.SetShaftType(0) 
        # axes.SetCylinderRadius(0.02) 
        # axes.SetAxisLabels(0) 
        # self.ren.AddActor(axes)

        #


        self.renWin = self.vtk_widget.GetRenderWindow()
        self.renWin.AddRenderer(self.ren)

        self.renWin.SetSize(20000,20000)
        self.renWin.Render()
        iren = self.renWin.GetInteractor()
        # iren.SetRenderWindow(renWin)
        
        # Assign actor to the renderer
        self.ren.AddActor(actor_zl1)
        self.ren.AddActor(actor_zl2)
        self.ren.AddActor(actor_zl3)
        self.ren.AddActor(actor_zl4)
        self.ren.AddActor(actor_zl5)
        self.ren.AddActor(actor_zl6)
        self.ren.AddActor(actor_zl7)
        self.ren.AddActor(actor_zl8)
        self.ren.AddActor(actor_zl9)
        self.ren.AddActor(actor_zl10)
        self.ren.AddActor(actor_zl11)

        self.ren.AddActor(actor_zz1)
        self.ren.AddActor(actor_zz2)
        self.ren.AddActor(actor_zz3)
        self.ren.AddActor(actor_zz4)
        self.ren.AddActor(actor_zz5)
        self.ren.AddActor(actor_zz6)
        self.ren.AddActor(actor_zz7)
        self.ren.AddActor(actor_zz8)
        self.ren.AddActor(actor_zz9)
        self.ren.AddActor(actor_zz10)
        self.ren.AddActor(actor_zz11)
        self.ren.AddActor(actor_zz12)

        self.ren.AddActor(actor_lg1)
        self.ren.AddActor(actor_lg2)

        self.ren.AddActor(actor_bj1)
        self.ren.AddActor(actor_bj2)

        self.ren.AddActor(actor_ab1)
        self.ren.AddActor(actor_ab2)
        self.ren.AddActor(actor_bz1)
        self.ren.AddActor(actor_hl1)

        self.actor_zl1_inf = str(actor_zl1.GetMapper().GetInformation())[16:32]
        self.actor_zl2_inf = str(actor_zl2.GetMapper().GetInformation())[16:32]
        self.actor_zl3_inf = str(actor_zl3.GetMapper().GetInformation())[16:32]
        self.actor_zl4_inf = str(actor_zl4.GetMapper().GetInformation())[16:32]
        self.actor_zl5_inf = str(actor_zl5.GetMapper().GetInformation())[16:32]
        self.actor_zl6_inf = str(actor_zl6.GetMapper().GetInformation())[16:32]
        self.actor_zl7_inf = str(actor_zl7.GetMapper().GetInformation())[16:32]
        self.actor_zl8_inf = str(actor_zl8.GetMapper().GetInformation())[16:32]
        self.actor_zl9_inf = str(actor_zl9.GetMapper().GetInformation())[16:32]
        self.actor_zl10_inf = str(actor_zl10.GetMapper().GetInformation())[16:32]
        self.actor_zl11_inf = str(actor_zl11.GetMapper().GetInformation())[16:32]

        self.actor2inf_dic = {}

        self.actor2inf_dic.update({self.actor_zl1_inf:'1'})
        self.actor2inf_dic.update({self.actor_zl2_inf:'2'})
        self.actor2inf_dic.update({self.actor_zl3_inf:'3'})
        self.actor2inf_dic.update({self.actor_zl4_inf:'4'})
        self.actor2inf_dic.update({self.actor_zl5_inf:'5'})
        self.actor2inf_dic.update({self.actor_zl6_inf:'6'})
        self.actor2inf_dic.update({self.actor_zl7_inf:'7'})
        self.actor2inf_dic.update({self.actor_zl8_inf:'8'})
        self.actor2inf_dic.update({self.actor_zl9_inf:'9'})
        self.actor2inf_dic.update({self.actor_zl10_inf:'10'})
        self.actor2inf_dic.update({self.actor_zl11_inf:'11'})

        camera = vtk.vtkCamera()
        camera.SetPosition(0.1,0.1,0)
        camera.SetFocalPoint(0,0,0)

        mylight = vtk.vtkLight()
        mylight.SetPosition(1,1,0)
        mylight.SetFocalPoint(0,0,0)
        self.ren.AddLight(mylight)

        self.ren.SetActiveCamera(camera)
        self.ren.ResetCamera()

        camera.Zoom(3)

        self.style = vtk.vtkInteractorStyleTrackballCamera()
        iren.SetInteractorStyle(self.style)
        
        iren.Initialize()

        self.picker = vtk.vtkCellPicker()
        self.picker.AddObserver("EndPickEvent", self.pickerfunc)     #将事件与回调函数建立连接
        self.style.AddObserver ('RightButtonReleaseEvent', self.pickerfunc)
        self.style.AddObserver ('RightButtonPressEvent', self.pickerfunc)

        iren.SetPicker(self.picker)
compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
volumeMapper = vtk.vtkVolumeRayCastMapper()
volumeMapper.SetVolumeRayCastFunction(compositeFunction)
volumeMapper.SetInputData(image)
volumeMapper.SetImageSampleDistance(5.0)

# The volume holds the mapper and the property and
# can be used to position/orient the volume
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)

ren = vtk.vtkRenderer()
ren.SetBackground(1, 1, 1)
ren.AddVolume(volume)
renWin = vtk.vtkRenderWindow()

light = vtk.vtkLight()
light.SetColor(1, 1, 1)  #光的颜色

ren.AddLight(light)

renWin.AddRenderer(ren)
renWin.SetSize(500, 500)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

renWin.Render()
iren.Initialize()
iren.Start()
Example #32
0
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphere.GetOutputPort())

sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)
sphereActor.GetProperty().SetColor(1, 0, 0)
sphereActor.GetProperty().SetAmbient(0.3)
sphereActor.GetProperty().SetDiffuse(0.0)
sphereActor.GetProperty().SetSpecular(0.5)

ren1 = vtk.vtkRenderer()
ren1.AddActor(sphereActor)
ren1.SetBackground(0.1, 0.2, 0.4)

light1 = vtk.vtkLight()
light1.SetFocalPoint(0, 0, 0)
light1.SetPosition(-0.8, 0.8, 1)
ren1.AddLight(light1)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(300, 300)

# for i in xrange(334):
#     sphereActor.GetProperty().SetAmbient(i * 0.03)
#     renWin.Render()

def Lighting(obj, ev):
    global i
    i += 1
Example #33
0
def main():
    colors = vtk.vtkNamedColors()

    # Set the background color.
    colors.SetColor("bkg", [26, 51, 102, 255])

    # The following lines create a sphere represented by polygons.
    #
    sphere = vtk.vtkSphereSource()
    sphere.SetThetaResolution(100)
    sphere.SetPhiResolution(50)

    # The mapper is responsible for pushing the geometry into the graphics
    # library. It may also do color mapping, if scalars or other attributes
    # are defined.
    #
    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphere.GetOutputPort())

    # The actor is a grouping mechanism: besides the geometry (mapper), it
    # also has a property, transformation matrix, and/or texture map.
    # In this example we create eight different spheres (two rows of four
    # spheres) and set the specular lighting coefficients. A little ambient
    # is turned on so the sphere is not completely black on the back side.
    #
    numberOfSpheres = 8
    spheres = list()
    ambient = 0.3
    diffuse = 0.5
    specular = 1.0
    spBase = 5.0
    spScale = 1.0
    position = [0, 0, 0]
    for i in range(0, numberOfSpheres):
        specularPower = spBase * spScale
        spheres.append(vtk.vtkActor())
        spheres[i].SetMapper(sphereMapper)
        spheres[i].GetProperty().SetColor(colors.GetColor3d("Red"))
        spheres[i].GetProperty().SetAmbient(ambient)
        spheres[i].GetProperty().SetDiffuse(diffuse)
        spheres[i].GetProperty().SetSpecular(specular)
        spheres[i].GetProperty().SetSpecularPower(specularPower)
        spheres[i].GetProperty().SetSpecularColor(colors.GetColor3d("White"))
        spheres[i].AddPosition(position)
        spScale = spScale * 2.0
        position[0] += 1.25
        if i == 3:
            specular = 0.5
            spScale = 1.0
            position[0] = 0
            position[1] = 1.25

    # Create the graphics structure. The renderer renders into the
    # render window. The render window interactor captures mouse events
    # and will perform appropriate camera or actor manipulation
    # depending on the nature of the events.
    #
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    # Add the actors to the renderer, set the background and size.
    #
    for i in range(0, numberOfSpheres):
        ren.AddActor(spheres[i])

    ren.SetBackground(colors.GetColor3d("bkg"))
    renWin.SetSize(640, 480)
    renWin.SetWindowName("Specular Spheres")

    # Set up the lighting.
    #
    light = vtk.vtkLight()
    light.SetFocalPoint(1.875, 0.6125, 0)
    light.SetPosition(0.875, 1.6125, 1)
    ren.AddLight(light)

    # We want to eliminate perspective effects on the apparent lighting.
    # Parallel camera projection will be used. To zoom in parallel projection
    # mode, the ParallelScale is set.
    #
    ren.GetActiveCamera().SetFocalPoint(0, 0, 0)
    ren.GetActiveCamera().SetPosition(0, 0, 1)
    ren.GetActiveCamera().SetViewUp(0, 1, 0)
    ren.GetActiveCamera().ParallelProjectionOn()
    ren.ResetCamera()
    ren.GetActiveCamera().SetParallelScale(2.0)
    # This starts the event loop and invokes an initial render.
    #
    iren.Initialize()
    renWin.Render()
    iren.Start()
actor.SetMapper(mapper)

#Computation of normals
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(reader.GetOutputPort())

# Set object properties
prop = actor.GetProperty()
prop.SetInterpolationToPhong()  # Set shading to Phong
prop.ShadingOn()
prop.SetDiffuse(0.8)  # 0.8
prop.SetAmbient(0.3)  # 0.3
prop.SetSpecular(1.0)  # 1.0

# Define light
light = vtk.vtkLight()
light.SetLightTypeToSceneLight()
light.SetAmbientColor(1, 1, 1)
light.SetDiffuseColor(1, 1, 1)
light.SetSpecularColor(1, 1, 1)
light.SetPosition(-100, 100, 25)
light.SetFocalPoint(0, 0, 0)
light.SetIntensity(0.8)

# Create a rendering window and renderer
ren = vtk.vtkRenderer()
# Add the light to the renderer
ren.AddLight(light)

# Assign actor to the renderer
ren.AddActor(actor)
Example #35
0
def main():

    fn0 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp"
    fn0c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp"
    fn1 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_l.vtp"
    fn1c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_l_col.vtp"
    fn2 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_r.vtp"
    fn2c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_r_col.vtp"
    fn0t = "/home/david/vtkESQuiData/Scenario/Textures/metal.jpg"
    fn3 = "/home/david/vtkESQuiData/Scenario/Tools/Probe/tip.vtp"
    fn3c = "/home/david/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp"

    #Create scenario
    scenario = vtkesqui.vtkScenario()

    # Left Tool (Probe)
    # Visualization model
    vis_stick_l = vtkesqui.vtkVisualizationModel()
    vis_stick_l.SetName("vis_stick_l")
    vis_stick_l.SetFileName(fn0)
    vis_stick_l.SetTextureFileName(fn0t)
    vis_stick_l.SetOpacity(1.0)
    vis_stick_l.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_l = vtkesqui.vtkCollisionModel()
    col_stick_l.SetName("col_stick_l_vtkbioeng")
    col_stick_l.SetFileName(fn0c)
    col_stick_l.SetOpacity(1.0)
    col_stick_l.SetColor(1.0, 1.0, 1.0)

    # First tool element (stick_l)
    stick_l = vtkesqui.vtkScenarioElement()
    stick_l.SetName("stick_l")
    stick_l.SetPosition(-3.0, 0.0, 0.0)
    stick_l.SetOrientation(0, 0, 20)
    stick_l.SetOrigin(0, 0, 6)
    stick_l.SetVisualizationModel(vis_stick_l)
    stick_l.SetCollisionModel(col_stick_l)

    # Visualization model
    vis_tip_l = vtkesqui.vtkVisualizationModel()
    vis_tip_l.SetName("vis_tip_l")
    vis_tip_l.SetFileName(fn3)
    vis_tip_l.SetTextureFileName(fn0t)
    vis_tip_l.SetOpacity(1.0)
    vis_tip_l.SetColor(1.0, 0.0, 0.0)

    # Collision model
    col_tip_l = vtkesqui.vtkCollisionModel()
    col_tip_l.SetName("col_tip_l_vtkbioeng")
    col_tip_l.SetFileName(fn3c)
    col_tip_l.SetOpacity(1.0)
    col_tip_l.SetColor(1.0, 1.0, 1.0)

    # Second tool element (tip_l)
    tip_l = vtkesqui.vtkScenarioElement()
    tip_l.SetName("tip_l")
    tip_l.SetPosition(-3.0, 0.0, 0.0)
    tip_l.SetOrientation(0, 0, 20)
    tip_l.SetOrigin(0, 0, 6)
    tip_l.SetVisualizationModel(vis_tip_l)
    tip_l.SetCollisionModel(col_tip_l)

    probe_l = vtkesqui.vtkToolProbe()
    probe_l.AddElement(stick_l)
    probe_l.AddElement(tip_l)

    # Right tool (Grasper)
    # Visualization model
    vis_stick_r = vtkesqui.vtkVisualizationModel()
    vis_stick_r.SetName("vis_stick_r")
    vis_stick_r.SetFileName(fn0)
    vis_stick_r.SetTextureFileName(fn0t)
    vis_stick_r.SetOpacity(1.0)
    vis_stick_r.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_r = vtkesqui.vtkCollisionModel()
    col_stick_r.SetName("col_stick_r_vtkbioeng")
    col_stick_r.SetFileName(fn0c)
    col_stick_r.SetOpacity(1.0)
    col_stick_r.SetColor(1.0, 1.0, 1.0)

    # First tool element (stick_r)
    stick_r = vtkesqui.vtkScenarioElement()
    stick_r.SetName("stick_r")
    stick_r.SetPosition(3.0, 0.0, 0.0)
    stick_r.SetOrientation(0, 0, -20)
    stick_r.SetOrigin(0, 0, 6)
    stick_r.SetVisualizationModel(vis_stick_r)
    stick_r.SetCollisionModel(col_stick_r)

    # Visualization model
    vis_l_lever_r = vtkesqui.vtkVisualizationModel()
    vis_l_lever_r.SetName("vis_l_lever_r")
    vis_l_lever_r.SetFileName(fn1)
    vis_l_lever_r.SetTextureFileName(fn0t)
    vis_l_lever_r.SetOpacity(1.0)
    vis_l_lever_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_l_lever_r = vtkesqui.vtkCollisionModel()
    col_l_lever_r.SetName("col_l_lever_r_vtkbioeng")
    col_l_lever_r.SetFileName(fn1c)
    col_l_lever_r.SetOpacity(1.0)
    col_l_lever_r.SetColor(1.0, 1.0, 1.0)

    # Second tool element (l_lever_r)
    l_lever_r = vtkesqui.vtkScenarioElement()
    l_lever_r.SetName("l_lever_r")
    l_lever_r.SetPosition(3.0, 0.0, 0.0)
    l_lever_r.SetOrientation(0, 0, -20)
    l_lever_r.SetOrigin(0, 0, 6)
    l_lever_r.SetVisualizationModel(vis_l_lever_r)
    l_lever_r.SetCollisionModel(col_l_lever_r)

    # Visualization model
    vis_r_lever_r = vtkesqui.vtkVisualizationModel()
    vis_r_lever_r.SetName("vis_r_lever_r")
    vis_r_lever_r.SetFileName(fn2)
    vis_r_lever_r.SetTextureFileName(fn0t)
    vis_r_lever_r.SetOpacity(1.0)
    vis_r_lever_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_r_lever_r = vtkesqui.vtkCollisionModel()
    col_r_lever_r.SetName("col_r_lever_r_vtkbioeng")
    col_r_lever_r.SetFileName(fn2c)
    col_r_lever_r.SetOpacity(1.0)
    col_r_lever_r.SetColor(1.0, 1.0, 1.0)

    # Second tool element (r_lever_r)
    r_lever_r = vtkesqui.vtkScenarioElement()
    r_lever_r.SetName("r_lever_r")
    r_lever_r.SetPosition(3.0, 0.0, 0.0)
    r_lever_r.SetOrientation(0, 0, -20)
    r_lever_r.SetOrigin(0, 0, 6)
    r_lever_r.SetVisualizationModel(vis_r_lever_r)
    r_lever_r.SetCollisionModel(col_r_lever_r)

    grasper_r = vtkesqui.vtkToolGrasper()
    grasper_r.SetStick(stick_r)
    grasper_r.SetLeftLever(l_lever_r)
    grasper_r.SetRightLever(r_lever_r)

    # Add objects to the scenario
    scenario.AddObject(probe_l)
    scenario.AddObject(grasper_r)

    #for i in range(2):
    #i = 0

    b = createBall(0)
    scenario.AddObject(b)

    # Scenario camera
    camera = vtk.vtkCamera()
    camera.SetPosition(0, 0, 6)
    camera.SetFocalPoint(0, 0, -6)
    camera.Yaw(0)
    camera.Elevation(20)
    camera.Pitch(-15)
    camera.ParallelProjectionOff()
    camera.SetViewAngle(70)
    scenario.SetCamera(camera)

    #/********** Lights  **********/
    headLight = vtk.vtkLight()
    headLight.SetLightTypeToHeadlight()
    headLight.PositionalOn()
    headLight.SetIntensity(0.8)
    headLight.SetConeAngle(20)
    scenario.AddLight(headLight)

    ambientLight = vtk.vtkLight()
    ambientLight.SetIntensity(0.8)
    ambientLight.SetLightTypeToHeadlight()
    ambientLight.PositionalOff()
    scenario.AddLight(ambientLight)

    # Force the scenario to initialize
    scenario.Update()

    # Sign up to receive TimerEvent
    iren = scenario.GetRenderWindowInteractor()
    cb = vtkTimerCallback()
    iren.AddObserver('TimerEvent', cb.execute)
    # 1ms timer
    timerId = iren.CreateRepeatingTimer(1)
    cb.scenario = scenario

    iren.Start()
Example #36
0
    def showLayer(self):
        if self.volume != Null:
            self.ren.RemoveVolume(self.volume)
        
        sliceNumber = self.sliceNumber.text()
        sliceIntArray = sliceNumber.toUInt()
        sliceInt = sliceIntArray[0]
        
        print "cool, it is done"
        fr=gzip.open(self.fname[:-3]+"voxr","rb")
        dataRed=pickle.load(fr)
        self.data_matrix_red=numpy.uint8(dataRed)
        self.data_matrix_red=self.data_matrix_red[sliceInt-1:sliceInt+1,:,:]
        with file('layerView.txt', 'w') as outfile:
            for data_slice in self.data_matrix_red:

        # The formatting string indicates that I'm writing out
        # the values in left-justified columns 7 characters in width
        # with 2 decimal places.  
                numpy.savetxt(outfile, data_slice,fmt='%-7.1f')

        # Writing out a break to indicate different slices...
                outfile.write('# New slice\n')
        
        
        self.dataImporterR = vtk.vtkImageImport()
        data_string = self.data_matrix_red.tostring()
        self.dataImporterR.CopyImportVoidPointer(data_string, len(data_string))
        self.dataImporterR.SetDataScalarTypeToUnsignedChar()
        self.dataImporterR.SetNumberOfScalarComponents(1)
        xdim,ydim,zdim=self.data_matrix_red.shape
        #self.dataImporter.SetDataExtent(0, zdim-1, 0, vtkPiecewiseFunctionb-1, 0, xdim-1)
        self.dataImporterR.SetDataExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        #self.dataImporter.SetWholeExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        self.dataImporterR.SetWholeExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        
        fg=gzip.open(self.fname[:-3]+"voxg","rb")
        dataGreen=pickle.load(fg)
        self.data_matrix_green=numpy.uint8(dataGreen)
        self.data_matrix_green = self.data_matrix_green[sliceInt-1:sliceInt+1,:,:] 
        self.dataImporterG = vtk.vtkImageImport()
        data_string = self.data_matrix_green.tostring()
        self.dataImporterG.CopyImportVoidPointer(data_string, len(data_string))
        self.dataImporterG.SetDataScalarTypeToUnsignedChar()
        self.dataImporterG.SetNumberOfScalarComponents(1)
        xdim,ydim,zdim=self.data_matrix_green.shape
        #self.dataImporter.SetDataExtent(0, zdim-1, 0, vtkPiecewiseFunctionb-1, 0, xdim-1)
        self.dataImporterG.SetDataExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        #self.dataImporter.SetWholeExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        self.dataImporterG.SetWholeExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        
        
        fb=gzip.open(self.fname[:-3]+"voxb","rb")
        dataBlue=pickle.load(fb)
        self.data_matrix_blue=numpy.uint8(dataBlue)
        self.data_matrix_blue = self.data_matrix_blue[sliceInt-1:sliceInt+1,:,:] 
        self.dataImporterB = vtk.vtkImageImport()
        data_string = self.data_matrix_blue.tostring()
        self.dataImporterB.CopyImportVoidPointer(data_string, len(data_string))
        self.dataImporterB.SetDataScalarTypeToUnsignedChar()
        self.dataImporterB.SetNumberOfScalarComponents(1)
        xdim,ydim,zdim=self.data_matrix_blue.shape
        #self.dataImporter.SetDataExtent(0, zdim-1, 0, vtkPiecewiseFunctionb-1, 0, xdim-1)
        self.dataImporterB.SetDataExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        #self.dataImporter.SetWholeExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)
        self.dataImporterB.SetWholeExtent(0, zdim-1, 0, ydim-1, 0, xdim-1)

        
        self.append = vtk.vtkImageAppendComponents() 
        self.append.SetInputConnection(self.dataImporterR.GetOutputPort()) 
        self.append.AddInputConnection(self.dataImporterG.GetOutputPort()) 
        self.append.AddInputConnection(self.dataImporterB.GetOutputPort()) 
        self.append.Update() 
        
        volumeMapper = vtk.vtkSmartVolumeMapper()
        volumeMapper.SetInputConnection(self.append.GetOutputPort())
        
        volumeProperty = vtk.vtkVolumeProperty() 
        volumeProperty.ShadeOff()
        volumeProperty.SetInterpolationTypeToLinear()
        volumeProperty.IndependentComponentsOn()
        
        opacityTF1 = vtk.vtkPiecewiseFunction() 
        opacityTF1.AddPoint(   0.0,  0.0 ) 
        opacityTF1.AddPoint(   1.0,  0.33)
        opacityTF1.AddPoint(   128.0, 0.33) 
        opacityTF1.AddPoint(   255.0,  0.33 ) 
        volumeProperty.SetScalarOpacity(0,opacityTF1) 
        
        colourTF1 = vtk.vtkColorTransferFunction() 
        colourTF1.AddRGBPoint(   0.0,  0.0, 0.0, 0.0 ) 
        colourTF1.AddRGBPoint(   1.0,  0.0, 0.0, 0.1 )
        colourTF1.AddRGBPoint(   128.0, 0.0, 0.0, 0.5 ) 
        colourTF1.AddRGBPoint(   255.0, 0.0, 0.0, 1.0 ) 
        volumeProperty.SetColor(0,colourTF1)
        
        opacityTF2 = vtk.vtkPiecewiseFunction() 
        opacityTF2.AddPoint(   0.0,  0.0 ) 
        opacityTF2.AddPoint(   1.0,  0.33 ) 
        opacityTF2.AddPoint(   128.0, 0.33)
        opacityTF2.AddPoint(   255.0,  0.33 ) 
        volumeProperty.SetScalarOpacity(1,opacityTF2) 
        
        colourTF2 = vtk.vtkColorTransferFunction() 
        colourTF2.AddRGBPoint(   0.0,  0.0, 0.0, 0.0 ) 
        colourTF2.AddRGBPoint(   1.0,  0.0, 0.1, 0.0 )
        colourTF2.AddRGBPoint(   128.0, 0.0, 0.5, 0.0 ) 
        colourTF2.AddRGBPoint(   255.0, 0.0, 1.0, 0.0 ) 
        volumeProperty.SetColor(1,colourTF2)
        
        opacityTF3 = vtk.vtkPiecewiseFunction() 
        opacityTF3.AddPoint(   0.0,  0.0 ) 
        opacityTF3.AddPoint(   1.0,  0.33 ) 
        opacityTF3.AddPoint(   128.0, 0.33)
        opacityTF3.AddPoint(   255.0,  0.33 ) 
        volumeProperty.SetScalarOpacity(2,opacityTF3) 
        
        colourTF3 = vtk.vtkColorTransferFunction() 
        colourTF3.AddRGBPoint(   0.0,  0.0, 0.0, 0.0 ) 
        colourTF3.AddRGBPoint(   1.0,  0.1, 0.0, 0.0 )
        colourTF3.AddRGBPoint(   128.0, 0.5, 0.0, 0.0 ) 
        colourTF3.AddRGBPoint(   255.0, 1.0, 0.0, 0.0 ) 
        volumeProperty.SetColor(2,colourTF3)
   
        self.volume.SetMapper(volumeMapper)
        self.volume.SetProperty(volumeProperty)
                    
        #self.ren.RemoveActor(self.actor)
                    
        self.ren.AddVolume(self.volume)
        self.ren.SetBackground(0, 0, 0)
        # A simple function to be called when the user decides to quit the application.
        def exitCheck(obj, event):
            if obj.GetEventPending() != 0:
                obj.SetAbortRender(1)
                                     
            # Tell the application to use the function as an exit check.
        light = vtk.vtkLight()
        #light.SetColor(1, 1, 1)
        light.SwitchOff()
        self.ren.AddLight(light)
        
        renderWin = self.vtkWidget.GetRenderWindow()
        renderWin.AddObserver("AbortCheckEvent", exitCheck)
                    
        self.iren.Initialize()
        self.iren.Start()
    def FringeSimulator(self, file_name, file_output):
        
 
        reader = vtk.vtkPLYReader()
        reader.SetFileName(file_name)
        reader.Update()

        smooth = vtk.vtkWindowedSincPolyDataFilter()   
        smooth.SetInput(reader.GetOutput())
        smooth.Update()
  
        normals = vtk.vtkPolyDataNormals()
        normals.SetInput(smooth.GetOutput())
        normals.SetComputePointNormals(1)
        normals.SetComputeCellNormals(1)
        normals.Update()

        mapper=vtk.vtkDataSetMapper()
        mapper.SetInput(smooth.GetOutput())
        mapper.SetScalarVisibility(1)

        actor = vtk.vtkActor()
        actor.GetProperty().SetInterpolationToFlat()
        actor.SetMapper(mapper)

        self.renderer.AddActor(actor)

        key_properties = vtk.vtkInformation()
        key_properties.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
        key_properties.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.

        actor.SetPropertyKeys(key_properties)
        actor.SetVisibility(1)

        self.renderer.ResetCamera()
        cam = self.renderer.GetActiveCamera()

        cam_pos = cam.GetPosition()
        cam_f =  cam.GetFocalPoint()

        vcam_pos = numpy.array([float(cam_pos[0]), float(cam_pos[1]), float(cam_pos[2])])
        vcam_f = numpy.array([float(cam_f[0]),float(cam_f[1]),float(cam_f[2])])

        v = vcam_f - vcam_pos 
        d = numpy.linalg.norm(v)
        vn = v/d

        ap = vtk.vtkAppendPolyData()
        dist_fringes = cam_pos - vn * -250

        for x in xrange(-220, 220):
            cube_source= vtk.vtkCubeSource()
            cube_source.SetXLength(0.20)
            cube_source.SetYLength(80)
            cube_source.SetZLength(0.1)

            xfm = vtk.vtkTransform()
            xfm.Translate(float(x) * 0.40, 0, 0) 

            xfmPd = vtk.vtkTransformPolyDataFilter()
            xfmPd.SetInput(cube_source.GetOutput())
            xfmPd.SetTransform(xfm)

            ap.AddInput(xfmPd.GetOutput())

        ap.Update()


        xfm = vtk.vtkTransform()
        xfm.Translate(200, dist_fringes[1], dist_fringes[2])

        xfmPd = vtk.vtkTransformPolyDataFilter()
        xfmPd.SetInput(ap.GetOutput())
        xfmPd.SetTransform(xfm)

        cube_mapper=vtk.vtkPolyDataMapper()
        cube_mapper.SetInput(xfmPd.GetOutput())


        fringes_actor = vtk.vtkActor()
        fringes_actor.SetMapper(cube_mapper)
        fringes_actor.GetProperty().SetColor(1,0,0)

        fringesKeyProperties=vtk.vtkInformation()
        fringesKeyProperties.Set(vtk.vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
        fringesKeyProperties.Set(vtk.vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.
        fringes_actor.SetPropertyKeys(fringesKeyProperties)

        self.renderer.AddActor(fringes_actor)
        
        self.renderer.LightFollowCameraOff()
        self.renderer.AutomaticLightCreationOff()
        self.renderer.RemoveAllLights()
        self.renderer.UpdateLights()

        l = vtk.vtkLight()
        l.SetLightTypeToSceneLight()

        dist_light = cam_pos - vn * 6

        l.SetFocalPoint(vcam_f[0], vcam_f[1], vcam_f[2])
        l.SetPosition(220, dist_light[1], dist_light[2])
        l.PositionalOn()
        self.renderer.AddLight(l)
    
        self.renderer.Render()

        wf = vtk.vtkWindowToImageFilter()
        wf.SetInput(self.ren_win)
        wf.Update()

        png = vtk.vtkPNGWriter()
        png.SetFileName(file_output + ".png")
        png.SetInput(wf.GetOutput())
        png.Write()
Example #38
0
ren.AddActor(actor)
ren.AddActor(titleActor)
ren.AddActor(outlineActor)
ren.AddActor(axes)

### need to make a camera object in pyvisi!!!
ren.ResetCamera()
cam = ren.GetActiveCamera()
cam.Azimuth(0)
cam.Elevation(-90)
cam.SetFocalPoint(centre)
ren.SetActiveCamera(cam)
ren.ResetCameraClippingRange()

# play around with lighting
light = vtk.vtkLight()
light.SetFocalPoint(centre)
light.SetPosition(centre[0]-bounds[1],
	centre[1]-bounds[3],
	centre[2]+bounds[5])
ren.AddLight(light)

light2 = vtk.vtkLight()
light2.SetFocalPoint(centre)
light2.SetPosition(centre[0]+bounds[1],
	 centre[1]+bounds[3],
	 centre[2]-bounds[5])
ren.AddLight(light2)

# set up stuff for interactive viewing
iren = vtk.vtkRenderWindowInteractor()
Example #39
0
def main():

  fn0 = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp";
  fn0c = "/home/david/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp";
  fn0t = "/home/david/vtkESQuiData/Scenario/Textures/metal.jpg";
  fn3 = "/home/david/vtkESQuiData/Scenario/Tools/Probe/tip.vtp";
  fn3c = "/home/david/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp";
  fn4 = "/home/david/vtkESQuiData/Scenario/Organs/ball.vtp";
  fn4c = "/home/david/vtkESQuiData/Scenario/Organs/ball_col_bb.vtp";
  fn4tl = "/home/david/vtkESQuiData/Scenario/Textures/leftball.jpg";
  fn5 = "/home/david/vtkESQuiData/Scenario/Organs/cavity.vtp";
  fn5t = "/home/david/vtkESQuiData/Scenario/Textures/intestine2.jpg";

  #Create scenario
  scenario = vtkesqui.vtkScenario()
  scenario.SetName("vtkESQui - Laparoscopy (Precission & Speed)")

  # Left Tool (Probe)
  # Visualization model
  vis_stick_l = vtkesqui.vtkVisualizationModel()
  vis_stick_l.SetName("vis_stick_l")
  vis_stick_l.SetFileName(fn0)
  vis_stick_l.SetTextureFileName(fn0t)
  vis_stick_l.SetOpacity(1.0)
  vis_stick_l.SetColor(1.0, 1.0, 1.0)
  
  # Collision model
  col_stick_l = vtkesqui.vtkCollisionModel()
  col_stick_l.SetName("col_stick_l_vtkbioeng")
  col_stick_l.SetFileName(fn0c)
  col_stick_l.SetVisibility(0.0)
  
  # First tool element (stick_l)
  stick_l = vtkesqui.vtkScenarioElement()
  stick_l.SetName("stick_l")
  stick_l.SetPosition(-3.0, 0.0, 0.0)
  stick_l.SetOrientation(0, 0, 15)
  stick_l.SetOrigin(0,0,5)
  stick_l.SetVisualizationModel(vis_stick_l)
  stick_l.SetCollisionModel(col_stick_l)
  
  # Visualization model
  vis_tip_l = vtkesqui.vtkVisualizationModel()
  vis_tip_l.SetName("vis_tip_l")
  vis_tip_l.SetFileName(fn3)
  vis_tip_l.SetTextureFileName(fn0t)
  vis_tip_l.SetOpacity(1.0)
  
  # Collision model
  col_tip_l = vtkesqui.vtkCollisionModel()
  col_tip_l.SetName("col_tip_l_vtkbioeng")
  col_tip_l.SetFileName(fn3c)
  col_tip_l.SetVisibility(0.0)
  
  # Second tool element (tip_l)
  tip_l = vtkesqui.vtkScenarioElement()
  tip_l.SetName("tip_l")
  tip_l.SetPosition(-3.0, 0.0, 0.0)
  tip_l.SetOrientation(0, 0, 15)
  tip_l.SetOrigin(0,0,5)
  tip_l.SetVisualizationModel(vis_tip_l)
  tip_l.SetCollisionModel(col_tip_l)
  
  probe_l = vtkesqui.vtkToolProbe()
  probe_l.AddElement(stick_l)
  probe_l.AddElement(tip_l)
  scenario.AddObject(probe_l)
  
  # Right tool (Grasper)
   # Visualization model
  vis_stick_r = vtkesqui.vtkVisualizationModel()
  vis_stick_r.SetName("vis_stick_r")
  vis_stick_r.SetFileName(fn0)
  vis_stick_r.SetTextureFileName(fn0t)
  vis_stick_r.SetOpacity(1.0)
  vis_stick_r.SetColor(1.0, 1.0, 1.0)
  
  # Collision model
  col_stick_r = vtkesqui.vtkCollisionModel()
  col_stick_r.SetName("col_stick_r_vtkbioeng")
  col_stick_r.SetFileName(fn0c)
  col_stick_r.SetVisibility(0.0)
  
  # First tool element (stick_r)
  stick_r = vtkesqui.vtkScenarioElement()
  stick_r.SetName("stick_r")
  stick_r.SetPosition(3.0, 0.0, 0.0)
  stick_r.SetOrientation(0, 0, 15)
  stick_r.SetOrigin(0,0,5)
  stick_r.SetVisualizationModel(vis_stick_r)
  stick_r.SetCollisionModel(col_stick_r)
  
  # Visualization model
  vis_tip_r = vtkesqui.vtkVisualizationModel()
  vis_tip_r.SetName("vis_tip_r")
  vis_tip_r.SetFileName(fn3)
  vis_tip_r.SetTextureFileName(fn0t)
  vis_tip_r.SetOpacity(1.0)
  
  # Collision model
  col_tip_r = vtkesqui.vtkCollisionModel()
  col_tip_r.SetName("col_tip_r_vtkbioeng")
  col_tip_r.SetFileName(fn3c)
  col_tip_r.SetVisibility(0.0)
  
  # Second tool element (tip_r)
  tip_r = vtkesqui.vtkScenarioElement()
  tip_r.SetName("tip_r")
  tip_r.SetPosition(3.0, 0.0, 0.0)
  tip_r.SetOrientation(0, 0, 15)
  tip_r.SetOrigin(0,0,5)
  tip_r.SetVisualizationModel(vis_tip_r)
  tip_r.SetCollisionModel(col_tip_r)
  
  probe_r = vtkesqui.vtkToolProbe()
  probe_r.AddElement(stick_r)
  probe_r.AddElement(tip_r)
  scenario.AddObject(probe_r)
  
  # Add an Organ (Cavity)
  # Visualization model
  vis_cavity = vtkesqui.vtkVisualizationModel()
  vis_cavity.SetName("vis_cavity")
  vis_cavity.SetFileName(fn5)
  vis_cavity.SetTextureFileName(fn5t)
  vis_cavity.SetOpacity(1.0)
  
  # Organ element (cavity)
  e_cavity = vtkesqui.vtkScenarioElement()
  e_cavity.SetName("e_cavity")
  e_cavity.SetPosition(0.0, 0.0, -1.0)
  e_cavity.SetOrientation(-45, 0, 0)
  e_cavity.SetVisualizationModel(vis_cavity)
  
  cavity = vtkesqui.vtkOrgan()
  cavity.SetName("cavity")
  cavity.AddElement(e_cavity)
  scenario.AddObject(cavity)
  
   # Add a ball
  # Visualization model
  vis_ball = vtkesqui.vtkVisualizationModel()
  vis_ball.SetName("vis_ball")
  vis_ball.SetFileName(fn4)
  vis_ball.SetColor(1.0,1.0,0.2)
  vis_ball.SetOpacity(1.0)
  
  # Collision model
  col_ball = vtkesqui.vtkCollisionModel()
  col_ball.SetName("col_ball_vtkbioeng")
  col_ball.SetFileName(fn4c)
  col_ball.SetVisibility(0.0)
  col_ball.SetOpacity(0.0)

  # Organ element (ball)
  e_ball = vtkesqui.vtkScenarioElement()
  e_ball.SetName("e_ball")
  e_ball.SetVisualizationModel(vis_ball)
  e_ball.SetCollisionModel(col_ball)
  
  ball = vtkesqui.vtkOrgan()
  ball.SetName("ball")
  ball.AddElement(e_ball)
 
  scenario.AddObject(ball)

  # Scenario camera
  camera = vtk.vtkCamera()
  camera.SetPosition(0, 0, 6)
  camera.SetFocalPoint(0, 0, -6)
  camera.Yaw(0)
  camera.Elevation(20)
  camera.Pitch(-15)
  camera.ParallelProjectionOff()
  camera.SetViewAngle(70)
  camera.Dolly(1.2)
  scenario.SetCamera(camera)
  
  #/********** Lights  **********/
  headLight = vtk.vtkLight()
  headLight.SetLightTypeToHeadlight()
  headLight.PositionalOn()
  headLight.SetIntensity(0.7)
  headLight.SetConeAngle(90)
  scenario.AddLight(headLight)
  
  ambientLight = vtk.vtkLight()
  ambientLight.SetLightTypeToSceneLight()
  ambientLight.PositionalOff()
  ambientLight.SetPosition(0,1,1)
  ambientLight.SetIntensity(0.5)
  scenario.AddLight(ambientLight)

  simulation = vtkesqui.vtkSimulation()
  simulation.SetScenario(scenario)
  simulation.SetRenderTimerRate(30)
  simulation.SetSimulationTimerRate(1)
  simulation.SetInteractionTimerRate(1)
  simulation.InteractionOn()
  simulation.CollisionOn()
  simulation.Initialize()
  
  #Wait for initialization to set collision mode
  simulation.SetCollisionModeToSimple()
  
  # Sign up to receive TimerEvent
  iren = scenario.GetRenderWindowInteractor()
  cb = vtkTimerCallback()
  iren.AddObserver('TimerEvent', cb.execute)
  # 100ms timer
  timerId = iren.CreateRepeatingTimer(100);
  cb.simulation = simulation
  cb.target = ball
  
  simulation.Run()
Example #40
0
quadric = vtk.vtkQuadric()
quadric.SetCoefficients(.5,1,.2,0,.1,0,0,.2,0,0)

sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(50,50,50)
sample.SetImplicitFunction(quadric)

contours = vtk.vtkContourFilter()
contours.SetInputConnection(sample.GetOutputPort())
contours.GenerateValues(6, 0.0, 2)

normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(contours.GetOutputPort())
normals.SetFeatureAngle(270.0)

contMapper = vtk.vtkPolyDataMapper()
contMapper.SetInputConnection(normals.GetOutputPort())
contMapper.SetScalarRange(0.0, 1.2)
contMapper.SetScalarVisibility(1)
actor = vtk.vtkActor()
actor.SetMapper(contMapper)

vtkAttachProp(actor, vtkNode)

l = vtk.vtkLight()
vtkAddLight(l)
#l.PositionalOn()
l.SetPosition(0, 4, 0)
l.SetColor(1,1,1)
Example #41
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
lgt = vtk.vtkLight()
# create pipeline
#
locator = vtk.vtkMergePoints()
locator.SetDivisions(32,32,46)
locator.SetNumberOfPointsPerBucket(2)
locator.AutomaticOff()
v16 = vtk.vtkVolume16Reader()
v16.SetDataDimensions(64,64)
v16.GetOutput().SetOrigin(0.0,0.0,0.0)
v16.SetDataByteOrderToLittleEndian()
v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter")
v16.SetImageRange(1,93)
v16.SetDataSpacing(3.2,3.2,1.5)
iso = vtk.vtkMarchingCubes()
iso.SetInputConnection(v16.GetOutputPort())
iso.SetValue(0,1150)
iso.ComputeGradientsOn()
Example #42
0
    def testCells(self):

        # Demonstrates all cell types
        #
        # NOTE: the use of NewInstance/DeepCopy is included to increase
        # regression coverage.  It is not required in most applications.

        ren = vtk.vtkRenderer()
        # turn off all cullers
        ren.GetCullers().RemoveAllItems()

        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        renWin.SetSize(300, 150)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)

        # create a scene with one of each cell type

        # Voxel

        voxelPoints = vtk.vtkPoints()
        voxelPoints.SetNumberOfPoints(8)
        voxelPoints.InsertPoint(0, 0, 0, 0)
        voxelPoints.InsertPoint(1, 1, 0, 0)
        voxelPoints.InsertPoint(2, 0, 1, 0)
        voxelPoints.InsertPoint(3, 1, 1, 0)
        voxelPoints.InsertPoint(4, 0, 0, 1)
        voxelPoints.InsertPoint(5, 1, 0, 1)
        voxelPoints.InsertPoint(6, 0, 1, 1)
        voxelPoints.InsertPoint(7, 1, 1, 1)

        aVoxel = vtk.vtkVoxel()
        aVoxel.GetPointIds().SetId(0, 0)
        aVoxel.GetPointIds().SetId(1, 1)
        aVoxel.GetPointIds().SetId(2, 2)
        aVoxel.GetPointIds().SetId(3, 3)
        aVoxel.GetPointIds().SetId(4, 4)
        aVoxel.GetPointIds().SetId(5, 5)
        aVoxel.GetPointIds().SetId(6, 6)
        aVoxel.GetPointIds().SetId(7, 7)

        bVoxel = aVoxel.NewInstance()
        bVoxel.DeepCopy(aVoxel)

        aVoxelGrid = vtk.vtkUnstructuredGrid()
        aVoxelGrid.Allocate(1, 1)
        aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds())
        aVoxelGrid.SetPoints(voxelPoints)

        aVoxelMapper = vtk.vtkDataSetMapper()
        aVoxelMapper.SetInputData(aVoxelGrid)

        aVoxelActor = vtk.vtkActor()
        aVoxelActor.SetMapper(aVoxelMapper)
        aVoxelActor.GetProperty().BackfaceCullingOn()

        # Hexahedron

        hexahedronPoints = vtk.vtkPoints()
        hexahedronPoints.SetNumberOfPoints(8)
        hexahedronPoints.InsertPoint(0, 0, 0, 0)
        hexahedronPoints.InsertPoint(1, 1, 0, 0)
        hexahedronPoints.InsertPoint(2, 1, 1, 0)
        hexahedronPoints.InsertPoint(3, 0, 1, 0)
        hexahedronPoints.InsertPoint(4, 0, 0, 1)
        hexahedronPoints.InsertPoint(5, 1, 0, 1)
        hexahedronPoints.InsertPoint(6, 1, 1, 1)
        hexahedronPoints.InsertPoint(7, 0, 1, 1)

        aHexahedron = vtk.vtkHexahedron()
        aHexahedron.GetPointIds().SetId(0, 0)
        aHexahedron.GetPointIds().SetId(1, 1)
        aHexahedron.GetPointIds().SetId(2, 2)
        aHexahedron.GetPointIds().SetId(3, 3)
        aHexahedron.GetPointIds().SetId(4, 4)
        aHexahedron.GetPointIds().SetId(5, 5)
        aHexahedron.GetPointIds().SetId(6, 6)
        aHexahedron.GetPointIds().SetId(7, 7)

        bHexahedron = aHexahedron.NewInstance()
        bHexahedron.DeepCopy(aHexahedron)

        aHexahedronGrid = vtk.vtkUnstructuredGrid()
        aHexahedronGrid.Allocate(1, 1)
        aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds())
        aHexahedronGrid.SetPoints(hexahedronPoints)

        aHexahedronMapper = vtk.vtkDataSetMapper()
        aHexahedronMapper.SetInputData(aHexahedronGrid)

        aHexahedronActor = vtk.vtkActor()
        aHexahedronActor.SetMapper(aHexahedronMapper)
        aHexahedronActor.AddPosition(2, 0, 0)
        aHexahedronActor.GetProperty().BackfaceCullingOn()

        # Tetra

        tetraPoints = vtk.vtkPoints()
        tetraPoints.SetNumberOfPoints(4)
        tetraPoints.InsertPoint(0, 0, 0, 0)
        tetraPoints.InsertPoint(1, 1, 0, 0)
        tetraPoints.InsertPoint(2, 0.5, 1, 0)
        tetraPoints.InsertPoint(3, 0.5, 0.5, 1)

        aTetra = vtk.vtkTetra()
        aTetra.GetPointIds().SetId(0, 0)
        aTetra.GetPointIds().SetId(1, 1)
        aTetra.GetPointIds().SetId(2, 2)
        aTetra.GetPointIds().SetId(3, 3)

        bTetra = aTetra.NewInstance()
        bTetra.DeepCopy(aTetra)

        aTetraGrid = vtk.vtkUnstructuredGrid()
        aTetraGrid.Allocate(1, 1)
        aTetraGrid.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds())
        aTetraGrid.SetPoints(tetraPoints)

        aTetraCopy = vtk.vtkUnstructuredGrid()
        aTetraCopy.ShallowCopy(aTetraGrid)

        aTetraMapper = vtk.vtkDataSetMapper()
        aTetraMapper.SetInputData(aTetraCopy)

        aTetraActor = vtk.vtkActor()
        aTetraActor.SetMapper(aTetraMapper)
        aTetraActor.AddPosition(4, 0, 0)
        aTetraActor.GetProperty().BackfaceCullingOn()

        # Wedge

        wedgePoints = vtk.vtkPoints()
        wedgePoints.SetNumberOfPoints(6)
        wedgePoints.InsertPoint(0, 0, 1, 0)
        wedgePoints.InsertPoint(1, 0, 0, 0)
        wedgePoints.InsertPoint(2, 0, 0.5, 0.5)
        wedgePoints.InsertPoint(3, 1, 1, 0)
        wedgePoints.InsertPoint(4, 1, 0, 0)
        wedgePoints.InsertPoint(5, 1, 0.5, 0.5)

        aWedge = vtk.vtkWedge()
        aWedge.GetPointIds().SetId(0, 0)
        aWedge.GetPointIds().SetId(1, 1)
        aWedge.GetPointIds().SetId(2, 2)
        aWedge.GetPointIds().SetId(3, 3)
        aWedge.GetPointIds().SetId(4, 4)
        aWedge.GetPointIds().SetId(5, 5)

        bWedge = aWedge.NewInstance()
        bWedge.DeepCopy(aWedge)

        aWedgeGrid = vtk.vtkUnstructuredGrid()
        aWedgeGrid.Allocate(1, 1)
        aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds())
        aWedgeGrid.SetPoints(wedgePoints)

        aWedgeCopy = vtk.vtkUnstructuredGrid()
        aWedgeCopy.DeepCopy(aWedgeGrid)

        aWedgeMapper = vtk.vtkDataSetMapper()
        aWedgeMapper.SetInputData(aWedgeCopy)

        aWedgeActor = vtk.vtkActor()
        aWedgeActor.SetMapper(aWedgeMapper)
        aWedgeActor.AddPosition(6, 0, 0)
        aWedgeActor.GetProperty().BackfaceCullingOn()

        # Pyramid

        pyramidPoints = vtk.vtkPoints()
        pyramidPoints.SetNumberOfPoints(5)
        pyramidPoints.InsertPoint(0, 0, 0, 0)
        pyramidPoints.InsertPoint(1, 1, 0, 0)
        pyramidPoints.InsertPoint(2, 1, 1, 0)
        pyramidPoints.InsertPoint(3, 0, 1, 0)
        pyramidPoints.InsertPoint(4, 0.5, 0.5, 1)

        aPyramid = vtk.vtkPyramid()
        aPyramid.GetPointIds().SetId(0, 0)
        aPyramid.GetPointIds().SetId(1, 1)
        aPyramid.GetPointIds().SetId(2, 2)
        aPyramid.GetPointIds().SetId(3, 3)
        aPyramid.GetPointIds().SetId(4, 4)

        bPyramid = aPyramid.NewInstance()
        bPyramid.DeepCopy(aPyramid)

        aPyramidGrid = vtk.vtkUnstructuredGrid()
        aPyramidGrid.Allocate(1, 1)
        aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds())
        aPyramidGrid.SetPoints(pyramidPoints)

        aPyramidMapper = vtk.vtkDataSetMapper()
        aPyramidMapper.SetInputData(aPyramidGrid)

        aPyramidActor = vtk.vtkActor()
        aPyramidActor.SetMapper(aPyramidMapper)
        aPyramidActor.AddPosition(8, 0, 0)
        aPyramidActor.GetProperty().BackfaceCullingOn()

        # Pixel

        pixelPoints = vtk.vtkPoints()
        pixelPoints.SetNumberOfPoints(4)
        pixelPoints.InsertPoint(0, 0, 0, 0)
        pixelPoints.InsertPoint(1, 1, 0, 0)
        pixelPoints.InsertPoint(2, 0, 1, 0)
        pixelPoints.InsertPoint(3, 1, 1, 0)

        aPixel = vtk.vtkPixel()
        aPixel.GetPointIds().SetId(0, 0)
        aPixel.GetPointIds().SetId(1, 1)
        aPixel.GetPointIds().SetId(2, 2)
        aPixel.GetPointIds().SetId(3, 3)

        bPixel = aPixel.NewInstance()
        bPixel.DeepCopy(aPixel)

        aPixelGrid = vtk.vtkUnstructuredGrid()
        aPixelGrid.Allocate(1, 1)
        aPixelGrid.InsertNextCell(aPixel.GetCellType(), aPixel.GetPointIds())
        aPixelGrid.SetPoints(pixelPoints)

        aPixelMapper = vtk.vtkDataSetMapper()
        aPixelMapper.SetInputData(aPixelGrid)

        aPixelActor = vtk.vtkActor()
        aPixelActor.SetMapper(aPixelMapper)
        aPixelActor.AddPosition(0, 0, 2)
        aPixelActor.GetProperty().BackfaceCullingOn()

        # Quad

        quadPoints = vtk.vtkPoints()
        quadPoints.SetNumberOfPoints(4)
        quadPoints.InsertPoint(0, 0, 0, 0)
        quadPoints.InsertPoint(1, 1, 0, 0)
        quadPoints.InsertPoint(2, 1, 1, 0)
        quadPoints.InsertPoint(3, 0, 1, 0)

        aQuad = vtk.vtkQuad()
        aQuad.GetPointIds().SetId(0, 0)
        aQuad.GetPointIds().SetId(1, 1)
        aQuad.GetPointIds().SetId(2, 2)
        aQuad.GetPointIds().SetId(3, 3)

        bQuad = aQuad.NewInstance()
        bQuad.DeepCopy(aQuad)

        aQuadGrid = vtk.vtkUnstructuredGrid()
        aQuadGrid.Allocate(1, 1)
        aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds())
        aQuadGrid.SetPoints(quadPoints)

        aQuadMapper = vtk.vtkDataSetMapper()
        aQuadMapper.SetInputData(aQuadGrid)

        aQuadActor = vtk.vtkActor()
        aQuadActor.SetMapper(aQuadMapper)
        aQuadActor.AddPosition(2, 0, 2)
        aQuadActor.GetProperty().BackfaceCullingOn()

        # Triangle

        trianglePoints = vtk.vtkPoints()
        trianglePoints.SetNumberOfPoints(3)
        trianglePoints.InsertPoint(0, 0, 0, 0)
        trianglePoints.InsertPoint(1, 1, 0, 0)
        trianglePoints.InsertPoint(2, 0.5, 0.5, 0)

        triangleTCoords = vtk.vtkFloatArray()
        triangleTCoords.SetNumberOfComponents(2)
        triangleTCoords.SetNumberOfTuples(3)
        triangleTCoords.InsertTuple2(0, 1, 1)
        triangleTCoords.InsertTuple2(1, 2, 2)
        triangleTCoords.InsertTuple2(2, 3, 3)

        aTriangle = vtk.vtkTriangle()
        aTriangle.GetPointIds().SetId(0, 0)
        aTriangle.GetPointIds().SetId(1, 1)
        aTriangle.GetPointIds().SetId(2, 2)

        bTriangle = aTriangle.NewInstance()
        bTriangle.DeepCopy(aTriangle)

        aTriangleGrid = vtk.vtkUnstructuredGrid()
        aTriangleGrid.Allocate(1, 1)
        aTriangleGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds())
        aTriangleGrid.SetPoints(trianglePoints)
        aTriangleGrid.GetPointData().SetTCoords(triangleTCoords)

        aTriangleMapper = vtk.vtkDataSetMapper()
        aTriangleMapper.SetInputData(aTriangleGrid)

        aTriangleActor = vtk.vtkActor()
        aTriangleActor.SetMapper(aTriangleMapper)
        aTriangleActor.AddPosition(4, 0, 2)
        aTriangleActor.GetProperty().BackfaceCullingOn()

        # Polygon

        polygonPoints = vtk.vtkPoints()
        polygonPoints.SetNumberOfPoints(4)
        polygonPoints.InsertPoint(0, 0, 0, 0)
        polygonPoints.InsertPoint(1, 1, 0, 0)
        polygonPoints.InsertPoint(2, 1, 1, 0)
        polygonPoints.InsertPoint(3, 0, 1, 0)

        aPolygon = vtk.vtkPolygon()
        aPolygon.GetPointIds().SetNumberOfIds(4)
        aPolygon.GetPointIds().SetId(0, 0)
        aPolygon.GetPointIds().SetId(1, 1)
        aPolygon.GetPointIds().SetId(2, 2)
        aPolygon.GetPointIds().SetId(3, 3)

        bPolygon = aPolygon.NewInstance()
        bPolygon.DeepCopy(aPolygon)

        aPolygonGrid = vtk.vtkUnstructuredGrid()
        aPolygonGrid.Allocate(1, 1)
        aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds())
        aPolygonGrid.SetPoints(polygonPoints)

        aPolygonMapper = vtk.vtkDataSetMapper()
        aPolygonMapper.SetInputData(aPolygonGrid)

        aPolygonActor = vtk.vtkActor()
        aPolygonActor.SetMapper(aPolygonMapper)
        aPolygonActor.AddPosition(6, 0, 2)
        aPolygonActor.GetProperty().BackfaceCullingOn()

        # Triangle Strip

        triangleStripPoints = vtk.vtkPoints()
        triangleStripPoints.SetNumberOfPoints(5)
        triangleStripPoints.InsertPoint(0, 0, 1, 0)
        triangleStripPoints.InsertPoint(1, 0, 0, 0)
        triangleStripPoints.InsertPoint(2, 1, 1, 0)
        triangleStripPoints.InsertPoint(3, 1, 0, 0)
        triangleStripPoints.InsertPoint(4, 2, 1, 0)

        triangleStripTCoords = vtk.vtkFloatArray()
        triangleStripTCoords.SetNumberOfComponents(2)
        triangleStripTCoords.SetNumberOfTuples(3)
        triangleStripTCoords.InsertTuple2(0, 1, 1)
        triangleStripTCoords.InsertTuple2(1, 2, 2)
        triangleStripTCoords.InsertTuple2(2, 3, 3)
        triangleStripTCoords.InsertTuple2(3, 4, 4)
        triangleStripTCoords.InsertTuple2(4, 5, 5)

        aTriangleStrip = vtk.vtkTriangleStrip()
        aTriangleStrip.GetPointIds().SetNumberOfIds(5)
        aTriangleStrip.GetPointIds().SetId(0, 0)
        aTriangleStrip.GetPointIds().SetId(1, 1)
        aTriangleStrip.GetPointIds().SetId(2, 2)
        aTriangleStrip.GetPointIds().SetId(3, 3)
        aTriangleStrip.GetPointIds().SetId(4, 4)

        bTriangleStrip = aTriangleStrip.NewInstance()
        bTriangleStrip.DeepCopy(aTriangleStrip)

        aTriangleStripGrid = vtk.vtkUnstructuredGrid()
        aTriangleStripGrid.Allocate(1, 1)
        aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds())
        aTriangleStripGrid.SetPoints(triangleStripPoints)
        aTriangleStripGrid.GetPointData().SetTCoords(triangleStripTCoords)

        aTriangleStripMapper = vtk.vtkDataSetMapper()
        aTriangleStripMapper.SetInputData(aTriangleStripGrid)

        aTriangleStripActor = vtk.vtkActor()
        aTriangleStripActor.SetMapper(aTriangleStripMapper)
        aTriangleStripActor.AddPosition(8, 0, 2)
        aTriangleStripActor.GetProperty().BackfaceCullingOn()

        # Line

        linePoints = vtk.vtkPoints()
        linePoints.SetNumberOfPoints(2)
        linePoints.InsertPoint(0, 0, 0, 0)
        linePoints.InsertPoint(1, 1, 1, 0)

        aLine = vtk.vtkLine()
        aLine.GetPointIds().SetId(0, 0)
        aLine.GetPointIds().SetId(1, 1)

        bLine = aLine.NewInstance()
        bLine.DeepCopy(aLine)

        aLineGrid = vtk.vtkUnstructuredGrid()
        aLineGrid.Allocate(1, 1)
        aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())
        aLineGrid.SetPoints(linePoints)

        aLineMapper = vtk.vtkDataSetMapper()
        aLineMapper.SetInputData(aLineGrid)

        aLineActor = vtk.vtkActor()
        aLineActor.SetMapper(aLineMapper)
        aLineActor.AddPosition(0, 0, 4)
        aLineActor.GetProperty().BackfaceCullingOn()

        # Poly line

        polyLinePoints = vtk.vtkPoints()
        polyLinePoints.SetNumberOfPoints(3)
        polyLinePoints.InsertPoint(0, 0, 0, 0)
        polyLinePoints.InsertPoint(1, 1, 1, 0)
        polyLinePoints.InsertPoint(2, 1, 0, 0)

        aPolyLine = vtk.vtkPolyLine()
        aPolyLine.GetPointIds().SetNumberOfIds(3)
        aPolyLine.GetPointIds().SetId(0, 0)
        aPolyLine.GetPointIds().SetId(1, 1)
        aPolyLine.GetPointIds().SetId(2, 2)

        bPolyLine = aPolyLine.NewInstance()
        bPolyLine.DeepCopy(aPolyLine)

        aPolyLineGrid = vtk.vtkUnstructuredGrid()
        aPolyLineGrid.Allocate(1, 1)
        aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
        aPolyLineGrid.SetPoints(polyLinePoints)

        aPolyLineMapper = vtk.vtkDataSetMapper()
        aPolyLineMapper.SetInputData(aPolyLineGrid)

        aPolyLineActor = vtk.vtkActor()
        aPolyLineActor.SetMapper(aPolyLineMapper)
        aPolyLineActor.AddPosition(2, 0, 4)
        aPolyLineActor.GetProperty().BackfaceCullingOn()

        # Vertex

        vertexPoints = vtk.vtkPoints()
        vertexPoints.SetNumberOfPoints(1)
        vertexPoints.InsertPoint(0, 0, 0, 0)

        aVertex = vtk.vtkVertex()
        aVertex.GetPointIds().SetId(0, 0)

        bVertex = aVertex.NewInstance()
        bVertex.DeepCopy(aVertex)

        aVertexGrid = vtk.vtkUnstructuredGrid()
        aVertexGrid.Allocate(1, 1)
        aVertexGrid.InsertNextCell(aVertex.GetCellType(), aVertex.GetPointIds())
        aVertexGrid.SetPoints(vertexPoints)

        aVertexMapper = vtk.vtkDataSetMapper()
        aVertexMapper.SetInputData(aVertexGrid)

        aVertexActor = vtk.vtkActor()
        aVertexActor.SetMapper(aVertexMapper)
        aVertexActor.AddPosition(0, 0, 6)
        aVertexActor.GetProperty().BackfaceCullingOn()

        # Poly Vertex

        polyVertexPoints = vtk.vtkPoints()
        polyVertexPoints.SetNumberOfPoints(3)
        polyVertexPoints.InsertPoint(0, 0, 0, 0)
        polyVertexPoints.InsertPoint(1, 1, 0, 0)
        polyVertexPoints.InsertPoint(2, 1, 1, 0)

        aPolyVertex = vtk.vtkPolyVertex()
        aPolyVertex.GetPointIds().SetNumberOfIds(3)
        aPolyVertex.GetPointIds().SetId(0, 0)
        aPolyVertex.GetPointIds().SetId(1, 1)
        aPolyVertex.GetPointIds().SetId(2, 2)

        bPolyVertex = aPolyVertex.NewInstance()
        bPolyVertex.DeepCopy(aPolyVertex)

        aPolyVertexGrid = vtk.vtkUnstructuredGrid()
        aPolyVertexGrid.Allocate(1, 1)
        aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(), aPolyVertex.GetPointIds())
        aPolyVertexGrid.SetPoints(polyVertexPoints)

        aPolyVertexMapper = vtk.vtkDataSetMapper()
        aPolyVertexMapper.SetInputData(aPolyVertexGrid)

        aPolyVertexActor = vtk.vtkActor()
        aPolyVertexActor.SetMapper(aPolyVertexMapper)
        aPolyVertexActor.AddPosition(2, 0, 6)
        aPolyVertexActor.GetProperty().BackfaceCullingOn()

        # Pentagonal prism

        pentaPoints = vtk.vtkPoints()
        pentaPoints.SetNumberOfPoints(10)
        pentaPoints.InsertPoint(0, 0.25, 0.0, 0.0)
        pentaPoints.InsertPoint(1, 0.75, 0.0, 0.0)
        pentaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
        pentaPoints.InsertPoint(3, 0.5, 1.0, 0.0)
        pentaPoints.InsertPoint(4, 0.0, 0.5, 0.0)
        pentaPoints.InsertPoint(5, 0.25, 0.0, 1.0)
        pentaPoints.InsertPoint(6, 0.75, 0.0, 1.0)
        pentaPoints.InsertPoint(7, 1.0, 0.5, 1.0)
        pentaPoints.InsertPoint(8, 0.5, 1.0, 1.0)
        pentaPoints.InsertPoint(9, 0.0, 0.5, 1.0)

        aPenta = vtk.vtkPentagonalPrism()
        aPenta.GetPointIds().SetId(0, 0)
        aPenta.GetPointIds().SetId(1, 1)
        aPenta.GetPointIds().SetId(2, 2)
        aPenta.GetPointIds().SetId(3, 3)
        aPenta.GetPointIds().SetId(4, 4)
        aPenta.GetPointIds().SetId(5, 5)
        aPenta.GetPointIds().SetId(6, 6)
        aPenta.GetPointIds().SetId(7, 7)
        aPenta.GetPointIds().SetId(8, 8)
        aPenta.GetPointIds().SetId(9, 9)

        bPenta = aPenta.NewInstance()
        bPenta.DeepCopy(aPenta)

        aPentaGrid = vtk.vtkUnstructuredGrid()
        aPentaGrid.Allocate(1, 1)
        aPentaGrid.InsertNextCell(aPenta.GetCellType(), aPenta.GetPointIds())
        aPentaGrid.SetPoints(pentaPoints)

        aPentaCopy = vtk.vtkUnstructuredGrid()
        aPentaCopy.DeepCopy(aPentaGrid)

        aPentaMapper = vtk.vtkDataSetMapper()
        aPentaMapper.SetInputData(aPentaCopy)

        aPentaActor = vtk.vtkActor()
        aPentaActor.SetMapper(aPentaMapper)
        aPentaActor.AddPosition(10, 0, 0)
        aPentaActor.GetProperty().BackfaceCullingOn()

        # Hexagonal prism

        hexaPoints = vtk.vtkPoints()
        hexaPoints.SetNumberOfPoints(12)
        hexaPoints.InsertPoint(0, 0.0, 0.0, 0.0)
        hexaPoints.InsertPoint(1, 0.5, 0.0, 0.0)
        hexaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
        hexaPoints.InsertPoint(3, 1.0, 1.0, 0.0)
        hexaPoints.InsertPoint(4, 0.5, 1.0, 0.0)
        hexaPoints.InsertPoint(5, 0.0, 0.5, 0.0)
        hexaPoints.InsertPoint(6, 0.0, 0.0, 1.0)
        hexaPoints.InsertPoint(7, 0.5, 0.0, 1.0)
        hexaPoints.InsertPoint(8, 1.0, 0.5, 1.0)
        hexaPoints.InsertPoint(9, 1.0, 1.0, 1.0)
        hexaPoints.InsertPoint(10, 0.5, 1.0, 1.0)
        hexaPoints.InsertPoint(11, 0.0, 0.5, 1.0)

        aHexa = vtk.vtkHexagonalPrism()
        aHexa.GetPointIds().SetId(0, 0)
        aHexa.GetPointIds().SetId(1, 1)
        aHexa.GetPointIds().SetId(2, 2)
        aHexa.GetPointIds().SetId(3, 3)
        aHexa.GetPointIds().SetId(4, 4)
        aHexa.GetPointIds().SetId(5, 5)
        aHexa.GetPointIds().SetId(6, 6)
        aHexa.GetPointIds().SetId(7, 7)
        aHexa.GetPointIds().SetId(8, 8)
        aHexa.GetPointIds().SetId(9, 9)
        aHexa.GetPointIds().SetId(10, 10)
        aHexa.GetPointIds().SetId(11, 11)

        bHexa = aHexa.NewInstance()
        bHexa.DeepCopy(aHexa)

        aHexaGrid = vtk.vtkUnstructuredGrid()
        aHexaGrid.Allocate(1, 1)
        aHexaGrid.InsertNextCell(aHexa.GetCellType(), aHexa.GetPointIds())
        aHexaGrid.SetPoints(hexaPoints)

        aHexaCopy = vtk.vtkUnstructuredGrid()
        aHexaCopy.DeepCopy(aHexaGrid)

        aHexaMapper = vtk.vtkDataSetMapper()
        aHexaMapper.SetInputData(aHexaCopy)

        aHexaActor = vtk.vtkActor()
        aHexaActor.SetMapper(aHexaMapper)
        aHexaActor.AddPosition(12, 0, 0)
        aHexaActor.GetProperty().BackfaceCullingOn()

        # RIB property
        aRIBProperty = vtk.vtkRIBProperty()
        aRIBProperty.SetVariable("Km", "float")
        aRIBProperty.SetSurfaceShader("LGVeinedmarble")
        aRIBProperty.SetVariable("veinfreq", "float")
        aRIBProperty.AddVariable("warpfreq", "float")
        aRIBProperty.AddVariable("veincolor", "color")
        aRIBProperty.AddParameter("veinfreq", " 2")
        aRIBProperty.AddParameter("veincolor", "1.0000 1.0000 0.9412")
        bRIBProperty = vtk.vtkRIBProperty()
        bRIBProperty.SetVariable("Km", "float")
        bRIBProperty.SetParameter("Km", "1.0")
        bRIBProperty.SetDisplacementShader("dented")
        bRIBProperty.SetSurfaceShader("plastic")
        aProperty = vtk.vtkProperty()
        bProperty = vtk.vtkProperty()

        aTriangleActor.SetProperty(aProperty)
        aTriangleStripActor.SetProperty(bProperty)

        ren.SetBackground(0.1, 0.2, 0.4)

        ren.AddActor(aVoxelActor)
        aVoxelActor.GetProperty().SetDiffuseColor(1, 0, 0)
        ren.AddActor(aHexahedronActor)
        aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0)
        ren.AddActor(aTetraActor)
        aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0)
        ren.AddActor(aWedgeActor)
        aWedgeActor.GetProperty().SetDiffuseColor(0, 1, 1)
        ren.AddActor(aPyramidActor)
        aPyramidActor.GetProperty().SetDiffuseColor(1, 0, 1)
        ren.AddActor(aPixelActor)
        aPixelActor.GetProperty().SetDiffuseColor(0, 1, 1)
        ren.AddActor(aQuadActor)
        aQuadActor.GetProperty().SetDiffuseColor(1, 0, 1)
        ren.AddActor(aTriangleActor)
        aTriangleActor.GetProperty().SetDiffuseColor(0.3, 1, 0.5)
        ren.AddActor(aPolygonActor)
        aPolygonActor.GetProperty().SetDiffuseColor(1, 0.4, 0.5)
        ren.AddActor(aTriangleStripActor)
        aTriangleStripActor.GetProperty().SetDiffuseColor(0.3, 0.7, 1)
        ren.AddActor(aLineActor)
        aLineActor.GetProperty().SetDiffuseColor(0.2, 1, 1)
        ren.AddActor(aPolyLineActor)
        aPolyLineActor.GetProperty().SetDiffuseColor(1, 1, 1)
        ren.AddActor(aVertexActor)
        aVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
        ren.AddActor(aPolyVertexActor)
        aPolyVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
        ren.AddActor(aPentaActor)
        aPentaActor.GetProperty().SetDiffuseColor(0.2, 0.4, 0.7)
        ren.AddActor(aHexaActor)
        aHexaActor.GetProperty().SetDiffuseColor(0.7, 0.5, 1)

        aRIBLight = vtk.vtkRIBLight()
        aRIBLight.ShadowsOn()
        aLight = vtk.vtkLight()

        aLight.PositionalOn()
        aLight.SetConeAngle(25)

        ren.AddLight(aLight)

        ren.ResetCamera()
        ren.GetActiveCamera().Azimuth(30)
        ren.GetActiveCamera().Elevation(20)
        ren.GetActiveCamera().Dolly(2.8)
        ren.ResetCameraClippingRange()

        aLight.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
        aLight.SetPosition(ren.GetActiveCamera().GetPosition())

        # write to the temp directory if possible, otherwise use .
        dir = tempfile.gettempdir()

        atext = vtk.vtkTexture()
        pnmReader = vtk.vtkBMPReader()
        pnmReader.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")
        atext.SetInputConnection(pnmReader.GetOutputPort())
        atext.InterpolateOff()
        aTriangleActor.SetTexture(atext)
        rib = vtk.vtkRIBExporter()
        rib.SetInput(renWin)
        rib.SetFilePrefix(dir + "/cells")
        rib.SetTexturePrefix(dir + "/cells")
        rib.Write()
        os.remove(dir + "/cells.rib")

        iv = vtk.vtkIVExporter()
        iv.SetInput(renWin)
        iv.SetFileName(dir + "/cells.iv")
        iv.Write()
        os.remove(dir + "/cells.iv")

        obj = vtk.vtkOBJExporter()
        obj.SetInput(renWin)
        obj.SetFilePrefix(dir + "/cells")
        obj.Write()
        os.remove(dir + "/cells.obj")
        os.remove(dir + "/cells.mtl")

        vrml = vtk.vtkVRMLExporter()
        vrml.SetInput(renWin)
        # vrml.SetStartWrite(vrml.SetFileName(dir + "/cells.wrl"))
        # vrml.SetEndWrite(vrml.SetFileName("/a/acells.wrl"))
        vrml.SetFileName(dir + "/cells.wrl")
        vrml.SetSpeed(5.5)
        vrml.Write()
        os.remove(dir + "/cells.wrl")

        oogl = vtk.vtkOOGLExporter()
        oogl.SetInput(renWin)
        oogl.SetFileName(dir + "/cells.oogl")
        oogl.Write()
        os.remove(dir + "/cells.oogl")

        # the UnRegister calls are because make object is the same as New,
        # and causes memory leaks. (Python does not treat NewInstance the same as New).
        def DeleteCopies():
            bVoxel.UnRegister(None)
            bHexahedron.UnRegister(None)
            bTetra.UnRegister(None)
            bWedge.UnRegister(None)
            bPyramid.UnRegister(None)
            bPixel.UnRegister(None)
            bQuad.UnRegister(None)
            bTriangle.UnRegister(None)
            bPolygon.UnRegister(None)
            bTriangleStrip.UnRegister(None)
            bLine.UnRegister(None)
            bPolyLine.UnRegister(None)
            bVertex.UnRegister(None)
            bPolyVertex.UnRegister(None)
            bPenta.UnRegister(None)
            bHexa.UnRegister(None)

        DeleteCopies()

        # render and interact with data

        renWin.Render()

        img_file = "cells.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
Example #43
0
 def __init__(self, renderer=None, **kwargs):
     super(ChiggerResultBase, self).__init__(**kwargs)
     self._vtkrenderer = renderer if renderer != None else vtk.vtkRenderer()
     self._vtklight = vtk.vtkLight()
     self._vtklight.SetLightTypeToHeadlight()
Example #44
0
mapper.SetInputConnection(cone.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetPosition(0, 0, 0)
actor.GetProperty().SetColor(0.8, 0.6, 0.1)
actor.GetProperty().SetAmbient(0.1)
actor.GetProperty().SetDiffuse(0.6)
actor.GetProperty().SetSpecular(0.8)

camera = vtk.vtkCamera()
camera.SetFocalPoint(0.0, 0.0, 0.0)
camera.SetPosition(0.0, 0.0, 8.0)
camera.SetViewUp(0.0, 1.0, 0.0)

light = vtk.vtkLight()
light.SetFocalPoint(0.0, 0.0, 0.0)
light.SetPosition(2.0, 2.0, 10.0)
light.SetConeAngle(100.0)
light.SetLightTypeToCameraLight()

spot = vtk.vtkLight()
spot.SetFocalPoint(0.0, 0.0, 0.0)
spot.SetPosition(-6.0, -10.0, 4.0)
spot.SetConeAngle(10.0)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.AddLight(light)
renderer.AddLight(spot)
renderer.SetActiveCamera(camera)
Example #45
0
def main():

    fn0 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp"
    fn0c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp"
    fn1 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_l.vtp"
    fn1c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_l_col.vtp"
    fn2 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_r.vtp"
    fn2c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Grasper/lever_r_col.vtp"
    fn0t = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Textures/metal.jpg"
    fn3 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Probe/tip.vtp"
    fn3c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp"
    fn4 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/ball.vtp"
    fn4c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/ball_col.vtp"
    fn4d = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/ball_def_c10.vtp"
    fn4t = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Textures/liver.jpg"
    fn5 = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/cavity.vtp"
    fn5c = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/cavity_col.vtp"
    fn5d = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Organs/cavity_def_c10.vtp"
    fn5t = "/Users/davidcastillobolado/vtkESQuiData/Scenario/Textures/intestine2.jpg"

    # Left Tool (Probe)
    # Visualization model
    vis_stick_l = vtkesqui.vtkVisualizationModel()
    vis_stick_l.SetName("vis_stick_l")
    vis_stick_l.SetFileName(fn0)
    vis_stick_l.SetTextureFileName(fn0t)
    vis_stick_l.SetOpacity(1.0)
    vis_stick_l.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_l = vtkesqui.vtkCollisionModel()
    col_stick_l.SetName("col_stick_l_vtkbioeng")
    col_stick_l.SetFileName(fn0c)
    col_stick_l.SetOpacity(0.0)
    col_stick_l.SetColor(1.0, 1.0, 1.0)

    # First tool element (stick_l)
    stick_l = vtkesqui.vtkScenarioElement()
    stick_l.SetName("stick_l")
    stick_l.SetPosition(-4.0, 0.0, 0.0)
    stick_l.SetOrientation(0, 0, 20)
    stick_l.SetOrigin(0, 0, 6)
    stick_l.SetVisualizationModel(vis_stick_l)
    stick_l.SetCollisionModel(col_stick_l)

    # Visualization model
    vis_tip_l = vtkesqui.vtkVisualizationModel()
    vis_tip_l.SetName("vis_tip_l")
    vis_tip_l.SetFileName(fn3)
    vis_tip_l.SetTextureFileName(fn0t)
    vis_tip_l.SetOpacity(1.0)
    vis_tip_l.SetColor(1.0, 0.0, 0.0)

    # Collision model
    col_tip_l = vtkesqui.vtkCollisionModel()
    col_tip_l.SetName("col_tip_l_vtkbioeng")
    col_tip_l.SetFileName(fn3c)
    col_tip_l.SetOpacity(0.0)
    col_tip_l.SetColor(1.0, 1.0, 1.0)

    # Second tool element (tip_l)
    tip_l = vtkesqui.vtkScenarioElement()
    tip_l.SetName("tip_l")
    tip_l.SetPosition(-4.0, 0.0, 0.0)
    tip_l.SetOrientation(0, 0, 20)
    tip_l.SetOrigin(0, 0, 6)
    tip_l.SetVisualizationModel(vis_tip_l)
    tip_l.SetCollisionModel(col_tip_l)

    probe_l = vtkesqui.vtkToolProbe()
    probe_l.AddElement(stick_l)
    probe_l.AddElement(tip_l)

    # Right tool (Grasper)
    # Visualization model
    vis_stick_r = vtkesqui.vtkVisualizationModel()
    vis_stick_r.SetName("vis_stick_r")
    vis_stick_r.SetFileName(fn0)
    vis_stick_r.SetTextureFileName(fn0t)
    vis_stick_r.SetOpacity(1.0)
    vis_stick_r.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_r = vtkesqui.vtkCollisionModel()
    col_stick_r.SetName("col_stick_r_vtkbioeng")
    col_stick_r.SetFileName(fn0c)
    col_stick_r.SetOpacity(0.0)
    col_stick_r.SetColor(1.0, 1.0, 1.0)

    # First tool element (stick_r)
    stick_r = vtkesqui.vtkScenarioElement()
    stick_r.SetName("stick_r")
    stick_r.SetPosition(4.0, 0.0, 0.0)
    stick_r.SetOrientation(0, 0, -20)
    stick_r.SetOrigin(0, 0, 6)
    stick_r.SetVisualizationModel(vis_stick_r)
    # stick_r.SetCollisionModel(col_stick_r)

    # Visualization model
    vis_l_lever_r = vtkesqui.vtkVisualizationModel()
    vis_l_lever_r.SetName("vis_l_lever_r")
    vis_l_lever_r.SetFileName(fn1)
    vis_l_lever_r.SetTextureFileName(fn0t)
    vis_l_lever_r.SetOpacity(1.0)
    vis_l_lever_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_l_lever_r = vtkesqui.vtkCollisionModel()
    col_l_lever_r.SetName("col_l_lever_r_vtkbioeng")
    col_l_lever_r.SetFileName(fn1c)
    col_l_lever_r.SetOpacity(0.0)
    col_l_lever_r.SetColor(1.0, 1.0, 1.0)

    # Second tool element (l_lever_r)
    l_lever_r = vtkesqui.vtkScenarioElement()
    l_lever_r.SetName("l_lever_r")
    l_lever_r.SetPosition(4.0, 0.0, 0.0)
    l_lever_r.SetOrientation(0, 0, -20)
    l_lever_r.SetOrigin(0, 0, 6)
    l_lever_r.SetVisualizationModel(vis_l_lever_r)
    l_lever_r.SetCollisionModel(col_l_lever_r)

    # Visualization model
    vis_r_lever_r = vtkesqui.vtkVisualizationModel()
    vis_r_lever_r.SetName("vis_r_lever_r")
    vis_r_lever_r.SetFileName(fn2)
    vis_r_lever_r.SetTextureFileName(fn0t)
    vis_r_lever_r.SetOpacity(1.0)
    vis_r_lever_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_r_lever_r = vtkesqui.vtkCollisionModel()
    col_r_lever_r.SetName("col_r_lever_r_vtkbioeng")
    col_r_lever_r.SetFileName(fn2c)
    col_r_lever_r.SetOpacity(0.0)
    col_r_lever_r.SetColor(1.0, 1.0, 1.0)

    # Second tool element (r_lever_r)
    r_lever_r = vtkesqui.vtkScenarioElement()
    r_lever_r.SetName("r_lever_r")
    r_lever_r.SetPosition(4.0, 0.0, 0.0)
    r_lever_r.SetOrientation(0, 0, -20)
    r_lever_r.SetOrigin(0, 0, 6)
    r_lever_r.SetVisualizationModel(vis_r_lever_r)
    r_lever_r.SetCollisionModel(col_r_lever_r)

    grasper_r = vtkesqui.vtkToolGrasper()
    grasper_r.SetStick(stick_r)
    grasper_r.SetLeftLever(l_lever_r)
    grasper_r.SetRightLever(r_lever_r)

    # Add an Organ
    # Visualization model
    vis_ball = vtkesqui.vtkVisualizationModel()
    vis_ball.SetName("vis_ball")
    vis_ball.SetFileName(fn4)
    vis_ball.SetTextureFileName(fn4t)
    vis_ball.SetOpacity(1.0)

    # Collision model
    col_ball = vtkesqui.vtkCollisionModel()
    col_ball.SetName("col_ball_vtkbioeng")
    col_ball.SetFileName(fn4c)
    col_ball.SetOpacity(0.0)

    # Deformation model
    def_ball = vtkesqui.vtkParticleSpringSystemInterface()
    def_ball.SetName("def_ball_particle")
    def_ball.SetFileName(fn4d)
    def_ball.SetOpacity(0.0)
    def_ball.SetSpring(150)
    def_ball.SetDistance(1.0)
    def_ball.SetDamping(3)
    def_ball.SetMass(0.1)
    def_ball.SetTimeStep(0.001)

    # Organ element (ball)
    e_ball = vtkesqui.vtkScenarioElement()
    e_ball.SetName("ball")
    e_ball.SetPosition(0.0, 0.0, -2.0)
    e_ball.SetOrientation(0, 0, 0)
    e_ball.SetVisualizationModel(vis_ball)
    e_ball.SetCollisionModel(col_ball)
    e_ball.SetDeformationModel(def_ball)

    ball = vtkesqui.vtkOrgan()
    ball.AddElement(e_ball)

    # Add an Organ (Cavity)
    # Visualization model
    vis_cavity = vtkesqui.vtkVisualizationModel()
    vis_cavity.SetName("vis_cavity")
    vis_cavity.SetFileName(fn5)
    vis_cavity.SetTextureFileName(fn5t)
    vis_cavity.SetOpacity(1.0)

    # Collision model
    col_cavity = vtkesqui.vtkCollisionModel()
    col_cavity.SetName("col_cavity_vtkbioeng")
    col_cavity.SetFileName(fn5c)
    col_cavity.SetOpacity(0.0)

    # Deformation model
    def_cavity = vtkesqui.vtkParticleSpringSystemInterface()
    def_cavity.SetName("def_cavity_particle")
    def_cavity.SetFileName(fn5d)
    def_cavity.SetOpacity(0.0)
    def_cavity.SetSpring(150)
    def_cavity.SetDistance(1.0)
    def_cavity.SetDamping(3)
    def_cavity.SetMass(0.1)
    def_cavity.SetTimeStep(0.001)

    # Organ element (cavity)
    e_cavity = vtkesqui.vtkScenarioElement()
    e_cavity.SetName("cavity")
    e_cavity.SetPosition(0.0, 0.0, -2.0)
    e_cavity.SetOrientation(-30, 0, 0)
    e_cavity.SetVisualizationModel(vis_cavity)
    e_cavity.SetCollisionModel(col_cavity)
    e_cavity.SetDeformationModel(def_cavity)

    cavity = vtkesqui.vtkOrgan()
    cavity.AddElement(e_cavity)

    scenario = vtkesqui.vtkScenario()
    scenario.SetName("vtkESQui - Laparoscopy")

    scenario.AddObject(probe_l)
    scenario.AddObject(grasper_r)
    scenario.AddObject(ball)
    scenario.AddObject(cavity)

    # Scenario camera
    camera = vtk.vtkCamera()
    camera.SetPosition(0, 0, 6)
    camera.SetFocalPoint(0, 0, -6)
    camera.Yaw(0)
    camera.Elevation(20)
    camera.Pitch(-15)
    camera.ParallelProjectionOff()
    camera.SetViewAngle(70)
    camera.Dolly(1.2)
    scenario.SetCamera(camera)

    # /********** Lights	**********/
    headLight = vtk.vtkLight()
    headLight.SetLightTypeToHeadlight()
    headLight.PositionalOn()
    headLight.SetIntensity(0.8)
    headLight.SetConeAngle(60)
    scenario.AddLight(headLight)

    ambientLight = vtk.vtkLight()
    ambientLight.SetLightTypeToSceneLight()
    ambientLight.PositionalOff()
    ambientLight.SetPosition(0, 1, 1)
    ambientLight.SetIntensity(0.5)
    scenario.AddLight(ambientLight)

    style = vtkesqui.vtkDefaultInteractorStyle()
    style.SetScenario(scenario)

    simulation = vtkesqui.vtkSimulation()
    simulation.SetScenario(scenario)
    simulation.SetInteractorStyle(style)
    simulation.SetRenderTimerRate(50)
    simulation.SetSimulationTimerRate(50)
    simulation.SetInteractionTimerRate(50)
    simulation.InteractionOn()
    simulation.CollisionOn()
    simulation.Initialize()

    simulation.Run()
Example #46
0
    def testCells(self):

        # Demonstrates all cell types
        #
        # NOTE: the use of NewInstance/DeepCopy is included to increase
        # regression coverage.  It is not required in most applications.

        ren = vtk.vtkRenderer()
        # turn off all cullers
        ren.GetCullers().RemoveAllItems()

        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        renWin.SetSize(300, 150)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin);

        # create a scene with one of each cell type

        # Voxel

        voxelPoints = vtk.vtkPoints()
        voxelPoints.SetNumberOfPoints(8)
        voxelPoints.InsertPoint(0, 0, 0, 0)
        voxelPoints.InsertPoint(1, 1, 0, 0)
        voxelPoints.InsertPoint(2, 0, 1, 0)
        voxelPoints.InsertPoint(3, 1, 1, 0)
        voxelPoints.InsertPoint(4, 0, 0, 1)
        voxelPoints.InsertPoint(5, 1, 0, 1)
        voxelPoints.InsertPoint(6, 0, 1, 1)
        voxelPoints.InsertPoint(7, 1, 1, 1)

        aVoxel = vtk.vtkVoxel()
        aVoxel.GetPointIds().SetId(0, 0)
        aVoxel.GetPointIds().SetId(1, 1)
        aVoxel.GetPointIds().SetId(2, 2)
        aVoxel.GetPointIds().SetId(3, 3)
        aVoxel.GetPointIds().SetId(4, 4)
        aVoxel.GetPointIds().SetId(5, 5)
        aVoxel.GetPointIds().SetId(6, 6)
        aVoxel.GetPointIds().SetId(7, 7)

        bVoxel = aVoxel.NewInstance()
        bVoxel.DeepCopy(aVoxel)

        aVoxelGrid = vtk.vtkUnstructuredGrid()
        aVoxelGrid.Allocate(1, 1)
        aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds())
        aVoxelGrid.SetPoints(voxelPoints)

        aVoxelMapper = vtk.vtkDataSetMapper()
        aVoxelMapper.SetInputData(aVoxelGrid)

        aVoxelActor = vtk.vtkActor()
        aVoxelActor.SetMapper(aVoxelMapper)
        aVoxelActor.GetProperty().BackfaceCullingOn()

        # Hexahedron

        hexahedronPoints = vtk.vtkPoints()
        hexahedronPoints.SetNumberOfPoints(8)
        hexahedronPoints.InsertPoint(0, 0, 0, 0)
        hexahedronPoints.InsertPoint(1, 1, 0, 0)
        hexahedronPoints.InsertPoint(2, 1, 1, 0)
        hexahedronPoints.InsertPoint(3, 0, 1, 0)
        hexahedronPoints.InsertPoint(4, 0, 0, 1)
        hexahedronPoints.InsertPoint(5, 1, 0, 1)
        hexahedronPoints.InsertPoint(6, 1, 1, 1)
        hexahedronPoints.InsertPoint(7, 0, 1, 1)

        aHexahedron = vtk.vtkHexahedron()
        aHexahedron.GetPointIds().SetId(0, 0)
        aHexahedron.GetPointIds().SetId(1, 1)
        aHexahedron.GetPointIds().SetId(2, 2)
        aHexahedron.GetPointIds().SetId(3, 3)
        aHexahedron.GetPointIds().SetId(4, 4)
        aHexahedron.GetPointIds().SetId(5, 5)
        aHexahedron.GetPointIds().SetId(6, 6)
        aHexahedron.GetPointIds().SetId(7, 7)

        bHexahedron = aHexahedron.NewInstance()
        bHexahedron.DeepCopy(aHexahedron)

        aHexahedronGrid = vtk.vtkUnstructuredGrid()
        aHexahedronGrid.Allocate(1, 1)
        aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds())
        aHexahedronGrid.SetPoints(hexahedronPoints)

        aHexahedronMapper = vtk.vtkDataSetMapper()
        aHexahedronMapper.SetInputData(aHexahedronGrid)

        aHexahedronActor = vtk.vtkActor()
        aHexahedronActor.SetMapper(aHexahedronMapper)
        aHexahedronActor.AddPosition(2, 0, 0)
        aHexahedronActor.GetProperty().BackfaceCullingOn()

        # Tetra

        tetraPoints = vtk.vtkPoints()
        tetraPoints.SetNumberOfPoints(4)
        tetraPoints.InsertPoint(0, 0, 0, 0)
        tetraPoints.InsertPoint(1, 1, 0, 0)
        tetraPoints.InsertPoint(2, .5, 1, 0)
        tetraPoints.InsertPoint(3, .5, .5, 1)

        aTetra = vtk.vtkTetra()
        aTetra.GetPointIds().SetId(0, 0)
        aTetra.GetPointIds().SetId(1, 1)
        aTetra.GetPointIds().SetId(2, 2)
        aTetra.GetPointIds().SetId(3, 3)

        bTetra = aTetra.NewInstance()
        bTetra.DeepCopy(aTetra)

        aTetraGrid = vtk.vtkUnstructuredGrid()
        aTetraGrid.Allocate(1, 1)
        aTetraGrid.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds())
        aTetraGrid.SetPoints(tetraPoints)

        aTetraCopy = vtk.vtkUnstructuredGrid()
        aTetraCopy.ShallowCopy(aTetraGrid)

        aTetraMapper = vtk.vtkDataSetMapper()
        aTetraMapper.SetInputData(aTetraCopy)

        aTetraActor = vtk.vtkActor()
        aTetraActor.SetMapper(aTetraMapper)
        aTetraActor.AddPosition(4, 0, 0)
        aTetraActor.GetProperty().BackfaceCullingOn()

        # Wedge

        wedgePoints = vtk.vtkPoints()
        wedgePoints.SetNumberOfPoints(6)
        wedgePoints.InsertPoint(0, 0, 1, 0)
        wedgePoints.InsertPoint(1, 0, 0, 0)
        wedgePoints.InsertPoint(2, 0, .5, .5)
        wedgePoints.InsertPoint(3, 1, 1, 0)
        wedgePoints.InsertPoint(4, 1, 0, 0)
        wedgePoints.InsertPoint(5, 1, .5, .5)

        aWedge = vtk.vtkWedge()
        aWedge.GetPointIds().SetId(0, 0)
        aWedge.GetPointIds().SetId(1, 1)
        aWedge.GetPointIds().SetId(2, 2)
        aWedge.GetPointIds().SetId(3, 3)
        aWedge.GetPointIds().SetId(4, 4)
        aWedge.GetPointIds().SetId(5, 5)

        bWedge = aWedge.NewInstance()
        bWedge.DeepCopy(aWedge)

        aWedgeGrid = vtk.vtkUnstructuredGrid()
        aWedgeGrid.Allocate(1, 1)
        aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds())
        aWedgeGrid.SetPoints(wedgePoints)

        aWedgeCopy = vtk.vtkUnstructuredGrid()
        aWedgeCopy.DeepCopy(aWedgeGrid)

        aWedgeMapper = vtk.vtkDataSetMapper()
        aWedgeMapper.SetInputData(aWedgeCopy)

        aWedgeActor = vtk.vtkActor()
        aWedgeActor.SetMapper(aWedgeMapper)
        aWedgeActor.AddPosition(6, 0, 0)
        aWedgeActor.GetProperty().BackfaceCullingOn()

        # Pyramid

        pyramidPoints = vtk.vtkPoints()
        pyramidPoints.SetNumberOfPoints(5)
        pyramidPoints.InsertPoint(0, 0, 0, 0)
        pyramidPoints.InsertPoint(1, 1, 0, 0)
        pyramidPoints.InsertPoint(2, 1, 1, 0)
        pyramidPoints.InsertPoint(3, 0, 1, 0)
        pyramidPoints.InsertPoint(4, .5, .5, 1)

        aPyramid = vtk.vtkPyramid()
        aPyramid.GetPointIds().SetId(0, 0)
        aPyramid.GetPointIds().SetId(1, 1)
        aPyramid.GetPointIds().SetId(2, 2)
        aPyramid.GetPointIds().SetId(3, 3)
        aPyramid.GetPointIds().SetId(4, 4)

        bPyramid = aPyramid.NewInstance()
        bPyramid.DeepCopy(aPyramid)

        aPyramidGrid = vtk.vtkUnstructuredGrid()
        aPyramidGrid.Allocate(1, 1)
        aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds())
        aPyramidGrid.SetPoints(pyramidPoints)

        aPyramidMapper = vtk.vtkDataSetMapper()
        aPyramidMapper.SetInputData(aPyramidGrid)

        aPyramidActor = vtk.vtkActor()
        aPyramidActor.SetMapper(aPyramidMapper)
        aPyramidActor.AddPosition(8, 0, 0)
        aPyramidActor.GetProperty().BackfaceCullingOn()

        # Pixel

        pixelPoints = vtk.vtkPoints()
        pixelPoints.SetNumberOfPoints(4)
        pixelPoints.InsertPoint(0, 0, 0, 0)
        pixelPoints.InsertPoint(1, 1, 0, 0)
        pixelPoints.InsertPoint(2, 0, 1, 0)
        pixelPoints.InsertPoint(3, 1, 1, 0)

        aPixel = vtk.vtkPixel()
        aPixel.GetPointIds().SetId(0, 0)
        aPixel.GetPointIds().SetId(1, 1)
        aPixel.GetPointIds().SetId(2, 2)
        aPixel.GetPointIds().SetId(3, 3)

        bPixel = aPixel.NewInstance()
        bPixel.DeepCopy(aPixel)

        aPixelGrid = vtk.vtkUnstructuredGrid()
        aPixelGrid.Allocate(1, 1)
        aPixelGrid.InsertNextCell(aPixel.GetCellType(), aPixel.GetPointIds())
        aPixelGrid.SetPoints(pixelPoints)

        aPixelMapper = vtk.vtkDataSetMapper()
        aPixelMapper.SetInputData(aPixelGrid)

        aPixelActor = vtk.vtkActor()
        aPixelActor.SetMapper(aPixelMapper)
        aPixelActor.AddPosition(0, 0, 2)
        aPixelActor.GetProperty().BackfaceCullingOn()

        # Quad

        quadPoints = vtk.vtkPoints()
        quadPoints.SetNumberOfPoints(4)
        quadPoints.InsertPoint(0, 0, 0, 0)
        quadPoints.InsertPoint(1, 1, 0, 0)
        quadPoints.InsertPoint(2, 1, 1, 0)
        quadPoints.InsertPoint(3, 0, 1, 0)

        aQuad = vtk.vtkQuad()
        aQuad.GetPointIds().SetId(0, 0)
        aQuad.GetPointIds().SetId(1, 1)
        aQuad.GetPointIds().SetId(2, 2)
        aQuad.GetPointIds().SetId(3, 3)

        bQuad = aQuad.NewInstance()
        bQuad.DeepCopy(aQuad)

        aQuadGrid = vtk.vtkUnstructuredGrid()
        aQuadGrid.Allocate(1, 1)
        aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds())
        aQuadGrid.SetPoints(quadPoints)

        aQuadMapper = vtk.vtkDataSetMapper()
        aQuadMapper.SetInputData(aQuadGrid)

        aQuadActor = vtk.vtkActor()
        aQuadActor.SetMapper(aQuadMapper)
        aQuadActor.AddPosition(2, 0, 2)
        aQuadActor.GetProperty().BackfaceCullingOn()

        # Triangle

        trianglePoints = vtk.vtkPoints()
        trianglePoints.SetNumberOfPoints(3)
        trianglePoints.InsertPoint(0, 0, 0, 0)
        trianglePoints.InsertPoint(1, 1, 0, 0)
        trianglePoints.InsertPoint(2, .5, .5, 0)

        triangleTCoords = vtk.vtkFloatArray()
        triangleTCoords.SetNumberOfComponents(2)
        triangleTCoords.SetNumberOfTuples(3)
        triangleTCoords.InsertTuple2(0, 1, 1)
        triangleTCoords.InsertTuple2(1, 2, 2)
        triangleTCoords.InsertTuple2(2, 3, 3)

        aTriangle = vtk.vtkTriangle()
        aTriangle.GetPointIds().SetId(0, 0)
        aTriangle.GetPointIds().SetId(1, 1)
        aTriangle.GetPointIds().SetId(2, 2)

        bTriangle = aTriangle.NewInstance()
        bTriangle.DeepCopy(aTriangle)

        aTriangleGrid = vtk.vtkUnstructuredGrid()
        aTriangleGrid.Allocate(1, 1)
        aTriangleGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds())
        aTriangleGrid.SetPoints(trianglePoints)
        aTriangleGrid.GetPointData().SetTCoords(triangleTCoords)

        aTriangleMapper = vtk.vtkDataSetMapper()
        aTriangleMapper.SetInputData(aTriangleGrid)

        aTriangleActor = vtk.vtkActor()
        aTriangleActor.SetMapper(aTriangleMapper)
        aTriangleActor.AddPosition(4, 0, 2)
        aTriangleActor.GetProperty().BackfaceCullingOn()

        # Polygon

        polygonPoints = vtk.vtkPoints()
        polygonPoints.SetNumberOfPoints(4)
        polygonPoints.InsertPoint(0, 0, 0, 0)
        polygonPoints.InsertPoint(1, 1, 0, 0)
        polygonPoints.InsertPoint(2, 1, 1, 0)
        polygonPoints.InsertPoint(3, 0, 1, 0)

        aPolygon = vtk.vtkPolygon()
        aPolygon.GetPointIds().SetNumberOfIds(4)
        aPolygon.GetPointIds().SetId(0, 0)
        aPolygon.GetPointIds().SetId(1, 1)
        aPolygon.GetPointIds().SetId(2, 2)
        aPolygon.GetPointIds().SetId(3, 3)

        bPolygon = aPolygon.NewInstance()
        bPolygon.DeepCopy(aPolygon)

        aPolygonGrid = vtk.vtkUnstructuredGrid()
        aPolygonGrid.Allocate(1, 1)
        aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds())
        aPolygonGrid.SetPoints(polygonPoints)

        aPolygonMapper = vtk.vtkDataSetMapper()
        aPolygonMapper.SetInputData(aPolygonGrid)

        aPolygonActor = vtk.vtkActor()
        aPolygonActor.SetMapper(aPolygonMapper)
        aPolygonActor.AddPosition(6, 0, 2)
        aPolygonActor.GetProperty().BackfaceCullingOn()

        # Triangle Strip

        triangleStripPoints = vtk.vtkPoints()
        triangleStripPoints.SetNumberOfPoints(5)
        triangleStripPoints.InsertPoint(0, 0, 1, 0)
        triangleStripPoints.InsertPoint(1, 0, 0, 0)
        triangleStripPoints.InsertPoint(2, 1, 1, 0)
        triangleStripPoints.InsertPoint(3, 1, 0, 0)
        triangleStripPoints.InsertPoint(4, 2, 1, 0)

        triangleStripTCoords = vtk.vtkFloatArray()
        triangleStripTCoords.SetNumberOfComponents(2)
        triangleStripTCoords.SetNumberOfTuples(3)
        triangleStripTCoords.InsertTuple2(0, 1, 1)
        triangleStripTCoords.InsertTuple2(1, 2, 2)
        triangleStripTCoords.InsertTuple2(2, 3, 3)
        triangleStripTCoords.InsertTuple2(3, 4, 4)
        triangleStripTCoords.InsertTuple2(4, 5, 5)

        aTriangleStrip = vtk.vtkTriangleStrip()
        aTriangleStrip.GetPointIds().SetNumberOfIds(5)
        aTriangleStrip.GetPointIds().SetId(0, 0)
        aTriangleStrip.GetPointIds().SetId(1, 1)
        aTriangleStrip.GetPointIds().SetId(2, 2)
        aTriangleStrip.GetPointIds().SetId(3, 3)
        aTriangleStrip.GetPointIds().SetId(4, 4)

        bTriangleStrip = aTriangleStrip.NewInstance()
        bTriangleStrip.DeepCopy(aTriangleStrip)

        aTriangleStripGrid = vtk.vtkUnstructuredGrid()
        aTriangleStripGrid.Allocate(1, 1)
        aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds())
        aTriangleStripGrid.SetPoints(triangleStripPoints)
        aTriangleStripGrid.GetPointData().SetTCoords(triangleStripTCoords)

        aTriangleStripMapper = vtk.vtkDataSetMapper()
        aTriangleStripMapper.SetInputData(aTriangleStripGrid)

        aTriangleStripActor = vtk.vtkActor()
        aTriangleStripActor.SetMapper(aTriangleStripMapper)
        aTriangleStripActor.AddPosition(8, 0, 2)
        aTriangleStripActor.GetProperty().BackfaceCullingOn()

        # Line

        linePoints = vtk.vtkPoints()
        linePoints.SetNumberOfPoints(2)
        linePoints.InsertPoint(0, 0, 0, 0)
        linePoints.InsertPoint(1, 1, 1, 0)

        aLine = vtk.vtkLine()
        aLine.GetPointIds().SetId(0, 0)
        aLine.GetPointIds().SetId(1, 1)

        bLine = aLine.NewInstance()
        bLine.DeepCopy(aLine)

        aLineGrid = vtk.vtkUnstructuredGrid()
        aLineGrid.Allocate(1, 1)
        aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())
        aLineGrid.SetPoints(linePoints)

        aLineMapper = vtk.vtkDataSetMapper()
        aLineMapper.SetInputData(aLineGrid)

        aLineActor = vtk.vtkActor()
        aLineActor.SetMapper(aLineMapper)
        aLineActor.AddPosition(0, 0, 4)
        aLineActor.GetProperty().BackfaceCullingOn()

        # Poly line

        polyLinePoints = vtk.vtkPoints()
        polyLinePoints.SetNumberOfPoints(3)
        polyLinePoints.InsertPoint(0, 0, 0, 0)
        polyLinePoints.InsertPoint(1, 1, 1, 0)
        polyLinePoints.InsertPoint(2, 1, 0, 0)

        aPolyLine = vtk.vtkPolyLine()
        aPolyLine.GetPointIds().SetNumberOfIds(3)
        aPolyLine.GetPointIds().SetId(0, 0)
        aPolyLine.GetPointIds().SetId(1, 1)
        aPolyLine.GetPointIds().SetId(2, 2)

        bPolyLine = aPolyLine.NewInstance()
        bPolyLine.DeepCopy(aPolyLine)

        aPolyLineGrid = vtk.vtkUnstructuredGrid()
        aPolyLineGrid.Allocate(1, 1)
        aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
        aPolyLineGrid.SetPoints(polyLinePoints)

        aPolyLineMapper = vtk.vtkDataSetMapper()
        aPolyLineMapper.SetInputData(aPolyLineGrid)

        aPolyLineActor = vtk.vtkActor()
        aPolyLineActor.SetMapper(aPolyLineMapper)
        aPolyLineActor.AddPosition(2, 0, 4)
        aPolyLineActor.GetProperty().BackfaceCullingOn()

        # Vertex

        vertexPoints = vtk.vtkPoints()
        vertexPoints.SetNumberOfPoints(1)
        vertexPoints.InsertPoint(0, 0, 0, 0)

        aVertex = vtk.vtkVertex()
        aVertex.GetPointIds().SetId(0, 0)

        bVertex = aVertex.NewInstance()
        bVertex.DeepCopy(aVertex)

        aVertexGrid = vtk.vtkUnstructuredGrid()
        aVertexGrid.Allocate(1, 1)
        aVertexGrid.InsertNextCell(aVertex.GetCellType(), aVertex.GetPointIds())
        aVertexGrid.SetPoints(vertexPoints)

        aVertexMapper = vtk.vtkDataSetMapper()
        aVertexMapper.SetInputData(aVertexGrid)

        aVertexActor = vtk.vtkActor()
        aVertexActor.SetMapper(aVertexMapper)
        aVertexActor.AddPosition(0, 0, 6)
        aVertexActor.GetProperty().BackfaceCullingOn()

        # Poly Vertex

        polyVertexPoints = vtk.vtkPoints()
        polyVertexPoints.SetNumberOfPoints(3)
        polyVertexPoints.InsertPoint(0, 0, 0, 0)
        polyVertexPoints.InsertPoint(1, 1, 0, 0)
        polyVertexPoints.InsertPoint(2, 1, 1, 0)

        aPolyVertex = vtk.vtkPolyVertex()
        aPolyVertex.GetPointIds().SetNumberOfIds(3)
        aPolyVertex.GetPointIds().SetId(0, 0)
        aPolyVertex.GetPointIds().SetId(1, 1)
        aPolyVertex.GetPointIds().SetId(2, 2)

        bPolyVertex = aPolyVertex.NewInstance()
        bPolyVertex.DeepCopy(aPolyVertex)

        aPolyVertexGrid = vtk.vtkUnstructuredGrid()
        aPolyVertexGrid.Allocate(1, 1)
        aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(), aPolyVertex.GetPointIds())
        aPolyVertexGrid.SetPoints(polyVertexPoints)

        aPolyVertexMapper = vtk.vtkDataSetMapper()
        aPolyVertexMapper.SetInputData(aPolyVertexGrid)

        aPolyVertexActor = vtk.vtkActor()
        aPolyVertexActor.SetMapper(aPolyVertexMapper)
        aPolyVertexActor.AddPosition(2, 0, 6)
        aPolyVertexActor.GetProperty().BackfaceCullingOn()

        # Pentagonal prism

        pentaPoints = vtk.vtkPoints()
        pentaPoints.SetNumberOfPoints(10)
        pentaPoints.InsertPoint(0, 0.25, 0.0, 0.0)
        pentaPoints.InsertPoint(1, 0.75, 0.0, 0.0)
        pentaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
        pentaPoints.InsertPoint(3, 0.5, 1.0, 0.0)
        pentaPoints.InsertPoint(4, 0.0, 0.5, 0.0)
        pentaPoints.InsertPoint(5, 0.25, 0.0, 1.0)
        pentaPoints.InsertPoint(6, 0.75, 0.0, 1.0)
        pentaPoints.InsertPoint(7, 1.0, 0.5, 1.0)
        pentaPoints.InsertPoint(8, 0.5, 1.0, 1.0)
        pentaPoints.InsertPoint(9, 0.0, 0.5, 1.0)

        aPenta = vtk.vtkPentagonalPrism()
        aPenta.GetPointIds().SetId(0, 0)
        aPenta.GetPointIds().SetId(1, 1)
        aPenta.GetPointIds().SetId(2, 2)
        aPenta.GetPointIds().SetId(3, 3)
        aPenta.GetPointIds().SetId(4, 4)
        aPenta.GetPointIds().SetId(5, 5)
        aPenta.GetPointIds().SetId(6, 6)
        aPenta.GetPointIds().SetId(7, 7)
        aPenta.GetPointIds().SetId(8, 8)
        aPenta.GetPointIds().SetId(9, 9)

        bPenta = aPenta.NewInstance()
        bPenta.DeepCopy(aPenta)

        aPentaGrid = vtk.vtkUnstructuredGrid()
        aPentaGrid.Allocate(1, 1)
        aPentaGrid.InsertNextCell(aPenta.GetCellType(), aPenta.GetPointIds())
        aPentaGrid.SetPoints(pentaPoints)

        aPentaCopy = vtk.vtkUnstructuredGrid()
        aPentaCopy.DeepCopy(aPentaGrid)

        aPentaMapper = vtk.vtkDataSetMapper()
        aPentaMapper.SetInputData(aPentaCopy)

        aPentaActor = vtk.vtkActor()
        aPentaActor.SetMapper(aPentaMapper)
        aPentaActor.AddPosition(10, 0, 0)
        aPentaActor.GetProperty().BackfaceCullingOn()

        # Hexagonal prism

        hexaPoints = vtk.vtkPoints()
        hexaPoints.SetNumberOfPoints(12)
        hexaPoints.InsertPoint(0, 0.0, 0.0, 0.0)
        hexaPoints.InsertPoint(1, 0.5, 0.0, 0.0)
        hexaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
        hexaPoints.InsertPoint(3, 1.0, 1.0, 0.0)
        hexaPoints.InsertPoint(4, 0.5, 1.0, 0.0)
        hexaPoints.InsertPoint(5, 0.0, 0.5, 0.0)
        hexaPoints.InsertPoint(6, 0.0, 0.0, 1.0)
        hexaPoints.InsertPoint(7, 0.5, 0.0, 1.0)
        hexaPoints.InsertPoint(8, 1.0, 0.5, 1.0)
        hexaPoints.InsertPoint(9, 1.0, 1.0, 1.0)
        hexaPoints.InsertPoint(10, 0.5, 1.0, 1.0)
        hexaPoints.InsertPoint(11, 0.0, 0.5, 1.0)

        aHexa = vtk.vtkHexagonalPrism()
        aHexa.GetPointIds().SetId(0, 0)
        aHexa.GetPointIds().SetId(1, 1)
        aHexa.GetPointIds().SetId(2, 2)
        aHexa.GetPointIds().SetId(3, 3)
        aHexa.GetPointIds().SetId(4, 4)
        aHexa.GetPointIds().SetId(5, 5)
        aHexa.GetPointIds().SetId(6, 6)
        aHexa.GetPointIds().SetId(7, 7)
        aHexa.GetPointIds().SetId(8, 8)
        aHexa.GetPointIds().SetId(9, 9)
        aHexa.GetPointIds().SetId(10, 10)
        aHexa.GetPointIds().SetId(11, 11)

        bHexa = aHexa.NewInstance()
        bHexa.DeepCopy(aHexa)

        aHexaGrid = vtk.vtkUnstructuredGrid()
        aHexaGrid.Allocate(1, 1)
        aHexaGrid.InsertNextCell(aHexa.GetCellType(), aHexa.GetPointIds())
        aHexaGrid.SetPoints(hexaPoints)

        aHexaCopy = vtk.vtkUnstructuredGrid()
        aHexaCopy.DeepCopy(aHexaGrid)

        aHexaMapper = vtk.vtkDataSetMapper()
        aHexaMapper.SetInputData(aHexaCopy)

        aHexaActor = vtk.vtkActor()
        aHexaActor.SetMapper(aHexaMapper)
        aHexaActor.AddPosition(12, 0, 0)
        aHexaActor.GetProperty().BackfaceCullingOn()

        # RIB property
        if hasattr(vtk, 'vtkRIBProperty'):
            aRIBProperty = vtk.vtkRIBProperty()
            aRIBProperty.SetVariable("Km", "float")
            aRIBProperty.SetSurfaceShader("LGVeinedmarble")
            aRIBProperty.SetVariable("veinfreq", "float")
            aRIBProperty.AddVariable("warpfreq", "float")
            aRIBProperty.AddVariable("veincolor", "color")
            aRIBProperty.AddSurfaceShaderParameter("veinfreq", " 2")
            aRIBProperty.AddSurfaceShaderParameter("veincolor", "1.0000 1.0000 0.9412")
            bRIBProperty = vtk.vtkRIBProperty()
            bRIBProperty.SetVariable("Km", "float")
            bRIBProperty.SetSurfaceShaderParameter("Km", "1.0")
            bRIBProperty.SetDisplacementShader("dented")
            bRIBProperty.SetSurfaceShader("plastic")
        aProperty = vtk.vtkProperty()
        bProperty = vtk.vtkProperty()

        aTriangleActor.SetProperty(aProperty)
        aTriangleStripActor.SetProperty(bProperty)

        ren.SetBackground(.1, .2, .4)

        ren.AddActor(aVoxelActor);aVoxelActor.GetProperty().SetDiffuseColor(1, 0, 0)
        ren.AddActor(aHexahedronActor);aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0)
        ren.AddActor(aTetraActor);aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0)
        ren.AddActor(aWedgeActor);aWedgeActor.GetProperty().SetDiffuseColor(0, 1, 1)
        ren.AddActor(aPyramidActor);aPyramidActor.GetProperty().SetDiffuseColor(1, 0, 1)
        ren.AddActor(aPixelActor);aPixelActor.GetProperty().SetDiffuseColor(0, 1, 1)
        ren.AddActor(aQuadActor);aQuadActor.GetProperty().SetDiffuseColor(1, 0, 1)
        ren.AddActor(aTriangleActor);aTriangleActor.GetProperty().SetDiffuseColor(.3, 1, .5)
        ren.AddActor(aPolygonActor);aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5)
        ren.AddActor(aTriangleStripActor);aTriangleStripActor.GetProperty().SetDiffuseColor(.3, .7, 1)
        ren.AddActor(aLineActor);aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1)
        ren.AddActor(aPolyLineActor);aPolyLineActor.GetProperty().SetDiffuseColor(1, 1, 1)
        ren.AddActor(aVertexActor);aVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
        ren.AddActor(aPolyVertexActor);aPolyVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
        ren.AddActor(aPentaActor);aPentaActor.GetProperty().SetDiffuseColor(.2, .4, .7)
        ren.AddActor(aHexaActor);aHexaActor.GetProperty().SetDiffuseColor(.7, .5, 1)

        if hasattr(vtk, 'vtkRIBLight'):
            aRIBLight = vtk.vtkRIBLight()

        ren.AddLight(aRIBLight)
        aLight = vtk.vtkLight()

        aLight.PositionalOn()
        aLight.SetConeAngle(10.0)
        aLight.SetIntensity(20.0)
        ren.AddLight(aLight)

        ren.ResetCamera()
        ren.GetActiveCamera().Azimuth(30)
        ren.GetActiveCamera().Elevation(20)
        ren.GetActiveCamera().Dolly(2.8)
        ren.ResetCameraClippingRange()

        # write to the temp directory if possible, otherwise use .
        dir = tempfile.gettempdir()

        atext = vtk.vtkTexture()
        pnmReader = vtk.vtkBMPReader()
        pnmReader.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")
        atext.SetInputConnection(pnmReader.GetOutputPort())
        atext.InterpolateOff()
        aTriangleActor.SetTexture(atext)

        aRIBLight.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
        aRIBLight.SetPosition(ren.GetActiveCamera().GetPosition())
        aLight.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
        aLight.SetPosition(ren.GetActiveCamera().GetPosition())

        # bascially have IO/Export ?
        if hasattr(vtk, 'vtkRIBExporter'):
            rib = vtk.vtkRIBExporter()
            rib.SetInput(renWin)
            rib.SetFilePrefix(dir + '/cells')
            rib.SetTexturePrefix(dir + '/cells')
            rib.Write()

            iv = vtk.vtkIVExporter()
            iv.SetInput(renWin)
            iv.SetFileName(dir + "/cells.iv")
            iv.Write()
            os.remove(dir + '/cells.iv')

            obj = vtk.vtkOBJExporter()
            obj.SetInput(renWin)
            obj.SetFilePrefix(dir + "/cells")
            obj.Write()
            os.remove(dir + '/cells.obj')
            os.remove(dir + '/cells.mtl')

            vrml = vtk.vtkVRMLExporter()
            vrml.SetInput(renWin)
            #vrml.SetStartWrite(vrml.SetFileName(dir + "/cells.wrl"))
            #vrml.SetEndWrite(vrml.SetFileName("/a/acells.wrl"))
            vrml.SetFileName(dir + "/cells.wrl")
            vrml.SetSpeed(5.5)
            vrml.Write()
            os.remove(dir + '/cells.wrl')

            oogl = vtk.vtkOOGLExporter()
            oogl.SetInput(renWin)
            oogl.SetFileName(dir + "/cells.oogl")
            oogl.Write()
            os.remove(dir + '/cells.oogl')

        # the UnRegister calls are because make object is the same as New,
        # and causes memory leaks. (Python does not treat NewInstance the same as New).
        def DeleteCopies():
            bVoxel.UnRegister(None)
            bHexahedron.UnRegister(None)
            bTetra.UnRegister(None)
            bWedge.UnRegister(None)
            bPyramid.UnRegister(None)
            bPixel.UnRegister(None)
            bQuad.UnRegister(None)
            bTriangle.UnRegister(None)
            bPolygon.UnRegister(None)
            bTriangleStrip.UnRegister(None)
            bLine.UnRegister(None)
            bPolyLine.UnRegister(None)
            bVertex.UnRegister(None)
            bPolyVertex.UnRegister(None)
            bPenta.UnRegister(None)
            bHexa.UnRegister(None)


        DeleteCopies()


        # render and interact with data

        renWin.Render()

        img_file = "cells.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
Example #47
0
 def __init__(self, renderer=None, **kwargs):
     super(ChiggerResultBase, self).__init__(**kwargs)
     self._vtkrenderer = renderer if renderer != None else vtk.vtkRenderer()
     self._vtklight = vtk.vtkLight()
     self._vtklight.SetLightTypeToHeadlight()
Example #48
0
    def testSphereWidget(self):

        # This example demonstrates how to use the vtkSphereWidget to control the
        # position of a light.

        # These are the pre-recorded events
        Recording = \
           "# StreamVersion 1\n\
            CharEvent 23 266 0 0 105 1 i\n\
            KeyReleaseEvent 23 266 0 0 105 1 i\n\
            EnterEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 68 293 0 0 0 0 i\n\
            MouseMoveEvent 67 292 0 0 0 0 i\n\
            MouseMoveEvent 66 289 0 0 0 0 i\n\
            MouseMoveEvent 66 282 0 0 0 0 i\n\
            MouseMoveEvent 66 271 0 0 0 0 i\n\
            MouseMoveEvent 69 253 0 0 0 0 i\n\
            MouseMoveEvent 71 236 0 0 0 0 i\n\
            MouseMoveEvent 74 219 0 0 0 0 i\n\
            MouseMoveEvent 76 208 0 0 0 0 i\n\
            MouseMoveEvent 78 190 0 0 0 0 i\n\
            MouseMoveEvent 78 173 0 0 0 0 i\n\
            MouseMoveEvent 77 162 0 0 0 0 i\n\
            MouseMoveEvent 77 151 0 0 0 0 i\n\
            MouseMoveEvent 77 139 0 0 0 0 i\n\
            MouseMoveEvent 76 125 0 0 0 0 i\n\
            MouseMoveEvent 73 114 0 0 0 0 i\n\
            MouseMoveEvent 73 106 0 0 0 0 i\n\
            MouseMoveEvent 73 101 0 0 0 0 i\n\
            MouseMoveEvent 72 95 0 0 0 0 i\n\
            MouseMoveEvent 72 92 0 0 0 0 i\n\
            MouseMoveEvent 70 89 0 0 0 0 i\n\
            MouseMoveEvent 69 86 0 0 0 0 i\n\
            MouseMoveEvent 67 84 0 0 0 0 i\n\
            MouseMoveEvent 65 81 0 0 0 0 i\n\
            MouseMoveEvent 60 79 0 0 0 0 i\n\
            MouseMoveEvent 59 79 0 0 0 0 i\n\
            MouseMoveEvent 58 79 0 0 0 0 i\n\
            MouseMoveEvent 57 78 0 0 0 0 i\n\
            MouseMoveEvent 55 78 0 0 0 0 i\n\
            MouseMoveEvent 54 77 0 0 0 0 i\n\
            LeftButtonPressEvent 54 77 0 0 0 0 i\n\
            MouseMoveEvent 61 79 0 0 0 0 i\n\
            MouseMoveEvent 67 83 0 0 0 0 i\n\
            MouseMoveEvent 72 88 0 0 0 0 i\n\
            MouseMoveEvent 77 90 0 0 0 0 i\n\
            MouseMoveEvent 78 91 0 0 0 0 i\n\
            MouseMoveEvent 80 92 0 0 0 0 i\n\
            MouseMoveEvent 84 93 0 0 0 0 i\n\
            MouseMoveEvent 85 94 0 0 0 0 i\n\
            MouseMoveEvent 88 97 0 0 0 0 i\n\
            MouseMoveEvent 90 100 0 0 0 0 i\n\
            MouseMoveEvent 92 102 0 0 0 0 i\n\
            MouseMoveEvent 94 103 0 0 0 0 i\n\
            MouseMoveEvent 97 105 0 0 0 0 i\n\
            MouseMoveEvent 101 107 0 0 0 0 i\n\
            MouseMoveEvent 102 109 0 0 0 0 i\n\
            MouseMoveEvent 104 111 0 0 0 0 i\n\
            MouseMoveEvent 108 113 0 0 0 0 i\n\
            MouseMoveEvent 112 115 0 0 0 0 i\n\
            MouseMoveEvent 118 119 0 0 0 0 i\n\
            MouseMoveEvent 118 120 0 0 0 0 i\n\
            MouseMoveEvent 118 123 0 0 0 0 i\n\
            MouseMoveEvent 120 125 0 0 0 0 i\n\
            MouseMoveEvent 122 128 0 0 0 0 i\n\
            MouseMoveEvent 123 129 0 0 0 0 i\n\
            MouseMoveEvent 125 132 0 0 0 0 i\n\
            MouseMoveEvent 125 134 0 0 0 0 i\n\
            MouseMoveEvent 127 138 0 0 0 0 i\n\
            MouseMoveEvent 127 142 0 0 0 0 i\n\
            MouseMoveEvent 127 147 0 0 0 0 i\n\
            MouseMoveEvent 126 152 0 0 0 0 i\n\
            MouseMoveEvent 126 155 0 0 0 0 i\n\
            MouseMoveEvent 125 160 0 0 0 0 i\n\
            MouseMoveEvent 125 167 0 0 0 0 i\n\
            MouseMoveEvent 125 169 0 0 0 0 i\n\
            MouseMoveEvent 125 174 0 0 0 0 i\n\
            MouseMoveEvent 122 179 0 0 0 0 i\n\
            MouseMoveEvent 120 183 0 0 0 0 i\n\
            MouseMoveEvent 116 187 0 0 0 0 i\n\
            MouseMoveEvent 113 192 0 0 0 0 i\n\
            MouseMoveEvent 113 193 0 0 0 0 i\n\
            MouseMoveEvent 111 195 0 0 0 0 i\n\
            MouseMoveEvent 108 198 0 0 0 0 i\n\
            MouseMoveEvent 106 200 0 0 0 0 i\n\
            MouseMoveEvent 104 202 0 0 0 0 i\n\
            MouseMoveEvent 103 203 0 0 0 0 i\n\
            MouseMoveEvent 99 205 0 0 0 0 i\n\
            MouseMoveEvent 97 207 0 0 0 0 i\n\
            MouseMoveEvent 94 208 0 0 0 0 i\n\
            MouseMoveEvent 91 210 0 0 0 0 i\n\
            MouseMoveEvent 89 211 0 0 0 0 i\n\
            MouseMoveEvent 86 211 0 0 0 0 i\n\
            MouseMoveEvent 84 211 0 0 0 0 i\n\
            MouseMoveEvent 80 211 0 0 0 0 i\n\
            MouseMoveEvent 77 211 0 0 0 0 i\n\
            MouseMoveEvent 75 211 0 0 0 0 i\n\
            MouseMoveEvent 71 211 0 0 0 0 i\n\
            MouseMoveEvent 68 211 0 0 0 0 i\n\
            MouseMoveEvent 66 210 0 0 0 0 i\n\
            MouseMoveEvent 62 210 0 0 0 0 i\n\
            MouseMoveEvent 58 209 0 0 0 0 i\n\
            MouseMoveEvent 54 207 0 0 0 0 i\n\
            MouseMoveEvent 52 204 0 0 0 0 i\n\
            MouseMoveEvent 51 203 0 0 0 0 i\n\
            MouseMoveEvent 51 200 0 0 0 0 i\n\
            MouseMoveEvent 48 196 0 0 0 0 i\n\
            MouseMoveEvent 45 187 0 0 0 0 i\n\
            MouseMoveEvent 45 181 0 0 0 0 i\n\
            MouseMoveEvent 44 168 0 0 0 0 i\n\
            MouseMoveEvent 40 161 0 0 0 0 i\n\
            MouseMoveEvent 39 154 0 0 0 0 i\n\
            MouseMoveEvent 38 146 0 0 0 0 i\n\
            MouseMoveEvent 35 131 0 0 0 0 i\n\
            MouseMoveEvent 34 121 0 0 0 0 i\n\
            MouseMoveEvent 34 110 0 0 0 0 i\n\
            MouseMoveEvent 34 103 0 0 0 0 i\n\
            MouseMoveEvent 34 91 0 0 0 0 i\n\
            MouseMoveEvent 34 86 0 0 0 0 i\n\
            MouseMoveEvent 34 73 0 0 0 0 i\n\
            MouseMoveEvent 35 66 0 0 0 0 i\n\
            MouseMoveEvent 37 60 0 0 0 0 i\n\
            MouseMoveEvent 37 53 0 0 0 0 i\n\
            MouseMoveEvent 38 50 0 0 0 0 i\n\
            MouseMoveEvent 38 48 0 0 0 0 i\n\
            MouseMoveEvent 41 45 0 0 0 0 i\n\
            MouseMoveEvent 43 45 0 0 0 0 i\n\
            MouseMoveEvent 44 45 0 0 0 0 i\n\
            MouseMoveEvent 47 43 0 0 0 0 i\n\
            MouseMoveEvent 51 44 0 0 0 0 i\n\
            MouseMoveEvent 54 44 0 0 0 0 i\n\
            MouseMoveEvent 55 44 0 0 0 0 i\n\
            MouseMoveEvent 59 44 0 0 0 0 i\n\
            MouseMoveEvent 64 44 0 0 0 0 i\n\
            MouseMoveEvent 67 44 0 0 0 0 i\n\
            MouseMoveEvent 68 44 0 0 0 0 i\n\
            MouseMoveEvent 71 44 0 0 0 0 i\n\
            MouseMoveEvent 74 44 0 0 0 0 i\n\
            MouseMoveEvent 77 44 0 0 0 0 i\n\
            MouseMoveEvent 80 45 0 0 0 0 i\n\
            MouseMoveEvent 81 45 0 0 0 0 i\n\
            MouseMoveEvent 85 49 0 0 0 0 i\n\
            MouseMoveEvent 89 50 0 0 0 0 i\n\
            MouseMoveEvent 94 52 0 0 0 0 i\n\
            MouseMoveEvent 99 56 0 0 0 0 i\n\
            MouseMoveEvent 104 58 0 0 0 0 i\n\
            MouseMoveEvent 107 61 0 0 0 0 i\n\
            MouseMoveEvent 109 63 0 0 0 0 i\n\
            MouseMoveEvent 109 67 0 0 0 0 i\n\
            MouseMoveEvent 111 83 0 0 0 0 i\n\
            MouseMoveEvent 113 86 0 0 0 0 i\n\
            MouseMoveEvent 113 87 0 0 0 0 i\n\
            MouseMoveEvent 113 89 0 0 0 0 i\n\
            MouseMoveEvent 112 93 0 0 0 0 i\n\
            MouseMoveEvent 112 97 0 0 0 0 i\n\
            MouseMoveEvent 111 104 0 0 0 0 i\n\
            MouseMoveEvent 112 108 0 0 0 0 i\n\
            MouseMoveEvent 116 115 0 0 0 0 i\n\
            MouseMoveEvent 116 123 0 0 0 0 i\n\
            MouseMoveEvent 116 129 0 0 0 0 i\n\
            MouseMoveEvent 119 138 0 0 0 0 i\n\
            MouseMoveEvent 122 141 0 0 0 0 i\n\
            MouseMoveEvent 127 148 0 0 0 0 i\n\
            MouseMoveEvent 128 161 0 0 0 0 i\n\
            MouseMoveEvent 131 166 0 0 0 0 i\n\
            MouseMoveEvent 134 168 0 0 0 0 i\n\
            MouseMoveEvent 135 171 0 0 0 0 i\n\
            MouseMoveEvent 134 174 0 0 0 0 i\n\
            MouseMoveEvent 132 176 0 0 0 0 i\n\
            MouseMoveEvent 132 178 0 0 0 0 i\n\
            MouseMoveEvent 129 180 0 0 0 0 i\n\
            MouseMoveEvent 127 182 0 0 0 0 i\n\
            MouseMoveEvent 124 185 0 0 0 0 i\n\
            MouseMoveEvent 122 186 0 0 0 0 i\n\
            MouseMoveEvent 118 189 0 0 0 0 i\n\
            MouseMoveEvent 114 191 0 0 0 0 i\n\
            MouseMoveEvent 114 193 0 0 0 0 i\n\
            MouseMoveEvent 112 193 0 0 0 0 i\n\
            MouseMoveEvent 111 194 0 0 0 0 i\n\
            MouseMoveEvent 110 197 0 0 0 0 i\n\
            MouseMoveEvent 110 198 0 0 0 0 i\n\
            MouseMoveEvent 109 199 0 0 0 0 i\n\
            MouseMoveEvent 108 200 0 0 0 0 i\n\
            MouseMoveEvent 108 201 0 0 0 0 i\n\
            MouseMoveEvent 108 202 0 0 0 0 i\n\
            MouseMoveEvent 108 203 0 0 0 0 i\n\
            MouseMoveEvent 104 206 0 0 0 0 i\n\
            LeftButtonReleaseEvent 104 206 0 0 0 0 i\n\
            MouseMoveEvent 104 205 0 0 0 0 i\n\
            MouseMoveEvent 104 204 0 0 0 0 i\n\
            MouseMoveEvent 105 205 0 0 0 0 i\n\
            MouseMoveEvent 105 206 0 0 0 0 i\n\
        "

        # Start by loading some data.
        #
        dem = vtk.vtkDEMReader()
        dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem")
        dem.Update()

        Scale = 2
        lut = vtk.vtkLookupTable()
        lut.SetHueRange(0.6, 0)
        lut.SetSaturationRange(1.0, 0)
        lut.SetValueRange(0.5, 1.0)
        lo = Scale * dem.GetElevationBounds()[0]

        hi = Scale * dem.GetElevationBounds()[1]

        shrink = vtk.vtkImageShrink3D()
        shrink.SetShrinkFactors(4, 4, 1)
        shrink.SetInputConnection(dem.GetOutputPort())
        shrink.AveragingOn()

        geom = vtk.vtkImageDataGeometryFilter()
        geom.SetInputConnection(shrink.GetOutputPort())
        geom.ReleaseDataFlagOn()

        warp = vtk.vtkWarpScalar()
        warp.SetInputConnection(geom.GetOutputPort())
        warp.SetNormal(0, 0, 1)
        warp.UseNormalOn()
        warp.SetScaleFactor(Scale)
        warp.ReleaseDataFlagOn()

        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(warp.GetOutputPort())
        elevation.SetLowPoint(0, 0, lo)
        elevation.SetHighPoint(0, 0, hi)
        elevation.SetScalarRange(lo, hi)
        elevation.ReleaseDataFlagOn()

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(elevation.GetOutputPort())
        normals.SetFeatureAngle(60)
        normals.ConsistencyOff()
        normals.SplittingOff()
        normals.ReleaseDataFlagOn()
        normals.Update()

        demMapper = vtk.vtkPolyDataMapper()
        demMapper.SetInputConnection(normals.GetOutputPort())
        demMapper.SetScalarRange(lo, hi)
        demMapper.SetLookupTable(lut)
        demMapper.ImmediateModeRenderingOn()

        demActor = vtk.vtkActor()
        demActor.SetMapper(demMapper)

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetMultiSamples(0)
        renWin.AddRenderer(ren)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)
        iRen.LightFollowCameraOff()

        #    iRen.SetInteractorStyle("")

        # The callback takes two arguments.
        # The first being the object that generates the event and
        # the second argument the event name (which is a string).
        def MoveLight(widget, event_string):
            light.SetPosition(rep.GetHandlePosition())

        # Associate the line widget with the interactor
        rep = vtk.vtkSphereRepresentation()
        rep.SetPlaceFactor(4)
        rep.PlaceWidget(normals.GetOutput().GetBounds())
        rep.HandleVisibilityOn()
        rep.SetRepresentationToWireframe()
        #  rep HandleVisibilityOff
        #  rep HandleTextOff
        sphereWidget = vtk.vtkSphereWidget2()
        sphereWidget.SetInteractor(iRen)
        sphereWidget.SetRepresentation(rep)
        #  sphereWidget.TranslationEnabledOff()
        #  sphereWidget.ScalingEnabledOff()
        sphereWidget.AddObserver("InteractionEvent", MoveLight)

        recorder = vtk.vtkInteractorEventRecorder()
        recorder.SetInteractor(iRen)
        #  recorder.SetFileName("c:/record.log")
        #  recorder.Record()
        recorder.ReadFromInputStringOn()
        recorder.SetInputString(Recording)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(demActor)
        ren.SetBackground(1, 1, 1)
        renWin.SetSize(300, 300)
        ren.SetBackground(0.1, 0.2, 0.4)

        cam1 = ren.GetActiveCamera()
        cam1.SetViewUp(0, 0, 1)
        cam1.SetFocalPoint(dem.GetOutput().GetCenter())
        cam1.SetPosition(1, 0, 0)
        ren.ResetCamera()
        cam1.Elevation(25)
        cam1.Azimuth(125)
        cam1.Zoom(1.25)

        light = vtk.vtkLight()
        light.SetFocalPoint(rep.GetCenter())
        light.SetPosition(rep.GetHandlePosition())
        ren.AddLight(light)

        iRen.Initialize()
        renWin.Render()

        # render the image
        renWin.Render()

        # Actually probe the data
        recorder.Play()

        img_file = "TestSphereWidget.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
Example #49
0
    def __init__(self, render_window_interactor, widget,config=None):

        # render_window_interactor.Initialize()
        # render_window_interactor.Start()
        self.configure(config)
        self.iren = render_window_interactor
        self.ren_win = render_window_interactor.GetRenderWindow()
        self.ren = vtk.vtkRenderer()
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground2(self.BACKGROUND2)
        self.ren.SetBackground(self.BACKGROUND1)
        self.ren.SetUseDepthPeeling(1)
        self.ren_win.SetMultiSamples(0)
        self.ren_win.AlphaBitPlanesOn()
        self.ren.SetOcclusionRatio(0.1)
        self.ren_win.AddRenderer(self.ren)

        self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())

        self.light = vtk.vtkLight()
        self.ren.AddLight(self.light)
        self.light.SetLightTypeToSceneLight()
        self.light.SetPositional(0)


        self.light2 = vtk.vtkLight()
        self.ren.AddLight(self.light2)
        self.light2.SetLightTypeToSceneLight()
        self.light2.SetPositional(0)

        self.light3 = vtk.vtkLight()
        self.ren.AddLight(self.light3)
        self.light3.SetLightTypeToSceneLight()
        self.light3.SetPositional(0)

        self.picker = vtk.vtkCellPicker()
        self.picker.SetTolerance(0.0005)
        self.iren.SetPicker(self.picker)

        self.experiment = None
        self.__cylinder_actors = {}
        self.__line_actors = {}
        self.__cone_actors = {}
        self.__cone_sources = {}
        self.__error_triple = None
        self.__temp_sample = None
        self.__highlighted_actors = []

        #orientation axes
        axes_actor = vtk.vtkAnnotatedCubeActor()
        axes_actor.SetXPlusFaceText("R")
        axes_actor.SetXMinusFaceText("L")
        axes_actor.SetYPlusFaceText("P")
        axes_actor.SetYMinusFaceText("I ")
        axes_actor.SetZPlusFaceText("B")
        axes_actor.SetZMinusFaceText("F")

        axes_actor.GetTextEdgesProperty().SetColor(1, 1, 1)
        axes_actor.GetTextEdgesProperty().SetLineWidth(2)
        axes_actor.GetCubeProperty().SetColor(0.3, 0.3, 0.3)
        axes_actor.SetTextEdgesVisibility(1)
        axes_actor.SetFaceTextVisibility(0)

        axes_actor.SetZFaceTextRotation(90)
        axes_actor.SetXFaceTextRotation(-90)

        axes = vtk.vtkOrientationMarkerWidget()
        axes.SetOrientationMarker(axes_actor)
        axes.SetViewport(0.01, 0.01, 0.2, 0.2)

        self.axes = axes
        self.axes_actor = axes_actor


        self.axes.SetInteractor(self.iren)
        self.axes.EnabledOn()
        self.axes.InteractiveOff()

        self.__widget = widget

        if self.SHADOWS:
            opaque_sequence = vtk.vtkSequencePass()
            passes2 = vtk.vtkRenderPassCollection()
            opaque = vtk.vtkOpaquePass()
            lights = vtk.vtkLightsPass()
            peeling = vtk.vtkDepthPeelingPass()
            translucent = vtk.vtkTranslucentPass()
            peeling.SetTranslucentPass(translucent)
            passes2.AddItem(lights)
            passes2.AddItem(opaque)
            opaque_sequence.SetPasses(passes2)

            opaque_camera_pass = vtk.vtkCameraPass()
            opaque_camera_pass.SetDelegatePass(opaque_sequence)

            shadow_baker = vtk.vtkShadowMapBakerPass()
            shadow_baker.SetOpaquePass(opaque_camera_pass)

            shadow_baker.SetResolution(2**12)
            shadow_baker.SetPolygonOffsetFactor(3.1)
            shadow_baker.SetPolygonOffsetUnits(10.0)

            shadows = vtk.vtkShadowMapPass()
            shadows.SetShadowMapBakerPass(shadow_baker)

            shadows.SetOpaquePass(opaque_sequence)

            seq = vtk.vtkSequencePass()
            passes = vtk.vtkRenderPassCollection()
            seq.SetPasses(passes)
            passes.AddItem(shadow_baker)
            passes.AddItem(shadows)

            passes.AddItem(lights)
            passes.AddItem(peeling)
            passes.AddItem(vtk.vtkVolumetricPass())

            cameraP = vtk.vtkCameraPass()
            cameraP.SetDelegatePass(seq)
            self.ren.SetPass(cameraP)
Example #50
0
def main():

  fn0 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp";
  fn0c = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp";
  fn0t = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/metal.jpg";
  fn3 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Probe/tip.vtp";
  fn3c = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp";
  fn4 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Organs/ball.vtp";
  fn4c = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Organs/ball_col_bb.vtp";
  fn4tl = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/leftball.jpg";
  fn4tr = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/rightball.jpg";
  fn4tb = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/bothball.jpg";
  fn5 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Organs/cavity.vtp";
  fn5t = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/intestine2.jpg";

  #Create scenario
  scenario = vtkesqui.vtkScenario()
  scenario.SetName("vtkESQui - Laparoscopy (Precission & Speed)")

  # Left Tool (Probe)
  # Visualization model
  vis_stick_l = vtkesqui.vtkVisualizationModel()
  vis_stick_l.SetName("vis_stick_l")
  vis_stick_l.SetFileName(fn0)
  vis_stick_l.SetTextureFileName(fn0t)
  vis_stick_l.SetOpacity(1.0)
  vis_stick_l.SetColor(1.0, 1.0, 1.0)
  
  # Collision model
  col_stick_l = vtkesqui.vtkCollisionModel()
  col_stick_l.SetName("col_stick_l_vtkbioeng")
  col_stick_l.SetFileName(fn0c)
  col_stick_l.SetVisibility(0.0)
  
  # First tool element (stick_l)
  stick_l = vtkesqui.vtkScenarioElement()
  stick_l.SetName("stick_l")
  stick_l.SetPosition(-4.0, 0.0, 0.0)
  stick_l.SetOrientation(0, 0, 20)
  stick_l.SetOrigin(0,0,6)
  stick_l.SetVisualizationModel(vis_stick_l)
  stick_l.SetCollisionModel(col_stick_l)
  
  # Visualization model
  vis_tip_l = vtkesqui.vtkVisualizationModel()
  vis_tip_l.SetName("vis_tip_l")
  vis_tip_l.SetFileName(fn3)
  vis_tip_l.SetTextureFileName(fn0t)
  vis_tip_l.SetOpacity(1.0)
  vis_tip_l.SetColor(1.0, 0.0, 0.0)
  
  # Collision model
  col_tip_l = vtkesqui.vtkCollisionModel()
  col_tip_l.SetName("col_tip_l_vtkbioeng")
  col_tip_l.SetFileName(fn3c)
  col_tip_l.SetVisibility(0.0)
  
  # Second tool element (tip_l)
  tip_l = vtkesqui.vtkScenarioElement()
  tip_l.SetName("tip_l")
  tip_l.SetPosition(-4.0, 0.0, 0.0)
  tip_l.SetOrientation(0, 0, 20)
  tip_l.SetOrigin(0,0,6)
  tip_l.SetVisualizationModel(vis_tip_l)
  tip_l.SetCollisionModel(col_tip_l)
  
  probe_l = vtkesqui.vtkToolProbe()
  probe_l.AddElement(stick_l)
  probe_l.AddElement(tip_l)
  scenario.AddObject(probe_l)
  
  # Right tool (Grasper)
   # Visualization model
  vis_stick_r = vtkesqui.vtkVisualizationModel()
  vis_stick_r.SetName("vis_stick_r")
  vis_stick_r.SetFileName(fn0)
  vis_stick_r.SetTextureFileName(fn0t)
  vis_stick_r.SetOpacity(1.0)
  vis_stick_r.SetColor(1.0, 1.0, 1.0)
  
  # Collision model
  col_stick_r = vtkesqui.vtkCollisionModel()
  col_stick_r.SetName("col_stick_r_vtkbioeng")
  col_stick_r.SetFileName(fn0c)
  col_stick_r.SetVisibility(0.0)
  
  # First tool element (stick_r)
  stick_r = vtkesqui.vtkScenarioElement()
  stick_r.SetName("stick_r")
  stick_r.SetPosition(4.0, 0.0, 0.0)
  stick_r.SetOrientation(0, 0, 20)
  stick_r.SetOrigin(0,0,6)
  stick_r.SetVisualizationModel(vis_stick_r)
  stick_r.SetCollisionModel(col_stick_r)
  
  # Visualization model
  vis_tip_r = vtkesqui.vtkVisualizationModel()
  vis_tip_r.SetName("vis_tip_r")
  vis_tip_r.SetFileName(fn3)
  vis_tip_r.SetTextureFileName(fn0t)
  vis_tip_r.SetOpacity(1.0)
  vis_tip_r.SetColor(0.0, 1.0, 0.0)
  
  # Collision model
  col_tip_r = vtkesqui.vtkCollisionModel()
  col_tip_r.SetName("col_tip_r_vtkbioeng")
  col_tip_r.SetFileName(fn3c)
  col_tip_r.SetVisibility(0.0)
  
  # Second tool element (tip_r)
  tip_r = vtkesqui.vtkScenarioElement()
  tip_r.SetName("tip_r")
  tip_r.SetPosition(4.0, 0.0, 0.0)
  tip_r.SetOrientation(0, 0, 20)
  tip_r.SetOrigin(0,0,6)
  tip_r.SetVisualizationModel(vis_tip_r)
  tip_r.SetCollisionModel(col_tip_r)
  
  probe_r = vtkesqui.vtkToolProbe()
  probe_r.AddElement(stick_r)
  probe_r.AddElement(tip_r)
  scenario.AddObject(probe_r)
  
  # Add an Organ (Cavity)
  # Visualization model
  vis_cavity = vtkesqui.vtkVisualizationModel()
  vis_cavity.SetName("vis_cavity")
  vis_cavity.SetFileName(fn5)
  vis_cavity.SetTextureFileName(fn5t)
  vis_cavity.SetOpacity(1.0)
  
  # Organ element (cavity)
  e_cavity = vtkesqui.vtkScenarioElement()
  e_cavity.SetName("e_cavity")
  e_cavity.SetPosition(0.0, 0.0, -3.0)
  e_cavity.SetOrientation(-45, 0, 0)
  e_cavity.SetVisualizationModel(vis_cavity)
  
  cavity = vtkesqui.vtkOrgan()
  cavity.SetName("cavity")
  cavity.AddElement(e_cavity)
  scenario.AddObject(cavity)
  
  # Organs
  balls = list()
  textures = list()
  textures.append(fn4tl)
  textures.append(fn4tr)
  textures.append(fn4tb)
  
  reader = vtk.vtkXMLPolyDataReader()
  reader.SetFileName(fn4)
  reader.Update()
  
  readerc = vtk.vtkXMLPolyDataReader()
  readerc.SetFileName(fn4c)
  readerc.Update()
  
  for i in range(9):
    
    # Define organ type
    # 3 organs of each type (left, right and both)
    t = i%3
    px = int(i/3)
    
    # Add a ball
    # Visualization model
    vis_ball = vtkesqui.vtkVisualizationModel()
    vis_ball.SetName("vis_ball"+str(i))
    vis_ball.SetFileName(fn4)
    vis_ball.SetTextureFileName(textures[t])
    vis_ball.SetOpacity(1.0)
  
    # Collision model
    col_ball = vtkesqui.vtkCollisionModel()
    col_ball.SetName("col_ball_vtkbioeng"+str(i))
    col_ball.SetFileName(fn4c)
    col_ball.SetVisibility(0.0)
    col_ball.SetOpacity(0.0)

    # Organ element (ball)
    #x = -3 + i*2.0
    e_ball = vtkesqui.vtkScenarioElement()
    e_ball.SetName("e_ball"+str(i))
    e_ball.SetPosition(px-1, -2*t, -3)
    e_ball.SetOrientation(15, -0, 0)
    e_ball.SetVisualizationModel(vis_ball)
    e_ball.SetCollisionModel(col_ball)
  
    ball = vtkesqui.vtkOrgan()
    ball.SetName("ball_"+str(i)+"_"+str(t))
    ball.AddElement(e_ball)
    ball.Update()
    ball.Disable()

    scenario.AddObject(ball)
    balls.append(ball)
  
  # Scenario camera
  camera = vtk.vtkCamera()
  camera.SetPosition(0, 0, 6)
  camera.SetFocalPoint(0, 0, -6)
  camera.Yaw(0)
  camera.Elevation(20)
  camera.Pitch(-15)
  camera.ParallelProjectionOff()
  camera.SetViewAngle(70)
  camera.Dolly(1.2)
  scenario.SetCamera(camera)
  
  #/********** Lights  **********/
  headLight = vtk.vtkLight()
  headLight.SetLightTypeToHeadlight()
  headLight.PositionalOn()
  headLight.SetIntensity(0.8)
  headLight.SetConeAngle(60)
  scenario.AddLight(headLight)
  
  ambientLight = vtk.vtkLight()
  ambientLight.SetLightTypeToSceneLight()
  ambientLight.PositionalOff()
  ambientLight.SetIntensity(0.1)
  scenario.AddLight(ambientLight)

  simulation = vtkesqui.vtkSimulation()
  simulation.SetScenario(scenario)
  simulation.SetRenderTimerRate(30)
  simulation.SetSimulationTimerRate(1)
  simulation.SetInteractionTimerRate(1)
  simulation.InteractionOn()
  simulation.CollisionOn()
  simulation.Initialize()
  
  #Wait for initialization to set collision mode
  simulation.SetCollisionModeToSimple()
  
  # Sign up to receive TimerEvent
  iren = scenario.GetRenderWindowInteractor()
  cb = vtkTimerCallback()
  iren.AddObserver('TimerEvent', cb.execute)
  # 100ms timer
  timerId = iren.CreateRepeatingTimer(100);
  cb.simulation = simulation
  cb.organs = balls
  
  simulation.Run()
    def testSphereWidget(self):

        # This example demonstrates how to use the vtkSphereWidget to control the
        # position of a light.

        # These are the pre-recorded events
        Recording = \
           "# StreamVersion 1\n\
            CharEvent 23 266 0 0 105 1 i\n\
            KeyReleaseEvent 23 266 0 0 105 1 i\n\
            EnterEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 68 293 0 0 0 0 i\n\
            MouseMoveEvent 67 292 0 0 0 0 i\n\
            MouseMoveEvent 66 289 0 0 0 0 i\n\
            MouseMoveEvent 66 282 0 0 0 0 i\n\
            MouseMoveEvent 66 271 0 0 0 0 i\n\
            MouseMoveEvent 69 253 0 0 0 0 i\n\
            MouseMoveEvent 71 236 0 0 0 0 i\n\
            MouseMoveEvent 74 219 0 0 0 0 i\n\
            MouseMoveEvent 76 208 0 0 0 0 i\n\
            MouseMoveEvent 78 190 0 0 0 0 i\n\
            MouseMoveEvent 78 173 0 0 0 0 i\n\
            MouseMoveEvent 77 162 0 0 0 0 i\n\
            MouseMoveEvent 77 151 0 0 0 0 i\n\
            MouseMoveEvent 77 139 0 0 0 0 i\n\
            MouseMoveEvent 76 125 0 0 0 0 i\n\
            MouseMoveEvent 73 114 0 0 0 0 i\n\
            MouseMoveEvent 73 106 0 0 0 0 i\n\
            MouseMoveEvent 73 101 0 0 0 0 i\n\
            MouseMoveEvent 72 95 0 0 0 0 i\n\
            MouseMoveEvent 72 92 0 0 0 0 i\n\
            MouseMoveEvent 70 89 0 0 0 0 i\n\
            MouseMoveEvent 69 86 0 0 0 0 i\n\
            MouseMoveEvent 67 84 0 0 0 0 i\n\
            MouseMoveEvent 65 81 0 0 0 0 i\n\
            MouseMoveEvent 60 79 0 0 0 0 i\n\
            MouseMoveEvent 59 79 0 0 0 0 i\n\
            MouseMoveEvent 58 79 0 0 0 0 i\n\
            MouseMoveEvent 57 78 0 0 0 0 i\n\
            MouseMoveEvent 55 78 0 0 0 0 i\n\
            MouseMoveEvent 54 77 0 0 0 0 i\n\
            LeftButtonPressEvent 54 77 0 0 0 0 i\n\
            MouseMoveEvent 61 79 0 0 0 0 i\n\
            MouseMoveEvent 67 83 0 0 0 0 i\n\
            MouseMoveEvent 72 88 0 0 0 0 i\n\
            MouseMoveEvent 77 90 0 0 0 0 i\n\
            MouseMoveEvent 78 91 0 0 0 0 i\n\
            MouseMoveEvent 80 92 0 0 0 0 i\n\
            MouseMoveEvent 84 93 0 0 0 0 i\n\
            MouseMoveEvent 85 94 0 0 0 0 i\n\
            MouseMoveEvent 88 97 0 0 0 0 i\n\
            MouseMoveEvent 90 100 0 0 0 0 i\n\
            MouseMoveEvent 92 102 0 0 0 0 i\n\
            MouseMoveEvent 94 103 0 0 0 0 i\n\
            MouseMoveEvent 97 105 0 0 0 0 i\n\
            MouseMoveEvent 101 107 0 0 0 0 i\n\
            MouseMoveEvent 102 109 0 0 0 0 i\n\
            MouseMoveEvent 104 111 0 0 0 0 i\n\
            MouseMoveEvent 108 113 0 0 0 0 i\n\
            MouseMoveEvent 112 115 0 0 0 0 i\n\
            MouseMoveEvent 118 119 0 0 0 0 i\n\
            MouseMoveEvent 118 120 0 0 0 0 i\n\
            MouseMoveEvent 118 123 0 0 0 0 i\n\
            MouseMoveEvent 120 125 0 0 0 0 i\n\
            MouseMoveEvent 122 128 0 0 0 0 i\n\
            MouseMoveEvent 123 129 0 0 0 0 i\n\
            MouseMoveEvent 125 132 0 0 0 0 i\n\
            MouseMoveEvent 125 134 0 0 0 0 i\n\
            MouseMoveEvent 127 138 0 0 0 0 i\n\
            MouseMoveEvent 127 142 0 0 0 0 i\n\
            MouseMoveEvent 127 147 0 0 0 0 i\n\
            MouseMoveEvent 126 152 0 0 0 0 i\n\
            MouseMoveEvent 126 155 0 0 0 0 i\n\
            MouseMoveEvent 125 160 0 0 0 0 i\n\
            MouseMoveEvent 125 167 0 0 0 0 i\n\
            MouseMoveEvent 125 169 0 0 0 0 i\n\
            MouseMoveEvent 125 174 0 0 0 0 i\n\
            MouseMoveEvent 122 179 0 0 0 0 i\n\
            MouseMoveEvent 120 183 0 0 0 0 i\n\
            MouseMoveEvent 116 187 0 0 0 0 i\n\
            MouseMoveEvent 113 192 0 0 0 0 i\n\
            MouseMoveEvent 113 193 0 0 0 0 i\n\
            MouseMoveEvent 111 195 0 0 0 0 i\n\
            MouseMoveEvent 108 198 0 0 0 0 i\n\
            MouseMoveEvent 106 200 0 0 0 0 i\n\
            MouseMoveEvent 104 202 0 0 0 0 i\n\
            MouseMoveEvent 103 203 0 0 0 0 i\n\
            MouseMoveEvent 99 205 0 0 0 0 i\n\
            MouseMoveEvent 97 207 0 0 0 0 i\n\
            MouseMoveEvent 94 208 0 0 0 0 i\n\
            MouseMoveEvent 91 210 0 0 0 0 i\n\
            MouseMoveEvent 89 211 0 0 0 0 i\n\
            MouseMoveEvent 86 211 0 0 0 0 i\n\
            MouseMoveEvent 84 211 0 0 0 0 i\n\
            MouseMoveEvent 80 211 0 0 0 0 i\n\
            MouseMoveEvent 77 211 0 0 0 0 i\n\
            MouseMoveEvent 75 211 0 0 0 0 i\n\
            MouseMoveEvent 71 211 0 0 0 0 i\n\
            MouseMoveEvent 68 211 0 0 0 0 i\n\
            MouseMoveEvent 66 210 0 0 0 0 i\n\
            MouseMoveEvent 62 210 0 0 0 0 i\n\
            MouseMoveEvent 58 209 0 0 0 0 i\n\
            MouseMoveEvent 54 207 0 0 0 0 i\n\
            MouseMoveEvent 52 204 0 0 0 0 i\n\
            MouseMoveEvent 51 203 0 0 0 0 i\n\
            MouseMoveEvent 51 200 0 0 0 0 i\n\
            MouseMoveEvent 48 196 0 0 0 0 i\n\
            MouseMoveEvent 45 187 0 0 0 0 i\n\
            MouseMoveEvent 45 181 0 0 0 0 i\n\
            MouseMoveEvent 44 168 0 0 0 0 i\n\
            MouseMoveEvent 40 161 0 0 0 0 i\n\
            MouseMoveEvent 39 154 0 0 0 0 i\n\
            MouseMoveEvent 38 146 0 0 0 0 i\n\
            MouseMoveEvent 35 131 0 0 0 0 i\n\
            MouseMoveEvent 34 121 0 0 0 0 i\n\
            MouseMoveEvent 34 110 0 0 0 0 i\n\
            MouseMoveEvent 34 103 0 0 0 0 i\n\
            MouseMoveEvent 34 91 0 0 0 0 i\n\
            MouseMoveEvent 34 86 0 0 0 0 i\n\
            MouseMoveEvent 34 73 0 0 0 0 i\n\
            MouseMoveEvent 35 66 0 0 0 0 i\n\
            MouseMoveEvent 37 60 0 0 0 0 i\n\
            MouseMoveEvent 37 53 0 0 0 0 i\n\
            MouseMoveEvent 38 50 0 0 0 0 i\n\
            MouseMoveEvent 38 48 0 0 0 0 i\n\
            MouseMoveEvent 41 45 0 0 0 0 i\n\
            MouseMoveEvent 43 45 0 0 0 0 i\n\
            MouseMoveEvent 44 45 0 0 0 0 i\n\
            MouseMoveEvent 47 43 0 0 0 0 i\n\
            MouseMoveEvent 51 44 0 0 0 0 i\n\
            MouseMoveEvent 54 44 0 0 0 0 i\n\
            MouseMoveEvent 55 44 0 0 0 0 i\n\
            MouseMoveEvent 59 44 0 0 0 0 i\n\
            MouseMoveEvent 64 44 0 0 0 0 i\n\
            MouseMoveEvent 67 44 0 0 0 0 i\n\
            MouseMoveEvent 68 44 0 0 0 0 i\n\
            MouseMoveEvent 71 44 0 0 0 0 i\n\
            MouseMoveEvent 74 44 0 0 0 0 i\n\
            MouseMoveEvent 77 44 0 0 0 0 i\n\
            MouseMoveEvent 80 45 0 0 0 0 i\n\
            MouseMoveEvent 81 45 0 0 0 0 i\n\
            MouseMoveEvent 85 49 0 0 0 0 i\n\
            MouseMoveEvent 89 50 0 0 0 0 i\n\
            MouseMoveEvent 94 52 0 0 0 0 i\n\
            MouseMoveEvent 99 56 0 0 0 0 i\n\
            MouseMoveEvent 104 58 0 0 0 0 i\n\
            MouseMoveEvent 107 61 0 0 0 0 i\n\
            MouseMoveEvent 109 63 0 0 0 0 i\n\
            MouseMoveEvent 109 67 0 0 0 0 i\n\
            MouseMoveEvent 111 83 0 0 0 0 i\n\
            MouseMoveEvent 113 86 0 0 0 0 i\n\
            MouseMoveEvent 113 87 0 0 0 0 i\n\
            MouseMoveEvent 113 89 0 0 0 0 i\n\
            MouseMoveEvent 112 93 0 0 0 0 i\n\
            MouseMoveEvent 112 97 0 0 0 0 i\n\
            MouseMoveEvent 111 104 0 0 0 0 i\n\
            MouseMoveEvent 112 108 0 0 0 0 i\n\
            MouseMoveEvent 116 115 0 0 0 0 i\n\
            MouseMoveEvent 116 123 0 0 0 0 i\n\
            MouseMoveEvent 116 129 0 0 0 0 i\n\
            MouseMoveEvent 119 138 0 0 0 0 i\n\
            MouseMoveEvent 122 141 0 0 0 0 i\n\
            MouseMoveEvent 127 148 0 0 0 0 i\n\
            MouseMoveEvent 128 161 0 0 0 0 i\n\
            MouseMoveEvent 131 166 0 0 0 0 i\n\
            MouseMoveEvent 134 168 0 0 0 0 i\n\
            MouseMoveEvent 135 171 0 0 0 0 i\n\
            MouseMoveEvent 134 174 0 0 0 0 i\n\
            MouseMoveEvent 132 176 0 0 0 0 i\n\
            MouseMoveEvent 132 178 0 0 0 0 i\n\
            MouseMoveEvent 129 180 0 0 0 0 i\n\
            MouseMoveEvent 127 182 0 0 0 0 i\n\
            MouseMoveEvent 124 185 0 0 0 0 i\n\
            MouseMoveEvent 122 186 0 0 0 0 i\n\
            MouseMoveEvent 118 189 0 0 0 0 i\n\
            MouseMoveEvent 114 191 0 0 0 0 i\n\
            MouseMoveEvent 114 193 0 0 0 0 i\n\
            MouseMoveEvent 112 193 0 0 0 0 i\n\
            MouseMoveEvent 111 194 0 0 0 0 i\n\
            MouseMoveEvent 110 197 0 0 0 0 i\n\
            MouseMoveEvent 110 198 0 0 0 0 i\n\
            MouseMoveEvent 109 199 0 0 0 0 i\n\
            MouseMoveEvent 108 200 0 0 0 0 i\n\
            MouseMoveEvent 108 201 0 0 0 0 i\n\
            MouseMoveEvent 108 202 0 0 0 0 i\n\
            MouseMoveEvent 108 203 0 0 0 0 i\n\
            MouseMoveEvent 104 206 0 0 0 0 i\n\
            LeftButtonReleaseEvent 104 206 0 0 0 0 i\n\
            MouseMoveEvent 104 205 0 0 0 0 i\n\
            MouseMoveEvent 104 204 0 0 0 0 i\n\
            MouseMoveEvent 105 205 0 0 0 0 i\n\
            MouseMoveEvent 105 206 0 0 0 0 i\n\
        "

        # Start by loading some data.
        #
        dem = vtk.vtkDEMReader()
        dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem")
        dem.Update()

        Scale = 2
        lut = vtk.vtkLookupTable()
        lut.SetHueRange(0.6, 0)
        lut.SetSaturationRange(1.0, 0)
        lut.SetValueRange(0.5, 1.0)
        lo = Scale * dem.GetElevationBounds()[0]

        hi = Scale * dem.GetElevationBounds()[1]


        shrink = vtk.vtkImageShrink3D()
        shrink.SetShrinkFactors(4, 4, 1)
        shrink.SetInputConnection(dem.GetOutputPort())
        shrink.AveragingOn()

        geom = vtk.vtkImageDataGeometryFilter()
        geom.SetInputConnection(shrink.GetOutputPort())
        geom.ReleaseDataFlagOn()

        warp = vtk.vtkWarpScalar()
        warp.SetInputConnection(geom.GetOutputPort())
        warp.SetNormal(0, 0, 1)
        warp.UseNormalOn()
        warp.SetScaleFactor(Scale)
        warp.ReleaseDataFlagOn()

        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(warp.GetOutputPort())
        elevation.SetLowPoint(0, 0, lo)
        elevation.SetHighPoint(0, 0, hi)
        elevation.SetScalarRange(lo, hi)
        elevation.ReleaseDataFlagOn()

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(elevation.GetOutputPort())
        normals.SetFeatureAngle(60)
        normals.ConsistencyOff()
        normals.SplittingOff()
        normals.ReleaseDataFlagOn()
        normals.Update()

        demMapper = vtk.vtkPolyDataMapper()
        demMapper.SetInputConnection(normals.GetOutputPort())
        demMapper.SetScalarRange(lo, hi)
        demMapper.SetLookupTable(lut)

        demActor = vtk.vtkActor()
        demActor.SetMapper(demMapper)

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetMultiSamples(0)
        renWin.AddRenderer(ren)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)
        iRen.LightFollowCameraOff()
        #    iRen.SetInteractorStyle("")

        # The callback takes two arguments.
        # The first being the object that generates the event and
        # the second argument the event name (which is a string).
        def MoveLight(widget, event_string):
            light.SetPosition(rep.GetHandlePosition())

        # Associate the line widget with the interactor
        rep = vtk.vtkSphereRepresentation()
        rep.SetPlaceFactor(4)
        rep.PlaceWidget(normals.GetOutput().GetBounds())
        rep.HandleVisibilityOn()
        rep.SetRepresentationToWireframe()
        #  rep HandleVisibilityOff
        #  rep HandleTextOff
        sphereWidget = vtk.vtkSphereWidget2()
        sphereWidget.SetInteractor(iRen)
        sphereWidget.SetRepresentation(rep)
        #  sphereWidget.TranslationEnabledOff()
        #  sphereWidget.ScalingEnabledOff()
        sphereWidget.AddObserver("InteractionEvent", MoveLight)

        recorder = vtk.vtkInteractorEventRecorder()
        recorder.SetInteractor(iRen)
        #  recorder.SetFileName("c:/record.log")
        #  recorder.Record()
        recorder.ReadFromInputStringOn()
        recorder.SetInputString(Recording)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(demActor)
        ren.SetBackground(1, 1, 1)
        renWin.SetSize(300, 300)
        ren.SetBackground(0.1, 0.2, 0.4)

        cam1 = ren.GetActiveCamera()
        cam1.SetViewUp(0, 0, 1)
        cam1.SetFocalPoint(dem.GetOutput().GetCenter())
        cam1.SetPosition(1, 0, 0)
        ren.ResetCamera()
        cam1.Elevation(25)
        cam1.Azimuth(125)
        cam1.Zoom(1.25)

        light = vtk.vtkLight()
        light.SetFocalPoint(rep.GetCenter())
        light.SetPosition(rep.GetHandlePosition())
        ren.AddLight(light)

        iRen.Initialize()
        renWin.Render()

        # render the image
        renWin.Render()

        # Actually probe the data
        recorder.Play()

        img_file = "TestSphereWidget.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
def main():

    fn0 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Grasper/stick.vtp"
    fn0c = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Grasper/stick_col.vtp"
    fn0t = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/metal.jpg"
    fn3 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Probe/tip.vtp"
    fn3c = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Tools/Probe/tip_col.vtp"
    fn4 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Organs/ball.vtp"
    fn4c = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Organs/ball_col_bb.vtp"
    fn4tl = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/leftball.jpg"
    fn4tr = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/rightball.jpg"
    fn4tb = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/bothball.jpg"
    fn5 = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Organs/cavity.vtp"
    fn5t = "/home/jballesteros/Workspace/data/vtkESQuiData/Scenario/Textures/intestine2.jpg"

    #Create scenario
    scenario = vtkesqui.vtkScenario()
    scenario.SetName("vtkESQui - Laparoscopy (Precission & Speed)")

    # Left Tool (Probe)
    # Visualization model
    vis_stick_l = vtkesqui.vtkVisualizationModel()
    vis_stick_l.SetName("vis_stick_l")
    vis_stick_l.SetFileName(fn0)
    vis_stick_l.SetTextureFileName(fn0t)
    vis_stick_l.SetOpacity(1.0)
    vis_stick_l.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_l = vtkesqui.vtkCollisionModel()
    col_stick_l.SetName("col_stick_l_vtkbioeng")
    col_stick_l.SetFileName(fn0c)
    col_stick_l.SetVisibility(0.0)

    # First tool element (stick_l)
    stick_l = vtkesqui.vtkScenarioElement()
    stick_l.SetName("stick_l")
    stick_l.SetPosition(-4.0, 0.0, 0.0)
    stick_l.SetOrientation(0, 0, 20)
    stick_l.SetOrigin(0, 0, 6)
    stick_l.SetVisualizationModel(vis_stick_l)
    stick_l.SetCollisionModel(col_stick_l)

    # Visualization model
    vis_tip_l = vtkesqui.vtkVisualizationModel()
    vis_tip_l.SetName("vis_tip_l")
    vis_tip_l.SetFileName(fn3)
    vis_tip_l.SetTextureFileName(fn0t)
    vis_tip_l.SetOpacity(1.0)
    vis_tip_l.SetColor(1.0, 0.0, 0.0)

    # Collision model
    col_tip_l = vtkesqui.vtkCollisionModel()
    col_tip_l.SetName("col_tip_l_vtkbioeng")
    col_tip_l.SetFileName(fn3c)
    col_tip_l.SetVisibility(0.0)

    # Second tool element (tip_l)
    tip_l = vtkesqui.vtkScenarioElement()
    tip_l.SetName("tip_l")
    tip_l.SetPosition(-4.0, 0.0, 0.0)
    tip_l.SetOrientation(0, 0, 20)
    tip_l.SetOrigin(0, 0, 6)
    tip_l.SetVisualizationModel(vis_tip_l)
    tip_l.SetCollisionModel(col_tip_l)

    probe_l = vtkesqui.vtkToolProbe()
    probe_l.AddElement(stick_l)
    probe_l.AddElement(tip_l)
    scenario.AddObject(probe_l)

    # Right tool (Grasper)
    # Visualization model
    vis_stick_r = vtkesqui.vtkVisualizationModel()
    vis_stick_r.SetName("vis_stick_r")
    vis_stick_r.SetFileName(fn0)
    vis_stick_r.SetTextureFileName(fn0t)
    vis_stick_r.SetOpacity(1.0)
    vis_stick_r.SetColor(1.0, 1.0, 1.0)

    # Collision model
    col_stick_r = vtkesqui.vtkCollisionModel()
    col_stick_r.SetName("col_stick_r_vtkbioeng")
    col_stick_r.SetFileName(fn0c)
    col_stick_r.SetVisibility(0.0)

    # First tool element (stick_r)
    stick_r = vtkesqui.vtkScenarioElement()
    stick_r.SetName("stick_r")
    stick_r.SetPosition(4.0, 0.0, 0.0)
    stick_r.SetOrientation(0, 0, 20)
    stick_r.SetOrigin(0, 0, 6)
    stick_r.SetVisualizationModel(vis_stick_r)
    stick_r.SetCollisionModel(col_stick_r)

    # Visualization model
    vis_tip_r = vtkesqui.vtkVisualizationModel()
    vis_tip_r.SetName("vis_tip_r")
    vis_tip_r.SetFileName(fn3)
    vis_tip_r.SetTextureFileName(fn0t)
    vis_tip_r.SetOpacity(1.0)
    vis_tip_r.SetColor(0.0, 1.0, 0.0)

    # Collision model
    col_tip_r = vtkesqui.vtkCollisionModel()
    col_tip_r.SetName("col_tip_r_vtkbioeng")
    col_tip_r.SetFileName(fn3c)
    col_tip_r.SetVisibility(0.0)

    # Second tool element (tip_r)
    tip_r = vtkesqui.vtkScenarioElement()
    tip_r.SetName("tip_r")
    tip_r.SetPosition(4.0, 0.0, 0.0)
    tip_r.SetOrientation(0, 0, 20)
    tip_r.SetOrigin(0, 0, 6)
    tip_r.SetVisualizationModel(vis_tip_r)
    tip_r.SetCollisionModel(col_tip_r)

    probe_r = vtkesqui.vtkToolProbe()
    probe_r.AddElement(stick_r)
    probe_r.AddElement(tip_r)
    scenario.AddObject(probe_r)

    # Add an Organ (Cavity)
    # Visualization model
    vis_cavity = vtkesqui.vtkVisualizationModel()
    vis_cavity.SetName("vis_cavity")
    vis_cavity.SetFileName(fn5)
    vis_cavity.SetTextureFileName(fn5t)
    vis_cavity.SetOpacity(1.0)

    # Organ element (cavity)
    e_cavity = vtkesqui.vtkScenarioElement()
    e_cavity.SetName("e_cavity")
    e_cavity.SetPosition(0.0, 0.0, -3.0)
    e_cavity.SetOrientation(-45, 0, 0)
    e_cavity.SetVisualizationModel(vis_cavity)

    cavity = vtkesqui.vtkOrgan()
    cavity.SetName("cavity")
    cavity.AddElement(e_cavity)
    scenario.AddObject(cavity)

    # Organs
    balls = list()
    textures = list()
    textures.append(fn4tl)
    textures.append(fn4tr)
    textures.append(fn4tb)

    reader = vtk.vtkXMLPolyDataReader()
    reader.SetFileName(fn4)
    reader.Update()

    readerc = vtk.vtkXMLPolyDataReader()
    readerc.SetFileName(fn4c)
    readerc.Update()

    for i in range(9):

        # Define organ type
        # 3 organs of each type (left, right and both)
        t = i % 3
        px = int(i / 3)

        # Add a ball
        # Visualization model
        vis_ball = vtkesqui.vtkVisualizationModel()
        vis_ball.SetName("vis_ball" + str(i))
        vis_ball.SetFileName(fn4)
        vis_ball.SetTextureFileName(textures[t])
        vis_ball.SetOpacity(1.0)

        # Collision model
        col_ball = vtkesqui.vtkCollisionModel()
        col_ball.SetName("col_ball_vtkbioeng" + str(i))
        col_ball.SetFileName(fn4c)
        col_ball.SetVisibility(0.0)
        col_ball.SetOpacity(0.0)

        # Organ element (ball)
        #x = -3 + i*2.0
        e_ball = vtkesqui.vtkScenarioElement()
        e_ball.SetName("e_ball" + str(i))
        e_ball.SetPosition(px - 1, -2 * t, -3)
        e_ball.SetOrientation(15, -0, 0)
        e_ball.SetVisualizationModel(vis_ball)
        e_ball.SetCollisionModel(col_ball)

        ball = vtkesqui.vtkOrgan()
        ball.SetName("ball_" + str(i) + "_" + str(t))
        ball.AddElement(e_ball)
        ball.Update()
        ball.Disable()

        scenario.AddObject(ball)
        balls.append(ball)

    # Scenario camera
    camera = vtk.vtkCamera()
    camera.SetPosition(0, 0, 6)
    camera.SetFocalPoint(0, 0, -6)
    camera.Yaw(0)
    camera.Elevation(20)
    camera.Pitch(-15)
    camera.ParallelProjectionOff()
    camera.SetViewAngle(70)
    camera.Dolly(1.2)
    scenario.SetCamera(camera)

    #/********** Lights  **********/
    headLight = vtk.vtkLight()
    headLight.SetLightTypeToHeadlight()
    headLight.PositionalOn()
    headLight.SetIntensity(0.8)
    headLight.SetConeAngle(60)
    scenario.AddLight(headLight)

    ambientLight = vtk.vtkLight()
    ambientLight.SetLightTypeToSceneLight()
    ambientLight.PositionalOff()
    ambientLight.SetIntensity(0.1)
    scenario.AddLight(ambientLight)

    simulation = vtkesqui.vtkSimulation()
    simulation.SetScenario(scenario)
    simulation.SetRenderTimerRate(30)
    simulation.SetSimulationTimerRate(1)
    simulation.SetInteractionTimerRate(1)
    simulation.InteractionOn()
    simulation.CollisionOn()
    simulation.Initialize()

    #Wait for initialization to set collision mode
    simulation.SetCollisionModeToSimple()

    # Sign up to receive TimerEvent
    iren = scenario.GetRenderWindowInteractor()
    cb = vtkTimerCallback()
    iren.AddObserver('TimerEvent', cb.execute)
    # 100ms timer
    timerId = iren.CreateRepeatingTimer(100)
    cb.simulation = simulation
    cb.organs = balls

    simulation.Run()