{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 05. Visualisation and Communication\n\nTurn a small room into an interactive figure. Rotate it, zoom in, and inspect the edges.\n\n**Goal:** Complete one small workflow. Run the cells from top to bottom in a fresh kernel.\n\n**Extra dependencies:** None beyond the base environment.\n\nAll examples use metres unless stated otherwise.\n",
   "id": "tutorial-05-00"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import os\nos.environ[\"TOPOLOGICPY_CORE_BACKEND\"] = \"pythonocc\"\n\nimport topologicpy\nfrom topologicpy.Core import Core\n\nassert topologicpy.__version__ == \"0.9.86\", \"Use TopologicPy 0.9.86 for these tutorials.\"\nassert type(Core.Backend()).__name__ == \"PythonOCCBackend\", \"Restart with the pythonocc backend.\"\nprint(\"TopologicPy\", topologicpy.__version__, \"—\", type(Core.Backend()).__name__)\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-05-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Create display data\n\nGeometry and its display are separate. Plotly converts topology into traces, then puts those traces in a figure.\n",
   "id": "tutorial-05-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Cell import Cell\nfrom topologicpy.Plotly import Plotly\n\nroom = Cell.Prism(width=4, length=3, height=2)\ndata = Plotly.DataByTopology(room, faceColor=\"skyblue\", faceOpacity=0.65)\nfigure = Plotly.FigureByData(data, width=750, height=450)\nassert len(figure.data) > 0\nfigure.show(renderer=\"notebook\")\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-05-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Save a portable presentation\n\nThe HTML file and notebook display both embed Plotly so they can be opened without an internet connection.\n",
   "id": "tutorial-05-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from pathlib import Path\n\noutput = Path(\"results\")\noutput.mkdir(exist_ok=True)\nfigure.write_html(str(output / \"05_room.html\"), include_plotlyjs=True)\nprint(\"Saved:\", output / \"05_room.html\")\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-05-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nChange the face colour and opacity, then save the figure again.\n",
   "id": "tutorial-05-06"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (TopologicPy tutorials)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
