Ejemplo n.º 1
0
def ParametricKuen(deltav0=None, **kwargs):
    """Generate Kuens' surface.

    ParametricKuen generates Kuens' surface. This surface has a constant
    negative gaussian curvature.

    Parameters
    ----------
    deltav0 : double, optional
        The value to use when V == 0.
        Default is 0.05, giving the best appearance with the default settings.
        Setting it to a value less than 0.05 extrapolates the surface
        towards a pole in the -z direction.
        Setting it to 0 retains the pole whose z-value is -inf.

    Returns
    -------
    surf : pyvista.PolyData
        ParametricKuen surface

    Examples
    --------
    Create a ParametricKuen mesh

    >>> import pyvista
    >>> mesh = pyvista.ParametricKuen()
    >>> mesh.plot(color='w', smooth_shading=True)  # doctest:+SKIP

    """
    parametric_function = vtk.vtkParametricKuen()
    if deltav0 is not None:
        parametric_function.SetDeltaV0(deltav0)

    center = kwargs.pop('center', [0., 0., 0.])
    direction = kwargs.pop('direction', [1., 0., 0.])
    surf = surface_from_para(parametric_function, **kwargs)

    translate(surf, center, direction)

    return surf
def main():
    colors = vtk.vtkNamedColors()

    colors.SetColor("BkgColor", [26, 51, 102, 255])

    parametricObjects = list()
    parametricObjects.append(vtk.vtkParametricBohemianDome())
    parametricObjects[-1].SetA(5.0)
    parametricObjects[-1].SetB(1.0)
    parametricObjects[-1].SetC(2.0)
    parametricObjects.append(vtk.vtkParametricBour())
    parametricObjects.append(vtk.vtkParametricCatalanMinimal())
    parametricObjects.append(vtk.vtkParametricHenneberg())
    parametricObjects.append(vtk.vtkParametricKuen())
    parametricObjects.append(vtk.vtkParametricPluckerConoid())
    parametricObjects.append(vtk.vtkParametricPseudosphere())

    parametricFunctionSources = list()
    renderers = list()
    mappers = list()
    actors = list()
    textmappers = list()
    textactors = list()

    # Create one text property for all
    textProperty = vtk.vtkTextProperty()
    textProperty.SetFontSize(12)
    textProperty.SetJustificationToCentered()

    backProperty = vtk.vtkProperty()
    backProperty.SetColor(colors.GetColor3d("Tomato"))

    # Create a parametric function source, renderer, mapper, and actor
    # for each object
    for i in range(0, len(parametricObjects)):
        parametricFunctionSources.append(
            vtk.vtkParametricFunctionSource())
        parametricFunctionSources[i].SetParametricFunction(parametricObjects[i])
        parametricFunctionSources[i].Update()

        mappers.append(vtk.vtkPolyDataMapper())
        mappers[i].SetInputConnection(
            parametricFunctionSources[i].GetOutputPort())

        actors.append(vtk.vtkActor())
        actors[i].SetMapper(mappers[i])
        actors[i].GetProperty().SetColor(colors.GetColor3d("Banana"))
        actors[i].GetProperty().SetSpecular(.5)
        actors[i].GetProperty().SetSpecularPower(20)
        actors[i].SetBackfaceProperty(backProperty)

        textmappers.append(vtk.vtkTextMapper())
        textmappers[i].SetInput(parametricObjects[i].GetClassName())
        textmappers[i].SetTextProperty(textProperty)

        textactors.append(vtk.vtkActor2D())
        textactors[i].SetMapper(textmappers[i])
        textactors[i].SetPosition(100, 16)

        renderers.append(vtk.vtkRenderer())
        renderers[i].AddActor(actors[i])
        renderers[i].AddActor(textactors[i])
        renderers[i].SetBackground(colors.GetColor3d("BkgColor"))

    # Setup the viewports
    xGridDimensions = 4
    yGridDimensions = 2
    rendererSize = 200
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName("Parametric Objects Demonstration2")
    renderWindow.SetSize(rendererSize * xGridDimensions,
                         rendererSize * yGridDimensions)
    for row in range(0, yGridDimensions):
        for col in range(0, xGridDimensions):
            index = row * xGridDimensions + col

            # (xmin, ymin, xmax, ymax)
            viewport = [float(col) / xGridDimensions,
                        float(yGridDimensions - (row + 1)) / yGridDimensions,
                        float(col + 1) / xGridDimensions,
                        float(yGridDimensions - row) / yGridDimensions]

            if index > (len(actors) - 1):
                # Add a renderer even if there is no actor.
                # This makes the render window background all the same color.
                ren = vtk.vtkRenderer()
                ren.SetBackground(colors.GetColor3d("BkgColor"))
                ren.SetViewport(viewport)
                renderWindow.AddRenderer(ren)
                continue

            renderers[index].SetViewport(viewport)
            renderers[index].ResetCamera()
            renderers[index].GetActiveCamera().Azimuth(30)
            renderers[index].GetActiveCamera().Elevation(-30)
            renderers[index].GetActiveCamera().Zoom(0.9)
            renderers[index].ResetCameraClippingRange()
            renderWindow.AddRenderer(renderers[index])

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    renderWindow.Render()
    interactor.Start()
Ejemplo n.º 3
0
    def ParametricObjects(self):

        colors = vtk.vtkNamedColors()
        # Set the background color.
        bkg = map(lambda x: x / 256.0, [25, 51, 102])
        colors.SetColor("BkgColor", *bkg)

        parametricObjects = list()
        parametricObjects.append(vtk.vtkParametricBohemianDome())
        parametricObjects[-1].SetA(0.5)
        parametricObjects[-1].SetB(1.0)
        parametricObjects[-1].SetC(2.0)
        parametricObjects.append(vtk.vtkParametricBour())
        parametricObjects.append(vtk.vtkParametricCatalanMinimal())
        parametricObjects.append(vtk.vtkParametricHenneberg())
        parametricObjects.append(vtk.vtkParametricKuen())
        parametricObjects.append(vtk.vtkParametricPluckerConoid())
        parametricObjects.append(vtk.vtkParametricPseudosphere())

        parametricFunctionSources = list()
        renderers = list()
        mappers = list()
        actors = list()
        textmappers = list()
        textactors = list()

        # Create a common text property.
        textProperty = vtk.vtkTextProperty()
        textProperty.SetFontSize(10)
        textProperty.SetJustificationToCentered()

        colors = vtk.vtkNamedColors()
        # Set the background color. Match those in VTKTextbook.pdf.
        bkg = map(lambda x: x / 256.0, [25, 51, 102])
        colors.SetColor("BkgColor", *bkg)

        backProperty = vtk.vtkProperty()
        backProperty.SetColor(colors.GetColor3d("Red"))

        # Create a parametric function source, renderer, mapper
        # and actor for each object.
        for idx, item in enumerate(parametricObjects):
            parametricFunctionSources.append(vtk.vtkParametricFunctionSource())
            parametricFunctionSources[idx].SetParametricFunction(item)
            parametricFunctionSources[idx].Update()

            mappers.append(vtk.vtkPolyDataMapper())
            mappers[idx].SetInputConnection(
                parametricFunctionSources[idx].GetOutputPort())

            actors.append(vtk.vtkActor())
            actors[idx].SetMapper(mappers[idx])
            actors[idx].GetProperty().SetColor(colors.GetColor3d("White"))
            actors[idx].SetBackfaceProperty(backProperty)

            textmappers.append(vtk.vtkTextMapper())
            textmappers[idx].SetInput(item.GetClassName())
            textmappers[idx].SetTextProperty(textProperty)

            textactors.append(vtk.vtkActor2D())
            textactors[idx].SetMapper(textmappers[idx])
            textactors[idx].SetPosition(100, 16)

            renderers.append(vtk.vtkRenderer())

        gridDimensionsX = 4
        gridDimensionsY = 2
        for idx in range(len(parametricObjects),
                         gridDimensionsX * gridDimensionsY):
            renderers.append(vtk.vtkRenderer)

        rendererSize = 200

        # Create the RenderWindow
        renderWindow = vtk.vtkRenderWindow()
        renderWindow.SetSize(rendererSize * gridDimensionsX,
                             rendererSize * gridDimensionsY)

        # Add and position the renders to the render window.
        viewport = list()
        for row in range(gridDimensionsY):
            for col in range(gridDimensionsX):
                idx = row * gridDimensionsX + col
                x0 = float(col) / gridDimensionsX
                y0 = float(gridDimensionsY - row - 1) / gridDimensionsY
                x1 = float(col + 1) / gridDimensionsX
                y1 = float(gridDimensionsY - row) / gridDimensionsY
                viewport[:] = []
                viewport.append(x0)
                viewport.append(y0)
                viewport.append(x1)
                viewport.append(y1)

                if idx > (len(parametricObjects) - 1):
                    continue

                renderWindow.AddRenderer(renderers[idx])
                renderers[idx].SetViewport(viewport)

                renderers[idx].AddActor(actors[idx])
                renderers[idx].AddActor(textactors[idx])
                renderers[idx].SetBackground(colors.GetColor3d("BkgColor"))
                renderers[idx].ResetCamera()
                renderers[idx].GetActiveCamera().Azimuth(30)
                renderers[idx].GetActiveCamera().Elevation(-30)
                renderers[idx].GetActiveCamera().Zoom(0.9)
                renderers[idx].ResetCameraClippingRange()

        interactor = vtk.vtkRenderWindowInteractor()
        interactor.SetRenderWindow(renderWindow)

        renderWindow.Render()

        interactor.Start()
Ejemplo n.º 4
0
def main():
    colors = vtk.vtkNamedColors()

    colors.SetColor("BkgColor", [26, 51, 102, 255])

    surface = vtk.vtkParametricKuen()
    source = vtk.vtkParametricFunctionSource()

    renderer = vtk.vtkRenderer()
    mapper = vtk.vtkPolyDataMapper()
    actor = vtk.vtkActor()

    backProperty = vtk.vtkProperty()
    backProperty.SetColor(colors.GetColor3d("Tomato"))

    # Create a parametric function source, renderer, mapper, and actor
    source.SetParametricFunction(surface)

    mapper.SetInputConnection(source.GetOutputPort())

    actor.SetMapper(mapper)
    actor.SetBackfaceProperty(backProperty)
    actor.GetProperty().SetDiffuseColor(colors.GetColor3d("Banana"))
    actor.GetProperty().SetSpecular(.5)
    actor.GetProperty().SetSpecularPower(20)

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName("Parametric Kuen Demonstration")
    renderWindow.AddRenderer(renderer)
    renderWindow.SetSize(640, 480)

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("BkgColor"))
    renderer.ResetCamera()
    renderer.GetActiveCamera().Azimuth(30)
    renderer.GetActiveCamera().Elevation(-30)
    renderer.GetActiveCamera().Zoom(0.9)
    renderer.ResetCameraClippingRange()

    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    # Setup a slider widget for each varying parameter
    tubeWidth = 0.008
    sliderLength = 0.008
    titleHeight = 0.02
    labelHeight = 0.02

    sliderRepMinimumU = vtk.vtkSliderRepresentation2D()

    sliderRepMinimumU.SetMinimumValue(-4.5)
    sliderRepMinimumU.SetMaximumValue(4.5)
    sliderRepMinimumU.SetValue(-4.5)
    sliderRepMinimumU.SetTitleText("U min")

    sliderRepMinimumU.GetPoint1Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMinimumU.GetPoint1Coordinate().SetValue(.1, .1)
    sliderRepMinimumU.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMinimumU.GetPoint2Coordinate().SetValue(.9, .1)

    sliderRepMinimumU.SetTubeWidth(tubeWidth)
    sliderRepMinimumU.SetSliderLength(sliderLength)
    sliderRepMinimumU.SetTitleHeight(titleHeight)
    sliderRepMinimumU.SetLabelHeight(labelHeight)

    sliderWidgetMinimumU = vtk.vtkSliderWidget()
    sliderWidgetMinimumU.SetInteractor(interactor)
    sliderWidgetMinimumU.SetRepresentation(sliderRepMinimumU)
    sliderWidgetMinimumU.SetAnimationModeToAnimate()
    sliderWidgetMinimumU.EnabledOn()

    sliderWidgetMinimumU.AddObserver('InteractionEvent', SliderCallbackMinimumU(surface))

    sliderRepMaximumU = vtk.vtkSliderRepresentation2D()

    sliderRepMaximumU.SetMinimumValue(-4.5)
    sliderRepMaximumU.SetMaximumValue(4.5)
    sliderRepMaximumU.SetValue(4.5)
    sliderRepMaximumU.SetTitleText("U max")

    sliderRepMaximumU.GetPoint1Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMaximumU.GetPoint1Coordinate().SetValue(.1, .9)
    sliderRepMaximumU.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMaximumU.GetPoint2Coordinate().SetValue(.9, .9)

    sliderRepMaximumU.SetTubeWidth(tubeWidth)
    sliderRepMaximumU.SetSliderLength(sliderLength)
    sliderRepMaximumU.SetTitleHeight(titleHeight)
    sliderRepMaximumU.SetLabelHeight(labelHeight)

    sliderWidgetMaximumU = vtk.vtkSliderWidget()
    sliderWidgetMaximumU.SetInteractor(interactor)
    sliderWidgetMaximumU.SetRepresentation(sliderRepMaximumU)
    sliderWidgetMaximumU.SetAnimationModeToAnimate()
    sliderWidgetMaximumU.EnabledOn()

    sliderWidgetMaximumU.AddObserver('InteractionEvent', SliderCallbackMaximumU(surface))

    sliderRepMinimumV = vtk.vtkSliderRepresentation2D()

    sliderRepMinimumV.SetMinimumValue(0.05)
    sliderRepMinimumV.SetMaximumValue(vtk.vtkMath.Pi())
    sliderRepMinimumV.SetValue(0.0)
    sliderRepMinimumV.SetTitleText("V min")

    sliderRepMinimumV.GetPoint1Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMinimumV.GetPoint1Coordinate().SetValue(.1, .1)
    sliderRepMinimumV.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMinimumV.GetPoint2Coordinate().SetValue(.1, .9)

    sliderRepMinimumV.SetTubeWidth(tubeWidth)
    sliderRepMinimumV.SetSliderLength(sliderLength)
    sliderRepMinimumV.SetTitleHeight(titleHeight)
    sliderRepMinimumV.SetLabelHeight(labelHeight)

    sliderWidgetMinimumV = vtk.vtkSliderWidget()
    sliderWidgetMinimumV.SetInteractor(interactor)
    sliderWidgetMinimumV.SetRepresentation(sliderRepMinimumV)
    sliderWidgetMinimumV.SetAnimationModeToAnimate()
    sliderWidgetMinimumV.EnabledOn()

    sliderWidgetMinimumV.AddObserver(vtk.vtkCommand.InteractionEvent, SliderCallbackMinimumV(surface))

    sliderRepMaximumV = vtk.vtkSliderRepresentation2D()

    sliderRepMaximumV.SetMinimumValue(0.05)
    sliderRepMaximumV.SetMaximumValue(vtk.vtkMath.Pi() - .05)
    sliderRepMaximumV.SetValue(vtk.vtkMath.Pi())
    sliderRepMaximumV.SetTitleText("V max")

    sliderRepMaximumV.GetPoint1Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMaximumV.GetPoint1Coordinate().SetValue(.9, .1)
    sliderRepMaximumV.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay()
    sliderRepMaximumV.GetPoint2Coordinate().SetValue(.9, .9)
    sliderRepMaximumV.SetTubeWidth(tubeWidth)
    sliderRepMaximumV.SetSliderLength(sliderLength)
    sliderRepMaximumV.SetTitleHeight(titleHeight)
    sliderRepMaximumV.SetLabelHeight(labelHeight)

    sliderWidgetMaximumV = vtk.vtkSliderWidget()
    sliderWidgetMaximumV.SetInteractor(interactor)
    sliderWidgetMaximumV.SetRepresentation(sliderRepMaximumV)
    sliderWidgetMaximumV.SetAnimationModeToAnimate()
    sliderWidgetMaximumV.EnabledOn()

    sliderWidgetMaximumV.AddObserver(vtk.vtkCommand.InteractionEvent, SliderCallbackMaximumV(surface))

    surface.SetMinimumU(-4.5)
    surface.SetMaximumU(4.5)
    surface.SetMinimumV(0.05)
    surface.SetMaximumV(vtk.vtkMath.Pi() - .05)

    renderer.ResetCamera()
    renderer.GetActiveCamera().Azimuth(30)
    renderer.GetActiveCamera().Elevation(-30)
    renderer.GetActiveCamera().Zoom(0.9)
    renderer.ResetCameraClippingRange()
    renderWindow.Render()

    interactor.Initialize()

    interactor.Start()
Ejemplo n.º 5
0
    def testMoreParametricFunctions(self):
        # ------------------------------------------------------------
        # For each parametric surface:
        # 1) Create it
        # 2) Assign mappers and actors
        # 3) Position the object
        # 5) Add a label
        # ------------------------------------------------------------

        # ------------------------------------------------------------
        # Create Kuen's Surface.
        # ------------------------------------------------------------
        kuen = vtk.vtkParametricKuen()
        kuenSource = vtk.vtkParametricFunctionSource()
        kuenSource.SetParametricFunction(kuen)
        kuenSource.SetScalarModeToU()

        kuenMapper = vtk.vtkPolyDataMapper()
        kuenMapper.SetInputConnection(kuenSource.GetOutputPort())

        kuenActor = vtk.vtkActor()
        kuenActor.SetMapper(kuenMapper)
        kuenActor.SetPosition(0, -19, 0)
        kuenActor.RotateX(90)

        kuenTextMapper = vtk.vtkTextMapper()
        kuenTextMapper.SetInput("Kuen")
        kuenTextMapper.GetTextProperty().SetJustificationToCentered()
        kuenTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        kuenTextMapper.GetTextProperty().SetColor(1, 0, 0)
        kuenTextMapper.GetTextProperty().SetFontSize(14)
        kuenTextActor = vtk.vtkActor2D()
        kuenTextActor.SetMapper(kuenTextMapper)
        kuenTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        kuenTextActor.GetPositionCoordinate().SetValue(0, -22.5, 0)

        # ------------------------------------------------------------
        # Create a Pseudosphere
        # ------------------------------------------------------------
        pseudo = vtk.vtkParametricPseudosphere()
        pseudo.SetMinimumU(-3)
        pseudo.SetMaximumU(3)
        pseudoSource = vtk.vtkParametricFunctionSource()
        pseudoSource.SetParametricFunction(pseudo)
        pseudoSource.SetScalarModeToY()

        pseudoMapper = vtk.vtkPolyDataMapper()
        pseudoMapper.SetInputConnection(pseudoSource.GetOutputPort())

        pseudoActor = vtk.vtkActor()
        pseudoActor.SetMapper(pseudoMapper)
        pseudoActor.SetPosition(8, -19, 0)
        pseudoActor.RotateX(90)

        pseudoTextMapper = vtk.vtkTextMapper()
        pseudoTextMapper.SetInput("Pseudosphere")
        pseudoTextMapper.GetTextProperty().SetJustificationToCentered()
        pseudoTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        pseudoTextMapper.GetTextProperty().SetColor(1, 0, 0)
        pseudoTextMapper.GetTextProperty().SetFontSize(14)
        pseudoTextActor = vtk.vtkActor2D()
        pseudoTextActor.SetMapper(pseudoTextMapper)
        pseudoTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        pseudoTextActor.GetPositionCoordinate().SetValue(8, -22.5, 0)

        # ------------------------------------------------------------
        # Create a Bohemian Dome
        # ------------------------------------------------------------
        bdome = vtk.vtkParametricBohemianDome()
        bdomeSource = vtk.vtkParametricFunctionSource()
        bdomeSource.SetParametricFunction(bdome)
        bdomeSource.SetScalarModeToU()

        bdomeMapper = vtk.vtkPolyDataMapper()
        bdomeMapper.SetInputConnection(bdomeSource.GetOutputPort())

        bdomeActor = vtk.vtkActor()
        bdomeActor.SetMapper(bdomeMapper)
        bdomeActor.SetPosition(16, -19, 0)
        bdomeActor.RotateY(90)

        bdomeTextMapper = vtk.vtkTextMapper()
        bdomeTextMapper.SetInput("Bohemian Dome")
        bdomeTextMapper.GetTextProperty().SetJustificationToCentered()
        bdomeTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        bdomeTextMapper.GetTextProperty().SetColor(1, 0, 0)
        bdomeTextMapper.GetTextProperty().SetFontSize(14)
        bdomeTextActor = vtk.vtkActor2D()
        bdomeTextActor.SetMapper(bdomeTextMapper)
        bdomeTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        bdomeTextActor.GetPositionCoordinate().SetValue(16, -22.5, 0)

        # ------------------------------------------------------------
        # Create Henneberg's Minimal Surface
        # ------------------------------------------------------------
        hberg = vtk.vtkParametricHenneberg()
        hberg.SetMinimumU(-.3)
        hberg.SetMaximumU(.3)
        hbergSource = vtk.vtkParametricFunctionSource()
        hbergSource.SetParametricFunction(hberg)
        hbergSource.SetScalarModeToV()

        hbergMapper = vtk.vtkPolyDataMapper()
        hbergMapper.SetInputConnection(hbergSource.GetOutputPort())

        hbergActor = vtk.vtkActor()
        hbergActor.SetMapper(hbergMapper)
        hbergActor.SetPosition(24, -19, 0)
        hbergActor.RotateY(90)

        hbergTextMapper = vtk.vtkTextMapper()
        hbergTextMapper.SetInput("Henneberg")
        hbergTextMapper.GetTextProperty().SetJustificationToCentered()
        hbergTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        hbergTextMapper.GetTextProperty().SetColor(1, 0, 0)
        hbergTextMapper.GetTextProperty().SetFontSize(14)
        hbergTextActor = vtk.vtkActor2D()
        hbergTextActor.SetMapper(hbergTextMapper)
        hbergTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        hbergTextActor.GetPositionCoordinate().SetValue(24, -22.5, 0)

        # ------------------------------------------------------------
        # Create Catalan's Minimal Surface
        # ------------------------------------------------------------
        catalan = vtk.vtkParametricCatalanMinimal()
        catalan.SetMinimumU(-2. * math.pi)
        catalan.SetMaximumU(2. * math.pi)
        catalanSource = vtk.vtkParametricFunctionSource()
        catalanSource.SetParametricFunction(catalan)
        catalanSource.SetScalarModeToV()

        catalanMapper = vtk.vtkPolyDataMapper()
        catalanMapper.SetInputConnection(catalanSource.GetOutputPort())

        catalanActor = vtk.vtkActor()
        catalanActor.SetMapper(catalanMapper)
        catalanActor.SetPosition(0, -27, 0)
        catalanActor.SetScale(.5, .5, .5)

        catalanTextMapper = vtk.vtkTextMapper()
        catalanTextMapper.SetInput("Catalan")
        catalanTextMapper.GetTextProperty().SetJustificationToCentered()
        catalanTextMapper.GetTextProperty().SetVerticalJustificationToCentered(
        )
        catalanTextMapper.GetTextProperty().SetColor(1, 0, 0)
        catalanTextMapper.GetTextProperty().SetFontSize(14)
        catalanTextActor = vtk.vtkActor2D()
        catalanTextActor.SetMapper(catalanTextMapper)
        catalanTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        catalanTextActor.GetPositionCoordinate().SetValue(0, -30.5, 0)

        # ------------------------------------------------------------
        # Create Bour's Minimal Surface
        # ------------------------------------------------------------
        bour = vtk.vtkParametricBour()
        bourSource = vtk.vtkParametricFunctionSource()
        bourSource.SetParametricFunction(bour)
        bourSource.SetScalarModeToU()

        bourMapper = vtk.vtkPolyDataMapper()
        bourMapper.SetInputConnection(bourSource.GetOutputPort())

        bourActor = vtk.vtkActor()
        bourActor.SetMapper(bourMapper)
        bourActor.SetPosition(8, -27, 0)

        bourTextMapper = vtk.vtkTextMapper()
        bourTextMapper.SetInput("Bour")
        bourTextMapper.GetTextProperty().SetJustificationToCentered()
        bourTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        bourTextMapper.GetTextProperty().SetColor(1, 0, 0)
        bourTextMapper.GetTextProperty().SetFontSize(14)
        bourTextActor = vtk.vtkActor2D()
        bourTextActor.SetMapper(bourTextMapper)
        bourTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        bourTextActor.GetPositionCoordinate().SetValue(8, -30.5, 0)

        # ------------------------------------------------------------
        # Create Plucker's Conoid Surface
        # ------------------------------------------------------------
        plucker = vtk.vtkParametricPluckerConoid()
        pluckerSource = vtk.vtkParametricFunctionSource()
        pluckerSource.SetParametricFunction(plucker)
        pluckerSource.SetScalarModeToZ()

        pluckerMapper = vtk.vtkPolyDataMapper()
        pluckerMapper.SetInputConnection(pluckerSource.GetOutputPort())

        pluckerActor = vtk.vtkActor()
        pluckerActor.SetMapper(pluckerMapper)
        pluckerActor.SetPosition(16, -27, 0)

        pluckerTextMapper = vtk.vtkTextMapper()
        pluckerTextMapper.SetInput("Plucker")
        pluckerTextMapper.GetTextProperty().SetJustificationToCentered()
        pluckerTextMapper.GetTextProperty().SetVerticalJustificationToCentered(
        )
        pluckerTextMapper.GetTextProperty().SetColor(1, 0, 0)
        pluckerTextMapper.GetTextProperty().SetFontSize(14)
        pluckerTextActor = vtk.vtkActor2D()
        pluckerTextActor.SetMapper(pluckerTextMapper)
        pluckerTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        pluckerTextActor.GetPositionCoordinate().SetValue(16, -30.5, 0)

        # ------------------------------------------------------------
        # Create the RenderWindow, Renderer and all vtkActors
        # ------------------------------------------------------------
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renWin)

        # add actors
        ren.AddViewProp(kuenActor)
        ren.AddViewProp(pseudoActor)
        ren.AddViewProp(bdomeActor)
        ren.AddViewProp(hbergActor)
        ren.AddViewProp(catalanActor)
        ren.AddViewProp(bourActor)
        ren.AddViewProp(pluckerActor)
        #add text actors
        ren.AddViewProp(kuenTextActor)
        ren.AddViewProp(pseudoTextActor)
        ren.AddViewProp(bdomeTextActor)
        ren.AddViewProp(hbergTextActor)
        ren.AddViewProp(catalanTextActor)
        ren.AddViewProp(bourTextActor)
        ren.AddViewProp(pluckerTextActor)

        ren.SetBackground(0.9, 0.9, 0.9)
        renWin.SetSize(500, 500)
        ren.ResetCamera()

        iren.Initialize()
        renWin.Render()

        img_file = "TestMoreParametricFunctions.png"
        vtk.test.Testing.compareImage(
            iren.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=10)
        vtk.test.Testing.interact()
