@@ -30,7 +30,7 @@ void readOBJ(const std::string& filename,
3030 std::vector<openvdb::Vec3s>& points,
3131 std::vector<openvdb::Vec3I>& triangles,
3232 std::vector<openvdb::Vec4I>& quads)
33- {
33+ {
3434 std::ifstream file (filename);
3535 if (!file.is_open ()) {
3636 OPENVDB_THROW (openvdb::IoError, " Failed to open OBJ file: " + filename);
@@ -44,52 +44,52 @@ void readOBJ(const std::string& filename,
4444 std::istringstream iss (line);
4545 std::string type;
4646 iss >> type;
47-
47+
4848 if (type == " v" ) {
4949 float x, y, z;
5050 iss >> x >> y >> z;
5151 points.push_back (openvdb::Vec3s (x, y, z));
5252 } else if (type == " f" ) {
5353 std::vector<int > faceIndices;
5454 std::string vertexData;
55-
55+
5656 while (iss >> vertexData) {
5757 // Isolate the vertex index (everything before the first slash)
5858 size_t slashPos = vertexData.find (' /' );
5959 std::string indexStr = vertexData.substr (0 , slashPos);
60-
60+
6161 if (indexStr.empty ()) continue ;
6262
6363 int raw_idx = std::stoi (indexStr);
6464 int actual_idx = 0 ;
65-
65+
6666 // Handle negative indices: relative to the number of points parsed so far
6767 if (raw_idx < 0 ) {
68- actual_idx = points.size () + raw_idx;
68+ actual_idx = points.size () + raw_idx;
6969 } else {
7070 // Standard positive indices: OBJ is 1-based, convert to 0-based for C++
71- actual_idx = raw_idx - 1 ;
71+ actual_idx = raw_idx - 1 ;
7272 }
7373
7474 // Strict bounds checking to prevent segfaults
7575 if (actual_idx < 0 || actual_idx >= points.size ()) {
76- OPENVDB_THROW (openvdb::ValueError,
77- " OBJ parse error on line " + std::to_string (lineNumber) +
78- " : Face index out of bounds (Raw: " + std::to_string (raw_idx) +
79- " , Computed: " + std::to_string (actual_idx) + " , Total Points: " +
76+ OPENVDB_THROW (openvdb::ValueError,
77+ " OBJ parse error on line " + std::to_string (lineNumber) +
78+ " : Face index out of bounds (Raw: " + std::to_string (raw_idx) +
79+ " , Computed: " + std::to_string (actual_idx) + " , Total Points: " +
8080 std::to_string (points.size ()) + " )" );
8181 }
8282
83- faceIndices.push_back (actual_idx);
83+ faceIndices.push_back (actual_idx);
8484 }
85-
85+
8686 // Add to the appropriate OpenVDB list
8787 if (faceIndices.size () == 3 ) {
8888 triangles.push_back (openvdb::Vec3I (faceIndices[0 ], faceIndices[1 ], faceIndices[2 ]));
8989 } else if (faceIndices.size () == 4 ) {
9090 quads.push_back (openvdb::Vec4I (faceIndices[0 ], faceIndices[1 ], faceIndices[2 ], faceIndices[3 ]));
9191 } else if (faceIndices.size () > 4 ) {
92- std::cerr << " Warning on line " << lineNumber << " : Skipping face with "
92+ std::cerr << " Warning on line " << lineNumber << " : Skipping face with "
9393 << faceIndices.size () << " vertices. Triangulate your mesh!" << std::endl;
9494 }
9595 }
@@ -121,8 +121,8 @@ int main(int argc, char *argv[])
121121 // Read the OBJ file
122122 std::cout << " Reading " << inputFile << " ..." << std::endl;
123123 readOBJ (inputFile, openvdb_points, openvdb_triangles, quads);
124- std::cout << " Loaded " << openvdb_points.size () << " vertices, "
125- << openvdb_triangles.size () << " openvdb_triangles, and "
124+ std::cout << " Loaded " << openvdb_points.size () << " vertices, "
125+ << openvdb_triangles.size () << " openvdb_triangles, and "
126126 << quads.size () << " quads." << std::endl;
127127
128128 // Initialize OpenVDB
@@ -154,7 +154,7 @@ int main(int argc, char *argv[])
154154 // Cast the raw pointers from the std::vector data
155155 const auto * nano_pts_data = reinterpret_cast <const nanovdb::Vec3f*>(openvdb_points.data ());
156156 const auto * nano_tris_data = reinterpret_cast <const nanovdb::Vec3i*>(openvdb_triangles.data ());
157-
157+
158158 // Initialize the thrust vectors using the casted pointer ranges
159159 thrust::universal_vector<nanovdb::Vec3f> nanovdb_points (nano_pts_data, nano_pts_data + openvdb_points.size ());
160160 thrust::universal_vector<nanovdb::Vec3i> nanovdb_triangles (nano_tris_data, nano_tris_data + openvdb_triangles.size ());
0 commit comments