Beispiel #1
0
    def __init__(self, Skeleton, Scene, Animator, idx):
        """
            Skeleton will be a list
        """
        self.ren = vtk.vtkRenderer()
        self.renWin = vtk.vtkRenderWindow()
        self.renWin.AddRenderer(self.ren)
        self.iren = vtk.vtkRenderWindowInteractor()
        self.iren.SetRenderWindow(self.renWin)
        self.style = vtk.vtkInteractorStyleTrackballCamera()
        self.iren.SetInteractorStyle(self.style)
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(0, 0, 0)
        self.ren.SetBackground2(0, 0, 0)
        self.renWin.SetSize(800, 800)
        self.animator = Animator

        for i in range(len(Skeleton)):
            self.addSkeleton(Skeleton[i])

        self.addScene(Scene)

        self.cameraP = vtk.vtkCameraPass()
        self.lights = vtk.vtkLightsPass()
        self.shadowsBaker = vtk.vtkShadowMapBakerPass()
        self.shadowsBaker.SetResolution(4096)

        self.shadows = vtk.vtkShadowMapPass()
        self.shadows.SetShadowMapBakerPass(self.shadowsBaker)

        self.seq = vtk.vtkSequencePass()
        self.passes = vtk.vtkRenderPassCollection()
        self.passes.AddItem(self.shadowsBaker)
        self.passes.AddItem(self.shadows)
        self.passes.AddItem(self.lights)
        self.seq.SetPasses(self.passes)
        self.cameraP.SetDelegatePass(self.seq)

        self.ren.SetPass(self.cameraP)
        self.iren.Initialize()
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().ParallelProjectionOff()
        self.ren.GetActiveCamera().Azimuth(180)
        self.ren.GetActiveCamera().Pitch(1)
        self.ren.GetActiveCamera().Elevation(20)
        self.ren.GetActiveCamera().SetViewAngle(55)
        self.renWin.Render()

        self.idx = idx
        self.frame_time = 33  # 8
        self.iren.AddObserver("KeyPressEvent", self.keyPress)
        self.iren.AddObserver('TimerEvent', Animator.animate)
        self.timerId = self.iren.CreateRepeatingTimer(self.frame_time)
        self.iren.Start()
        print(self.idx)
Beispiel #2
0
    def InitRenderPasses(self):
        """Initiate and add realism passes to renderer"""
        cameraP = vtk.vtkCameraPass()
        opaque = vtk.vtkOpaquePass()
        peeling = vtk.vtkDepthPeelingPass()
        peeling.SetMaximumNumberOfPeels(1000)
        peeling.SetOcclusionRatio(0.1)

        translucent = vtk.vtkTranslucentPass()
        peeling.SetTranslucentPass(translucent)

        volume = vtk.vtkVolumetricPass()
        overlay = vtk.vtkOverlayPass()

        lights = vtk.vtkLightsPass()
        opaqueSequence = vtk.vtkSequencePass()

        passes2 = vtk.vtkRenderPassCollection()
        passes2.AddItem(lights)
        passes2.AddItem(opaque)
        opaqueSequence.SetPasses(passes2)

        opaqueCameraPass = vtk.vtkCameraPass()
        opaqueCameraPass.SetDelegatePass(opaqueSequence)

        shadowsBaker = vtk.vtkShadowMapBakerPass()
        shadowsBaker.SetOpaqueSequence(opaqueCameraPass)
        shadowsBaker.SetResolution(SHADOW_RENDER_RES)

        shadows = vtk.vtkShadowMapPass()
        shadows.SetShadowMapBakerPass(shadowsBaker)
        shadows.SetOpaqueSequence(opaqueSequence)

        seq = vtk.vtkSequencePass()
        passes = vtk.vtkRenderPassCollection()
        passes.AddItem(shadowsBaker)
        passes.AddItem(shadows)
        passes.AddItem(lights)
        passes.AddItem(peeling)
        passes.AddItem(volume)
        passes.AddItem(overlay)
        seq.SetPasses(passes)
        cameraP.SetDelegatePass(seq)

        self.renderer.SetPass(cameraP)
Beispiel #3
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.GetActiveCamera().OrthogonalizeViewUp()
    renderer.ResetCamera()
    renderer.GetActiveCamera().Dolly(2.25)
    renderer.ResetCameraClippingRange()
    renderWindow.SetWindowName('Shadows')
    renderWindow.Render()

    interactor.Start()
Beispiel #4
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)
Beispiel #5
0


# #set tonemapping https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/OpenGL2/Testing/Cxx/TestToneMappingPass.cxx
cameraP=vtk.vtkCameraPass()
seq=vtk.vtkSequencePass()
opaque=vtk.vtkOpaquePass()
lights=vtk.vtkLightsPass()

passes=vtk.vtkRenderPassCollection()
passes.AddItem(lights)
passes.AddItem(opaque)
seq.SetPasses(passes)

#shadows  https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/OpenGL2/Testing/Cxx/TestShadowMapPass.cxx
shadows=vtk.vtkShadowMapPass()
shadows.GetShadowMapBakerPass().SetResolution(1024)
# to cancel self->shadowing
# shadows.GetShadowMapBakerPass().SetPolygonOffsetFactor(3.1)
# shadows.GetShadowMapBakerPass().SetPolygonOffsetUnits(10.0)
seq=vtk.vtkSequencePass()
passes=vtk.vtkRenderPassCollection()
passes.AddItem(lights)
passes.AddItem(opaque)
passes.AddItem(shadows.GetShadowMapBakerPass())
passes.AddItem(shadows)
seq.SetPasses(passes)
cameraP=vtk.vtkCameraPass()
cameraP.SetDelegatePass(seq)

Beispiel #6
0
def main():
    interactor = vtk.vtkRenderWindowInteractor()

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetSize(400, 400)
    renderWindow.SetMultiSamples(0)

    renderWindow.SetAlphaBitPlanes(1)
    interactor.SetRenderWindow(renderWindow)

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

    rectangleSource = vtk.vtkPlaneSource()
    rectangleSource.SetOrigin(-5.0, 0.0, 5.0)
    rectangleSource.SetPoint1(5.0, 0.0, 5.0)
    rectangleSource.SetPoint2(-5.0, 0.0, -5.0)
    rectangleSource.SetResolution(100, 100)

    rectangleMapper = vtk.vtkPolyDataMapper()
    rectangleMapper.SetInputConnection(rectangleSource.GetOutputPort())

    rectangleMapper.SetScalarVisibility(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)

    colors = vtk.vtkNamedColors()
    boxColor = colors.GetColor3d("Tomato")
    rectangleColor = colors.GetColor3d("Beige")
    coneColor = colors.GetColor3d("Peacock")
    sphereColor = colors.GetColor3d("Banana")

    rectangleActor = vtk.vtkActor()
    rectangleActor.SetMapper(rectangleMapper)
    rectangleActor.VisibilityOn()
    rectangleActor.GetProperty().SetColor(rectangleColor)

    boxSource = vtk.vtkCubeSource()
    boxSource.SetXLength(2.0)

    boxNormals = vtk.vtkPolyDataNormals()
    boxNormals.SetInputConnection(boxSource.GetOutputPort())
    boxNormals.ComputePointNormalsOff()
    boxNormals.ComputeCellNormalsOn()
    boxNormals.Update()
    boxNormals.GetOutput().GetPointData().SetNormals(None)

    boxMapper = vtk.vtkPolyDataMapper()
    boxMapper.SetInputConnection(boxNormals.GetOutputPort())
    boxMapper.ScalarVisibilityOff()

    boxActor = vtk.vtkActor()
    boxActor.SetMapper(boxMapper)
    boxActor.VisibilityOn()
    boxActor.SetPosition(-2.0, 2.0, 0.0)
    boxActor.GetProperty().SetColor(boxColor)

    coneSource = vtk.vtkConeSource()
    coneSource.SetResolution(24)
    coneSource.SetDirection(1.0, 1.0, 1.0)

    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(coneSource.GetOutputPort())
    coneMapper.SetScalarVisibility(0)

    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)
    coneActor.VisibilityOn()
    coneActor.SetPosition(0.0, 1.0, 1.0)
    coneActor.GetProperty().SetColor(coneColor)

    sphereSource = vtk.vtkSphereSource()
    sphereSource.SetThetaResolution(32)
    sphereSource.SetPhiResolution(32)

    sphereMapper = vtk.vtkPolyDataMapper()
    sphereMapper.SetInputConnection(sphereSource.GetOutputPort())
    sphereMapper.ScalarVisibilityOff()

    sphereActor = vtk.vtkActor()
    sphereActor.SetMapper(sphereMapper)

    sphereActor.VisibilityOn()
    sphereActor.SetPosition(2.0, 2.0, -1.0)
    sphereActor.GetProperty().SetColor(sphereColor)

    renderer.AddViewProp(rectangleActor)
    renderer.AddViewProp(boxActor)
    renderer.AddViewProp(coneActor)
    renderer.AddViewProp(sphereActor)

    # Spotlights.

    # lighting the box.
    l1 = vtk.vtkLight()
    l1.SetPosition(-4.0, 4.0, -1.0)
    l1.SetFocalPoint(boxActor.GetPosition())
    l1.SetColor(1.0, 1.0, 1.0)
    l1.PositionalOn()
    renderer.AddLight(l1)
    l1.SwitchOn()

    # lighting the sphere
    l2 = vtk.vtkLight()
    l2.SetPosition(4.0, 5.0, 1.0)
    l2.SetFocalPoint(sphereActor.GetPosition())
    l2.SetColor(1.0, 0.0, 1.0)
    l2.PositionalOn()
    renderer.AddLight(l2)
    l2.SwitchOn()

    # For each spotlight, add a light frustum wireframe representation and a cone
    # wireframe representation, colored with the light color.
    angle = l1.GetConeAngle()
    if l1.LightTypeIsSceneLight() and l1.GetPositional(
    ) and angle < 180.0:  # spotlight
        la = vtk.vtkLightActor()
        la.SetLight(l1)
        renderer.AddViewProp(la)
    angle = l2.GetConeAngle()
    if l2.LightTypeIsSceneLight() and l2.GetPositional(
    ) and angle < 180.0:  # spotlight
        la = vtk.vtkLightActor()
        la.SetLight(l2)
        renderer.AddViewProp(la)

    renderer.SetBackground2(colors.GetColor3d("Silver"))
    renderer.SetBackground(colors.GetColor3d("LightGrey"))
    renderer.SetGradientBackground(True)

    renderWindow.Render()
    renderWindow.SetWindowName('ShadowsLightsDemo')

    renderer.ResetCamera()

    camera = renderer.GetActiveCamera()
    camera.Azimuth(40.0)
    camera.Elevation(10.0)

    renderWindow.Render()

    interactor.Start()
