Browse Source

cat and .mesh reader writer

Former-commit-id: ff3ad7ac375de5a96e882c2a308a54fb3d241526
jalec 13 years ago
parent
commit
618e148359
10 changed files with 150 additions and 8 deletions
  1. 0 1
      cat.h
  2. 23 0
      examples/cat/Makefile
  3. 9 0
      examples/cat/README
  4. 36 0
      examples/cat/example.cpp
  5. 23 0
      examples/mode/Makefile
  6. 9 0
      examples/mode/README
  7. 34 0
      examples/mode/example.cpp
  8. 6 0
      matlab-to-eigen.html
  9. 1 1
      readMESH.h
  10. 9 6
      writeMESH.h

+ 0 - 1
cat.h

@@ -171,7 +171,6 @@ Mat igl::cat(const int dim, const Mat & A, const Mat & B)
 template <class Mat>
 void cat(const std::vector<std::vector< Mat > > & A, Mat & C)
 {
-  assert(dim == 1 || dim == 2);
   using namespace igl;
   using namespace std;
   // Start with empty matrix

+ 23 - 0
examples/cat/Makefile

@@ -0,0 +1,23 @@
+
+.PHONY: all
+
+all: example
+
+.PHONY: example
+
+igl_lib=../../
+eigen=/usr/local/include/eigen3/
+
+CFLAGS=-g
+inc=-I$(igl_lib) -I$(eigen)
+lib=
+
+example: example.o
+	g++ $(CFLAGS) -o example example.o $(lib)
+	rm example.o
+
+example.o: example.cpp
+	g++ $(CFLAGS) -c example.cpp -o example.o $(inc)
+clean:
+	rm -f example.o
+	rm -f example

+ 9 - 0
examples/cat/README

@@ -0,0 +1,9 @@
+This is a simple example program that shows how to use the cat function on
+eigen matrices like matlab's C = cat(dim,A,B) function
+
+
+To Build:
+  make
+
+To Run:
+  ./example

+ 36 - 0
examples/cat/example.cpp

@@ -0,0 +1,36 @@
+// g++ -o main main.cpp -I. -I/usr/local/include/eigen3
+#include <Eigen/Core>
+#include <iostream>
+#include "cat.h"
+
+using namespace std;
+using namespace igl;
+using namespace Eigen;
+
+
+template <class T>
+void matlab_print(const string name, const T & X)
+{
+  cout<<name<<"=["<<endl<<X<<endl<<"];"<<endl;
+}
+
+int main(int argc, char * argv[])
+{
+  Eigen::MatrixXd A(3,4);
+  A << 
+    3,5,4,5,
+    1,2,4,2,
+    1,1,2,5;
+  matlab_print("A",A);
+  Eigen::MatrixXd B(3,4);
+  B << 
+    13,15,14,15,
+    11,12,14,12,
+    11,11,12,15;
+  matlab_print("B",B);
+  Eigen::MatrixXd C;
+  C = cat(1,A,B);
+  matlab_print("cat(1,A,B)",C);
+  C = cat(2,A,B);
+  matlab_print("cat(2,A,B)",C);
+}

+ 23 - 0
examples/mode/Makefile

@@ -0,0 +1,23 @@
+
+.PHONY: all
+
+all: example
+
+.PHONY: example
+
+igl_lib=../../
+eigen=/usr/local/include/eigen3/
+
+CFLAGS=-g
+inc=-I$(igl_lib) -I$(eigen)
+lib=
+
+example: example.o
+	g++ $(CFLAGS) -o example example.o $(lib)
+	rm example.o
+
+example.o: example.cpp
+	g++ $(CFLAGS) -c example.cpp -o example.o $(inc)
+clean:
+	rm -f example.o
+	rm -f example

+ 9 - 0
examples/mode/README

@@ -0,0 +1,9 @@
+This is a simple example program that shows how to use the mode function on
+eigen matrices like matlab's mode(X,dim) function
+
+
+To Build:
+  make
+
+To Run:
+  ./example

+ 34 - 0
examples/mode/example.cpp

@@ -0,0 +1,34 @@
+// g++ -o main main.cpp -I. -I/usr/local/include/eigen3
+#include <Eigen/Core>
+#include <iostream>
+#include "mode.h"
+
+using namespace std;
+using namespace igl;
+using namespace Eigen;
+
+
+template <class T>
+void matlab_print(const string name, const T & X)
+{
+  cout<<name<<"=["<<endl<<X<<endl<<"];"<<endl;
+}
+
+int main(int argc, char * argv[])
+{
+  Eigen::MatrixXd X(3,4);
+  X << 
+    3,5,4,5,
+    1,2,4,2,
+    1,1,2,5;
+  matlab_print("X",X);
+
+  // Sorted output matrix
+  Eigen::Matrix<double,Dynamic,1> M1;
+  mode(X,1,M1);
+  matlab_print("M1",M1);
+
+  Eigen::Matrix<double,Dynamic,1> M2;
+  mode(X,2,M2);
+  matlab_print("M2",M2);
+}

+ 6 - 0
matlab-to-eigen.html

@@ -233,6 +233,12 @@ tr.gotcha2 td
         <td></td>
       </tr>
 
+      <tr class=d0>
+        <td><pre><code>A = arrayfun(FUN, B)</code></pre></td>
+        <td><pre><code>B = A.unaryExpr(ptr_fun(FUN))</code></pre></td>
+        <td>If FUN is templated, the templates must be fully resolved.</td>
+      </tr>
+
       <!-- Insert rows for each command pair -->
 
       <!-- Leave this here for copy and pasting

+ 1 - 1
readMESH.h

@@ -40,7 +40,7 @@ namespace igl
 
 // Implementation
 #include <cstdio>
-#include <verbose.h>;
+#include <verbose.h>
 
 template <typename Scalar, typename Index>
 inline bool igl::readMESH(

+ 9 - 6
writeMESH.h

@@ -98,7 +98,10 @@ inline bool igl::writeMESH(
   for(int i = 0;i<number_of_triangles;i++)
   {
     // loop over vertices in face
-    fprintf(mesh_file,"%ld %ld %ld 1\n", F(i,0)+1, F(i,1)+1, F(i,2)+1);
+    fprintf(mesh_file,"%d %d %d 1\n", 
+      (int)F(i,0)+1, 
+      (int)F(i,1)+1, 
+      (int)F(i,2)+1);
   }
   // print tetrahedra
   fprintf(mesh_file,"Tetrahedra\n");
@@ -109,11 +112,11 @@ inline bool igl::writeMESH(
   for(size_t i = 0; i < number_of_tetrahedra;i++)
   {
     // mesh standard uses 1-based indexing
-    fprintf(mesh_file, "%ld %ld %ld %ld 1\n",
-      T(i,0)+1,
-      T(i,1)+1,
-      T(i,2)+1,
-      T(i,3)+1);
+    fprintf(mesh_file, "%d %d %d %d 1\n",
+      (int)T(i,0)+1,
+      (int)T(i,1)+1,
+      (int)T(i,2)+1,
+      (int)T(i,3)+1);
   }
   fclose(mesh_file);
   return true;