def importModel(self, m): print '\t\tmodel: ' + m.get('Name') + '...' if (m.get('Type') == 'Visualization'): model = vtkesqui.vtkVisualizationModel() model.SetTextureFileName(m.get('TextureFileName')) elif (m.get('Type') == 'Collision'): model = vtkesqui.vtkCollisionModel() elif (m.get('Type') == 'Deformation'): dm = m[0] if dm.tag == 'Interface': if dm.get('Type') == 'PSS': model = vtkesqui.vtkParticleSpringSystemInterface() model.SetTimeStep(float(dm.get('DeltaT'))) g = str(dm.get('Gravity')).split(' ') model.SetGravity(float(g[0]), float(g[1]), float(g[2])) model.SetSpring(float(dm.get('Spring'))) model.SetDamping(float(dm.get('Damping'))) model.SetDistance(float(dm.get('Distance'))) model.SetMass(float(dm.get('Mass'))) else: return #model.SetStatus(int(m.get('Status'))) model.SetName(m.get('Name')) model.SetFileName(m.get('FileName')) c = str(m.get('Color')).split(" ") model.SetColor(float(c[0]), float(c[1]), float(c[2])) model.SetVisibility(bool(m.get('Visibility'))) model.SetOpacity(float(m.get('Opacity'))) return model
def importModel(self, m): print '\t\tmodel: '+m.get('Name')+'...' if(m.get('Type') == 'Visualization'): model = vtkesqui.vtkVisualizationModel() model.SetTextureFileName(m.get('TextureFileName')) elif(m.get('Type') == 'Collision'): model = vtkesqui.vtkCollisionModel() elif(m.get('Type') == 'Deformation'): dm = m[0] if dm.tag == 'Interface': if dm.get('Type') == 'PSS': model = vtkesqui.vtkParticleSpringSystemInterface() model.SetTimeStep(float(dm.get('DeltaT'))) g = str(dm.get('Gravity')).split(' ') model.SetGravity(float(g[0]), float(g[1]), float(g[2])) model.SetSpring(float(dm.get('Spring'))) model.SetDamping(float(dm.get('Damping'))) model.SetDistance(float(dm.get('Distance'))) model.SetMass(float(dm.get('Mass'))) else: return #model.SetStatus(int(m.get('Status'))) model.SetName(m.get('Name')) model.SetFileName(m.get('FileName')) c = str(m.get('Color')).split(" ") model.SetColor(float(c[0]), float(c[1]), float(c[2])) model.SetVisibility(bool(m.get('Visibility'))) model.SetOpacity(float(m.get('Opacity'))) return model
def createBall(i): fn = "/home/david/vtkESQuiData/Scenario/Organs/ball.vtp" fnc = "/home/david/vtkESQuiData/Scenario/Organs/ball_col.vtp" fntl = "/home/david/vtkESQuiData/Scenario/Textures/leftball.jpg" fntr = "/home/david/vtkESQuiData/Scenario/Textures/rightball.jpg" fntb = "/home/david/vtkESQuiData/Scenario/Textures/bothball.jpg" # Add an Organ # Visualization model vis_ball = vtkesqui.vtkVisualizationModel() #vis_ball.SetName("vis_ball"+str(i)) vis_ball.SetFileName("/home/david/vtkESQuiData/Scenario/Organs/ball.vtp") vis_ball.SetTextureFileName( "/home/david/vtkESQuiData/Scenario/Textures/leftball.jpg") vis_ball.SetOpacity(1.0) # Collision model col_ball = vtkesqui.vtkCollisionModel() col_ball.SetName("col_ball_vtkbioeng" + str(i)) col_ball.SetFileName("/home/david/vtkESQuiData/Scenario/Organs/ball.vtp") col_ball.SetOpacity(1.0) # Organ element (ball) #x = -3 + i*2.0 e_ball = vtkesqui.vtkScenarioElement() #e_ball.SetName("e_ball"+str(i)) e_ball.SetPosition(2 * i, -2, -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)) ball.AddElement(e_ball) return ball
def createBall(i): fn ="/home/david/vtkESQuiData/Scenario/Organs/ball.vtp" fnc ="/home/david/vtkESQuiData/Scenario/Organs/ball_col.vtp" fntl = "/home/david/vtkESQuiData/Scenario/Textures/leftball.jpg"; fntr = "/home/david/vtkESQuiData/Scenario/Textures/rightball.jpg"; fntb = "/home/david/vtkESQuiData/Scenario/Textures/bothball.jpg"; # Add an Organ # Visualization model vis_ball = vtkesqui.vtkVisualizationModel() #vis_ball.SetName("vis_ball"+str(i)) vis_ball.SetFileName("/home/david/vtkESQuiData/Scenario/Organs/ball.vtp") vis_ball.SetTextureFileName("/home/david/vtkESQuiData/Scenario/Textures/leftball.jpg") vis_ball.SetOpacity(1.0) # Collision model col_ball = vtkesqui.vtkCollisionModel() col_ball.SetName("col_ball_vtkbioeng"+str(i)) col_ball.SetFileName("/home/david/vtkESQuiData/Scenario/Organs/ball.vtp") col_ball.SetOpacity(1.0) # Organ element (ball) #x = -3 + i*2.0 e_ball = vtkesqui.vtkScenarioElement() #e_ball.SetName("e_ball"+str(i)) e_ball.SetPosition(2*i, -2, -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)) ball.AddElement(e_ball) return ball
fn = "/home/david/vtkESQuiData/Scenario/Organs/ball.vtp" tfn = "/home/david/vtkESQuiData/Scenario/Textures/steel.jpg" cfn = "/home/david/vtkESQuiData/Scenario/Organs/ball_col.vtp" dfn = "/home/david/vtkESQuiData/Scenario/Organs/ball_def_c10.vtp" # Visualization Model vis = vtkesqui.vtkVisualizationModel() vis.SetName("ball_vis") vis.SetFileName(fn) vis.SetTextureFileName(tfn) vis.SetOpacity(1.0) vis.SetColor(1.0, 0.0, 1.0) # Visualization Model col = vtkesqui.vtkCollisionModel() col.SetName("ball_vtkbioeng") col.SetFileName(cfn) col.SetOpacity(1.0) col.SetColor(0.0, 0.0, 1.0) # Deformation Model defo = vtkesqui.vtkParticleSpringSystemInterface() defo.SetName("ball_ParticleSpringSystem") defo.SetFileName(dfn) defo.SetOpacity(0.5) defo.SetColor(1.0, 1.0, 1.0) ball = vtkesqui.vtkScenarioElement() ball.SetId(0) ball.SetName("ball")
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()
decimate = vtk.vtkDecimatePro() decimate.SetInput(input) decimate.SetTargetReduction(.50) decimate.Update() input_col = decimate.GetOutput() vis = vtkesqui.vtkVisualizationModel(); vis.SetName("sphere_vis"); vis.SetInput(input); vis.SetTextureFileName(tfn); vis.SetOpacity(1.0); vis.SetColor(1.0, 1.0, 1.0); col = vtkesqui.vtkCollisionModel(); col.SetName("sphere_col"); col.SetInput(input_col); col.SetOpacity(0.5); col.SetColor(0.0, 0.0, 1.0); col.SetRadius(0.02) stick = vtkesqui.vtkScenarioElement(); stick.SetId(0); stick.SetName("sphere"); stick.SetOrigin(0.0, 0.0, 0.0); stick.SetPosition(3.0, 0.0, 0.0); stick.SetOrientation(0, 0, -20); stick.SetVisualizationModel(vis); stick.SetCollisionModel(col);
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()
def main(): fn ="/home/david/vtkESQuiData/Scenario/Organs/ball.vtp" tfn ="/home/david/vtkESQuiData/Scenario/Textures/muscle.jpg" cfn ="/home/david/vtkESQuiData/Scenario/Organs/ball_col.vtp" dfn ="/home/david/vtkESQuiData/Scenario/Organs/ball_def_c10.vtp" # Visualization Model vis = vtkesqui.vtkVisualizationModel() vis.SetName("ball_vis") vis.SetFileName(fn) vis.SetTextureFileName(tfn) vis.SetOpacity(1.0) vis.SetColor(1.0, 1.0, 1.0) # Visualization Model col = vtkesqui.vtkCollisionModel() col.SetName("ball_vtkbioeng") col.SetFileName(cfn) col.SetVisibility(1) # Deformation Model defo = vtkesqui.vtkParticleSpringSystemInterface() defo.SetName("ball_defo") defo.SetFileName(dfn) defo.SetOpacity(0.5) defo.SetVisibility(1) defo.SetColor(1.0, 1.0, 1.0) defo.SetSpring(150) defo.SetDistance(1.0) defo.SetDamping(3) defo.SetMass(.5) defo.SetTimeStep(0.001) ball = vtkesqui.vtkScenarioElement() ball.SetId(0) ball.SetName("ball") ball.SetPosition(3.0, 0.0, 0.0) ball.SetOrientation(0, 0, -20) ball.SetVisualizationModel(vis) ball.SetCollisionModel(col) ball.SetDeformationModel(defo) ball.Update() ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetWindowName("vtkESQui - Particle Spring System") iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren.AddActor(vis.GetActor()) ren.AddActor(col.GetActor()) ren.AddActor(defo.GetActor()) ren.SetBackground(0.3, 0.6, 0.3) renWin.SetSize(800, 600) ren.ResetCamera() camera = ren.GetActiveCamera() camera.Azimuth(15) camera.Zoom(1.6) iren.Initialize() # Sign up to receive TimerEvent cb = vtkTimerCallback() cb.ball = ball iren.AddObserver('TimerEvent', cb.execute) timerId = iren.CreateRepeatingTimer(1) cb.renderTimerId = timerId cb.defo = defo iren.Start()
# Define organ type # 3 organs of each type (left, right and both) t = i%3 px = int(i/3) # Add an Organ # Visualization model vis_ball = vtkesqui.vtkVisualizationModel() vis_ball.SetName("vis_ball"+str(i)) vis_ball.SetInput(reader.GetOutput()) 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.SetInput(readerc.GetOutput()) col_ball.SetOpacity(1.0) # Organ element (ball) #x = -3 + i*2.0 e_ball = vtkesqui.vtkScenarioElement() e_ball.SetName("e_ball"+str(i)) e_ball.SetPosition(2*px-2, -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))
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()
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 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()
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()
import vtk import vtkesqui fn ="/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_l_col.vtp" fn1 ="/home/david/vtkESQuiData/Scenario/Tools/Grasper/lever_r_col.vtp" fn2 ="/home/david/vtkESQuiData/Scenario/Organs/ball_col.vtp" # Collision Model reader = vtk.vtkXMLPolyDataReader() reader.SetFileName(fn) reader.Update() col0 = vtkesqui.vtkCollisionModel() col0.SetName("lever_l_col") col0.SetInput(reader.GetOutput()) col0.SetObjectId(0) col0.SetOpacity(1.0) col0.SetColor(1.0, 0.0, 1.0) col0.Update() reader1 = vtk.vtkXMLPolyDataReader() reader1.SetFileName(fn1) reader1.Update() col1 = vtkesqui.vtkCollisionModel() col1.SetName("lever_r_col") col1.SetInput(reader1.GetOutput()) col1.SetObjectId(1) col1.SetOpacity(1.0) col1.SetColor(0.0, 1.0, 1.0)
def TestvtkBioEngInterface(): src0 = vtk.vtkSphereSource() src0.SetRadius(1) src0.SetThetaResolution(12) src0.SetPhiResolution(12) src0.Update() s0 = src0.GetOutput() src1 = vtk.vtkSphereSource() src1.SetRadius(0.5) src1.SetThetaResolution(12) src1.SetPhiResolution(12) src1.Update() s1 = src1.GetOutput() col0 = vtkesqui.vtkCollisionModel() col0.SetName("col0") col0.SetInput(s0) col0.SetObjectId(0) col0.SetId(0) col0.Update() col0.GetActor().SetPosition(0,0,0) col1 = vtkesqui.vtkCollisionModel() col1.SetName("col1") col1.SetInput(s1) col1.SetObjectId(0) col1.SetId(0) col1.Update() col1.GetActor().SetPosition(3,0,0) renderer = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetSize(500,500) renWin.AddRenderer(renderer) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renderer.AddActor(col0.GetActor()) renderer.AddActor(col1.GetActor()) col = vtkesqui.vtkBioEngInterface() col.SetBoxTolerance(0) col.SetCellTolerance(0) col.SetNumberOfCellsPerNode(2) col.SetModeToFull() col.Initialize() col.AddModel(col0) col.AddModel(col1) col.Update() renderer.SetBackground(0.3, 0.6, 0.3) renderer.ResetCamera() iren.Initialize() iren.CreateRepeatingTimer(500) print "here" cb = TimerCallback1() # Segmention fault here iren.AddObserver("TimerEvent", cb) cb.SetModel(0, col0) cb.SetModel(1, col1) cb.SetFilter(col) tid = iren.CreateRepeatingTimer(500) cb.SetTimerId(tid) renWin.Render() iren.Start()
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" # 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) scenario = vtkesqui.vtkScenario() scenario.AddObject(probe_l) scenario.AddObject(grasper_r) 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) scenario.Update() style = vtkesqui.vtkDefaultInteractorStyle() style.SetScenario(scenario) style.Initialize() iren = scenario.GetRenderWindowInteractor() iren.SetInteractorStyle(style) iren.Initialize() # Sign up to receive TimerEvent cb = vtkTimerCallback() iren.AddObserver('TimerEvent', cb.execute) # 1ms timer timerId = iren.CreateRepeatingTimer(1) cb.scenario = scenario iren.Start()
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()