void write_faces(std::ofstream& fout, const VectorI& faces, const size_t vertex_per_face, const VectorI& uv_indices=VectorI::Zero(0)) { if (vertex_per_face != 3 && vertex_per_face != 4) { std::stringstream err_msg; err_msg << "OBJ format does not support non-triangle non-quad face with " << vertex_per_face << " vertices." << std::endl; throw RuntimeError(err_msg.str()); } const size_t num_faces = faces.size() / vertex_per_face; const size_t num_uvs = uv_indices.size() / 2; if (num_uvs == 0) { for (size_t i=0; i<num_faces; i++) { const auto& f = faces.segment(i*vertex_per_face, vertex_per_face); fout << "f"; for (size_t j=0; j<vertex_per_face; j++) { fout << " " << f[j] + 1; } fout << std::endl; } } else { for (size_t i=0; i<num_faces; i++) { const auto& f = faces.segment(i*vertex_per_face, vertex_per_face); const auto& uv = uv_indices.segment(i*vertex_per_face, vertex_per_face); fout << "f "; for (size_t j=0; j<vertex_per_face; j++) { fout << f[j] + 1 << "/" << uv[j] + 1 << " "; } fout << std::endl; } } }
void correct_tet_orientation(const VectorF& vertices, VectorI& voxels) { const size_t num_voxels = voxels.size() / 4; for (size_t i=0; i<num_voxels; i++) { const VectorI tet = voxels.segment(i*4, 4); const Vector3F& v1 = vertices.segment(tet[0]*3, 3); const Vector3F& v2 = vertices.segment(tet[1]*3, 3); const Vector3F& v3 = vertices.segment(tet[2]*3, 3); const Vector3F& v4 = vertices.segment(tet[3]*3, 3); if (!positive_orientated(v1, v2, v3, v4)) { voxels[i*4] = tet[1]; voxels[i*4+1] = tet[0]; } } }