AGXDynamics  2.31.1.0
Trimesh.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
207 
209 
210  private:
212  Trimesh();
213 
215  Trimesh(const Trimesh& trimesh);
216 
218  Trimesh& operator=(const Trimesh& trimesh);
219 
237  void addConstructionData(const agx::Vec3Vector* vertices,
238  const agx::UInt32Vector* indices,
239  const char* sourceName,
240  uint32_t optionsMask);
241 
246  void finalize(const char* sourceName, bool showWarnings, uint32_t optionsMask);
247 
252  void flipNormal(const size_t triangleIndex);
253 
257  bool getTriangleHalfEdgePartnerTriangleIndexAndLocalEdgeIndex(const size_t triangleIndex, const size_t localEdgeIndex, size_t& neighborIndex, size_t& neighborLocalEdgeIndex);
258 
259 
260 
261  protected:
265  void calculateMassProperties(bool showWarnings);
266 
274  void finalizeMeshTopology(bool showWarnings, uint32_t optionsMask);
275 
277  Trimesh(Type type, agx::Physics::Geometry::ShapePtr entity, const agx::Vec3Vector* vertices, const agx::UInt32Vector* indices,
278  const char* sourceName, uint32_t optionsMask = 0);
279 
282 
283  // Sets the values in a shallow-copy way.
284  void setValuesAsShallowCopy(const Trimesh* other);
285 
287  virtual ~Trimesh();
288 
290  virtual void updateBvhTree() override;
291 
292 
293  protected:
296  uint32_t m_optionsMask;
298 
299  };
300 
301 
302  // Implementations
303 
305  const agx::Vec3& segmentStartLocal,
306  const agx::Vec3& segmentEndLocal,
307  agx::UInt32Vector& triangleIndices) const
308  {
309  this->getBvhTree()->findCollisionWithLineSegment(segmentStartLocal, segmentEndLocal, triangleIndices);
310  }
311 
312 
313 
315  const agx::Vec3& segmentStartLocal,
316  const agx::Vec3& segmentEndLocal,
317  agxData::LocalVector<agx::UInt32>& triangleIndices) const
318  {
319  this->getBvhTree()->findCollisionWithLineSegment(segmentStartLocal, segmentEndLocal, triangleIndices);
320  }
321 
322 }
323 
324 #endif
Removes exactly identical duplicates in the vertices, as well as (resulting or previously existing) t...
Definition: Trimesh.h:77
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Definition: Mesh.h:68
agx::String m_sourceName
Definition: Trimesh.h:294
Base class for a shape.
Definition: Shape.h:53
agxCollide namespace consists of a set of classes for handling geometric intersection tests including...
#define AGXPHYSICS_EXPORT
Pointer to a entity instance of type Physics.Geometry.Shape.
Definition: ShapeEntity.h:195
TrimeshOptionsFlags
Parameters for trimesh creation from data set.
Definition: Trimesh.h:49
uint32_t m_optionsMask
Definition: Trimesh.h:296
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::ref_ptr< const Trimesh > m_shallowCopySource
Definition: Trimesh.h:297
#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:206
Type
Define the type of a Shape.
Definition: Shape.h:58
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:304
double Real
Definition: Real.h:42
agx::String m_warnings
Definition: Trimesh.h:295
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:42
AGX_DECLARE_POINTER_TYPES(SpaceListener)
GLenum type
Definition: gl.h:5539