Ejemplo n.º 1
0
def main():
    colors = vtkNamedColors()
    renWin = vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    earthCenter = [100.0, 0.0, 0.0]
    earth = CreatePlanet(4.0, earthCenter)

    marsCenter = [80.0, 0.0, 0.0]
    mars = CreatePlanet(3.0, marsCenter)

    sunCenter = [0.0, 0.0, 0.0]
    sun = CreatePlanet(15.0, sunCenter)

    earthActor = CreateVisualization(earth)
    earthActor.GetProperty().SetColor(colors.GetColor3d('Blue'))

    marsActor = CreateVisualization(mars)
    marsActor.GetProperty().SetColor(colors.GetColor3d('Red'))

    sunActor = CreateVisualization(sun)
    sunActor.GetProperty().SetColor(colors.GetColor3d('Yellow'))

    renderer.SetBackground(colors.GetColor3d('Black'))
    renWin.SetSize(640, 480)
    renWin.SetWindowName('Aarya\'s Solar System')

    renWin.Render()

    # Interact with the data.
    iren.Start()
Ejemplo n.º 2
0
def make_sgrid_actor(sgrid, color='Peacock', edges_on=True, grid_only=True):
    sgridMapper = vtkDataSetMapper()
    sgridMapper.SetInputData(sgrid)
    sgridActor = vtkActor()
    sgridActor.SetMapper(sgridMapper)
    sgridActor.GetProperty().SetColor(vtkNamedColors().GetColor3d(color))
    if edges_on and not grid_only: sgridActor.GetProperty().EdgeVisibilityOn()
    if grid_only:
        sgridActor.GetProperty().SetRepresentationToWireframe()
    return sgridActor
Ejemplo n.º 3
0
def main():
    colors = vtkNamedColors()
    renderer = vtkRenderer()
    renWin = vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    sphere = vtkSphereSource()
    sphere.SetPhiResolution(100)
    sphere.SetThetaResolution(16)
    sphere.SetCenter(2, 0, 0)
    sphere.SetRadius(69)
    sphere.Update()
    sphereGeom = sphere.GetOutput()

    cone = vtkConeSource()
    cone.SetRadius(40)
    cone.SetHeight(100)
    cone.SetResolution(50)
    cone.Update()
    coneGeom = cone.GetOutput()

    print('Number of points in sphere = ', sphereGeom.GetNumberOfPoints())
    print('Number of triangles in sphere = ', sphereGeom.GetNumberOfCells())

    print('Number of points in cone = ', coneGeom.GetNumberOfPoints())
    print('Number of triangles in cone = ', coneGeom.GetNumberOfCells())

    mapperS = vtkDataSetMapper()
    mapperS.SetInputData(sphereGeom)
    actorS = vtkActor()
    actorS.SetMapper(mapperS)
    actorS.GetProperty().SetColor(1.0, 0.0, 0.0)
    actorS.GetProperty().SetOpacity(0.5)
    renderer.AddActor(actorS)

    mapperC = vtkDataSetMapper()
    mapperC.SetInputData(coneGeom)
    actorC = vtkActor()
    actorC.SetMapper(mapperC)
    actorC.GetProperty().SetOpacity(0.5)
    renderer.AddActor(actorC)

    renderer.SetBackground(colors.GetColor3d('SlateGray'))
    renWin.SetSize(640, 480)
    renWin.SetWindowName('Aarya\'s First VTK Program')

    renWin.Render()

    # Interact with the data.
    iren.Start()
