VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbTriFaceMesh3D.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
35
36#include <basics/Timer/Timer.h>
49#include <cstdint>
50#include <limits>
51#include <unordered_map>
52
53#define MAX_ITER 10
54
55using namespace std;
56
58{
59 this->setName("CAB_GbTriFaceMesh3D");
60 this->nodes = new vector<Vertex>;
61 this->triangles = new vector<TriFace>;
62 this->consistent = false;
64}
65/*=======================================================================*/
67 KDTREE_SPLITAGORITHM splitAlg, bool removeRedundantNodes)
68 : GbObject3D(), nodes(nodes), triangles(triangles), kdtreeSplitAlg(splitAlg)
69{
70 if (name.empty())
71 throw UbException(UB_EXARGS, "no name specified");
72 if (!nodes)
73 throw UbException(UB_EXARGS, "no nodes specified");
74 if (!triangles)
75 throw UbException(UB_EXARGS, "no triangles specified");
76
77 this->setName(name);
78
80 this->deleteRedundantNodes(); // dort wird autoamtisch calculateValues() aufgerufen
81 } else {
82 this->calculateValues();
83 }
84}
85/*=======================================================================*/
87{
88 if (nodes) {
89 delete nodes;
90 nodes = NULL;
91 }
92 if (triangles) {
93 delete triangles;
95 }
96 if (kdTree) {
97 delete kdTree;
98 kdTree = NULL;
99 }
100}
101/*======================================================================*/
103{
104 //nodes = NULL;
105 //triangles = NULL;
106 x1min = 0.0;
107 x1max = 0.0;
108 x1center = 0.0;
109 x2min = 0.0;
110 x2max = 0.0;
111 x2center = 0.0;
112 x3min = 0.0;
113 x3max = 0.0;
114 x3center = 0.0;
115 consistent = false;
116}
117/*======================================================================*/
119{
122
123 int numberNodes = (int)this->nodes->size();
124
125 double x, y, z;
126 for (int u = 0; u < numberNodes; u++) {
127 x = (*nodes)[u].x;
128 y = (*nodes)[u].y;
129 z = (*nodes)[u].z;
130 newNodes->push_back(GbTriFaceMesh3D::Vertex((float)x, (float)y, (float)z));
131 }
132 int numberTris = (int)this->triangles->size();
133 UBLOG(logDEBUG1, "numberTris:" << numberTris);
134
135 int id1, id2, id3;
136 for (int u = 0; u < numberTris; u++) {
137 id1 = (*this->triangles)[u].v1;
138 id2 = (*this->triangles)[u].v2;
139 id3 = (*this->triangles)[u].v3;
141 // cout<<u<<" - id1,id2,id3:"<<id1<<","<<id2<<","<<id3<<endl;
142 }
143 UBLOG(logDEBUG1, "Tris gelesen");
144
145 GbTriFaceMesh3D *mesh = new GbTriFaceMesh3D("no name", newNodes, newTriangles);
146 UBLOG(logDEBUG1, "mesh cloned ...");
147
148 return mesh;
149}
150
151/*======================================================================*/
152// checks for doppelt nodes und fixed Dreicke die zweimal denselben Knoten haben
154{
155 // Fast approximate deduplication: quantize vertices to a small grid and merge identical keys.
156 const double eps = 1.0e-7; // quantization step
157 auto quantize = [eps](double v) { return static_cast<int64_t>(std::llround(v / eps)); };
158 struct Key {
159 int64_t x, y, z;
160 bool operator==(const Key &rhs) const { return x == rhs.x && y == rhs.y && z == rhs.z; }
161 };
162 struct KeyHash {
163 size_t operator()(const Key &k) const
164 {
165 // Simple mix of three 64-bit ints
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));
169 return h;
170 }
171 };
172
174 vector<Vertex> &oldNodes = *this->nodes;
176 newNodes.reserve(oldNodes.size());
177
178 std::unordered_map<Key, int, KeyHash> lut;
179 lut.reserve(oldNodes.size());
180
181 for (size_t t = 0; t < tris.size(); ++t) {
182 TriFace &tri = tris[t];
183 for (int v = 0; v < 3; ++v) {
184 Vertex vert = tri.getNode(v, oldNodes);
185 Key key{quantize(vert.x), quantize(vert.y), quantize(vert.z)};
186 auto it = lut.find(key);
187 if (it == lut.end()) {
188 newNodes.push_back(vert);
189 int idx = static_cast<int>(newNodes.size() - 1);
190 lut.emplace(key, idx);
191 tri.setNode(v, idx);
192 } else {
193 tri.setNode(v, it->second);
194 }
195 }
196 }
197
198 std::swap(*nodes, newNodes);
199
200 // Filter degenerate triangles (duplicate indices or near-zero area) and log a compact summary
201 size_t dupIdx = 0, tinyArea = 0;
202 double minArea2 = std::numeric_limits<double>::max();
203 std::vector<TriFace> cleaned;
204 cleaned.reserve(tris.size());
205 const double minArea2Threshold = 1.0e-18; // squared area threshold to drop lines/points
206
207 for (const auto &tri : tris) {
208 int i0 = tri.getIndexVertex1();
209 int i1 = tri.getIndexVertex2();
210 int i2 = tri.getIndexVertex3();
211 if (i0 == i1 || i0 == i2 || i1 == i2) {
212 ++dupIdx;
213 continue;
214 }
215 const Vertex &a = (*nodes)[i0];
216 const Vertex &b = (*nodes)[i1];
217 const Vertex &c = (*nodes)[i2];
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;
223 double area2 = nx * nx + ny * ny + nz * nz;
224 minArea2 = std::min(minArea2, area2);
225 if (area2 < minArea2Threshold) {
226 ++tinyArea;
227 continue;
228 }
229 cleaned.push_back(tri);
230 }
231 tris.swap(cleaned);
232 UBLOG(logINFO, "deleteRedundantNodes summary: dropped dupIdx=" << dupIdx << " tinyArea=" << tinyArea
233 << " kept=" << tris.size() << " minArea2="
234 << (minArea2 == std::numeric_limits<double>::max()
235 ? 0.0
236 : minArea2));
237
238 this->calculateValues();
239}
240/*======================================================================*/
242{
243 if (kdTree && mode != this->kdtreeSplitAlg) {
244 delete kdTree;
245 kdTree = NULL;
246 }
247 this->kdtreeSplitAlg = mode;
248}
249
251{
252 if (this->kdTree)
253 return this->kdTree;
254
255 vf::basics::Timer timer;
256 timer.start();
257
258 try {
259 if (this->kdtreeSplitAlg == KDTREE_SAHPLIT)
261 else
263
264 UBLOG(logDEBUG3, "GbTriFaceMesh3D::ensureKdTree - built kdTree in "
265 << timer.getCurrentRuntimeInSeconds() << " seconds");
266 } catch (const std::exception &ex) {
267 UBLOG(logWARNING, "GbTriFaceMesh3D::ensureKdTree - failed to build kdTree: " << ex.what());
268 delete this->kdTree;
269 this->kdTree = nullptr;
270 }
271
272 return this->kdTree;
273}
274/*======================================================================*/
280{
282 ss << "GbTriFaceMesh3D[";
283 ss << (int)this->triangles->size() << "-Triangles, " << (int)this->nodes->size() << "-Nodes, " << endl;
284 ss << "]";
285 return (ss.str());
286}
302{
305
306 double x1, x2, x3, y1, y2, y3, z1, z2, z3, G3i;
307 // double rSP1 = 0.0;double rSP2 = 0.0;double rSP3 = 0.0;
308 double volume = 0.0;
309 for (size_t t = 0; t < tris.size(); t++) {
312 y1 = triangle.getV1y(vertices);
313 z1 = triangle.getV1z(vertices);
314 x2 = triangle.getV2x(vertices);
315 y2 = triangle.getV2y(vertices);
316 z2 = triangle.getV2z(vertices);
317 x3 = triangle.getV3x(vertices);
318 y3 = triangle.getV3y(vertices);
319 z3 = triangle.getV3z(vertices);
320 G3i = x1 * (y2 * z3 - z2 * y3) + y1 * (z2 * x3 - x2 * z3) + z1 * (x2 * y3 - y2 * x3);
321 volume = volume + G3i / 6.0;
322 }
323 return volume;
324}
325/*===============================================*/
327{
330
331 double x1, x2, x3, y1, y2, y3, z1, z2, z3;
332 double G3i;
333 double rSP1 = 0.0, rSP2 = 0.0, rSP3 = 0.0, volume = 0.0;
334
335 for (size_t t = 0; t < tris.size(); t++) {
338 y1 = triangle.getV1y(vertices);
339 z1 = triangle.getV1z(vertices);
340 x2 = triangle.getV2x(vertices);
341 y2 = triangle.getV2y(vertices);
342 z2 = triangle.getV2z(vertices);
343 x3 = triangle.getV3x(vertices);
344 y3 = triangle.getV3y(vertices);
345 z3 = triangle.getV3z(vertices);
346 G3i = x1 * (y2 * z3 - z2 * y3) + y1 * (z2 * x3 - x2 * z3) + z1 * (x2 * y3 - y2 * x3);
347 volume = volume + G3i / 6.0;
348 rSP1 = rSP1 + G3i * (x1 + x2 + x3);
349 rSP2 = rSP2 + G3i * (y1 + y2 + y3);
350 rSP3 = rSP3 + G3i * (z1 + z2 + z3);
351 }
352 rSP1 = rSP1 / (24.0 * volume);
353 rSP2 = rSP2 / (24.0 * volume);
354 rSP3 = rSP3 / (24.0 * volume);
355
356 return { rSP1, rSP2, rSP3 };
357}
358/*===============================================*/
360{
362
363 double x1, x2, x3, y1, y2, y3, z1, z2, z3;
364 double G3i;
365 double xx, yy, zz, xy, yz, zx;
366 double rSP1 = 0.0;
367 double rSP2 = 0.0;
368 double rSP3 = 0.0;
369 double volume = 0.0;
370 double top11 = 0.0;
371 double top22 = 0.0;
372 double top33 = 0.0;
373 double top12 = 0.0;
374 double top23 = 0.0;
375 double top13 = 0.0;
376 int size = (int)this->triangles->size();
377 for (int u = 0; u < size; u++) {
378 TriFace &triangle = (*this->triangles)[u];
380 y1 = triangle.getV1y(vertices);
381 z1 = triangle.getV1z(vertices);
382 x2 = triangle.getV2x(vertices);
383 y2 = triangle.getV2y(vertices);
384 z2 = triangle.getV2z(vertices);
385 x3 = triangle.getV3x(vertices);
386 y3 = triangle.getV3y(vertices);
387 z3 = triangle.getV3z(vertices);
388 G3i = x1 * (y2 * z3 - z2 * y3) + y1 * (z2 * x3 - x2 * z3) + z1 * (x2 * y3 - y2 * x3);
389 volume = volume + G3i / 6.0;
390 rSP1 = rSP1 + G3i * (x1 + x2 + x3);
391 rSP2 = rSP2 + G3i * (y1 + y2 + y3);
392 rSP3 = rSP3 + G3i * (z1 + z2 + z3);
393 }
394 rSP1 = rSP1 / (24.0 * volume);
395 rSP2 = rSP2 / (24.0 * volume);
396 rSP3 = rSP3 / (24.0 * volume);
397
398 double x1s = 0.0; // rSP1;//0.0;//
399 double x2s = 0.0; // rSP2;//0.0;//
400 double x3s = 0.0; // rSP3;//0.0;//
401
402 for (int u = 0; u < size; u++) {
403 TriFace &triangle = (*this->triangles)[u];
404 x1 = triangle.getV1x(vertices) - x1s;
405 y1 = triangle.getV1y(vertices) - x2s;
406 z1 = triangle.getV1z(vertices) - x3s;
407 x2 = triangle.getV2x(vertices) - x1s;
408 y2 = triangle.getV2y(vertices) - x2s;
409 z2 = triangle.getV2z(vertices) - x3s;
410 x3 = triangle.getV3x(vertices) - x1s;
411 y3 = triangle.getV3y(vertices) - x2s;
412 z3 = triangle.getV3z(vertices) - x3s;
413 G3i = x1 * (y2 * z3 - z2 * y3) + y1 * (z2 * x3 - x2 * z3) + z1 * (x2 * y3 - y2 * x3);
414 // rSP1 = rSP1+G3i*(x1+x2+x3)/(24.0*volume);
415 // rSP2 = rSP2+G3i*(y1+y2+y3)/(24.0*volume);
416 // rSP3 = rSP3+G3i*(z1+z2+z3)/(24.0*volume);
417 xx = x1 * x1 + x2 * x2 + x3 * x3 + x1 * x2 + x2 * x3 + x3 * x1;
418 yy = y1 * y1 + y2 * y2 + y3 * y3 + y1 * y2 + y2 * y3 + y3 * y1;
419 zz = z1 * z1 + z2 * z2 + z3 * z3 + z1 * z2 + z2 * z3 + z3 * z1;
420 top11 = top11 + (yy + zz) * rhoP * G3i / 60.;
421 top22 = top22 + (xx + zz) * rhoP * G3i / 60.;
422 top33 = top33 + (yy + xx) * rhoP * G3i / 60.;
423 xy = 2.0 * (x1 * y1 + x2 * y2 + x3 * y3) + x2 * y3 + x3 * y1 + x1 * y2 + x3 * y2 + x1 * y3 + x2 * y1;
424 yz = 2.0 * (y1 * z1 + y2 * z2 + y3 * z3) + y2 * z3 + y3 * z1 + y1 * z2 + y3 * z2 + y1 * z3 + y2 * z1;
425 zx = 2.0 * (z1 * x1 + z2 * x2 + z3 * x3) + z2 * x3 + z3 * x1 + z1 * x2 + z3 * x2 + z1 * x3 + z2 * x1;
426 top12 = top12 - xy * rhoP * G3i / 120.;
427 top23 = top23 - yz * rhoP * G3i / 120.;
428 top13 = top13 - zx * rhoP * G3i / 120.;
429 }
430 // Satz von Steiner ...
431 top11 = top11 - rhoP * volume * (rSP2 * rSP2 + rSP3 + rSP3);
432 top22 = top22 - rhoP * volume * (rSP3 * rSP3 + rSP1 * rSP1);
433 top33 = top33 - rhoP * volume * (rSP1 * rSP1 + rSP2 * rSP2);
434 top12 = top12 + rhoP * volume * rSP1 * rSP2;
435 top23 = top23 + rhoP * volume * rSP2 * rSP3;
436 top13 = top13 + rhoP * volume * rSP3 * rSP1;
437
438 cout << "Volume:" << volume << "\n Traegheitsmomente:\n";
439 cout << " top11:" << top11 << " top22:" << top22 << " top33:" << top33 << endl;
440 cout << " top12:" << top12 << " top23:" << top23 << " top13:" << top13 << endl;
441
442 return { top11, top22, top33, top12, top23, top13 };
443}
444/*==============================================================*/
446{
447 relationVertTris.clear();
448
449 if (nodes->empty()) {
450 x1min = x1max = x2min = x2max = x3min = x3max = 0.0;
451 } else {
452 Vertex &v = (*nodes)[0];
453 x1min = x1max = v.x;
454 x2min = x2max = v.y;
455 x3min = x3max = v.z;
456
457 for (size_t i = 1; i < this->nodes->size(); i++) {
458 Vertex &v1 = (*nodes)[i];
459
460 x1min = ub_math::min<double>(x1min, v1.x);
461 x2min = ub_math::min<double>(x2min, v1.y);
462 x3min = ub_math::min<double>(x3min, v1.z);
463
464 x1max = ub_math::max<double>(x1max, v1.x);
465 x2max = ub_math::max<double>(x2max, v1.y);
466 x3max = ub_math::max<double>(x3max, v1.z);
467 }
468 x1center = 0.5 * (x1min + x1max);
469 x2center = 0.5 * (x2min + x2max);
470 x3center = 0.5 * (x3min + x3max);
471
473 vector<Vertex> &verts = *this->nodes;
474 for (size_t i = 0; i < this->triangles->size(); i++) {
475 tris[i].calculateNormal(verts);
476 }
477 // relation Vertex <-> Triangle ermitteln
479 for (size_t t = 0; t < tris.size(); t++) {
480 TriFace &tri = tris[t];
481 relationVertTris.insert(make_pair(&verts[tri.v1], &tri));
482 relationVertTris.insert(make_pair(&verts[tri.v2], &tri));
483 relationVertTris.insert(make_pair(&verts[tri.v3], &tri));
484 }
485 }
486 }
487 if (kdTree) {
488 delete kdTree;
489 kdTree = NULL;
490 }
491
492 this->consistent = true;
493}
494/*=========================================================================*/
495std::vector<GbTriFaceMesh3D::TriFace *> GbTriFaceMesh3D::getTrianglesForVertex(Vertex *vertex)
496{
499 consistent = false;
500 }
501 if (!consistent)
502 this->calculateValues();
503
504 typedef std::multimap<Vertex *, TriFace *>::iterator Iterator;
506
507 std::vector<TriFace *> tmpTris;
508 for (Iterator pos = objRange.first; pos != objRange.second; ++pos)
509 tmpTris.push_back(pos->second);
510
511 return tmpTris;
512}
513/*=======================================================*/
514void GbTriFaceMesh3D::setCenterCoordinates(const double &x1, const double &x2, const double &x3)
515{
516 this->translate(x1 - getX1Centroid(), x2 - getX2Centroid(), x3 - getX3Centroid());
517}
518
519/*======================================================================*/
521{
522 throw UbException(UB_EXARGS, "not implemented for " + (std::string) typeid(*this).name());
523}
524
525/*======================================================================*/
526void GbTriFaceMesh3D::scale(const double &sx1, const double &sx2, const double &sx3)
527{
529 1.0, 0.0, 0.0, 0.0);
531 sx3, 0, 0, 0);
532
534 for (size_t i = 0; i < vertices.size(); i++) {
535 Vertex &v = vertices[i];
536 double p1x1 = trafoForw.transformForwardToX1Coordinate(v.x, v.y, v.z);
537 double p1x2 = trafoForw.transformForwardToX2Coordinate(v.x, v.y, v.z);
538 double p1x3 = trafoForw.transformForwardToX3Coordinate(v.x, v.y, v.z);
539 v.x = (float)trafoBack.transformBackwardToX1Coordinate(p1x1, p1x2, p1x3);
540 v.y = (float)trafoBack.transformBackwardToX2Coordinate(p1x1, p1x2, p1x3);
541 v.z = (float)trafoBack.transformBackwardToX3Coordinate(p1x1, p1x2, p1x3);
542 }
543 this->calculateValues();
544}
545/*======================================================================*/
546void GbTriFaceMesh3D::rotate(const double &alpha, const double &beta, const double &gamma)
547{
549 1.0, 0.0, 0.0, 0.0);
551 1.0, alpha, beta, gamma);
552
554 for (size_t i = 0; i < vertices.size(); i++) {
555 Vertex &v = vertices[i];
556 double p1x1 = trafoForw.transformForwardToX1Coordinate(v.x, v.y, v.z);
557 double p1x2 = trafoForw.transformForwardToX2Coordinate(v.x, v.y, v.z);
558 double p1x3 = trafoForw.transformForwardToX3Coordinate(v.x, v.y, v.z);
559 v.x = (float)trafoBack.transformBackwardToX1Coordinate(p1x1, p1x2, p1x3);
560 v.y = (float)trafoBack.transformBackwardToX2Coordinate(p1x1, p1x2, p1x3);
561 v.z = (float)trafoBack.transformBackwardToX3Coordinate(p1x1, p1x2, p1x3);
562 }
563 this->calculateValues();
564}
565/*======================================================================*/
566void GbTriFaceMesh3D::rotateAroundPoint(const double &px1, const double &px2, const double &px3, const double &alpha,
567 const double &beta, const double &gamma)
568{
569 CoordinateTransformation3D trafoForw(px1, px2, px3, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0);
570 CoordinateTransformation3D trafoBack(px1, px2, px3, 1.0, 1.0, 1.0, alpha, beta, gamma);
571
573 for (size_t i = 0; i < vertices.size(); i++) {
574 Vertex &v = vertices[i];
575 double p1x1 = trafoForw.transformForwardToX1Coordinate(v.x, v.y, v.z);
576 double p1x2 = trafoForw.transformForwardToX2Coordinate(v.x, v.y, v.z);
577 double p1x3 = trafoForw.transformForwardToX3Coordinate(v.x, v.y, v.z);
578 v.x = (float)trafoBack.transformBackwardToX1Coordinate(p1x1, p1x2, p1x3);
579 v.y = (float)trafoBack.transformBackwardToX2Coordinate(p1x1, p1x2, p1x3);
580 v.z = (float)trafoBack.transformBackwardToX3Coordinate(p1x1, p1x2, p1x3);
581 }
582 this->calculateValues();
583}
584
585/*======================================================================*/
586void GbTriFaceMesh3D::translate(const double &x1, const double &x2, const double &x3)
587{
589 for (size_t i = 0; i < vertices.size(); i++) {
590 Vertex &v = vertices[i];
591 v.x += static_cast<float>(x1);
592 v.y += static_cast<float>(x2);
593 v.z += static_cast<float>(x3);
594 }
595 this->calculateValues();
596}
597/*======================================================================*/
599{
600 // SirAnn: eine miese Speicherlochmethode
601 // hier werden dynmamische Objekte angelegt
602 // mit sowas rechnet von aussen kein Mensch!!!
604
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];
609
610 tris[i] = new GbTriangle3D(new GbPoint3D(v1.x, v1.y, v1.z), new GbPoint3D(v2.x, v2.y, v2.z),
611 new GbPoint3D(v3.x, v3.y, v3.z));
612 }
613 return tris;
614}
615/*=======================================================*/
617{
618 int nodeNr = int(pts.size());
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];
623 pts.push_back(makeUbTuple(v1.x, v1.y, v1.z));
624 pts.push_back(makeUbTuple(v2.x, v2.y, v2.z));
625 pts.push_back(makeUbTuple(v3.x, v3.y, v3.z));
626
627 tris.push_back(makeUbTuple(nodeNr, nodeNr + 1, nodeNr + 2));
628 nodeNr += 3;
629 }
630}
631/*======================================================================*/
632// bool GbTriFaceMesh3D::isPointInGbObject3D(const double& x1, const double& x2, const double& x3, int counter)
633//{
634//
635//
636// if( !nodes->empty() )
637// {
638// //Baum erstellen, wen noch keiner vorhanden
639// if( !kdTree)
640// {
641// UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree start");
642// vf::basics::Timer timer; timer.start();
643// if(kdtreeSplitAlg == KDTREE_SAHPLIT )
644// {
645// UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
646// this->kdTree = new kd_tree::Tree<double>( *this, kd_tree::SAHSplit<double>() );
647// }
648// else if(kdtreeSplitAlg == KDTREE_SPATIALSPLIT)
649// {
650// UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
651// this->kdTree = new kd_tree::Tree<double>( *this, kd_tree::SpatialMedianSplit<double>() );
652// }
653// else throw UbException(UB_EXARGS, "unknown kdtree split option)" );
654// UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - built kdTree in "<<timer.getCurrentRuntimeInSeconds()<<"seconds");
655// }
656//
657// //eigentlicher PIO-Test
658// //int iSec;
659// //for(int i=0; i<100; i++)
660// //{
661// // kd_tree::Ray<double> ray( x1, x2, x3 //, 1, 0 ,0 );
662// // , ( x1 < x1center ? UbRandom::rand(-1.0,-0.001, 10) : UbRandom::rand(0.001, 1.0, 10) )
663// // , ( x2 < x2center ? UbRandom::rand(-1.0,-0.001, 10) : UbRandom::rand(0.001, 1.0, 10) )
664// // , ( x3 < x3center ? UbRandom::rand(-1.0,-0.001, 10) : UbRandom::rand(0.001, 1.0, 10) )
665// );
666// //
667// // iSec = kdTree->intersectRay( ray, kd_tree::CountRayIntersectionHandler<double>() );
668// //
669// // if( iSec != kd_tree::Intersection::INTERSECT_EDGE ) //KEINE Kante getroffen
670// // {
671// // if(iSec == kd_tree::Intersection::ON_BOUNDARY )
672// // {
673// // return true;
674// // }
675// // return (iSec&1); //ungerade anzahl an schnitten --> drinnen
676// // }
677// // UBLOG(logDEBUG3, "GbTriFaceMesh3D.isPointInGbObject3D.if - an edge was hit ");
678// //}
679// //throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
680// int iSec1,iSec2;
681//
682// kd_tree::Ray<double> ray1( x1, x2, x3, 1.0, 0.0 ,0.0 );
683// iSec1 = kdTree->intersectRay( ray1, kd_tree::CountRayIntersectionHandler<double>() );
684// kd_tree::Ray<double> ray2( x1, x2, x3, -1.0, 0.0 ,0.0 );
685// iSec2 = kdTree->intersectRay( ray2, kd_tree::CountRayIntersectionHandler<double>() );
686//
687// if(iSec1 == kd_tree::Intersection::ON_BOUNDARY || iSec2 == kd_tree::Intersection::ON_BOUNDARY)
688// {
689// return true;
690// }
691// if( iSec1 == kd_tree::Intersection::INTERSECT_EDGE && iSec2 == kd_tree::Intersection::INTERSECT_EDGE)
692// {
693// UBLOG(logINFO, "GbTriFaceMesh3D.isPointInGbObject3D.INTERSECT_EDGE");
694// double eps = ub_math::getEqualityEpsilon<float>()*1000.0;
695// if (counter>100) {return(iSec1&1); UBLOG(logINFO, "NACH 100 Iterationen Eps umsetzen aufgegeben!");}
696// return this->isPointInGbObject3D(x1+eps, x2+eps, x3+eps,(counter+1));
697// }
698// else if( iSec1 == kd_tree::Intersection::INTERSECT_EDGE)
699// {
700// return (iSec2&1);
701// }
702// else if( iSec2 == kd_tree::Intersection::INTERSECT_EDGE)
703// {
704// return (iSec1&1);
705// }
706// else
707// {
708// if((iSec1&1) != (iSec2&1))
709// {
710// UBLOG(logINFO, "GbTriFaceMesh3D.isPointInGbObject3D.iSec1&1 != iSec2&1");
711// double eps = ub_math::getEqualityEpsilon<float>()*1000.0;
712// if (counter>100) {return(iSec1&1); UBLOG(logINFO, "NACH 100 Iterationen Eps umsetzen aufgegeben!");}
713// return this->isPointInGbObject3D(x1+eps, x2+eps, x3+eps,(counter+1));
714// }
715// return iSec1&1;
716// }
717// //throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
718//
719// }
720// return false;
721//}
722bool GbTriFaceMesh3D::isPointInGbObject3D(const double &x1, const double &x2, const double &x3, int counter)
723{
724
725 if (!nodes->empty()) {
726 // Baum erstellen, wen noch keiner vorhanden
727 if (!kdTree) {
728 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree start");
729 vf::basics::Timer timer;
730 timer.start();
732 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
734 } else if (kdtreeSplitAlg == KDTREE_SPATIALSPLIT) {
735 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
737 } else
738 throw UbException(UB_EXARGS, "unknown kdtree split option)");
739 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - built kdTree in " << timer.getCurrentRuntimeInSeconds() << "seconds");
740 }
741
742 // eigentlicher PIO-Test
743 // int iSec;
744 // for(int i=0; i<100; i++)
745 //{
746 // kd_tree::Ray<double> ray( x1, x2, x3 //, 1, 0 ,0 );
747 // , ( x1 < x1center ? UbRandom::rand(-1.0,-0.001, 10) : UbRandom::rand(0.001, 1.0, 10) )
748 // , ( x2 < x2center ? UbRandom::rand(-1.0,-0.001, 10) : UbRandom::rand(0.001, 1.0, 10) )
749 // , ( x3 < x3center ? UbRandom::rand(-1.0,-0.001, 10) : UbRandom::rand(0.001, 1.0, 10) )
750 // );
751 //
752 // iSec = kdTree->intersectRay( ray, kd_tree::CountRayIntersectionHandler<double>() );
753 //
754 // if( iSec != kd_tree::Intersection::INTERSECT_EDGE ) //KEINE Kante getroffen
755 // {
756 // if(iSec == kd_tree::Intersection::ON_BOUNDARY )
757 // {
758 // return true;
759 // }
760 // return (iSec&1); //ungerade anzahl an schnitten --> drinnen
761 // }
762 // UBLOG(logDEBUG3, "GbTriFaceMesh3D.isPointInGbObject3D.if - an edge was hit ");
763 //}
764 // throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
765 int iSec1, iSec2;
766 double eps = 0.05;
767 kd_tree::Ray<double> ray1(x1, x2, x3, 1.0 + eps * ((double)counter), eps * ((double)counter),
768 eps * ((double)counter));
770 kd_tree::Ray<double> ray2(x1, x2, x3, -1.0 - eps * ((double)counter), -eps * ((double)counter),
771 -eps * ((double)counter));
772
774
776 return true;
777 }
779 // UBLOG(logINFO, "GbTriFaceMesh3D.isPointInGbObject3D.INTERSECT_EDGE");
780
781 if (counter > 20) {
782 return (iSec1 & 1); /*UBLOG(logINFO, "NACH 100 Iterationen Eps umsetzen aufgegeben!");*/
783 }
784 return this->isPointInGbObject3D(x1, x2, x3, (counter + 1));
786 return (iSec2 & 1);
788 return (iSec1 & 1);
789 } else {
790 if ((iSec1 & 1) != (iSec2 & 1)) {
791 // UBLOG(logINFO, "GbTriFaceMesh3D.isPointInGbObject3D.iSec1&1 != iSec2&1");
792
793 if (counter > 20) {
794 return (iSec1 & 1); /* UBLOG(logINFO, "NACH 100 Iterationen Eps umsetzen aufgegeben!");*/
795 }
796 return this->isPointInGbObject3D(x1, x2, x3, (counter + 1));
797 }
798 return iSec1 & 1;
799 }
800 // throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
801 }
802 return false;
803}
804/*======================================================================*/
805bool GbTriFaceMesh3D::isPointInGbObject3D(const double &x1, const double &x2, const double &x3)
806{
807 if (!nodes->empty()) {
808 // Baum erstellen, wen noch keiner vorhanden
809 if (!kdTree) {
810 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree start");
811 vf::basics::Timer timer;
812 timer.start();
814 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
815 //cout << "GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit" << std::endl;
817 } else if (kdtreeSplitAlg == KDTREE_SPATIALSPLIT) {
818 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
820 } else
821 throw UbException(UB_EXARGS, "unknown kdtree split option)");
822 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - built kdTree in " << timer.getCurrentRuntimeInSeconds() << "seconds");
823 //cout << "GbTriFaceMesh3D::calculateValues - built kdTree in " << timer.stop() << "seconds" << std::endl;
824 }
825
826 // eigentlicher PIO-Test
827 int iSec;
828 for (int i = 0; i < MAX_ITER; i++) {
829 kd_tree::Ray<double> ray(x1, x2, x3 //, 1, 0 ,0 );
830 ,
831 (x1 < x1center ? UbRandom::rand(-1.0, -0.001, 10) : UbRandom::rand(0.001, 1.0, 10)),
832 (x2 < x2center ? UbRandom::rand(-1.0, -0.001, 10) : UbRandom::rand(0.001, 1.0, 10)),
833 (x3 < x3center ? UbRandom::rand(-1.0, -0.001, 10) : UbRandom::rand(0.001, 1.0, 10)));
834
836
837 if (iSec != kd_tree::Intersection::INTERSECT_EDGE) // KEINE Kante getroffen
838 {
840 return true;
841 }
842 return (iSec & 1); // ungerade anzahl an schnitten --> drinnen
843 }
844 UBLOG(logDEBUG3, "GbTriFaceMesh3D.isPointInGbObject3D.if - an edge was hit ");
845 }
846 throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
847
848 // int iSec1,iSec2;
849 //
850 // kd_tree::Ray<double> ray1( x1, x2, x3, 1.0, 0.0 ,0.0 );
851 // iSec1 = kdTree->intersectRay( ray1, kd_tree::CountRayIntersectionHandler<double>() );
852 // kd_tree::Ray<double> ray2( x1, x2, x3, -1.0, 0.0 ,0.0 );
853 // iSec2 = kdTree->intersectRay( ray2, kd_tree::CountRayIntersectionHandler<double>() );
854
855 // if(iSec1 == kd_tree::Intersection::ON_BOUNDARY || iSec2 == kd_tree::Intersection::ON_BOUNDARY)
856 // {
857 // return true;
858 // }
859 // if( iSec1 == kd_tree::Intersection::INTERSECT_EDGE && iSec2 == kd_tree::Intersection::INTERSECT_EDGE)
860 // {
861 // //UBLOG(logINFO, "GbTriFaceMesh3D.isPointInGbObject3D.INTERSECT_EDGE");
862 // double eps = ub_math::getEqualityEpsilon<double>();
863 // if (counter>100) {return(iSec1&1); UBLOG(logINFO, "NACH 100 Iterationen Eps umsetzen aufgegeben!");}
864 // return this->isPointInGbObject3D(x1+eps, x2+eps, x3+eps,(counter+1));
865 // }
866 // else if( iSec1 == kd_tree::Intersection::INTERSECT_EDGE)
867 // {
868 // return (iSec2&1);
869 // }
870 // else if( iSec2 == kd_tree::Intersection::INTERSECT_EDGE)
871 // {
872 // return (iSec1&1);
873 // }
874 // else
875 // {
876 // if((iSec1&1) != (iSec2&1))
877 // {
878 // UBLOG(logINFO, "GbTriFaceMesh3D.isPointInGbObject3D.iSec1&1 != iSec2&1");
879 // double eps = ub_math::getEqualityEpsilon<double>();
880 // if (counter>100) {return(iSec1&1); UBLOG(logINFO, "NACH 100 Iterationen Eps umsetzen aufgegeben!");}
881 // return this->isPointInGbObject3D(x1+eps, x2+eps, x3+eps,(counter+1));
882 // }
883 // return iSec1&1;
884 // }
885 // //throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
886 }
887 return false;
888}
889/*======================================================================*/
890bool GbTriFaceMesh3D::isPointInGbObject3D(const double &x1, const double &x2, const double &x3, bool &pointIsOnBoundary)
891{
892 if (!nodes->empty()) {
893 // Baum erstellen, wen noch keiner vorhanden
894 if (!kdTree) {
895 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree start");
896 vf::basics::Timer timer;
897 timer.start();
899 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
901 } else if (kdtreeSplitAlg == KDTREE_SPATIALSPLIT) {
902 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
904 } else
905 throw UbException(UB_EXARGS, "unknown kdtree split option)");
906 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - built kdTree in " << timer.getCurrentRuntimeInSeconds() << "seconds");
907 }
908
909 // eigentlicher PIO-Test
910 int iSec;
911 for (int i = 0; i < MAX_ITER; i++) {
913 x1, x2, x3, float((x1 < x1center ? UbRandom::rand(-1.0, -0.001, 10) : UbRandom::rand(0.001, 1.0, 10))),
914 float((x2 < x2center ? UbRandom::rand(-1.0, -0.001, 10) : UbRandom::rand(0.001, 1.0, 10))),
915 float((x3 < x3center ? UbRandom::rand(-1.0, -0.001, 10) : UbRandom::rand(0.001, 1.0, 10))));
916
918
919 if (iSec != kd_tree::Intersection::INTERSECT_EDGE) // KEINE Kante getroffen
920 {
922 pointIsOnBoundary = true;
923 return true;
924 }
925 pointIsOnBoundary = false;
926 return (iSec & 1); // ungerade anzahl an schnitten --> drinnen
927 }
928 }
929
930 throw UbException(UB_EXARGS, "ups, nach 100 Strahlen immer noch kein Ergebnis");
931 }
932
933 return false;
934}
935/*======================================================================*/
936bool GbTriFaceMesh3D::intersectLine(const double &p1_x1, const double &p1_x2, const double &p1_x3, const double &p2_x1,
937 const double &p2_x2, const double &p2_x3)
938{
939 // Baum erstellen, wen noch keiner vorhanden
940 if (!kdTree) {
941 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree start");
942 vf::basics::Timer timer;
943 timer.start();
945 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SAHSplit");
947 } else if (kdtreeSplitAlg == KDTREE_SPATIALSPLIT) {
948 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - build KdTree with SpatialMedianSplit");
950 } else
951 throw UbException(UB_EXARGS, "unknown kdtree split option)");
952 UBLOG(logDEBUG3, "GbTriFaceMesh3D::calculateValues - built kdTree in " << timer.getCurrentRuntimeInSeconds() << "seconds");
953 }
954
957
959}
960/*======================================================================*/
962{
963 throw UbException(UB_EXARGS, "not implemented");
964}
965
966/*======================================================================*/
968 vector<string> *datanames,
969 std::vector<std::vector<double>> *nodedata)
970{
971 UBLOG(logINFO, "GbTriFaceMesh3D::writeMesh ");
972
975
976 for (size_t i = 0; i < nodes->size(); i++)
977 triNodes[i] = makeUbTuple((*nodes)[i].x, (*nodes)[i].y, (*nodes)[i].z);
978
979 for (size_t i = 0; i < triangles->size(); i++)
980 tris[i] = makeUbTuple((*triangles)[i].v1, (*triangles)[i].v2, (*triangles)[i].v3);
981
983
984 if (!datanames || datanames->empty() || !nodedata) {
986 } else {
988 }
989
990 if (writeNormals) {
992 vector<UbTupleInt2> lines(triangles->size());
993 for (size_t i = 0; i < triangles->size(); i++) {
994 TriFace &triangle = (*triangles)[i];
995 lineNodes[i * 2] = makeUbTuple(triangle.getX1Centroid(*nodes), triangle.getX2Centroid(*nodes),
996 triangle.getX3Centroid(*nodes));
997
998 lineNodes[i * 2 + 1] = makeUbTuple((float)(triangle.getX1Centroid(*nodes) + 1.0 * triangle.nx),
999 (float)(triangle.getX2Centroid(*nodes) + 1.0 * triangle.ny),
1000 (float)(triangle.getX3Centroid(*nodes) + 1.0 * triangle.nz));
1001
1002 lines[i] = makeUbTuple((int)i * 2, (int)i * 2 + 1);
1003 }
1004 val<2>(filenames) = writer->writeLines(filename + "_normals", lineNodes, lines);
1005 }
1006
1007 return filenames;
1008}
1009/*======================================================================*/
1010void GbTriFaceMesh3D::writeMeshPly(const std::string &filename)
1011{
1012 ofstream out(filename.c_str());
1013 if (!out)
1014 throw UbException(UB_EXARGS, "couldn't open " + filename);
1015
1016 out << "ply" << endl;
1017 out << "format ascii 1.0" << endl;
1018 out << "element vertex " << (int)nodes->size() << endl;
1019 out << "property float x" << endl;
1020 out << "property float y" << endl;
1021 out << "property float z" << endl;
1022 out << "element face " << (int)triangles->size() << endl;
1023 out << "property list uchar int vertex_indices" << endl;
1024 out << "end_header" << endl;
1025
1026 for (size_t i = 0; i < nodes->size(); i++)
1027 out << (*nodes)[i].x << " " << (*nodes)[i].y << " " << (*nodes)[i].z << endl;
1028
1029 for (size_t i = 0; i < triangles->size(); i++)
1030 out << "3 " << (*triangles)[i].v1 << " " << (*triangles)[i].v2 << " " << (*triangles)[i].v3 << endl;
1031}
1032/*======================================================================*/
1034{
1035 UBLOG(logDEBUG1, "GbTriFaceMesh3DCreator::readMeshFromSTLFile !!! Dieses Format hat leider redundante Knoten ...");
1036
1037 int nr = 0;
1038
1039 ifstream in(filename.c_str());
1040 if (!in.good()) {
1041 (*nodes).clear();
1042 (*triangles).clear();
1043 UB_THROW(UbException(UB_EXARGS, "Can not open STL file: " + filename));
1044 }
1045 char title[80];
1046 std::string s0, s1;
1047 float n0, n1, n2, f0, f1, f2, f3, f4, f5, f6, f7, f8;
1048 in.read(title, 80);
1049 while (!in.eof()) {
1050 in >> s0; // facet || endsolid
1051 if (s0 == "facet") {
1052 in >> s1 >> n0 >> n1 >> n2; // normal x y z
1053 in >> s0 >> s1; // outer loop
1054 in >> s0 >> f0 >> f1 >> f2; // vertex x y z
1055 in >> s0 >> f3 >> f4 >> f5; // vertex x y z
1056 in >> s0 >> f6 >> f7 >> f8; // vertex x y z
1057 in >> s0; // endloop
1058 in >> s0; // endfacet
1059 // Generate a new Triangle without Normal as 3 Vertices
1060 nodes->push_back(GbTriFaceMesh3D::Vertex(f0, f1, f2));
1061 nodes->push_back(GbTriFaceMesh3D::Vertex(f3, f4, f5));
1062 nodes->push_back(GbTriFaceMesh3D::Vertex(f6, f7, f8));
1063 triangles->push_back(GbTriFaceMesh3D::TriFace(nr, nr + 1, nr + 2));
1064 nr += 3;
1065 } else if (s0 == "endsolid") {
1066 break;
1067 }
1068 }
1069 in.close();
1070
1072 this->deleteRedundantNodes(); // dort wird autoamtisch calculateValues() aufgerufen
1073 } else {
1074 this->calculateValues();
1075 }
1076 //UBLOG(logDEBUG1, "GbTriFaceMesh3DCreator::readMeshFromSTLFile !!! Dieses Format hat leider redundante Knoten ...");
1077
1078 //string dummy;
1079
1080 //double x, y, z;
1081 //int nr = 0;
1082
1083 //UbFileInputASCII in(filename);
1084 //in.readLine();
1085 //while (dummy != "endsolid") {
1086 // in.readLine();
1087 // in.readLine();
1088 // dummy = in.readString();
1089 // if (dummy != "vertex")
1090 // throw UbException(UB_EXARGS, "no vertex format");
1091 // x = in.readDouble();
1092 // y = in.readDouble();
1093 // z = in.readDouble();
1094 // nodes->push_back(GbTriFaceMesh3D::Vertex((float)x, (float)y, (float)z));
1095 // in.readLine();
1096 // in.readString();
1097 // x = in.readDouble();
1098 // y = in.readDouble();
1099 // z = in.readDouble();
1100 // nodes->push_back(GbTriFaceMesh3D::Vertex((float)x, (float)y, (float)z));
1101 // in.readLine();
1102 // in.readString();
1103 // x = in.readDouble();
1104 // y = in.readDouble();
1105 // z = in.readDouble();
1106 // nodes->push_back(GbTriFaceMesh3D::Vertex((float)x, (float)y, (float)z));
1107 // triangles->push_back(GbTriFaceMesh3D::TriFace(nr, nr + 1, nr + 2));
1108 // in.readLine();
1109 // in.readLine();
1110 // in.readLine();
1111 // dummy = in.readString();
1112 // nr += 3;
1113 // // std::cout<<"read mesh "<< nr <<" \n";
1114 //}
1115
1116 //if (removeRedundantNodes) {
1117 // this->deleteRedundantNodes(); // dort wird autoamtisch calculateValues() aufgerufen
1118 //} else {
1119 // this->calculateValues();
1120 //}
1121}
1122/*======================================================================*/
1124{
1125 int nr = 0;
1126 FILE *f = fopen(filename.c_str(), "rb");
1127 if (!f) {
1128 (*nodes).clear();
1129 (*triangles).clear();
1130 UB_THROW(UbException(UB_EXARGS, "Can not open STL file: " + filename));
1131 }
1132 char title[80];
1133 int nFaces;
1134 size_t sizef = fread(title, 80, 1, f);
1135 sizef = fread((void *)&nFaces, 4, 1, f);
1136 float v[12]; // normal=3, vertices=3*3 = 12
1137 unsigned short uint16;
1138 // Every Face is 50 Bytes: Normal(3*float), Vertices(9*float), 2 Bytes Spacer
1139 for (int i = 0; i < nFaces; ++i) {
1140 for (size_t j = 0; j < 12; ++j) {
1141 sizef = fread((void *)&v[j], sizeof(float), 1, f);
1142 }
1143 sizef = fread((void *)&uint16, sizeof(unsigned short), 1, f); // spacer between successive faces
1144 nodes->push_back(GbTriFaceMesh3D::Vertex(v[3], v[4], v[5]));
1145 nodes->push_back(GbTriFaceMesh3D::Vertex(v[6], v[7], v[8]));
1146 nodes->push_back(GbTriFaceMesh3D::Vertex(v[9], v[10], v[11]));
1147 triangles->push_back(GbTriFaceMesh3D::TriFace(nr, nr + 1, nr + 2));
1148 nr += 3;
1149 }
1150 (void)sizef;
1151 fclose(f);
1152
1154 this->deleteRedundantNodes(); // dort wird autoamtisch calculateValues() aufgerufen
1155 } else {
1156 this->calculateValues();
1157 }
1158}
1159
A class provides 3d coordinate transformation.
This Class provides basic 3D line objects.
Definition GbLine3D.h:59
This Interface provides basic 3D geometry objects methods.
Definition GbObject3D.h:64
This Class provides basic 3D point objects.
Definition GbPoint3D.h:49
float & getV1x(std::vector< Vertex > &nodes)
KDTREE_SPLITAGORITHM kdtreeSplitAlg
double getX1Centroid() override
std::string filename
std::multimap< Vertex *, TriFace * > relationVertTris
std::vector< TriFace > * triangles
double getX3Centroid() override
kd_tree::Tree< double > * kdTree
std::vector< Vertex > * nodes
double getX2Centroid() override
This Class provides basic 3D triangle objects.
void setName(std::string name)
Definition ObObject.h:52
static int rand(const int &min, const int &max)
Definition UbRandom.h:72
A class implements a tuple.
Definition UbTuple.h:477
virtual std::string writeLines(const std::string &, std::vector< UbTupleFloat3 > &, std::vector< UbTupleInt2 > &)
Definition WbWriter.h:83
virtual std::string writeTrianglesWithNodeData(const std::string &, std::vector< UbTupleFloat3 > &, std::vector< UbTupleInt3 > &, std::vector< std::string > &, std::vector< std::vector< double > > &)
Definition WbWriter.h:121
virtual std::string writeTriangles(const std::string &, std::vector< UbTupleFloat3 > &, std::vector< UbTupleInt3 > &)
Definition WbWriter.h:116
bool intersectLine(const UbTuple< T, T, T > &n1, const UbTuple< T, T, T > &n2, const LineIntersectionHandler< T > &iHandler)
Definition KdTree.h:67
int intersectRay(const Ray< T > &ray, const RayIntersectionHandler< T > &iHandler)
Definition KdTree.h:74
double getCurrentRuntimeInSeconds() const
Definition Timer.cpp:63
constexpr bool operator==(const real3 &a, const real3 &b)
Definition DataTypes.h:107
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)
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
#define MAX_ITER
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)
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
const uint ny
const uint nz
const uint nx
#define UB_THROW(e)
Definition UbException.h:78
#define UBLOG(level, logtext)
Definition UbLogger.h:327
#define UB_EXARGS
Definition UbException.h:73
UbTuple< double, double, double, double, double, double > UbTupleDouble6
Definition UbTuple.h:636
UbTuple< double, double, double > UbTupleDouble3
Definition UbTuple.h:634
UbTuple< T1 > makeUbTuple(T1 const &a1)
Definition UbTuple.h:554
@ logDEBUG1
Definition UbLogger.h:54
@ logWARNING
Definition UbLogger.h:54
@ logINFO
Definition UbLogger.h:54
@ logDEBUG3
Definition UbLogger.h:54
static const int ON_BOUNDARY
Definition KdUtilities.h:55
static const int INTERSECT_EDGE
Definition KdUtilities.h:56
static const int NO_INTERSECTION
Definition KdUtilities.h:58