Exemple #1
0
    def __init__(self, renderer):
        Visualizer.__init__(self)

        assert isinstance(renderer, vtk.vtkRenderer)
        self.ren = renderer
    
        # -------- add the beam ----
        # geometry
        self.beam = vtk.vtkCubeSource()
        self.beam.SetXLength(st.visBeamLength)
        self.beam.SetYLength(st.visBeamWidth)
        self.beam.SetZLength(st.visBeamDepth)

        # mapper
        self.beamMapper = vtk.vtkPolyDataMapper()
        self.beamMapper.SetInputConnection(self.beam.GetOutputPort())

        # actor
        self.beamActor = vtk.vtkLODActor()
        self.beamActor.SetMapper(self.beamMapper)

        # make it look nice
        self.beamProp = self.beamActor.GetProperty()
        self.beamProp.SetColor(101 / 255, 123 / 255, 131 / 255)

        self.ren.AddActor(self.beamActor)

        # -------- add the ball ----
        # geometry
        self.ball = vtk.vtkSphereSource()
        self.ball.SetRadius(st.visR)
        self.ball.SetThetaResolution(20)
        self.ball.SetPhiResolution(20)

        # mapper
        self.ballMapper = vtk.vtkPolyDataMapper()
        self.ballMapper.SetInputConnection(self.ball.GetOutputPort())

        # actor
        self.ballActor = vtk.vtkLODActor()
        self.ballActor.SetMapper(self.ballMapper)

        # make it look nice
        self.ballProp = self.ballActor.GetProperty()
        self.ballProp.SetColor(255 / 255, 255 / 255, 0)
        self.ballProp.SetAmbient(0.2)
        self.ballProp.SetDiffuse(0.8)
        self.ballProp.SetSpecular(0.5)
        self.ballProp.SetSpecularPower(0.5)

        self.ren.AddActor(self.ballActor)

        # add background
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(228 / 255, 232 / 255, 213 / 255)
        self.ren.SetBackground2(38 / 255, 139 / 255, 210 / 255)

        # get everybody into the frame
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(1.7)
Exemple #2
0
    def __init__(self, renderer):
        Visualizer.__init__(self)

        assert isinstance(renderer, vtk.vtkRenderer)
        self.ren = renderer

        # -------- add the beam ----
        # geometry
        self.beam = vtk.vtkCubeSource()
        self.beam.SetXLength(st.visBeamLength)
        self.beam.SetYLength(st.visBeamWidth)
        self.beam.SetZLength(st.visBeamDepth)

        # mapper
        self.beamMapper = vtk.vtkPolyDataMapper()
        self.beamMapper.SetInputConnection(self.beam.GetOutputPort())

        # actor
        self.beamActor = vtk.vtkLODActor()
        self.beamActor.SetMapper(self.beamMapper)

        # make it look nice
        self.beamProp = self.beamActor.GetProperty()
        self.beamProp.SetColor(101 / 255, 123 / 255, 131 / 255)

        self.ren.AddActor(self.beamActor)

        # -------- add the ball ----
        # geometry
        self.ball = vtk.vtkSphereSource()
        self.ball.SetRadius(st.visR)
        self.ball.SetThetaResolution(20)
        self.ball.SetPhiResolution(20)

        # mapper
        self.ballMapper = vtk.vtkPolyDataMapper()
        self.ballMapper.SetInputConnection(self.ball.GetOutputPort())

        # actor
        self.ballActor = vtk.vtkLODActor()
        self.ballActor.SetMapper(self.ballMapper)

        # make it look nice
        self.ballProp = self.ballActor.GetProperty()
        self.ballProp.SetColor(255 / 255, 255 / 255, 0)
        self.ballProp.SetAmbient(0.2)
        self.ballProp.SetDiffuse(0.8)
        self.ballProp.SetSpecular(0.5)
        self.ballProp.SetSpecularPower(0.5)

        self.ren.AddActor(self.ballActor)

        # add background
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(228 / 255, 232 / 255, 213 / 255)
        self.ren.SetBackground2(38 / 255, 139 / 255, 210 / 255)

        # get everybody into the frame
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(1.7)
Exemple #3
0
    def __init__(self, renderer):
        Visualizer.__init__(self)

        assert isinstance(renderer, vtk.vtkRenderer)
        self.ren = renderer

        # -------- add the beam ----
        # geometry
        self.beam = vtk.vtkCubeSource()
        self.beam.SetXLength(st.beam_length)
        self.beam.SetYLength(st.beam_width)
        self.beam.SetZLength(st.beam_depth)

        # mapper
        self.beam_Mapper = vtk.vtkPolyDataMapper()
        self.beam_Mapper.SetInputConnection(self.beam.GetOutputPort())

        # actor
        self.beam_Actor = vtk.vtkLODActor()
        self.beam_Actor.SetMapper(self.beam_Mapper)
        self.beam_Actor.SetPosition(0,
                                    -(st.cart_width / 2 + st.beam_width / 2),
                                    0)

        # make it look nice
        self.beam_Prop = self.beam_Actor.GetProperty()
        # RAL 9007, grey-aluminium
        self.beam_Prop.SetColor(142 / 255, 142 / 255, 139 / 255)

        self.ren.AddActor(self.beam_Actor)

        # -------- add cart ----
        # geometry
        self.cart = vtk.vtkCubeSource()
        self.cart.SetXLength(st.cart_length)
        self.cart.SetYLength(st.cart_width)
        self.cart.SetZLength(st.cart_depth)

        # mapper
        self.cart_Mapper = vtk.vtkPolyDataMapper()
        self.cart_Mapper.SetInputConnection(self.cart.GetOutputPort())

        # actor
        self.cart_Actor = vtk.vtkLODActor()
        self.cart_Actor.SetPosition(0, 0, 0)
        self.cart_Actor.RotateWXYZ(0, 1, 0, 0)
        self.cart_Actor.SetMapper(self.cart_Mapper)

        # make it look nice
        self.cart_Prop = self.cart_Actor.GetProperty()
        # RAL 7011, iron-grey
        self.cart_Prop.SetColor(64 / 255, 74 / 255, 84 / 255)

        self.ren.AddActor(self.cart_Actor)
        # save pose
        self.cart_pose = [np.array([0, 0, 0]), np.eye(3)]

        # -------- add axis ----
        # geometry
        self.axis = vtk.vtkCylinderSource()
        self.axis.SetHeight(st.axis_height)
        self.axis.SetRadius(st.axis_radius)
        self.axis.SetResolution(100)

        # mapper
        self.axis_Mapper = vtk.vtkPolyDataMapper()
        self.axis_Mapper.SetInputConnection(self.axis.GetOutputPort())

        # actor
        self.axis_Actor = vtk.vtkLODActor()
        self.axis_Actor.SetPosition(0, 0,
                                    st.cart_depth / 2 + st.axis_height / 2)
        self.axis_Actor.RotateWXYZ(90, 1, 0, 0)
        self.axis_Actor.SetMapper(self.axis_Mapper)

        # make it look nice
        self.axis_Prop = self.axis_Actor.GetProperty()
        # RAL 7011, iron-grey
        self.axis_Prop.SetColor(64 / 255, 74 / 255, 84 / 255)

        self.ren.AddActor(self.axis_Actor)
        # save pose
        self.axis_pose = [
            np.array([0, 0, st.cart_depth / 2 + st.axis_height / 2]),
            to.rotation_matrix_xyz("x", 90, "deg")
        ]

        # -------- add short pendulum ----
        # add short pendulum shaft
        # geometry
        self.short_pendulum_shaft = vtk.vtkCylinderSource()
        self.short_pendulum_shaft.SetHeight(st.pendulum_shaft_height)
        self.short_pendulum_shaft.SetRadius(st.pendulum_shaft_radius)
        self.short_pendulum_shaft.SetResolution(100)

        # mapper
        self.short_pendulum_shaft_Mapper = vtk.vtkPolyDataMapper()
        self.short_pendulum_shaft_Mapper.SetInputConnection(
            self.short_pendulum_shaft.GetOutputPort())

        # actor
        self.short_pendulum_shaft_Actor = vtk.vtkLODActor()
        self.short_pendulum_shaft_Actor.SetPosition(
            0, 0,
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2)
        self.short_pendulum_shaft_Actor.RotateWXYZ(90, 1, 0, 0)
        self.short_pendulum_shaft_Actor.SetMapper(
            self.short_pendulum_shaft_Mapper)

        # make it look nice
        self.short_pendulum_shaft_Prop = self.short_pendulum_shaft_Actor.GetProperty(
        )
        # RAL 9007, grey-aluminium, a little bit darker
        self.short_pendulum_shaft_Prop.SetColor(122 / 255, 122 / 255,
                                                119 / 255)

        self.ren.AddActor(self.short_pendulum_shaft_Actor)
        # save pose
        self.short_pendulum_shaft_pose = [
            np.array([
                0, 0, st.cart_depth / 2 + st.axis_height +
                st.pendulum_shaft_height / 2
            ]),
            to.rotation_matrix_xyz("x", 90, "deg")
        ]

        # add short pendulum
        # geometry
        self.short_pendulum = vtk.vtkCylinderSource()
        self.short_pendulum.SetHeight(st.short_pendulum_height)
        self.short_pendulum.SetRadius(st.short_pendulum_radius)
        self.short_pendulum.SetResolution(100)

        # mapper
        self.short_pendulum_Mapper = vtk.vtkPolyDataMapper()
        self.short_pendulum_Mapper.SetInputConnection(
            self.short_pendulum.GetOutputPort())

        # actor
        self.short_pendulum_Actor = vtk.vtkLODActor()
        self.short_pendulum_Actor.SetPosition(
            0, st.short_pendulum_height / 2,
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2)
        self.short_pendulum_Actor.RotateWXYZ(0, 1, 0, 0)
        self.short_pendulum_Actor.SetMapper(self.short_pendulum_Mapper)

        # make it look nice
        self.short_pendulum_Prop = self.short_pendulum_Actor.GetProperty()
        # RAL 9007, grey-aluminium, a little bit darker
        self.short_pendulum_Prop.SetColor(122 / 255, 122 / 255, 119 / 255)

        self.ren.AddActor(self.short_pendulum_Actor)
        self.short_pendulum_pose = [
            np.array([
                0, st.short_pendulum_height / 2, st.cart_depth / 2 +
                st.axis_height + st.pendulum_shaft_height / 2
            ]),
            np.eye(3)
        ]

        # add short pendulum weight
        # geometry
        self.short_pendulum_weight = vtk.vtkCylinderSource()
        self.short_pendulum_weight.SetHeight(st.pendulum_weight_height)
        self.short_pendulum_weight.SetRadius(st.pendulum_weight_radius)
        self.short_pendulum_weight.SetResolution(100)

        # mapper
        self.short_pendulum_weight_Mapper = vtk.vtkPolyDataMapper()
        self.short_pendulum_weight_Mapper.SetInputConnection(
            self.short_pendulum_weight.GetOutputPort())

        # actor
        self.short_pendulum_weight_Actor = vtk.vtkLODActor()
        self.short_pendulum_weight_Actor.SetPosition(
            0, (st.short_pendulum_height + st.pendulum_weight_height / 2),
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2)
        self.short_pendulum_weight_Actor.RotateWXYZ(0, 1, 0, 0)
        self.short_pendulum_weight_Actor.SetMapper(
            self.short_pendulum_weight_Mapper)

        # make it look nice
        self.short_pendulum_weight_Prop = self.short_pendulum_weight_Actor.GetProperty(
        )
        # RAL 9006, white-aluminium
        self.short_pendulum_weight_Prop.SetColor(162 / 255, 166 / 255,
                                                 164 / 255)

        self.ren.AddActor(self.short_pendulum_weight_Actor)
        self.short_pendulum_weight_pose = [
            np.array([
                0, (st.short_pendulum_height + st.pendulum_weight_height / 2),
                st.cart_depth / 2 + st.axis_height +
                st.pendulum_shaft_height / 2
            ]),
            np.eye(3)
        ]

        # -------- add long pendulum ----
        # add long pendulum shaft
        # geometry
        self.long_pendulum_shaft = vtk.vtkCylinderSource()
        self.long_pendulum_shaft.SetHeight(st.pendulum_shaft_height)
        self.long_pendulum_shaft.SetRadius(st.pendulum_shaft_radius)
        self.long_pendulum_shaft.SetResolution(100)

        # mapper
        self.long_pendulum_shaft_Mapper = vtk.vtkPolyDataMapper()
        self.long_pendulum_shaft_Mapper.SetInputConnection(
            self.long_pendulum_shaft.GetOutputPort())

        # actor
        self.long_pendulum_shaft_Actor = vtk.vtkLODActor()
        self.long_pendulum_shaft_Actor.SetPosition(
            0, 0, st.cart_depth / 2 + st.axis_height +
            st.pendulum_shaft_height + st.pendulum_shaft_height / 2)
        self.long_pendulum_shaft_Actor.RotateWXYZ(90, 1, 0, 0)
        self.long_pendulum_shaft_Actor.SetMapper(
            self.long_pendulum_shaft_Mapper)

        # make it look nice
        self.long_pendulum_shaft_Prop = self.long_pendulum_shaft_Actor.GetProperty(
        )
        # RAL 9007, grey-aluminium
        self.long_pendulum_shaft_Prop.SetColor(142 / 255, 142 / 255, 139 / 255)

        self.ren.AddActor(self.long_pendulum_shaft_Actor)
        # save pose
        self.long_pendulum_shaft_pose = [
            np.array([
                0, 0, st.cart_depth / 2 + st.axis_height +
                st.pendulum_shaft_height + st.pendulum_shaft_height / 2
            ]),
            to.rotation_matrix_xyz("x", 90, "deg")
        ]

        # add long pendulum
        # geometry
        self.long_pendulum = vtk.vtkCylinderSource()
        self.long_pendulum.SetHeight(st.long_pendulum_height)
        self.long_pendulum.SetRadius(st.long_pendulum_radius)
        self.long_pendulum.SetResolution(100)

        # mapper
        self.long_pendulum_Mapper = vtk.vtkPolyDataMapper()
        self.long_pendulum_Mapper.SetInputConnection(
            self.long_pendulum.GetOutputPort())

        # actor
        self.long_pendulum_Actor = vtk.vtkLODActor()
        self.long_pendulum_Actor.SetPosition(
            0, st.long_pendulum_height / 2,
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height +
            st.pendulum_shaft_height / 2)
        self.long_pendulum_Actor.RotateWXYZ(0, 1, 0, 0)
        self.long_pendulum_Actor.SetMapper(self.long_pendulum_Mapper)

        # make it look nice
        self.long_pendulum_Prop = self.long_pendulum_Actor.GetProperty()
        # RAL 9007, grey-aluminium
        self.long_pendulum_Prop.SetColor(142 / 255, 142 / 255, 139 / 255)

        self.ren.AddActor(self.long_pendulum_Actor)
        self.long_pendulum_pose = [
            np.array([
                0, st.long_pendulum_height / 2,
                st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height +
                st.pendulum_shaft_height / 2
            ]),
            np.eye(3)
        ]

        # add long pendulum weight
        # geometry
        self.long_pendulum_weight = vtk.vtkCylinderSource()
        self.long_pendulum_weight.SetHeight(st.pendulum_weight_height)
        self.long_pendulum_weight.SetRadius(st.pendulum_weight_radius)
        self.long_pendulum_weight.SetResolution(100)

        # mapper
        self.long_pendulum_weight_Mapper = vtk.vtkPolyDataMapper()
        self.long_pendulum_weight_Mapper.SetInputConnection(
            self.long_pendulum_weight.GetOutputPort())

        # actor
        self.long_pendulum_weight_Actor = vtk.vtkLODActor()
        self.long_pendulum_weight_Actor.SetPosition(
            0, (st.long_pendulum_height + st.pendulum_weight_height / 2),
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height +
            st.pendulum_shaft_height / 2)
        self.long_pendulum_weight_Actor.RotateWXYZ(0, 1, 0, 0)
        self.long_pendulum_weight_Actor.SetMapper(
            self.long_pendulum_weight_Mapper)

        # make it look nice
        self.long_pendulum_weight_Prop = self.long_pendulum_weight_Actor.GetProperty(
        )
        # RAL 9006, white-aluminium
        self.long_pendulum_weight_Prop.SetColor(162 / 255, 166 / 255,
                                                164 / 255)

        self.ren.AddActor(self.long_pendulum_weight_Actor)
        self.long_pendulum_weight_pose = [
            np.array([
                0, (st.long_pendulum_height + st.pendulum_weight_height / 2),
                st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height +
                st.pendulum_shaft_height / 2
            ]),
            np.eye(3)
        ]

        # add background
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(228 / 255, 232 / 255, 213 / 255)
        self.ren.SetBackground2(38 / 255, 139 / 255, 210 / 255)

        # get everybody into the frame
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(1.45)
        self.ren.GetActiveCamera().SetFocalPoint(0, 0, 0)

        # add camera reset functionality
        self.can_reset_view = True
        self.position = self.ren.GetActiveCamera().GetPosition()
        self.focal_point = self.ren.GetActiveCamera().GetFocalPoint()
        self.view_up = self.ren.GetActiveCamera().GetViewUp()
        self.view_angle = self.ren.GetActiveCamera().GetViewAngle()
        self.parallel_projection = self.ren.GetActiveCamera(
        ).GetParallelProjection()
        self.parallel_scale = self.ren.GetActiveCamera().GetParallelScale()
        self.clipping_range = self.ren.GetActiveCamera().GetClippingRange()
