Exemplo n.º 1
0
    def __init__(self,
                 camera_gear,
                 lines_length=1.,
                 outer_line_thickness=6.0,
                 alpha=0.5):
        """ """
        self.camera_gear = camera_gear

        self.alpha = alpha

        self.crosshair_outer_lines_length = lines_length
        self.crosshair_outer_thickness = outer_line_thickness
        self.crosshair_outer_color = Vec4(0., 0., 0., self.alpha)

        self.crosshair_inner_thickness = 1. / 3. * self.crosshair_outer_thickness
        self.crosshair_inner_lines_length = 0.98 * self.crosshair_outer_lines_length
        self.crosshair_inner_color = Vec4(1., 1., 1., self.alpha)

        self.l1i = None
        self.l1o = None

        self.l2i = None
        self.l2o = None

        self.l3i = None
        self.l3o = None

        TQGraphicsNodePath.__init__(self)

        self.update()
Exemplo n.º 2
0
    def __init__(self, pdf_panner2d, pdf_filepath, *args, **kwargs):
        TQGraphicsNodePath.__init__(self, *args, **kwargs)

        # logical variables
        self.pdf_filepath = pdf_filepath
        self.pptos = []
        self.y_pages_distance = PDFViewer.y_pages_distance_0

        # derived
        self.pdf_panner2d = pdf_panner2d  # something like Panner2d
        self.ppr = PopplerPDFRenderer(self.pdf_filepath)

        # direct objects
        base.accept('1', self.return_to_middle_view)
        base.accept('space', self.scroll_spacebar_down)
        base.accept('shift-space', self.scroll_spacebar_up)

        base.accept('control-0', self.return_to_middle_view)

        # quad visualizing large margins for visual orientation
        self.margins_quad = Quad(thickness=10.)
        self.margins_quad.reparentTo(self)

        # plot
        self.render_pages()

        self.return_to_middle_view()
Exemplo n.º 3
0
    def __init__(self):
        """ """
        TQGraphicsNodePath.__init__(self)

        ls = LineSegs()
        ls.setThickness(1)

        # X axis
        ls.setColor(1.0, 0.0, 0.0, 1.0)
        ls.moveTo(0.0, 0.0, 0.0)
        ls.drawTo(1.0, 0.0, 0.0)

        # Y axis
        ls.setColor(0.0, 1.0, 0.0, 1.0)
        ls.moveTo(0.0, 0.0, 0.0)
        ls.drawTo(0.0, 1.0, 0.0)

        # Z axis
        ls.setColor(0.0, 0.0, 1.0, 1.0)
        ls.moveTo(0.0, 0.0, 0.0)
        ls.drawTo(0.0, 0.0, 1.0)

        geomnode = ls.create()
        self.set_p3d_nodepath(NodePath(geomnode))
        self.setLightOff(1)
Exemplo n.º 4
0
    def __init__(self, tex_expression, **kwargs):
        TQGraphicsNodePath.__init__(self, **kwargs)

        self.tex_expression = tex_expression

        self.makeObject()

        self.doInitialSetupTransformation()
Exemplo n.º 5
0
    def __init__(self, coords=None, thickness=1., color=Vec4(1., 1., 1., 1.), **kwargs):
        TQGraphicsNodePath.__init__(self, **kwargs)

        self.coords = coords
        self.thickness = thickness
        self.color = color

        # self.set_p3d_nodepath(None)

        self.updateObject()
Exemplo n.º 6
0
    def __init__(self):
        """
        """
        self.log_list = []

        self.task_obj_update = None

        self.task_obj_update = taskMgr.add(self.update, 'update')

        TQGraphicsNodePath.__init__(self)
Exemplo n.º 7
0
    def __init__(self, orbiter):
        """
        Args:
            orbiter : the orbiter object that gets these visual aids """
        self.orbiter = orbiter

        TQGraphicsNodePath.__init__(self)

        # self.crosshair = None
        self.crosshair = CrossHair3d(self.orbiter, lines_length=0.25)
        self.crosshair.reparentTo(self)
