Microflow 3D  v1.0
MF::GB::StlMesher Class Reference

Converts surface mesh to volumetric grid with constant voxelSize spacing. More...

#include <StlMesher.h>

Public Member Functions

 StlMesher ()=default
 
 ~StlMesher ()=default
 
openvdb::FloatGrid::Ptr readSTLGrid (const std::string &fileName, double voxelSize, bool verbose=false)
 Reads .stl file with tyti stl reader. More...
 
openvdb::FloatGrid::Ptr getVDBGrid_Ptr ()
 Returns VDBGrid shared Ptr. More...
 

Static Public Member Functions

static std::shared_ptr< MF::GB::StlMesherNew (const std::string &fileName, const double voxelSize, const bool verbose=false)
 

Detailed Description

Converts surface mesh to volumetric grid with constant voxelSize spacing.

Definition at line 27 of file StlMesher.h.

Constructor & Destructor Documentation

◆ StlMesher()

MF::GB::StlMesher::StlMesher ( )
default

◆ ~StlMesher()

MF::GB::StlMesher::~StlMesher ( )
default

Member Function Documentation

◆ getVDBGrid_Ptr()

openvdb::FloatGrid::Ptr MF::GB::StlMesher::getVDBGrid_Ptr ( )
inline

Returns VDBGrid shared Ptr.

Definition at line 40 of file StlMesher.h.

◆ New()

static std::shared_ptr<MF::GB::StlMesher> MF::GB::StlMesher::New ( const std::string &  fileName,
const double  voxelSize,
const bool  verbose = false 
)
inlinestatic

Definition at line 32 of file StlMesher.h.

References readSTLGrid().

Referenced by MF::GB::GeometryBuildFromSTL::Clean().

32  {
33  auto StlMesher_Ptr = std::make_shared<MF::GB::StlMesher>();
34  StlMesher_Ptr->m_VDBGridPtr = StlMesher_Ptr->readSTLGrid(fileName, voxelSize, verbose);
35  return StlMesher_Ptr;
36  };

◆ readSTLGrid()

openvdb::FloatGrid::Ptr MF::GB::StlMesher::readSTLGrid ( const std::string &  fileName,
double  voxelSize,
bool  verbose = false 
)

Reads .stl file with tyti stl reader.

Definition at line 12 of file StlMesher.cpp.

Referenced by New().

12  {
13 
14  // Read stl grid with tyti stl reader.
15  auto STLGrid = std::make_unique<MF::RW::STLReaderTyti>(fileName, verbose);
16 
17  // Linear transformation object world-to-grid and grid-to-world coordinates.
18  static openvdb::math::Transform::Ptr transformer = {
19  openvdb::math::Transform::createLinearTransform(voxelSize)};
20 
21  // Mesh adapter structure required by openvdb meshToVolume.
22  struct MeshAdapter {
23  const std::vector<tyti::stl::vec3> in_vertices;
24  const double in_voxelSize;
25 
26  MeshAdapter(tyti::stl::basic_solid<float> &grid, const double voxelSize) : in_vertices(grid.vertices), in_voxelSize(voxelSize) {}
27  size_t pointCount() const { return in_vertices.size(); }
28  size_t vertexCount(size_t n) const { return 3; }
29  size_t vertexCount() const { return 3; }
30  size_t polygonCount() const { return pointCount() / vertexCount(); }
31 
32  // Return position pos in local grid index space for polygon n and vertex v
33  void getIndexSpacePoint(size_t n, size_t v, openvdb::Vec3d &pos) const {
34  const size_t offset = 3 * n + v;
35  const openvdb::Vec3d &vertex = {in_vertices[offset].data[0], in_vertices[offset].data[1],
36  in_vertices[offset].data[2]};
37  pos = transformer->worldToIndexCellCentered(vertex).asVec3d();
38  //pos = transformer->worldToIndexNodeCentered(vertex).asVec3d();
39  }
40  };
41 
42  const MeshAdapter mesh_adapter(STLGrid->getSTLGrid_ref().first, voxelSize);
43  // Conversion of surface grid to volumetric grid (openvdb level-set grid: inside (-), outside (+)).
44  m_VDBGridPtr = openvdb::tools::meshToVolume<openvdb::FloatGrid, MeshAdapter>(mesh_adapter, *transformer, 3.0, 3.0);
45  return m_VDBGridPtr;
46  }

The documentation for this class was generated from the following files: