Browse Source

fix string format issue only supporting doubles

Former-commit-id: 5c9b12bf784fae465f853f35e4940571f1734f78
Alec Jacobson 10 years ago
parent
commit
a8f47a55a5
1 changed files with 9 additions and 2 deletions
  1. 9 2
      include/igl/readSTL.cpp

+ 9 - 2
include/igl/readSTL.cpp

@@ -88,7 +88,8 @@ IGL_INLINE bool igl::readSTL(
       int ret;
       char facet[IGL_LINE_MAX],normal[IGL_LINE_MAX];
       vector<TypeN > n(3);
-      ret = fscanf(stl_file,"%s %s %lg %lg %lg",facet,normal,&n[0],&n[1],&n[2]);
+      double nd[3];
+      ret = fscanf(stl_file,"%s %s %lg %lg %lg",facet,normal,nd,nd+1,nd+2);
       if(string("endsolid") == facet)
       {
         break;
@@ -98,6 +99,8 @@ IGL_INLINE bool igl::readSTL(
         cerr<<"IOError: "<<filename<<" bad format (1)."<<endl;
         goto close_false;
       }
+      // copy casts to Type
+      n[0] = nd[0]; n[1] = nd[1]; n[2] = nd[2];
       N.push_back(n);
       char outer[IGL_LINE_MAX], loop[IGL_LINE_MAX];
       ret = fscanf(stl_file,"%s %s",outer,loop);
@@ -117,13 +120,16 @@ IGL_INLINE bool igl::readSTL(
         }else if(ret == 1 && string("vertex") == word)
         {
           vector<TypeV> v(3);
-          int ret = fscanf(stl_file,"%lg %lg %lg",&v[0],&v[1],&v[2]);
+          double vd[3];
+          int ret = fscanf(stl_file,"%lg %lg %lg",vd,vd+1,vd+2);
           if(ret != 3)
           {
             cerr<<"IOError: "<<filename<<" bad format (3)."<<endl;
             goto close_false;
           }
           f.push_back(V.size());
+          // copy casts to Type
+          v[0] = vd[0]; v[1] = vd[1]; v[2] = vd[2];
           V.push_back(v);
         }else
         {
@@ -219,4 +225,5 @@ close_true:
 template bool igl::readSTL<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 // generated by autoexplicit.sh
 template bool igl::readSTL<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template bool igl::readSTL<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
 #endif