Geometry — 3D

Typedefs

typedef CGAL::Exact_predicates_exact_constructions_kernel EX_K
typedef Traits_2::Point_2 Point_2
typedef EX_K::Point_3 Point_3
typedef CGAL::Polygon_2<EX_K> Polygon_2
typedef CGAL::Simple_cartesian<double> SC_Kernel
typedef SC_Kernel::Point_3 SC_Point
typedef openvdb::FloatGrid SDF_Grid
typedef Traits_2::X_monotone_curve_2 Segment_2
typedef CGAL::Arr_segment_traits_2<EX_K> Traits_2
struct Indexed_Triangle
#include <primitives.h>

Public Members

size_t p1
size_t p2
size_t p3
class SurfaceMesh
#include <SurfaceMesh.h>

A class for storing and manipulating triangle meshes.

Public Types

typedef CGAL::AABB_face_graph_triangle_primitive<CGALMesh> AABBPrimitive
typedef CGAL::Surface_mesh<SC_Point> CGALMesh
typedef CGAL::AABB_traits_3<SC_Kernel, AABBPrimitive> MeshAABBTraits
typedef CGAL::AABB_tree<MeshAABBTraits> MeshAABBTree
typedef CGAL::Side_of_triangle_mesh<CGALMesh, SC_Kernel> Point_inside

Public Functions

std::pair<glm::vec3, glm::vec3> bounding_box() const

Returns the bounding box of the mesh.

Returns:

The bounding box of the mesh

void center()

Centers the mesh around the origin.

SDF_Grid::Ptr compute_sdf(glm::vec3 voxel_size, float exterior_band_width = 3.0f, float interior_band_width = 3.0f) const

Returns the center of the mesh.

Parameters:
  • voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.

  • exterior_band_width – The width of the exterior band of the SDF

  • interior_band_width – The width of the interior band of the SDF

Returns:

The center of the mesh

double signed_distance(double x, double y, double z) const
SurfaceMesh()

Default constructor.

SurfaceMesh(std::string file_path, bool disable_validation = false)

Constructor that loads a mesh from a file.

Parameters:

file_path – The path to the file to load

SurfaceMesh(std::vector<glm::vec3> vertices, std::vector<Indexed_Triangle> triangles, bool disable_validation = false)

Constructor that creates a mesh from vertices and triangles.

Parameters:
  • vertices – The vertices of the mesh

  • triangles – The triangles of the mesh

void translate(glm::vec3 translation)

Translates the mesh by a given translation vector.

Parameters:

translation – The translation vector to apply to the mesh (mm)

std::vector<Indexed_Triangle> triangles() const

Returns the triangles of the mesh.

Returns:

The triangles of the mesh

std::vector<glm::vec3> vertices() const

Returns the vertices of the mesh.

Returns:

The vertices of the mesh

void write_stl(const std::string &output_file_name)

Writes the mesh to a binary STL file.

Parameters:

output_file_name – The name of the file to write to

Private Functions

void check_mesh_for_errors() const
void prepare_fast_queries()

Private Members

std::shared_ptr<CGALMesh> m_cgal_mesh

The CGAL mesh.

std::shared_ptr<Point_inside> m_inside_tester
glm::vec3 m_max

The maximum coordinate of the mesh.

glm::vec3 m_min

The minimum coordinate of the mesh.

std::shared_ptr<MeshAABBTree> m_tree
std::vector<Indexed_Triangle> m_triangles

The triangles of the mesh.

std::vector<glm::vec3> m_vertices

The vertices of the mesh.

Private Static Functions

static std::tuple<std::vector<glm::vec3>, std::vector<Indexed_Triangle>, glm::vec3, glm::vec3> LoadMeshFromFile(std::string file_path)

Loads a mesh from a file.

Parameters:

file_path – The path to the file to load

Returns:

A tuple containing the vertices, triangles, minimum coordinate, and maximum coordinate of the mesh

static std::shared_ptr<CGALMesh> ToCGALMesh(std::vector<glm::vec3> vertices, std::vector<Indexed_Triangle> triangles)
struct TriangleMeshDataAdapter

An adapter for OpenVDB to use with mesh triangle/ vertex data.

Public Functions

inline void addTriangle(openvdb::Vec3I triangle)

Add a triangle from the mesh to the adapter.

Note

triangles are stored as a Vec3I, where each element is the index of a vertex in the vertex array

Parameters:

triangle – The triangle to add

inline void addVertex(openvdb::Vec3f vertex)

Add a vertex from the mesh to the adapter.

Parameters:

vertex – The vertex to add

inline void getIndexSpacePoint(size_t n, size_t v, openvdb::Vec3d &pos) const

Return position pos in local grid index space for polygon n and vertex v.

Parameters:
  • n – The polygon index

  • v – The vertex index

  • pos – The position of the vertex in local grid index space

inline size_t pointCount() const

Total number of points (vertices in this case).

Returns:

The number of points

inline size_t polygonCount() const

Total number of polygons (triangles in this case).

Returns:

The number of polygons

inline TriangleMeshDataAdapter(glm::vec3 voxel_size, long long vertex_count, long long triangle_count)

Constructor.

Parameters:
  • voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.

  • vertex_count – The number of vertices in the mesh- used to preallocate memory

  • triangle_count – The number of triangles in the mesh- used to preallocate memory

inline size_t vertexCount(size_t n) const

Vertex count for polygon n (always 3 in this case because of triangles).

Parameters:

n – The polygon index

Private Members

double m_inv_min_voxel_size

The inverse of the minimum voxel size.

std::vector<openvdb::Vec3I> m_triangles

The triangles of the mesh.

std::vector<openvdb::Vec3f> m_vertices

The vertices of the mesh.

glm::vec3 m_voxel_size

The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.

int tri_index = 0

The index of the next triangle to add.

int vert_index = 0

The index of the next vertex to add.

class CADPart
#include <cad_part.h>

A CAD geometry primitive.

The CAD is loaded from a file into memory and provides a signed distance adapter to the surface.

Note

This class supports STEP and IGES file formats.

Public Functions

std::pair<glm::vec3, glm::vec3> bounding_box()
CADPart() = default
CADPart(const std::string &path)

Constructor.

Parameters:

path – The path to the CAD file to load

CADPart(TopoDS_Shape part)
std::shared_ptr<CADPart> clone()
void export_as_stl(const std::string &path, double deflection = 0.1)
void set_fast_mode(bool fast_mode, glm::vec3 voxel_size, double interior_bandwidth, double exterior_bandwidth, double deflection = 0.1)
double signed_distance_to_surface(double x, double y, double z)

Returns the signed distance to the surface of the CAD geometry.

Parameters:
  • x – The x coordinate

  • y – The y coordinate

  • z – The z coordinate

std::shared_ptr<SurfaceMesh> to_surface_mesh(double deflection = 0.1)

Private Types

typedef openvdb::FloatGrid GridType

The type of grid used by OpenVDB.

Private Functions

void compute_bbox()
void load(const std::string &path)

Loads the CAD file into memory.

void prepare_classification()
void prepare_fast_classification(glm::vec3 voxel_size, double interior_bandwidth, double exterior_bandwidth, double deflection = 0.1)

Private Members

std::shared_ptr<GridType::Accessor> m_accessor = nullptr

The accessor for the grid.

BRepClass3d_SolidClassifier m_classifier
bool m_fast_mode = false
GridType::Ptr m_grid = nullptr

The OpenVDB grid used to store the signed distance field.

glm::vec3 m_max
glm::vec3 m_min
TopoDS_Shape m_part
openvdb::tools::GridSampler<GridType, openvdb::tools::BoxSampler>::Ptr m_sampler
TopoDS_Shape m_shell

Private Static Functions

static TopoDS_Shape load_iges(std::string path)

Loads an IGES file into a TopoDS_Shape.

Parameters:

path – The path to the IGES file

static TopoDS_Shape load_step(std::string path)

Loads a STEP file into a TopoDS_Shape.

Parameters:

