コード例 #1
0
    def on_timer(self, event):

        model = np.eye(4, dtype=np.float32)
        #scale(model, 1, 1, 1)
        self.cube['model'] = model

        self.view = np.eye(4)
        xrotate(self.view, self.rotate[0])
        yrotate(self.view, self.rotate[1])
        zrotate(self.view, self.rotate[2])
        translate(self.view, *self.translate)

        self.listener.waitForTransform("/robot", "/wrist_joint", rospy.Time(), rospy.Duration(4))
        
        pos, rot = self.listener.lookupTransform("/robot", "/wrist_joint", rospy.Time(0))

        print list(pos)
        
        self.translate[0] = -list(pos)[0] * 10
        self.translate[1] = -list(pos)[1] * 10
        self.translate[2] = -5

        self.cube['view'] = self.view



        self.update()
コード例 #2
0
ファイル: terrain.py プロジェクト: almarklein/vispy
    def on_key_press(self, event):
        """Controls -
        a(A) - move left
        d(D) - move right
        w(W) - move up
        s(S) - move down
        x/X - rotate about x-axis cw/anti-cw
        y/Y - rotate about y-axis cw/anti-cw
        z/Z - rotate about z-axis cw/anti-cw
        space - reset view
        p(P) - print current view
        i(I) - zoom in
        o(O) - zoom out
        """
        self.translate = [0, 0, 0]
        self.rotate = [0, 0, 0]

        if(event.text == 'p' or event.text == 'P'):
            print(self.view)
        elif(event.text == 'd' or event.text == 'D'):
            self.translate[0] = 0.3
        elif(event.text == 'a' or event.text == 'A'):
            self.translate[0] = -0.3
        elif(event.text == 'w' or event.text == 'W'):
            self.translate[1] = 0.3
        elif(event.text == 's' or event.text == 'S'):
            self.translate[1] = -0.3
        elif(event.text == 'o' or event.text == 'O'):
            self.translate[2] = 0.3
        elif(event.text == 'i' or event.text == 'I'):
            self.translate[2] = -0.3
        elif(event.text == 'x'):
            self.rotate = [1, 0, 0]
        elif(event.text == 'X'):
            self.rotate = [-1, 0, 0]
        elif(event.text == 'y'):
            self.rotate = [0, 1, 0]
        elif(event.text == 'Y'):
            self.rotate = [0, -1, 0]
        elif(event.text == 'z'):
            self.rotate = [0, 0, 1]
        elif(event.text == 'Z'):
            self.rotate = [0, 0, -1]
        elif(event.text == ' '):
            self.view = self.default_view

        translate(self.view, -self.translate[0], -self.translate[1],
                  -self.translate[2])
        xrotate(self.view, self.rotate[0])
        yrotate(self.view, self.rotate[1])
        zrotate(self.view, self.rotate[2])

        self.program['u_view'] = self.view
        self.update()
コード例 #3
0
ファイル: terrain.py プロジェクト: vanossj/vispy
    def on_key_press(self, event):
        """Controls -
        a(A) - move left
        d(D) - move right
        w(W) - move up
        s(S) - move down
        x/X - rotate about x-axis cw/anti-cw
        y/Y - rotate about y-axis cw/anti-cw
        z/Z - rotate about z-axis cw/anti-cw
        space - reset view
        p(P) - print current view
        i(I) - zoom in
        o(O) - zoom out
        """
        self.translate = [0, 0, 0]
        self.rotate = [0, 0, 0]

        if (event.text == 'p' or event.text == 'P'):
            print(self.view)
        elif (event.text == 'd' or event.text == 'D'):
            self.translate[0] = 0.3
        elif (event.text == 'a' or event.text == 'A'):
            self.translate[0] = -0.3
        elif (event.text == 'w' or event.text == 'W'):
            self.translate[1] = 0.3
        elif (event.text == 's' or event.text == 'S'):
            self.translate[1] = -0.3
        elif (event.text == 'o' or event.text == 'O'):
            self.translate[2] = 0.3
        elif (event.text == 'i' or event.text == 'I'):
            self.translate[2] = -0.3
        elif (event.text == 'x'):
            self.rotate = [1, 0, 0]
        elif (event.text == 'X'):
            self.rotate = [-1, 0, 0]
        elif (event.text == 'y'):
            self.rotate = [0, 1, 0]
        elif (event.text == 'Y'):
            self.rotate = [0, -1, 0]
        elif (event.text == 'z'):
            self.rotate = [0, 0, 1]
        elif (event.text == 'Z'):
            self.rotate = [0, 0, -1]
        elif (event.text == ' '):
            self.view = self.default_view

        translate(self.view, -self.translate[0], -self.translate[1],
                  -self.translate[2])
        xrotate(self.view, self.rotate[0])
        yrotate(self.view, self.rotate[1])
        zrotate(self.view, self.rotate[2])

        self.program['u_view'] = self.view
        self.update()
コード例 #4
0
ファイル: view_simulation.py プロジェクト: ccccjason/IEEE2015
    def on_timer(self, event):
        # self.phi += .5
        model = np.eye(4, dtype=np.float32)
        scale(model, 1, 1, 1)
        # rotate(model, self.phi, 0, 0, 1)
        self.cube['model'] = model

        self.view = np.eye(4)
        xrotate(self.view, self.rotate[0])
        yrotate(self.view, self.rotate[1])
        zrotate(self.view, self.rotate[2])
        translate(self.view, *self.translate)

        self.cube['view'] = self.view

        self.update()
コード例 #5
0
ファイル: view_simulation.py プロジェクト: shihyu/IEEE2015
    def on_timer(self, event):
        # self.phi += .5
        model = np.eye(4, dtype=np.float32)
        scale(model, 1, 1, 1)
        # rotate(model, self.phi, 0, 0, 1)
        self.cube['model'] = model

        self.view = np.eye(4)
        xrotate(self.view, self.rotate[0])
        yrotate(self.view, self.rotate[1])
        zrotate(self.view, self.rotate[2])
        translate(self.view, *self.translate)

        self.cube['view'] = self.view

        self.update()
コード例 #6
0
    def __init__(self, text, canvas, position=1, color=(0.1, 0.0, 0.7)):
        '''
        Give this the 
        - text to be written
        - main app.canvas
        - position (1-9, or which button position this should occupy)
        '''

        # State Controller
        State.register_button(position, text)

        self.position = position
        self.canvas = canvas
        self.projection = np.eye(4)
        self.view = np.eye(4)
        self.model = np.eye(4)
        height, width = 5.0, 15.0  # Meters

        orientation_vector = (1, 1, 0)
        unit_orientation_angle = np.array(orientation_vector) / np.linalg.norm(
            orientation_vector)

        scale_factor = 0.2
        lowest_button = -5.2
        midset = 0.2

        scale(self.model, scale_factor)
        yrotate(self.model, -60)
        # rotate(self.model, 30, *unit_orientation_angle)
        offset = (position * ((height + midset) * scale_factor))
        translate(self.model, -7.4, lowest_button + offset, -10)

        pixel_to_length = 10
        self.size = map(lambda o: pixel_to_length * o, [width, height])

        # Add texture coordinates
        # Rectangle of height height
        self.vertices = np.array([
            [-width / 2, -height / 2, 0],
            [width / 2, -height / 2, 0],
            [width / 2, height / 2, 0],
            [-width / 2, height / 2, 0],
        ],
                                 dtype=np.float32)

        self.tex_coords = np.array([
            [0, 0],
            [1, 0],
            [1, 1],
            [0, 1],
        ],
                                   dtype=np.float32)

        self.indices = IndexBuffer([
            0,
            1,
            2,
            2,
            3,
            0,
        ])

        self.program = Program(self.button_vertex_shader,
                               self.button_fragment_shader)

        self.program['vertex_position'] = self.vertices
        self.program['default_texcoord'] = self.tex_coords
        self.program['view'] = self.view
        self.program['model'] = self.model
        self.program['projection'] = self.projection
        self.program['background_color'] = color

        self.program['highlighted'] = 0

        # self.texture = Texture2D(shape=(1000, 1000) + (3,))
        # self.text_buffer = FrameBuffer(self.texture, RenderBuffer((1000, 1000)))
        self.texture = Texture2D(shape=(500, 1500) + (3, ))
        self.text_buffer = FrameBuffer(self.texture, RenderBuffer((500, 1500)))

        self.program['texture'] = self.texture
        self.text = text
        self.make_text(self.text)

        self.first = True
コード例 #7
0
ファイル: menu.py プロジェクト: jpanikulam/visar
    def __init__(self, text, canvas, position=1, color=(0.1, 0.0, 0.7)):
        '''
        Give this the 
        - text to be written
        - main app.canvas
        - position (1-9, or which button position this should occupy)
        '''

        # State Controller
        State.register_button(position, text)

        self.position = position
        self.canvas = canvas
        self.projection = np.eye(4)
        self.view = np.eye(4)
        self.model = np.eye(4)
        height, width = 5.0, 15.0  # Meters

        orientation_vector = (1, 1, 0)
        unit_orientation_angle = np.array(orientation_vector) / np.linalg.norm(orientation_vector)

        scale_factor = 0.2
        lowest_button = -5.2 
        midset = 0.2

        scale(self.model, scale_factor)
        yrotate(self.model, -60)
        # rotate(self.model, 30, *unit_orientation_angle)
        offset = (position * ((height + midset) * scale_factor))
        translate(self.model, -7.4, lowest_button + offset, -10)

        pixel_to_length = 10
        self.size = map(lambda o: pixel_to_length * o, [width, height])

        # Add texture coordinates
        # Rectangle of height height
        self.vertices = np.array([
            [-width / 2, -height / 2, 0],
            [ width / 2, -height / 2, 0],
            [ width / 2,  height / 2, 0],
            [-width / 2,  height / 2, 0],
        ], dtype=np.float32)

        self.tex_coords = np.array([
            [0, 0],
            [1, 0],
            [1, 1],
            [0, 1],

        ], dtype=np.float32)

        self.indices = IndexBuffer([
            0, 1, 2,
            2, 3, 0,
        ])

        self.program = Program(self.button_vertex_shader, self.button_fragment_shader)

        self.program['vertex_position'] = self.vertices
        self.program['default_texcoord'] = self.tex_coords
        self.program['view'] = self.view
        self.program['model'] = self.model
        self.program['projection'] = self.projection
        self.program['background_color'] = color

        self.program['highlighted'] = 0

        # self.texture = Texture2D(shape=(1000, 1000) + (3,))        
        # self.text_buffer = FrameBuffer(self.texture, RenderBuffer((1000, 1000)))
        self.texture = Texture2D(shape=(500, 1500) + (3,))        
        self.text_buffer = FrameBuffer(self.texture, RenderBuffer((500, 1500)))

        self.program['texture'] = self.texture
        self.text = text
        self.make_text(self.text)

        self.first = True
