{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Quick Start\n",
    "\n",
    "Extract a complex surface in just a few lines of code.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-07-05T04:06:16.922815Z",
     "iopub.status.busy": "2026-07-05T04:06:16.922730Z",
     "iopub.status.idle": "2026-07-05T04:06:18.071216Z",
     "shell.execute_reply": "2026-07-05T04:06:18.070779Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracted 196,176 vertices, 392,348 triangles\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"100%\"\n",
       "            height=\"420\"\n",
       "            src=\"_static/viser/index.html?playbackPath=../scenes/db27569071b48c17.viser\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "            style=\"border: 1px solid #8888; border-radius: 4px;\"\n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x75c488b7e780>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import isoext\n",
    "from isoext.sdf import (\n",
    "    SphereSDF, TorusSDF, \n",
    "    UnionOp, IntersectionOp, NegationOp, RotationOp\n",
    ")\n",
    "from isoext import viewer\n",
    "\n",
    "# Create a high-resolution grid\n",
    "grid = isoext.UniformGrid([256, 256, 256])\n",
    "\n",
    "# Build a complex shape: sphere with three interlocking toroidal tunnels\n",
    "sphere = SphereSDF(radius=0.75)\n",
    "torus = TorusSDF(R=0.75, r=0.15)\n",
    "\n",
    "shape = IntersectionOp([\n",
    "    sphere,\n",
    "    NegationOp(UnionOp([\n",
    "        torus,\n",
    "        RotationOp(torus, axis=[1, 0, 0], angle=90),\n",
    "        RotationOp(torus, axis=[0, 1, 0], angle=90),\n",
    "    ]))\n",
    "])\n",
    "\n",
    "# Evaluate and extract\n",
    "grid.set_values(shape(grid.get_points()))\n",
    "vertices, faces = isoext.marching_cubes(grid)\n",
    "\n",
    "print(f\"Extracted {vertices.shape[0]:,} vertices, {faces.shape[0]:,} triangles\")\n",
    "viewer.embed(vertices, faces, color=\"coral\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interactive viewing\n",
    "\n",
    "Outside of these docs, `isoext.viewer` can also open a live viewer in your browser:\n",
    "\n",
    "```python\n",
    "from isoext import viewer\n",
    "\n",
    "server = viewer.show(vertices, faces)  # prints the URL it serves on\n",
    "# ... inspect the mesh in the browser ...\n",
    "server.stop()\n",
    "```\n",
    "\n",
    "`viewer.embed`, used above, instead records the scene to a static file next to the\n",
    "notebook, so the rendered page stays interactive without a running server.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What just happened?\n",
    "\n",
    "1. **Created a grid** — A 256³ lattice of points in 3D space\n",
    "2. **Computed scalar values** — Evaluated a signed distance function at each point\n",
    "3. **Extracted the surface** — Marching Cubes found where the scalar field equals zero\n",
    "\n",
    "## Learn more\n",
    "\n",
    "- [Working with Grids](grids.ipynb) — How to create grids and set values (including custom functions and neural networks)\n",
    "- [Marching Cubes](marching_cubes.ipynb) — Triangular mesh extraction\n",
    "- [Dual Contouring](dual_contouring.ipynb) — Triangle mesh extraction with sharp features\n",
    "- [SDF Utilities](sdf_guide.ipynb) — Built-in shape primitives and CSG operations\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
