AGXDynamics  2.35.0.2
Trimesh.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXCOLLIDE_TRIMESH_H
18 #define AGXCOLLIDE_TRIMESH_H
19 
20 #include <agx/agx_vector_types.h>
21 #include <agx/SPDMatrix3x3.h>
22 
23 #include <agx/agxPhysics_export.h>
24 #include <agxCollide/MeshData.h>
25 #include <agxCollide/Mesh.h>
27 
28 #include <agxStream/Serializable.h>
29 
30 #include <agxData/LocalVector.h>
31 
32 
33 
34 namespace agxCollide
35 {
37 
43  {
44  public:
45 
54  CLOCKWISE_ORIENTATION = 0x1,
67  NO_WARNINGS = 0x10,
72  TERRAIN = 0x20,
77  REMOVE_DUPLICATE_VERTICES = 0x40,
82  RECALCULATE_NORMALS_GIVEN_FIRST_TRIANGLE = 0x80
83  };
84 
85 
87  // Trimesh member declarations //
89 
90  // Constructors //
91 
133  Trimesh(
134  const agx::Vec3Vector* vertices, const agx::UInt32Vector* indices,
135  const char* sourceName, uint32_t optionsMask = Trimesh::REMOVE_DUPLICATE_VERTICES, agx::Real bottomMargin = 0);
136 
137  // Accessors //
138 
146  virtual void calculatePossibleTriangleOverlapsAlongLineSegment(
147  const agx::Vec3& segmentStartLocal,
148  const agx::Vec3& segmentEndLocal,
149  agx::UInt32Vector& triangleIndices) const override;
150 
158  virtual void calculatePossibleTriangleOverlapsAlongLineSegment(
159  const agx::Vec3& segmentStartLocal,
160  const agx::Vec3& segmentEndLocal,
161  agxData::LocalVector<agx::UInt32>& triangleIndices) const override;
162 
163  virtual Shape* clone() const override;
164 
172  Trimesh* shallowCopy() const;
173 
182  Trimesh* deepCopy() const;
183 
192  void updateMeshGeometry(bool showWarnings, bool recalculateMassProperties = true);
193 
195  uint32_t getOptionsMask() const;
196 
198  const agx::String& getSourceName() const;
199 
205  const agx::String& getWarnings() const;
206 
210  bool isShallowCopy() const;
211 
215  const Trimesh* getShallowCopySource();
216 
218 
219  private:
221  Trimesh();
222 
224  Trimesh(const Trimesh& trimesh);
225 
227  Trimesh& operator=(const Trimesh& trimesh);
228 
246  void addConstructionData(const agx::Vec3Vector* vertices,
247  const agx::UInt32Vector* indices,
248  const char* sourceName,
249  uint32_t optionsMask);
250 
255  void finalize(const char* sourceName, bool showWarnings, uint32_t optionsMask);
256 
261  void flipNormal(const size_t triangleIndex);
262 
266  bool getTriangleHalfEdgePartnerTriangleIndexAndLocalEdgeIndex(const size_t triangleIndex, const size_t localEdgeIndex, size_t& neighborIndex, size_t& neighborLocalEdgeIndex);
267 
268 
269 
270  protected:
274  void calculateMassProperties(bool showWarnings);
275 
283  void finalizeMeshTopology(bool showWarnings, uint32_t optionsMask);
284 
286  Trimesh(Type type, agx::Physics::Geometry::ShapePtr entity, const agx::Vec3Vector* vertices, const agx::UInt32Vector* indices,
287  const char* sourceName, uint32_t optionsMask = 0);
288 
291 
292  // Sets the values in a shallow-copy way.
293  void setValuesAsShallowCopy(const Trimesh* other);
294 
296  virtual ~Trimesh();
297 
299  virtual void updateBvhTree() override;
300 
301 
302  protected:
305  uint32_t m_optionsMask;
307 
308  };
309 
310 
311  // Implementations
312 
314  const agx::Vec3& segmentStartLocal,
315  const agx::Vec3& segmentEndLocal,
316  agx::UInt32Vector& triangleIndices) const
317  {
318  this->getBvhTree()->findCollisionWithLineSegment(segmentStartLocal, segmentEndLocal, triangleIndices);
319  }
320 
321 
322 
324  const agx::Vec3& segmentStartLocal,
325  const agx::Vec3& segmentEndLocal,
326  agxData::LocalVector<agx::UInt32>& triangleIndices) const
327  {
328  this->getBvhTree()->findCollisionWithLineSegment(segmentStartLocal, segmentEndLocal, triangleIndices);
329  }
330 
331 }
332 
333 #endif
agxCollide::Trimesh::TrimeshOptionsFlags
TrimeshOptionsFlags
Parameters for trimesh creation from data set.
Definition: Trimesh.h:49
agxPhysics_export.h
SPDMatrix3x3.h
agxCollide::Mesh
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Definition: Mesh.h:69
agx::Real
double Real
Definition: Real.h:42
TriangleVoronoiRegion.h
MeshData.h
agxCollide::Trimesh::m_optionsMask
uint32_t m_optionsMask
Definition: Trimesh.h:305
AGXSTREAM_DECLARE_SERIALIZABLE
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
agx::VectorPOD< Vec3 >
agxCollide::Trimesh::m_sourceName
agx::String m_sourceName
Definition: Trimesh.h:303
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
agxCollide::Trimesh::REMOVE_DUPLICATE_VERTICES
@ REMOVE_DUPLICATE_VERTICES
Removes exactly identical duplicates in the vertices, as well as (resulting or previously existing) t...
Definition: Trimesh.h:77
agxCollide::Shape::Type
Type
Define the type of a Shape.
Definition: Shape.h:58
agxCollide::Mesh::getBvhTree
const AabbTree * getBvhTree() const
Definition: Mesh.h:883
agxCollide::Trimesh::m_warnings
agx::String m_warnings
Definition: Trimesh.h:304
Serializable.h
Mesh.h
agx::Physics::Geometry::ShapePtr
Pointer to a entity instance of type Physics.Geometry.Shape.
Definition: ShapeEntity.h:195
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agxCollide::Trimesh::m_shallowCopySource
agx::ref_ptr< const Trimesh > m_shallowCopySource
Definition: Trimesh.h:306
agxCollide::Trimesh::calculatePossibleTriangleOverlapsAlongLineSegment
virtual void calculatePossibleTriangleOverlapsAlongLineSegment(const agx::Vec3 &segmentStartLocal, const agx::Vec3 &segmentEndLocal, agx::UInt32Vector &triangleIndices) const override
Calculates an array of triangle indices of the triangles whose bounding volumes get intersected by a ...
Definition: Trimesh.h:313
agxCollide::AGX_DECLARE_POINTER_TYPES
AGX_DECLARE_POINTER_TYPES(SpaceListener)
agx::AgXString< std::string >
agx::Vec3T< Real >
agxCollide::Trimesh
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:42
LocalVector.h
agx_vector_types.h
agxData::LocalVector< agx::UInt32 >