path – The path to the STEP file

Typedefs

template<typename T>
using AABB_tetrahedron_traits = CGAL::AABB_traits_3<SC_Kernel, TetrahedronPrimitive<T>>

Define the AABB traits for the TetrahedronPrimitive.

template<typename T>
using AABBTree = CGAL::AABB_tree<AABB_tetrahedron_traits<T>>

Define the AABB tree for the TetrahedronPrimitive.

template<typename T>
class Tetrahedron
#include <tetrahedron.h>

A class that represents a tetrahedron in 3D space.

This class is used to represent a tetrahedron in 3D space. The tetrahedron is defined by four points in 3D space. The class also stores a value (template) associated with each point in the tetrahedron. Methods are provided to interpolate given a point in space within the tetrahedron.

Public Functions

inline glm::vec3 a() const

Get the first point of the tetrahedron.

inline T a_val() const

Get the value associated with the first point.

inline glm::vec3 b() const

Get the second point of the tetrahedron.

inline T b_val() const

Get the value associated with the second point.

inline glm::vec3 barycenter() const

Compute the barycenter of the tetrahedron.

Returns:

The barycenter or center of mass of the tetrahedron

inline glm::vec4 barycentric_coordinates(const glm::vec3 &point) const

Compute the barycentric coordinates of a point in space within the tetrahedron.

Parameters:

point – The point in space to compute the barycentric coordinates for

Returns:

The barycentric coordinates of the point

inline std::pair<glm::vec3, glm::vec3> bounding_box() const

Compute the bounding box of the tetrahedron.

Returns:

A pair of the minimum and maximum points of the bounding box

inline glm::vec3 c() const

Get the third point of the tetrahedron.

inline T c_val() const

Get the value associated with the third point.

inline glm::vec3 d() const

Get the fourth point of the tetrahedron.

inline T d_val() const

Get the value associated with the fourth point.

inline bool is_point_inside(const glm::vec3 &point) const

Check if a point is inside the tetrahedron.

Note

depends on barycentric_coordinates()

Parameters:

point – The point to check

Returns:

True if the point is inside the tetrahedron, false otherwise

inline glm::vec3 max_point() const

Compute the maximum point of the tetrahedron.

Returns:

The maximum point of the tetrahedron

inline glm::vec3 min_point() const

Compute the minimum point of the tetrahedron.

Returns:

The minimum point of the tetrahedron

inline T sample(const glm::vec3 &point) const

Interpolate a value at a point in space within the tetrahedron.

Parameters:

point – The point in space to interpolate the value at

Returns:

The interpolated value at the point

inline void set_a(const glm::vec3 &a)

Set the first point of the tetrahedron.

inline void set_a_val(const T &val)

Set the value associated with the first point.

inline void set_b(const glm::vec3 &b)

Set the second point of the tetrahedron.

inline void set_b_val(const T &val)

Set the value associated with the second point.

inline void set_c(const glm::vec3 &c)

Set the third point of the tetrahedron.

inline void set_c_val(const T &val)

Set the value associated with the third point.

inline void set_d(const glm::vec3 &d)

Set the fourth point of the tetrahedron.

inline void set_d_val(const T &val)

Set the value associated with the fourth point.

Tetrahedron() = default

Constructor.

inline Tetrahedron(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, const glm::vec3 &d, const T &a_val, const T &b_val, const T &c_val, const T &d_val)

Constructor.

Parameters:
  • a – The first point of the tetrahedron

  • b – The second point of the tetrahedron

  • c – The third point of the tetrahedron

  • d – The fourth point of the tetrahedron

  • a_val – The value associated with the first point

  • b_val – The value associated with the second point

  • c_val – The value associated with the third point

  • d_val – The value associated with the fourth point

inline double volume() const

Compute the volume of the tetrahedron.

Returns:

The volume of the tetrahedron in mm^3

Private Members

glm::vec3 m_a
T m_a_val
glm::vec3 m_b
T m_b_val
glm::vec3 m_c
T m_c_val
glm::vec3 m_d
T m_d_val
template<typename T>
class TetrahedronPrimitive
#include <tetrahedron.h>

Public Types

typedef SC_Kernel::Iso_cuboid_3 Datum
typedef const Tetrahedron<T> *Id
typedef SC_Point Point

Public Functions

inline Datum datum() const
inline Id id() const
inline Point reference_point() const
inline TetrahedronPrimitive(Tetrahedron<T> *tet)

Public Members

Tetrahedron<T> *m_ptr

Typedefs

typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3
typedef CGAL::Parallel_tag Concurrency_tag
typedef Kernel::FT FT
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria
typedef CGAL::Labeled_mesh_domain_3<Kernel> Mesh_domain
typedef Kernel::Point_3 Point
typedef CGAL::Mesh_triangulation_3<Mesh_domain, CGAL::Default, Concurrency_tag>::type Tr
class TetrahedralMesh
#include <tetrahedral_mesh.h>

Class representing a tetrahedral mesh using CGAL.

Contains functions to write out the mesh.

Public Functions

inline size_t degree_of_freedom() const
inline size_t number_of_elements() const
inline size_t number_of_nodes() const
TetrahedralMesh(const C3t3 &c3t3)

Constructor that takes a C3t3 object.

Parameters:

c3t3 – The C3t3 object

void write_to_inp(const std::string &filename, std::shared_ptr<MaterialDefs> material_defs = nullptr, std::shared_ptr<Node> root = nullptr) const

Writes the tetrahedral mesh to an INP file.

Parameters:
  • filename – The filename to write to

  • root – Optional root node of the tree to sample material properties from

Public Static Functions

static TetrahedralMesh FromTree(const std::shared_ptr<Node> &root, double facet_angle, double facet_size, double facet_distance, size_t cell_radius_edge_ratio, double cell_size)

Creates a TetrahedralMesh from a tree using a static cell size.

static TetrahedralMesh FromTree(const std::shared_ptr<Node> &root, double facet_angle, double facet_size, double facet_distance, size_t cell_radius_edge_ratio, double cell_size_lower, double cell_size_upper, std::string variable_cell_size_expression)

Creates a TetrahedralMesh from a tree using a variable cell size based on the material properties gradient.

Private Members

C3t3 m_c3t3
class HexahedralMesh
#include <hexahedral_mesh.h>

Public Functions

std::pair<glm::vec3, glm::vec3> bounding_box()
void compute()
inline std::vector<std::tuple<size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t>> elements() const
HexahedralMesh(std::shared_ptr<Node> node, size_t x_vox, size_t y_vox, size_t z_vox)
inline std::unordered_map<uint8_t, std::vector<size_t>> material_assignments() const
inline std::vector<glm::vec3> nodes() const

Private Functions

std::string getHashKey(double x, double y, double z)
size_t insert_node(double x, double y, double z)

Private Members

std::vector<std::tuple<size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t>> m_elements
std::unordered_map<uint8_t, std::vector<size_t>> m_material_assignments
std::unordered_map<std::string, size_t> m_node_map
std::vector<glm::vec3> m_nodes
std::shared_ptr<Node> m_root
size_t m_x_voxels
size_t m_y_voxels
size_t m_z_voxels
struct IndexedPoint

Public Members

long long index
double x
double y
double z

Variables

static int EdgeTable[256]
static int TriangleTable[4096]

Typedefs

using AABB_vcad_node_traits = CGAL::AABB_traits_3<SC_Kernel, VCADNodeBBoxPrimitive>
using AABBVCADTree = CGAL::AABB_tree<AABB_vcad_node_traits>
struct VCADNodeBBoxPrimitive
#include <vcad_node_bbox_primitive.h>

Public Types

typedef SC_Kernel::Iso_cuboid_3 Datum
typedef const Node *Id
typedef SC_Point Point

Public Functions

inline Datum datum() const
inline Id id() const
inline Point reference_point() const
inline VCADNodeBBoxPrimitive(const std::shared_ptr<Node> &node)

Public Members

std::shared_ptr<Node> m_ptr