From 77baf715b5dac59d19247d7927ce843b21325848 Mon Sep 17 00:00:00 2001 From: nhz2 Date: Wed, 20 Nov 2024 19:37:54 -0500 Subject: [PATCH] Update Meshing.jl examples for v0.7 --- Project.toml | 4 ++-- Readme.md | 14 ++++++++++---- notebooks/Project.toml | 4 ++-- notebooks/demo.ipynb | 10 ++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 7ef6bde..78a07d9 100644 --- a/Project.toml +++ b/Project.toml @@ -29,10 +29,10 @@ Colors = "0.9, 0.10, 0.11, 0.12, 0.13" CoordinateTransformations = "0.5, 0.6" DocStringExtensions = "0.5, 0.6, 0.7, 0.8, 0.9" FFMPEG = "0.2, 0.3, 0.4" -GeometryBasics = "0.3, 0.4, 0.5" +GeometryBasics = "0.3, 0.4" HTTP = "1" MeshIO = "0.4" -Meshing = "0.5, 0.6" +Meshing = "0.7" MsgPack = "1" Parameters = "0.10, 0.11, 0.12, 0.13" PrecompileTools = "1" diff --git a/Readme.md b/Readme.md index 3fa658a..46180f7 100644 --- a/Readme.md +++ b/Readme.md @@ -82,11 +82,17 @@ setobject!(vis, PointCloud(verts, colors)) ```julia # Visualize a mesh from the level set of a function -using Meshing: MarchingTetrahedra -using GeometryBasics: Mesh, HyperRectangle +using Meshing: MarchingTetrahedra, isosurface +using GeometryBasics: + Mesh, + TriangleFace, + Vec, + Point +xr,yr,zr = ntuple(_->LinRange(-1,1,50),3) f = x -> sum(sin, 5 * x) -mesh = Mesh(f, HyperRectangle(Vec(-1, -1, -1), Vec(2, 2, 2)), - MarchingTetrahedra()) +sdf = [f(Vec(x,y,z)) for x in xr, y in yr, z in zr] +vts, fcs = isosurface(sdf, MarchingTetrahedra(), xr, yr, zr) +mesh = Mesh(Point.(vts), TriangleFace.(fcs)) setobject!(vis, mesh, MeshPhongMaterial(color=RGBA{Float32}(1, 0, 0, 0.5))) ``` diff --git a/notebooks/Project.toml b/notebooks/Project.toml index 4114917..2f0d173 100644 --- a/notebooks/Project.toml +++ b/notebooks/Project.toml @@ -9,8 +9,8 @@ MeshIO = "7269a6da-0436-5bbc-96c2-40638cbb6118" Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc" [compat] -Colors = "0.9, 0.10, 0.11, 0.12" +Colors = "0.9, 0.10, 0.11, 0.12, 0.13" FileIO = "1" GeometryBasics = "0.3, 0.4" -Meshing = "0.5, 0.6" +Meshing = "0.7" MeshIO = "0.4" diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb index c3558a9..9b74cf5 100644 --- a/notebooks/demo.ipynb +++ b/notebooks/demo.ipynb @@ -36,7 +36,7 @@ "using MeshCat\n", "using CoordinateTransformations\n", "using Rotations\n", - "using GeometryBasics: HyperRectangle, Vec, Point, Mesh\n", + "using GeometryBasics: HyperRectangle, Vec, Point, Mesh, TriangleFace\n", "using Colors: RGBA, RGB" ] }, @@ -384,10 +384,12 @@ "# Those two pieces of information are all we need to construct a mesh geometry.\n", "\n", "# Using `Meshing.jl`, we can construct a mesh directly from our function:\n", - "using Meshing: MarchingCubes\n", + "using Meshing: MarchingTetrahedra, isosurface\n", "\n", - "bounds = HyperRectangle(lower_bound, upper_bound - lower_bound)\n", - "mesh = Mesh(f, bounds, MarchingCubes())\n", + "xr,yr,zr = ntuple(i->LinRange(lower_bound[i], upper_bound[i],50),3)\n", + "sdf = [f(Vec(x,y,z)) for x in xr, y in yr, z in zr]\n", + "vts, fcs = isosurface(sdf, MarchingTetrahedra(), xr, yr, zr)\n", + "mesh = Mesh(Point.(vts), TriangleFace.(fcs))\n", "\n", "# And now we can load that geometry into the visualizer\n", "setobject!(vis, mesh)"