Ocean
BlockedMesh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_TRACKING_MAPTEXTURING_BLOCKED_MESH_H
9 #define META_OCEAN_TRACKING_MAPTEXTURING_BLOCKED_MESH_H
10 
12 
13 #include "ocean/math/AnyCamera.h"
15 #include "ocean/math/RGBAColor.h"
16 #include "ocean/math/Sphere3.h"
17 #include "ocean/math/Triangle3.h"
18 
20 
21 namespace Ocean
22 {
23 
24 namespace Tracking
25 {
26 
27 namespace MapTexturing
28 {
29 
30 // Forward declaration.
31 class BlockedMesh;
32 
33 /**
34  * Definition of a vector holding BlockedMesh objects.
35  */
36 typedef std::vector<BlockedMesh> BlockedMeshes;
37 
38 /**
39  * This class implements a blocked mesh storing only triangles located in a 3D block/box.
40  * @ingroup trackingmaptexturing
41  */
42 class OCEAN_TRACKING_MAPTEXTURING_EXPORT BlockedMesh
43 {
44  protected:
45 
46  typedef std::unordered_map<Index32, Index32> IndexMap;
47 
48  public:
49 
50  /**
51  * Default constructor.
52  */
53  BlockedMesh() = default;
54 
55  BlockedMesh(const VectorI3& block, const Box3& boundingBox, Vectors3&& vertices, Vectors3&& perVertexNormals, RGBAColors&& perVertexColors, Rendering::TriangleFaces&& triangleFaces) :
56  block_(block),
57  boundingBox_(boundingBox),
58  boundingSphere_(boundingBox),
59  vertices_(std::move(vertices)),
60  perVertexNormals_(std::move(perVertexNormals)),
61  perVertexColors_(std::move(perVertexColors)),
62  triangleFaces_(std::move(triangleFaces))
63  {
64  ocean_assert(!triangleFaces_.empty() == boundingBox_.isValid());
65  }
66 
67  void addTriangle(const Rendering::TriangleFace& triangleFace, const Vector3* vertices);
68 
69  void addTriangle(const Rendering::TriangleFace& triangleFace, const Vector3* vertices, const Vector3* perVertexNormals);
70 
71  void addTriangle(const Rendering::TriangleFace& triangleFace, const Vector3* vertices, const Vector3* perVertexNormals, const RGBAColor* perVertexColors);
72 
73  inline const VectorI3& block() const
74  {
75  return block_;
76  }
77 
78  inline const Box3& boundingBox() const
79  {
80  return boundingBox_;
81  }
82 
83  inline const Sphere3& boundingSphere() const
84  {
85  return boundingSphere_;
86  }
87 
88  inline bool isValid() const
89  {
90  return !triangleFaces_.empty();
91  }
92 
93  static BlockedMeshes separateMesh(const Vectors3& vertices, const Rendering::TriangleFaces& triangleFaces, const int blockSize = 1);
94 
95  static BlockedMeshes separateMesh(const Vectors3& vertices, const Vectors3& perVertexNormals, const Rendering::TriangleFaces& triangleFaces, const int blockSize = 1);
96 
97  static BlockedMeshes separateMesh(const Vectors3& vertices, const Vectors3& perVertexNormals, const RGBAColors& perVertexColors, const Rendering::TriangleFaces& triangleFaces, const int blockSize = 1);
98 
99  static VectorT3<int> vertex2block(const Vector3& vertex, const int blockSize);
100 
101  static Index64 makeTriangleId(const Index32& meshId, const Index32& triangleIndex)
102  {
103  return Index64(meshId) | Index64(triangleIndex) << 32u;
104  }
105 
106  static void separateTriangleId(const Index64 triangleId, Index32& meshId, Index32& triangleIndex)
107  {
108  meshId = Index32(triangleId & Index64(0xFFFFFFFFu));
109  triangleIndex = Index32(triangleId >> 32u);
110  }
111 
112  public:
113 
115 
117 
119 
120  /// The vertices of this mesh.
122 
123  /// The per-vertex normals of this mesh.
125 
126  /// The per-vertex colors of this mesh.
128 
129  /// The triangle faces of this mesh.
131 
133 };
134 
135 }
136 
137 }
138 
139 }
140 
141 #endif // META_OCEAN_TRACKING_MAPTEXTURING_BLOCKED_MESH_H
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
Definition of a triangle face with three vertex indices.
Definition: TriangleFace.h:37
This class implements a blocked mesh storing only triangles located in a 3D block/box.
Definition: BlockedMesh.h:43
static BlockedMeshes separateMesh(const Vectors3 &vertices, const Rendering::TriangleFaces &triangleFaces, const int blockSize=1)
BlockedMesh(const VectorI3 &block, const Box3 &boundingBox, Vectors3 &&vertices, Vectors3 &&perVertexNormals, RGBAColors &&perVertexColors, Rendering::TriangleFaces &&triangleFaces)
Definition: BlockedMesh.h:55
Rendering::TriangleFaces triangleFaces_
The triangle faces of this mesh.
Definition: BlockedMesh.h:130
bool isValid() const
Definition: BlockedMesh.h:88
RGBAColors perVertexColors_
The per-vertex colors of this mesh.
Definition: BlockedMesh.h:127
Box3 boundingBox_
Definition: BlockedMesh.h:116
std::unordered_map< Index32, Index32 > IndexMap
Definition: BlockedMesh.h:46
static Index64 makeTriangleId(const Index32 &meshId, const Index32 &triangleIndex)
Definition: BlockedMesh.h:101
Sphere3 boundingSphere_
Definition: BlockedMesh.h:118
static BlockedMeshes separateMesh(const Vectors3 &vertices, const Vectors3 &perVertexNormals, const Rendering::TriangleFaces &triangleFaces, const int blockSize=1)
Vectors3 vertices_
The vertices of this mesh.
Definition: BlockedMesh.h:121
BlockedMesh()=default
Default constructor.
VectorI3 block_
Definition: BlockedMesh.h:114
IndexMap indexMap_
Definition: BlockedMesh.h:132
const VectorI3 & block() const
Definition: BlockedMesh.h:73
static BlockedMeshes separateMesh(const Vectors3 &vertices, const Vectors3 &perVertexNormals, const RGBAColors &perVertexColors, const Rendering::TriangleFaces &triangleFaces, const int blockSize=1)
Vectors3 perVertexNormals_
The per-vertex normals of this mesh.
Definition: BlockedMesh.h:124
void addTriangle(const Rendering::TriangleFace &triangleFace, const Vector3 *vertices)
const Sphere3 & boundingSphere() const
Definition: BlockedMesh.h:83
static VectorT3< int > vertex2block(const Vector3 &vertex, const int blockSize)
void addTriangle(const Rendering::TriangleFace &triangleFace, const Vector3 *vertices, const Vector3 *perVertexNormals, const RGBAColor *perVertexColors)
void addTriangle(const Rendering::TriangleFace &triangleFace, const Vector3 *vertices, const Vector3 *perVertexNormals)
static void separateTriangleId(const Index64 triangleId, Index32 &meshId, Index32 &triangleIndex)
Definition: BlockedMesh.h:106
const Box3 & boundingBox() const
Definition: BlockedMesh.h:78
uint64_t Index64
Definition of a 64 bit index value.
Definition: Base.h:90
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
std::vector< RGBAColor > RGBAColors
Definition of a vector holding rgba color objects.
Definition: RGBAColor.h:21
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition: Vector3.h:65
std::vector< TriangleFace > TriangleFaces
Definition of a vector holding triangle faces.
Definition: TriangleFace.h:23
std::vector< BlockedMesh > BlockedMeshes
Definition of a vector holding BlockedMesh objects.
Definition: BlockedMesh.h:31
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15