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)
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()
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()
def __init__(self, tex_expression, **kwargs): TQGraphicsNodePath.__init__(self, **kwargs) self.tex_expression = tex_expression self.makeObject() self.doInitialSetupTransformation()
def __init__(self): """ """ self.log_list = [] self.task_obj_update = None self.task_obj_update = taskMgr.add(self.update, 'update') TQGraphicsNodePath.__init__(self)
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()
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()
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)
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)
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()
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)
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)
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()
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, )
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
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()
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]]
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)
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()
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()
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()
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
def _reparentTo_additional_trafo_nodepath(self): self.additional_trafo_nodepath = TQGraphicsNodePath() self.additional_trafo_nodepath.reparentTo_p3d(self.getParent_p3d()) super().reparentTo(self.additional_trafo_nodepath)
class Text(IndicatorPrimitive): def __init__(self, **kwargs): IndicatorPrimitive.__init__(self) self.pointsize = None if "pointsize" in kwargs: self.pointsize = kwargs.get("pointsize") elif self.pointsize is None: self.pointsize = 10 self.text = None if "text" in kwargs: self.text = kwargs.get("text") elif self.text is None: self.text = "Basic text" self.font = None if "font" in kwargs: self.font = kwargs.get("font") elif self.font is None: self.font = "fonts/arial.ttf" self.alignment = None if "alignment" in kwargs: self.alignment = kwargs.get("alignment") elif self.alignment is None: self.alignment = "left" def _set_text_static_graphics_1(self): self.textNode = TextNode('foo') self.textNode.setText(self.text) self._font_p3d = loader.loadFont(self.font) self.pixels_per_unit = engine.tq_graphics_basics.get_font_bmp_pixels_from_height( engine.tq_graphics_basics.get_pts_to_p3d_units(self.pointsize)) self._font_p3d.setPixelsPerUnit(self.pixels_per_unit) self._font_p3d.setPointSize(self.pointsize) self.textNode.setFont(self._font_p3d) self.textNode.setShadow(0.05, 0.05) self.textNode.setShadowColor(0, 0, 0, 1) def _set_text_static_graphics_2(self): self.set_node_p3d(self.textNode) self.set_p3d_nodepath(NodePath(self.textNode.generate())) self._font_p3d.clear() self.setLightOff(1) self.setTwoSided(True) self.set_render_above_all(True) scale = self._get_scale() self.setScale(scale, 1., scale) def _get_scale(self): # --- get_scale_matrix_initial_to_font_size initial_height = self.textNode.getHeight() scale_factor_to_height_1 = 1. / initial_height pixels_per_p3d_length_unit = engine.tq_graphics_basics.get_window_size_y( ) / 2.0 scale_height_1_to_pixels = 1. / pixels_per_p3d_length_unit return scale_height_1_to_pixels * self.pixels_per_unit def _reparentTo_additional_trafo_nodepath(self): self.additional_trafo_nodepath = TQGraphicsNodePath() self.additional_trafo_nodepath.reparentTo_p3d(self.getParent_p3d()) super().reparentTo(self.additional_trafo_nodepath) def _update_textnode_alignment(self): if self.alignment == "right": self.textNode.setAlign(TextNode.ARight) elif self.alignment == "left": self.textNode.setAlign(TextNode.ALeft) elif self.alignment == "center": self.textNode.setAlign(TextNode.ACenter) def get_size(self): height = engine.tq_graphics_basics.get_pts_to_p3d_units(self.pointsize) width = (self.textNode.getWidth() / self.textNode.getHeight()) * height return height, width
def __init__(self, *args, **kwargs): TQGraphicsNodePath.__init__(self, *args, **kwargs)
def __init__(self, symbol_geometries, **kwargs): TQGraphicsNodePath.__init__(self, **kwargs) self.makeObject(symbol_geometries)
def __init__(self): """ """ TQGraphicsNodePath.__init__(self) self.line = None self.label = None
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)
def __init__(self): """ """ TQGraphicsNodePath.__init__(self) self.lines = []
def __init__(self, point_cloud, **kwargs): TQGraphicsNodePath.__init__(self, **kwargs) self.makeObject(point_cloud)