DracoEncoder.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2018 Uni Osnabrück
2  * This file is part of the LAS VEGAS Reconstruction Toolkit,
3  *
4  * LAS VEGAS is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * LAS VEGAS is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17  */
18 
30 #include "lvr2/io/DracoEncoder.hpp"
31 #include <draco/metadata/geometry_metadata.h>
32 
33 namespace lvr2
34 {
35 
52 template <typename ArrayType, typename DataType, int size>
53 int saveAttributeToDraco(ArrayType array, draco::PointCloud* drcPointcloud,
54  draco::GeometryAttribute::Type geometryType, draco::DataType dracoDataType,
55  size_t numPoints, bool normalized)
56 {
57  if (array == nullptr)
58  {
59  throw std::invalid_argument("attribute is not existing");
60  }
61 
62  draco::PointAttribute attribute;
63  attribute.Init(geometryType, nullptr, size, dracoDataType, normalized, sizeof(DataType) * size,
64  0);
65  int attribute_id = drcPointcloud->AddAttribute(attribute, true, numPoints);
66 
67  std::array<DataType, size> tmp;
68  for (int i = 0; i < numPoints; ++i)
69  {
70  for (int j = 0; j < size; ++j)
71  {
72  tmp[j] = array[i * size + j];
73  }
74 
75  drcPointcloud->attribute(attribute_id)
76  ->SetAttributeValue(draco::AttributeValueIndex(i), &tmp);
77  }
78 
79  return attribute_id;
80 }
81 
90 void saveTextures(std::vector<int32_t>* textureValue, textureArr textures, size_t numTextures)
91 {
92  for (int i = 0; i < numTextures; ++i)
93  {
94  // get texture attributes
95  GlTexture* lvrTexture = textures[i];
96  int index = lvrTexture->m_texIndex;
97  int height = lvrTexture->m_height;
98  int width = lvrTexture->m_width;
99  unsigned char* pixel = lvrTexture->m_pixels;
100 
101  // calculate number of values in the pixel-array (number of pixels * 3(rgb))
102  unsigned long pixelDat = (unsigned long)height * width * 3;
103 
104  // store texture attributes
105  textureValue->push_back(index);
106  textureValue->push_back(height);
107  textureValue->push_back(width);
108 
109  // store pixel data
110  for (unsigned long j = 0; j < pixelDat; ++j)
111  {
112  textureValue->push_back((int32_t)pixel[j]);
113  }
114  }
115 }
116 
125 void saveTextures(std::vector<int32_t>* textureValue, vector<Texture>& textures)
126 {
127  for (int i = 0; i < textures.size(); ++i)
128  {
129  // get texture attributes
130  Texture lvrTexture = textures[i];
131  int index = lvrTexture.m_index;
132  int height = lvrTexture.m_height;
133  int width = lvrTexture.m_width;
134  unsigned char* pixel = lvrTexture.m_data;
135 
136  // calculate number of values in the pixel-array (number of pixels * 3(rgb))
137  unsigned long pixelDat = (unsigned long)height * width * 3;
138 
139  // store texture attributes
140  textureValue->push_back(index);
141  textureValue->push_back(height);
142  textureValue->push_back(width);
143 
144  // store pixel data
145  for (unsigned long j = 0; j < pixelDat; ++j)
146  {
147  textureValue->push_back((int32_t)pixel[j]);
148  }
149  }
150 }
151 
161 std::unique_ptr<draco::EncoderBuffer> encodePointCloud(ModelPtr modelPtr, draco::Encoder& encoder)
162 {
163  draco::PointCloud pointCloud;
164  draco::GeometryMetadata* metadata = new draco::GeometryMetadata();
165 
166  // assuming number of colors, normals, intensities and confidences are equal to number of points
167  size_t numElem;
168  size_t numPoints = modelPtr->m_pointCloud->numPoints();
169  pointCloud.set_num_points(numPoints);
170 
171  // save point coordinates
172  try
173  {
174  floatArr coordinates = modelPtr->m_pointCloud->getPointArray();
175  saveAttributeToDraco<floatArr, float, 3>(coordinates, &pointCloud,
176  draco::GeometryAttribute::Type::POSITION,
177  draco::DT_FLOAT32, numPoints, false);
178  }
179  catch (const std::invalid_argument& ia)
180  {
181  std::cerr << "No point coordinates could be found in the pointcloud" << std::endl;
182  return std::unique_ptr<draco::EncoderBuffer>(nullptr);
183  }
184 
185  // save point normals
186  try
187  {
188  floatArr normals = modelPtr->m_pointCloud->getNormalArray();
189  if (normals)
190  {
191  saveAttributeToDraco<floatArr, float, 3>(normals, &pointCloud,
192  draco::GeometryAttribute::Type::NORMAL,
193  draco::DT_FLOAT32, numElem, true);
194  }
195  }
196  catch (const std::invalid_argument& ia)
197  {
198  }
199 
200  // save point colors
201  try
202  {
203  size_t w;
204  ucharArr colors = modelPtr->m_pointCloud->getColorArray(w);
205  if (colors && (w == 3))
206  {
207 
208  saveAttributeToDraco<ucharArr, unsigned char, 3>(colors, &pointCloud,
209  draco::GeometryAttribute::Type::COLOR,
210  draco::DT_UINT8, numElem, false);
211  }
212  }
213  catch (const std::invalid_argument& ia)
214  {
215  }
217  // save point confidences
218  // try
219  // {
220  // floatArr confidences = modelPtr->m_pointCloud->getPointIntensityArray(numElem);
221 
222  // int attId = saveAttributeToDraco<floatArr, float, 1>(
223  // confidences, &pointCloud, draco::GeometryAttribute::Type::GENERIC, draco::DT_FLOAT32,
224  // numElem, false);
225 
226  // draco::AttributeMetadata* attributeMeta = new draco::AttributeMetadata();
227  // attributeMeta->set_att_unique_id(attId);
228  // attributeMeta->AddEntryString("name", "confidence");
229 
230  // metadata->AddAttributeMetadata(std::unique_ptr<draco::AttributeMetadata>(attributeMeta));
231  // }
232  // catch (const std::invalid_argument& ia)
233  // {
234  // }
235 
237  // save point intensities
238  // try
239  // {
240  // floatArr intensities = modelPtr->m_pointCloud->getPointIntensityArray(numElem);
241 
242  // int attId = saveAttributeToDraco<floatArr, float, 1>(
243  // intensities, &pointCloud, draco::GeometryAttribute::Type::GENERIC, draco::DT_FLOAT32,
244  // numElem, false);
245 
246  // draco::AttributeMetadata* attributeMeta = new draco::AttributeMetadata();
247  // attributeMeta->set_att_unique_id(attId);
248  // attributeMeta->AddEntryString("name", "intensity");
249 
250  // metadata->AddAttributeMetadata(std::unique_ptr<draco::AttributeMetadata>(attributeMeta));
251  // }
252  // catch (const std::invalid_argument& ia)
253  // {
254  // }
255 
256  pointCloud.AddMetadata(std::unique_ptr<draco::GeometryMetadata>(metadata));
257 
258  // Encode Data
259  std::unique_ptr<draco::EncoderBuffer> buffer(new draco::EncoderBuffer());
260  auto status = encoder.EncodePointCloudToBuffer(pointCloud, buffer.get());
261 
262  if (!status.ok())
263  {
264  std::cerr << "An error occurred:"
265  << " " << status.error_msg_string() << std::endl;
266  return std::unique_ptr<draco::EncoderBuffer>(nullptr);
267  }
268 
269  return buffer;
270 }
271 
280 std::unique_ptr<draco::EncoderBuffer> encodeMesh(ModelPtr modelPtr, draco::Encoder& encoder)
281 {
282  draco::Mesh mesh;
283  draco::GeometryMetadata* metadata = new draco::GeometryMetadata();
284 
285  // load sizes and arrays from modelPtr
286  size_t w;
287  size_t numVertices = modelPtr->m_mesh->numVertices();
288  floatArr vertices = modelPtr->m_mesh->getVertices();
289  floatArr vertexNormals = modelPtr->m_mesh->getVertexNormals();
290  ucharArr vertexColors = modelPtr->m_mesh->getVertexColors(w);
291  bool hasVertexColors = modelPtr->m_mesh->hasVertexColors();
292  bool hasFaceColors = modelPtr->m_mesh->hasFaceColors();
293  bool hasVertexNormals = modelPtr->m_mesh->hasVertexNormals();
294  bool hasFaceNormals = modelPtr->m_mesh->hasFaceNormals();
295 
296  // size_t numVertexConfidences;
297  // floatArr vertexConfidences = modelPtr->m_mesh->getVertexConfidenceArray(numVertexConfidences);
298 
299  // size_t numVertexIntensities;
300  // floatArr vertexIntensities = modelPtr->m_mesh->getVertexIntensityArray(numVertexIntensities);
301 
302  size_t numVertexTextureCoordinates = numVertices;
303  floatArr vertexTextureCoordinates = modelPtr->m_mesh->getTextureCoordinates();
304 
305  size_t numFaces = modelPtr->m_mesh->numFaces();
306  uintArr faces = modelPtr->m_mesh->getFaceIndices();
307 
308  std::vector<Texture> textures = modelPtr->m_mesh->getTextures();
309  std::vector<Material> materials = modelPtr->m_mesh->getMaterials();
310 
311  indexArray faceMaterialIndices = modelPtr->m_mesh->getFaceMaterialIndices();
312 
313  // put data into draco format
314  mesh.set_num_points(numFaces * 3); // one point per corner
315  mesh.SetNumFaces(numFaces);
316 
317  // init Attributes
318  int verticesAttId = -1;
319  int vertexNormalsAttId = -1;
320  int vertexColorsAttId = -1;
321  int vertexConfidencesAttId = -1;
322  int vertexIntensitiesAttId = -1;
323  int vertexTextureCoordinatesAttId = -1;
324  int faceMaterialIndicesAttId = -1;
325 
326  // textures and materials are stored as metadata
327 
328  // if there are material indices which exist per face, index draco mesh by face
329  // if not, index draco mesh by vertex:
330  bool faceIndexed = (faceMaterialIndices != 0);
331 
332  if (numVertices > 0)
333  {
334  draco::GeometryAttribute attribute;
335  attribute.Init(draco::GeometryAttribute::POSITION, nullptr, 3, draco::DT_FLOAT32, false,
336  sizeof(float) * 3, 0);
337  verticesAttId =
338  mesh.AddAttribute(attribute, true, faceIndexed ? numFaces * 3 : numVertices);
339  mesh.SetAttributeElementType(verticesAttId,
340  draco::MeshAttributeElementType::MESH_VERTEX_ATTRIBUTE);
341  }
342 
343  if (hasVertexNormals)
344  {
345  draco::GeometryAttribute attribute;
346  attribute.Init(draco::GeometryAttribute::NORMAL, nullptr, 3, draco::DT_FLOAT32, true,
347  sizeof(float) * 3, 0);
348  vertexNormalsAttId =
349  mesh.AddAttribute(attribute, true, faceIndexed ? numFaces * 3 : numVertices);
350  mesh.SetAttributeElementType(vertexNormalsAttId,
351  draco::MeshAttributeElementType::MESH_VERTEX_ATTRIBUTE);
352  }
353 
354  if (hasVertexColors)
355  {
356  draco::GeometryAttribute attribute;
357  attribute.Init(draco::GeometryAttribute::COLOR, nullptr, 3, draco::DT_UINT8, false,
358  sizeof(uint8_t) * 3, 0);
359  vertexColorsAttId =
360  mesh.AddAttribute(attribute, true, faceIndexed ? numFaces * 3 : numVertices);
361  mesh.SetAttributeElementType(vertexColorsAttId,
362  draco::MeshAttributeElementType::MESH_VERTEX_ATTRIBUTE);
363  }
364 
365  // if (numVertexConfidences > 0)
366  // {
367  // draco::GeometryAttribute attribute;
368  // attribute.Init(draco::GeometryAttribute::GENERIC, nullptr, 1, draco::DT_FLOAT32, false,
369  // sizeof(float), 0);
370  // vertexConfidencesAttId =
371  // mesh.AddAttribute(attribute, true, faceIndexed ? numFaces * 3 : numVertexConfidences);
372  // mesh.SetAttributeElementType(vertexConfidencesAttId,
373  // draco::MeshAttributeElementType::MESH_VERTEX_ATTRIBUTE);
374 
375  // draco::AttributeMetadata* attributeMeta = new draco::AttributeMetadata();
376  // attributeMeta->set_att_unique_id(vertexConfidencesAttId);
377  // attributeMeta->AddEntryString("name", "confidence");
378 
379  // metadata->AddAttributeMetadata(std::unique_ptr<draco::AttributeMetadata>(attributeMeta));
380  // }
381 
382  // if (numVertexIntensities > 0)
383  // {
384  // draco::GeometryAttribute attribute;
385  // attribute.Init(draco::GeometryAttribute::GENERIC, nullptr, 1, draco::DT_FLOAT32, false,
386  // sizeof(float), 0);
387  // vertexIntensitiesAttId =
388  // mesh.AddAttribute(attribute, true, faceIndexed ? numFaces * 3 : numVertexIntensities);
389  // mesh.SetAttributeElementType(vertexIntensitiesAttId,
390  // draco::MeshAttributeElementType::MESH_VERTEX_ATTRIBUTE);
391 
392  // draco::AttributeMetadata* attributeMeta = new draco::AttributeMetadata();
393  // attributeMeta->set_att_unique_id(vertexIntensitiesAttId);
394  // attributeMeta->AddEntryString("name", "intensity");
395 
396  // metadata->AddAttributeMetadata(std::unique_ptr<draco::AttributeMetadata>(attributeMeta));
397  // }
398 
399  if (vertexTextureCoordinates)
400  {
401  draco::GeometryAttribute attribute;
402  attribute.Init(draco::GeometryAttribute::TEX_COORD, nullptr, 3, draco::DT_FLOAT32, false,
403  sizeof(float) * 3, 0);
404  vertexTextureCoordinatesAttId = mesh.AddAttribute(
405  attribute, true, faceIndexed ? numFaces * 3 : numVertexTextureCoordinates);
406  mesh.SetAttributeElementType(vertexTextureCoordinatesAttId,
407  draco::MeshAttributeElementType::MESH_VERTEX_ATTRIBUTE);
408  }
409 
410  if (faceMaterialIndices)
411  {
412  draco::GeometryAttribute attribute;
413  attribute.Init(draco::GeometryAttribute::GENERIC, nullptr, 1, draco::DT_UINT32, false,
414  sizeof(uint32_t), 0);
415  faceMaterialIndicesAttId =
416  mesh.AddAttribute(attribute, true, faceIndexed ? numFaces * 3 : numFaces);
417  mesh.SetAttributeElementType(faceMaterialIndicesAttId,
418  draco::MeshAttributeElementType::MESH_FACE_ATTRIBUTE);
419 
420  draco::AttributeMetadata* attributeMeta = new draco::AttributeMetadata();
421  attributeMeta->set_att_unique_id(faceMaterialIndicesAttId);
422  attributeMeta->AddEntryString("name", "materialindex");
423 
424  metadata->AddAttributeMetadata(std::unique_ptr<draco::AttributeMetadata>(attributeMeta));
425  }
426 
427  // apply materials
428  if (faceMaterialIndices && materials.size())
429  {
430  std::vector<int32_t> materialData;
431 
432  for (int i = 0; i < materials.size(); i++)
433  {
434  boost::optional<TextureHandle> opt_texture_index = materials[i].m_texture;
435  boost::optional<Rgb8Color> opt_mat_color = materials[i].m_color;
436  if(opt_mat_color)
437  {
438  Rgb8Color mat_color = *opt_mat_color;
439  materialData.push_back(mat_color[0]);
440  materialData.push_back(mat_color[1]);
441  materialData.push_back(mat_color[2]);
442  }
443  else
444  {
445  // Push back default color if none defined
446  materialData.push_back(126);
447  materialData.push_back(126);
448  materialData.push_back(126);
449  }
450 
451  if(opt_texture_index)
452  {
453  TextureHandle handle = *opt_texture_index;
454  materialData.push_back(handle.idx());
455  }
456  else
457  {
458  // Default
459  materialData.push_back(-1);
460  }
461 
462 
463  }
464  metadata->AddEntryIntArray("material", materialData);
465 
466  // textures
467  if (textures.size())
468  {
469  std::vector<int32_t> textureValue;
470  saveTextures(&textureValue, textures);
471  metadata->AddEntryIntArray("texture", textureValue);
472  }
473  }
474 
475  // apply attributes
476  if (faceIndexed)
477  {
478  draco::Mesh::Face face;
479  for (draco::FaceIndex i(0); i < numFaces; i++)
480  {
481  // TODO: check for illegal accesses of original arrays using the array size
482 
483  // face
484  face[0] = draco::PointIndex(i.value() * 3 + 0);
485  face[1] = draco::PointIndex(i.value() * 3 + 1);
486  face[2] = draco::PointIndex(i.value() * 3 + 2);
487  mesh.SetFace(i, face);
488 
489  // positions
490  mesh.attribute(verticesAttId)
491  ->SetAttributeValue(draco::AttributeValueIndex(face[0].value()),
492  vertices.get() + faces[3 * i.value() + 0] * 3);
493  mesh.attribute(verticesAttId)
494  ->SetAttributeValue(draco::AttributeValueIndex(face[1].value()),
495  vertices.get() + faces[3 * i.value() + 1] * 3);
496  mesh.attribute(verticesAttId)
497  ->SetAttributeValue(draco::AttributeValueIndex(face[2].value()),
498  vertices.get() + faces[3 * i.value() + 2] * 3);
499 
500  // normals
501  if (hasFaceNormals)
502  {
503  mesh.attribute(vertexNormalsAttId)
504  ->SetAttributeValue(draco::AttributeValueIndex(face[0].value()),
505  vertexNormals.get() + faces[3 * i.value() + 0] * 3);
506  mesh.attribute(vertexNormalsAttId)
507  ->SetAttributeValue(draco::AttributeValueIndex(face[1].value()),
508  vertexNormals.get() + faces[3 * i.value() + 1] * 3);
509  mesh.attribute(vertexNormalsAttId)
510  ->SetAttributeValue(draco::AttributeValueIndex(face[2].value()),
511  vertexNormals.get() + faces[3 * i.value() + 2] * 3);
512  }
513 
514  // colors
515  if (hasVertexColors)
516  {
517  for (int j = 0; j < 3; j++)
518  {
519  unsigned char color[3];
520  color[0] = vertexColors[3 * i.value()];
521  color[1] = vertexColors[3 * i.value() + 1];
522  color[2] = vertexColors[3 * i.value() + 2];
523  mesh.attribute(vertexColorsAttId)
524  ->SetAttributeValue(draco::AttributeValueIndex(face[j].value()), color);
525  }
526  }
527 
528  // // confidences
529  // if (numVertexConfidences > 0)
530  // {
531  // mesh.attribute(vertexConfidencesAttId)
532  // ->SetAttributeValue(draco::AttributeValueIndex(face[0].value()),
533  // vertexConfidences.get() + faces[3 * i.value() + 0]);
534  // mesh.attribute(vertexConfidencesAttId)
535  // ->SetAttributeValue(draco::AttributeValueIndex(face[1].value()),
536  // vertexConfidences.get() + faces[3 * i.value() + 1]);
537  // mesh.attribute(vertexConfidencesAttId)
538  // ->SetAttributeValue(draco::AttributeValueIndex(face[2].value()),
539  // vertexConfidences.get() + faces[3 * i.value() + 2]);
540  // }
541 
542  // // intensities
543  // if (numVertexIntensities > 0)
544  // {
545  // mesh.attribute(vertexIntensitiesAttId)
546  // ->SetAttributeValue(draco::AttributeValueIndex(face[0].value()),
547  // vertexIntensities.get() + faces[3 * i.value() + 0]);
548  // mesh.attribute(vertexIntensitiesAttId)
549  // ->SetAttributeValue(draco::AttributeValueIndex(face[1].value()),
550  // vertexIntensities.get() + faces[3 * i.value() + 1]);
551  // mesh.attribute(vertexIntensitiesAttId)
552  // ->SetAttributeValue(draco::AttributeValueIndex(face[2].value()),
553  // vertexIntensities.get() + faces[3 * i.value() + 2]);
554  // }
555 
556  // texture coordinates
557  if (vertexTextureCoordinates)
558  {
559  mesh.attribute(vertexTextureCoordinatesAttId)
560  ->SetAttributeValue(draco::AttributeValueIndex(face[0].value()),
561  vertexTextureCoordinates.get() +
562  faces[3 * i.value() + 0] * 3);
563  mesh.attribute(vertexTextureCoordinatesAttId)
564  ->SetAttributeValue(draco::AttributeValueIndex(face[1].value()),
565  vertexTextureCoordinates.get() +
566  faces[3 * i.value() + 1] * 3);
567  mesh.attribute(vertexTextureCoordinatesAttId)
568  ->SetAttributeValue(draco::AttributeValueIndex(face[2].value()),
569  vertexTextureCoordinates.get() +
570  faces[3 * i.value() + 2] * 3);
571  }
572 
573  // apply materialindices
574  if (faceMaterialIndices)
575  {
576  mesh.attribute(faceMaterialIndicesAttId)
577  ->SetAttributeValue(draco::AttributeValueIndex(face[0].value()),
578  faceMaterialIndices.get() + i.value());
579  mesh.attribute(faceMaterialIndicesAttId)
580  ->SetAttributeValue(draco::AttributeValueIndex(face[1].value()),
581  faceMaterialIndices.get() + i.value());
582  mesh.attribute(faceMaterialIndicesAttId)
583  ->SetAttributeValue(draco::AttributeValueIndex(face[2].value()),
584  faceMaterialIndices.get() + i.value());
585  }
586  }
587  }
588  else
589  {
590  // apply positions
591  for (draco::AttributeValueIndex i(0); i < numVertices; i++)
592  {
593  mesh.attribute(verticesAttId)->SetAttributeValue(i, vertices.get() + i.value() * 3);
594  }
595 
596  // apply normals
597  for (draco::AttributeValueIndex i(0); i < numVertices; i++)
598  {
599  mesh.attribute(vertexNormalsAttId)
600  ->SetAttributeValue(i, vertexNormals.get() + i.value() * 3);
601  }
602 
603  // apply colors
604  for (draco::AttributeValueIndex i(0); i < numVertices; i++)
605  {
606  unsigned char color[3];
607  color[0] = vertexColors[3 * i.value()];
608  color[1] = vertexColors[3 * i.value() + 1];
609  color[2] = vertexColors[3 * i.value() + 2];
610  mesh.attribute(vertexColorsAttId)->SetAttributeValue(i, color);
611  }
612 
613  // // apply confidences
614  // for (draco::AttributeValueIndex i(0); i < numVertexConfidences; i++)
615  // {
616  // mesh.attribute(vertexConfidencesAttId)
617  // ->SetAttributeValue(i, vertexConfidences.get() + i.value());
618  // }
619 
620  // // apply intensities
621  // for (draco::AttributeValueIndex i(0); i < numVertexIntensities; i++)
622  // {
623  // mesh.attribute(vertexIntensitiesAttId)
624  // ->SetAttributeValue(i, vertexIntensities.get() + i.value());
625  // }
626 
627  // apply faces
628  draco::Mesh::Face face;
629  for (draco::FaceIndex i(0); i < numFaces; i++)
630  {
631  for (int j = 0; j < 3; j++)
632  {
633  face[j] = faces[3 * i.value() + j];
634  }
635  mesh.SetFace(i, face);
636  }
637  }
638 
639  mesh.AddMetadata(std::unique_ptr<draco::GeometryMetadata>(metadata));
640 
641  // Encode Data
642  std::unique_ptr<draco::EncoderBuffer> buffer(new draco::EncoderBuffer());
643  auto status = encoder.EncodeMeshToBuffer(mesh, buffer.get());
644 
645  if (!status.ok())
646  {
647  std::cerr << "An error occurred:"
648  << " " << status.error_msg_string() << std::endl;
649  return std::unique_ptr<draco::EncoderBuffer>(nullptr);
650  }
651 
652  return buffer;
653 }
654 
655 std::unique_ptr<draco::EncoderBuffer> encodeDraco(ModelPtr modelPtr,
656  draco::EncodedGeometryType type)
657 {
658  draco::Encoder encoder;
659  // configure encoder
660  encoder.SetSpeedOptions(0, 0);
661 
662  if (type == draco::TRIANGULAR_MESH)
663  {
664  return encodeMesh(modelPtr, encoder);
665  }
666  else if (type == draco::POINT_CLOUD)
667  {
668  // configure this only for pointclounds because it causes loss in visuals of faces on a
669  // plain surface
670  encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 12);
671  encoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD, 12);
672  encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, 10);
673  encoder.SetAttributeQuantization(draco::GeometryAttribute::GENERIC, 8);
674 
675  return encodePointCloud(modelPtr, encoder);
676  }
677 
678  return std::unique_ptr<draco::EncoderBuffer>(nullptr);
679 }
680 
681 } // namespace lvr
void saveTextures(std::vector< int32_t > *textureValue, textureArr textures, size_t numTextures)
pushes the given textures in a int32_t vector to store it in the draco structure
int m_width
The width of the texture in pixels.
Definition: GlTexture.hpp:103
HalfEdgeMesh< Vec > mesh
boost::shared_array< unsigned int > uintArr
Definition: DataStruct.hpp:130
int m_index
Texture index.
Definition: Texture.hpp:108
boost::shared_array< GlTexture *> textureArr
Definition: DataStruct.hpp:159
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
int saveAttributeToDraco(ArrayType array, draco::PointCloud *drcPointcloud, draco::GeometryAttribute::Type geometryType, draco::DataType dracoDataType, size_t numPoints, bool normalized)
adds the given data to a new attribute and attaches the attribute to the pointcloud ...
Handle to access textures of the mesh.
Definition: Handles.hpp:158
__kf_device__ float3 normalized(const float3 &v)
Definition: temp_utils.hpp:97
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
This class represents a texture.
Definition: Texture.hpp:54
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
SingleArray< int > DataType
Definition: data_types.h:222
int m_height
The height of the texture in pixels.
Definition: GlTexture.hpp:106
unsigned char * m_pixels
The aligned pixel data. Three bytes per pixel (r,g,b)
Definition: GlTexture.hpp:109
std::unique_ptr< draco::EncoderBuffer > encodeDraco(ModelPtr modelPtr, draco::EncodedGeometryType type)
encodes Model to draco EncodeBuffer which contents can be written into a file
IdxT idx() const
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
unsigned char * m_data
The texture data.
Definition: Texture.hpp:114
unsigned short int m_width
The dimensions of the texture.
Definition: Texture.hpp:111
std::array< uint8_t, 3 > Rgb8Color
GLuint m_texIndex
The texture index of the texture.
Definition: GlTexture.hpp:112
std::unique_ptr< draco::EncoderBuffer > encodeMesh(ModelPtr modelPtr, draco::Encoder &encoder)
transfers a mesh of a modelPtr to a draco EncoderBuffer that can be written into a file ...
std::unique_ptr< draco::EncoderBuffer > encodePointCloud(ModelPtr modelPtr, draco::Encoder &encoder)
transfers a pointcloud of a modelPtr to a draco EncoderBuffer that can be written into a file ...
unsigned short int m_height
Definition: Texture.hpp:111
Encodes a lvr model into a draco compressed file.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06