瀏覽代碼

handle binary data to fixed size matrix

Former-commit-id: 326b919f650a67ce798ce1b9eed82299c5174d04
Alec Jacobson 10 年之前
父節點
當前提交
0a359fa533
共有 1 個文件被更改,包括 15 次插入2 次删除
  1. 15 2
      include/igl/readDMAT.cpp

+ 15 - 2
include/igl/readDMAT.cpp

@@ -78,8 +78,13 @@ IGL_INLINE bool igl::readDMAT(const std::string file_name,
     return false;
   }
 
-  // Resize output to fit matrix
-  W.resize(num_rows,num_cols);
+  // Resize output to fit matrix, only if non-empty since this will trigger an
+  // error on fixed size matrices before reaching binary data.
+  bool empty = num_rows == 0 || num_cols == 0;
+  if(!empty)
+  {
+    W.resize(num_rows,num_cols);
+  }
 
   // Loop over columns slowly
   for(int j = 0;j < num_cols;j++)
@@ -119,6 +124,14 @@ IGL_INLINE bool igl::readDMAT(const std::string file_name,
         W(i,j) = Wraw[j*num_rows+i];
       }
     }
+  }else
+  {
+    // we skipped resizing before in case there was binary data
+    if(empty)
+    {
+      // This could trigger an error if using fixed size matrices.
+      W.resize(num_rows,num_cols);
+    }
   }
 
   fclose(fp);