Exemplo n.º 8
0
    def __init__(self, camera_gear, scale=0.05):
        """ """
        self.camera_gear = camera_gear  # needed for re-orientation towards the camera whenever it's updated or the camera moves

        self.scale_total = scale
        self.rel_scale_point_center = 0.4
        self.rel_scale_circle_outer_first = 0.6
        self.rel_scale_circle_outer_second = 0.9
        # self.rel_scale_circle_outer_third = 1.2
        self.num_of_verts = 20

        self.color_point_center = Vec4(1., 1., 1., 1.)
        self.color_circle_outer_first = Vec4(0., 0., 0., 1.)
        self.color_circle_outer_second = Vec4(1., 1., 1., 1.)
        # self.color_circle_outer_third = Vec4(0., 0., 0., 1.)

        self._initial_normal_vector = Vec3(1., 0., 0.)

        TQGraphicsNodePath.__init__(self)

        self.point_center = Point3d(scale=self.scale_total *
                                    self.rel_scale_point_center)
        self.point_center.reparentTo(self)

        self.circle_outer_first = OrientedCircle(
            target_normal_vector=self._initial_normal_vector,
            initial_scaling=self.scale_total *
            self.rel_scale_circle_outer_first,
            num_of_verts=self.num_of_verts,
            thickness=3.)
        self.circle_outer_first.reparentTo(self)

        self.circle_outer_second = OrientedCircle(
            target_normal_vector=self._initial_normal_vector,
            initial_scaling=self.scale_total *
            self.rel_scale_circle_outer_second,
            num_of_verts=self.num_of_verts,
            thickness=3.)
        self.circle_outer_second.reparentTo(self)

        # the closest to root node of the cursor saves the translation (along the edgeplayer) (i.e. here the additional_trafo_nodepath)
        # the edgeplayer node itself actually only has a rotation, which it sets to
        # always reorient towards the camera. If I didn't separate the two (translation and rotation)
        # into two separate nodes, I would need to declare additional functions for TQGraphicsNodePath to
        # set and get Rotation, Position and Scaling components of the Model Matrix independently of each other
        # (which I guess can be done, since a Model Matrix actually be decomposed)

        self.additional_trafo_nodepath = TQGraphicsNodePath()
        self.additional_trafo_nodepath.reparentTo_p3d(self.getParent_p3d())
        super().reparentTo(self.additional_trafo_nodepath)

        self.camera_gear.add_camera_move_hook(self._adjust)

        self._adjust()
Exemplo n.º 9
0
    def __init__(self, camera_gear, height=None, width=None, **kwargs):
        """ """
        height_0 = 0.5
        width_0 = 16 / 9 * height_0

        TQGraphicsNodePath.__init__(self, **kwargs)

        self.camera_gear = camera_gear
        self.drag_point = Point3d()
        self.drag_point.reparentTo(engine.tq_graphics_basics.tq_render)
        self.drag_point.setColor(Vec4(1.0, 0., 0., 1.), 1)

        self.quad_border_thickness = None
        if "quad_border_thickness" in kwargs:
            self.quad_border_thickness = kwargs.get("quad_border_thickness")
        elif self.quad_border_thickness is None:
            self.quad_border_thickness = 1.5

        self.bg_quad = Quad(thickness=self.quad_border_thickness)

        if height is None:
            height = height_0

        if width is None:
            width = width_0

        self.bg_quad.set_height(height)
        self.bg_quad.set_width(width)
        self.bg_quad.reparentTo(self)
        self.bg_quad.setPos(Vec3(0., 0., 0.))
        self.bg_quad.setColor(Vec4(1., 1., 1., 0.5), 1)

        # -------------------------------------
        self.pom = PickableObjectManager()
        self.pom.tag(self.drag_point.get_p3d_nodepath())

        self.dadom = DragAndDropObjectsManager()

        self.pt_dragger = PickableObjectDragger(self.drag_point,
                                                self.camera_gear)
        self.pt_dragger.add_on_state_change_function(
            self.move_frame_when_dragged)

        self.dadom.add_dragger(self.pt_dragger)

        self.collisionPicker = CollisionPicker(
            camera_gear, engine.tq_graphics_basics.tq_render,
            base.mouseWatcherNode, self.dadom)

        # -- add a mouse task to check for picking
        self.p3d_draw_direct_object = DirectObject.DirectObject()
        self.p3d_draw_direct_object.accept('mouse1',
                                           self.collisionPicker.onMouseTask)
