精华内容
下载资源
问答
  • 本文整理汇总了Pythonvtk.vtkTransform方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkTransform方法的具体用法?Python vtk.vtkTransform怎么用?Python vtk.vtkTransform使用的例子?那么恭喜您,...

    本文整理汇总了Python中vtk.vtkTransform方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkTransform方法的具体用法?Python vtk.vtkTransform怎么用?Python vtk.vtkTransform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块vtk的用法示例。

    在下文中一共展示了vtk.vtkTransform方法的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

    示例1: getDepthMapData

    ​点赞 7

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:RobotLocomotion,项目名称:director,代码行数:18,

    示例2: set_scale

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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()

    开发者ID:pyvista,项目名称:pyvista,代码行数:26,

    示例3: CameraModeToObjectAxis

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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()

    开发者ID:pyCGNS,项目名称:pyCGNS,代码行数:19,

    示例4: CameraModeToObjectAllAxis

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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()

    开发者ID:pyCGNS,项目名称:pyCGNS,代码行数:22,

    示例5: Roll

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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()

    # -----------------------------------------------------------------------------

    开发者ID:pyCGNS,项目名称:pyCGNS,代码行数:27,

    示例6: RequestData

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:OpenGeoVis,项目名称:PVGeo,代码行数:18,

    示例7: getFootFramesFromReferenceFrame

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:RobotLocomotion,项目名称:director,代码行数:26,

    示例8: getDrillMesh

    ​点赞 6

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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())

    开发者ID:RobotLocomotion,项目名称:director,代码行数:18,

    示例9: test_translate_should_match_vtk_transformation

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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)

    开发者ID:pyvista,项目名称:pyvista,代码行数:16,

    示例10: test_rotate_should_match_vtk_rotation

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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)

    开发者ID:pyvista,项目名称:pyvista,代码行数:16,

    示例11: transform

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:pyvista,项目名称:pyvista,代码行数:35,

    示例12: getActorCircle

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:VisualComputingInstitute,项目名称:3d-semantic-segmentation,代码行数:29,

    示例13: _repr

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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)

    开发者ID:RobotLocomotion,项目名称:director,代码行数:13,

    示例14: computeAToB

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:RobotLocomotion,项目名称:director,代码行数:11,

    示例15: lockAffordanceToHand

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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())

    开发者ID:RobotLocomotion,项目名称:director,代码行数:15,

    示例16: applyICP

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:RobotLocomotion,项目名称:director,代码行数:12,

    示例17: addDrillAffordance

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:RobotLocomotion,项目名称:director,代码行数:17,

    示例18: getLinkFrame

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    def getLinkFrame(linkName):

    robotStateModel = om.findObjectByName('robot state model')

    assert robotStateModel

    t = vtk.vtkTransform()

    robotStateModel.model.getLinkToWorld(linkName, t)

    return t

    开发者ID:RobotLocomotion,项目名称:director,代码行数:8,

    示例19: getDrillInHandOffset

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:RobotLocomotion,项目名称:director,代码行数:14,

    示例20: segmentDebrisWallManual

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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)

    开发者ID:RobotLocomotion,项目名称:director,代码行数:29,

    示例21: getFrame

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    def getFrame(self, name, relativeTo='local'):

    t = vtk.vtkTransform()

    self.reader.GetTransform(name, relativeTo, self.reader.GetCurrentScanTime(), t)

    return t

    开发者ID:RobotLocomotion,项目名称:director,代码行数:6,

    示例22: getActorCircle

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:lightaime,项目名称:deep_gcns_torch,代码行数:29,

    示例23: __init__

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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"

    开发者ID:Slicer,项目名称:SlicerJupyter,代码行数:32,

    示例24: _array2vtkTransform

    ​点赞 5

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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

    开发者ID:poodarchu,项目名称:Det3D,代码行数:10,

    示例25: vis_with_renderer

    ​点赞 4

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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()

    开发者ID:mfxox,项目名称:ILCC,代码行数:46,

    示例26: segmentTruss

    ​点赞 4

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import vtkTransform [as 别名]

    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())

    开发者ID:RobotLocomotion,项目名称:director,代码行数:57,

    注:本文中的vtk.vtkTransform方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

    展开全文
  • Vtk是在面向对象原理的基础上设计和实现的,它的内核是用C++构建的,包含有大约250,000行代码,2000多个类,还包含有几个转换界面,因此也可以自由的通过Java,Tcl/Tk和Python各种语言使用vtk。以下介绍VTK对于STL...

    Vtk,(visualization toolkit)是一个开源的免费软件系统,主要用于三维计算机图形学、图像处理和可视化。Vtk是在面向对象原理的基础上设计和实现的,它的内核是用C++构建的,包含有大约250,000行代码,2000多个类,还包含有几个转换界面,因此也可以自由的通过Java,Tcl/Tk和Python各种语言使用vtk。以下介绍VTK对于STL图像的基本操作

    STL图像加载、缩放、旋转

    import os

    import vtk

    base_file = "E:\\study\\company\\model"

    test_file = "dongmai.stl"

    actor = vtk.vtkActor()

    def show(file_name):

    # load stl file

    reader = vtk.vtkSTLReader()

    reader.SetFileName(file_name)

    mapper = vtk.vtkPolyDataMapper()

    mapper.SetInputConnection(reader.GetOutputPort())

    actor.SetMapper(mapper)

    # actor.RotateY(45)

    # Create a rendering window and renderer

    ren = vtk.vtkRenderer()

    renWin = vtk.vtkRenderWindow()

    renWin.AddRenderer(ren)

    # Create a renderwindowinteractor

    iren = vtk.vtkRenderWindowInteractor()

    iren.SetRenderWindow(renWin)

    # Assign actor to the renderer

    ren.AddActor(actor)

    # Enable user interface interactor

    iren.Initialize()

    renWin.Render()

    iren.Start()

    return iren

    # 绕x轴旋转

    def rotate_x(num):

    actor.RotateX(num)

    def rotate_y(num):

    actor.RotateY(num)

    def rotate_z(num):

    actor.RotateZ(num)

    # 设置方向

    def set_origin(x, y, z):

    actor.SetOrientation(x, y, z)

    def get_origin():

    return actor.GetOrientation()

    # 缩放

    def set_scale(x, y, z):

    actor.SetScale(x, y, z)

    def main():

    show(os.path.join(base_file, test_file))

    if __name__ == ‘__main__‘:

    main()

    显示结果

    鼠标事件监听

    # 监听事件

    class MyEvent(vtk.vtkInteractorStyleTrackballCamera):

    def __init__(self, parent=None):

    # 鼠标中键

    self.AddObserver("MiddleButtonPressEvent", self.middle_button_press_event)

    self.AddObserver("MiddleButtonReleaseEvent", self.middle_button_release_event)

    # 鼠标左键

    self.AddObserver("LeftButtonPressEvent", self.left_button_press_event)

    self.AddObserver("LeftButtonReleaseEvent", self.left_button_release_event)

    # 鼠标右键

    self.AddObserver("RightButtonPressEvent", self.right_button_press_event)

    self.AddObserver("RightButtonReleaseEvent", self.right_button_release_event)

    def middle_button_press_event(self, obj, event):

    print("Middle Button pressed")

    self.OnMiddleButtonDown()

    return

    def middle_button_release_event(self, obj, event):

    print("Middle Button released")

    self.OnMiddleButtonUp()

    return

    def left_button_press_event(self, obj, event):

    print("Left Button pressed")

    self.OnLeftButtonDown()

    return

    def left_button_release_event(self, obj, event):

    print("Left Button released")

    self.OnLeftButtonUp()

    return

    def right_button_press_event(self, obj, event):

    print("right Button pressed")

    self.OnRightButtonDown()

    return

    def right_button_release_event(self, obj, event):

    print("right Button released")

    self.OnLeftButtonUp()

    return

    # 引入上一段代码调用

    iren.SetInteractorStyle(MyEvent())

    结果

    参考文档

    展开全文
  • # 需要导入模块: import vtk [as 别名]# 或者: from vtk import util [as 别名]def to_itk_image(image_like):if isinstance(image_like, itk.Image):return image_likeif is_arraylike(image_like):array = np.as...

    # 需要导入模块: import vtk [as 别名]

    # 或者: from vtk import util [as 别名]

    def to_itk_image(image_like):

    if isinstance(image_like, itk.Image):

    return image_like

    if is_arraylike(image_like):

    array = np.asarray(image_like)

    case_use_view = array.flags['OWNDATA']

    if have_dask and isinstance(image_like, dask.array.core.Array):

    case_use_view = False

    array = np.ascontiguousarray(array)

    if case_use_view:

    image_from_array = itk.image_view_from_array(array)

    else:

    image_from_array = itk.image_from_array(array)

    return image_from_array

    elif have_vtk and isinstance(image_like, vtk.vtkImageData):

    from vtk.util import numpy_support as vtk_numpy_support

    array = vtk_numpy_support.vtk_to_numpy(

    image_like.GetPointData().GetScalars())

    array.shape = tuple(image_like.GetDimensions())[::-1]

    image_from_array = itk.image_view_from_array(array)

    image_from_array.SetSpacing(image_like.GetSpacing())

    image_from_array.SetOrigin(image_like.GetOrigin())

    return image_from_array

    elif have_simpleitk and isinstance(image_like, sitk.Image):

    array = sitk.GetArrayViewFromImage(image_like)

    image_from_array = itk.image_view_from_array(array)

    image_from_array.SetSpacing(image_like.GetSpacing())

    image_from_array.SetOrigin(image_like.GetOrigin())

    direction = image_like.GetDirection()

    npdirection = np.asarray(direction)

    npdirection = np.reshape(npdirection, (-1, 3))

    itkdirection = itk.matrix_from_array(npdirection)

    image_from_array.SetDirection(itkdirection)

    return image_from_array

    elif have_imagej:

    import imglyb

    if isinstance(image_like,

    imglyb.util.ReferenceGuardingRandomAccessibleInterval):

    array = imglyb.to_numpy(image_like)

    image_from_array = itk.image_view_from_array(array)

    return image_from_array

    elif isinstance(image_like, itk.ProcessObject):

    return itk.output(image_like)

    return None

    展开全文
  • vtk刚开始看,这里仅仅只是其最简单的读取显示功能。此处用到了vtk库,可自行百度安装方法。下面附上代码:from vtk import *# reader the dicom filereader = vtkDICOMImageReader()reader....

    因为做项目的原因,所以接触到了医学图像dicom文件。vtk刚开始看,这里仅仅只是其最简单的读取显示功能。此处用到了vtk库,可自行百度安装方法。

    下面附上代码:

    from vtk import *

    # reader the dicom file

    reader = vtkDICOMImageReader()

    reader.SetDataByteOrderToLittleEndian()

    reader.SetFileName("00efb2fedf64b867a36031a394e5855a.dcm")

    reader.Update()

    # show the dicom flie

    imageViewer = vtkImageViewer2()

    imageViewer.SetInputConnection(reader.GetOutputPort())

    renderWindowInteractor = vtkRenderWindowInteractor()

    imageViewer.SetupInteractor(renderWindowInteractor)

    imageViewer.Render()

    imageViewer.GetRenderer().ResetCamera()

    imageViewer.Render()

    renderWindowInteractor.Start()

    运行程序得到显示图:

    DICOM图像显示是可以设置窗宽、窗位的,还在学习尝试中,效果好的话再更新。

    以上这篇Python vtk读取并显示dicom文件示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持爱蒂网。

    展开全文
  • 我有多个字段的PLY文件,我已经成功地使用PythonVTK读入、过滤和可视化。我的主要目标是最终分割并对单个作物地块进行分析。在然而,为了使这项任务更容易,我首先想“规范化”我的点云,这样所有的绘图基本上都是...
  • 今天小编就为大家分享一篇Python vtk读取并显示dicom文件示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • vtk刚开始看,这里仅仅只是其最简单的读取显示功能。此处用到了vtk库,可自行百度安装方法。下面附上代码:from vtk import *# reader the dicom filereader = vtkDICOMImageReader()reader....
  • 我有一个文件,其中第一列是x坐标,第二列是y坐标,第三列是z坐标,第四列是与每个点相关的值。...我发现更快的方法是使用pythonvtk。这是我现在掌握的代码:import vtkimport numpy as np## DATA# Generate r...
  • 本文整理汇总了Pythonvtk.vtkUnsignedCharArray方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkUnsignedCharArray方法的具体用法?Python vtk.vtkUnsignedCharArray怎么用?Python vtk....
  • Vtk是在面向对象原理的基础上设计和实现的,它的内核是用C++构建的,包含有大约250,000行代码,2000多个类,还包含有几个转换界面,因此也可以自由的通过Java,Tcl/Tk和Python各种语言使用vtk。(推荐学习:Python...
  • 我想看看使用vtk库的传感器点云。所以我做了。首先,我在定时器回调函数中接收原始传感器数据。但它有延迟时间,大约2秒。所以我使用多处理,我在父进程中收到原始传感器数据。子进程显示这个。但它仍然有延迟时间。...
  • {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":4,"count":4}]},"card":[{"des":"阿里技术人对外发布原创技术内容的最大平台;社区覆盖了云计算、大数据、人工智能、...
  • 我写了一个相当笨拙的python程序,它创建了一个特定几何体的单元单元,并对其进行了复制,这样我就得到了一个3x3x3的单元单元单元数组。结果保存为.stl。目标是直接创建这些结构,而不是使用CAD。在我的问题是计算...
  • VTK文档中看到的有些函数在python中没进行封装,也没有相关文档,通过测试,下面的程序可以实现删除指定的交互函数#!/usr/bin/env pythonimport vtkt1 = 0t2 = 0t3 = 0iren = vtk.vtkRenderWindowInteractor()def ...
  • 我发现了一些工具,如vtk,pptk等,并显示存储的数据。但我不能实时显示这些。我不知道该怎么办。我找不到细节。你能给我一些信息,建议或例子吗?谢谢。在我试过实时pptk。但它每次都会打开新的窗口。在import ...
  • Vtk是在面向对象原理的基础上设计和实现的,它的内核是用C++构建的,包含有大约250,000行代码,2000多个类,还包含有几个转换界面,因此也可以自由的通过Java,Tcl/Tk和Python各种语言使用vtk。在Windows环境下用...
  • <pre><code>import vtk </code></pre> <p>at the top of Python files, see if we can import a smaller subset containing only what we need.</p><p>该提问来源于开源项目:OpenChemistry/tomviz</p></div>
  • import vtkimport numpy as npsrc=np.random.rand(32,3)vtkPoints=vtk.vtkPoints()for i in range(0,src.shape[0]):x=src[i,0]y=src[i,1]z=src[i,2]p=[x,y,z]vtkPoints.InsertNextPoint(p)poly = vtk.vtkPolyData()p...
  • 大神的源码在这里:在c#中,有些VTK的功能不支持,所以需要自己改一下:namespaceSliceMonitortest{//////封装了4*4矩阵的乘法///因为在Activiz中,vtkMatrix4x4的MultiplyPoint功能无法使用,所以自己封装了一个类...
  • /usr/bin/env python#This simple example shows how to do basic rendering and pipeline#creation.importvtkclassMouseInteractorHighLightActor(vtk.vtkInteractorStyleTrackballCamera):def __init__(self, pa.....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,318
精华内容 527
热门标签
关键字:

pythonvtk

python 订阅