MPM-Geomechanics
Material Point Method for simulating geo-materials under large deformation conditions
Loading...
Searching...
No Matches
STLReader.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2021-2025 MPM-Geomechanics Development Team
3
4#ifndef STL_READER_H
5#define STL_READER_H
6
7#include <Eigen/Eigenvalues>
8using namespace Eigen;
9
10#include <string>
11#include <vector>
12
14struct Triangle {
15
16 Vector3d normal;
17 Vector3d v1, v2, v3;
18
21 Vector3d getVertex1() const {
22 return v1;
23 }
24
27 const Vector3d& getVertex2() const {
28 return v2;
29 }
30
33 const Vector3d& getVertex3() const {
34 return v3;
35 }
36
39 const Vector3d& getNormal() const {
40 return normal;
41 }
42
45 Vector3d getCentroid() const {
46 return (v1 + v2 + v3) / 3.0f;
47 }
48
51 double getArea() const {
52 return 0.5f * ((v2 - v1).cross(v3 - v1)).norm();
53 }
54};
55
57class STLReader {
58
59public:
61 bool read(const std::string& filename);
62
65 const std::vector<Triangle>& getTriangles() const;
66
70 void removeTrianglesOutsideLimits(const Vector3d& min, const Vector3d& max);
71
72private:
73
75 std::vector<Triangle> triangles;
76
78 bool readASCII(std::ifstream& file);
79
81 bool readBinary(std::ifstream& file);
82};
83
84#endif
Class to read STL files.
Definition STLReader.h:57
const std::vector< Triangle > & getTriangles() const
Get the triangles of the STL mesh.
bool readASCII(std::ifstream &file)
Read the ASCII STL file.
void removeTrianglesOutsideLimits(const Vector3d &min, const Vector3d &max)
Remove triangles that have all vertices outside the specified bounding box.
bool readBinary(std::ifstream &file)
Read the binary STL file.
bool read(const std::string &filename)
Read the STL file.
std::vector< Triangle > triangles
Vector containing the triangles.
Definition STLReader.h:75
Struct representing a triangle.
Definition STLReader.h:14
Vector3d v1
Definition STLReader.h:17
double getArea() const
Calculate the area of the triangle.
Definition STLReader.h:51
Vector3d getCentroid() const
Calculate the centroid of the triangle.
Definition STLReader.h:45
Vector3d normal
Normal vector of the triangle.
Definition STLReader.h:16
const Vector3d & getVertex2() const
Get the second vertex of the triangle.
Definition STLReader.h:27
const Vector3d & getVertex3() const
Get the third vertex of the triangle.
Definition STLReader.h:33
Vector3d getVertex1() const
Get the first vertex of the triangle.
Definition STLReader.h:21
Vector3d v2
Definition STLReader.h:17
Vector3d v3
Vertices of the triangle.
Definition STLReader.h:17
const Vector3d & getNormal() const
Get the normal of the triangle.
Definition STLReader.h:39