Exemplo n.º 10
0
    def __init__(self, fig=None):
        """ """
        TQGraphicsNodePath.__init__(self)

        self.fig = None
        if fig is not None:
            self.fig = fig
        else:
            fig = plt.figure(figsize=(5, 5))

        tmplf = TextureOfMatplotlibFigure(fig,
                                          scaling=1.0,
                                          backgroud_opacity=0.0)
        tmplf.attach_to_aspect2d()

        width, height = tmplf.get_dimensions_from_calc()
        tmplf.setPos(
            Vec3(
                1.0 * engine.tq_graphics_basics.get_window_aspect_ratio() -
                width, 0., -1.))

        self.angle = 0.
        self.ax = fig.add_subplot(111, projection='3d')

        def add_plot_thread_wrapped():
            """ """
            td = threading.Thread(target=self.add_plot, daemon=True)
            td.start()

            def wait_for_thread_to_finish_task(task):
                """ """
                if td.is_alive():
                    return task.cont

                self.ax.w_xaxis.line.set_color("white")
                self.ax.w_yaxis.line.set_color("white")
                self.ax.w_zaxis.line.set_color("white")

                tmplf.update_figure_texture(
                    update_full=True,  # tight_layout=True
                )
                # base.acceptOnce("c", add_plot_thread_wrapped)

                # time.sleep(0.2)
                # Wait(0.001)
                add_plot_thread_wrapped()

                return task.done

            taskMgr.add(wait_for_thread_to_finish_task, 'foo')

        add_plot_thread_wrapped()
Exemplo n.º 11
0
    def __init__(self, description, is_alive_func):
        """ when launching a thread, this logger can be called with
        Args:
            description: a description of the task that the thread is doing
            is_alive_func: if return value turns from True to False,
                           kill the log """
        self.description = description
        self.is_alive_func = is_alive_func

        TQGraphicsNodePath.__init__(self)

        self.processing_box = ProcessingBox(lambda: not is_alive_func(), description)
        self.processing_box.reparentTo(self)
Exemplo n.º 12
0
    def __init__(self, func, param_interv=np.array([0, 1]),
                 thickness=1., color=Vec4(1., 1., 1., 1.), howmany_points=50, **kwargs):
        """ """
        TQGraphicsNodePath.__init__(self, **kwargs)

        self.thickness = thickness
        self.color = color
        self.howmany_points = howmany_points
        self.func = func
        self.param_interv = param_interv
        self.func = func
        self.thickness = thickness
        self.makeObject(func, param_interv, thickness, color, howmany_points)
Exemplo n.º 13
0
    def __init__(self, pdf_page, pdf_renderer, *args, **kwargs):
        """
        pdf_page : number starting from 0
        pdf_renderer : instance of PopplerPDFRenderer
        """

        TQGraphicsNodePath.__init__(self, **kwargs)

        self.pdf_page = pdf_page
        self.pdf_renderer = pdf_renderer

        self.makeObject()

        self.doInitialSetupTransformation()
Exemplo n.º 14
0
 def __init__(self,
              func,
              param_interv=np.array([0,
                                     1]),
              thickness=1.,
              color=Vec4(1., 1., 1., 1.),
              howmany_points=50, **kwargs):
     TQGraphicsNodePath.__init__(self, **kwargs)
     self.makeObject(
         func,
         param_interv,
         thickness,
         color,
         howmany_points,
     )
Exemplo n.º 15
0
    def __init__(self, get_lps_rate_func, get_duration_func):
        """ """
        TQGraphicsNodePath.__init__(self)

        self.v1 = None
        self.v_dir = None

        self.line = None
        self.primary_color = None
        self.cursor_sequence = None
        self.extraArgs = []

        self.get_lps_rate_func = get_lps_rate_func
        self.get_duration_func = get_duration_func

        self.v2_override = None

        pass
