CsatiZoltan / CristalX

Identification and analysis of polycrystalline microstructures
https://cristalx.readthedocs.io
GNU Lesser General Public License v3.0
6 stars 7 forks source link

Display grain number and grain properties on grains #20

Open CsatiZoltan opened 4 years ago

CsatiZoltan commented 4 years ago

Similarly as done for matplotlib: https://github.com/CsatiZoltan/Polycrystalline-microstructures/blob/89cdfed050a268a5904ab126dc42efbf258e1fea/grains/analysis.py#L154

The center of the grain can be found by computing the center of mass, assuming that the grain is homogeneous (refer to core_shape_properties.py):

from OCC.GProp import GProp_GProps
from OCC.BRepGProp import brepgprop_SurfaceProperties
...
# Compute inertia properties
props = GProp_GProps()
brepgprop_SurfaceProperties(region, props)  # region is a *TopoDS_Face* object
area = props.Mass()  # assuming that the region is homogeneous
cog = props.CentreOfMass()
cog_x, cog_y, cog_z = cog.Coord()