Ejemplo n.º 4
0
    def __init__(self, linuxcncDataSource, model_path):
        super(SpindleActor, self).__init__()

        self._datasource = linuxcncDataSource
        self._tool_table = self._datasource.getToolTable()

        tool = self._tool_table[0]

        if self._datasource.isMachineMetric():
            self.height = 25.4 * 2.0
        else:
            self.height = 2.0

        start_point = [-tool.xoffset, -tool.yoffset, -tool.zoffset]
        end_point = [0, 0, 0]

        filename = model_path
        # filename = os.path.join(os.path.dirname(__file__), "models/laser.stl")

        source = vtk.vtkSTLReader()
        source.SetFileName(filename)

        transform = vtk.vtkTransform()

        # transform.RotateWXYZ(180, 1, 0, 0)

        transform_filter = vtk.vtkTransformPolyDataFilter()
        transform_filter.SetTransform(transform)
        transform_filter.SetInputConnection(source.GetOutputPort())
        transform_filter.Update()

        colors = vtkNamedColors()

        # Create a mapper and actor for the arrow
        mapper = vtkPolyDataMapper()
        mapper.SetInputConnection(transform_filter.GetOutputPort())

        self.SetMapper(mapper)

        self.GetProperty().SetDiffuse(0.8)
        self.GetProperty().SetDiffuseColor(colors.GetColor3d('LightSteelBlue'))
        self.GetProperty().SetSpecular(0.3)
        self.GetProperty().SetSpecularPower(60.0)

        # Avoid visible backfaces on Linux with some video cards like intel
        # From: https://stackoverflow.com/questions/51357630/vtk-rendering-not-working-as-expected-inside-pyqt?rq=1#comment89720589_51360335
        self.GetProperty().SetBackfaceCulling(1)
Ejemplo n.º 5
0
def createLine(point1: tuple, point2: tuple, color: str = "Black") -> vtkActor:
    """
    :param point1:
    :param point2:
    :param color:
    :return:
    """
    line = vtkLineSource()

    line.SetPoint1(*point1)
    line.SetPoint2(*point2)

    mapper = vtkPolyDataMapper()
    mapper.SetInputConnection(line.GetOutputPort())

    actor = vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(vtkNamedColors().GetColor3d(color))

    return actor
Ejemplo n.º 6
0
    def __init__(self, linuxcncDataSource):
        super(ToolOffsetActor, self).__init__()

        self._datasource = linuxcncDataSource
        self._tool_table = self._datasource.getToolTable()

        tool = self._tool_table[0]

        if self._datasource.isMachineMetric():
            self.height = 25.4 * 2.0
        else:
            self.height = 2.0

        start_point = [-tool.xoffset, -tool.yoffset, -tool.zoffset]
        end_point = [0, 0, 0]

        source = vtkCylinderSource()
        transform = vtk.vtkTransform()

        source.SetHeight(tool.zoffset)
        source.SetCenter(-tool.xoffset, -tool.zoffset / 2, -tool.yoffset)
        source.SetRadius(tool.diameter / 2)
        source.SetResolution(64)
        transform.RotateWXYZ(90, 1, 0, 0)

        transform_filter = vtk.vtkTransformPolyDataFilter()
        transform_filter.SetTransform(transform)
        transform_filter.SetInputConnection(source.GetOutputPort())
        transform_filter.Update()

        colors = vtkNamedColors()

        # Create a mapper and actor for the arrow
        mapper = vtkPolyDataMapper()
        mapper.SetInputConnection(transform_filter.GetOutputPort())

        self.SetMapper(mapper)

        # Avoid visible backfaces on Linux with some video cards like intel
        # From: https://stackoverflow.com/questions/51357630/vtk-rendering-not-working-as-expected-inside-pyqt?rq=1#comment89720589_51360335
        self.GetProperty().SetBackfaceCulling(1)
Ejemplo n.º 7
0
def render_actors(actor_lst, bg_color='White'):
    renderer = vtkRenderer()
    renWin = vtkRenderWindow()
    renWin.AddRenderer(renderer)

    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    style = vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)

    for actor in actor_lst:
        renderer.AddActor(actor)

    colors = vtkNamedColors()
    renderer.SetBackground(colors.GetColor3d(bg_color))
    renderer.ResetCamera()
    # renWin.SetSize(640, 480)

    # Interact with the data.
    renWin.Render()
    iren.Start()
