Skip to content

Commit

Permalink
Add some documentation (#1199)
Browse files Browse the repository at this point in the history
* Add some documentation

* add image
  • Loading branch information
Grantim authored May 3, 2023
1 parent 6e0feb3 commit 9f1de16
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions doxygen/HowToExamples.dox
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,78 @@ rotationXf = mrmeshpy.AffineXf3f.linear( mrmeshpy.Matrix3f.rotation( plusZ, 3.14
mesh.transform(rotationXf)
\endcode

Simple triangulation
\code
from meshlib import mrmeshpy as mm
from meshlib import mrmeshnumpy as mn
import numpy as np

u, v = np.mgrid[0:2 * np.pi:100j, 0:np.pi:100j]
x = np.cos(u) * np.sin(v)
y = np.sin(u) * np.sin(v)
z = np.cos(v)

# Prepare for MeshLib PointCloud
verts = np.stack((x.flatten(),y.flatten(),z.flatten()),axis=-1).reshape(-1,3)
# Create MeshLib PointCloud from np ndarray
pc = mn.pointCloudFromPoints(verts)
# Remove duplicate points
pc.validPoints = mm.pointUniformSampling(pc,1e-3)
pc.invalidateCaches()

# Triangulate it
triangulatedPC = mm.triangulatePointCloud(pc)

# Fix possible issues
triangulatedPC = mm.offsetMesh(triangulatedPC, 0.0)
\endcode

Tirangulation of regular numpy grid
\code
from meshlib import mrmeshpy as mm
from meshlib import mrmeshnumpy as mn
import numpy as np

u, v = np.mgrid[0:2 * np.pi:50j, 0:np.pi:100j]
x = np.cos(u) * np.sin(v)
y = np.sin(u) * np.sin(v)
z = np.cos(v)

mesh = mn.meshFromUVPoints(x,y,z)
\endcode

Using plotly to visualize mesh
\code
from meshlib import mrmeshpy as mm
from meshlib import mrmeshnumpy as mn
import numpy as np
import plotly.graph_objects as go

# load mesh
mesh = mm.loadMesh(mm.Path("mesh.stl"))
# extract numpy arrays
verts = mn.getNumpyVerts(mesh)
faces = mn.getNumpyFaces(mesh.topology)

# prepare data for plotly
vertsT = np.transpose(verts)
facesT = np.transpose(faces)

# draw
fig = go.Figure(data=[
go.Mesh3d(
x = vertsT[0],
y = vertsT[1],
z = vertsT[2],
i = facesT[0],
j = facesT[1],
k = facesT[2]
)
])

fig.show()
\endcode
\image html plotly_visualization.png "Plotly visualization" width = 300cm

\sa \ref EmbendedPythonOverview
*/
Expand Down

0 comments on commit 9f1de16

Please sign in to comment.