{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Cloud viewer\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 ui\nfrom itom import dataObject\n\ntry:\n from itom import pointCloud\nexcept Exception as ex:\n ui.msgInformation(\n \"PointCloud missing\",\n \"your itom version is compiled without support of pointClouds\",\n )\n raise ex" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a data objects with X, Y and Z values of a topography\nas well as a 2.5D topography in terms of a data object.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "[X, Y] = np.meshgrid(np.arange(0, 5, 0.1), np.arange(0, 5, 0.1))\nZ = np.sin(X * 2) + np.cos(Y * 0.5)\nI = np.random.rand(*X.shape) # further intensity\nC = dataObject.randN(\n [X.shape[0], X.shape[1]], \"rgba32\"\n) # further color information\ntopography = dataObject(Z).astype(\"float32\")\ntopography.axisScales = (0.1, 0.1)\ntopography[0, 0] = float(\"nan\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a point cloud from the X, Y and Z arrays with further intensity information.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cloud1 = pointCloud.fromXYZI(X, Y, Z, I)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a point cloud from the topography image with further colour information.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cloud2 = pointCloud.fromTopography(topography, color=C)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a point cloud from the X, Y and Z arrays with further colour information.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cloud3 = pointCloud.fromXYZRGBA(X, Y, Z, C)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a point cloud from the X, Y and Z arrays with the Z-values as intensity information.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cloud4 = pointCloud.fromXYZI(X, Y, Z - 0.1, Z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Manually create triangular polygons for the whole surface\nthe polygons are regularly distributed and each rectangle is divided into two polygons.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "polygons = dataObject.zeros([2 * 49 * 49, 3], \"uint16\")\nc = 0\nfor row in range(0, 49):\n for col in range(0, 49):\n polygons[c, 0] = row * 50 + col\n polygons[c, 1] = (row + 1) * 50 + col\n polygons[c, 2] = row * 50 + 1 + col\n c += 1\nfor row in range(0, 49):\n for col in range(0, 49):\n polygons[c, 0] = (row + 1) * 50 + col\n polygons[c, 1] = (row + 1) * 50 + col + 1\n polygons[c, 2] = row * 50 + col + 1\n c += 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create polygonal mesh structure from cloud3 and polygons.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh = polygonMesh.fromCloudAndPolygons(cloud3, polygons)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As alternative approach you can directly create the same polygonal mesh\nfrom the point cloud if you know that the point cloud is organized, hence,\nthe points are located like in a regular grid.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh2 = polygonMesh.fromOrganizedCloud(cloud2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create GUI (3D Viewer)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "gui = ui(\"cloudViewer.ui\", ui.TYPEWINDOW)\n\n# gui.plot.call(\"addPointCloud\",cloud1,\"cloud1\")\n# gui.plot.call(\"addPointCloud\",cloud2,\"cloud2\")\n# gui.plot.call(\"addPointCloud\",cloud3,\"cloud3\")\ngui.plot.call(\n \"addPointCloud\", cloud4, \"cloud4\"\n) # visualize cloud4 under the name 'cloud4'\ngui.plot.call(\n \"setItemProperty\", \"cloud4\", \"PointSize\", 10\n) # change the property PointSize of this point\n# gui.plot.call(\"addMesh\",mesh,\"mesh\")\ngui.plot.call(\n \"addMesh\", mesh2, \"mesh2\"\n) # visualize the mesh2 under the name 'mesh2'\ngui.show()" ] } ], "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 }