Ejemplo n.º 8
0
def test_msh_curves_lattice():

    iso_eth_crv1 = gbs.BSCurve2d([[0., 0.], [0.8, 0.], [1.2, 1.], [2., 1.]],
                                 [0., 0.5, 1.], [3, 1, 3], 2)
    iso_eth_crv2 = gbs.BSCurve2d(
        [[0., 1.0], [0.5, 1.2], [1.5, 1.5], [2., 1.5]], [0., 0.3, 1.],
        [3, 1, 3], 2)
    iso_eth_crv3 = gbs.BSCurve2d([[0., 2.], [0.7, 2.], [1.5, 2.], [2., 2.]],
                                 [0., 0.5, 1.], [3, 1, 3], 2)

    iso_ksi_crv1 = gbs.BSCurve2d(
        [iso_eth_crv1.begin(), iso_eth_crv3.begin()], [0., 1.], [2, 2], 1)
    iso_ksi_crv2 = gbs.BSCurve2d(
        [iso_eth_crv1.end(), iso_eth_crv3.end()], [0., 1.], [2, 2], 1)

    ksi_i = [0., 0.5, 1.]
    eth_j = [0., 1.]

    X_ksi, X_eth, X_ksi_eth, ksi, eth = gbs.msh_curves_lattice(
        [iso_eth_crv1, iso_eth_crv2, iso_eth_crv3],
        [iso_ksi_crv1, iso_ksi_crv2],
        ksi_i,
        eth_j,
        [20],
        [10, 10],
    )
    dims = [len(X_ksi), len(X_eth), 1]

    pts = gbs.tfi_mesh(X_ksi, X_eth, X_ksi_eth, ksi_i, eth_j, ksi, eth)

    assert len(pts) == dims[0] * dims[1] * dims[2]

    assert gbs.dist(iso_eth_crv1.begin(), pts[0]) == pytest.approx(0.)
    assert gbs.dist(iso_eth_crv1.end(), pts[dims[0] - 1]) == pytest.approx(0.)
    assert gbs.dist(iso_eth_crv3.begin(),
                    pts[dims[0] * (dims[1] - 1)]) == pytest.approx(0.)
    assert gbs.dist(iso_eth_crv3.end(),
                    pts[dims[0] * dims[1] - 1]) == pytest.approx(0.)

    plot = True

    if plot:
        from vtkmodules.vtkCommonColor import vtkNamedColors

        sgrid = gbs.make_structuredgrid(pts, dims[0], dims[1])

        colors = vtkNamedColors()

        sgridActor = vbs.make_sgrid_actor(
            sgrid, grid_only=False)  # colors.GetColor3d('Peacock')

        iso_eth_crv1_actor = gbs.make_actor(iso_eth_crv1)
        iso_eth_crv1_actor.GetProperty().SetColor(
            colors.GetColor3d('Chartreuse'))
        iso_eth_crv2_actor = gbs.make_actor(iso_eth_crv2)
        iso_eth_crv2_actor.GetProperty().SetColor(
            colors.GetColor3d('Chartreuse'))
        iso_eth_crv3_actor = gbs.make_actor(iso_eth_crv3)
        iso_eth_crv3_actor.GetProperty().SetColor(
            colors.GetColor3d('Chartreuse'))
        iso_ksi_crv1_actor = gbs.make_actor(iso_ksi_crv1)
        iso_ksi_crv2_actor = gbs.make_actor(iso_ksi_crv2)

        vbs.render_actors([
            sgridActor,
            iso_eth_crv1_actor,
            iso_eth_crv2_actor,
            iso_eth_crv3_actor,
            iso_ksi_crv1_actor,
            iso_ksi_crv2_actor,
        ])
