소스 검색

removed numpy dependencies, added constructor from lists to dense matrices

Former-commit-id: d8d04a7774a30749b8cd0f022880d69164f99a2a
Daniele Panozzo 9 년 전
부모
커밋
6c117041d6
7개의 변경된 파일40개의 추가작업 그리고 23개의 파일을 삭제
  1. 0 2
      python/101_FileIO.py
  2. 8 10
      python/105_Overlays.py
  3. 2 4
      python/203_CurvatureDirections.py
  4. 1 2
      python/204_Gradient.py
  5. 1 2
      python/205_Laplacian.py
  6. 5 3
      python/301_Slice.py
  7. 23 0
      python/py_vector.cpp

+ 0 - 2
python/101_FileIO.py

@@ -1,6 +1,4 @@
 from __future__ import print_function
-import sys, os
-import numpy as np
 import igl
 
 # Load a mesh in OFF format

+ 8 - 10
python/105_Overlays.py

@@ -1,6 +1,4 @@
 import igl
-import numpy as np
-from iglhelpers import *
 
 V = igl.eigen.MatrixXd()
 F = igl.eigen.MatrixXi()
@@ -12,8 +10,9 @@ igl.readOFF("../tutorial/shared/bunny.off", V, F)
 m = V.colwiseMinCoeff()
 M = V.colwiseMaxCoeff()
 
+
 # Corners of the bounding box
-V_box = p2e(np.matrix(
+V_box = igl.eigen.MatrixXd(
 [
 [m[0,0], m[0,1], m[0,2]],
 [M[0,0], m[0,1], m[0,2]],
@@ -24,9 +23,9 @@ V_box = p2e(np.matrix(
 [M[0,0], M[0,1], M[0,2]],
 [m[0,0], M[0,1], M[0,2]]
 ]
-))
+)
 
-E_box = p2e(np.matrix(
+E_box = igl.eigen.MatrixXi(
 [
 [0, 1],
 [1, 2],
@@ -40,23 +39,22 @@ E_box = p2e(np.matrix(
 [1, 5],
 [2, 6],
 [7 ,3]
-], dtype='int32'
-))
+]
+)
 
 # Plot the mesh
 viewer = igl.viewer.Viewer()
 viewer.data.set_mesh(V, F)
 
 # Plot the corners of the bounding box as points
-viewer.data.add_points(V_box,p2e(np.array([[1,0,0]], dtype='float64')))
+viewer.data.add_points(V_box,igl.eigen.MatrixXd([[1,0,0]]))
 
 # Plot the edges of the bounding box
-
 for i in range(0,E_box.rows()):
     viewer.data.add_edges(
         V_box.row(E_box[i,0]),
         V_box.row(E_box[i,1]),
-        p2e(np.array([[1,0,0]], dtype='float64')))
+        igl.eigen.MatrixXd([[1,0,0]]))
 
 # Plot labels with the coordinates of bounding box vertices
 l1 = 'x: ' + str(m[0,0]) + ' y: ' + str(m[0,1]) + ' z: ' + str(m[0,2])

+ 2 - 4
python/203_CurvatureDirections.py

@@ -1,6 +1,4 @@
 import igl
-import numpy as np
-from iglhelpers import *
 
 V = igl.eigen.MatrixXd();
 F = igl.eigen.MatrixXi();
@@ -49,8 +47,8 @@ viewer.data.set_colors(C)
 avg = igl.avg_edge_length(V,F)
 
 # Draw a blue segment parallel to the minimal curvature direction
-red = p2e(np.array([[0.8,0.2,0.2]]))
-blue = p2e(np.array([[0.2,0.2,0.8]]))
+red = igl.eigen.MatrixXd([[0.8,0.2,0.2]])
+blue = igl.eigen.MatrixXd([[0.2,0.2,0.8]])
 
 viewer.data.add_edges(V + PD1*avg, V - PD1*avg, blue)
 

+ 1 - 2
python/204_Gradient.py

@@ -1,5 +1,4 @@
 import igl
-from iglhelpers import *
 
 V = igl.eigen.MatrixXd()
 F = igl.eigen.MatrixXi()
@@ -42,7 +41,7 @@ max_size = igl.avg_edge_length(V,F) / GU_mag.mean()
 BC = igl.eigen.MatrixXd()
 igl.barycenter(V,F,BC)
 
-black = p2e(np.array([[0.0,0.0,0.0]]))
+black = igl.eigen.MatrixXd([[0.0,0.0,0.0]])
 viewer.data.add_edges(BC,BC+max_size*GU, black)
 
 # Hide wireframe

+ 1 - 2
python/205_Laplacian.py

@@ -1,6 +1,5 @@
 from __future__ import print_function
 import igl
-from iglhelpers import *
 import math
 
 global V
@@ -74,7 +73,7 @@ def key_pressed(viewer, key, modifier):
         area = 0.5*dblA.sum()
         BC = igl.eigen.MatrixXd()
         igl.barycenter(U,F,BC)
-        centroid = p2e(np.array([[0.0,0.0,0.0]]))
+        centroid = igl.eigen.MatrixXd([[0.0,0.0,0.0]])
 
         for i in range(0,BC.rows()):
             centroid += 0.5*dblA[i,0]/area*BC.row(i)

+ 5 - 3
python/301_Slice.py

@@ -1,6 +1,5 @@
 from __future__ import print_function
 import igl
-from iglhelpers import *
 
 V = igl.eigen.MatrixXd()
 F = igl.eigen.MatrixXi()
@@ -24,11 +23,14 @@ igl.floor((0.5*(temp+1.)*I.rows()),J)
 K = igl.eigen.MatrixXi()
 igl.slice(I,J,K)
 
+exit(0)
+
 # default green for all faces
-C = p2e(np.array([[0.4,0.8,0.3]])).replicate(F.rows(),1)
+#C = p2e(np.array([[0.4,0.8,0.3]])).replicate(F.rows(),1)
+C = igl.eigen.MatrixXd([[0.4,0.8,0.3]]).replicate(F.rows(),1)
 
 # Red for each in K
-R = p2e(np.array([[1.0,0.3,0.3]])).replicate(K.rows(),1)
+R = igl.eigen.MatrixXd([[1.0,0.3,0.3]]).replicate(K.rows(),1)
 # C(K,:) = R
 igl.slice_into(R,K,1,C)
 

+ 23 - 0
python/py_vector.cpp

@@ -22,6 +22,29 @@ py::class_<Type> bind_eigen_2(py::module &m, const char *name,
             new (&m) Type(1, 1);
             m(0, 0) = f;
         })
+        .def("__init__", [](Type &m, std::vector<std::vector< Scalar> >& b) {
+          if (b.size() == 0)
+          {
+            new (&m) Type(0, 0);
+            return;
+          }
+
+          // Size checks
+          unsigned rows = b.size();
+          unsigned cols = b[0].size();
+          for (unsigned i=0;i<rows;++i)
+            if (b[i].size() != cols)
+              throw std::runtime_error("All rows should have the same size!");
+
+          new (&m) Type(rows, cols);
+
+          m.resize(rows,cols);
+          for (unsigned i=0;i<rows;++i)
+            for (unsigned j=0;j<cols;++j)
+              m(i,j) = b[i][j];
+
+          return;
+        })
         .def("__init__", [](Type &m, py::buffer b) {
             py::buffer_info info = b.request();
             if (info.format != py::format_descriptor<Scalar>::value())