Exemplo n.º 16
0
    def __init__(self, done_function, position, size=0.2, frequency=1):
        """
        Args:
            done_function: function which controls when the waiting symbol
                           animation should be stopped (when True)
            position: Vec3 of the upper left hand corner in p3d coordinates """

        # -- logical
        self.done_function = done_function

        self.position = position
        self.size = size
        self.frequency = frequency
        self.duration = 1.

        self.a = None

        TQGraphicsNodePath.__init__(self)

        # -- supporting graphics
        self.quad = Quad(thickness=3.0,
                         TQGraphicsNodePath_creation_parent_node=engine.
                         tq_graphics_basics.tq_aspect2d)
        self.quad.reparentTo(self)

        self.quad.set_pos_vec3(self.position)
        self.quad.set_height(self.size)
        self.quad.set_width(self.size)

        self.line = Line1dSolid(thickness=3.0,
                                TQGraphicsNodePath_creation_parent_node=engine.
                                tq_graphics_basics.tq_aspect2d)
        self.line.reparentTo(self)

        self.anim_seq = Sequence()

        self.anim_seq.set_sequence_params(
            duration=self.duration,
            extraArgs=[],
            update_function=self.update,
            on_finish_function=self.restart_animation)

        self.anim_seq.start()
Exemplo n.º 17
0
    def __init__(self,
                 camera_gear,
                 update_labels_orientation=False,
                 attach_to_space="render"):
        """
        Args:
            arr: numbers at which to create the tick lines """
        TQGraphicsNodePath.__init__(self)
        self.camera_gear = camera_gear

        self.attach_to_space = attach_to_space

        self.update_labels_orientation = update_labels_orientation

        # self.lines = []
        self.ticks = []
        self.tick_length = 0.05

        self.num_arrs = [[0.0, 1.0], [0.0, 1.0]]
Exemplo n.º 18
0
    def __init__(self,
                 pos_vec3=Vec3(0., 0., 0.),
                 width=1.0,
                 height=1.0,
                 **kwargs):
        """
        Args:
            pos_vec3: upper left corner in p3d coordinates in aspect2d
                      (+x is right, +z is up, y has to be 0.)
            **kwargs:
                TQGraphicsNodePath_creation_parent_node: aspect2d or render
                thickness: thickness of the lines in the quad
        """

        self.pos_vec3 = None
        self.width = None
        self.height = None

        TQGraphicsNodePath.__init__(self)

        self.set_pos_vec3(pos_vec3)

        self.border_line_top = Line1dSolid(**kwargs)
        self.border_line_top.reparentTo(self)

        self.border_line_bottom = Line1dSolid(**kwargs)
        self.border_line_bottom.reparentTo(self)

        self.border_line_left = Line1dSolid(**kwargs)
        self.border_line_left.reparentTo(self)

        self.border_line_right = Line1dSolid(**kwargs)
        self.border_line_right.reparentTo(self)

        self.b2d = Box2d()  # background box
        self.b2d.reparentTo(self)
        self.b2d.setColor(Quad.bg_color, 1)

        self.set_border_color(Quad.border_color, 1)

        self.set_width(width)
        self.set_height(height)
Exemplo n.º 19
0
    def __init__(self,
                 mpl_figure,
                 scaling=1.0,
                 backgroud_opacity=0.2,
                 **kwargs):
        """ get a textured quad from a 2d array of pixel data """
        # self.np_2d_arr = np_2d_arr
        self.myTexture = None
        self.num_of_pixels_x = None
        self.num_of_pixels_y = None
        self.scaling = scaling
        self.backgroud_opacity = backgroud_opacity

        self.mpl_figure = mpl_figure

        TQGraphicsNodePath.__init__(self, **kwargs)

        self.makeObject()

        self.doInitialSetupTransformation()
Exemplo n.º 20
0
    def __init__(self,
                 direction_vector,
                 axis_length=1.,
                 ticksperunitlength=4,
                 thickness1dline=2.,
                 color=Vec4(1., 0., 0., 1.)):
        TQGraphicsNodePath.__init__(self)

        # logical properties
        self.axis_length = axis_length
        self.direction_vector = direction_vector.normalized()
        self.ticksperunitlength = ticksperunitlength

        # building blocks
        self.axis_vector = None
        self.ticks = None

        self.thickness1dline = thickness1dline
        self.color = color

        self._build_vector()