Exemple #4
0
    def __init__(self, renderer):
        Visualizer.__init__(self)

        assert isinstance(renderer, vtk.vtkRenderer)
        self.ren = renderer

        # -------- add a line ----
        # geometry
        self.line = vtk.vtkLineSource()
        self.line.SetPoint1(0, 0, 0)
        self.line.SetPoint2(0, +st.visTubeLength, 0)

        # mapper
        self.lineMapper = vtk.vtkPolyDataMapper()
        self.lineMapper.SetInputConnection(self.line.GetOutputPort())

        # actor
        self.lineActor = vtk.vtkLODActor()
        self.lineActor.SetMapper(self.lineMapper)

        # make it look nice
        self.lineProp = self.lineActor.GetProperty()
        self.lineProp.SetOpacity(0.0)

        self.ren.AddActor(self.lineActor)

        # -------- add a tube around the line ----
        # geometry
        self.tube = vtk.vtkTubeFilter()
        self.tube.SetNumberOfSides(100)
        self.tube.SetInputConnection(self.line.GetOutputPort())
        self.tube.SetRadius(st.visTubeDiameter/2)

        # mapper
        self.tubeMapper = vtk.vtkPolyDataMapper()
        self.tubeMapper.SetInputConnection(self.tube.GetOutputPort())

        # actor
        self.tubeActor = vtk.vtkLODActor()
        self.tubeActor.SetMapper(self.tubeMapper)

        # make it look nice
        self.tubeProp = self.tubeActor.GetProperty()
        self.tubeProp.SetColor(101/255, 123/255, 131/255)
        self.tubeProp.SetOpacity(0.5)

        self.ren.AddActor(self.tubeActor)

        # -------- add the ball ----
        # geometry
        self.ball = vtk.vtkSphereSource()
        self.ball.SetRadius(st.visBallDiameter/2)
        self.ball.SetThetaResolution(30)
        self.ball.SetPhiResolution(30)
        self.ball.SetCenter(0, st.visBallDiameter/2, 0)

        # mapper
        self.ballMapper = vtk.vtkPolyDataMapper()
        self.ballMapper.SetInputConnection(self.ball.GetOutputPort())

        # actor
        self.ballActor = vtk.vtkLODActor()
        self.ballActor.SetMapper(self.ballMapper)

        # make it look nice
        self.ballProp = self.ballActor.GetProperty()
        self.ballProp.SetColor(255/255, 255/255, 0)
        self.ballProp.SetAmbient(0.2)
        self.ballProp.SetDiffuse(0.8)
        self.ballProp.SetSpecular(0.5)
        self.ballProp.SetSpecularPower(0.5)

        self.ren.AddActor(self.ballActor)

        # -------- add background ----
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(228/255, 232/255, 213/255)
        self.ren.SetBackground2(38/255, 139/255, 210/255)

        # get everybody into the frame
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(1.0)
Exemple #5
0
    def __init__(self, renderer):
        Visualizer.__init__(self)

        assert isinstance(renderer, vtk.vtkRenderer)
        self.ren = renderer

        # -------- add the beam ----
        # geometry
        self.beam = vtk.vtkCubeSource()
        self.beam.SetXLength(st.beam_length)
        self.beam.SetYLength(st.beam_width)
        self.beam.SetZLength(st.beam_depth)

        # mapper
        self.beam_Mapper = vtk.vtkPolyDataMapper()
        self.beam_Mapper.SetInputConnection(self.beam.GetOutputPort())

        # actor
        self.beam_Actor = vtk.vtkLODActor()
        self.beam_Actor.SetMapper(self.beam_Mapper)
        self.beam_Actor.SetPosition(0, -(st.cart_width / 2 + st.beam_width / 2), 0)

        # make it look nice
        self.beam_Prop = self.beam_Actor.GetProperty()
        # RAL 9007, grey-aluminium
        self.beam_Prop.SetColor(142 / 255, 142 / 255, 139 / 255)

        self.ren.AddActor(self.beam_Actor)

        # -------- add cart ----
        # geometry
        self.cart = vtk.vtkCubeSource()
        self.cart.SetXLength(st.cart_length)
        self.cart.SetYLength(st.cart_width)
        self.cart.SetZLength(st.cart_depth)

        # mapper
        self.cart_Mapper = vtk.vtkPolyDataMapper()
        self.cart_Mapper.SetInputConnection(self.cart.GetOutputPort())

        # actor
        self.cart_Actor = vtk.vtkLODActor()
        self.cart_Actor.SetPosition(0, 0, 0)
        self.cart_Actor.RotateWXYZ(0, 1, 0, 0)
        self.cart_Actor.SetMapper(self.cart_Mapper)

        # make it look nice
        self.cart_Prop = self.cart_Actor.GetProperty()
        # RAL 7011, iron-grey
        self.cart_Prop.SetColor(64 / 255, 74 / 255, 84 / 255)

        self.ren.AddActor(self.cart_Actor)
        # save pose
        self.cart_pose = [np.array([0, 0, 0]), np.eye(3)]

        # -------- add axis ----
        # geometry
        self.axis = vtk.vtkCylinderSource()
        self.axis.SetHeight(st.axis_height)
        self.axis.SetRadius(st.axis_radius)
        self.axis.SetResolution(100)

        # mapper
        self.axis_Mapper = vtk.vtkPolyDataMapper()
        self.axis_Mapper.SetInputConnection(self.axis.GetOutputPort())

        # actor
        self.axis_Actor = vtk.vtkLODActor()
        self.axis_Actor.SetPosition(0, 0, st.cart_depth / 2 + st.axis_height / 2)
        self.axis_Actor.RotateWXYZ(90, 1, 0, 0)
        self.axis_Actor.SetMapper(self.axis_Mapper)

        # make it look nice
        self.axis_Prop = self.axis_Actor.GetProperty()
        # RAL 7011, iron-grey
        self.axis_Prop.SetColor(64 / 255, 74 / 255, 84 / 255)

        self.ren.AddActor(self.axis_Actor)
        # save pose
        self.axis_pose = [
            np.array([0, 0, st.cart_depth / 2 + st.axis_height / 2]),
            to.rotation_matrix_xyz("x", 90, "deg"),
        ]

        # -------- add short pendulum ----
        # add short pendulum shaft
        # geometry
        self.short_pendulum_shaft = vtk.vtkCylinderSource()
        self.short_pendulum_shaft.SetHeight(st.pendulum_shaft_height)
        self.short_pendulum_shaft.SetRadius(st.pendulum_shaft_radius)
        self.short_pendulum_shaft.SetResolution(100)

        # mapper
        self.short_pendulum_shaft_Mapper = vtk.vtkPolyDataMapper()
        self.short_pendulum_shaft_Mapper.SetInputConnection(self.short_pendulum_shaft.GetOutputPort())

        # actor
        self.short_pendulum_shaft_Actor = vtk.vtkLODActor()
        self.short_pendulum_shaft_Actor.SetPosition(
            0, 0, st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2
        )
        self.short_pendulum_shaft_Actor.RotateWXYZ(90, 1, 0, 0)
        self.short_pendulum_shaft_Actor.SetMapper(self.short_pendulum_shaft_Mapper)

        # make it look nice
        self.short_pendulum_shaft_Prop = self.short_pendulum_shaft_Actor.GetProperty()
        # RAL 9007, grey-aluminium, a little bit darker
        self.short_pendulum_shaft_Prop.SetColor(122 / 255, 122 / 255, 119 / 255)

        self.ren.AddActor(self.short_pendulum_shaft_Actor)
        # save pose
        self.short_pendulum_shaft_pose = [
            np.array([0, 0, st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2]),
            to.rotation_matrix_xyz("x", 90, "deg"),
        ]

        # add short pendulum
        # geometry
        self.short_pendulum = vtk.vtkCylinderSource()
        self.short_pendulum.SetHeight(st.short_pendulum_height)
        self.short_pendulum.SetRadius(st.short_pendulum_radius)
        self.short_pendulum.SetResolution(100)

        # mapper
        self.short_pendulum_Mapper = vtk.vtkPolyDataMapper()
        self.short_pendulum_Mapper.SetInputConnection(self.short_pendulum.GetOutputPort())

        # actor
        self.short_pendulum_Actor = vtk.vtkLODActor()
        self.short_pendulum_Actor.SetPosition(
            0, st.short_pendulum_height / 2, st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2
        )
        self.short_pendulum_Actor.RotateWXYZ(0, 1, 0, 0)
        self.short_pendulum_Actor.SetMapper(self.short_pendulum_Mapper)

        # make it look nice
        self.short_pendulum_Prop = self.short_pendulum_Actor.GetProperty()
        # RAL 9007, grey-aluminium, a little bit darker
        self.short_pendulum_Prop.SetColor(122 / 255, 122 / 255, 119 / 255)

        self.ren.AddActor(self.short_pendulum_Actor)
        self.short_pendulum_pose = [
            np.array(
                [0, st.short_pendulum_height / 2, st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2]
            ),
            np.eye(3),
        ]

        # add short pendulum weight
        # geometry
        self.short_pendulum_weight = vtk.vtkCylinderSource()
        self.short_pendulum_weight.SetHeight(st.pendulum_weight_height)
        self.short_pendulum_weight.SetRadius(st.pendulum_weight_radius)
        self.short_pendulum_weight.SetResolution(100)

        # mapper
        self.short_pendulum_weight_Mapper = vtk.vtkPolyDataMapper()
        self.short_pendulum_weight_Mapper.SetInputConnection(self.short_pendulum_weight.GetOutputPort())

        # actor
        self.short_pendulum_weight_Actor = vtk.vtkLODActor()
        self.short_pendulum_weight_Actor.SetPosition(
            0,
            (st.short_pendulum_height + st.pendulum_weight_height / 2),
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2,
        )
        self.short_pendulum_weight_Actor.RotateWXYZ(0, 1, 0, 0)
        self.short_pendulum_weight_Actor.SetMapper(self.short_pendulum_weight_Mapper)

        # make it look nice
        self.short_pendulum_weight_Prop = self.short_pendulum_weight_Actor.GetProperty()
        # RAL 9006, white-aluminium
        self.short_pendulum_weight_Prop.SetColor(162 / 255, 166 / 255, 164 / 255)

        self.ren.AddActor(self.short_pendulum_weight_Actor)
        self.short_pendulum_weight_pose = [
            np.array(
                [
                    0,
                    (st.short_pendulum_height + st.pendulum_weight_height / 2),
                    st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height / 2,
                ]
            ),
            np.eye(3),
        ]

        # -------- add long pendulum ----
        # add long pendulum shaft
        # geometry
        self.long_pendulum_shaft = vtk.vtkCylinderSource()
        self.long_pendulum_shaft.SetHeight(st.pendulum_shaft_height)
        self.long_pendulum_shaft.SetRadius(st.pendulum_shaft_radius)
        self.long_pendulum_shaft.SetResolution(100)

        # mapper
        self.long_pendulum_shaft_Mapper = vtk.vtkPolyDataMapper()
        self.long_pendulum_shaft_Mapper.SetInputConnection(self.long_pendulum_shaft.GetOutputPort())

        # actor
        self.long_pendulum_shaft_Actor = vtk.vtkLODActor()
        self.long_pendulum_shaft_Actor.SetPosition(
            0, 0, st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height + st.pendulum_shaft_height / 2
        )
        self.long_pendulum_shaft_Actor.RotateWXYZ(90, 1, 0, 0)
        self.long_pendulum_shaft_Actor.SetMapper(self.long_pendulum_shaft_Mapper)

        # make it look nice
        self.long_pendulum_shaft_Prop = self.long_pendulum_shaft_Actor.GetProperty()
        # RAL 9007, grey-aluminium
        self.long_pendulum_shaft_Prop.SetColor(142 / 255, 142 / 255, 139 / 255)

        self.ren.AddActor(self.long_pendulum_shaft_Actor)
        # save pose
        self.long_pendulum_shaft_pose = [
            np.array(
                [0, 0, st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height + st.pendulum_shaft_height / 2]
            ),
            to.rotation_matrix_xyz("x", 90, "deg"),
        ]

        # add long pendulum
        # geometry
        self.long_pendulum = vtk.vtkCylinderSource()
        self.long_pendulum.SetHeight(st.long_pendulum_height)
        self.long_pendulum.SetRadius(st.long_pendulum_radius)
        self.long_pendulum.SetResolution(100)

        # mapper
        self.long_pendulum_Mapper = vtk.vtkPolyDataMapper()
        self.long_pendulum_Mapper.SetInputConnection(self.long_pendulum.GetOutputPort())

        # actor
        self.long_pendulum_Actor = vtk.vtkLODActor()
        self.long_pendulum_Actor.SetPosition(
            0,
            st.long_pendulum_height / 2,
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height + st.pendulum_shaft_height / 2,
        )
        self.long_pendulum_Actor.RotateWXYZ(0, 1, 0, 0)
        self.long_pendulum_Actor.SetMapper(self.long_pendulum_Mapper)

        # make it look nice
        self.long_pendulum_Prop = self.long_pendulum_Actor.GetProperty()
        # RAL 9007, grey-aluminium
        self.long_pendulum_Prop.SetColor(142 / 255, 142 / 255, 139 / 255)

        self.ren.AddActor(self.long_pendulum_Actor)
        self.long_pendulum_pose = [
            np.array(
                [
                    0,
                    st.long_pendulum_height / 2,
                    st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height + st.pendulum_shaft_height / 2,
                ]
            ),
            np.eye(3),
        ]

        # add long pendulum weight
        # geometry
        self.long_pendulum_weight = vtk.vtkCylinderSource()
        self.long_pendulum_weight.SetHeight(st.pendulum_weight_height)
        self.long_pendulum_weight.SetRadius(st.pendulum_weight_radius)
        self.long_pendulum_weight.SetResolution(100)

        # mapper
        self.long_pendulum_weight_Mapper = vtk.vtkPolyDataMapper()
        self.long_pendulum_weight_Mapper.SetInputConnection(self.long_pendulum_weight.GetOutputPort())

        # actor
        self.long_pendulum_weight_Actor = vtk.vtkLODActor()
        self.long_pendulum_weight_Actor.SetPosition(
            0,
            (st.long_pendulum_height + st.pendulum_weight_height / 2),
            st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height + st.pendulum_shaft_height / 2,
        )
        self.long_pendulum_weight_Actor.RotateWXYZ(0, 1, 0, 0)
        self.long_pendulum_weight_Actor.SetMapper(self.long_pendulum_weight_Mapper)

        # make it look nice
        self.long_pendulum_weight_Prop = self.long_pendulum_weight_Actor.GetProperty()
        # RAL 9006, white-aluminium
        self.long_pendulum_weight_Prop.SetColor(162 / 255, 166 / 255, 164 / 255)

        self.ren.AddActor(self.long_pendulum_weight_Actor)
        self.long_pendulum_weight_pose = [
            np.array(
                [
                    0,
                    (st.long_pendulum_height + st.pendulum_weight_height / 2),
                    st.cart_depth / 2 + st.axis_height + st.pendulum_shaft_height + st.pendulum_shaft_height / 2,
                ]
            ),
            np.eye(3),
        ]

        # add background
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(228 / 255, 232 / 255, 213 / 255)
        self.ren.SetBackground2(38 / 255, 139 / 255, 210 / 255)

        # get everybody into the frame
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(1.45)
        self.ren.GetActiveCamera().SetFocalPoint(0, 0, 0)

        # add camera reset functionality
        self.can_reset_view = True
        self.position = self.ren.GetActiveCamera().GetPosition()
        self.focal_point = self.ren.GetActiveCamera().GetFocalPoint()
        self.view_up = self.ren.GetActiveCamera().GetViewUp()
        self.view_angle = self.ren.GetActiveCamera().GetViewAngle()
        self.parallel_projection = self.ren.GetActiveCamera().GetParallelProjection()
        self.parallel_scale = self.ren.GetActiveCamera().GetParallelScale()
        self.clipping_range = self.ren.GetActiveCamera().GetClippingRange()
Exemple #6
0
    def __init__(self, renderer):
        Visualizer.__init__(self)

        assert isinstance(renderer, vtk.vtkRenderer)
        self.ren = renderer

        # -------- add a line ----
        # geometry
        self.line = vtk.vtkLineSource()
        self.line.SetPoint1(0, 0, 0)
        self.line.SetPoint2(0, +st.visTubeLength, 0)

        # mapper
        self.lineMapper = vtk.vtkPolyDataMapper()
        self.lineMapper.SetInputConnection(self.line.GetOutputPort())

        # actor
        self.lineActor = vtk.vtkLODActor()
        self.lineActor.SetMapper(self.lineMapper)

        # make it look nice
        self.lineProp = self.lineActor.GetProperty()
        self.lineProp.SetOpacity(0.0)

        self.ren.AddActor(self.lineActor)

        # -------- add a tube around the line ----
        # geometry
        self.tube = vtk.vtkTubeFilter()
        self.tube.SetNumberOfSides(100)
        self.tube.SetInputConnection(self.line.GetOutputPort())
        self.tube.SetRadius(st.visTubeDiameter / 2)

        # mapper
        self.tubeMapper = vtk.vtkPolyDataMapper()
        self.tubeMapper.SetInputConnection(self.tube.GetOutputPort())

        # actor
        self.tubeActor = vtk.vtkLODActor()
        self.tubeActor.SetMapper(self.tubeMapper)

        # make it look nice
        self.tubeProp = self.tubeActor.GetProperty()
        self.tubeProp.SetColor(101 / 255, 123 / 255, 131 / 255)
        self.tubeProp.SetOpacity(0.5)

        self.ren.AddActor(self.tubeActor)

        # -------- add the ball ----
        # geometry
        self.ball = vtk.vtkSphereSource()
        self.ball.SetRadius(st.visBallDiameter / 2)
        self.ball.SetThetaResolution(30)
        self.ball.SetPhiResolution(30)
        self.ball.SetCenter(0, st.visBallDiameter / 2, 0)

        # mapper
        self.ballMapper = vtk.vtkPolyDataMapper()
        self.ballMapper.SetInputConnection(self.ball.GetOutputPort())

        # actor
        self.ballActor = vtk.vtkLODActor()
        self.ballActor.SetMapper(self.ballMapper)

        # make it look nice
        self.ballProp = self.ballActor.GetProperty()
        self.ballProp.SetColor(255 / 255, 255 / 255, 0)
        self.ballProp.SetAmbient(0.2)
        self.ballProp.SetDiffuse(0.8)
        self.ballProp.SetSpecular(0.5)
        self.ballProp.SetSpecularPower(0.5)

        self.ren.AddActor(self.ballActor)

        # -------- add background ----
        self.ren.GradientBackgroundOn()
        self.ren.SetBackground(228 / 255, 232 / 255, 213 / 255)
        self.ren.SetBackground2(38 / 255, 139 / 255, 210 / 255)

        # get everybody into the frame
        self.ren.ResetCamera()
        self.ren.GetActiveCamera().Zoom(1.0)