pass2.AddItem(lights)
pass2.AddItem(opaque)
opaqueSequence.SetPasses(pass2)

opaqueCameraPass = vtk.vtkCameraPass()
opaqueCameraPass.SetDelegatePass(opaqueSequence)

shadowBaker = vtk.vtkShadowMapBakerPass()
shadowBaker.SetOpaquePass(opaqueCameraPass)
shadowBaker.SetResolution(1024)
# to cancel self->shadowing
shadowBaker.SetPolygonOffsetFactor(3.1)
shadowBaker.SetPolygonOffsetUnits(10.0)

shadows = vtk.vtkShadowMapPass()
shadows.SetShadowMapBakerPass(shadowBaker)
shadows.SetOpaquePass(opaqueSequence)

seq = vtk.vtkSequencePass()
passes = vtk.vtkRenderPassCollection()
passes.AddItem(shadowBaker)
passes.AddItem(shadows)
passes.AddItem(lights)
passes.AddItem(peeling)
passes.AddItem(volume)
passes.AddItem(overlay)
seq.SetPasses(passes)
cameraP.SetDelegatePass(seq)

renderer.SetPass(cameraP)
    def __init__(self):
       
        self.renderer = vtk.vtkRenderer()
        self.renderer.GradientBackgroundOn()

        self.ren_win = ren_win = vtk.vtkRenderWindow()
        
        ren_win.SetSize(512,512) 
        ren_win.SetMultiSamples(0)
        ren_win.SetAlphaBitPlanes(1)
        ren_win.SetOffScreenRendering(1) #default 1

        iren = self.iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(ren_win)
        ren_win.AddRenderer(self.renderer)
       
        camera_pass = vtk.vtkCameraPass()
        opaque = vtk.vtkOpaquePass()

        peeling=vtk.vtkDepthPeelingPass()
        peeling.SetMaximumNumberOfPeels(200)
        peeling.SetOcclusionRatio(0.1)

        translucent=vtk.vtkTranslucentPass()
        peeling.SetTranslucentPass(translucent)

        volume=vtk.vtkVolumetricPass()
        overlay=vtk.vtkOverlayPass()
        lights=vtk.vtkLightsPass()
        opaque_sequence=vtk.vtkSequencePass()

        passes2=vtk.vtkRenderPassCollection()
        passes2.AddItem(lights)
        passes2.AddItem(opaque)

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

        shadows_baker=vtk.vtkShadowMapBakerPass()
        shadows_baker.SetOpaquePass(opaque_camera_pass)
        shadows_baker.SetResolution(1024)

        #To cancel self-shadowing.
        shadows_baker.SetPolygonOffsetFactor(3.1)
        shadows_baker.SetPolygonOffsetUnits(10.0)

        shadows=vtk.vtkShadowMapPass()
        shadows.SetShadowMapBakerPass(shadows_baker)
        shadows.SetOpaquePass(opaque_sequence)

        seq=vtk.vtkSequencePass()
        passes=vtk.vtkRenderPassCollection()
        passes.AddItem(shadows_baker)
        passes.AddItem(shadows)
        passes.AddItem(lights)
        passes.AddItem(peeling)
        passes.AddItem(volume)
        passes.AddItem(overlay)

        seq.SetPasses(passes)
        camera_pass.SetDelegatePass(seq)
        self.renderer.SetPass(camera_pass)