{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# PointCloudNode\n", "The PointCloudNode class in Geomapi represents the data and metadata of point cloud data. The data itself and methods build upon Open3D PointCloud concepts while the metadata builds upon the RDFlib framework:\n", "\n", "[http://www.open3d.org/docs/release/python_api/open3d.geometry.PointCloud.html](http://www.open3d.org/docs/release/python_api/open3d.geometry.PointCloud.html)\n", "\n", "[https://rdflib.readthedocs.io/](https://rdflib.readthedocs.io/)\n", "\n", "The code below shows how to create a PointCloudNode from various inputs. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First the geomapi and external packages are imported" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Jupyter environment detected. Enabling Open3D WebVisualizer.\n", "[Open3D INFO] WebRTC GUI backend enabled.\n", "[Open3D INFO] WebRTCWindowSystem: HTTP handshake server disabled.\n" ] } ], "source": [ "#IMPORT PACKAGES\n", "from rdflib import Graph\n", "import os\n", "import numpy as np\n", "\n", "#IMPORT MODULES\n", "from context import geomapi #context import for documentation only\n", "from geomapi.nodes import PointCloudNode" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PointCloudNode Creation\n", "\n", "A PointCloudNode is constructed using the same parameters as the base Node. Please refer to [Node Tutorial](../tutorial/tutorial_nodes.ipynb) For more info about Node Creation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "PointCloudNode( subject = None, # (URIRef, optional) : A subject to use as identifier for the Node.\n", " graph = None, # (Graph, optional) : An RDF Graph to parse.\n", " graphPath = None, # (Path, optional) : The path of an RDF Graph to parse.\n", " name = None, # (str, optional) : A name of the Node.\n", " path = None, # (Path, optional) : A filepath to a resource.\n", " timestamp = None, # (str, optional) : Timestamp for the node.\n", " resource = None, # (optional) : Resource associated with the node.\n", " cartesianTransform = None, # (np.ndarray, optional) : The (4x4) transformation matrix.\n", " orientedBoundingBox = None, # (o3d.geometry.OrientedBoundingBox, optional) : The oriented bounding box of the node.\n", " convexHull = None, # (o3d.geometry.TrianglePointCloud, optional) : The convex hull of the node.\n", " loadResource = False, # Load the resource at initialization?\n", " e57Index = None # (int, optional) : index of the scan you want to import from an e57 file. Defaults to 0.\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Ontology link\n", "\n", "The PointCloudNode has 1 new standard propertie that are serialized to the graph:\n", "\n", "| python name | predicate |\n", "|----------- |-----------|\n", "| `pointCount` | `geomapi:pointCount` |\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creation From E57 file\n", "Since E57 files contain a large amount of elements, they cannot be loaded directly into a PointCloudNode.\n", "Use the [`geomapi.tools.e57_to_pointcloud_nodes`](../geomapi/geomapi.tools.html#geomapi.tools.e57_to_pointcloud_nodes) function to load all elements into a list of PointCloudNodes." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PointCount cannot be set directly when a resource is present\n", "PointCount cannot be set directly when a resource is present\n", "2\n" ] } ], "source": [ "import geomapi.tools as tl\n", "\n", "PointCloudnodes = tl.e57_to_pointcloud_nodes(e57Path = r\"../../..\\tests\\testfiles\\pcd\\lidar.e57\", loadResource = True)\n", "print(len(PointCloudnodes))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creation From E57 xml file\n", "Since xml files contain a large amount of elements, they cannot be loaded directly into a PointCloudNode.\n", "Use the [`geomapi.tools.e57xml_to_pointcloud_nodes`](../geomapi/geomapi.tools.html#geomapi.tools.e57xml_to_pointcloud_nodes) function to load all elements into a list of PointCloudNodes." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "PointCount cannot be set directly when a resource is present\n", "PointCount cannot be set directly when a resource is present\n", "2\n" ] } ], "source": [ "import geomapi.tools as tl\n", "\n", "PointCloudnodes = tl.e57xml_to_pointcloud_nodes(xmlPath = r\"../../..\\tests\\testfiles\\pcd\\lidar.xml\", loadResource = True)\n", "print(len(PointCloudnodes))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PointCloudNode Resource\n", "\n", "When creating a PointCloudNode with a resource, it can be done either directly with the resource, or with the path to the resource. The resource can be a `o3d.geometry.TriangleMesh`, `trimesh.base.Trimesh` or an `ifcopenshell.entity_instance`. The resource is always converted to a `o3d.geometry.TriangleMesh`\n", "\n", "A resource can be a big piece of data, this is why it is not always wanted to load the whole resource at initialization. This is why the `loadResource` parameter is default to `False`\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Loading The Resource" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Resource not loaded, but path is defined, call `load_resource()` to access it.\n", "Resource not loaded, but path is defined, call `load_resource()` to access it.\n", "resource before loading: None\n", "resource after loading: PointCloud with 556485 points.\n" ] } ], "source": [ "node = PointCloudNode(path=r\"../../..\\tests\\testfiles\\pcd\\parking.pcd\", loadResource=False)\n", "print(\"resource before loading:\",node.resource)\n", "node.load_resource() # Use specialized node fo each type of resource.\n", "print(\"resource after loading:\",node.resource)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Saving The Resource\n", "\n", "A PointCloud resource can be saved to disk using the `save_resource()` function.\n", "Currently supports: .ply, .obj" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "node = PointCloudNode(path=r\"../../..\\tests\\testfiles\\pcd\\parking.pcd\", loadResource=True)\n", "node.save_resource(directory=r\"../../../tests/testfiles/resources\", extension=\".pcd\") # Save the resource to the resourcePath" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PointCloudNode Transformation\n", "\n", "Since every nod has a cartesian transform, it can be transformed using the `node.transform()` function.\n", "\n", "The transformation also updates the `convexHull` and `orientedBoundingBox`.\n", "\n", "Furthermore, if the PointCloudNode has a resource, that resource is also transformed." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[1. 0. 0. 0.]\n", " [0. 1. 0. 0.]\n", " [0. 0. 1. 0.]\n", " [0. 0. 0. 1.]]\n", "applying transformation: (-1)\n", "[[0. 0. 1. 0.]\n", " [0. 1. 0. 0.]\n", " [1. 0. 0. 0.]\n", " [0. 0. 0. 1.]] \n", "\n", "applying rotation: (90,0,0)\n", "[[ 1.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00]\n", " [ 0.000000e+00 6.123234e-17 -1.000000e+00 0.000000e+00]\n", " [ 0.000000e+00 1.000000e+00 6.123234e-17 0.000000e+00]\n", " [ 0.000000e+00 0.000000e+00 0.000000e+00 1.000000e+00]] \n", "\n", "applying translation: (1,2,3)\n", "[[1. 0. 0. 1.]\n", " [0. 1. 0. 2.]\n", " [0. 0. 1. 3.]\n", " [0. 0. 0. 1.]]\n" ] } ], "source": [ "node = PointCloudNode()\n", "print(node.cartesianTransform)\n", "transformation = np.array([[0,0,1,0],[0,1,0,0],[1,0,0,0],[0,0,0,1]])\n", "node.transform(transformation=transformation)\n", "print(\"applying transformation: (-1)\")\n", "print(node.cartesianTransform,\"\\n\")\n", "\n", "node = PointCloudNode()\n", "rotation = np.array([90,0,0]) #eulers in degrees\n", "node.transform(rotation=rotation)\n", "print(\"applying rotation: (90,0,0)\")\n", "print(node.cartesianTransform,\"\\n\")\n", "\n", "node = PointCloudNode()\n", "translation = np.array([1,2,3])\n", "node.transform(translation=translation)\n", "print(\"applying translation: (1,2,3)\")\n", "print(node.cartesianTransform)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PointCloudNode Visualisation\n", "\n", "When a PointCloudNode has a resource, the `show()` function displays the PointCloud using either open3d or Trimesh, depending on the workspace.\n", "\n", "Use the `inline = True` parameter to display the Mesh using the Trimesh viewer in your jupyter notebook file. Otherwise the function opens a new python window to display the open3d viewer" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "