Skip to content
Snippets Groups Projects
Commit 2e9e7984 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Updating PipelineReuse

parent f01eaace
No related branches found
No related tags found
Loading
Pipeline #390024 canceled
......@@ -70,6 +70,7 @@ This Python script, [SelectExamples](../Python/Utilities/SelectExamples), will l
| Example Name | Description | Image |
| -------------- | ------------- | ------- |
[GeometricObjectsDemo](/PythonicAPI/GeometricObjects/GeometricObjectsDemo) |
[PipelineReuse](/PythonicAPI/GeometricObjects/PipelineReuse) | How to reuse a pipeline.
[SourceObjectsDemo](/PythonicAPI/GeometricObjects/SourceObjectsDemo) | Examples of source objects that procedurally generate polygonal models. These nine images represent just some of the capability of VTK. From upper left in reading order: sphere, cone, cylinder, cube, plane, text, random point cloud, disk (with or without hole), and line source. Other polygonal source objects are available; check subclasses of vtkPolyDataAlgorithm.
### Cells
......
......@@ -6,67 +6,46 @@ import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersCore import (
vtkAppendPolyData,
vtkElevationFilter,
vtkPolyDataNormals,
)
from vtkmodules.vtkFiltersSources import (
vtkConeSource,
vtkCylinderSource
vtkCylinderSource,
)
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
def main():
colors = vtkNamedColors()
# extraction_mode = {'point_seeded_regions': 1, 'cell_seeded_regions': 2, 'specified_regions': 3, 'largest_region': 4,
# 'all_regions': 5, 'closest_point_region': 6}
# pipeline = (
# vtkElevationFilter()
# >> vtkShrinkFilter()
# >> vtkGeometryFilter()
# >> vtkPolyDataConnectivityFilter(color_regions=True, extraction_mode=extraction_mode['all_regions'])
# >> vtkPolyDataNormals()
# )
p1 = (
vtkElevationFilter(low_point=(0, -2, 2), high_point=(0, 3, 2))
p = (
vtkElevationFilter(low_point=(0, -2.5, 0), high_point=(0, 3.5, 0))
>> vtkPolyDataNormals()
)
p2 = (
vtkElevationFilter(low_point=(0, -2, 2), high_point=(0, 3, 2))
>> vtkPolyDataNormals()
)
cone = vtkConeSource(radius=5, resolution=8, height=2, direction=(0, 1, 0), center=(0, 1.5001, 0))
cone_mapper = vtkPolyDataMapper()
cone_actor = vtkActor(mapper=cone_mapper)
cone = vtkConeSource(radius=5, resolution=8, height=3, direction=(0, 1, 0), center=(0, 2.0, 0))
cylinder = vtkCylinderSource(radius=6, resolution=9, height=3, center=(0, -1, 0))
cylinder_mapper = vtkPolyDataMapper()
cylinder_actor = vtkActor(mapper=cylinder_mapper)
# This works since p1 and p2 are separate pipelines.
cone >> p1 >> cone_mapper
cylinder >> p2 >> cylinder_mapper
append = vtkAppendPolyData()
mapper = vtkPolyDataMapper()
actor = vtkActor(mapper=mapper)
# Only the cylinder is mapped because whilst p1 is assigned to p2, it is, in fact, p1.
# p2 = p1
# Will not work because update() is the same as update().output.
# p2 = p1.update()
# AttributeError: 'Pipeline' object has no attribute 'DeepCopy'
# p2 = p1.DeepCopy()
#
# cylinder >> p2 >> cylinder_mapper
# Here we use the pipeline in a functional way. This allows us to reuse the pipeline.
# p(cone()) returns a data object detached from the pipeline so any changes to the pipeline
# afterward would not be automatically propagated to the rendering pipeline.
# Finally, we use an append filter to combine the cone and cylinder.
(p(cone()), p(cylinder())) >> append >> mapper
ren = vtkRenderer(background=colors.GetColor3d('DimGray'))
ren.AddActor(cone_actor)
ren.AddActor(cylinder_actor)
ren.AddActor(actor)
ren_win = vtkRenderWindow(size=[600, 600], window_name='PipelineReuse')
ren_win.AddRenderer(ren)
......
......@@ -104,3 +104,22 @@ Sometimes we need to update part of a pipeline so that output can be used in oth
| -------------- | ---------------------- | ------- |
[LineOnMesh](/PythonicAPI/DataManipulation/LineOnMesh) | One pipeline creates a smoothed dataset. However we need to update `smooth_loop` in the pipeline so that `?vtkCellLocator?` finds cells in order to create the spline.
[MeshLabelImageColor](/PythonicAPI/DataManipulation/MeshLabelImageColor) | We need the smoother error for the scalar range in the mapper. So we create the pipeline and update `smoother` to get the needed scalar range. Of course, all other pipeline elements feeding into `smoother` will be updated also.
## Reusing a pipeline
Pipelines can be reused.
``` Python
# The pipeline to reuse.
p = (a >> b >> c)
# Sources for the pipeline.
s1 = d
s2 = e
# Use the pipeline in a functional way.
p1 = p(s1())
p2 = p(ss())
```
| Example Name | Comments | Image |
| -------------- | ---------------------- | ------- |
[PipelineReuse](/PythonicAPI/GeometricObjects/PipelineReuse) | Here we use the pipeline in a functional way. This allows us to reuse the pipeline, here, p(cone()) returns a data object so any changes to the pipeline afterward would not be automatically propagated to the rendering pipeline. Finally, we use an append filter to combine the cone and cylinder.
src/Testing/Baseline/PythonicAPI/GeometricObjects/TestScreenshotCallback.png

130 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment