51#include <unordered_map>
59 this->
setName(
"CAB_GbTriFaceMesh3D");
123 int numberNodes = (
int)this->nodes->size();
126 for (
int u = 0;
u < numberNodes;
u++) {
156 const double eps = 1.0e-7;
163 size_t operator()(
const Key &k)
const
166 size_t h =
static_cast<size_t>(k.x);
167 h ^=
static_cast<size_t>(k.y + 0x9e3779b97f4a7c15ULL + (
h << 6) + (
h >> 2));
168 h ^=
static_cast<size_t>(k.z + 0x9e3779b97f4a7c15ULL + (
h << 6) + (
h >> 2));
178 std::unordered_map<Key, int, KeyHash>
lut;
181 for (
size_t t = 0;
t <
tris.size(); ++
t) {
183 for (
int v = 0; v < 3; ++v) {
186 auto it =
lut.find(key);
187 if (
it ==
lut.end()) {
193 tri.setNode(v,
it->second);
202 double minArea2 = std::numeric_limits<double>::max();
208 int i0 =
tri.getIndexVertex1();
209 int i1 =
tri.getIndexVertex2();
210 int i2 =
tri.getIndexVertex3();
218 double ux =
b.
x - a.
x,
uy =
b.y - a.
y, uz =
b.z - a.
z;
219 double vx =
c.x - a.
x, vy =
c.y - a.
y, vz =
c.z - a.
z;
220 double nx =
uy * vz - uz * vy;
221 double ny = uz * vx - ux * vz;
222 double nz = ux * vy -
uy * vx;
233 <<
" kept=" <<
tris.size() <<
" minArea2="
234 << (
minArea2 == std::numeric_limits<double>::max()
264 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::ensureKdTree - built kdTree in "
266 }
catch (
const std::exception &
ex) {
267 UBLOG(
logWARNING,
"GbTriFaceMesh3D::ensureKdTree - failed to build kdTree: " <<
ex.what());
282 ss <<
"GbTriFaceMesh3D[";
283 ss << (
int)this->triangles->size() <<
"-Triangles, " << (
int)this->nodes->size() <<
"-Nodes, " <<
endl;
309 for (
size_t t = 0;
t <
tris.size();
t++) {
335 for (
size_t t = 0;
t <
tris.size();
t++) {
376 int size = (
int)this->triangles->size();
377 for (
int u = 0;
u < size;
u++) {
402 for (
int u = 0;
u < size;
u++) {
417 xx = x1 * x1 + x2 * x2 + x3 * x3 + x1 * x2 + x2 * x3 + x3 * x1;
423 xy = 2.0 * (x1 *
y1 + x2 *
y2 + x3 *
y3) + x2 *
y3 + x3 *
y1 + x1 *
y2 + x3 *
y2 + x1 *
y3 + x2 *
y1;
425 zx = 2.0 * (
z1 * x1 +
z2 * x2 +
z3 * x3) +
z2 * x3 +
z3 * x1 +
z1 * x2 +
z3 * x2 +
z1 * x3 +
z2 * x1;
438 cout <<
"Volume:" <<
volume <<
"\n Traegheitsmomente:\n";
449 if (
nodes->empty()) {
457 for (
size_t i = 1;
i < this->nodes->size();
i++) {
474 for (
size_t i = 0;
i < this->triangles->size();
i++) {
479 for (
size_t t = 0;
t <
tris.size();
t++) {
504 typedef std::multimap<Vertex *, TriFace *>::iterator
Iterator;
507 std::vector<TriFace *>
tmpTris;
551 1.0, alpha, beta, gamma);
567 const double &beta,
const double &gamma)
591 v.
x +=
static_cast<float>(x1);
592 v.
y +=
static_cast<float>(x2);
593 v.
z +=
static_cast<float>(x3);
605 for (
size_t i = 0;
i < this->triangles->size();
i++) {
606 Vertex &v1 = (*nodes)[(*triangles)[
i].v1];
607 Vertex &v2 = (*nodes)[(*triangles)[
i].v2];
608 Vertex &v3 = (*nodes)[(*triangles)[
i].v3];
619 for (
int i = 0;
i < (
int)this->triangles->size();
i++) {
620 Vertex &v1 = (*nodes)[(*triangles)[
i].v1];
621 Vertex &v2 = (*nodes)[(*triangles)[
i].v2];
622 Vertex &v3 = (*nodes)[(*triangles)[
i].v3];
725 if (!
nodes->empty()) {
728 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree start");
732 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
735 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
768 eps * ((
double)counter));
771 -
eps * ((
double)counter));
807 if (!
nodes->empty()) {
810 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree start");
814 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
818 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
844 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D.isPointInGbObject3D.if - an edge was hit ");
892 if (!
nodes->empty()) {
895 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree start");
899 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
902 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
941 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree start");
945 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
948 UBLOG(
logDEBUG3,
"GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
969 std::vector<std::vector<double>> *
nodedata)
976 for (
size_t i = 0;
i <
nodes->size();
i++)
984 if (!datanames || datanames->empty() || !
nodedata) {
1017 out <<
"format ascii 1.0" <<
endl;
1019 out <<
"property float x" <<
endl;
1020 out <<
"property float y" <<
endl;
1021 out <<
"property float z" <<
endl;
1023 out <<
"property list uchar int vertex_indices" <<
endl;
1026 for (
size_t i = 0;
i <
nodes->size();
i++)
1027 out << (*
nodes)[
i].x <<
" " << (*nodes)[
i].y <<
" " << (*nodes)[
i].z <<
endl;
1030 out <<
"3 " << (*
triangles)[
i].v1 <<
" " << (*triangles)[
i].v2 <<
" " << (*triangles)[
i].v3 <<
endl;
1035 UBLOG(
logDEBUG1,
"GbTriFaceMesh3DCreator::readMeshFromSTLFile !!! Dieses Format hat leider redundante Knoten ...");
1042 (*triangles).clear();
1047 float n0,
n1,
n2,
f0,
f1,
f2,
f3,
f4,
f5,
f6,
f7,
f8;
1051 if (
s0 ==
"facet") {
1065 }
else if (
s0 ==
"endsolid") {
1129 (*triangles).clear();
1140 for (
size_t j = 0;
j < 12; ++
j) {
1141 sizef =
fread((
void *)&v[
j],
sizeof(
float), 1, f);
This Class provides basic 3D line objects.
This Interface provides basic 3D geometry objects methods.
This Class provides basic 3D point objects.
float & getV1x(std::vector< Vertex > &nodes)
KDTREE_SPLITAGORITHM kdtreeSplitAlg
double getX1Centroid() override
std::multimap< Vertex *, TriFace * > relationVertTris
std::vector< TriFace > * triangles
double getX3Centroid() override
bool buildVertTriRelationMap
kd_tree::Tree< double > * kdTree
std::vector< Vertex > * nodes
double getX2Centroid() override
This Class provides basic 3D triangle objects.
void setName(std::string name)
static int rand(const int &min, const int &max)
A class implements a tuple.
virtual std::string writeLines(const std::string &, std::vector< UbTupleFloat3 > &, std::vector< UbTupleInt2 > &)
virtual std::string writeTrianglesWithNodeData(const std::string &, std::vector< UbTupleFloat3 > &, std::vector< UbTupleInt3 > &, std::vector< std::string > &, std::vector< std::vector< double > > &)
virtual std::string writeTriangles(const std::string &, std::vector< UbTupleFloat3 > &, std::vector< UbTupleInt3 > &)
bool intersectLine(const UbTuple< T, T, T > &n1, const UbTuple< T, T, T > &n2, const LineIntersectionHandler< T > &iHandler)
int intersectRay(const Ray< T > &ray, const RayIntersectionHandler< T > &iHandler)
double getCurrentRuntimeInSeconds() const
constexpr bool operator==(const real3 &a, const real3 &b)
std::shared_ptr< T > SPtr
void rotate(const double &alpha, const double &beta, const double &gamma) override
virtual UbTuple< std::string, std::string > writeMesh(std::string filename, WbWriter *writer, bool writeNormals=false, std::vector< std::string > *datanames=NULL, std::vector< std::vector< double > > *nodedata=NULL)
void setKdTreeSplitAlgorithm(KDTREE_SPLITAGORITHM mode)
kd_tree::Tree< double > * ensureKdTree()
std::vector< Vertex > * getNodes()
void setCenterCoordinates(const double &x1, const double &x2, const double &x3) override
void scale(const double &sx1, const double &sx2, const double &sx3) override
UbTupleDouble6 calculateMomentOfInertia(double rhoP)
void readMeshFromSTLFileBinary(std::string filename, bool removeRedundantNodes)
std::string toString() override
~GbTriFaceMesh3D() override
void readMeshFromSTLFileASCII(std::string filename, bool removeRedundantNodes)
void deleteRedundantNodes()
std::vector< GbTriangle3D * > getSurfaceTriangleSet() override
void rotateAroundPoint(const double &px1, const double &px2, const double &px3, const double &alpha, const double &beta, const double &gamma)
void writeMeshPly(const std::string &filename)
GbTriFaceMesh3D * clone() override
GbLine3D * createClippedLine3D(GbPoint3D &point1, GbPoint3D &point2) override
std::vector< GbTriFaceMesh3D::TriFace * > getTrianglesForVertex(Vertex *vertex)
void translate(const double &x1, const double &x2, const double &x3) override
bool isPointInGbObject3D(const double &x1, const double &x2, const double &x3) override
std::vector< TriFace > * getTriangles()
void addSurfaceTriangleSet(std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &triangles) override
UbTupleDouble3 calculateCenterOfGravity()
bool intersectLine(const double &p1_x1, const double &p1_x2, const double &p1_x3, const double &p2_x1, const double &p2_x2, const double &p2_x3)
#define UBLOG(level, logtext)
UbTuple< double, double, double, double, double, double > UbTupleDouble6
UbTuple< double, double, double > UbTupleDouble3
UbTuple< T1 > makeUbTuple(T1 const &a1)
static const int ON_BOUNDARY
static const int INTERSECT_EDGE
static const int NO_INTERSECTION