Exemplo n.º 21
0
    def __init__(self, camera, axes=None, dimension=3):
        """
        Parameters:
        camera -- e.g. an Orbiter object, to attach 2d labels properly to the
                  3d geometry
        """
        TQGraphicsNodePath.__init__(self)

        self.scatters = []
        self.dimension = dimension
        self.axes = []
        self.camera = camera

        for direction_vec, color_vec in zip(
                CoordinateSystem.cartesian_axes_directions[:dimension],
                CoordinateSystem.cartesian_axes_colors[:dimension]):
            ax = Axis(direction_vec, thickness1dline=5, color=color_vec)
            self.axes.append(ax)
            ax.reparentTo(self)

        self.attach_axes_labels()
Exemplo n.º 22
0
    def __init__(self, is_done_function, description):
        self.description = description

        self.x_pos_left_border = None
        self.y_pos_top_box = None

        self.is_done_function = is_done_function

        self.time_initial = time.time_ns()

        self.task_obj_update = None

        self.waiting_symbol = None

        self.text = None

        self.elapsed_time_text = None

        self.quad = None

        self.task_obj_update = None

        self.task_obj_update = taskMgr.add(self.update_task, 'update_task')

        self.height = None

        self.width = None

        if self.height is None:
            self.height = 0.2

        if self.width is None:
            self.width = 0.9

        TQGraphicsNodePath.__init__(self)

        pass
Exemplo n.º 23
0
    def __init__(
            self,
            camera_gear=None,
            update_labels_orientation=False,
            with_ticks=True,
            attach_to_space="aspect2d",  # or "render",
            attach_directly=True):
        """ """
        TQGraphicsNodePath.__init__(self)

        self.attached_p = False

        if attach_to_space == "aspect2d":
            if update_labels_orientation == True:
                print(
                    "WARNING: do not set attach_to_space to aspect2d and update_labels_orientation=True simultaneously!"
                )
                update_labels_orientation = False

        if attach_to_space == "render":
            if camera_gear is None:
                print(
                    "ERR: if attach_to_space == render, supply a camera_gear as well that is not None!"
                )
                exit(1)

        self.attach_to_space = attach_to_space  # "render" or "aspect2d"

        self.quad = None

        # if camera_gear == None:
        #     self.update_labels_orientation == False

        # if update_labels_orientation == True and camera_gear == None:
        #     print("WARNING: if update_labels_orientation == True, camera_gear cannot be None")
        #      exit(1)

        self.camera_gear = camera_gear

        self.update_labels_orientation = update_labels_orientation

        size = 0.5
        self.height = size
        self.width = size * 1.618

        # self.lines = []  # lines

        # self.linesin2dframe = None
        self.linesin2dframe = LinesIn2dFrame()
        self.linesin2dframe.reparentTo(self)

        self.with_ticks = with_ticks

        self.d = 2  # dimension of frame

        self.xmin_hard = None
        self.xmax_hard = None

        self.ymin_hard = None
        self.ymax_hard = None

        self._xmin_soft = 0.
        self._xmax_soft = 1.

        self._ymin_soft = 0.
        self._ymax_soft = 1.

        self.axes_ticks_numbers = None
        self.regenerate_axes_ticks_numbers()

        self.clipping_planes_p3d_nodepaths = []

        self.quad = Quad(thickness=1.5)
        self.quad.reparentTo(self)

        # --- Ticks -----
        print("with_ticks: ", self.with_ticks)
        if self.with_ticks == True:
            self.axes_ticks = []

            for i, n_vec in zip(range(self.d), Frame2d.axis_direction_vectors):
                ticks = Ticks(
                    camera_gear,
                    update_labels_orientation=self.update_labels_orientation,
                    attach_to_space="aspect2d")
                self.axes_ticks.append(ticks)
                ticks.reparentTo(self)
                ticks.setMat_normal(
                    math_utils.getMat4by4_to_rotate_xhat_to_vector(n_vec))
                # h, p, r = ticks.getHpr()
                # ticks.setHpr(h, p , r - i * 90.)

            self.regenerate_ticks()

        self.update_alignment()

        if attach_directly == True and self.attached_p == False:
            # print("Attaching directly")
            if attach_to_space == "aspect2d":
                self.attach_to_aspect2d()
            elif attach_to_space == "render":
                self.attach_to_render()
            else:
                exit(1)
Exemplo n.º 24
0
 def __init__(self, *args, **kwargs):
     TQGraphicsNodePath.__init__(self, *args, **kwargs)
     self.stroke_segments = []
     self.last_added_point = None  # np array
Exemplo n.º 25
0
    def __init__(self):
        """ """
        TQGraphicsNodePath.__init__(self)

        self.lines = []
Exemplo n.º 26
0
    def __init__(self):
        """ """
        TQGraphicsNodePath.__init__(self)

        self.line = None
        self.label = None
Exemplo n.º 27
0
 def __init__(self, *args, **kwargs):
     TQGraphicsNodePath.__init__(self, *args, **kwargs)
Exemplo n.º 28
0
    def __init__(self, symbol_geometries, **kwargs):
        TQGraphicsNodePath.__init__(self, **kwargs)

        self.makeObject(symbol_geometries)
Exemplo n.º 29
0
    def __init__(self, point_cloud, **kwargs):
        TQGraphicsNodePath.__init__(self, **kwargs)

        self.makeObject(point_cloud)
Exemplo n.º 30
0
    def __init__(self,
                 tail_point_logical=None,
                 tip_point_logical=None,
                 arrowhead_scale=1. / 15.,
                 **kwargs):
        TQGraphicsNodePath.__init__(self, **kwargs)

        if 'linetype' in kwargs:
            self.linetype = kwargs.get('linetype')
        else:
            self.linetype = "1d"

        if 'color' in kwargs:
            self.color = kwargs.get('color')
        else:
            self.color = Vec4(1., 0., 0., 1.)

        if self.linetype == "1d":
            if 'thickness1dline' in kwargs:
                self.thickness1dline = kwargs.get('thickness1dline')
            else:
                self.thickness1dline = 2.

            if 'linestyle' in kwargs:
                self.linestyle = kwargs.get('linestyle')
            else:
                self.linestyle = "-"

            if self.linestyle == "--":
                howmany_periods = 5.
                if 'howmany_periods' in kwargs:
                    howmany_periods = kwargs.get('howmany_periods')

                self.line1 = Line1dDashed(thickness=self.thickness1dline,
                                          color=self.color,
                                          howmany_periods=howmany_periods)
            else:
                self.line1 = Line1dSolid(thickness=self.thickness1dline,
                                         color=self.color)
        elif self.linetype == "2d":
            self.line1 = Line2dObject()
        else:
            print("Error: linetype " + self.linetype + " is invalid")

        if 'arrowheadstyle' in kwargs:
            self.arrowheadstyle = kwargs.get('arrowheadstyle')
            if self.arrowheadstyle == "ArrowHeadCone":
                self.arrowhead = ArrowHeadCone()
            elif self.arrowheadstyle == "ArrowHeadConeShaded":
                self.arrowhead = ArrowHeadConeShaded(color=self.color)
            elif self.arrowheadstyle == "ArrowHead":
                self.arrowhead = ArrowHead()
        else:
            self.arrowhead = ArrowHeadConeShaded(color=self.color,
                                                 scale=arrowhead_scale)

        self.line1.reparentTo(self)
        self.arrowhead.reparentTo(self)

        self.tip_point_logical = tip_point_logical
        self.tail_point_logical = tail_point_logical

        if self.tip_point_logical is None or self.tail_point_logical is None:
            self.tip_point_logical = Vec3(0., 0., 0.)
            self.tail_point_logical = Vec3(0., 0., 0.)

        self.setTipPoint(self.tip_point_logical)
        self.setTailPoint(self.tail_point_logical)

        self.setColor(self.color)

        self.label = None  # usually it is not labelled