• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Razakhel / RaZ / 8382348195

21 Mar 2024 09:30PM UTC coverage: 79.234%. Remained the same
8382348195

push

github

Razakhel
[Data] Instrumented data features for profiling purposes

7982 of 10074 relevant lines covered (79.23%)

2079.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/RaZ/Data/OffLoad.cpp
1
#include "RaZ/Data/OffFormat.hpp"
2
#include "RaZ/Data/Mesh.hpp"
3
#include "RaZ/Utils/FilePath.hpp"
4
#include "RaZ/Utils/Logger.hpp"
5

6
#include "tracy/Tracy.hpp"
7

8
#include <fstream>
9

10
namespace Raz::OffFormat {
11

12
Mesh load(const FilePath& filePath) {
×
13
  ZoneScopedN("OffFormat::load");
14

15
  Logger::debug("[OffLoad] Loading OFF file ('" + filePath + "')...");
×
16

17
  std::ifstream file(filePath, std::ios_base::in | std::ios_base::binary);
×
18

19
  if (!file)
×
20
    throw std::invalid_argument("Error: Could not open the OFF file '" + filePath + '\'');
×
21

22
  Mesh mesh;
×
23
  Submesh& submesh = mesh.addSubmesh();
×
24

25
  std::size_t vertexCount {};
×
26
  std::size_t faceCount {};
×
27

28
  file.ignore(3);
×
29
  file >> vertexCount >> faceCount;
×
30
  file.ignore(100, '\n');
×
31

32
  std::vector<Vertex>& vertices = submesh.getVertices();
×
33
  vertices.resize(vertexCount * 3);
×
34

35
  std::vector<unsigned int>& indices = submesh.getTriangleIndices();
×
36
  indices.reserve(faceCount * 3);
×
37

38
  for (std::size_t vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) {
×
39
    file >> vertices[vertexIndex].position.x()
×
40
         >> vertices[vertexIndex].position.y()
×
41
         >> vertices[vertexIndex].position.z();
×
42
  }
43

44
  for (std::size_t faceIndex = 0; faceIndex < faceCount; ++faceIndex) {
×
45
    uint16_t partCount {};
×
46
    file >> partCount;
×
47

48
    std::vector<std::size_t> partsIndices(partCount);
×
49
    file >> partsIndices[0] >> partsIndices[1] >> partsIndices[2];
×
50

51
    indices.emplace_back(static_cast<unsigned int>(partsIndices[0]));
×
52
    indices.emplace_back(static_cast<unsigned int>(partsIndices[1]));
×
53
    indices.emplace_back(static_cast<unsigned int>(partsIndices[2]));
×
54

55
    for (uint16_t partIndex = 3; partIndex < partCount; ++partIndex) {
×
56
      file >> partsIndices[partIndex];
×
57

58
      indices.emplace_back(static_cast<unsigned int>(partsIndices[0]));
×
59
      indices.emplace_back(static_cast<unsigned int>(partsIndices[partIndex - 1]));
×
60
      indices.emplace_back(static_cast<unsigned int>(partsIndices[partIndex]));
×
61
    }
62
  }
×
63

64
  indices.shrink_to_fit();
×
65

66
  mesh.computeTangents();
×
67

68
  Logger::debug("[OffLoad] Loaded OFF file (" + std::to_string(mesh.recoverVertexCount()) + " vertices, "
×
69
                                              + std::to_string(mesh.recoverTriangleCount()) + " triangles)");
×
70

71
  return mesh;
×
72
}
×
73

74
} // namespace Raz::OffFormat
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc