|
@@ -4,7 +4,8 @@ template <typename Scalar, typename Index>
|
|
|
IGL_INLINE bool igl::readOFF(
|
|
|
const std::string off_file_name,
|
|
|
std::vector<std::vector<Scalar > > & V,
|
|
|
- std::vector<std::vector<Index > > & F)
|
|
|
+ std::vector<std::vector<Index > > & F,
|
|
|
+ std::vector<std::vector<Scalar > > & N)
|
|
|
{
|
|
|
FILE * off_file = fopen(off_file_name.c_str(),"r");
|
|
|
if(NULL==off_file)
|
|
@@ -14,6 +15,7 @@ IGL_INLINE bool igl::readOFF(
|
|
|
}
|
|
|
V.clear();
|
|
|
F.clear();
|
|
|
+ N.clear();
|
|
|
// First line is always OFF
|
|
|
char header[1000];
|
|
|
const std::string OFF("OFF");
|
|
@@ -40,6 +42,8 @@ IGL_INLINE bool igl::readOFF(
|
|
|
}
|
|
|
sscanf(line,"%d %d %d",&number_of_vertices,&number_of_faces,&number_of_edges);
|
|
|
V.resize(number_of_vertices);
|
|
|
+ if (has_normals)
|
|
|
+ N.resize(number_of_vertices);
|
|
|
F.resize(number_of_faces);
|
|
|
//printf("%s %d %d %d\n",(has_normals ? "NOFF" : "OFF"),number_of_vertices,number_of_faces,number_of_edges);
|
|
|
// Read vertices
|
|
@@ -55,6 +59,16 @@ IGL_INLINE bool igl::readOFF(
|
|
|
vertex[1] = y;
|
|
|
vertex[2] = z;
|
|
|
V[i] = vertex;
|
|
|
+
|
|
|
+ if (has_normals)
|
|
|
+ {
|
|
|
+ std::vector<Scalar > normal;
|
|
|
+ normal.resize(3);
|
|
|
+ normal[0] = nx;
|
|
|
+ normal[1] = ny;
|
|
|
+ normal[2] = nz;
|
|
|
+ N[i] = normal;
|
|
|
+ }
|
|
|
i++;
|
|
|
}else if(
|
|
|
fscanf(off_file,"%[#]",&tic_tac_toe)==1)
|
|
@@ -109,13 +123,14 @@ IGL_INLINE bool igl::readOFF(
|
|
|
|
|
|
template <typename DerivedV, typename DerivedF>
|
|
|
IGL_INLINE bool igl::readOFF(
|
|
|
- const std::string str,
|
|
|
- Eigen::PlainObjectBase<DerivedV>& V,
|
|
|
- Eigen::PlainObjectBase<DerivedF>& F)
|
|
|
+ const std::string str,
|
|
|
+ Eigen::PlainObjectBase<DerivedV>& V,
|
|
|
+ Eigen::PlainObjectBase<DerivedF>& F)
|
|
|
{
|
|
|
std::vector<std::vector<double> > vV;
|
|
|
+ std::vector<std::vector<double> > vN;
|
|
|
std::vector<std::vector<int> > vF;
|
|
|
- bool success = igl::readOFF(str,vV,vF);
|
|
|
+ bool success = igl::readOFF(str,vV,vF,vN);
|
|
|
if(!success)
|
|
|
{
|
|
|
// readOFF(str,vV,vF) should have already printed an error
|
|
@@ -136,8 +151,54 @@ IGL_INLINE bool igl::readOFF(
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+template <typename DerivedV, typename DerivedF>
|
|
|
+IGL_INLINE bool igl::readOFF(
|
|
|
+ const std::string str,
|
|
|
+ Eigen::PlainObjectBase<DerivedV>& V,
|
|
|
+ Eigen::PlainObjectBase<DerivedF>& F,
|
|
|
+ Eigen::PlainObjectBase<DerivedV>& N)
|
|
|
+{
|
|
|
+ std::vector<std::vector<double> > vV;
|
|
|
+ std::vector<std::vector<double> > vN;
|
|
|
+ std::vector<std::vector<int> > vF;
|
|
|
+ bool success = igl::readOFF(str,vV,vF,vN);
|
|
|
+ if(!success)
|
|
|
+ {
|
|
|
+ // readOFF(str,vV,vF) should have already printed an error
|
|
|
+ // message to stderr
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bool V_rect = igl::list_to_matrix(vV,V);
|
|
|
+ if(!V_rect)
|
|
|
+ {
|
|
|
+ // igl::list_to_matrix(vV,V) already printed error message to std err
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ bool F_rect = igl::list_to_matrix(vF,F);
|
|
|
+ if(!F_rect)
|
|
|
+ {
|
|
|
+ // igl::list_to_matrix(vF,F) already printed error message to std err
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (vN.size())
|
|
|
+ {
|
|
|
+ bool N_rect = igl::list_to_matrix(vN,N);
|
|
|
+ if(!N_rect)
|
|
|
+ {
|
|
|
+ // igl::list_to_matrix(vN,N) already printed error message to std err
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
#ifndef IGL_HEADER_ONLY
|
|
|
// Explicit template specialization
|
|
|
// generated by autoexplicit.sh
|
|
|
template bool igl::readOFF<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
|
|
|
+template bool igl::readOFF<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&);
|
|
|
#endif
|