{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Cloud\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom itom import plot\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 sphere\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "polarRad = np.radians(np.arange(0, 360, 1))\nazimuthRad = np.radians(np.arange(0, 180, 1))\nnominalRadius = 5\npolars, azimuths = np.meshgrid(azimuthRad, polarRad)\n\nX = nominalRadius * np.cos(polars) * np.cos(azimuths)\nY = nominalRadius * np.sin(polars) * np.cos(azimuths)\nZ = nominalRadius * np.sin(azimuths)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Flatten all X,Y,Z coordinates\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "X = X.flatten()\nY = Y.flatten()\nZ = Z.flatten()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create random noise in X, Y and Z direction\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "level = 0.3\nXnoise = (np.random.rand(len(X)) - 0.5) * level\nYnoise = (np.random.rand(len(Y)) - 0.5) * level\nZnoise = (np.random.rand(len(Z)) - 0.5) * level\ndist = np.sqrt(Xnoise ** 2 + Ynoise ** 2 + Znoise ** 2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cloud 1: perfect sphere, no intensity values\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cloud1 = pointCloud.fromXYZ(X, Y, Z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cloud 2: noisy sphere, noise deviation as intensity, shift it a little bit in X direction\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "Xshift = nominalRadius * 2.2\ncloud2 = pointCloud.fromXYZI(\n X + Xnoise + Xshift, Y + Ynoise, Z + Znoise, dist\n)\n\n# Plot the first cloud --> this cloud has the default name 'source_cloud_normal'\nindex, handle = plot(cloud1, \"vtk3dvisualizer\")\n\n# parametrize cloud1\nhandle.call(\"setItemProperty\", \"source_cloud_normal\", \"ColorMode\", \"Z\")\nhandle.call(\"setItemProperty\", \"source_cloud_normal\", \"ColorMap\", \"hsv\")\n\n# plot the second sphere and shift it a little bit\nhandle.call(\n \"addPointCloud\", cloud2, \"cloud2\"\n) # visualize cloud2 under the name 'cloud2'\nhandle.call(\n \"setItemProperty\", \"cloud2\", \"PointSize\", 2\n) # change the property PointSize of this point\nhandle.call(\"setItemProperty\", \"cloud2\", \"ColorMode\", \"Intensity\")\nhandle.call(\"setItemProperty\", \"cloud2\", \"ColorMap\", \"blue2red\")\nhandle.call(\"setItemProperty\", \"cloud2\", \"ColorValueRange\", (0.1, 0.2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n" ] } ], "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 }