Ejemplo n.º 6
0
    def testMoreParametricFunctions(self):
        # ------------------------------------------------------------
        # For each parametric surface:
        # 1) Create it
        # 2) Assign mappers and actors
        # 3) Position the object
        # 5) Add a label
        # ------------------------------------------------------------

        # ------------------------------------------------------------
        # Create Kuen's Surface.
        # ------------------------------------------------------------
        kuen = vtk.vtkParametricKuen()
        kuenSource = vtk.vtkParametricFunctionSource()
        kuenSource.SetParametricFunction(kuen)
        kuenSource.SetScalarModeToU()

        kuenMapper = vtk.vtkPolyDataMapper()
        kuenMapper.SetInputConnection(kuenSource.GetOutputPort())

        kuenActor = vtk.vtkActor()
        kuenActor.SetMapper(kuenMapper)
        kuenActor.SetPosition(0, -19, 0)
        kuenActor.RotateX(90)

        kuenTextMapper = vtk.vtkTextMapper()
        kuenTextMapper.SetInput("Kuen")
        kuenTextMapper.GetTextProperty().SetJustificationToCentered()
        kuenTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        kuenTextMapper.GetTextProperty().SetColor(1, 0, 0)
        kuenTextMapper.GetTextProperty().SetFontSize(14)
        kuenTextActor = vtk.vtkActor2D()
        kuenTextActor.SetMapper(kuenTextMapper)
        kuenTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        kuenTextActor.GetPositionCoordinate().SetValue(0, -22.5, 0)

        # ------------------------------------------------------------
        # Create a Pseudosphere
        # ------------------------------------------------------------
        pseudo = vtk.vtkParametricPseudosphere()
        pseudo.SetMinimumU(-3)
        pseudo.SetMaximumU(3)
        pseudoSource = vtk.vtkParametricFunctionSource()
        pseudoSource.SetParametricFunction(pseudo)
        pseudoSource.SetScalarModeToY()

        pseudoMapper = vtk.vtkPolyDataMapper()
        pseudoMapper.SetInputConnection(pseudoSource.GetOutputPort())

        pseudoActor = vtk.vtkActor()
        pseudoActor.SetMapper(pseudoMapper)
        pseudoActor.SetPosition(8, -19, 0)
        pseudoActor.RotateX(90)

        pseudoTextMapper = vtk.vtkTextMapper()
        pseudoTextMapper.SetInput("Pseudosphere")
        pseudoTextMapper.GetTextProperty().SetJustificationToCentered()
        pseudoTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        pseudoTextMapper.GetTextProperty().SetColor(1, 0, 0)
        pseudoTextMapper.GetTextProperty().SetFontSize(14)
        pseudoTextActor = vtk.vtkActor2D()
        pseudoTextActor.SetMapper(pseudoTextMapper)
        pseudoTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        pseudoTextActor.GetPositionCoordinate().SetValue(8, -22.5, 0)

        # ------------------------------------------------------------
        # Create a Bohemian Dome
        # ------------------------------------------------------------
        bdome = vtk.vtkParametricBohemianDome()
        bdomeSource = vtk.vtkParametricFunctionSource()
        bdomeSource.SetParametricFunction(bdome)
        bdomeSource.SetScalarModeToU()

        bdomeMapper = vtk.vtkPolyDataMapper()
        bdomeMapper.SetInputConnection(bdomeSource.GetOutputPort())

        bdomeActor = vtk.vtkActor()
        bdomeActor.SetMapper(bdomeMapper)
        bdomeActor.SetPosition(16, -19, 0)
        bdomeActor.RotateY(90)

        bdomeTextMapper = vtk.vtkTextMapper()
        bdomeTextMapper.SetInput("Bohemian Dome")
        bdomeTextMapper.GetTextProperty().SetJustificationToCentered()
        bdomeTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        bdomeTextMapper.GetTextProperty().SetColor(1, 0, 0)
        bdomeTextMapper.GetTextProperty().SetFontSize(14)
        bdomeTextActor = vtk.vtkActor2D()
        bdomeTextActor.SetMapper(bdomeTextMapper)
        bdomeTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        bdomeTextActor.GetPositionCoordinate().SetValue(16, -22.5, 0)

        # ------------------------------------------------------------
        # Create Henneberg's Minimal Surface
        # ------------------------------------------------------------
        hberg = vtk.vtkParametricHenneberg()
        hberg.SetMinimumU(-0.3)
        hberg.SetMaximumU(0.3)
        hbergSource = vtk.vtkParametricFunctionSource()
        hbergSource.SetParametricFunction(hberg)
        hbergSource.SetScalarModeToV()

        hbergMapper = vtk.vtkPolyDataMapper()
        hbergMapper.SetInputConnection(hbergSource.GetOutputPort())

        hbergActor = vtk.vtkActor()
        hbergActor.SetMapper(hbergMapper)
        hbergActor.SetPosition(24, -19, 0)
        hbergActor.RotateY(90)

        hbergTextMapper = vtk.vtkTextMapper()
        hbergTextMapper.SetInput("Henneberg")
        hbergTextMapper.GetTextProperty().SetJustificationToCentered()
        hbergTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        hbergTextMapper.GetTextProperty().SetColor(1, 0, 0)
        hbergTextMapper.GetTextProperty().SetFontSize(14)
        hbergTextActor = vtk.vtkActor2D()
        hbergTextActor.SetMapper(hbergTextMapper)
        hbergTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        hbergTextActor.GetPositionCoordinate().SetValue(24, -22.5, 0)

        # ------------------------------------------------------------
        # Create Catalan's Minimal Surface
        # ------------------------------------------------------------
        catalan = vtk.vtkParametricCatalanMinimal()
        catalan.SetMinimumU(-2.0 * math.pi)
        catalan.SetMaximumU(2.0 * math.pi)
        catalanSource = vtk.vtkParametricFunctionSource()
        catalanSource.SetParametricFunction(catalan)
        catalanSource.SetScalarModeToV()

        catalanMapper = vtk.vtkPolyDataMapper()
        catalanMapper.SetInputConnection(catalanSource.GetOutputPort())

        catalanActor = vtk.vtkActor()
        catalanActor.SetMapper(catalanMapper)
        catalanActor.SetPosition(0, -27, 0)
        catalanActor.SetScale(0.5, 0.5, 0.5)

        catalanTextMapper = vtk.vtkTextMapper()
        catalanTextMapper.SetInput("Catalan")
        catalanTextMapper.GetTextProperty().SetJustificationToCentered()
        catalanTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        catalanTextMapper.GetTextProperty().SetColor(1, 0, 0)
        catalanTextMapper.GetTextProperty().SetFontSize(14)
        catalanTextActor = vtk.vtkActor2D()
        catalanTextActor.SetMapper(catalanTextMapper)
        catalanTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        catalanTextActor.GetPositionCoordinate().SetValue(0, -30.5, 0)

        # ------------------------------------------------------------
        # Create Bour's Minimal Surface
        # ------------------------------------------------------------
        bour = vtk.vtkParametricBour()
        bourSource = vtk.vtkParametricFunctionSource()
        bourSource.SetParametricFunction(bour)
        bourSource.SetScalarModeToU()

        bourMapper = vtk.vtkPolyDataMapper()
        bourMapper.SetInputConnection(bourSource.GetOutputPort())

        bourActor = vtk.vtkActor()
        bourActor.SetMapper(bourMapper)
        bourActor.SetPosition(8, -27, 0)

        bourTextMapper = vtk.vtkTextMapper()
        bourTextMapper.SetInput("Bour")
        bourTextMapper.GetTextProperty().SetJustificationToCentered()
        bourTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        bourTextMapper.GetTextProperty().SetColor(1, 0, 0)
        bourTextMapper.GetTextProperty().SetFontSize(14)
        bourTextActor = vtk.vtkActor2D()
        bourTextActor.SetMapper(bourTextMapper)
        bourTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        bourTextActor.GetPositionCoordinate().SetValue(8, -30.5, 0)

        # ------------------------------------------------------------
        # Create Plucker's Conoid Surface
        # ------------------------------------------------------------
        plucker = vtk.vtkParametricPluckerConoid()
        pluckerSource = vtk.vtkParametricFunctionSource()
        pluckerSource.SetParametricFunction(plucker)
        pluckerSource.SetScalarModeToZ()

        pluckerMapper = vtk.vtkPolyDataMapper()
        pluckerMapper.SetInputConnection(pluckerSource.GetOutputPort())

        pluckerActor = vtk.vtkActor()
        pluckerActor.SetMapper(pluckerMapper)
        pluckerActor.SetPosition(16, -27, 0)

        pluckerTextMapper = vtk.vtkTextMapper()
        pluckerTextMapper.SetInput("Plucker")
        pluckerTextMapper.GetTextProperty().SetJustificationToCentered()
        pluckerTextMapper.GetTextProperty().SetVerticalJustificationToCentered()
        pluckerTextMapper.GetTextProperty().SetColor(1, 0, 0)
        pluckerTextMapper.GetTextProperty().SetFontSize(14)
        pluckerTextActor = vtk.vtkActor2D()
        pluckerTextActor.SetMapper(pluckerTextMapper)
        pluckerTextActor.GetPositionCoordinate().SetCoordinateSystemToWorld()
        pluckerTextActor.GetPositionCoordinate().SetValue(16, -30.5, 0)

        # ------------------------------------------------------------
        # Create the RenderWindow, Renderer and all vtkActors
        # ------------------------------------------------------------
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(ren)
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renWin)

        # add actors
        ren.AddViewProp(kuenActor)
        ren.AddViewProp(pseudoActor)
        ren.AddViewProp(bdomeActor)
        ren.AddViewProp(hbergActor)
        ren.AddViewProp(catalanActor)
        ren.AddViewProp(bourActor)
        ren.AddViewProp(pluckerActor)
        # add text actors
        ren.AddViewProp(kuenTextActor)
        ren.AddViewProp(pseudoTextActor)
        ren.AddViewProp(bdomeTextActor)
        ren.AddViewProp(hbergTextActor)
        ren.AddViewProp(catalanTextActor)
        ren.AddViewProp(bourTextActor)
        ren.AddViewProp(pluckerTextActor)

        ren.SetBackground(0.9, 0.9, 0.9)
        renWin.SetSize(500, 500)
        ren.ResetCamera()

        iren.Initialize()
        renWin.Render()

        img_file = "TestMoreParametricFunctions.png"
        vtk.test.Testing.compareImage(iren.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=10)
        vtk.test.Testing.interact()
Ejemplo n.º 7
0
    TA3.SetInput(func.GetClassName().replace('vtkParametric', ''))
    TA3.GetTextProperty().SetFontSize(20)
    TA3.SetScale(.02)
    TA3.SetPosition(pos[0], pos[1] - 2, pos[2] + .1)
    R.AddActor(TA3)
    return A


lst = [
    vtk.vtkParametricBoy(),
    vtk.vtkParametricConicSpiral(),
    vtk.vtkParametricCrossCap(),
    vtk.vtkParametricDini(),
    vtk.vtkParametricFigure8Klein(),
    vtk.vtkParametricKlein(),
    vtk.vtkParametricKuen(),
    vtk.vtkParametricMobius(),
    vtk.vtkParametricPseudosphere(),
    vtk.vtkParametricRoman(),
    #vtk.vtkParametricCatalanMinimal(),
    #vtk.vtkParametricEllipsoid(),
    #vtk.vtkParametricEnneper(),
    #vtk.vtkParametricHenneberg(),
    #vtk.vtkParametricPluckerConoid(),
    #vtk.vtkParametricRandomHills(),
    #vtk.vtkParametricSpline(),
    #vtk.vtkParametricSuperEllipsoid(),
    #vtk.vtkParametricSuperToroid(),
    #vtk.vtkParametricTorus(),
]
Ejemplo n.º 8
0
def get_parametric_functions():
    """
    Create a map of the parametric functions and set some parameters.
    The first key groups the parametric functions and the
      second key is the name of the function.

    :return: The map of functions.
    """
    # We could use OrderedDict if Python version >= 3.2
    pfn = collections.defaultdict(collections.defaultdict)
    pfn[0]['Boy'] = vtk.vtkParametricBoy()
    pfn[0]['ConicSpiral'] = vtk.vtkParametricConicSpiral()
    pfn[0]['CrossCap'] = vtk.vtkParametricCrossCap()
    pfn[0]['Dini'] = vtk.vtkParametricDini()
    pfn[0]['Ellipsoid'] = vtk.vtkParametricEllipsoid()
    pfn[0]['Enneper'] = vtk.vtkParametricEnneper()
    pfn[0]['Figure8Klein'] = vtk.vtkParametricFigure8Klein()
    pfn[0]['Klein'] = vtk.vtkParametricKlein()
    pfn[0]['Mobius'] = vtk.vtkParametricMobius()
    pfn[0]['RandomHills'] = vtk.vtkParametricRandomHills()
    pfn[0]['Roman'] = vtk.vtkParametricRoman()
    pfn[0]['SuperEllipsoid'] = vtk.vtkParametricSuperEllipsoid()
    pfn[0]['SuperToroid'] = vtk.vtkParametricSuperToroid()
    pfn[0]['Torus'] = vtk.vtkParametricTorus()
    pfn[0]['Spline'] = vtk.vtkParametricSpline()
    # Extra parametric surfaces.
    pfn[1]['BohemianDome'] = vtk.vtkParametricBohemianDome()
    pfn[1]['Bour'] = vtk.vtkParametricBour()
    pfn[1]['CatalanMinimal'] = vtk.vtkParametricCatalanMinimal()
    pfn[1]['Henneberg'] = vtk.vtkParametricHenneberg()
    pfn[1]['Kuen'] = vtk.vtkParametricKuen()
    pfn[1]['PluckerConoid'] = vtk.vtkParametricPluckerConoid()
    pfn[1]['Pseudosphere'] = vtk.vtkParametricPseudosphere()
    # Now set some parameters.
    pfn[0]["Ellipsoid"].SetXRadius(0.5)
    pfn[0]["Ellipsoid"].SetYRadius(2.0)
    pfn[0]["Mobius"].SetRadius(2.0)
    pfn[0]["Mobius"].SetMinimumV(-0.5)
    pfn[0]["Mobius"].SetMaximumV(0.5)
    pfn[0]["RandomHills"].AllowRandomGenerationOn()
    pfn[0]["RandomHills"].SetRandomSeed(1)
    pfn[0]["RandomHills"].SetNumberOfHills(30)
    pfn[0]["SuperEllipsoid"].SetN1(0.5)
    pfn[0]["SuperEllipsoid"].SetN2(0.4)
    pfn[0]["SuperToroid"].SetN1(0.5)
    pfn[0]["SuperToroid"].SetN2(3.0)
    # The spline needs points
    inputPoints = vtk.vtkPoints()
    rng = vtk.vtkMinimalStandardRandomSequence()
    rng.SetSeed(8775070)
    for p in range(0, 10):
        xyz = [None] * 3
        for idx in range(0, len(xyz)):
            xyz[idx] = rng.GetRangeValue(-1.0, 1.0)
            rng.Next()
        inputPoints.InsertNextPoint(xyz)

    pfn[0]["Spline"].SetPoints(inputPoints)
    # Extra parametric surfaces.
    pfn[1]["BohemianDome"].SetA(5.0)
    pfn[1]["BohemianDome"].SetB(1.0)
    pfn[1]["BohemianDome"].SetC(2.0)
    pfn[1]["Kuen"].SetDeltaV0(0.001)

    return pfn