{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# VTK 3D Visualizer\n\nThe ``Vtk3dVisualizer`` can be used to visualize the following items:\n\n* pointClouds\n* polygonMeshes\n* geometric items like cuboids, pyramids, cylinders, spheres\n* text at arbitrary 3D positions\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\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\n\n\nfrom itom import polygonMesh\nfrom itom import dataObject\nfrom itom import plot\nfrom itom import algorithms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load a polygonal mesh of a bunny.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "bunny = polygonMesh()\nalgorithms.loadPolygonMesh(bunny, \"bunny.obj\")\ntrafo = dataObject.eye(4, \"float64\")\ntrafo[1, 1] = 0\ntrafo[2, 2] = 0\ntrafo[1, 2] = 1\ntrafo[2, 1] = 1\ntrafo[0:3, 3] = (0, 0, -2)\nbunny_transformed_mesh = polygonMesh()\nalgorithms.meshTransformAffine(bunny, bunny_transformed_mesh, trafo)\n\n[i, h] = plot(bunny_transformed_mesh, \"Vtk3dVisualizer\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Configure the mesh (called ``source_mesh``).\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "h.call(\"setItemProperty\", \"source_mesh\", \"ColorMode\", \"Z\")\nh.call(\"setItemProperty\", \"source_mesh\", \"ColorMap\", \"viridis\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A cylinder is added to the canvas. The axis of symmetry is given by a start point and an orientation vector.\nThe length of the orientation vector defines the height of the cylinder, its radius is given by the third parameter.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "h.call(\"addCylinder\", (10, 0, 0), (0, 0, 5), 0.5, \"cylinder\") # arguments: point, orientation, radius, name\nh.call(\"setItemProperty\", \"cylinder\", \"Representation\", \"Surface\")\nh.call(\"setItemProperty\", \"cylinder\", \"LineColor\", \"#808000\")\nh.call(\"setItemProperty\", \"cylinder\", \"Lighting\", True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A sphere is added on top of the cylinder. Its center is given as first parameter, followed by the radius.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "h.call(\"addSphere\", (10, 0, 7), 1.5, \"sphere\")\nh.call(\"setItemProperty\", \"sphere\", \"Interpolation\", \"Gouraud\")\nh.call(\"setItemProperty\", \"sphere\", \"Lighting\", True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A pyramid is added. It is defined by its five corner points using a ``3 x 5`` ``dataObject``. The first four\ncolumns hereby describe the corner points of the base rectangle, the last column are the ``x, y, z``\ncoordinates of the tip. Currently, a pyramid only consists of line and no surface representation is possible.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pyramid = np.array([[0, 0, 6, 6, 3], [0, 6, 6, 0, 3], [0, 0, 0, 0, 7]])\nh.call(\"addPyramid\", dataObject(pyramid), \"pyramid\")\nh.call(\"setItemProperty\", \"pyramid\", \"LineColor\", \"blue\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add a cube with a side length of ``(12, 10, 2)`` ``[x, y, z]``. The cube is originally centered at the origin ``(0,0,0)``.\nThe second parameter however translates it by ``(dx, dy, dz)``. The third vector contains rotations around\nthe x-, y- and z-axis in rad. As alternative to 'addCube', it is also possible to use ``addCuboid`` that has the\ncoordinates of the 8 corner points as 3x8 ``dataObject`` (first argument).\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "h.call(\"addCube\", (12, 10, 2), (5, 2, -1.2), (0, 0, -np.pi / 8), \"cube\")\nh.call(\"setItemProperty\", \"cube\", \"Lighting\", True)\nh.call(\"setItemProperty\", \"cube\", \"Representation\", \"Surface\")\nh.call(\"setItemProperty\", \"cube\", \"LineColor\", \"white\")\nh.call(\"setItemProperty\", \"cube\", \"Specular\", 0.8)\nh.call(\"setItemProperty\", \"cube\", \"SpecularColor\", \"#ff6347\")\n\nlines = dataObject([8, 6], \"float32\")\nlines[:, 0] = 3\nlines[:, 1] = 3\nlines[:, 2] = 7\nfor idx in range(8):\n lines[idx, 3] = 3 + 5 * np.sin(2 * idx * np.pi / 8)\n lines[idx, 4] = 3 + 5 * np.cos(2 * idx * np.pi / 8)\nlines[:, 5] = 12\nh.call(\"addLines\", lines, \"lines\")\nh.call(\"setItemProperty\", \"lines\", \"LineWidth\", 3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Places a 2D text to the given ``x, y`` coordinates (in screen coordinates). The third number argument\nis ``14pt``; the last value is the optional color of the text\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "h.call(\"addText\", \"itom artwork\", 200, 300, 14, \"text\", \"#008866\")\n\n# general settings of the plot\nh[\"cubeAxesVisible\"] = True\nh[\"xAxisInterval\"] = (-15, 15) # defines the extend of the cube axes\nh[\"yAxisInterval\"] = (-15, 15)\nh[\"zAxisInterval\"] = (-10, 10)\nh[\"xDrawGridlines\"] = True\nh[\"yDrawGridlines\"] = True\nh[\"zDrawGridlines\"] = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\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 }