openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
mesher.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
22 #include <iostream>
23 #include <fstream>
24 #include <cstdio>
25 #include <cstring>
26 #include <string>
27 #include <cmath>
28 #include <stdlib.h>
29 #include <limits>
30 #include <algorithm>
31 #include <vector>
32 
33 #include "vect.h"
34 #include <mesher_p.h>
35 #include <mesher_d.h>
36 #include "mesher_schema.hpp"
37 #include "runtime.hpp"
38 
39 
40 using namespace opencarp;
41 
42 typedef enum {Myocardium=1, Isobath, Anisobath } region_t;
43 
44 #define BOX_CENTERS_GRID false
45 #define NODE_GRID true
46 
47 Point p_assign_array( float *p )
48 {
49  Point a;
50  a.x = p[0]; a.y=p[1]; a.z=p[2];
51  return a;
52 }
53 
54 const Point e_circ = {1,0,0};
55 const Point e_long = {0,1,0};
56 const Point e_rad = {0,1,0};
57 
58 
59 
60 const float CM2UM=1.e4;
61 
62 class TisAxes {
63  public:
64  void set_xi(float xi_) { xi=xi_; }
65  void set_axes(float alpha_, float beta_pr_, float gamma_);
66  void set_bath_axes(bool);
67  Point fiber(void) {return f;}
68  Point sheet(void) {return s;}
69  private:
70  float xi;
71  float alpha;
72  float beta_pr;
73  float gamma;
74  Point f;
75  Point s;
76  Point sn;
77 };
78 
79 void
80 TisAxes::set_axes(float b, float c, float d)
81 {
82  alpha = b/180*M_PI;
83  beta_pr = c/180*M_PI;
84  gamma = d/180*M_PI;
85 
86  Point p(cos(alpha), sin(alpha), sin(gamma));
87  f = normalize(p);
88 
89  Point sp(0.0, sin(double(beta_pr)), cos(double(beta_pr)));
90  float lambda = -dot(f, sp)/dot(f, e_circ);
91  s = normalize(sp + scal_X(e_circ,lambda));
92 }
93 
94 void
95 TisAxes::set_bath_axes(bool aniso_bath)
96 {
97  f.y = f.z = 0.0;
98  s.x = s.y = s.z = 0.0;
99 
100  f.x = aniso_bath?1.0:0.0;
101 }
102 
103 class Region {
104  public:
105  Region(Point p, int b): p0_(p), bath_(b), tag_(-1) {}
106  virtual ~Region() {}
107  virtual bool inside(Point) = 0;
108  bool isbath() { return bath_; }
109  int tag() { return tag_; }
110  void tag(int t) { tag_ = t; }
111  protected:
113  int bath_;
114  int tag_;
115 };
116 
117 class BlockRegion: public Region {
118  public:
119  BlockRegion(Point p0, Point p, int bth): Region(p0, bth), p1_(p) {}
120  virtual bool inside(Point p);
121  private:
122  Point p1_;
123 };
124 
125 class SphericalRegion: public Region {
126  public:
127  SphericalRegion(Point ctr, float r, int bth):
128  Region(ctr, bth), radius2_(r*r) {}
129  virtual bool inside(Point p) { return dist_2(p, p0_)<= radius2_; }
130  private:
131  float radius2_; //square of radius
132 };
133 
134 bool
136 {
137  return p.x >= p0_.x && p.x <= p1_.x && p.y >= p0_.y && p.y <= p1_.y &&
138  p.z >= p0_.z && p.z <= p1_.z;
139 }
140 
141 
142 class CylindricalRegion: public Region {
143  public:
144  CylindricalRegion(Point origin, Point dir, float r, float l, int bth):
145  Region(origin, bth), radius2_(r*r)
146  {axis_=normalize(dir);len_=(l==0.)?1.e36:l;}
147  virtual bool inside( Point p );
148  private:
149  Point axis_;
150  float radius2_;
151  float len_;
152 };
153 
154 bool
156 {
157  Point R = p - p0_;
158  float d = dot(R, axis_);
159 
160  return d>=0 && d<=len_ && mag2(R)-d*d <= radius2_;
161 }
162 
163 
164 class Element {
165  public:
166  Element(int N, const char *t):n_(N),p_(new int[N]),type_(t){}
167  ~Element() { delete[] p_; }
168  Point centre(Point *ctr);
169  int num(){ return n_; };
170  friend std::ostream& operator<<(std::ostream &, Element& );
172  protected:
173  int n_;
174  int *p_;
175  std::string type_;
176 };
177 
178 
180  Point result = ctr[p_[0]];
181  for( int i=1; i<n_; i++ ) result = result + ctr[p_[i]];
182  return scal_X( result, 1./(float)n_);
183 }
184 
185 
186 class Tetrahedron:public Element {
187  public:
188  Tetrahedron( int A, int B, int C, int D ): Element(4,"Tt") {
189  p_[0]=A; p_[1]=B; p_[2]=C; p_[3]=D; }
190  void chkNegVolume(Point *pts);
191 };
192 
193 
195  Point P01 = pts[p_[1]] - pts[p_[0]];
196  Point P02 = pts[p_[2]] - pts[p_[0]];
197  Point P03 = pts[p_[3]] - pts[p_[0]];
198  double vol = det3(P01,P02,P03); // 6x volume
199  if( vol < 0. )
200  std::swap(p_[0],p_[1]);
201 }
202 
203 class Hexahedron:public Element {
204  public:
205  Hexahedron( int A, int B, int C, int D, int E, int F, int G, int H ): Element(8,"Hx") {
206  p_[0]=A; p_[1]=B; p_[2]=C; p_[3]=D; p_[4]=E; p_[5]=F; p_[6]=G; p_[7]=H; }
207 };
208 
209 
210 class Quadrilateral:public Element {
211  public:
212  Quadrilateral( int A, int B, int C, int D ): Element(4,"Qd") {
213  p_[0] = A; p_[1] = B; p_[2] = C; p_[3] = D;
214  }
215 };
216 
217 
218 class Triangle:public Element {
219  public:
220  Triangle( int A, int B, int C ): Element(3,"Tr") {
221  p_[0] = A; p_[1] = B; p_[2] = C;
222  }
223 };
224 
225 
226 class Line:public Element {
227  public:
228  Line( int A, int B ): Element(2,"Ln"){p_[0]=A; p_[1]=B;}
229 };
230 
231 
232 std::ostream& operator<<( std::ostream& out, Element &e ) {
233  out << e.type_ << " ";
234  for( int i=0; i<e.num()-1; i++ )
235  out << e.p_[i] << " ";
236  out << e.p_[e.num()-1];
237  return out;
238 }
239 
240 std::ostream& operator<<( std::ostream& out, Point p ) {
241  out << p.x << " " << p.y << " " << p.z;
242  return out;
243 }
244 
245 
246 class tmProfile {
247  public:
248  ~tmProfile() { free(xi); free(ang); }
249  int read(char *fname);
250  float lookup(float xi);
251  int linear(float ang_endo, float ang_epi, float z_endo, float z_epi );
252  private:
253  int N;
254  float *xi;
255  float *ang;
256 };
257 
258 
259 int
260 tmProfile::linear (float ang_endo,float ang_epi, float z_endo, float z_epi)
261 {
262  float dz = 10; // sample the profile at a 10 um resolution
263  if( z_epi==z_endo ) // 2D case
264  N = 0;
265  else
266  N = (z_epi-z_endo)/dz;
267 
268  xi = (float *)malloc(sizeof(float)*(N+1));
269  ang = (float *)malloc(sizeof(float)*(N+1));
270 
271  if(xi==NULL || ang==NULL) {
272  std::cerr << "Memory allocation failed." << std::endl;
273  return -1;
274  }
275  else if( !N ) { // 2D
276  xi[0] = 0;
277  ang[0] = ang_endo;
278  } else {
279  float K = (ang_epi-ang_endo)/(z_epi-z_endo);
280  for(int i=0;i<=N;i++) {
281  float z = z_endo+i*dz;
282  xi[i] = (z-z_endo)/(z_epi-z_endo)-0.5;
283  ang[i] = ang_endo + K*(z-z_endo);
284  }
285  }
286  return 0;
287 }
288 
289 float
291 {
292  if( !N ) return ang[0];
293 
294  int i=0;
295  while(xi[i]<xi_ && i<N) i++;
296 
297  if((i==0)|| (i==N))
298  return ang[i];
299  else
300  return ang[i-1]+(ang[i]-ang[i-1])/(xi[i]-xi[i-1])*(xi_-xi[i-1]);
301 }
302 
303 int
304 tmProfile::read(char *fname)
305 {
306  FILE *profile = fopen(fname,"rt");
307  if(profile==NULL) {
308  fprintf( stderr, "Can't open transmural profile data file %s.\n", fname);
309  return -1;
310  }
311 
312  int err = fscanf(profile,"%d",&N);
313  xi = (float *)malloc(sizeof(float)*N);
314  ang = (float *)malloc(sizeof(float)*N);
315  for(int i=0; i<N; i++) {
316  xi[i] = (float)i/(float)(N-1)-0.5;
317  err = fscanf(profile,"%f",ang+i);
318  }
319  fclose(profile);
320 
321  return err;
322 }
323 
324 class BBoxDef {
325  public:
326  void update( Point p );
327 // private:
328  float xd = 0;
331  float yd = 0;
334  float zd = 0;
337 };
338 
339 void
341 {
342  if(p.x<x_mn) x_mn = p.x;
343  if(p.y<y_mn) y_mn = p.y;
344  if(p.z<z_mn) z_mn = p.z;
345  if(p.x>x_mx) x_mx = p.x;
346  if(p.y>y_mx) y_mx = p.y;
347  if(p.z>z_mx) z_mx = p.z;
348 }
349 
350 
351 class BoundingBox {
352  public:
353  virtual ~BoundingBox() { delete[] bx; delete[] res; }
354  void init( int *_bx, float *_res, Point p0);
355  void dims(void);
356  float z2xi(float z, bool nodeGrid);
357  float mn_z(bool nodeGrid){ return nodeGrid?nodes.z_mn:bctrs.z_mn; };
358  float mx_z(bool nodeGrid){ return nodeGrid?nodes.z_mx:bctrs.z_mx; };
359  public:
360  int *bx;
361  int bx_inds[3][2];
362  protected:
363  float *res;
366 };
367 
368 float
369 BoundingBox::z2xi (float z, bool nodeGrid)
370 {
371  float zd = nodeGrid?nodes.zd:bctrs.zd;
372  float z_mn = nodeGrid?nodes.z_mn:bctrs.z_mn;
373 
374  if(zd==0.)
375  return 0.;
376  else
377  return (z-z_mn)/zd-0.5;
378 }
379 
380 void
381 BoundingBox::init(int *_bx, float *_res, Point p0)
382 {
383  bx = new int [3];
384  res = new float [3];
385  for(int i=0;i<3;i++) {
386  bx [i] = _bx [i];
387  res[i] = _res[i];
388  bx_inds[i][0] = 0;
389  bx_inds[i][1] = bx[i]-1;
390  }
391 
392  // min corner of nodal bbx
393  nodes.update(p0);
394 
395  // min corner of center bbx
396  Point pc0 = p0;
397  pc0.x = p0.x + res[0]/2;
398  pc0.y = p0.y + res[1]/2;
399  pc0.z = p0.z + res[2]/2;
400  bctrs.update(pc0);
401 
402  // max corner of nodal bbx
403  Point p1 = p0;
404  p1.x = p0.x+bx[0]*res[0];
405  p1.y = p0.y+bx[1]*res[1];
406  p1.z = p0.z+bx[2]*res[2];
407  nodes.update(p1);
408 
409  // max corner of center bbx
410  Point pc1 = p1;
411  pc1.x = p1.x - res[0]/2;
412  pc1.y = p1.y - res[1]/2;
413  pc1.z = p1.z - res[2]/2;
414  bctrs.update(pc1);
415 
416  dims();
417 }
418 
419 void
421 {
422  // figure out dims in terms of nodes
423  nodes.xd = nodes.x_mx - nodes.x_mn;
424  nodes.yd = nodes.y_mx - nodes.y_mn;
425  nodes.zd = nodes.z_mx - nodes.z_mn;
426 
427  // and in terms of box centers
428  bctrs.xd = bctrs.x_mx - bctrs.x_mn;
429  bctrs.yd = bctrs.y_mx - bctrs.y_mn;
430  bctrs.zd = bctrs.z_mx - bctrs.z_mn;
431 }
432 
433 class fibDef {
434  public:
435  void setFiberDefs(char *f_prof, float fEndo, float fEpi, float imbr,
436  char *s_prof, float sEndo, float sEpi);
437  bool withSheets(void);
438  char *f_name(void) { return f_Prof; };
439  char *s_name(void) { return s_Prof; };
440  float imbrication() { return f_imbr; };
441  float rotEndo() { return f_Endo; };
442  float rotEpi() { return f_Epi; };
443  float sheetEndo() { return s_Endo; };
444  float sheetEpi() { return s_Epi; };
445 
446  private:
447  char *f_Prof;
448  float f_Endo;
449  float f_Epi;
450  float f_imbr;
451  char *s_Prof;
452  float s_Endo;
453  float s_Epi;
454 };
455 
456 void fibDef::setFiberDefs(char *f_prof, float fEndo, float fEpi, float imbr,
457  char *s_prof, float sEndo, float sEpi)
458 {
459  f_Prof = strdup(f_prof);
460  f_Endo = fEndo;
461  f_Epi = fEpi;
462  f_imbr = imbr;
463  s_Prof = strdup(s_prof);
464  s_Endo = sEndo;
465  s_Epi = sEpi;
466 }
467 
468 bool
470 {
471  if((f_imbr!=0.0) || (s_Endo!=0.0) || (s_Epi!=0.0) || (strcmp(s_Prof,"")))
472  return true;
473  else
474  return false;
475 
476 }
477 
478 
479 class Grid {
480  public:
481  Grid( char *, Region **, int );
482  virtual ~Grid() {}
483  void unPrMFiberDefs(void);
484  virtual void build_mesh(float*,float*,float*,bool *,float*,float,bool,int)=0;
485  virtual void output_boundary( char * )=0;
486  void add_element( Element &, region_t );
487  void set_indx_bounds(bool *sym);
488  bool chk_bath( int i, int j, int k );
489  bool os_good();
490  protected:
492  int npt;
495  std::ofstream pt_os, elem_os, lon_os, elemc_os, vec_os;
497  int num_axes;
501  int dim;
502 };
503 
504 class Grid2D : public Grid {
505  public:
506  virtual void build_mesh(float*, float*, float*, bool *, float*, float, bool, int);
507  virtual void output_boundary( char *fn ){};
508  Grid2D( char *m, Region **r ):Grid(m,r,2){}
509  private:
510  void add_tri( int, int, int );
511 };
512 
513 class Grid3D : public Grid {
514  public:
515  virtual void build_mesh(float*, float*, float*, bool *, float*, float, bool, int);
516  virtual void output_boundary( char *fn ){}
517  Grid3D( char *m, Region **r ):Grid(m,r,3){}
518  private:
519  void add_tet( int, int, int, int );
520 };
521 
522 class Grid1D : public Grid {
523  public:
524  virtual void build_mesh(float*, float*, float*, bool *, float*, float, bool, int);
525  virtual void output_boundary( char *fn ){}
526  Grid1D( char *m, Region **r ):Grid(m,r,1){}
527  private:
528  void add_line( int, int, int, int );
529 };
530 
531 
533 {
534  return pt_os.good() && lon_os.good() && elem_os.good();
535 }
536 
537 
538 Grid::Grid( char *msh, Region **r, int d ): region(r),dim(d)
539 {
540  std::string fname(msh);
541  fname = msh;
542  fname += ".lon";
543  lon_os.open(fname.c_str());
544 
545  fname = msh;
546  fname += ".pts";
547  pt_os.open(fname.c_str());
548 
549  fname = msh;
550  fname += ".elem";
551  elem_os.open(fname.c_str());
552 
553  fname = msh;
554  fname += ".vpts";
555  elemc_os.open(fname.c_str());
556 
557  fname = msh;
558  fname += ".vec";
559  vec_os.open(fname.c_str());
560 }
561 
562 
569 void
571 {
572  for(int i=0;i<3;i++) {
573  if(b_bbx.bx[i]>t_bbx.bx[i]) {
574  t_bbx.bx_inds[i][0] = 0;
575  if(sym[i])
576  t_bbx.bx_inds[i][0] = (b_bbx.bx[i]-t_bbx.bx[i])/2;
577  t_bbx.bx_inds[i][1] = t_bbx.bx_inds[i][0]+t_bbx.bx[i]-1;
578  }
579  }
580 }
581 
582 
591 bool
592 Grid::chk_bath(int i, int j, int k)
593 {
594  bool bth[] = { false, false, false };
595  int idx[] = { i, j, k };
596 
597  for(int cnt=0; cnt<dim; cnt++ )
598  if( idx[cnt]<t_bbx.bx_inds[cnt][0] || idx[cnt]>t_bbx.bx_inds[cnt][1] )
599  return true;
600 
601  return false;
602 }
603 
604 
605 void
607 {
608  f_def.setFiberDefs(param_globals::fibers.tm_fiber_profile,
609  param_globals::fibers.rotEndo,
610  param_globals::fibers.rotEpi,
611  param_globals::fibers.imbrication,
612  param_globals::fibers.tm_sheet_profile,
613  param_globals::fibers.sheetEndo,
614  param_globals::fibers.sheetEpi);
615 }
616 
622 void
624 {
625  elem_os << elem;
626  Point c = elem.centre(pt);
627  elemc_os << c << std::endl;
628  int r=-1;
629  int regid = regtype==Myocardium?1:0;
630  while( region[++r] != NULL ) {
631  if( region[r]->inside( c ) ) {
632  if( region[r]->isbath() ) { // myo or bath becomes bath
633  regid = region[r]->tag()<0 ? 0 : region[r]->tag();
634  regtype = region[r]->isbath()==1?Isobath:Anisobath;
635  } else if( regtype == Myocardium ) { // only myo becomes other myo
636  regid = region[r]->tag()<0 ? r+2 : region[r]->tag();
637  }
638  if(param_globals::first_reg)
639  break;
640  }
641  }
642 
643  if(regtype==Myocardium) {
644  float xi = t_bbx.z2xi(c.z,BOX_CENTERS_GRID);
645  elem.ax.set_xi(xi);
646  elem.ax.set_axes( f_xi.lookup(xi),s_xi.lookup(xi),f_def.imbrication());
647  }
648  else {
649  elem.ax.set_bath_axes(regtype==Anisobath);
650  if(regtype==Anisobath)
651  regid *= -1;
652  }
653 
654  elem_os << " " << regid << std::endl;
655  if(num_axes>1)
656  lon_os << elem.ax.fiber() << " " << elem.ax.sheet() << std::endl;
657  else
658  lon_os << elem.ax.fiber() << std::endl;
659 
660  // write fiber to vector file
661  vec_os << elem.ax.fiber() << std::endl;
662 }
663 
664 
677 void
678 Grid1D::build_mesh(float* x0, float* x, float* tissue, bool *sym, float *res,
679  float pert, bool aniso_bath, int periodic_bc)
680 {
681  bool eletype;
682  int p1, p2, p3, p4;
683  int bnx[3]; // number of cubes in each direction
684  int tnx[3]; // number of tissue cubes in each direction
685 
686  // determine number of boxes
687  for( int i=0; i<3; i++ ) {
688  bnx[i] = (int)(x[i]/res[i]);
689  tnx[i] = (int)(tissue[i]/res[i]);
690  }
691 
692  // determine origins for tissue and bath bounding box
693  Point pt0, pb0;
694  pt0.x = -tnx[0]*res[0]/2 + x0[0];
695  pt0.y = 0;
696  pt0.z = 0;
697 
698  pb0.x = sym[0]?pt0.x-(bnx[0]-tnx[0])*res[0]/2:pt0.x+x0[0];
699  pb0.y = 0.0;
700  pb0.z = 0.0;
701 
702  // determine bounding box of bath and tissue grids
703  b_bbx.init(bnx,res,pb0);
704  t_bbx.init(tnx,res,pt0);
705 
706  // set tissue index boundaries relative to bath grid
707  set_indx_bounds(sym);
708 
709  f_xi.linear( f_def.rotEndo(), f_def.rotEpi(), 0, 0 );
710  s_xi.linear( f_def.sheetEndo(), f_def.sheetEpi(), 0, 0 );
711 
712  // output the points file
713  npt = (bnx[0]+1);
714  std::cout << "Number of points: " << npt << std::endl;
715  pt = new Point[npt];
716  pt_os << npt << std::endl;
717  npt = 0;
718  for( int i=0; i<=bnx[0]; i++ ) {
719  pt[npt].assign<double>(x0[0]+i*res[0], 0, 0);
720 
721  if( i!=bnx[0] ) {
722  pt[npt].x += ((double)random()/(double)RAND_MAX)*pert*res[0];
723  }
724  pt_os << pt[npt++] << std::endl;
725  }
726  pt_os.close();
727 
728  int num_in_layer = (bnx[0]+1);
729  elem_os << bnx[0] << std::endl;
730  std::cout << "Number of linear elements: " << bnx[0] << std::endl;
731 
732  for( int i=0; i<bnx[0]; i++ ) {
733  p1 = i;
734  p2 = p1+1;
735 
736  region_t regtype = Myocardium;
737  if( chk_bath(i,0,0) )
738  regtype = aniso_bath?Anisobath:Isobath;
739 
740  Line l(p1, p2 );
741  add_element( l, regtype );
742  }
743  elem_os.close();
744  lon_os.close();
745  delete[] pt;
746 }
747 
748 
761 void
762 Grid2D::build_mesh(float* x0, float* x, float* tissue, bool *sym, float *res,
763  float pert, bool aniso_bath, int periodic_bc)
764 {
765  bool eletype;
766  int p1, p2, p3, p4;
767  int bnx[3]; // number of cubes in each direction
768  int tnx[3]; // number of tissue cubes in each direction
769 
770  // determine number of boxes
771  for( int i=0; i<3; i++ ) {
772  bnx[i] = (int)(x[i]/res[i]);
773  tnx[i] = (int)(tissue[i]/res[i]);
774  }
775 
776  // determine origins for tissue and bath bounding box
777  Point pt0, pb0;
778  pt0.x = -tnx[0]*res[0]/2 + x0[0];
779  pt0.y = -tnx[1]*res[1]/2 + x0[1];
780  pt0.z = 0.0;
781 
782  pb0.x = sym[0]?pt0.x-(bnx[0]-tnx[0])*res[0]/2:pt0.x+ x0[0];
783  pb0.y = sym[0]?pt0.y-(bnx[0]-tnx[0])*res[0]/2:pt0.y+ x0[1];
784  pb0.z = 0.0;
785 
786  // determine bounding box of bath and tissue grids
787  b_bbx.init(bnx,res,pb0);
788  t_bbx.init(tnx,res,pt0);
789 
790  // set tissue index boundaries relative to bath grid
791  set_indx_bounds(sym);
792 
793  // output the points file
794  npt = (bnx[0]+1)*(bnx[1]+1);
795  std::cout << "Number of points: " << npt << std::endl;
796  pt = new Point[npt];
797  pt_os << npt << std::endl;
798  npt = 0;
799  for( int j=0; j<=bnx[1]; j++ )
800  for( int i=0; i<=bnx[0]; i++ ) {
801  pt[npt].assign<double>(x0[0]+i*res[0], x0[1]+j*res[1], 0);
802 
803  if( j && j!=bnx[1] && i && i!=bnx[0] ) {
804  pt[npt].x += ((double)random()/(double)RAND_MAX)*pert*res[0];
805  pt[npt].y += ((double)random()/(double)RAND_MAX)*pert*res[1];
806  }
807  pt_os << pt[npt++] << std::endl;
808  }
809  pt_os.close();
810 
811  // determine periodic b.c. connections
812  int nper_cnnx = 0;
813  if( (periodic_bc&1) == 1 )
814  nper_cnnx += bnx[1]+1;
815  if( (periodic_bc&2) == 2 )
816  nper_cnnx += bnx[0]+1;
817 
818  int num_in_layer = (bnx[0]+1)*(bnx[1]+1);
819 
820  if(param_globals::tri2D) {
821  elem_os << 2*bnx[0]*bnx[1]+nper_cnnx << std::endl;
822  elemc_os << 2*bnx[0]*bnx[1]+nper_cnnx << std::endl;
823  std::cout << "Number of triangles: " << 2*bnx[0]*bnx[1] << std::endl;
824  } else {
825  elem_os << bnx[0]*bnx[1]+nper_cnnx << std::endl;
826  elemc_os << bnx[0]*bnx[1]+nper_cnnx << std::endl;
827  std::cout << "Number of quadrilaterals: " << bnx[0]*bnx[1] << std::endl;
828  }
829  if( nper_cnnx )
830  std::cout << "Number of periodic connections: " << nper_cnnx << std::endl;
831 
832  f_xi.linear( f_def.rotEndo(), f_def.rotEpi(), 0, 0 );
833  s_xi.linear( f_def.sheetEndo(), f_def.sheetEpi(), 0, 0 );
834 
835  num_axes = f_def.withSheets()?2:1;
836  lon_os << num_axes << std::endl;
837  if(num_axes>1)
838  std::cout << "Using orthotropic fiber setup." << std::endl;
839  else
840  std::cout << "Using transversely isotropic fiber setup." << std::endl;
841 
842  for( int j=0; j<bnx[1]; j++ ) {
843  eletype = j%2;
844  for( int i=0; i<bnx[0]; i++ ) {
845  p1 = j*(bnx[0]+1) + i;
846  p2 = p1+1;
847  p3 = (j+1)*(bnx[0]+1) + i;
848  p4 = p3+1;
849 
850  region_t regtype = Myocardium;
851  if( chk_bath(i,j,0) )
852  regtype = aniso_bath?Anisobath:Isobath;
853 
854  if( param_globals::tri2D ) {
855  if( eletype ) {
856  Triangle t1(p1, p2, p3), t2(p2, p4, p3);
857  add_element( t1, regtype );
858  add_element( t2, regtype );
859  } else {
860  Triangle t1(p1, p2, p4), t2(p1, p4, p3);
861  add_element( t1, regtype );
862  add_element( t2, regtype );
863  }
864  eletype = !eletype;
865  } else {
866  Quadrilateral q(p1,p2,p4,p3);
867  add_element( q, regtype );
868  }
869  }
870  }
871 
872  if( (periodic_bc&1) == 1 ) {
873  for( int i=0; i<=bnx[1]; i++ ) {
874  Line l( i*(bnx[0]+1), (i+1)*(bnx[0]+1)-1 );
875  elem_os << l << " " << param_globals::periodic_tag<<std::endl;
876  lon_os << "1 0 0" << std::endl;
877  }
878  }
879  if( (periodic_bc&2) == 2 ) {
880  for( int i=0; i<=bnx[0]; i++ ) {
881  Line l( i, (bnx[0]+1)*(bnx[1])+i );
882  elem_os << l << " " << param_globals::periodic_tag+1 << std::endl;
883  lon_os << "0 1 0" << std::endl;
884  }
885  }
886 
887  elem_os.close();
888  lon_os.close();
889  delete[] pt;
890 }
891 
892 
903 void
904 Grid3D::build_mesh( float* x0, float* x, float* tissue, bool *sym, float *res,
905  float pert, bool aniso_bath, int periodic_bc)
906 {
907  bool eletype;
908  int p1, p2, p3, p4, p5, p6, p7,p8;
909  int bnx[3]; // number of cubes in each direction
910  int tnx[3]; // number of tissue cubes in each direction
911 
912  // determine number of boxes
913  for( int i=0; i<3; i++ ) {
914  bnx[i] = (int)(x[i]/res[i]);
915  tnx[i] = (int)(tissue[i]/res[i]);
916  }
917 
918  // determine origins for tissue and bath bounding box
919  Point pt0, pb0;
920  pt0 = {x0[0],x0[1],x0[2]};
921 
922  pb0.x = sym[0]?pt0.x-(bnx[0]-tnx[0])*res[0]/2:pt0.x + x0[0];
923  pb0.y = sym[1]?pt0.y-(bnx[1]-tnx[1])*res[1]/2:pt0.y + x0[1];
924  pb0.z = sym[2]?pt0.z-(bnx[2]-tnx[2])*res[2]/2:pt0.z + x0[2];
925 
926  // determine bounding box of bath and tissue grids
927  b_bbx.init(bnx,res,pb0);
928  t_bbx.init(tnx,res,pt0);
929 
930  // set tissue index boundaries relative to bath grid
931  set_indx_bounds(sym);
932 
933 
934  // define fiber and sheet arrangements
935  if(strcmp(f_def.f_name(),"")) {
936  std::cout << "Reading transmural fiber rotation profile from " << f_def.f_name() << std::endl;
937  f_xi.read(f_def.f_name());
938  }
939  else
942 
943  if(strcmp(f_def.s_name(),"")) {
944  std::cout << "Reading transmural sheet profile from " << f_def.s_name() << std::endl;
945  s_xi.read(f_def.s_name());
946  }
947  else
950 
951  // output the points file
952  npt = (bnx[0]+1)*(bnx[1]+1)*(bnx[2]+1);
953  std::cout << "Number of points: " << npt << std::endl;
954  pt = new Point[npt];
955  pt_os << npt << std::endl;
956  npt = 0;
957  for( int k=0; k<=bnx[2]; k++ )
958  for( int j=0; j<=bnx[1]; j++ )
959  for( int i=0; i<=bnx[0]; i++ ) {
960  pt[npt] = {x0[0]+i*res[0], x0[1]+j*res[1], x0[2]+k*res[2]};
961  if( k && k!=bnx[2] && j && j!=bnx[1] && i && i!=bnx[0] ) {
962  pt[npt].x += ((double)random()/(double)RAND_MAX)*pert*res[0];
963  pt[npt].y += ((double)random()/(double)RAND_MAX)*pert*res[1];
964  pt[npt].z += ((double)random()/(double)RAND_MAX)*pert*res[2];
965  }
966  pt_os << pt[npt++] << std::endl;
967  }
968  pt_os.close();
969 
970  int num_in_layer = (bnx[0]+1)*(bnx[1]+1);
971  if(!param_globals::Elem3D) {
972  elem_os << 5*bnx[0]*bnx[1]*bnx[2] << std::endl;
973  elemc_os << 5*bnx[0]*bnx[1]*bnx[2] << std::endl;
974  std::cout << "Number of Tetrahedra: " << 5*bnx[0]*bnx[1]*bnx[2] << std::endl;
975  }
976  else {
977  elem_os << bnx[0]*bnx[1]*bnx[2] << std::endl;
978  elemc_os << bnx[0]*bnx[1]*bnx[2] << std::endl;
979  std::cout << "Number of Hexahedra: " << bnx[0]*bnx[1]*bnx[2] << std::endl;
980  }
981 
982  num_axes = f_def.withSheets()?2:1;
983  lon_os << num_axes << std::endl;
984  if(num_axes>1)
985  std::cout << "Using orthotropic fiber setup." << std::endl;
986  else
987  std::cout << "Using transversely isotropic fiber setup." << std::endl;
988 
989 
990  for( int k=0; k<bnx[2]; k++ ) {
991  eletype = k%2;
992  for( int j=0; j<bnx[1]; j++ ) {
993  // if bnx[0] is even we need to toggle
994  // otherwise we break the chessboard pattern
995  if(j && !(bnx[0]%2) )
996  eletype = !eletype;
997 
998  for( int i=0; i<bnx[0]; i++ ) {
999  p1 = k*num_in_layer + j*(bnx[0]+1) + i;
1000  p2 = p1+1;
1001  p3 = k*num_in_layer + (j+1)*(bnx[0]+1) + i;
1002  p4 = p3+1;
1003  p5 = (k+1)*num_in_layer + j*(bnx[0]+1) + i;
1004  p6 = p5+1;
1005  p7 = (k+1)*num_in_layer + (j+1)*(bnx[0]+1) + i;
1006  p8 = p7+1;
1007 
1008  region_t regtype = Myocardium;
1009  if(chk_bath(i,j,k))
1010  regtype = aniso_bath?Anisobath:Isobath;
1011 
1012  if(!param_globals::Elem3D) {
1013  // generate tet mesh
1014  if( eletype ) {
1015  Tetrahedron t1(p1, p2, p4, p6),
1016  t2(p1, p3, p4, p7),
1017  t3(p1, p4, p6, p7),
1018  t4(p1, p5, p6, p7),
1019  t5(p4, p6, p7, p8);
1020  t1.chkNegVolume( pt ); add_element( t1, regtype );
1021  t2.chkNegVolume( pt ); add_element( t2, regtype );
1022  t3.chkNegVolume( pt ); add_element( t3, regtype );
1023  t4.chkNegVolume( pt ); add_element( t4, regtype );
1024  t5.chkNegVolume( pt ); add_element( t5, regtype );
1025  } else {
1026  Tetrahedron t1(p1, p2, p3, p5),
1027  t2(p2, p3, p4, p8),
1028  t3(p2, p5, p6, p8),
1029  t4(p2, p3, p5, p8),
1030  t5(p3, p5, p7, p8);
1031  t1.chkNegVolume( pt ); add_element( t1, regtype );
1032  t2.chkNegVolume( pt ); add_element( t2, regtype );
1033  t3.chkNegVolume( pt ); add_element( t3, regtype );
1034  t4.chkNegVolume( pt ); add_element( t4, regtype );
1035  t5.chkNegVolume( pt ); add_element( t5, regtype );
1036  }
1037  eletype = !eletype;
1038  }
1039  else {
1040  // Hex
1041 
1042  // this is the original hex ordering. not compatible with the SF ansatzfunc scheme..
1043  // Hexahedron h1(p4, p3, p1, p2, p8, p6, p5, p7);
1044 
1045  Hexahedron h1(p5, p7, p8, p6, p1, p2, p4, p3);
1046  add_element( h1, regtype );
1047  }
1048  }
1049  }
1050  }
1051  elem_os.close();
1052  lon_os.close();
1053  elemc_os.close();
1054  vec_os.close();
1055  delete[] pt;
1056 }
1057 
1058 namespace {
1059 
1060 bool match_long_option(const std::string& token, const char* option, std::string* attached_value)
1061 {
1062  *attached_value = std::string();
1063  if (token == option) {
1064  return true;
1065  }
1066 
1067  const std::string prefix = std::string(option) + "=";
1068  if (token.size() > prefix.size() && token.compare(0, prefix.size(), prefix) == 0) {
1069  *attached_value = token.substr(prefix.size());
1070  return true;
1071  }
1072 
1073  return false;
1074 }
1075 
1076 bool is_help_topic_candidate(const char* token)
1077 {
1078  return token != NULL && token[0] != '\0' && token[0] != '-' && token[0] != '+';
1079 }
1080 
1081 bool is_long_option_argument_error(const std::string& token,
1082  const char* option,
1083  const std::string& attached_value,
1084  std::string* error)
1085 {
1086  if (attached_value.empty()) {
1087  return false;
1088  }
1089 
1090  *error = "Unexpected argument for " + std::string(option) + " in '" + token + "'";
1091  return true;
1092 }
1093 
1094 bool normalize_runtime_args(int argc,
1095  char** argv,
1096  std::vector<std::string>* normalized,
1097  std::string* error)
1098 {
1099  normalized->clear();
1100 
1101  if (argc <= 0 || argv == NULL || argv[0] == NULL) {
1102  *error = "Missing program name";
1103  return false;
1104  }
1105 
1106  normalized->push_back(argv[0]);
1107 
1108  for (int i = 1; i < argc; ++i) {
1109  const std::string token = argv[i];
1110  if (token == "+") {
1111  break;
1112  }
1113 
1114  std::string attached_value;
1115 
1116  if (token == "+Help" || match_long_option(token, "--help", &attached_value)) {
1117  std::string topic = "PrM";
1118  if (!attached_value.empty()) {
1119  topic = attached_value;
1120  } else if (i + 1 < argc && is_help_topic_candidate(argv[i + 1])) {
1121  topic = argv[++i];
1122  }
1123  normalized->push_back("+Help");
1124  normalized->push_back(topic);
1125  break;
1126  }
1127 
1128  if (token == "+Doc" || match_long_option(token, "--doc", &attached_value)) {
1129  std::string topic = "ALL";
1130  if (!attached_value.empty()) {
1131  topic = attached_value;
1132  } else if (i + 1 < argc && is_help_topic_candidate(argv[i + 1])) {
1133  topic = argv[++i];
1134  }
1135  normalized->push_back("+Doc");
1136  normalized->push_back(topic);
1137  break;
1138  }
1139 
1140  if (token == "+Default" || match_long_option(token, "--default", &attached_value)) {
1141  if (token != "+Default" && is_long_option_argument_error(token, "--default", attached_value, error)) {
1142  return false;
1143  }
1144  normalized->push_back("+Default");
1145  break;
1146  }
1147 
1148  if (token == "+Run" || match_long_option(token, "--run", &attached_value)) {
1149  if (token != "+Run" && is_long_option_argument_error(token, "--run", attached_value, error)) {
1150  return false;
1151  }
1152  normalized->push_back("+Run");
1153  continue;
1154  }
1155 
1156  if (token == "+I" || match_long_option(token, "--interactive", &attached_value)) {
1157  if (!attached_value.empty()) {
1158  *error = "Unexpected argument for --interactive in '" + token + "'";
1159  } else {
1160  *error = "Unsupported option " + token + " (interactive mode is not available)";
1161  }
1162  return false;
1163  }
1164 
1165  if (token == "+F" || match_long_option(token, "--file", &attached_value)) {
1166  std::string filename = attached_value;
1167  if (filename.empty()) {
1168  if (i + 1 >= argc) {
1169  *error = "Missing filename after " + token;
1170  return false;
1171  }
1172  filename = argv[++i];
1173  }
1174  normalized->push_back("+F");
1175  normalized->push_back(filename);
1176  continue;
1177  }
1178 
1179  if (token == "+Save" || match_long_option(token, "--save", &attached_value)) {
1180  std::string filename = attached_value;
1181  if (filename.empty()) {
1182  if (i + 1 >= argc) {
1183  *error = "Missing argument after " + token;
1184  return false;
1185  }
1186  filename = argv[++i];
1187  }
1188  normalized->push_back("+Save");
1189  normalized->push_back(filename);
1190  continue;
1191  }
1192 
1193  normalized->push_back(token);
1194  }
1195 
1196  return true;
1197 }
1198 
1199 void populate_arg_pointers(const std::vector<std::string>& values, std::vector<char*>* argv)
1200 {
1201  argv->assign(values.size(), NULL);
1202  for (std::size_t i = 0; i < values.size(); ++i) {
1203  (*argv)[i] = const_cast<char*>(values[i].c_str());
1204  }
1205 }
1206 
1207 void print_lines(FILE* stream, const char* label, const std::vector<std::string>& lines)
1208 {
1209  for (std::size_t i = 0; i < lines.size(); ++i) {
1210  std::fprintf(stream, "%s%s\n", label, lines[i].c_str());
1211  }
1212 }
1213 
1214 paramschema::ExecutionResult execute_parser_runtime_args(const std::vector<std::string>& runtime_args)
1215 {
1216  std::vector<char*> argv;
1217  populate_arg_pointers(runtime_args, &argv);
1218 
1219  return paramschema::execute_legacy_cli(paramschema::mesher_schema(),
1220  static_cast<int>(argv.size()),
1221  argv.data());
1222 }
1223 
1224 bool apply_parser_runtime_args(const std::vector<std::string>& runtime_args)
1225 {
1226  const paramschema::ExecutionResult executed = execute_parser_runtime_args(runtime_args);
1227  print_lines(stderr, "parameter parser warning: ", executed.warnings);
1228  if (!executed.rendered_output.empty()) {
1229  std::fputs(executed.rendered_output.c_str(), stdout);
1230  }
1231  if (!executed.errors.empty() || executed.status == paramschema::ExecutionStatus::Fatal) {
1232  print_lines(stderr, "parameter parser error: ", executed.errors);
1233  return false;
1234  }
1235 
1236  if (executed.status == paramschema::ExecutionStatus::Help) {
1237  exit(EXIT_SUCCESS);
1238  }
1239 
1240  return true;
1241 }
1242 
1243 } // namespace
1244 
1245 
1246 int main( int argc, char *argv[] )
1247 {
1248  std::vector<std::string> normalized_args;
1249  std::string normalize_error;
1250  if (!normalize_runtime_args(argc, argv, &normalized_args, &normalize_error)) {
1251  std::fprintf(stderr, "\n*** %s\n\n", normalize_error.c_str());
1252  exit(EXIT_FAILURE);
1253  }
1254 
1255  if (!apply_parser_runtime_args(normalized_args)) {
1256  exit(EXIT_FAILURE);
1257  }
1258 
1259 
1260  float tsize[3], x0[3];
1261  bool symbath[3];
1262 
1263 
1264  for( int i=0; i<3; i++ ) {
1265  param_globals::size[i] *= CM2UM;
1266  param_globals::bath[i] *= CM2UM;
1267  param_globals::center[i] *= CM2UM;
1268  // in 2D case we don't allow a bath attached in the direction
1269  // perpendicular to the 2D surface
1270  if(param_globals::size[i]==0.) param_globals::bath[i] = 0.0;
1271  if(param_globals::bath[i]>=0) {
1272  tsize[i] = param_globals::size[i]+param_globals::bath[i];
1273  symbath[i] = false;
1274  x0[i] = -0.5*param_globals::size[i]+param_globals::center[i];
1275  }
1276  else {
1277  tsize[i] = param_globals::size[i]-2*param_globals::bath[i];
1278  symbath[i] = true;
1279  x0[i] = -0.5*tsize[i]+param_globals::center[i];
1280  }
1281  }
1282 
1283  Region **region = (Region**)calloc(param_globals::numRegions+1,sizeof(Region*));
1284  Point ctr;
1285  ctr.x = param_globals::center[0];
1286  ctr.y = param_globals::center[1];
1287  ctr.z = param_globals::center[2];
1288 
1289  RegionDef* regdef = param_globals::regdef;
1290 
1291  for (int r = 0; r < param_globals::numRegions; r++ ) {
1292  Point p0 = scal_X( p_assign_array(regdef[r].p0), CM2UM );
1293  if( !param_globals::size[2]) p0.z = 0;
1294  Point p1;
1295  switch(regdef[r].type) {
1296  case 0:
1297  if( !param_globals::size[2] ) p1.z = 0;
1298  p1 = scal_X( p_assign_array( regdef[r].p1 ), CM2UM );
1299  p1 = p1 + ctr;
1300  if( p0.x>p1.x ) std::swap( p0.x, p1.x );
1301  if( p0.y>p1.y ) std::swap( p0.y, p1.y );
1302  if( p0.z>p1.z ) std::swap( p0.z, p1.z );
1303  region[r] = new BlockRegion( p0, p1, regdef[r].bath );
1304  break;
1305  case 1:
1306  regdef[r].rad *= CM2UM;
1307  region[r] = new SphericalRegion( p0,regdef[r].rad, regdef[r].bath );
1308  break;
1309  case 2:
1310  Point axis;
1311  if( !param_globals::size[2] )
1312  axis = {0,0,1};
1313  else
1314  axis = p_assign_array( regdef[r].p1 );
1315  regdef[r].rad *= CM2UM;
1316  regdef[r].cyllen *= CM2UM;
1317  region[r] = new CylindricalRegion( p0, axis, regdef[r].rad,
1318  regdef[r].cyllen, regdef[r].bath );
1319  break;
1320  }
1321  region[r]->tag(regdef[r].tag);
1322  }
1323  region[param_globals::numRegions] = NULL;
1324 
1325 
1326  Grid *grid;
1327  if( !param_globals::size[1] && !param_globals::size[2] )
1328  grid = new Grid1D( param_globals::mesh, region );
1329  else if( !param_globals::size[2] )
1330  grid = new Grid2D( param_globals::mesh, region );
1331  else {
1332  grid = new Grid3D( param_globals::mesh, region );
1333  }
1334 
1335  if( grid->os_good() ) {
1336  grid->unPrMFiberDefs();
1337  grid->build_mesh(x0, tsize, param_globals::size, symbath, param_globals::resolution,
1338  param_globals::perturb, param_globals::anisoBath, param_globals::periodic);
1339  delete grid;
1340  }
1341  else {
1342  std::cerr << "ERROR:" << std::endl;
1343  std::cerr << "Could not open mesh files " << param_globals::mesh << ".* for writing!" << std::endl;
1344  std::cerr << "Aborting!" << std::endl;
1345  delete grid;
1346  return 1;
1347  }
1348 
1349  return 0;
1350 }
#define M_PI
Definition: ION_IF.h:57
void update(Point p)
Definition: mesher.cc:340
virtual bool inside(Point p)
Definition: mesher.cc:135
BlockRegion(Point p0, Point p, int bth)
Definition: mesher.cc:119
int * bx
Definition: mesher.cc:358
float z2xi(float z, bool nodeGrid)
Definition: mesher.cc:369
BBoxDef bctrs
Definition: mesher.cc:364
float mx_z(bool nodeGrid)
Definition: mesher.cc:358
float * res
Definition: mesher.cc:363
BBoxDef nodes
Definition: mesher.cc:365
void dims(void)
Definition: mesher.cc:420
int bx_inds[3][2]
Definition: mesher.cc:361
virtual ~BoundingBox()
Definition: mesher.cc:353
void init(int *_bx, float *_res, Point p0)
Definition: mesher.cc:381
float mn_z(bool nodeGrid)
Definition: mesher.cc:357
virtual bool inside(Point p)
Definition: mesher.cc:155
CylindricalRegion(Point origin, Point dir, float r, float l, int bth)
Definition: mesher.cc:144
~Element()
Definition: mesher.cc:167
int n_
Definition: mesher.cc:173
int num()
Definition: mesher.cc:169
TisAxes ax
Definition: mesher.cc:171
Element(int N, const char *t)
Definition: mesher.cc:166
Point centre(Point *ctr)
Definition: mesher.cc:179
std::string type_
Definition: mesher.cc:175
int * p_
Definition: mesher.cc:174
virtual void output_boundary(char *fn)
Definition: mesher.cc:525
Grid1D(char *m, Region **r)
Definition: mesher.cc:526
virtual void build_mesh(float *, float *, float *, bool *, float *, float, bool, int)
Definition: mesher.cc:678
Grid2D(char *m, Region **r)
Definition: mesher.cc:508
virtual void output_boundary(char *fn)
Definition: mesher.cc:507
virtual void build_mesh(float *, float *, float *, bool *, float *, float, bool, int)
Definition: mesher.cc:762
virtual void build_mesh(float *, float *, float *, bool *, float *, float, bool, int)
Definition: mesher.cc:904
virtual void output_boundary(char *fn)
Definition: mesher.cc:516
Grid3D(char *m, Region **r)
Definition: mesher.cc:517
Definition: mesher.cc:479
virtual void output_boundary(char *)=0
fibDef f_def
Definition: mesher.cc:498
std::ofstream pt_os
Definition: mesher.cc:495
virtual ~Grid()
Definition: mesher.cc:482
BoundingBox t_bbx
Definition: mesher.cc:494
std::ofstream elem_os
Definition: mesher.cc:495
bool os_good()
Definition: mesher.cc:532
virtual void build_mesh(float *, float *, float *, bool *, float *, float, bool, int)=0
int dim
Definition: mesher.cc:501
void set_indx_bounds(bool *sym)
Definition: mesher.cc:570
std::ofstream lon_os
Definition: mesher.cc:495
std::ofstream vec_os
Definition: mesher.cc:495
Point * pt
Definition: mesher.cc:491
Grid(char *, Region **, int)
Definition: mesher.cc:538
int num_axes
Definition: mesher.cc:497
void add_element(Element &, region_t)
Definition: mesher.cc:623
std::ofstream elemc_os
Definition: mesher.cc:495
int npt
Definition: mesher.cc:492
void unPrMFiberDefs(void)
Definition: mesher.cc:606
tmProfile f_xi
Definition: mesher.cc:499
bool chk_bath(int i, int j, int k)
Definition: mesher.cc:592
BoundingBox b_bbx
Definition: mesher.cc:493
tmProfile s_xi
Definition: mesher.cc:500
Region ** region
Definition: mesher.cc:496
Hexahedron(int A, int B, int C, int D, int E, int F, int G, int H)
Definition: mesher.cc:205
Definition: mesher.cc:226
Line(int A, int B)
Definition: mesher.cc:228
Quadrilateral(int A, int B, int C, int D)
Definition: mesher.cc:212
virtual bool inside(Point)=0
bool isbath()
Definition: mesher.cc:108
int tag_
Definition: mesher.cc:114
Region(Point p, int b)
Definition: mesher.cc:105
Point p0_
Definition: mesher.cc:112
virtual ~Region()
Definition: mesher.cc:106
int tag()
Definition: mesher.cc:109
void tag(int t)
Definition: mesher.cc:110
int bath_
Definition: mesher.cc:113
virtual bool inside(Point p)
Definition: mesher.cc:129
SphericalRegion(Point ctr, float r, int bth)
Definition: mesher.cc:127
Tetrahedron(int A, int B, int C, int D)
Definition: mesher.cc:188
void chkNegVolume(Point *pts)
Definition: mesher.cc:194
void set_axes(float alpha_, float beta_pr_, float gamma_)
Definition: mesher.cc:80
void set_xi(float xi_)
Definition: mesher.cc:64
Point fiber(void)
Definition: mesher.cc:67
void set_bath_axes(bool)
Definition: mesher.cc:95
Point sheet(void)
Definition: mesher.cc:68
Triangle(int A, int B, int C)
Definition: mesher.cc:220
char * s_name(void)
Definition: mesher.cc:439
float sheetEpi()
Definition: mesher.cc:444
float imbrication()
Definition: mesher.cc:440
float rotEpi()
Definition: mesher.cc:442
float rotEndo()
Definition: mesher.cc:441
void setFiberDefs(char *f_prof, float fEndo, float fEpi, float imbr, char *s_prof, float sEndo, float sEpi)
Definition: mesher.cc:456
float sheetEndo()
Definition: mesher.cc:443
bool withSheets(void)
Definition: mesher.cc:469
char * f_name(void)
Definition: mesher.cc:438
int read(char *fname)
Definition: mesher.cc:304
int linear(float ang_endo, float ang_epi, float z_endo, float z_epi)
Definition: mesher.cc:260
float lookup(float xi)
Definition: mesher.cc:290
~tmProfile()
Definition: mesher.cc:248
int main(int argc, char *argv[])
Definition: mesher.cc:1246
const float CM2UM
Definition: mesher.cc:60
const Point e_circ
Definition: mesher.cc:54
const Point e_rad
Definition: mesher.cc:56
region_t
Definition: mesher.cc:42
@ Anisobath
Definition: mesher.cc:42
@ Isobath
Definition: mesher.cc:42
@ Myocardium
Definition: mesher.cc:42
const Point e_long
Definition: mesher.cc:55
#define BOX_CENTERS_GRID
Definition: mesher.cc:44
std::ostream & operator<<(std::ostream &out, Element &e)
Definition: mesher.cc:232
Point p_assign_array(float *p)
Definition: mesher.cc:47
axis
split axis
Definition: kdpart.hpp:48
constexpr T min(T a, T b)
Definition: ion_type.h:18
constexpr T max(T a, T b)
Definition: ion_type.h:16
V det3(const vec3< V > &a, const vec3< V > &b, const vec3< V > &c)
Definition: vect.h:82
vec3< V > scal_X(const vec3< V > &a, S k)
Definition: vect.h:136
V dot(const vec3< V > &p1, const vec3< V > &p2)
Definition: vect.h:111
vec3< V > normalize(vec3< V > a)
Definition: vect.h:184
V dist_2(const vec3< V > &p1, const vec3< V > &p2)
Definition: vect.h:88
V mag2(const vec3< V > &vect)
Definition: vect.h:124
void assign(S ix, S iy, S iz)
Definition: vect.h:31