OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
Geometry.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <assert.h>
5#include <vector>
6#include <list>
7#include <map>
8
9#include <bsoncxx/builder/basic/document.hpp>
10
11#include "OldTreeIcon.h"
12
13namespace Geometry {
14
15 // This namespace contains a collection of geometry manipulations on Entities
16
17 class __declspec(dllexport) Node {
18 public:
19 Node() { coord[0] = coord[1] = coord[2] = 0.0; normal[0] = normal[1] = normal[2] = 0.0; uvpar[0] = uvpar[1] = 0.0; };
20 virtual ~Node() {};
21
22 void setCoords(double x, double y, double z) { coord[0] = x; coord[1] = y; coord[2] = z; };
23 void setNormals(double x, double y, double z) { normal[0] = x; normal[1] = y; normal[2] = z; };
24 void setUVpar(double u, double v) { uvpar[0] = u; uvpar[1] = v; };
25
26 double getCoord(int index) { assert(index >= 0 && index < 3); return coord[index]; };
27 double getNormal(int index) { assert(index >= 0 && index < 3); return normal[index]; };
28 double getUVpar(int index) { assert(index >= 0 && index < 2); return uvpar[index]; };
29
30 void setX(double x) { coord[0] = x; };
31 void setY(double y) { coord[1] = y; };
32 void setZ(double z) { coord[2] = z; };
33
34 void setNx(double x) { normal[0] = x; };
35 void setNy(double y) { normal[1] = y; };
36 void setNz(double z) { normal[2] = z; };
37
38 void setU(double u) { uvpar[0] = u; };
39 void setV(double v) { uvpar[1] = v; };
40
41 private:
42 double coord[3];
43 double normal[3];
44 double uvpar[2];
45 };
46
47 class __declspec(dllexport) Triangle {
48 public:
49 Triangle() { node[0] = node[1] = node[2] = 0; faceId = 0; };
50 Triangle(ot::UID node1, ot::UID node2, ot::UID node3, ot::UID id) { node[0] = node1; node[1] = node2; node[2] = node3; faceId = id; };
51 virtual ~Triangle() {};
52
53 void setNodes(ot::UID node1, ot::UID node2, ot::UID node3) { node[0] = node1; node[1] = node2; node[2] = node3; }
54 ot::UID getNode(int index) { assert(index >= 0 && index < 3); return node[index]; };
55
56 void setFaceId(ot::UID id) { faceId = id; };
57 ot::UID getFaceId(void) { return faceId; };
58
59 private:
60 ot::UID node[3];
61 ot::UID faceId;
62 };
63
64 class __declspec(dllexport) Point {
65 public:
66 Point() { coord[0] = coord[1] = coord[2] = 0.0; };
67 Point(const Point &other) { if (&other != this) { coord[0] = other.coord[0]; coord[1] = other.coord[1]; coord[2] = other.coord[2]; } };
68 Point(double x, double y, double z) { coord[0] = x; coord[1] = y; coord[2] = z; };
69 virtual ~Point() {};
70
71 void setCoord(double x, double y, double z) { coord[0] = x; coord[1] = y; coord[2] = z; };
72 double getX(void) { return coord[0]; };
73 double getY(void) { return coord[1]; };
74 double getZ(void) { return coord[2]; };
75
76 private:
77 double coord[3] = {0.,0.,0.};
78 };
79
80 class __declspec(dllexport) Edge {
81 public:
82 Edge() { npoints = 0; points = nullptr; faceId = 0; };
83 virtual ~Edge() { if (points != nullptr) delete[] points; };
84 Edge(const Edge &other) { if (&other != this) { npoints = 0; faceId = other.faceId; if (other.npoints > 0) { npoints = other.npoints; points = new Point[npoints]; for (int i = 0; i < npoints; i++) points[i] = other.points[i]; } } }
85
86 int getNpoints(void) { return npoints; };
87 Point &getPoint(int index) { return points[index]; };
88
89 void setNpoints(int n) { if (points != nullptr) delete[] points; points = new Point[n]; npoints = n; };
90 void setPoint(int index, double x, double y, double z) { points[index].setCoord(x, y, z); };
91
92 void setFaceId(ot::UID id) { faceId = id; };
93 ot::UID getFaceId(void) { return faceId; };
94
95 private:
96 int npoints = 0;
97 Point *points = nullptr;
98 ot::UID faceId = 0;
99 };
100
101 _declspec(dllexport) bsoncxx::document::value getBSON(std::vector<Geometry::Node> &nodes);
102 _declspec(dllexport) bsoncxx::document::value getBSON(std::list<Geometry::Triangle> &triangles);
103 _declspec(dllexport) bsoncxx::document::value getBSON(std::list<Geometry::Edge>& edges);
104 _declspec(dllexport) bsoncxx::document::value getBSON(std::map<ot::UID, std::string>& faceNameMap);
105
106 _declspec(dllexport) void readBSON(bsoncxx::document::view &nodesObj, std::vector<Geometry::Node> &nodes);
107 _declspec(dllexport) void readBSON(bsoncxx::document::view &trianglesObj, std::list<Geometry::Triangle> &triangles);
108 _declspec(dllexport) void readBSON(bsoncxx::document::view& edgesObj, std::list<Geometry::Edge>& edges);
109 _declspec(dllexport) void readBSON(bsoncxx::document::view& faceNamesObj, std::map<ot::UID, std::string>& faceNameMap);
110}
class _declspec(dllexport) ClassFactoryHandler
Definition ClassFactoryHandler.h:5
@ nodes
Definition MonitorSettings.h:17
@ edges
Definition MonitorSettings.h:17
Definition Geometry.h:13
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27