コード例 #8
0
ファイル: battery.py プロジェクト: khaledhassan/visar
    def __init__(self):
        self.projection = np.eye(4)
        self.view = np.eye(4)
        self.model = np.eye(4)

        height, width = 3.0, 6.0
        scale_factor = 0.2
        x_offset = -8
        y_offset = 2
        pixel_to_length = 10
        color = (1.0, 1.0, 1.0)

        scale(self.model, scale_factor)
        yrotate(self.model, -60)
        translate(self.model, x_offset, y_offset, -10)
        size = (int(height * 100), int(width * 100))

        self.vertices = np.array([
            [-width / 2, -height / 2, 0],
            [width / 2, -height / 2, 0],
            [width / 2, height / 2, 0],
            [-width / 2, height / 2, 0],
        ],
                                 dtype=np.float32)

        self.tex_coords = np.array([
            [0, 0],
            [1, 0],
            [1, 1],
            [0, 1],
        ],
                                   dtype=np.float32)

        self.indices = IndexBuffer([
            0,
            1,
            2,
            2,
            3,
            0,
        ])

        self.program = Program(self.battery_vertex_shader,
                               self.battery_fragment_shader)

        self.texture = Texture2D(shape=size + (3, ))
        self.text_buffer = FrameBuffer(self.texture, RenderBuffer(size))

        images = []
        images.append(
            Image.open(
                os.path.join(Paths.get_path_to_visar(), 'visar', 'images',
                             'battery', 'battery_low_color.png')))
        images.append(
            Image.open(
                os.path.join(Paths.get_path_to_visar(), 'visar', 'images',
                             'battery', 'battery_used_color.png')))
        images.append(
            Image.open(
                os.path.join(Paths.get_path_to_visar(), 'visar', 'images',
                             'battery', 'battery_full_color.png')))

        self.level_texture = {}  # texture for each level

        for x in range(0, len(images)):
            default_image = images[x]
            default_image = default_image.rotate(-90)
            default_image = default_image.resize(size)
            default_image = default_image.transpose(Image.FLIP_TOP_BOTTOM)
            default_image_array = np.asarray(default_image)
            self.level_texture[x + 1] = default_image_array

        #default_image_array = imageio.imread(os.path.join(Paths.get_path_to_visar(), 'visar', 'images', 'battery', 'battery_full_color.png'))

        # self.default_tex = Texture2D(data=default_image_array)
        # self.default_tex = Texture2D(shape=size + (3,))
        # self.default_tex.set_data(self.level_texture[3])

        self.program['vertex_position'] = self.vertices
        self.program['default_texcoord'] = self.tex_coords
        self.program['view'] = self.view
        self.program['model'] = self.model
        self.program['projection'] = self.projection
        self.program['hide'] = 0

        # self.tex_program = Program(self.tex_vert_shader, self.battery_fragment_shader)

        # self.tex_program['vertex_position']  = self.vertices
        # self.tex_program['default_texcoord'] = self.tex_coords
        # self.tex_program['hide']             = 0
        # self.tex_program['texture']          = self.default_tex

        self.flag = True  # flag to update the texture

        self.level = 3  # level of the battery 1 - 3
        full_middle_split = 75  # split between levels 2 and 3
        middle_low_split = 25  # split between levels 1 and 2
        fault_tolerance = 5
        self.full_lower = full_middle_split - fault_tolerance  # lower limit for going from 3 to 2
        self.middle_upper = full_middle_split + fault_tolerance  # upper limit for going from 2 to 3
        self.middle_lower = middle_low_split - fault_tolerance  # lower limit for going from 2 to 1
        self.low_upper = middle_low_split + fault_tolerance  # upper limit for going from 1 to 2
コード例 #9
0
ファイル: battery.py プロジェクト: jpanikulam/visar
    def __init__(self):
        self.projection = np.eye(4)
        self.view       = np.eye(4)
        self.model      = np.eye(4)

        height, width   = 3.0, 6.0
        scale_factor    = 0.2
        x_offset        = -8
        y_offset        = 2
        pixel_to_length = 10
        color           = (1.0, 1.0, 1.0)

        scale(self.model, scale_factor)
        yrotate(self.model, -60)
        translate(self.model, x_offset, y_offset, -10)
        size = (int(height*100), int(width*100))

        self.vertices = np.array([
            [-width / 2, -height / 2, 0],
            [ width / 2, -height / 2, 0],
            [ width / 2,  height / 2, 0],
            [-width / 2,  height / 2, 0],
        ], dtype=np.float32)

        self.tex_coords = np.array([
            [0, 0],
            [1, 0],
            [1, 1],
            [0, 1],

        ], dtype=np.float32)

        self.indices = IndexBuffer([
            0, 1, 2,
            2, 3, 0,
        ])

        self.program = Program(self.battery_vertex_shader, self.battery_fragment_shader)

        self.texture = Texture2D(shape=size + (3,))
        self.text_buffer = FrameBuffer(self.texture, RenderBuffer(size))

        images = []
        images.append(Image.open(os.path.join(Paths.get_path_to_visar(), 'visar', 'images', 'battery', 'battery_low_color.png')))
        images.append(Image.open(os.path.join(Paths.get_path_to_visar(), 'visar', 'images', 'battery', 'battery_used_color.png')))
        images.append(Image.open(os.path.join(Paths.get_path_to_visar(), 'visar', 'images', 'battery', 'battery_full_color.png')))

        self.level_texture = {} # texture for each level

        for x in range(0, len(images)):
            default_image = images[x]
            default_image = default_image.rotate(-90)
            default_image = default_image.resize(size)
            default_image = default_image.transpose(Image.FLIP_TOP_BOTTOM)
            default_image_array = np.asarray(default_image)
            self.level_texture[x + 1] = default_image_array

        #default_image_array = imageio.imread(os.path.join(Paths.get_path_to_visar(), 'visar', 'images', 'battery', 'battery_full_color.png'))


        # self.default_tex = Texture2D(data=default_image_array)
        # self.default_tex = Texture2D(shape=size + (3,))
        # self.default_tex.set_data(self.level_texture[3])

        self.program['vertex_position']  = self.vertices
        self.program['default_texcoord'] = self.tex_coords
        self.program['view']             = self.view
        self.program['model']            = self.model
        self.program['projection']       = self.projection
        self.program['hide']             = 0

        # self.tex_program = Program(self.tex_vert_shader, self.battery_fragment_shader)

        # self.tex_program['vertex_position']  = self.vertices
        # self.tex_program['default_texcoord'] = self.tex_coords
        # self.tex_program['hide']             = 0
        # self.tex_program['texture']          = self.default_tex

        self.flag = True # flag to update the texture

        self.level = 3 # level of the battery 1 - 3
        full_middle_split = 75 # split between levels 2 and 3
        middle_low_split = 25 # split between levels 1 and 2
        fault_tolerance = 5
        self.full_lower = full_middle_split - fault_tolerance # lower limit for going from 3 to 2
        self.middle_upper = full_middle_split + fault_tolerance # upper limit for going from 2 to 3
        self.middle_lower = middle_low_split - fault_tolerance # lower limit for going from 2 to 1
        self.low_upper = middle_low_split + fault_tolerance # upper limit for going from 1 to 2
コード例 #10
0
ファイル: main.py プロジェクト: lzir/vispy-point-cloud
    def on_key_press(self, event):
        """Controls -
        a(A) - move left
        d(D) - move right
        w(W) - move up
        s(S) - move down
        x/X - rotate about x-axis cw/anti-cw
        y/Y - rotate about y-axis cw/anti-cw
        z/Z - rotate about z-axis cw/anti-cw
        space - reset view
        p(P) - print current view
        i(I) - zoom in
        o(O) - zoom out
        6 - Move light right
        4 - Move light left
        8 - Move light up
        5 - Move light down
        7 - Move light up (depthwise)
        1 - Move light down (depthwise)
        """
        self.translate = [0, 0, 0]
        self.rotate = [0, 0, 0]

        if (event.text == 'p' or event.text == 'P'):
            print(self.view)
        elif (event.text == 'd' or event.text == 'D'):
            self.translate[0] = 30.
        elif (event.text == 'a' or event.text == 'A'):
            self.translate[0] = -30.
        elif (event.text == 'w' or event.text == 'W'):
            self.translate[1] = 30.
        elif (event.text == 's' or event.text == 'S'):
            self.translate[1] = -30.
        elif (event.text == 'o' or event.text == 'O'):
            self.translate[2] = 30.
        elif (event.text == 'i' or event.text == 'I'):
            self.translate[2] = -30.
        elif (event.text == 'x'):
            self.rotate = [1, 0, 0]
        elif (event.text == 'X'):
            self.rotate = [-1, 0, 0]
        elif (event.text == 'y'):
            self.rotate = [0, 1, 0]
        elif (event.text == 'Y'):
            self.rotate = [0, -1, 0]
        elif (event.text == 'z'):
            self.rotate = [0, 0, 1]
        elif (event.text == 'Z'):
            self.rotate = [0, 0, -1]
        elif (event.text == 'h'):
            self.rotate = [0, 0, 0]
        elif (event.text == 'j'):
            self.rotate = [90, 0, 0]
        elif (event.text == 'k'):
            self.rotate = [180, 0, 0]
        elif (event.text == 'l'):
            self.rotate = [270, 0, 0]
        elif (event.text == ' '):
            self.view = self.default_view
        elif (event.text == '6'):
            self.lightx += 100.
        elif (event.text == '4'):
            self.lightx += -100.
        elif (event.text == '8'):
            self.lighty += 100.
        elif (event.text == '5'):
            self.lighty += -100.
        elif (event.text == '7'):
            self.lightz += 100.
        elif (event.text == '1'):
            self.lightz += -100.

        translate(self.view, -self.translate[0], -self.translate[1],
                  -self.translate[2])
        xrotate(self.view, self.rotate[0])
        yrotate(self.view, self.rotate[1])
        zrotate(self.view, self.rotate[2])

        self.program[
            "u_light_position"] = self.lightx, self.lighty, self.lightz
        self.program['u_view'] = self.view
        self.update()