Conscience Core
CscWorldElement.h
Go to the documentation of this file.
1 //
2 // CscEnvironnement.hpp
3 // ConscienceRobotManager
4 //
5 // Created by Conscience_Hazar on 05/03/2019.
6 // Copyright © 2019 IliesZaoui. All rights reserved.
7 //
8 
9 #ifndef CscWorldElement_h
10 #define CscWorldElement_h
11 
12 #include "CscCommon.h"
13 #include <limits>
14 #include "Axiomes/Csc3dTypes.h"
17 
18 using std::stringstream, std::istringstream, std::endl, std::ios, std::numeric_limits;
19 using namespace conscience_core::axiomes;
20 
21 typedef string CscWorldElementId;
22 
24 
25 public:
26 
28  const string & name,
29  CscPoint3d * positionIn,
30  CscPoint3d * rotationEulerIn,
32  float mass = 5.0,
33  vector<CscWorldElementPart *> * parts = nullptr,
34  vector<CscPoint3d *> * positions = nullptr,
35  vector<CscPoint3d *> * normals = nullptr,
36  vector<CscPolygon *> * polygons = nullptr,
37  vector<const CscLocationTag *> * locationTags = nullptr,
38  float minX = 0,
39  float minY = 0,
40  float minZ = 0,
41  float depth = 0,
42  float height = 0,
43  float width = 0);
44 
45  virtual ~CscWorldElement();
46 
50  virtual CscPoint3d getMinPositionInWorldCoordinates() const;
51 
57  const CscPoint3d * getPosition() const;
58 
62  void setPosition(float x, float y, float z);
63 
71  const CscPoint3d * getRotationEulerAsPoint() const;
72 
76  void setRotationEuler(double x, double y, double z);
77 
81  void setRotationQuaternion(double w, double x, double y, double z);
82 
83  bool isIn3DArea(const CscArea3d *area) const;
84 
85  const string & getName() const;
86 
87  virtual CscWorldElementId getId() const;
88 
89  float getMass();
90 
100  virtual CscSize3d getDimensions() const;
101 
102  float depth = 0;
103  float height = 0;
104  float width = 0;
105  float minX, minY, minZ;
106  float mass = 1.0;
107  float restitution = 0.3;
108  float dampingLinear = 0.3;
109  float dampingAngular = 0.3;
110  float friction = 1.0;
111  bool collideWithOthers = true;
112 
113  float certitude = 0.0; // TMP
114 
115  float * getVerticesArray() const;
116  float * getPolygonsArray() const;
117  int getVerticesCount() const;
118  int getPolygonsCount() const;
119 
120  void repositionateToZeroOriginPositions();
121  void repositionateToZeroOriginPolygons();
122 
126  vector<CscPoint3d *> * getPositions() const;
127 
131  vector<CscPolygon *> * getPolygons() const;
132 
137  vector<CscPolygon *> getPolygonsInWorldCoordinates() const;
138 
144  vector<CscPoint3d *> getYPlanSlicePoints(double sliceY, double precisionCm = 5.0) const;
145 
149  vector<CscPoint3d *> * getNormals() const;
150 
154  const vector<CscWorldElementPart *> * getParts() const;
155 
162  vector<CscPoint3d *> * getReconstructedVerticesFromPolygons(const int stepInCm = 10) const;
163 
168  unsigned long long numericId;
169  if (lastNumericId >= MAX_NUMERIC_ID - 2) {
170  LOG_WARN("Csc objects counter reached max and starts over at min value");
171  numericId = MIN_NUMERIC_ID;
172  } else {
173  numericId = ++lastNumericId;
174  }
175 
176  return to_string(numericId);
177  }
178 
179  CscPhysicsType getPhysicsType() const;
180 
184  const CscLocationTag* getLocationTagByName(const string & name) const;
185 
190  void forcePolygons(const vector<CscPolygon *> & newPolygons);
191 
192  void addTag(const string &tag);
193  void removeTag(const string &tag);
194  bool hasTag(const string &tag) const;
195 
199  const double *const getRotationQuaternionArray() const;
200 
201  CscQuaternion getRotationQuaternion() const;
202  CscRotation3dEuler getRotationEuler() const;
203 
204 private:
205  inline static const unsigned long long MIN_NUMERIC_ID = numeric_limits<unsigned long long>::min();
206  inline static const unsigned long long MAX_NUMERIC_ID = numeric_limits<unsigned long long>::max();
207  inline static unsigned long long lastNumericId = CscWorldElement::MIN_NUMERIC_ID;
208 
209  const string name;
210  CscPoint3d * position;
211  CscPoint3d * rotationEuler;
212 
216  double rotationQuaternion[4];
217 
218  vector<CscPoint3d *> * positions;
219 
220  const CscPhysicsType physicsType;
221  vector<CscPoint3d *> * normals;
222  vector<CscPolygon *> * polygons;
223 
224  vector<CscWorldElementPart *> * parts;
225 
226  vector<string> tags;
227 
228 protected:
230  vector<const CscLocationTag*> * locationTags;
231 
235  virtual const CscPoint3d &getBaseRotation() const;
236 };
237 
238 #endif
nlohmann::to_string
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:26470
conscience_core::axiomes::CscPoint3d
The CscPoint3d class represents a point in three-dimensional space. It is primarily used to denote a ...
Definition: Csc3dTypes.h:24
CscLocationTag
Definition: CscWorldElementParts.h:63
conscience_core::axiomes
Definition: Csc2dTypes.cpp:9
CscWorldElement::nextId
static CscWorldElementId nextId()
Definition: CscWorldElement.h:167
conscience_core::axiomes::CscArea3d
Definition: Csc3dTypes.h:231
CscWorldElement::locationTags
vector< const CscLocationTag * > * locationTags
Definition: CscWorldElement.h:230
conscience_core::axiomes::CscRotation3dEuler
Definition: Csc3dTypes.h:194
BOUNDING_BOX
@ BOUNDING_BOX
Definition: CscPhysicsType.h:22
LOG_WARN
#define LOG_WARN(message)
Definition: conscience_log.h:193
CscWorldElementId
string CscWorldElementId
Definition: CscWorldElement.h:21
CscWorldElementId
string CscWorldElementId
Definition: Command.h:15
CscPhysicsType
CscPhysicsType
Definition: CscPhysicsType.h:12
CscCommon.h
CscWorldElement
Definition: CscWorldElement.h:23
Csc3dTypes.h
conscience_core::axiomes::CscQuaternion
Definition: Csc3dTypes.h:138
CscWorldElementParts.h
CscPhysicsType.h
CscWorldElement::id
const CscWorldElementId id
Definition: CscWorldElement.h:229
CscWorldElement::minZ
float minZ
Definition: CscWorldElement.h:105