{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import subprocess as sp\n", "import numpy as np\n", "import k3d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Test" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5a19ded0fb32480994e13c36259c9470", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot = k3d.plot()\n", "plot += k3d.line([[0, 0, 0],\n", " [1, 1, 1]])\n", "plot.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Trial 1" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def getFacets3D(filename):\n", " exe = [\"./getFacets3D\", filename]\n", " p = sp.Popen(exe, stdout=sp.PIPE, stderr=sp.PIPE)\n", " stdout, stderr = p.communicate()\n", " temp1 = stderr.decode(\"utf-8\")\n", "\n", " lines = temp1.strip().split('\\n')\n", "\n", " all_points = []\n", " all_indices = []\n", " current_index = 0\n", "\n", " for line in lines:\n", " if line.strip() == '':\n", " # Move to next plane\n", " if len(all_points) > current_index:\n", " # Calculate indices for the previous plane\n", " n = len(all_points) - current_index\n", " indices = np.vstack((np.zeros(n-2, dtype=np.uint32) + current_index,\n", " np.arange(1, n-1, dtype=np.uint32) + current_index,\n", " np.arange(2, n, dtype=np.uint32) + current_index)).T.flatten()\n", " all_indices.append(indices)\n", " current_index = len(all_points)\n", " else:\n", " # Convert each line into a tuple of floats (x, y, z) and add it to all_points\n", " point = tuple(map(float, line.split()))\n", " all_points.append(point)\n", "\n", " # Adding indices for the last plane if it exists\n", " if len(all_points) > current_index:\n", " n = len(all_points) - current_index\n", " indices = np.vstack((np.zeros(n-2, dtype=np.uint32) + current_index,\n", " np.arange(1, n-1, dtype=np.uint32) + current_index,\n", " np.arange(2, n, dtype=np.uint32) + current_index)).T.flatten()\n", " all_indices.append(indices)\n", "\n", " # Convert lists to numpy arrays\n", " all_points = np.array(all_points, dtype=np.float32)\n", " all_indices = np.concatenate(all_indices).astype(np.uint32)\n", "\n", " return all_points, all_indices" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1655813\n", "2544717\n" ] } ], "source": [ "# Example usage\n", "points, indices = getFacets3D(\"dump\")\n", "print(len(points))\n", "print(len(indices))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5fdaf35054d647fa88ee91048fd771fa", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Plotting with k3d\n", "plot = k3d.plot()\n", "mesh = k3d.mesh(points, indices, wireframe=True) # Set opacity to 1 for full solidity\n", "plot += mesh\n", "plot.display()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "default-py", "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.13.3" } }, "nbformat": 4, "nbformat_minor": 2 }