Python vtk.vtkTransform() Examples

The following are 28 code examples of vtk.vtkTransform(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vtk , or try the search function .
Example #1
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 9 votes vote down vote up
def Roll(self, *args):
        camera = self._parent._vtkren.GetActiveCamera()
        transform = vtk.vtkTransform()
        pos = camera.GetPosition()
        fp = camera.GetFocalPoint()
        axis = [fp[i] - pos[i] for i in range(3)]
        (DisplayCenter, Center) = self.ComputeDisplayCenter()
        x1 = self._parent._iren.GetLastEventPosition()[0] - int(DisplayCenter[0])
        x2 = self._parent._iren.GetEventPosition()[0] - int(DisplayCenter[0])
        y1 = self._parent._iren.GetLastEventPosition()[1] - int(DisplayCenter[1])
        y2 = self._parent._iren.GetEventPosition()[1] - int(DisplayCenter[1])
        zCross = x1 * y2 - y1 * x2
        zCross = float(zCross)
        angle = vtk.vtkMath().DegreesFromRadians(zCross / (math.sqrt(float(x1 * x1 + y1 * y1)) *
                                                           math.sqrt(float(x2 * x2 + y2 * y2))))
        transform.Identity()
        transform.Translate(Center[0], Center[1], Center[2])
        transform.RotateWXYZ(angle, axis[0], axis[1], axis[2])
        transform.Translate(-Center[0], -Center[1], -Center[2])
        camera.ApplyTransform(transform)
        camera.OrthogonalizeViewUp()
        self._parent._vtkren.ResetCameraClippingRange()
        self._parent._iren.Render()

        # ----------------------------------------------------------------- 
Example #2
Source File: perception.py    From director with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def getDepthMapData(self, viewId):

        mapId = self.reader.GetCurrentMapId(viewId)
        if mapId < 0:
            return None, None

        depthImage = vtk.vtkImageData()
        transform = vtk.vtkTransform()
        self.reader.GetDataForMapId(viewId, mapId, depthImage, transform)

        dims = depthImage.GetDimensions()
        d = vnp.getNumpyFromVtk(depthImage, 'ImageScalars')
        d = d.reshape(dims[1], dims[0])
        t = np.array([[transform.GetMatrix().GetElement(r, c) for c in range(4)] for r in range(4)])

        return d, t 
Example #3
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def getFootFramesFromReferenceFrame(referenceFrame, stanceWidth, stanceRotation, stanceOffset):

    footHeight=0.0745342

    ref = vtk.vtkTransform()
    ref.SetMatrix(referenceFrame.GetMatrix())

    stanceFrame = vtk.vtkTransform()
    stanceFrame.PostMultiply()
    stanceFrame.RotateZ(stanceRotation)
    stanceFrame.Translate(stanceOffset)
    stanceFrame.Concatenate(ref)

    lfootFrame = vtk.vtkTransform()
    lfootFrame.PostMultiply()
    lfootFrame.Translate(0, stanceWidth/2.0, footHeight)
    lfootFrame.Concatenate(stanceFrame)

    rfootFrame = vtk.vtkTransform()
    rfootFrame.PostMultiply()
    rfootFrame.Translate(0, -stanceWidth/2.0, footHeight)
    rfootFrame.Concatenate(stanceFrame)

    return stanceFrame, lfootFrame, rfootFrame 
Example #4
Source File: visualizercontrol.py    From Det3D with Apache License 2.0 6 votes vote down vote up
def _array2vtkTransform(self, arr):
        T = vtk.vtkTransform()
        matrix = vtk.vtkMatrix4x4()
        for i in range(0, 4):
            for j in range(0, 4):
                matrix.SetElement(i, j, arr[i, j])
        T.SetMatrix(matrix)
        return T 
Example #5
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def getDrillMesh(applyBitOffset=False):

    button = np.array([0.007, -0.035, -0.06])
    drillMesh = ioUtils.readPolyData(os.path.join(app.getDRCBase(), 'software/models/otdf/dewalt_button.obj'))

    if applyBitOffset:
        t = vtk.vtkTransform()
        t.Translate(0.01, 0.0, 0.0)
        drillMesh = transformPolyData(drillMesh, t)

    d = DebugData()
    d.addPolyData(drillMesh)
    d.addSphere(button, radius=0.005, color=[0,1,0])
    d.addLine([0.0,0.0,0.155], [0.0, 0.0, 0.14], radius=0.001, color=[0,1,0])

    return shallowCopy(d.getPolyData()) 
Example #6
Source File: xyz.py    From PVGeo with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def RequestData(self, request, inInfo, outInfo):
        """Used by pipeline to generate output"""
        # Get input/output of Proxy
        pdi = self.GetInputData(inInfo, 0, 0)
        # Get number of points
        pdo = self.GetOutputData(outInfo, 0)
        #### Perfrom task ####
        filt = vtk.vtkTransformFilter()
        trans = vtk.vtkTransform()
        trans.Scale(self.get_conversion(), self.get_conversion(), self.get_conversion())
        filt.SetTransform(trans)
        filt.SetInputDataObject(pdi)
        filt.Update()
        scaled = filt.GetOutputDataObject(0)
        pdo.DeepCopy(scaled)
        return 1 
Example #7
Source File: viz.py    From 3d-semantic-segmentation with MIT License 6 votes vote down vote up
def getActorCircle(radius_inner=100, radius_outer=99, color=(1,0,0)):
    """"""
    # create source
    source = vtk.vtkDiskSource()
    source.SetInnerRadius(radius_inner)
    source.SetOuterRadius(radius_outer)
    source.SetRadialResolution(100)
    source.SetCircumferentialResolution(100)

    # Transformer
    transform = vtk.vtkTransform()
    transform.RotateWXYZ(90, 1, 0, 0)
    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetTransform(transform)
    transformFilter.SetInputConnection(source.GetOutputPort())
    transformFilter.Update()

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(transformFilter.GetOutputPort())

    # actor
    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(color)
    actor.SetMapper(mapper)

    return actor 
Example #8
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 6 votes vote down vote up
def CameraModeToObjectAllAxis(self):
        camera = self._parent._vtkren.GetActiveCamera()
        transform = vtk.vtkTransform()
        transform.Identity()
        (pt, center) = self.ComputeDisplayCenter()
        transform.Translate(center[0], center[1], center[2])
        dx = self._parent._iren.GetLastEventPosition()[0] - self._parent._iren.GetEventPosition()[0]
        dy = self._parent._iren.GetLastEventPosition()[1] - self._parent._iren.GetEventPosition()[1]
        camera.OrthogonalizeViewUp()
        viewUp = camera.GetViewUp()
        size = self._parent._vtkren.GetSize()
        transform.RotateWXYZ(360.0 * dx / size[0], viewUp[0], viewUp[1], viewUp[2])
        v2 = [0, 0, 0]
        vtk.vtkMath().Cross(camera.GetDirectionOfProjection(), viewUp, v2)
        transform.RotateWXYZ(-360.0 * dy / size[1], v2[0], v2[1], v2[2])
        transform.Translate(-center[0], -center[1], -center[2])
        camera.ApplyTransform(transform)
        camera.OrthogonalizeViewUp()
        self._parent._vtkren.ResetCameraClippingRange()
        self._parent._vtkren.GetRenderWindow().Render() 
Example #9
Source File: renderer.py    From pyvista with MIT License 6 votes vote down vote up
def set_scale(self, xscale=None, yscale=None, zscale=None, reset_camera=True):
        """Scale all the datasets in the scene.

        Scaling in performed independently on the X, Y and Z axis.
        A scale of zero is illegal and will be replaced with one.

        """
        if xscale is None:
            xscale = self.scale[0]
        if yscale is None:
            yscale = self.scale[1]
        if zscale is None:
            zscale = self.scale[2]
        self.scale = [xscale, yscale, zscale]

        # Update the camera's coordinate system
        transform = vtk.vtkTransform()
        transform.Scale(xscale, yscale, zscale)
        self.camera.SetModelTransformMatrix(transform.GetMatrix())
        self.parent.render()
        if reset_camera:
            self.update_bounds_axes()
            self.reset_camera()
        self.Modified() 
Example #10
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 6 votes vote down vote up
def Roll(self, *args):
        camera = self._parent._vtkren.GetActiveCamera()
        transform = vtk.vtkTransform()
        pos = camera.GetPosition()
        fp = camera.GetFocalPoint()
        axis = [fp[i] - pos[i] for i in range(3)]
        (DisplayCenter, Center) = self.ComputeDisplayCenter()
        x1 = self._parent._iren.GetLastEventPosition()[0] - int(DisplayCenter[0])
        x2 = self._parent._iren.GetEventPosition()[0] - int(DisplayCenter[0])
        y1 = self._parent._iren.GetLastEventPosition()[1] - int(DisplayCenter[1])
        y2 = self._parent._iren.GetEventPosition()[1] - int(DisplayCenter[1])
        zCross = x1 * y2 - y1 * x2
        zCross = float(zCross)
        angle = vtk.vtkMath().DegreesFromRadians(zCross / (math.sqrt(float(x1 * x1 + y1 * y1)) *
                                                           math.sqrt(float(x2 * x2 + y2 * y2))))
        transform.Identity()
        transform.Translate(Center[0], Center[1], Center[2])
        transform.RotateWXYZ(angle, axis[0], axis[1], axis[2])
        transform.Translate(-Center[0], -Center[1], -Center[2])
        camera.ApplyTransform(transform)
        camera.OrthogonalizeViewUp()
        self._parent._vtkren.ResetCameraClippingRange()
        self._parent._iren.Render()

        # ----------------------------------------------------------------------------- 
Example #11
Source File: wvtk.py    From pyCGNS with GNU Lesser General Public License v2.1 6 votes vote down vote up
def CameraModeToObjectAxis(self, axis):
        camera = self._parent._vtkren.GetActiveCamera()
        transform = vtk.vtkTransform()
        transform.Identity()
        (pt, center) = self.ComputeDisplayCenter()
        transform.Translate(center[0], center[1], center[2])
        dx = self._parent._iren.GetLastEventPosition()[0] - self._parent._iren.GetEventPosition()[0]
        dy = self._parent._iren.GetLastEventPosition()[1] - self._parent._iren.GetEventPosition()[1]
        camera.OrthogonalizeViewUp()
        size = self._parent._vtkren.GetSize()
        transform.RotateWXYZ(360.0 * dx / size[0], axis[0], axis[1], axis[2])
        transform.RotateWXYZ(360.0 * dy / size[1], axis[0], axis[1], axis[2])
        transform.Translate(-center[0], -center[1], -center[2])
        camera.ApplyTransform(transform)
        camera.OrthogonalizeViewUp()
        self._parent._vtkren.ResetCameraClippingRange()
        self._parent._vtkren.GetRenderWindow().Render() 
Example #12
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def addDrillAffordance():

    drillMesh = getDrillMesh()

    aff = showPolyData(drillMesh, 'drill', cls=FrameAffordanceItem, visible=True)
    t = vtk.vtkTransform()
    t.PostMultiply()
    aff.actor.SetUserTransform(t)
    showFrame(t, 'drill frame', parent=aff, visible=False).addToView(app.getDRCView())

    params = getDrillAffordanceParams(np.array(t.GetPosition()), [1,0,0], [0,1,0], [0,0,1])
    aff.setAffordanceParams(params)
    aff.updateParamsFromActorTransform()
    aff.addToView(app.getDRCView())
    return aff 
Example #13
Source File: test_common.py    From pyvista with MIT License 5 votes vote down vote up
def test_translate_should_match_vtk_transformation(rotate_amounts, translate_amounts, grid):
    trans = vtk.vtkTransform()
    trans.RotateWXYZ(0, *rotate_amounts)
    trans.Translate(translate_amounts)
    trans.Update()

    grid_a = grid.copy()
    grid_b = grid.copy()
    grid_c = grid.copy()
    grid_a.transform(trans)
    grid_b.transform(trans.GetMatrix())
    grid_c.transform(pyvista.trans_from_matrix(trans.GetMatrix()))
    assert np.allclose(grid_a.points, grid_b.points, equal_nan=True)
    assert np.allclose(grid_a.points, grid_c.points, equal_nan=True) 
Example #14
Source File: display.py    From SlicerJupyter with MIT License 5 votes vote down vote up
def __init__(self, viewID=0, orientation=None):
    slicer.app.processEvents()
    widget = slicer.app.layoutManager().threeDWidget(viewID)
    view = widget.threeDView()
    if orientation is not None:
      camera = view.interactorStyle().GetCameraNode().GetCamera()
      cameraToWorld = vtk.vtkTransform()
      cameraToWorld.RotateX(90)
      cameraToWorld.RotateY(180)
      cameraToWorld.RotateY(orientation[2])
      cameraToWorld.RotateX(orientation[1])
      cameraToWorld.RotateZ(orientation[0])
      cameraToWorld.Translate(0, 0, camera.GetDistance())
      viewUp = [0,1,0,0]
      slicer.vtkAddonMathUtilities.GetOrientationMatrixColumn(cameraToWorld.GetMatrix(), 1, viewUp)
      position = cameraToWorld.GetPosition()
      focalPoint = camera.GetFocalPoint()
      camera.SetPosition(focalPoint[0]+position[0], focalPoint[1]+position[1], focalPoint[2]+position[2])
      camera.SetViewUp(viewUp[0:3])
      camera.OrthogonalizeViewUp()
    view.forceRender()
    screenshot = view.grab()
    bArray = qt.QByteArray()
    buffer = qt.QBuffer(bArray)
    buffer.open(qt.QIODevice.WriteOnly)
    #screenshot.save(buffer, "PNG")
    screenshot.save(buffer, "JPG")
    self.dataValue = bArray.toBase64().data().decode()
    #dataType = "image/png"
    self.dataType = "image/jpeg" 
Example #15
Source File: viz.py    From deep_gcns with MIT License 5 votes vote down vote up
def getActorCircle(radius_inner=100, radius_outer=99, color=(1,0,0)):
    """"""
    # create source
    source = vtk.vtkDiskSource()
    source.SetInnerRadius(radius_inner)
    source.SetOuterRadius(radius_outer)
    source.SetRadialResolution(100)
    source.SetCircumferentialResolution(100)

    # Transformer
    transform = vtk.vtkTransform()
    transform.RotateWXYZ(90, 1, 0, 0)
    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetTransform(transform)
    transformFilter.SetInputConnection(source.GetOutputPort())
    transformFilter.Update()

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(transformFilter.GetOutputPort())

    # actor
    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(color)
    actor.SetMapper(mapper)

    return actor 
Example #16
Source File: pc_viz.py    From deep_gcns_torch with MIT License 5 votes vote down vote up
def getActorCircle(radius_inner=100, radius_outer=99, color=(1, 0, 0)):
    """"""
    # create source
    source = vtk.vtkDiskSource()
    source.SetInnerRadius(radius_inner)
    source.SetOuterRadius(radius_outer)
    source.SetRadialResolution(100)
    source.SetCircumferentialResolution(100)

    # Transformer
    transform = vtk.vtkTransform()
    transform.RotateWXYZ(90, 1, 0, 0)
    transformFilter = vtk.vtkTransformPolyDataFilter()
    transformFilter.SetTransform(transform)
    transformFilter.SetInputConnection(source.GetOutputPort())
    transformFilter.Update()

    # mapper
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(transformFilter.GetOutputPort())

    # actor
    actor = vtk.vtkActor()
    actor.GetProperty().SetColor(color)
    actor.SetMapper(mapper)

    return actor 
Example #17
Source File: test_common.py    From pyvista with MIT License 5 votes vote down vote up
def test_rotate_should_match_vtk_rotation(angle, axis, grid):
    trans = vtk.vtkTransform()
    getattr(trans, 'Rotate{}'.format(axis.upper()))(angle)
    trans.Update()

    trans_filter = vtk.vtkTransformFilter()
    trans_filter.SetTransform(trans)
    trans_filter.SetInputData(grid)
    trans_filter.Update()
    grid_a = pyvista.UnstructuredGrid(trans_filter.GetOutput())

    grid_b = grid.copy()
    getattr(grid_b, 'rotate_{}'.format(axis))(angle)
    assert np.allclose(grid_a.points, grid_b.points, equal_nan=True) 
Example #18
Source File: perception.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getFrame(self, name, relativeTo='local'):
        t = vtk.vtkTransform()
        self.reader.GetTransform(name, relativeTo, self.reader.GetCurrentScanTime(), t)
        return t 
Example #19
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def segmentDebrisWallManual(point1, point2):

    p1, p2 = point1, point2

    d = DebugData()
    d.addSphere(p1, radius=0.01)
    d.addSphere(p2, radius=0.01)
    d.addLine(p1, p2)
    edgeObj = updatePolyData(d.getPolyData(), 'debris plane edge', visible=True)
    edgeObj.points = [p1, p2]

    xaxis = p2 - p1
    xaxis /= np.linalg.norm(xaxis)
    zaxis = np.array([0.0, 0.0, 1.0])
    yaxis = np.cross(zaxis, xaxis)

    t = getTransformFromAxes(xaxis, yaxis, zaxis)
    t.PostMultiply()
    t.Translate(p1)

    updateFrame(t, 'debris plane frame', parent=edgeObj, visible=False)

    refFrame = vtk.vtkTransform()
    refFrame.PostMultiply()
    refFrame.SetMatrix(t.GetMatrix())
    refFrame.Translate(-xaxis + yaxis + zaxis*20.0)
    updateFrame(refFrame, 'debris reference frame', parent=edgeObj, visible=False) 
Example #20
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getDrillInHandOffset(zRotation=0.0, zTranslation=0.0, xTranslation=0.0, yTranslation=0.0,flip=False):

    drillOffset = vtk.vtkTransform()
    drillOffset.PostMultiply()
    if flip:
        drillOffset.RotateY(180)
    drillOffset.RotateZ(zRotation)
    drillOffset.RotateY(-90)
    #drillOffset.Translate(0, 0.09, zTranslation - 0.015)
    #drillOffset.Translate(zTranslation - 0.015, 0.035 + xTranslation, 0.0)
    drillOffset.Translate(zTranslation, xTranslation, 0.0 + yTranslation)
    return drillOffset 
Example #21
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getLinkFrame(linkName):
    robotStateModel = om.findObjectByName('robot state model')
    assert robotStateModel
    t = vtk.vtkTransform()
    robotStateModel.model.getLinkToWorld(linkName, t)
    return t 
Example #22
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def applyICP(source, target):

    icp = vtk.vtkIterativeClosestPointTransform()
    icp.SetSource(source)
    icp.SetTarget(target)
    icp.GetLandmarkTransform().SetModeToRigidBody()
    icp.Update()
    t = vtk.vtkTransform()
    t.SetMatrix(icp.GetMatrix())
    return t 
Example #23
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def lockAffordanceToHand(aff, hand='l_hand'):

    linkFrame = getLinkFrame(hand)
    affT = aff.actor.GetUserTransform()

    if not hasattr(aff, 'handToAffT') or not aff.handToAffT:
        aff.handToAffT = computeAToB(linkFrame, affT)

    t = vtk.vtkTransform()
    t.PostMultiply()
    t.Concatenate(aff.handToAffT)
    t.Concatenate(linkFrame)
    aff.actor.GetUserTransform().SetMatrix(t.GetMatrix()) 
Example #24
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def computeAToB(a,b):

    t = vtk.vtkTransform()
    t.PostMultiply()
    t.Concatenate(b)
    t.Concatenate(a.GetLinearInverse())
    tt = vtk.vtkTransform()
    tt.SetMatrix(t.GetMatrix())
    return tt 
Example #25
Source File: fieldcontainer.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _repr(self, indent=4):
    if isinstance(self, FieldContainer):
        return _fields_repr(self, indent)
    if isinstance(self, vtk.vtkTransform):
        return _transform_repr(self, indent)
    if isinstance(self, dict):
        return _dict_repr(self, indent)
    if isinstance(self, list) and len(self) and not isinstance(self[0], (int, float)):
        return _list_repr(self, indent)
    else:
        return repr(self) 
Example #26
Source File: common.py    From pyvista with MIT License 5 votes vote down vote up
def transform(self, trans):
        """Compute a transformation in place using a 4x4 transform.

        Parameters
        ----------
        trans : vtk.vtkMatrix4x4, vtk.vtkTransform, or np.ndarray
            Accepts a vtk transformation object or a 4x4 transformation matrix.

        """
        if isinstance(trans, vtk.vtkMatrix4x4):
            t = pyvista.trans_from_matrix(trans)
        elif isinstance(trans, vtk.vtkTransform):
            t = pyvista.trans_from_matrix(trans.GetMatrix())
        elif isinstance(trans, np.ndarray):
            if trans.ndim != 2:
                raise ValueError('Transformation array must be 4x4')
            elif trans.shape[0] != 4 or trans.shape[1] != 4:
                raise ValueError('Transformation array must be 4x4')
            t = trans
        else:
            raise TypeError('Input transform must be either:\n'
                            '\tvtk.vtkMatrix4x4\n'
                            '\tvtk.vtkTransform\n'
                            '\t4x4 np.ndarray\n')

        x = (self.points*t[0, :3]).sum(1) + t[0, -1]
        y = (self.points*t[1, :3]).sum(1) + t[1, -1]
        z = (self.points*t[2, :3]).sum(1) + t[2, -1]

        # overwrite points
        self.points[:, 0] = x
        self.points[:, 1] = y
        self.points[:, 2] = z 
Example #27
Source File: segmentation.py    From director with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def segmentTruss(point1, point2):



    edge = point2 - point1
    edgeLength = np.linalg.norm(edge)

    stanceOffset = [-0.42, 0.0, 0.0]
    stanceYaw = 0.0


    d = DebugData()
    p1 = [0.0, 0.0, 0.0]
    p2 = -np.array([0.0, -1.0, 0.0]) * edgeLength
    d.addSphere(p1, radius=0.02)
    d.addSphere(p2, radius=0.02)
    d.addLine(p1, p2)

    stanceTransform = vtk.vtkTransform()
    stanceTransform.PostMultiply()
    stanceTransform.Translate(stanceOffset)
    #stanceTransform.RotateZ(stanceYaw)

    geometry = transformPolyData(d.getPolyData(), stanceTransform.GetLinearInverse())

    yaxis = edge/edgeLength
    zaxis = [0.0, 0.0, 1.0]
    xaxis = np.cross(yaxis, zaxis)
    xaxis /= np.linalg.norm(xaxis)
    yaxis = np.cross(zaxis, xaxis)
    yaxis /= np.linalg.norm(yaxis)


    xwidth = 0.1
    ywidth = edgeLength
    zwidth = 0.1

    t = getTransformFromAxes(xaxis, yaxis, zaxis)
    t.PreMultiply()
    t.Concatenate(stanceTransform)
    t.PostMultiply()
    t.Translate(point1)

    name = 'truss'
    otdfType = 'robot_knees'
    obj = showPolyData(geometry, name, cls=FrameAffordanceItem, parent='affordances')
    obj.actor.SetUserTransform(t)
    obj.addToView(app.getDRCView())

    params = dict(origin=t.GetPosition(), xwidth=xwidth, ywidth=ywidth, zwidth=zwidth, xaxis=xaxis, yaxis=yaxis, zaxis=zaxis, friendly_name=name, otdf_type=otdfType)
    obj.setAffordanceParams(params)
    obj.updateParamsFromActorTransform()

    frameObj = showFrame(obj.actor.GetUserTransform(), name + ' frame', parent=obj, visible=False)
    frameObj.addToView(app.getDRCView()) 
Example #28
Source File: utility.py    From ILCC with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def vis_with_renderer(renderer):
    # Renderer

    # renderer.SetBackground(.2, .3, .4)
    renderer.SetBackground(1, 1, 1)
    renderer.ResetCamera()

    transform = vtk.vtkTransform()
    transform.Translate(1.0, 0.0, 0.0)
    axes = vtk.vtkAxesActor()
    renderer.AddActor(axes)

    # Render Window
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)

    # Interactor
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    def get_camera_info(obj, ev):
        if renderWindowInteractor.GetKeyCode() == "s":
            w2if = vtk.vtkWindowToImageFilter()
            w2if.SetInput(renderWindow)
            w2if.Update()

            writer = vtk.vtkPNGWriter()
            writer.SetFileName("screenshot.png")
            if vtk.VTK_MAJOR_VERSION == 5:
                writer.SetInput(w2if.GetOutput())
            else:
                writer.SetInputData(w2if.GetOutput())
            writer.Write()
            print "screenshot saved"

    style = vtk.vtkInteractorStyleSwitch()
    renderWindowInteractor.SetInteractorStyle(style)
    # style.SetCurrentStyleToTrackballActor()
    style.SetCurrentStyleToTrackballCamera()

    # Begin Interaction
    renderWindowInteractor.AddObserver(vtk.vtkCommand.KeyPressEvent, get_camera_info, 1)
    renderWindow.Render()
    renderWindowInteractor.Start()