Ejemplo n.º 9
0
def main():
    colors = vtkNamedColors()

    operation = "intersection"
    reader = vtkUnstructuredGridReader()
    reader.SetFileName(ATRIA_VTK_FILE)
    geo_filter = vtkGeometryFilter()
    geo_filter.SetInputConnection(reader.GetOutputPort())
    geo_filter.Update()
    poly1 = geo_filter.GetOutput()

    tri1 = vtkTriangleFilter()
    tri1.SetInputData(poly1)
    clean1 = vtkCleanPolyData()
    clean1.SetInputConnection(tri1.GetOutputPort())
    clean1.Update()
    input1 = clean1.GetOutput()

    sphereSource1 = vtkSphereSource()
    sphereSource1.SetCenter(20.43808060942321, 18.333007878470767,
                            34.5753857481471)
    sphereSource1.SetRadius(0.5)
    # sphereSource1.SetPhiResolution(21)
    # sphereSource1.SetThetaResolution(21)
    sphereSource1.Update()
    input2 = sphereSource1.GetOutput()

    input1Mapper = vtkPolyDataMapper()
    input1Mapper.SetInputData(input1)
    input1Mapper.ScalarVisibilityOff()
    input1Actor = vtkActor()
    input1Actor.SetMapper(input1Mapper)
    input1Actor.GetProperty().SetDiffuseColor(colors.GetColor3d("Tomato"))
    input1Actor.GetProperty().SetSpecular(0.6)
    input1Actor.GetProperty().SetSpecularPower(20)
    # input1Actor.SetPosition(input1.GetBounds()[1] - input1.GetBounds()[0], 0, 0)

    input2Mapper = vtkPolyDataMapper()
    input2Mapper.SetInputData(input2)
    input2Mapper.ScalarVisibilityOff()
    input2Actor = vtkActor()
    input2Actor.SetMapper(input2Mapper)
    input2Actor.GetProperty().SetDiffuseColor(colors.GetColor3d("Mint"))
    input2Actor.GetProperty().SetSpecular(0.6)
    input2Actor.GetProperty().SetSpecularPower(20)
    # input2Actor.SetPosition(-(input1.GetBounds()[1] - input1.GetBounds()[0]), 0, 0)

    booleanOperation = vtkBooleanOperationPolyDataFilter()
    if operation.lower() == "union":
        booleanOperation.SetOperationToUnion()
    elif operation.lower() == "intersection":
        booleanOperation.SetOperationToIntersection()
    elif operation.lower() == "difference":
        booleanOperation.SetOperationToDifference()
    else:
        print("Unknown operation:", operation)
        return

    booleanOperation.SetInputData(0, input1)
    booleanOperation.SetInputData(1, input2)

    booleanOperationMapper = vtkPolyDataMapper()
    booleanOperationMapper.SetInputConnection(booleanOperation.GetOutputPort())
    booleanOperationMapper.ScalarVisibilityOff()

    booleanOperationActor = vtkActor()
    booleanOperationActor.SetMapper(booleanOperationMapper)
    booleanOperationActor.GetProperty().SetDiffuseColor(
        colors.GetColor3d("Banana"))
    booleanOperationActor.GetProperty().SetSpecular(0.6)
    booleanOperationActor.GetProperty().SetSpecularPower(20)

    renderer = vtkRenderer()
    renderer.AddViewProp(input1Actor)
    renderer.AddViewProp(input2Actor)
    renderer.AddViewProp(booleanOperationActor)
    renderer.SetBackground(colors.GetColor3d("Silver"))
    renderWindow = vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetSize(640, 480)
    renderWindow.SetWindowName("BooleanOperationPolyDataFilter")

    viewUp = [0.0, 0.0, 1.0]
    position = [0.0, -1.0, 0.0]
    PositionCamera(renderer, viewUp, position)
    renderer.GetActiveCamera().Dolly(1.4)
    renderer.ResetCameraClippingRange()

    renWinInteractor = vtkRenderWindowInteractor()
    renWinInteractor.SetRenderWindow(renderWindow)

    renderWindow.Render()
    renWinInteractor.Start()