Prechádzať zdrojové kódy

bug fix in readDMAT

Former-commit-id: 3fca2bbba7862d8fe86065c063fb5d8ce892d06e
Alec Jacobson (jalec 12 rokov pred
rodič
commit
6b9a74a8e3

+ 1 - 0
file-formats/dmat.html

@@ -36,6 +36,7 @@ Then there should be another header containing the size of the binary part:
 Then coefficents are written in column-major order in Little-endian 4-byte
 double precision IEEE floating point format.
     </p>
+    <p><strong>Note:</strong> Line endings must be <code>'\n'</code> aka char(10) aka line feeds.</p>
     <p>See also: <a href=.>file formats</a></p>
   </div>
   </body>

+ 4 - 4
include/igl/launch_medit.cpp

@@ -11,9 +11,9 @@
 
 template <typename DerivedV, typename DerivedT, typename DerivedF>
 IGL_INLINE int igl::launch_medit(
-  const Eigen::MatrixBase<DerivedV> & V, 
-  const Eigen::MatrixBase<DerivedT> & T,
-  const Eigen::MatrixBase<DerivedF> & F,
+  const Eigen::PlainObjectBase<DerivedV> & V, 
+  const Eigen::PlainObjectBase<DerivedT> & T,
+  const Eigen::PlainObjectBase<DerivedF> & F,
   const bool wait)
 {
   using namespace std;
@@ -57,6 +57,6 @@ IGL_INLINE int igl::launch_medit(
 
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
-template int igl::launch_medit<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, bool);
+template int igl::launch_medit<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, bool);
 #endif
 

+ 4 - 4
include/igl/launch_medit.h

@@ -2,7 +2,7 @@
 #define IGL_LAUNCH_MEDIT_H
 #include "igl_inline.h"
 
-#include <Eigen/Dense>
+#include <Eigen/Core>
 
 namespace igl 
 {
@@ -23,9 +23,9 @@ namespace igl
   // because of the fork)
   template <typename DerivedV, typename DerivedT, typename DerivedF>
   IGL_INLINE int launch_medit(
-    const Eigen::MatrixBase<DerivedV> & V, 
-    const Eigen::MatrixBase<DerivedT> & T,
-    const Eigen::MatrixBase<DerivedF> & F,
+    const Eigen::PlainObjectBase<DerivedV> & V, 
+    const Eigen::PlainObjectBase<DerivedT> & T,
+    const Eigen::PlainObjectBase<DerivedF> & F,
     const bool wait);
 }
 

+ 10 - 1
include/igl/readDMAT.cpp

@@ -16,10 +16,11 @@
 //   1  did not find header
 //   2  bad num_cols
 //   3  bad num_rows
+//   4  bad line ending
 static inline int readDMAT_read_header(FILE * fp, int & num_rows, int & num_cols)
 {
   // first line contains number of rows and number of columns
-  int res = fscanf(fp,"%d %d\n",&num_cols,&num_rows);
+  int res = fscanf(fp,"%d %d",&num_cols,&num_rows);
   if(res != 2)
   {
     return 1;
@@ -35,6 +36,14 @@ static inline int readDMAT_read_header(FILE * fp, int & num_rows, int & num_cols
     fprintf(stderr,"IOError: readDMAT() number of rows %d < 0\n",num_rows);
     return 3;
   }
+  // finish reading header
+  char lf;
+  if(fread(&lf, sizeof(char), 1, fp)!=1 || lf != '\n')
+  {
+    fprintf(stderr,"IOError: bad line ending in header\n");
+    return 4;
+  }
+
   return 0;
 }
 

+ 1 - 1
include/igl/writeDMAT.cpp

@@ -37,6 +37,7 @@ IGL_INLINE bool igl::writeDMAT(
     // first line contains number of rows and number of columns
     fprintf(fp,"%d %d\n",(int)W.cols(),(int)W.rows());
     Eigen::MatrixXd Wd = W.template cast<double>();
+    fwrite(Wd.data(),sizeof(double),Wd.size(),fp);
     //// Loop over columns slowly
     //for(int j = 0;j < W.cols();j++)
     //{
@@ -47,7 +48,6 @@ IGL_INLINE bool igl::writeDMAT(
     //    fwrite(&d,sizeof(double),1,fp);
     //  }
     //}
-    fwrite(Wd.data(),sizeof(double),Wd.size(),fp);
   }
   fclose(fp);
   return true;