
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "../../docs/source/_gallery/example_pointcloud_simple_workflow.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_.._.._docs_source__gallery_example_pointcloud_simple_workflow.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_.._.._docs_source__gallery_example_pointcloud_simple_workflow.py:


.. _example_pointcloud_simple_workflow:

Simple point cloud workflow 
=====================================

.. contents:: Table of Contents
   :local:
   :depth: 2
   :backlinks: top

This example demonstrates a simple workflow for creating, manipulating,
and visualizing a point cloud using the ``pysdic`` library.

.. seealso::

    :class:`pysdic.PointCloud` - Official documentation for the PointCloud class.

.. GENERATED FROM PYTHON SOURCE LINES 22-29

Creating a Point Cloud
---------------------------

To create a point cloud, we first need to give the coordinates of the points.

Additionally some convenience methods are provided to save and load point clouds
from files.

.. GENERATED FROM PYTHON SOURCE LINES 29-40

.. code-block:: Python


    import numpy
    from pysdic import PointCloud

    # Define coordinates for the point cloud
    coords = numpy.random.rand(100, 3)  # 100 points in 3D space [0, 1)

    # Create the point cloud
    point_cloud = PointCloud.from_array(coords)
    print(point_cloud)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    PointCloud(n_points=100, n_dimensions=3)




.. GENERATED FROM PYTHON SOURCE LINES 41-48

Add some point properties
---------------------------
We can add properties to the points in the point cloud. Here, we add a random scalar property
to each point.

Each property can be multi-dimensional, e.g., a vector or tensor associated with each point.
All the properties are stored in a dictionary-like structure with shape :math:`(N_p, A)`.

.. GENERATED FROM PYTHON SOURCE LINES 48-56

.. code-block:: Python


    point_properties = numpy.random.rand(100)  # Random scalar property for each point
    point_cloud.set_property("intensity", point_properties)

    multi_dim_property = numpy.random.rand(100, 2)  # Random 2D property for each point
    point_cloud.set_property("vector_property", multi_dim_property)
    print(point_cloud)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    PointCloud(n_points=100, n_dimensions=3)
      - Property: 'intensity' with shape (100, 1)
      - Property: 'vector_property' with shape (100, 2)




.. GENERATED FROM PYTHON SOURCE LINES 57-65

Filter some points 
---------------------------

We can filter points based on certain criteria. Here, we keep only the points
with an intensity greater than 0.5.

The `inplace` parameter can be used to modify the existing point cloud instead of creating a new one.


.. GENERATED FROM PYTHON SOURCE LINES 65-71

.. code-block:: Python


    # Note that get_property returns a (N, 1) array for scalar properties, so we reshape it to (N,) for comparison
    mask = point_cloud.get_property("intensity").reshape(-1) > 0.5
    new_point_cloud = point_cloud.filter_points(mask)
    print(new_point_cloud)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    PointCloud(n_points=59, n_dimensions=3)
      - Property: 'intensity' with shape (59, 1)
      - Property: 'vector_property' with shape (59, 2)




.. GENERATED FROM PYTHON SOURCE LINES 72-81

Visualize the Point Cloud
---------------------------

The point cloud can be visualized using the built-in visualization method with ``pyvista``.

.. seealso::

   :meth:`pysdic.PointCloud.visualize` - Official documentation for the visualize method.


.. GENERATED FROM PYTHON SOURCE LINES 81-89

.. code-block:: Python


    point_cloud.visualize(
        title="Example Point Cloud", 
        point_size=10,
        property="intensity", 
        bounds_grid="back",
        property_cmap="inferno",
        property_clim=(0.5, 1),
    )


.. image-sg:: /_gallery/images/sphx_glr_example_pointcloud_simple_workflow_001.png
   :alt: example pointcloud simple workflow
   :srcset: /_gallery/images/sphx_glr_example_pointcloud_simple_workflow_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.288 seconds)


.. _sphx_glr_download_.._.._docs_source__gallery_example_pointcloud_simple_workflow.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: example_pointcloud_simple_workflow.ipynb <example_pointcloud_simple_workflow.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: example_pointcloud_simple_workflow.py <example_pointcloud_simple_workflow.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: example_pointcloud_simple_workflow.zip <example_pointcloud_simple_workflow.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
