frame_field.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Daniele Panozzo <daniele.panozzo@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "frame_field.h"
  9. #include <igl/triangle_triangle_adjacency.h>
  10. #include <igl/edge_topology.h>
  11. #include <igl/per_face_normals.h>
  12. #include <igl/comiso/nrosy.h>
  13. #include <iostream>
  14. namespace igl
  15. {
  16. namespace comiso
  17. {
  18. class FrameInterpolator
  19. {
  20. public:
  21. // Init
  22. IGL_INLINE FrameInterpolator(const Eigen::MatrixXd& _V, const Eigen::MatrixXi& _F);
  23. IGL_INLINE ~FrameInterpolator();
  24. // Reset constraints (at least one constraint must be present or solve will fail)
  25. IGL_INLINE void resetConstraints();
  26. IGL_INLINE void setConstraint(const int fid, const Eigen::VectorXd& v);
  27. IGL_INLINE void interpolateSymmetric();
  28. // Generate the frame field
  29. IGL_INLINE void solve();
  30. // Convert the frame field in the canonical representation
  31. IGL_INLINE void frame2canonical(const Eigen::MatrixXd& TP, const Eigen::RowVectorXd& v, double& theta, Eigen::VectorXd& S);
  32. // Convert the canonical representation in a frame field
  33. IGL_INLINE void canonical2frame(const Eigen::MatrixXd& TP, const double theta, const Eigen::VectorXd& S, Eigen::RowVectorXd& v);
  34. IGL_INLINE Eigen::MatrixXd getFieldPerFace();
  35. IGL_INLINE void PolarDecomposition(Eigen::MatrixXd V, Eigen::MatrixXd& U, Eigen::MatrixXd& P);
  36. // Symmetric
  37. Eigen::MatrixXd S;
  38. std::vector<bool> S_c;
  39. // -------------------------------------------------
  40. // Face Topology
  41. Eigen::MatrixXi TT, TTi;
  42. // Two faces are consistent if their representative vector are taken modulo PI
  43. std::vector<bool> edge_consistency;
  44. Eigen::MatrixXi edge_consistency_TT;
  45. private:
  46. IGL_INLINE double mod2pi(double d);
  47. IGL_INLINE double modpi2(double d);
  48. IGL_INLINE double modpi(double d);
  49. // Convert a direction on the tangent space into an angle
  50. IGL_INLINE double vector2theta(const Eigen::MatrixXd& TP, const Eigen::RowVectorXd& v);
  51. // Convert an angle in a vector in the tangent space
  52. IGL_INLINE Eigen::RowVectorXd theta2vector(const Eigen::MatrixXd& TP, const double theta);
  53. // Interpolate the cross field (theta)
  54. IGL_INLINE void interpolateCross();
  55. // Compute difference between reference frames
  56. IGL_INLINE void computek();
  57. // Compute edge consistency
  58. IGL_INLINE void compute_edge_consistency();
  59. // Cross field direction
  60. Eigen::VectorXd thetas;
  61. std::vector<bool> thetas_c;
  62. // Edge Topology
  63. Eigen::MatrixXi EV, FE, EF;
  64. std::vector<bool> isBorderEdge;
  65. // Angle between two reference frames
  66. // R(k) * t0 = t1
  67. Eigen::VectorXd k;
  68. // Mesh
  69. Eigen::MatrixXd V;
  70. Eigen::MatrixXi F;
  71. // Normals per face
  72. Eigen::MatrixXd N;
  73. // Reference frame per triangle
  74. std::vector<Eigen::MatrixXd> TPs;
  75. };
  76. FrameInterpolator::FrameInterpolator(const Eigen::MatrixXd& _V, const Eigen::MatrixXi& _F)
  77. {
  78. using namespace std;
  79. using namespace Eigen;
  80. V = _V;
  81. F = _F;
  82. assert(V.rows() > 0);
  83. assert(F.rows() > 0);
  84. // Generate topological relations
  85. igl::triangle_triangle_adjacency(F,TT,TTi);
  86. igl::edge_topology(V,F, EV, FE, EF);
  87. // Flag border edges
  88. isBorderEdge.resize(EV.rows());
  89. for(unsigned i=0; i<EV.rows(); ++i)
  90. isBorderEdge[i] = (EF(i,0) == -1) || ((EF(i,1) == -1));
  91. // Generate normals per face
  92. igl::per_face_normals(V, F, N);
  93. // Generate reference frames
  94. for(unsigned fid=0; fid<F.rows(); ++fid)
  95. {
  96. // First edge
  97. Vector3d e1 = V.row(F(fid,1)) - V.row(F(fid,0));
  98. e1.normalize();
  99. Vector3d e2 = N.row(fid);
  100. e2 = e2.cross(e1);
  101. e2.normalize();
  102. MatrixXd TP(2,3);
  103. TP << e1.transpose(), e2.transpose();
  104. TPs.push_back(TP);
  105. }
  106. // Reset the constraints
  107. resetConstraints();
  108. // Compute k, differences between reference frames
  109. computek();
  110. // Alloc internal variables
  111. thetas = VectorXd::Zero(F.rows());
  112. S = MatrixXd::Zero(F.rows(),3);
  113. compute_edge_consistency();
  114. }
  115. FrameInterpolator::~FrameInterpolator()
  116. {
  117. }
  118. double FrameInterpolator::mod2pi(double d)
  119. {
  120. while(d<0)
  121. d = d + (2.0*M_PI);
  122. return fmod(d, (2.0*M_PI));
  123. }
  124. double FrameInterpolator::modpi2(double d)
  125. {
  126. while(d<0)
  127. d = d + (M_PI/2.0);
  128. return fmod(d, (M_PI/2.0));
  129. }
  130. double FrameInterpolator::modpi(double d)
  131. {
  132. while(d<0)
  133. d = d + (M_PI);
  134. return fmod(d, (M_PI));
  135. }
  136. double FrameInterpolator::vector2theta(const Eigen::MatrixXd& TP, const Eigen::RowVectorXd& v)
  137. {
  138. // Project onto the tangent plane
  139. Eigen::Vector2d vp = TP * v.transpose();
  140. // Convert to angle
  141. double theta = atan2(vp(1),vp(0));
  142. return theta;
  143. }
  144. Eigen::RowVectorXd FrameInterpolator::theta2vector(const Eigen::MatrixXd& TP, const double theta)
  145. {
  146. Eigen::Vector2d vp(cos(theta),sin(theta));
  147. return vp.transpose() * TP;
  148. }
  149. void FrameInterpolator::interpolateCross()
  150. {
  151. using namespace std;
  152. using namespace Eigen;
  153. //olga: was
  154. // NRosyField nrosy(V,F);
  155. // for (unsigned i=0; i<F.rows(); ++i)
  156. // if(thetas_c[i])
  157. // nrosy.setConstraintHard(i,theta2vector(TPs[i],thetas(i)));
  158. // nrosy.solve(4);
  159. // MatrixXd R = nrosy.getFieldPerFace();
  160. //olga: is
  161. Eigen::MatrixXd R;
  162. Eigen::VectorXd S;
  163. Eigen::VectorXi b; b.resize(F.rows(),1);
  164. Eigen::MatrixXd bc; bc.resize(F.rows(),3);
  165. int num = 0;
  166. for (unsigned i=0; i<F.rows(); ++i)
  167. if(thetas_c[i])
  168. {
  169. b[num] = i;
  170. bc.row(num) = theta2vector(TPs[i],thetas(i));
  171. num++;
  172. }
  173. b.conservativeResize(num,Eigen::NoChange);
  174. bc.conservativeResize(num,Eigen::NoChange);
  175. igl::comiso::nrosy(V, F, b, bc, 4, R, S);
  176. //olga:end
  177. assert(R.rows() == F.rows());
  178. for (unsigned i=0; i<F.rows(); ++i)
  179. thetas(i) = vector2theta(TPs[i],R.row(i));
  180. }
  181. void FrameInterpolator::resetConstraints()
  182. {
  183. thetas_c.resize(F.rows());
  184. S_c.resize(F.rows());
  185. for(unsigned i=0; i<F.rows(); ++i)
  186. {
  187. thetas_c[i] = false;
  188. S_c[i] = false;
  189. }
  190. }
  191. void FrameInterpolator::compute_edge_consistency()
  192. {
  193. using namespace std;
  194. using namespace Eigen;
  195. // Compute per-edge consistency
  196. edge_consistency.resize(EF.rows());
  197. edge_consistency_TT = MatrixXi::Constant(TT.rows(),3,-1);
  198. // For every non-border edge
  199. for (unsigned eid=0; eid<EF.rows(); ++eid)
  200. {
  201. if (!isBorderEdge[eid])
  202. {
  203. int fid0 = EF(eid,0);
  204. int fid1 = EF(eid,1);
  205. double theta0 = thetas(fid0);
  206. double theta1 = thetas(fid1);
  207. theta0 = theta0 + k(eid);
  208. double r = modpi(theta0-theta1);
  209. edge_consistency[eid] = r < M_PI/4.0 || r > 3*(M_PI/4.0);
  210. // Copy it into edge_consistency_TT
  211. int i1 = -1;
  212. int i2 = -1;
  213. for (unsigned i=0; i<3; ++i)
  214. {
  215. if (TT(fid0,i) == fid1)
  216. i1 = i;
  217. if (TT(fid1,i) == fid0)
  218. i2 = i;
  219. }
  220. assert(i1 != -1);
  221. assert(i2 != -1);
  222. edge_consistency_TT(fid0,i1) = edge_consistency[eid];
  223. edge_consistency_TT(fid1,i2) = edge_consistency[eid];
  224. }
  225. }
  226. }
  227. void FrameInterpolator::computek()
  228. {
  229. using namespace std;
  230. using namespace Eigen;
  231. k.resize(EF.rows());
  232. // For every non-border edge
  233. for (unsigned eid=0; eid<EF.rows(); ++eid)
  234. {
  235. if (!isBorderEdge[eid])
  236. {
  237. int fid0 = EF(eid,0);
  238. int fid1 = EF(eid,1);
  239. Vector3d N0 = N.row(fid0);
  240. //Vector3d N1 = N.row(fid1);
  241. // find common edge on triangle 0 and 1
  242. int fid0_vc = -1;
  243. int fid1_vc = -1;
  244. for (unsigned i=0;i<3;++i)
  245. {
  246. if (EV(eid,0) == F(fid0,i))
  247. fid0_vc = i;
  248. if (EV(eid,1) == F(fid1,i))
  249. fid1_vc = i;
  250. }
  251. assert(fid0_vc != -1);
  252. assert(fid1_vc != -1);
  253. Vector3d common_edge = V.row(F(fid0,(fid0_vc+1)%3)) - V.row(F(fid0,fid0_vc));
  254. common_edge.normalize();
  255. // Map the two triangles in a new space where the common edge is the x axis and the N0 the z axis
  256. MatrixXd P(3,3);
  257. VectorXd o = V.row(F(fid0,fid0_vc));
  258. VectorXd tmp = -N0.cross(common_edge);
  259. P << common_edge, tmp, N0;
  260. P.transposeInPlace();
  261. MatrixXd V0(3,3);
  262. V0.row(0) = V.row(F(fid0,0)).transpose() -o;
  263. V0.row(1) = V.row(F(fid0,1)).transpose() -o;
  264. V0.row(2) = V.row(F(fid0,2)).transpose() -o;
  265. V0 = (P*V0.transpose()).transpose();
  266. assert(V0(0,2) < 10e-10);
  267. assert(V0(1,2) < 10e-10);
  268. assert(V0(2,2) < 10e-10);
  269. MatrixXd V1(3,3);
  270. V1.row(0) = V.row(F(fid1,0)).transpose() -o;
  271. V1.row(1) = V.row(F(fid1,1)).transpose() -o;
  272. V1.row(2) = V.row(F(fid1,2)).transpose() -o;
  273. V1 = (P*V1.transpose()).transpose();
  274. assert(V1(fid1_vc,2) < 10e-10);
  275. assert(V1((fid1_vc+1)%3,2) < 10e-10);
  276. // compute rotation R such that R * N1 = N0
  277. // i.e. map both triangles to the same plane
  278. double alpha = -atan2(V1((fid1_vc+2)%3,2),V1((fid1_vc+2)%3,1));
  279. MatrixXd R(3,3);
  280. R << 1, 0, 0,
  281. 0, cos(alpha), -sin(alpha) ,
  282. 0, sin(alpha), cos(alpha);
  283. V1 = (R*V1.transpose()).transpose();
  284. assert(V1(0,2) < 10e-10);
  285. assert(V1(1,2) < 10e-10);
  286. assert(V1(2,2) < 10e-10);
  287. // measure the angle between the reference frames
  288. // k_ij is the angle between the triangle on the left and the one on the right
  289. VectorXd ref0 = V0.row(1) - V0.row(0);
  290. VectorXd ref1 = V1.row(1) - V1.row(0);
  291. ref0.normalize();
  292. ref1.normalize();
  293. double ktemp = atan2(ref1(1),ref1(0)) - atan2(ref0(1),ref0(0));
  294. // just to be sure, rotate ref0 using angle ktemp...
  295. MatrixXd R2(2,2);
  296. R2 << cos(ktemp), -sin(ktemp), sin(ktemp), cos(ktemp);
  297. tmp = R2*ref0.head<2>();
  298. assert(tmp(0) - ref1(0) < (0.000001));
  299. assert(tmp(1) - ref1(1) < (0.000001));
  300. k[eid] = ktemp;
  301. }
  302. }
  303. }
  304. void FrameInterpolator::frame2canonical(const Eigen::MatrixXd& TP, const Eigen::RowVectorXd& v, double& theta, Eigen::VectorXd& S_v)
  305. {
  306. using namespace std;
  307. using namespace Eigen;
  308. RowVectorXd v0 = v.segment<3>(0);
  309. RowVectorXd v1 = v.segment<3>(3);
  310. // Project onto the tangent plane
  311. Vector2d vp0 = TP * v0.transpose();
  312. Vector2d vp1 = TP * v1.transpose();
  313. // Assemble matrix
  314. MatrixXd M(2,2);
  315. M << vp0, vp1;
  316. if (M.determinant() < 0)
  317. M.col(1) = -M.col(1);
  318. assert(M.determinant() > 0);
  319. // cerr << "M: " << M << endl;
  320. MatrixXd R,S;
  321. PolarDecomposition(M,R,S);
  322. // Finally, express the cross field as an angle
  323. theta = atan2(R(1,0),R(0,0));
  324. MatrixXd R2(2,2);
  325. R2 << cos(theta), -sin(theta), sin(theta), cos(theta);
  326. assert((R2-R).norm() < 10e-8);
  327. // Convert into rotation invariant form
  328. S = R * S * R.inverse();
  329. // Copy in vector form
  330. S_v = VectorXd(3);
  331. S_v << S(0,0), S(0,1), S(1,1);
  332. }
  333. void FrameInterpolator::canonical2frame(const Eigen::MatrixXd& TP, const double theta, const Eigen::VectorXd& S_v, Eigen::RowVectorXd& v)
  334. {
  335. using namespace std;
  336. using namespace Eigen;
  337. assert(S_v.size() == 3);
  338. MatrixXd S_temp(2,2);
  339. S_temp << S_v(0), S_v(1), S_v(1), S_v(2);
  340. // Convert angle in vector in the tangent plane
  341. // Vector2d vp(cos(theta),sin(theta));
  342. // First reconstruct R
  343. MatrixXd R(2,2);
  344. R << cos(theta), -sin(theta), sin(theta), cos(theta);
  345. // Rotation invariant reconstruction
  346. MatrixXd M = S_temp * R;
  347. Vector2d vp0(M(0,0),M(1,0));
  348. Vector2d vp1(M(0,1),M(1,1));
  349. // Unproject the vectors
  350. RowVectorXd v0 = vp0.transpose() * TP;
  351. RowVectorXd v1 = vp1.transpose() * TP;
  352. v.resize(6);
  353. v << v0, v1;
  354. }
  355. void FrameInterpolator::solve()
  356. {
  357. interpolateCross();
  358. interpolateSymmetric();
  359. }
  360. void FrameInterpolator::interpolateSymmetric()
  361. {
  362. using namespace std;
  363. using namespace Eigen;
  364. // Generate uniform Laplacian matrix
  365. typedef Eigen::Triplet<double> triplet;
  366. std::vector<triplet> triplets;
  367. // Variables are stacked as x1,y1,z1,x2,y2,z2
  368. triplets.reserve(3*4*F.rows());
  369. MatrixXd b = MatrixXd::Zero(3*F.rows(),1);
  370. // Build L and b
  371. for (unsigned eid=0; eid<EF.rows(); ++eid)
  372. {
  373. if (!isBorderEdge[eid])
  374. {
  375. for (int z=0;z<2;++z)
  376. {
  377. // W = [w_a, w_b
  378. // w_b, w_c]
  379. //
  380. // It is not symmetric
  381. int i = EF(eid,z==0?0:1);
  382. int j = EF(eid,z==0?1:0);
  383. int w_a_0 = (i*3)+0;
  384. int w_b_0 = (i*3)+1;
  385. int w_c_0 = (i*3)+2;
  386. int w_a_1 = (j*3)+0;
  387. int w_b_1 = (j*3)+1;
  388. int w_c_1 = (j*3)+2;
  389. // Rotation to change frame
  390. double r_a = cos(z==1?k(eid):-k(eid));
  391. double r_b = -sin(z==1?k(eid):-k(eid));
  392. double r_c = sin(z==1?k(eid):-k(eid));
  393. double r_d = cos(z==1?k(eid):-k(eid));
  394. // First term
  395. // w_a_0 = r_a^2 w_a_1 + 2 r_a r_b w_b_1 + r_b^2 w_c_1 = 0
  396. triplets.push_back(triplet(w_a_0,w_a_0, -1 ));
  397. triplets.push_back(triplet(w_a_0,w_a_1, r_a*r_a ));
  398. triplets.push_back(triplet(w_a_0,w_b_1, 2 * r_a*r_b ));
  399. triplets.push_back(triplet(w_a_0,w_c_1, r_b*r_b ));
  400. // Second term
  401. // w_b_0 = r_a r_c w_a + (r_b r_c + r_a r_d) w_b + r_b r_d w_c
  402. triplets.push_back(triplet(w_b_0,w_b_0, -1 ));
  403. triplets.push_back(triplet(w_b_0,w_a_1, r_a*r_c ));
  404. triplets.push_back(triplet(w_b_0,w_b_1, r_b*r_c + r_a*r_d ));
  405. triplets.push_back(triplet(w_b_0,w_c_1, r_b*r_d ));
  406. // Third term
  407. // w_c_0 = r_c^2 w_a + 2 r_c r_d w_b + r_d^2 w_c
  408. triplets.push_back(triplet(w_c_0,w_c_0, -1 ));
  409. triplets.push_back(triplet(w_c_0,w_a_1, r_c*r_c ));
  410. triplets.push_back(triplet(w_c_0,w_b_1, 2 * r_c*r_d ));
  411. triplets.push_back(triplet(w_c_0,w_c_1, r_d*r_d ));
  412. }
  413. }
  414. }
  415. SparseMatrix<double> L(3*F.rows(),3*F.rows());
  416. L.setFromTriplets(triplets.begin(), triplets.end());
  417. triplets.clear();
  418. // Add soft constraints
  419. double w = 100000;
  420. for (unsigned fid=0; fid < F.rows(); ++fid)
  421. {
  422. if (S_c[fid])
  423. {
  424. for (unsigned i=0;i<3;++i)
  425. {
  426. triplets.push_back(triplet(3*fid + i,3*fid + i,w));
  427. b(3*fid + i) += w*S(fid,i);
  428. }
  429. }
  430. }
  431. SparseMatrix<double> soft(3*F.rows(),3*F.rows());
  432. soft.setFromTriplets(triplets.begin(), triplets.end());
  433. SparseMatrix<double> M;
  434. M = L + soft;
  435. // Solve Lx = b;
  436. SparseLU<SparseMatrix<double> > solver;
  437. solver.compute(M);
  438. if(solver.info()!=Success)
  439. {
  440. std::cerr << "LU failed - frame_interpolator.cpp" << std::endl;
  441. assert(0);
  442. }
  443. MatrixXd x;
  444. x = solver.solve(b);
  445. if(solver.info()!=Success)
  446. {
  447. std::cerr << "Linear solve failed - frame_interpolator.cpp" << std::endl;
  448. assert(0);
  449. }
  450. S = MatrixXd::Zero(F.rows(),3);
  451. // Copy back the result
  452. for (unsigned i=0;i<F.rows();++i)
  453. S.row(i) << x(i*3+0), x(i*3+1), x(i*3+2);
  454. }
  455. void FrameInterpolator::setConstraint(const int fid, const Eigen::VectorXd& v)
  456. {
  457. using namespace std;
  458. using namespace Eigen;
  459. double t_;
  460. VectorXd S_;
  461. frame2canonical(TPs[fid],v,t_,S_);
  462. Eigen::RowVectorXd v2;
  463. canonical2frame(TPs[fid], t_, S_, v2);
  464. thetas(fid) = t_;
  465. thetas_c[fid] = true;
  466. S.row(fid) = S_;
  467. S_c[fid] = true;
  468. }
  469. Eigen::MatrixXd FrameInterpolator::getFieldPerFace()
  470. {
  471. using namespace std;
  472. using namespace Eigen;
  473. MatrixXd R(F.rows(),6);
  474. for (unsigned i=0; i<F.rows(); ++i)
  475. {
  476. RowVectorXd v;
  477. canonical2frame(TPs[i],thetas(i),S.row(i),v);
  478. R.row(i) = v;
  479. }
  480. return R;
  481. }
  482. void FrameInterpolator::PolarDecomposition(Eigen::MatrixXd V, Eigen::MatrixXd& U, Eigen::MatrixXd& P)
  483. {
  484. using namespace std;
  485. using namespace Eigen;
  486. // Polar Decomposition
  487. JacobiSVD<MatrixXd> svd(V,Eigen::ComputeFullU | Eigen::ComputeFullV);
  488. U = svd.matrixU() * svd.matrixV().transpose();
  489. P = svd.matrixV() * svd.singularValues().asDiagonal() * svd.matrixV().transpose();
  490. }
  491. }
  492. }
  493. IGL_INLINE void igl::comiso::frame_field(
  494. const Eigen::MatrixXd& V,
  495. const Eigen::MatrixXi& F,
  496. const Eigen::VectorXi& b,
  497. const Eigen::MatrixXd& bc1,
  498. const Eigen::MatrixXd& bc2,
  499. Eigen::MatrixXd& FF1,
  500. Eigen::MatrixXd& FF2
  501. )
  502. {
  503. using namespace std;
  504. using namespace Eigen;
  505. assert(b.size() > 0);
  506. // Init Solver
  507. FrameInterpolator field(V,F);
  508. for (unsigned i=0; i<b.size(); ++i)
  509. {
  510. VectorXd t(6); t << bc1.row(i).transpose(), bc2.row(i).transpose();
  511. field.setConstraint(b(i), t);
  512. }
  513. // Solve
  514. field.solve();
  515. // Copy back
  516. MatrixXd R = field.getFieldPerFace();
  517. FF1 = R.block(0, 0, R.rows(), 3);
  518. FF2 = R.block(0, 3, R.rows(), 3);
  519. }