-
Notifications
You must be signed in to change notification settings - Fork 2
doc: Add extended migration guide #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
12de712
doc: Add extended migration guide
AlejandroFernandezLuces 97810f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7e30b78
chore: adding changelog file 363.miscellaneous.md [dependabot-skip]
pyansys-ci-bot 77d8d27
fix: Pre-commit
AlejandroFernandezLuces 1ca7134
Merge branch 'doc/migration-guide' of https://github.com/ansys/ansys-…
AlejandroFernandezLuces 932b41c
fix: Vale
AlejandroFernandezLuces b7a3846
fix: Vale warnings
AlejandroFernandezLuces 4eca2b4
fix: Vale warnings
AlejandroFernandezLuces 2975177
Merge branch 'main' into doc/migration-guide
AlejandroFernandezLuces 4a91e01
Merge branch 'main' into doc/migration-guide
AlejandroFernandezLuces 9be5646
Merge branch 'main' into doc/migration-guide
AlejandroFernandezLuces 8005b38
Merge branch 'main' into doc/migration-guide
AlejandroFernandezLuces bfa6f50
Merge branch 'main' into doc/migration-guide
AlejandroFernandezLuces bf17548
Apply suggestions from code review
AlejandroFernandezLuces 69b025f
Merge branch 'main' into doc/migration-guide
AlejandroFernandezLuces 6d30c70
fix: Doc review suggestions
AlejandroFernandezLuces 2a61348
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0963bd4
fix: Vale
AlejandroFernandezLuces 1ab170c
Merge branch 'doc/migration-guide' of https://github.com/ansys/ansys-…
AlejandroFernandezLuces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Doc: Add extended migration guide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AlejandroFernandezLuces marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| .. _ref_migration_guide: | ||
|
|
||
| Migration | ||
| ######### | ||
|
|
||
| In this section two guides are provided to help you migrate from PyVista plotters to the Ansys Tools Visualization Interface plotters. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The first one addresses code migration, and the second one addresses documentation migration. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Code migration guide | ||
| ==================== | ||
|
|
||
| This guide intends to help users transition from PyVista plotters to the new Ansys Tools Visualization Interface plotters. Since cases are very different | ||
| from each other, a few examples are provided to cover the most common scenarios. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| From simple PyVista mesh plotting to the Ansys visualization interface plotter | ||
| ------------------------------------------------------------------------------ | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| If you only need to plot simple PyVista meshes, you can directly replace your PyVista plotter code with the Ansys Tools Visualization Interface plotter code. | ||
| On top of common PyVista functionalities, the Ansys Tools Visualization Interface plotter provides additional interactivity such as view buttons, mesh slicing, etc. | ||
| Here is an example of how to do this: | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - PyVista code: | ||
|
|
||
| .. code-block:: python | ||
| import pyvista as pv | ||
| # Create a pyvista mesh | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mesh = pv.Cube() | ||
| # Create a plotter | ||
| pl = pv.Plotter() | ||
| # Add the mesh to the plotter | ||
| pl.add_mesh(mesh) | ||
| # Show the plotter | ||
| pl.show() | ||
| - Ansys Tools Visualization Interface code: | ||
|
|
||
| .. code-block:: python | ||
| import pyvista as pv | ||
| from ansys.tools.visualization_interface import Plotter | ||
| # Create a pyvista mesh | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mesh = pv.Cube() | ||
| # Create a plotter | ||
| pl = Plotter() | ||
| # Add the mesh to the plotter | ||
| pl.plot(mesh) | ||
| # Show the plotter | ||
| pl.show() | ||
| Convert your custom meshes to MeshObjectPlot and use the Ansys visualization interface plotter | ||
| ---------------------------------------------------------------------------------------------- | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Your custom object must have a method that returns a PyVista mesh and a method that exposes a ``name`` or ``id`` attribute of your object. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| .. code-block:: python | ||
| class CustomObject: | ||
| def __init__(self): | ||
| self.name = "CustomObject" | ||
| self.mesh = pv.Cube(center=(1, 1, 0)) | ||
| def get_mesh(self): | ||
| return self.mesh | ||
| def name(self): | ||
| return self.name | ||
| Then you need to create a ``MeshObjectPlot`` instance that relates the PyVista mesh with your custom object. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| .. code-block:: python | ||
| from ansys.tools.visualization_interface import MeshObjectPlot | ||
| custom_object = CustomObject() | ||
| mesh_object_plot = MeshObjectPlot( | ||
| custom_object=custom_object, | ||
| mesh=custom_object.get_mesh(), | ||
| ) | ||
| With this, you can use the Ansys Tools Visualization Interface plotter to visualize your custom object. It enables interactivity such as picking and hovering. | ||
|
|
||
|
|
||
| Customizing the PyVista backend | ||
| ------------------------------- | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You can customize the backend of the Ansys Tools Visualization Interface plotter to enable or turn off certain functionalities. For example, | ||
| if you want to enable picking, you can do it as follows: | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| .. code-block:: python | ||
| from ansys.tools.visualization_interface import Plotter | ||
| from ansys.tools.visualization_interface.backends import PyVistaBackend | ||
| backend = PyVistaBackend(allow_picking=True) | ||
| # Create a plotter | ||
| pl = Plotter(backend=backend) | ||
| # Add the MeshObjectPlot instance to the plotter | ||
| pl.plot(mesh_object_plot) | ||
| # Show the plotter | ||
| pl.show() | ||
| If you want to go further and customize the backend even more, you can create your own backend by inheriting from the ``PyVistaBackendInterface`` class | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| and implementing the required methods. You can find more information about this in the backend documentation: | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| .. code-block:: python | ||
| @abstractmethod | ||
| def plot_iter(self, plottable_object: Any, name_filter: str = None, **plotting_options): | ||
| """Plot one or more compatible objects to the plotter. | ||
| Parameters | ||
| ---------- | ||
| plottable_object : Any | ||
| One or more objects to add. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name_filter : str, default: None. | ||
| Regular expression with the desired name or names to include in the plotter. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| **plotting_options : dict, default: None | ||
| Keyword arguments. For allowable keyword arguments, see the | ||
| :meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method. | ||
| """ | ||
| pass | ||
| @abstractmethod | ||
| def plot(self, plottable_object: Any, name_filter: str = None, **plotting_options): | ||
| """Plot a single object to the plotter. | ||
| Parameters | ||
| ---------- | ||
| plottable_object : Any | ||
| Object to add. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name_filter : str | ||
| Regular expression with the desired name or names to include in the plotter. | ||
| **plotting_options : dict, default: None | ||
| Keyword arguments. For allowable keyword arguments, see the | ||
| :meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method. | ||
| """ | ||
| pass | ||
| The rest of the methods are implemented for you. This ensures that while you can customize what you need for plotting, the rest of the functionalities still work as expected. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| If you need to even go further, you can also create your own plotter by inheriting from the ``BaseBackend`` class and implementing the required methods, | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| although this may break existing features. You can find more information about this in the plotter documentation. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Customize the picker or hover behavior | ||
| -------------------------------------- | ||
| You can customize the picker of the Ansys Tools Visualization Interface plotter to decide what happens when an object is picked or hovered. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| For example, if you want to print the name of the picked object, you can do it as described in the custom picker example. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Using PyVista Qt backend | ||
| ------------------------ | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| You can use the PyVista Qt backend with the Ansys Tools Visualization Interface plotter. To do this, you need to set the PyVista backend to Qt | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| before creating the plotter. Here is an example of how to do this: | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| .. code-block:: python | ||
| cube = pv.Cube() | ||
| pv_backend = PyVistaBackend(use_qt=True, show_qt=True) | ||
| pl = Plotter(backend=pv_backend) | ||
| pl.plot(cube) | ||
| pl.backend.enable_widgets() | ||
| pv_backend.scene.show() | ||
| With this, you can integrate the plotter into a PyQt or PySide app by disabling ``show_qt`` parameter. | ||
| You can find more information about this in the `PyVista documentation <https://qtdocs.pyvista.org/>`_. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| Documentation migration guide | ||
| ============================= | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This guide is intended to help users transition from PyVista documentation configuration to the new Ansys Tools Visualization Interface documentation configuration. | ||
AlejandroFernandezLuces marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 1. Add environment variables for documentation: | ||
|
|
||
| .. code-block:: python | ||
| os.environ["PYANSYS_VISUALIZER_DOC_MODE"] = "true" | ||
| os.environ["PYANSYS_VISUALIZER_HTML_BACKEND"] = "true" | ||
| 2. Use PyVista DynamicScraper: | ||
|
|
||
| .. code-block:: python | ||
| from pyvista.plotting.utilities.sphinx_gallery import DynamicScraper | ||
| sphinx_gallery_conf = { | ||
| "image_scrapers": (DynamicScraper()), | ||
| } | ||
| 3. Add PyVista viewer directive to extensions: | ||
|
|
||
| .. code-block:: python | ||
| extensions = ["pyvista.ext.viewer_directive"] | ||
| 4. Make sure you are executing the notebook cells: | ||
|
|
||
| .. code-block:: python | ||
| nbsphinx_execute = "always" | ||
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.