예제 #1
0
def viewer(scene=None, background=(1.0, 1.0, 1.0)):
    """viewer(scene=None,background=(1.0,1.0,1.0)): starts a standalone coin viewer with the contents of the given scene"""

    # Initialize Coin. This returns a main window to use
    from pivy import sogui
    win = sogui.SoGui.init()
    if win == None:
        print("Unable to create a SoGui window")
        return

    win.setBackgroundColor(
        coin.SbColor(background[0], background[1], background[2]))

    if not scene:
        # build a quick default scene
        mat = coin.SoMaterial()
        mat.diffuseColor = (1.0, 0.0, 0.0)
        # Make a scene containing a red cone
        scene = coin.SoSeparator()
        scene.addChild(mat)
        scene.addChild(coin.SoCone())

    # ref the scene so it doesn't get garbage-collected
    scene.ref()

    # Create a viewer in which to see our scene graph
    viewer = sogui.SoGuiExaminerViewer(win)

    # Put our scene into viewer, change the title
    viewer.setSceneGraph(scene)
    viewer.setTitle("Coin viewer")
    viewer.show()

    sogui.SoGui.show(win)  # Display main window
    sogui.SoGui.mainLoop()  # Main Coin event loop
예제 #2
0
    def Activated(self):
        from pivy import sogui
        from pivy import coin

        global myRenderArea
        if myRenderArea == None:
            root = coin.SoSeparator()
            myCamera = coin.SoPerspectiveCamera()
            myMaterial = coin.SoMaterial()
            root.addChild(myCamera)
            root.addChild(coin.SoDirectionalLight())
            #myMaterial.diffuseColor = (1.0, 0.0, 0.0)   # Red
            root.addChild(myMaterial)
            root.addChild(coin.SoCone())

            # Create a renderArea in which to see our scene graph.
            # The render area will appear within the main window.
            myRenderArea = sogui.SoGuiRenderArea(FreeCADGui.getMainWindow())

            # Make myCamera see everything.
            myCamera.viewAll(root, myRenderArea.getViewportRegion())

            # Put our scene in myRenderArea, change the title
            myRenderArea.setSceneGraph(root)
            myRenderArea.setTitle("Hello Cone")
        myRenderArea.show()
예제 #3
0
 def __init__(self,
              pl=None,
              scale=[100, 100, 20],
              offset=100,
              name='ARROW'):
     # define main properties
     self.view = FreeCADGui.ActiveDocument.ActiveView
     self.sg = self.view.getSceneGraph()
     self.cb = self.view.addEventCallbackPivy(
         coin.SoMouseButtonEvent.getClassTypeId(), self.pickCB)
     # define OpenInventor properties
     self.node = coin.SoSeparator()  #self.node=coin.SoSelection()
     self.name = name
     self.node.setName(self.name)
     self.color = coin.SoBaseColor()
     self.color.rgb = 0, 0.8, 0
     self.transform = coin.SoTransform()
     self.transform.scaleFactor.setValue(scale)
     self.cone = coin.SoCone()
     # create children of node
     self.node.addChild(self.color)
     self.node.addChild(self.transform)
     self.node.addChild(self.cone)
     # draw the arrow and move it to its Placement with the specified offset
     self.sg.addChild(self.node)
     self.offset = offset
     if not pl:
         pl = FreeCAD.Placement()
     self.moveto(pl)
    def __init__(self, view, coneHeight=5):
        self.view = view
        self.tsze = coneHeight

        self.cam = coin.SoOrthographicCamera()
        self.cam.aspectRatio = 1
        self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

        self.pos = coin.SoTranslation()

        self.mat = coin.SoMaterial()
        self.mat.diffuseColor = coin.SbColor(0.9, 0.0, 0.9)
        self.mat.transparency = 0

        self.fnt = coin.SoFont()

        self.txt = coin.SoText2()
        self.txt.string = 'setValues'
        self.txt.justification = coin.SoText2.LEFT

        self.sep = coin.SoSeparator()

        self.sep.addChild(self.cam)
        self.sep.addChild(self.pos)
        self.sep.addChild(self.mat)
        self.sep.addChild(self.fnt)
        self.sep.addChild(self.txt)

        self.tTrf = coin.SoTransform()
        self.tTrf.translation.setValue((0, -self.tsze / 2, 0))
        self.tTrf.center.setValue((0, self.tsze / 2, 0))
        self.tTrf.rotation.setValue(coin.SbVec3f((1, 0, 0)), -math.pi / 2)

        self.tPos = coin.SoTranslation()

        self.tMat = coin.SoMaterial()
        self.tMat.diffuseColor = coin.SbColor(0.4, 0.4, 0.4)
        self.tMat.transparency = 0.8

        self.tool = coin.SoCone()
        self.tool.height.setValue(self.tsze)
        self.tool.bottomRadius.setValue(self.tsze / 4)

        self.tSep = coin.SoSeparator()
        self.tSep.addChild(self.tPos)
        self.tSep.addChild(self.tTrf)
        self.tSep.addChild(self.tMat)
        self.tSep.addChild(self.tool)

        self.viewer = self.view.getViewer()
        self.render = self.viewer.getSoRenderManager()
        self.sup = None

        self.updatePreferences()
        self.setPosition(0, 0, 0, 0, 0, 0, False, False)
예제 #5
0
def main():
    app = QApplication(sys.argv)
    viewer = quarter.QuarterWidget()

    root = coin.SoSeparator()
    root += coin.SoCone()
    root += test()

    viewer.setSceneGraph(root)
    viewer.setBackgroundColor(QColor(255, 255, 255))
    viewer.setWindowTitle("minimal")
    viewer.show()
    sys.exit(app.exec_())
예제 #6
0
 def __init__(self, points, dynamic=False, arrow_size=0.04, length=2):
     super(Arrow, self).__init__(points, dynamic)
     self.arrow_sep = coin.SoSeparator()
     self.arrow_rot = coin.SoRotation()
     self.arrow_scale = coin.SoScale()
     self.arrow_translate = coin.SoTranslation()
     self.arrow_scale.scaleFactor.setValue(arrow_size, arrow_size, arrow_size)
     self.cone = coin.SoCone()
     arrow_length = coin.SoScale()
     arrow_length.scaleFactor = (1, length, 1)
     arrow_origin = coin.SoTranslation()
     arrow_origin.translation = (0, -1, 0)
     self.arrow_sep += [self.arrow_translate, self.arrow_rot, self.arrow_scale]
     self.arrow_sep += [arrow_length, arrow_origin, self.cone]
     self += [self.arrow_sep]
     self.set_arrow_direction()
예제 #7
0
def viewer(scene=None,background=(1.0,1.0,1.0),lightdir=None):

    """viewer(scene=None,background=(1.0,1.0,1.0),lightdir=None): starts
    a standalone coin viewer with the contents of the given scene. You can
    give a background color, and optionally a light direction as a (x,y,z)
    tuple. In this case, a directional light will be added and shadows will
    be turned on. This might not work with some 3D drivers."""

    # Initialize Coin. This returns a main window to use
    from pivy import coin
    from pivy import sogui

    win = sogui.SoGui.init()
    if win is None:
        print("Unable to create a SoGui window")
        return

    win.setBackgroundColor(coin.SbColor(background[0],background[1],background[2]))

    if not scene:
        # build a quick default scene
        mat = coin.SoMaterial()
        mat.diffuseColor = (1.0, 0.0, 0.0)
        # Make a scene containing a red cone
        scene = coin.SoSeparator()
        scene.addChild(mat)
        scene.addChild(coin.SoCone())

    if lightdir:
        scene = embedLight(scene,lightdir)

    # ref the scene so it doesn't get garbage-collected
    scene.ref()

    # Create a viewer in which to see our scene graph
    viewer = sogui.SoGuiExaminerViewer(win)

    # Put our scene into viewer, change the title
    viewer.setSceneGraph(scene)
    viewer.setTitle("Coin viewer")
    viewer.show()

    sogui.SoGui.show(win) # Display main window
    sogui.SoGui.mainLoop()     # Main Coin event loop
예제 #8
0
 def setToolShape(self, shape):
     '''Takes the actual shape of the tool and copies it into the 3d view.
     Should the tool in question be a legacy tool without a shape the tool
     is stylized by the traditional inverted cone.'''
     if self.tool:
         self.sep.removeChild(self.tool)
     if shape and MachinekitPreferences.hudToolShowShape():
         buf = shape.writeInventor()
         cin = coin.SoInput()
         cin.setBuffer(buf)
         self.tool = coin.SoDB.readAll(cin)
         # the shape is correct, but we need to adjust the offset
         self.trf.translation.setValue((0, 0, -shape.BoundBox.ZMin))
         self.trf.center.setValue((0, 0, 0))
         self.trf.rotation.setValue(coin.SbVec3f((0, 0, 0)), 0)
     else:
         self.tool = coin.SoCone()
         self.tool.height.setValue(self.tsze)
         self.tool.bottomRadius.setValue(self.tsze / 4)
         # we need to flip and translate the cone so it sits on it's top
         self.trf.translation.setValue((0, -self.tsze / 2, 0))
         self.trf.center.setValue((0, self.tsze / 2, 0))
         self.trf.rotation.setValue(coin.SbVec3f((1, 0, 0)), -math.pi / 2)
     self.sep.addChild(self.tool)
예제 #9
0
        hints.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE
        hints.shapeType = coin.SoShapeHints.SOLID
        hints.faceType = coin.SoShapeHints.CONVEX
        self.root.addChild(self.rotor)
        self.root.addChild(hints)

    def getSRoot(self):
        return self.viewer.getSoRenderManager().getSceneGraph()

    def toText(self, root):
        wa = coin.SoWriteAction()
        return wa.apply(root)

    def setStereoAdjustment(self, val):
        self.camera.setStereoAdjustment(val)


if __name__ == "__main__":
    import sys

    app = QtGui.QApplication(sys.argv)
    visor = MinimalViewer()
    ## ============================
    visor.root.addChild(coin.SoCone())
    ## ============================
    visor.resize(400, 400)
    visor.show()
    visor.viewAll()

    sys.exit(app.exec_())
예제 #10
0
def dim_symbol(symbol=None, invert=False):
    """Return the specified dimension symbol.

    Parameters
    ----------
    symbol: int, optional
        It defaults to `None`, in which it gets the value from the parameter
        database, `get_param("dimsymbol", 0)`.

        A numerical value defines different markers
         * 0, `SoSphere`
         * 1, `SoMarkerSet` with a circle
         * 2, `SoSeparator` with a `soCone`
         * 3, `SoSeparator` with a `SoFaceSet`
         * 4, `SoSeparator` with a `SoLineSet`, calling `dim_dash`
         * Otherwise, `SoSphere`

    invert: bool, optional
        It defaults to `False`.
        If it is `True` and `symbol=2`, the cone will be rotated
        -90 degrees around the Z axis, otherwise the rotation is positive,
        +90 degrees.

    Returns
    -------
    Coin.SoNode
        A `Coin.SoSphere`, or `Coin.SoMarkerSet` (circle),
        or `Coin.SoSeparator` (cone, face, line)
        that will be used as a dimension symbol.
    """
    if symbol is None:
        symbol = utils.get_param("dimsymbol", 0)

    if symbol == 0:
        # marker = coin.SoMarkerSet()
        # marker.markerIndex = 80

        # Returning a sphere means that the bounding box will
        # be 3-dimensional; a marker will always be planar seen from any
        # orientation but it currently doesn't work correctly
        marker = coin.SoSphere()
        return marker
    elif symbol == 1:
        marker = coin.SoMarkerSet()
        # Should be the same as
        # marker.markerIndex = 10
        marker.markerIndex = Gui.getMarkerIndex("circle", 9)
        return marker
    elif symbol == 2:
        marker = coin.SoSeparator()
        t = coin.SoTransform()
        t.translation.setValue((0, -2, 0))
        t.center.setValue((0, 2, 0))
        if invert:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), -math.pi/2)
        else:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), math.pi/2)
        c = coin.SoCone()
        c.height.setValue(4)
        marker.addChild(t)
        marker.addChild(c)
        return marker
    elif symbol == 3:
        marker = coin.SoSeparator()
        c = coin.SoCoordinate3()
        c.point.setValues([(-1, -2, 0), (0, 2, 0),
                           (1, 2, 0), (0, -2, 0)])
        f = coin.SoFaceSet()
        marker.addChild(c)
        marker.addChild(f)
        return marker
    elif symbol == 4:
        return dimDash((-1.5, -1.5, 0), (1.5, 1.5, 0))
    else:
        _wrn(_tr("Symbol not implemented. Use a default symbol."))
        return coin.SoSphere()
예제 #11
0
from __future__ import print_function
import sys
from pivy import coin
from pivy.gui import soqt
# import shiboken if you want to use the widget within qt

# Initialize Coin (returns main window to use)
# If unsuccessful, exit.
myWindow = soqt.SoQt.init(sys.argv[0])
print(myWindow)
# Make a scene containing a red cone.
myMaterial = coin.SoMaterial()
myMaterial.diffuseColor = (1.0, 0.0, 0.0)
scene = coin.SoSeparator()
scene.ref()
scene.addChild(myMaterial)
scene.addChild(coin.SoCone())
# Create a viewer to visualize our scene.
viewer = soqt.SoQtExaminerViewer(myWindow)
# Put our scene into viewer, change the title.
viewer.setSceneGraph(scene)
viewer.setTitle("Examiner Viewer")
viewer.show()
soqt.SoQt.show(myWindow)
soqt.SoQt.mainLoop()
    def attach(self, vobj):
        r"""Setup the scene sub-graph of the view provider,
        this method is mandatory
        
        See Also
        --------
        https://www.freecadweb.org/wiki/Scripted_objects

        """
        debug("AnchorViewProvider/attach")

        self.shaded = coin.SoSeparator()
        self.wireframe = coin.SoSeparator()

        # group u cone and cylinder
        self.group_u = coin.SoSeparator()
        self.color_u = coin.SoBaseColor()

        self.group_cyl_u = coin.SoSeparator()
        self.transform_cyl_u = coin.SoTransform()

        self.group_cone_u = coin.SoSeparator()
        self.transform_cone_u = coin.SoTransform()

        # group v cone and cylinder
        self.group_v = coin.SoSeparator()
        self.transform_v = coin.SoTransform()
        self.color_v = coin.SoBaseColor()

        self.group_cyl_v = coin.SoSeparator()
        self.transform_cyl_v = coin.SoTransform()

        self.group_cone_v = coin.SoSeparator()
        self.transform_cone_v = coin.SoTransform()

        # global
        self.scale = coin.SoScale()
        self.scale.scaleFactor.setValue(1., 1., 1.)
        self.transform = coin.SoTransform()

        # arrow dimensions
        self.arrow_length = 1
        cone_cyl_ratio = 0.2
        cyl_radius_ratio = 0.05
        cone_base_radius_ratio = 0.1

        # The cylinder is created from its middle at the origin
        # -> compensation
        self.transform_cyl_u.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) / 2, 0.))
        self.transform_cone_u.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) +
             self.arrow_length * cone_cyl_ratio / 2, 0.))

        self.transform_cyl_v.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) / 2, 0.))
        self.transform_cone_v.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) +
             self.arrow_length * cone_cyl_ratio / 2, 0.))

        # put v at 90 degrees
        self.transform_v.center.setValue((0, 0, 0))
        self.transform_v.rotation.setValue(coin.SbVec3f((1, 0, 0)),
                                           math.pi / 2)

        # Cone and cylinder creation from dimensions
        cone_u = coin.SoCone()
        cone_u.height.setValue(self.arrow_length * cone_cyl_ratio)
        cone_u.bottomRadius.setValue(self.arrow_length *
                                     cone_base_radius_ratio)

        cylinder_u = coin.SoCylinder()
        cylinder_u.radius.setValue(self.arrow_length * cyl_radius_ratio)
        cylinder_u.height.setValue(self.arrow_length * (1 - cone_cyl_ratio))

        cone_v = coin.SoCone()
        cone_v.height.setValue(self.arrow_length * cone_cyl_ratio)
        cone_v.bottomRadius.setValue(self.arrow_length *
                                     cone_base_radius_ratio)

        cylinder_v = coin.SoCylinder()
        cylinder_v.radius.setValue(self.arrow_length * cyl_radius_ratio)
        cylinder_v.height.setValue(self.arrow_length * (1 - cone_cyl_ratio))

        # group_cyl_u
        self.group_cyl_u.addChild(self.transform_cyl_u)
        self.group_cyl_u.addChild(cylinder_u)

        # group_cone_u
        self.group_cone_u.addChild(self.transform_cone_u)
        self.group_cone_u.addChild(cone_u)

        # group_u
        self.group_u.addChild(self.color_u)
        self.group_u.addChild(self.group_cyl_u)
        self.group_u.addChild(self.group_cone_u)

        # group_cyl_v
        self.group_cyl_v.addChild(self.transform_cyl_v)
        self.group_cyl_v.addChild(cylinder_v)

        # group_cone_v
        self.group_cone_v.addChild(self.transform_cone_v)
        self.group_cone_v.addChild(cone_v)

        # group_v
        self.group_v.addChild(self.transform_v)
        self.group_v.addChild(self.color_v)
        self.group_v.addChild(self.group_cyl_v)
        self.group_v.addChild(self.group_cone_v)

        # ** shaded **
        self.shaded.addChild(self.transform)
        self.shaded.addChild(self.scale)
        self.shaded.addChild(self.group_u)
        self.shaded.addChild(self.group_v)
        vobj.addDisplayMode(self.shaded, "Shaded")

        # ** wireframe **
        style = coin.SoDrawStyle()
        style.style = coin.SoDrawStyle.LINES
        self.wireframe.addChild(style)
        self.wireframe.addChild(self.transform)
        self.wireframe.addChild(self.scale)
        self.wireframe.addChild(self.group_u)
        self.wireframe.addChild(self.group_v)
        vobj.addDisplayMode(self.wireframe, "Wireframe")

        self.onChanged(vobj, "ColorU")
        self.onChanged(vobj, "ColorV")
예제 #13
0
def dim_symbol(symbol=None, invert=False):
    """Return the specified dimension symbol.

    Parameters
    ----------
    symbol: int, optional
        It defaults to `None`, in which it gets the value from the parameter
        database, `get_param("dimsymbol", 0)`.

        A numerical value defines different markers
         * 0, `SoSphere`
         * 1, `SoSeparator` with a `SoLineSet`, a circle (in fact a 24 sided polygon)
         * 2, `SoSeparator` with a `soCone`
         * 3, `SoSeparator` with a `SoFaceSet`
         * 4, `SoSeparator` with a `SoLineSet`, calling `dim_dash`
         * Otherwise, `SoSphere`

    invert: bool, optional
        It defaults to `False`.
        If it is `True` and `symbol=2`, the cone will be rotated
        -90 degrees around the Z axis, otherwise the rotation is positive,
        +90 degrees.

    Returns
    -------
    Coin.SoNode
        A `Coin.SoSphere`, or `Coin.SoSeparator` (circle, cone, face, line)
        that will be used as a dimension symbol.
    """
    if symbol is None:
        symbol = utils.get_param("dimsymbol", 0)

    if symbol == 0:
        # marker = coin.SoMarkerSet()
        # marker.markerIndex = 80

        # Returning a sphere means that the bounding box will
        # be 3-dimensional; a marker will always be planar seen from any
        # orientation but it currently doesn't work correctly
        marker = coin.SoSphere()
        return marker
    elif symbol == 1:
        marker = coin.SoSeparator()
        v = coin.SoVertexProperty()
        for i in range(25):
            ang = math.radians(i * 15)
            v.vertex.set1Value(i, (math.sin(ang), math.cos(ang), 0))
        p = coin.SoLineSet()
        p.vertexProperty = v
        marker.addChild(p)
        return marker
    elif symbol == 2:
        marker = coin.SoSeparator()
        t = coin.SoTransform()
        t.translation.setValue((0, -2, 0))
        t.center.setValue((0, 2, 0))
        if invert:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), -math.pi / 2)
        else:
            t.rotation.setValue(coin.SbVec3f((0, 0, 1)), math.pi / 2)
        c = coin.SoCone()
        c.height.setValue(4)
        marker.addChild(t)
        marker.addChild(c)
        return marker
    elif symbol == 3:
        marker = coin.SoSeparator()
        # hints are required otherwise only the bottom of the face is colored
        h = coin.SoShapeHints()
        h.vertexOrdering = h.COUNTERCLOCKWISE
        c = coin.SoCoordinate3()
        c.point.setValues([(-1, -2, 0), (0, 2, 0), (1, 2, 0), (0, -2, 0)])
        f = coin.SoFaceSet()
        marker.addChild(h)
        marker.addChild(c)
        marker.addChild(f)
        return marker
    elif symbol == 4:
        return dim_dash((-1.5, -1.5, 0), (1.5, 1.5, 0))
    else:
        _wrn(
            translate("draft",
                      "Symbol not implemented. Using a default symbol."))
        return coin.SoSphere()
예제 #14
0
    def makeFrame(self, frame_labels):
        """
Method which makes a Coin3D frame to show a current pose in a RobRotation.

A frame is made from 3 red, green and blue arrows representing X, Y and Z.
Arrows are each constructed from a shaft and an arrowhead. Their dimensions
and other attributes are unassigned as they are extracted from appropriate
`RobRotation` properties.

Returns:
    A SoSeparator with the frame shown in the FreeCAD View.
        """
        # make a generic shaft from 0 in Y direction
        shaft_vertices = coin.SoVertexProperty()
        shaft_vertices.vertex.setNum(2)
        shaft_vertices.vertex.set1Value(0, 0, 0, 0)
        self.frame_shaft = coin.SoLineSet()
        self.frame_shaft.vertexProperty.setValue(shaft_vertices)
        self.frame_shaft.numVertices.setNum(1)
        self.frame_shaft.numVertices.setValue(2)

        # make a generic conic arrowhead oriented in Y axis direction and
        # move it at the end of the shaft
        self.frame_arrowhead_translation = coin.SoTranslation()
        self.frame_arrowhead_cone = coin.SoCone()
        self.frame_arrowhead = coin.SoSwitch()
        self.frame_arrowhead.addChild(self.frame_arrowhead_translation)
        self.frame_arrowhead.addChild(self.frame_arrowhead_cone)

        # make rotations to rotate prepared shaft and arrowhead for Y axis
        # direction also to X and Z
        rot_y2x = coin.SoRotation()
        rot_y2x.rotation.setValue(coin.SbRotation(coin.SbVec3f(0, 1, 0),
                                                  coin.SbVec3f(1, 0, 0)))
        rot_y2z = coin.SoRotation()
        rot_y2z.rotation.setValue(coin.SbRotation(coin.SbVec3f(0, 1, 0),
                                                  coin.SbVec3f(0, 0, 1)))

        # prepare colors for X,Y,Z which will correspond to R,G,B as customary
        self.frame_color_x = coin.SoPackedColor()
        self.frame_color_y = coin.SoPackedColor()
        self.frame_color_z = coin.SoPackedColor()

        # make complete colored and rotated arrows
        x_arrow = coin.SoSeparator()
        x_arrow.addChild(rot_y2x)
        x_arrow.addChild(self.frame_color_x)
        x_arrow.addChild(self.frame_shaft)
        x_arrow.addChild(self.frame_arrowhead)
        x_arrow.addChild(frame_labels[0])
        y_arrow = coin.SoSeparator()
        y_arrow.addChild(self.frame_color_y)
        y_arrow.addChild(self.frame_shaft)
        y_arrow.addChild(self.frame_arrowhead)
        y_arrow.addChild(frame_labels[1])
        z_arrow = coin.SoSeparator()
        z_arrow.addChild(rot_y2z)
        z_arrow.addChild(self.frame_color_z)
        z_arrow.addChild(self.frame_shaft)
        z_arrow.addChild(self.frame_arrowhead)
        z_arrow.addChild(frame_labels[2])

        # prepare draw style to control shaft width
        self.frame_drawstyle = coin.SoDrawStyle()

        # make complete frame and it to shaded display mode
        separated_frame = coin.SoSeparator()
        separated_frame.addChild(self.frame_drawstyle)
        separated_frame.addChild(x_arrow)
        separated_frame.addChild(y_arrow)
        separated_frame.addChild(z_arrow)

        return separated_frame
예제 #15
0
    def makeFrame(self, frame_labels):
        # make a generic shaft from 0 in Y direction
        shaft_vertices = coin.SoVertexProperty()
        shaft_vertices.vertex.setNum(2)
        shaft_vertices.vertex.set1Value(0, 0, 0, 0)
        self.frame_shaft = coin.SoLineSet()
        self.frame_shaft.vertexProperty.setValue(shaft_vertices)
        self.frame_shaft.numVertices.setNum(1)
        self.frame_shaft.numVertices.setValue(2)

        # make a generic conic arrowhead oriented in Y axis direction and
        # move it at the end of the shaft
        self.frame_arrowhead_translation = coin.SoTranslation()
        self.frame_arrowhead_cone = coin.SoCone()
        self.frame_arrowhead = coin.SoSwitch()
        self.frame_arrowhead.addChild(self.frame_arrowhead_translation)
        self.frame_arrowhead.addChild(self.frame_arrowhead_cone)

        # make rotations to rotate prepared shaft and arrowhead for Y axis
        # direction also to X and Z
        rot_y2x = coin.SoRotation()
        rot_y2x.rotation.setValue(
            coin.SbRotation(coin.SbVec3f(0, 1, 0), coin.SbVec3f(1, 0, 0)))
        rot_y2z = coin.SoRotation()
        rot_y2z.rotation.setValue(
            coin.SbRotation(coin.SbVec3f(0, 1, 0), coin.SbVec3f(0, 0, 1)))

        # prepare colors for X,Y,Z which will correspond to R,G,B as customary
        self.frame_color_x = coin.SoPackedColor()
        self.frame_color_y = coin.SoPackedColor()
        self.frame_color_z = coin.SoPackedColor()

        # make complete colored and rotated arrows
        x_arrow = coin.SoSeparator()
        x_arrow.addChild(rot_y2x)
        x_arrow.addChild(self.frame_color_x)
        x_arrow.addChild(self.frame_shaft)
        x_arrow.addChild(self.frame_arrowhead)
        x_arrow.addChild(frame_labels[0])
        y_arrow = coin.SoSeparator()
        y_arrow.addChild(self.frame_color_y)
        y_arrow.addChild(self.frame_shaft)
        y_arrow.addChild(self.frame_arrowhead)
        y_arrow.addChild(frame_labels[1])
        z_arrow = coin.SoSeparator()
        z_arrow.addChild(rot_y2z)
        z_arrow.addChild(self.frame_color_z)
        z_arrow.addChild(self.frame_shaft)
        z_arrow.addChild(self.frame_arrowhead)
        z_arrow.addChild(frame_labels[2])

        # prepare draw style to control shaft width
        self.frame_drawstyle = coin.SoDrawStyle()

        # make complete frame and it to shaded display mode
        separated_frame = coin.SoSeparator()
        separated_frame.addChild(self.frame_drawstyle)
        separated_frame.addChild(x_arrow)
        separated_frame.addChild(y_arrow)
        separated_frame.addChild(z_arrow)

        return separated_frame
예제 #16
0
파일: minimal.py 프로젝트: jthirp/pivy_jtp
from __future__ import print_function
import sys
from pivy import coin
from pivy.gui import soqt
# import shiboken if you want to use the widget within qt

myWindow = soqt.SoQt.init(sys.argv[0])
print(myWindow)
scene = coin.SoSeparator()
cam = coin.SoPerspectiveCamera()
cam.position = (0, 0, 4)
light = coin.SoLightModel()
light.model = coin.SoLightModel.BASE_COLOR
scene += light, cam, coin.SoCone()
viewer = soqt.SoQtRenderArea(myWindow)
viewer.setSceneGraph(scene)
viewer.setTitle("Examiner Viewer")
viewer.show()
soqt.SoQt.show(myWindow)
soqt.SoQt.mainLoop()