21 #ifndef EMODNET_QMGC_QUANTIZED_MESH_H 22 #define EMODNET_QMGC_QUANTIZED_MESH_H 29 #include "misc_utils.h" 72 unsigned int vertexCount = 0;
73 std::vector<unsigned short>
u;
74 std::vector<unsigned short>
v;
101 std::vector<float>
nx;
102 std::vector<float>
ny;
103 std::vector<float>
nz;
107 std::vector<unsigned char>
mask ;
110 enum ExtensionIds {OCT_VERTEX_NORMALS = 1, WATER_MASK = 2};
128 bool readFile(
const std::string &filePath);
131 bool writeFile(
const std::string &filePath);
170 const unsigned short int TILE_SIZE = 65;
171 static const unsigned short MAX_VERTEX_DATA = 32767;
182 double valueRemap = remap(value, minOr, maxOr, 0, MAX_VERTEX_DATA) ;
183 return static_cast<unsigned short>(valueRemap);
186 static double remapFromVertexDataValue(
const double& value,
const double& minOr,
const double& maxOr) {
187 return remap(value, 0, MAX_VERTEX_DATA, minOr, maxOr ) ;
199 int m_bytesPerIndex ;
206 unsigned short zigZagDecode(
const unsigned short &value ) {
207 return (value >> 1) ^ (-(value & 1)) ;
211 unsigned short zigZagEncode(
const short &value ) {
212 return (value << 1) ^ (value >> 31) ;
216 void octEncode(
const float xyz[3],
unsigned char octxy[2] ) {
217 const float invL1Norm = (1.0f) / (fabs(xyz[0]) + fabs(xyz[1]) + fabs(xyz[2]));
220 octxy[0] =
static_cast<unsigned char>((1.0f - float(fabs(xyz[1] * invL1Norm))) * sign(xyz[0]));
221 octxy[1] =
static_cast<unsigned char>((1.0f - float(fabs(xyz[0] * invL1Norm))) * sign(xyz[1]));
223 octxy[0] =
static_cast<unsigned char>(xyz[0] * invL1Norm);
224 octxy[1] =
static_cast<unsigned char>(xyz[1] * invL1Norm);
229 void octDecode(
const unsigned char octxy[2],
float xyz[3] ) {
231 xyz[0] = uchar2float(octxy[0]);
232 xyz[1] = uchar2float(octxy[1]);
233 xyz[2] = 1.0f - (fabs(xyz[0]) + fabs(xyz[1]));
237 xyz[0] = ((1.0f) - fabs(xyz[1])) * sign(oldX);
238 xyz[1] = ((1.0f) - fabs(oldX)) * sign(xyz[1]);
243 inline float sign(
float v) {
244 return (v < 0.0f) ? -1.0f : 1.0f;
248 float uchar2float(
unsigned char u ) {
249 return float(clamp(
int(8) * (1.0f /
float((uint64_t(1) << 7) - 1)), -1.0f, 1.0f));
253 unsigned char float2uchar(
float f ) {
254 return (
unsigned char)round(clamp(f, -1.0f, 1.0f) * ((uint64_t(1) << 7) - 1));
258 inline float clamp(
float val,
float low,
float hi) {
261 }
else if (val >= hi) {
269 inline float round(
float f) {
270 return floor(f + 0.5f);
276 #endif //EMODNET_QMGC_QUANTIZED_MESH_H
void setHeader(const Header &header)
Set the header part of the quantized mesh structure.
Definition: quantized_mesh.h:140
std::vector< float > nz
Z coordinate of the normal.
Definition: quantized_mesh.h:103
std::vector< unsigned short > height
height coordinate of the vertex
Definition: quantized_mesh.h:75
EdgeIndices getEdgeIndices() const
Get the edge indices of the quantized mesh structure.
Definition: quantized_mesh.h:167
IndexData getIndexData() const
Get the index data of the quantized mesh structure.
Definition: quantized_mesh.h:161
void setIndexData(const IndexData &id)
Set the index data part of the quantized mesh structure.
Definition: quantized_mesh.h:146
QuantizedMesh()
Constructor.
Definition: quantized_mesh.h:114
bool readFile(const std::string &filePath)
Read the tile from a file.
Definition: quantized_mesh.cpp:36
Header getHeader() const
Get the header part of the quantized mesh structure.
Definition: quantized_mesh.h:155
std::vector< unsigned short > u
U coordinate of the vertex.
Definition: quantized_mesh.h:73
std::vector< unsigned int > westIndices
The indices of the vertices falling in the western border of the tile.
Definition: quantized_mesh.h:87
static unsigned short remapToVertexDataValue(const double &value, const double &minOr, const double &maxOr)
Remap a value to be between 0 and 32767.
Definition: quantized_mesh.h:181
Definition: quantized_mesh.h:84
void printHeader()
Show the contents of the header of the tile on screen.
Definition: quantized_mesh.cpp:482
std::vector< unsigned int > southIndices
The indices of the vertices falling in the southern border of the tile.
Definition: quantized_mesh.h:90
std::vector< float > ny
Y coordinate of the normal.
Definition: quantized_mesh.h:102
void setVertexData(const VertexData &vd)
Set the vertex data part of the quantized mesh structure.
Definition: quantized_mesh.h:143
unsigned int northVertexCount
Number of vertices in the northern border of the tile.
Definition: quantized_mesh.h:95
Definition: quantized_mesh.h:70
VertexData getVertexData() const
Get the vertex data part of the quantized mesh structure.
Definition: quantized_mesh.h:158
unsigned int eastVertexCount
Number of vertices in the eastern border of the tile.
Definition: quantized_mesh.h:92
Contains all the data of a Quantized-mesh.
Definition: quantized_mesh.h:35
std::vector< unsigned int > eastIndices
The indices of the vertices falling in the eastern border of the tile.
Definition: quantized_mesh.h:93
Definition: quantized_mesh.h:99
void setVertexNormals(const VertexNormals &vn)
Set the vertices normal part of the quantized mesh structure.
Definition: quantized_mesh.h:152
void print()
Show the contents of the tile on screen.
Definition: quantized_mesh.cpp:383
bool writeFile(const std::string &filePath)
Write the tile to a file.
Definition: quantized_mesh.cpp:215
std::vector< unsigned short > v
v coordinate of the vertex
Definition: quantized_mesh.h:74
VertexNormals getVertexNormals() const
Get the vertex normals of the quantized mesh structure.
Definition: quantized_mesh.h:164
Definition: quantized_mesh.h:106
Set of miscellaneous functions extending the functionality of the CGAL library.
unsigned int southVertexCount
Number of vertices in the southern border of the tile.
Definition: quantized_mesh.h:89
void setEdgeIndices(const EdgeIndices &ei)
Set the edge indices data part of the quantized mesh structure.
Definition: quantized_mesh.h:149
std::vector< unsigned int > indices
Indices of the triangles in the tile, size triangleCount*3. While they can be ints or shorts...
Definition: quantized_mesh.h:81
unsigned int westVertexCount
Number of vertices in the western border of the tile.
Definition: quantized_mesh.h:86
Definition: quantized_mesh.h:78
unsigned int triangleCount
Number of triangles in the tile.
Definition: quantized_mesh.h:80
std::vector< float > nx
X coordinate of the normal.
Definition: quantized_mesh.h:101
QuantizedMesh(const std::string &filePath)
Constructor from file.
Definition: quantized_mesh.h:125
std::vector< unsigned int > northIndices
The indices of the vertices falling in the northern border of the tile.
Definition: quantized_mesh.h:96
std::vector< unsigned char > mask
Water mask. Can be either a single value or 256x256.
Definition: quantized_mesh.h:107