{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# PointCloud \n\nThis demo is a very short introduction to basic point clouds\nand a polygon mesh, that consists of two triangles, whose corner\npoints are given by some points of a cloud.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom itom import pointCloud\nfrom itom import polygonMesh\nfrom itom import point" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a new, empty ``pointCloud`` of type x,y,z only.\nPoint clouds can either be organized or unorganized. Organized point\nclouds have a height > 1, such that all points are organized in a 2d grid\nand the direct neighbours of every point are therefore defined.\nIn unorganized point clouds, the height is always <= 1 and the size is\nequal to the width of the cloud. No point has any neighbourhood relationship\nto other points. This is usually the default.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pcl = pointCloud(point.PointXYZ)\n\nprint(\n \"Initial point cloud pcl, shape (h, w): %i x %i, fields: %s, organized: %i\"\n % (pcl.height, pcl.width, str(pcl.fields), pcl.organized)\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add 8 points of a unit cube.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pcl.append(point(point.PointXYZ, (0, 0, 0)))\npcl.append(point(point.PointXYZ, (1, 0, 0)))\npcl.append(point(point.PointXYZ, (0, 1, 0)))\npcl.append(point(point.PointXYZ, (1, 1, 0)))\npcl.append(point(point.PointXYZ, (0, 0, 1)))\npcl.append(point(point.PointXYZ, (1, 0, 1)))\npcl.append(point(point.PointXYZ, (0, 1, 1)))\npcl.append(point(point.PointXYZ, (1, 1, 1)))\n\nprint(\n \"Modified point cloud pcl, shape (h, w): %i x %i, fields: %s, organized: %i\"\n % (pcl.height, pcl.width, str(pcl.fields), pcl.organized)\n)\n\nfor idx in range(pcl.size):\n print(\"Point %i: %s\" % (idx + 1, str(pcl[idx])))\n\n# A polygon mesh can be constructed from a point cloud, that indicates\n# all corner points of the mesh and a table of vertices. Every entry in the\n# vertices table must contain 3 (default) or 4 values and indicate the indices\n# to the points in the cloud that define a triangle or quadrangle of the\n# mesh. If the normal vector to such a triangle points towards the outside\n# of the object, the order of the points is given by the right-hand rule, where\n# the thumbs shows in the direction of the normale vector.\n\n# create an array with two triangles. The first triangle has the corner\n# points with the indices 0, 1 and 2 of the cloud. The 2nd triangle consists\n# of the corner points 0, 1 and 3.\nvertices = np.array([[0, 1, 2], [0, 1, 3]])\n\n# create a mesh from the cloud and the vertices\nmesh = polygonMesh.fromCloudAndPolygons(pcl, vertices)\n\nprint(\"Mesh of %i polygons\" % mesh.nrOfPolygons)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }