def falsecolour(results, minval, maxval): res_colours = [] for result in results: r, g, b = pseudocolor(result, minval, maxval) colour = OCCViewer.rgb_color(r, g, b) res_colours.append(colour) return res_colours
def init_widget(self): d = self.declaration widget = self.widget #: Create viewer widget._display = OCCViewer.Viewer3d(widget.GetHandle()) display = widget._display display.Create() # background gradient self.set_background_gradient(d.background_gradient) self.set_trihedron_mode(d.trihedron_mode) self.set_display_mode(d.display_mode) self.set_selection_mode(d.selection_mode) self.set_view_mode(d.view_mode) self.set_antialiasing(d.antialiasing) self.set_double_buffer(d.double_buffer) self._update_raytracing_mode() #: Setup callbacks display.register_select_callback(self.update_selection) self.update_selection() widget._inited = True # dict mapping keys to functions widget._SetupKeyMap() # display.thisown = False
def InitDriver(self): self._display = OCCViewer.Viewer3d(self.GetWinId()) self._display.Create() self._display.SetModeShaded() self._inited = True # dict mapping keys to functions self._SetupKeyMap()
def InitDriver(self): try: os.environ["CSF_GraphicShr"] except KeyError: raise "Please set the CSF_GraphicShr environment variable." self._display = OCCViewer.Viewer2d(self.GetHandle()) self._display.Create() self._inited = True
def InitDriver(self): self._display = OCCViewer.Viewer3d(self.GetHandle()) self._display.Create() # background gradient self._display.set_bg_gradient_color(206, 215, 222, 128, 128, 128) # background gradient self._display.display_trihedron() self._display.SetModeShaded() self._display.EnableAntiAliasing() self._inited = True # dict mapping keys to functions self._SetupKeyMap()
def InitDriver(self): try: os.environ["CSF_GraphicShr"] except KeyError: raise "Please set the CSF_GraphicShr environment variable." self._display = OCCViewer.Viewer3d(self.GetHandle()) self._display.Create() self._display.display_trihedron() self._display.SetModeShaded() self._inited = True # dict mapping keys to functions self._SetupKeyMap()
def InitDriver(self): self._display = OCCViewer.Viewer3d(window_handle=self.GetHandle(), parent=self) self._display.Create() # background gradient self._display.SetModeShaded() self._inited = True # dict mapping keys to functions self._key_map = {ord('W'): self._display.SetModeWireFrame, ord('S'): self._display.SetModeShaded, ord('A'): self._display.EnableAntiAliasing, ord('B'): self._display.DisableAntiAliasing, ord('H'): self._display.SetModeHLR, ord('F'): self._display.FitAll, ord('G'): self._display.SetSelectionMode} self.createCursors()
def __init__(self, parent=None): super(qtBaseViewer, self).__init__(parent) self._display = OCCViewer.Viewer3d() self._inited = False # enable Mouse Tracking self.setMouseTracking(True) # Strong focus self.setFocusPolicy(QtCore.Qt.WheelFocus) self.setAttribute(QtCore.Qt.WA_NativeWindow) self.setAttribute(QtCore.Qt.WA_PaintOnScreen) self.setAttribute(QtCore.Qt.WA_NoSystemBackground) self.setAutoFillBackground(False)
def InitDriver(self): if sys.platform == "darwin": handle_retina(self.GetHandle()) self._display = OCCViewer.Viewer3d(self.GetHandle()) self._display.Create() # background gradient self._display.set_bg_gradient_color(206, 215, 222, 128, 128, 128) # background gradient self._display.display_trihedron() self._display.SetModeShaded() self._display.EnableAntiAliasing() self._inited = True # dict mapping keys to functions self._SetupKeyMap() # self._display.thisown = False self.createCursors()
def __init__(self, parent=None): fmt = QtOpenGL.QGLFormat() super().__init__(fmt, parent=parent) self._display = OCCViewer.Viewer3d() self._inited = False # enable Mouse Tracking self.setMouseTracking(True) # Strong focus self.setFocusPolicy(QtCore.Qt.WheelFocus) self.setAttribute(QtCore.Qt.WA_NativeWindow) self.setAttribute(QtCore.Qt.WA_PaintOnScreen) self.setAttribute(QtCore.Qt.WA_NoSystemBackground) self.setAutoFillBackground(False) color1 = Quantity_Color(.55, .55, .55, Quantity_TOC_RGB) color2 = Quantity_Color(.22, .22, .22, Quantity_TOC_RGB) self._display.View.SetBgGradientColors( color1, color2, Aspect_GFM_VER, True)
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False, fit=False): ''' ''' # if a gp_Pnt is passed, first convert to vertex if issubclass(shapes.__class__, OCCViewer.gp_Pnt): vertex = OCCViewer.BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.gp_Pnt2d): vertex = OCCViewer.BRepBuilderAPI_MakeVertex( OCCViewer.gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] SOLO = True # if a Geom_Curve is passed elif callable(getattr(shapes, "GetHandle", None)): handle = shapes.GetHandle() if issubclass(handle.__class__, OCCViewer.Handle_Geom_Curve): edge = OCCViewer.BRepBuilderAPI_MakeEdge(handle) shapes = [edge.Shape()] SOLO = True elif issubclass(handle.__class__, OCCViewer.Handle_Geom2d_Curve): edge2d = OCCViewer.BRepBuilderAPI_MakeEdge2d(handle) shapes = [edge2d.Shape()] SOLO = True elif issubclass(handle.__class__, OCCViewer.Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = OCCViewer.BRepBuilderAPI_MakeFace() face.Init(handle, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = OCCViewer.BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom_Curve): edge = OCCViewer.BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom2d_Curve): edge2d = OCCViewer.BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] SOLO = True elif issubclass(shapes.__class__, OCCViewer.TopoDS_Shape): shapes = [shapes] SOLO = True else: SOLO = False ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(OCCViewer.OCC.V3d.V3d_TEX_ALL) shape_to_display = OCCViewer.OCC.AIS.AIS_TexturedShape( shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties( ) shape_to_display.SetTextureFileName( OCCViewer.TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = OCCViewer.AIS_Shape(shape) shape_to_display.SetMaterial(material) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = OCCViewer.AIS_Shape(shape) ais_shapes.append(shape_to_display.GetHandle()) if not SOLO: # computing graphic properties is expensive # if an iterable is found, so cluster all TopoDS_Shape under # an AIS_MultipleConnectedInteractive shape_to_display = OCCViewer.AIS_MultipleConnectedInteractive() for i in ais_shapes: shape_to_display.Connect(i) # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective shape_to_display.SetMaterial(OCCViewer.Graphic3d_NOM_NEON_GNC) if color: if isinstance(color, str): color = OCCViewer.get_color_from_name(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: shape_to_display.SetTransparency(transparency) if update: # only update when explicitely told to do so self.Context.Display(shape_to_display.GetHandle(), False) # especially this call takes up a lot of time... if fit: self.FitAll() self.Repaint() else: self.Context.Display(shape_to_display.GetHandle(), False) if SOLO: return ais_shapes[0] else: return shape_to_display
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False, fit=False): ''' ''' # if a gp_Pnt is passed, first convert to vertex if issubclass(shapes.__class__, OCCViewer.gp_Pnt): vertex = OCCViewer.BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.gp_Pnt2d): vertex = OCCViewer.BRepBuilderAPI_MakeVertex(OCCViewer.gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] SOLO = True # if a Geom_Curve is passed elif callable(getattr(shapes, "GetHandle", None)): handle = shapes.GetHandle() if issubclass(handle.__class__, OCCViewer.Handle_Geom_Curve): edge = OCCViewer.BRepBuilderAPI_MakeEdge(handle) shapes = [edge.Shape()] SOLO = True elif issubclass(handle.__class__, OCCViewer.Handle_Geom2d_Curve): edge2d = OCCViewer.BRepBuilderAPI_MakeEdge2d(handle) shapes = [edge2d.Shape()] SOLO = True elif issubclass(handle.__class__, OCCViewer.Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = OCCViewer.BRepBuilderAPI_MakeFace() face.Init(handle, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = OCCViewer.BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom_Curve): edge = OCCViewer.BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] SOLO = True elif isinstance(shapes, OCCViewer.Handle_Geom2d_Curve): edge2d = OCCViewer.BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] SOLO = True elif issubclass(shapes.__class__, OCCViewer.TopoDS_Shape): shapes = [shapes] SOLO = True else: SOLO = False ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(OCCViewer.OCC.V3d.V3d_TEX_ALL) shape_to_display = OCCViewer.OCC.AIS.AIS_TexturedShape(shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties() shape_to_display.SetTextureFileName(OCCViewer.TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = OCCViewer.AIS_Shape(shape) shape_to_display.SetMaterial(material) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = OCCViewer.AIS_Shape(shape) ais_shapes.append(shape_to_display.GetHandle()) if not SOLO: # computing graphic properties is expensive # if an iterable is found, so cluster all TopoDS_Shape under # an AIS_MultipleConnectedInteractive shape_to_display = OCCViewer.AIS_MultipleConnectedInteractive() for i in ais_shapes: shape_to_display.Connect(i) # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective shape_to_display.SetMaterial(OCCViewer.Graphic3d_NOM_NEON_GNC) if color: if isinstance(color, str): color = OCCViewer.get_color_from_name(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: shape_to_display.SetTransparency(transparency) if update: # only update when explicitely told to do so self.Context.Display(shape_to_display.GetHandle(), False) # especially this call takes up a lot of time... if fit: self.FitAll() self.Repaint() else: self.Context.Display(shape_to_display.GetHandle(), False) if SOLO: return ais_shapes[0] else: return shape_to_display