{ "cells": [ { "cell_type": "markdown", "id": "61f42d01", "metadata": {}, "source": [ "# Primitives Example" ] }, { "cell_type": "markdown", "id": "89d8587b", "metadata": {}, "source": [ "MorphoNet has a system named primitive that allow you to upload a mesh as a primitive, and instantiate this primitive instead of instantiating multiple times the same mesh. This is very efficient for simulation\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "c1ab09a4", "metadata": {}, "outputs": [], "source": [ "import morphonet" ] }, { "cell_type": "code", "execution_count": null, "id": "1cfeb8bd", "metadata": {}, "outputs": [], "source": [ "mn_login=\"user\"\n", "mn_password=\"password\"\n", "mn=morphonet.Net(mn_login,mn_password)" ] }, { "cell_type": "markdown", "id": "2b93eaf4", "metadata": {}, "source": [ "Let's create a dataset with only 1 time step\n", "\n", "**Parameters**\n", "\n", "\n", "name : (string)\n", " name of the new dataset\n", "\n", "minTime : (int)\n", " begin time point \n", "\n", "maxTime : (int)\n", " end time point , here the same than begin because we don't have any time properties\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a9d8f970", "metadata": {}, "outputs": [], "source": [ "mn.create_dataset(\"api_test_primitive\",minTime=0,maxTime=0)" ] }, { "cell_type": "markdown", "id": "e20d9028", "metadata": {}, "source": [ "Than we will load into memory the primitives source we want to upload\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "f1ccb08e", "metadata": {}, "outputs": [], "source": [ "prim1 = mn.read_mesh(\"DATASET/Multiple_Objs/obj502.obj\")\n", "prim2 = mn.read_mesh(\"DATASET/Multiple_Objs/obj505.obj\")" ] }, { "cell_type": "markdown", "id": "23fe24b3", "metadata": {}, "source": [ "Than we can upload the mesh that will be the primitive in the dataset \n", "\n", "**Parameters**\n", "\n", "\n", "name : (string)\n", " Name of the primitive\n", " \n", "obj : (bytes)\n", " 3d data of the primitive\n" ] }, { "cell_type": "code", "execution_count": null, "id": "bb27bd19", "metadata": {}, "outputs": [], "source": [ "mn.upload_primitive(\"object1\",prim1)\n", "mn.upload_primitive(\"object2\",prim2)" ] }, { "cell_type": "markdown", "id": "9a1f1753", "metadata": {}, "source": [ "Than we can upload the mesh for the time point that use the primitives. You can check on MorphoNet format help to create a mesh file with the correct format to use primitives\n" ] }, { "cell_type": "code", "execution_count": null, "id": "b4e7634a", "metadata": {}, "outputs": [], "source": [ "mesh1 = mn.read_mesh(\"DATASET/Multiple_Objs/obj506.obj\")\n", "mn.upload_mesh_with_primitive_at(0,mesh1)" ] }, { "cell_type": "markdown", "id": "1df2247a", "metadata": {}, "source": [ "If a primitive is not used you can delete a primitive by it's name for the dataset\n", "\n", "**Parameters**\n", "\n", "\n", "name : (string)\n", " name of the primitive to delete\n" ] }, { "cell_type": "code", "execution_count": null, "id": "5061c7be", "metadata": {}, "outputs": [], "source": [ "mn.delete_primitive(\"object1\")" ] }, { "cell_type": "markdown", "id": "2b818664", "metadata": {}, "source": [ "Or you can delete all primitive of current dataset\n" ] }, { "cell_type": "code", "execution_count": null, "id": "f7644970", "metadata": {}, "outputs": [], "source": [ "mn.delete_primitives()" ] }, { "cell_type": "code", "execution_count": null, "id": "cdb7cc82", "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.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }