14 static const int TriFaces[1][3] = {
18 static const int TetFaces[4][3] = {
26 #define FIL_PTS_FILE 0
27 #define FIL_ELEM_FILE 1
28 #define FIL_DATA_FILE 2
47 void interpoate_vm(
int numNodes,
float **d,
int M,
float **rd,
float rDist);
71 Real whole = fabs(spts[1].x*spts[2].y/2.);
72 Point a[3] = { PTs, spts[1], spts[2] };
74 Real c2 = fabs(spts[1].x*PTs.y/2.)/whole;
76 fprintf( stderr,
"transformation back failed\n" );
78 return opts[0]*c0 + opts[2]*c2 + opts[1]*(1-c0-c2);
94 return 0.5*
mag(
cross(pts[1] - pts[0],pts[2] - pts[0]));
110 Point n=
cross(pts[1] - pts[0],pts[2] - pts[0]);
126 int numNodes = tbf->
nodes;
127 float **d = (
float **)(tbf->
d );
128 float **rd = (
float **)(tbf->
dr);
130 float rdist = tbf->
rdist;
149 for(
int j=0;j<numNodes;j++) {
150 rd[0][j] = d[0 ][j]+rdist*(d[1 ][j]-d[0 ][j]);
151 rd[1][j] = d[M-2][j]+rdist*(d[M-1][j]-d[M-2][j]);
176 #pragma omp parallel for
177 for(
int i=0;i<elst->
NElems; i++) {
185 log_msg(NULL,2,0,
"%s: Type in Element %d not supported yet.\n",
189 for(
int j=0;j<e.
Nnode;j++) {
190 d0_elem[j] = d0[e.
N[j]];
191 d1_elem[j] = d1[e.
N[j]];
211 for(
int j=0; j<e.
Nnode; j++ )
212 lp[j] = nlst->
Node[e.
N[j]];
218 d0_elem[3] = d0_elem[0];
219 d1_elem[3] = d1_elem[0];
248 s.back().ps.eIndx = eIndx;
255 std::sort(
s.begin(),
s.end(),
274 char pname[512], ename[512], dname[512];
276 snprintf(pname,
sizeof pname,
"%s.pts_t", meshname);
277 snprintf(ename,
sizeof ename,
"%s.elem_t", meshname);
278 snprintf(dname,
sizeof dname,
"%s.dat_t", meshname);
283 FILE *fhp = fopen(pname,
"wt"); fh[0] = fhp;
284 FILE *fhe = fopen(ename,
"wt"); fh[1] = fhe;
285 FILE *fhd = fopen(dname,
"wt"); fh[2] = fhd;
287 if( (fhp==NULL) || (fhe==NULL) || (fhd==NULL) )
293 fprintf(fhp,
"## Format x y z # singularity type (0=PS || 1=FilSeg) Global element index \n");
294 fprintf(fhp,
"%d\n", numT);
295 fprintf(fhe,
"## Format Ln p0 p1 || PS p0 \n");
296 fprintf(fhe,
"%d\n", numT);
297 fprintf(fhd,
"## Format data (matching with pts_t file) \n");
298 fprintf(fhd,
"%d\n", numT);
317 char pname[512], ename[512], dname[512];
319 snprintf(fname,
sizeof fname,
"filament_%.2f.cnnx", t);
320 FILE *fh = fopen(fname,
"wt");
324 for(
int i=0; i<f->
num_segs(); i++ ) {
326 Elem &e = elst->
Ele[f->
s[i].ps.eIndx];
331 fprintf( fh,
"%d %d\n", vtx0, vtx1 );
356 fprintf(filHdls[i],
"#%.6f\n",t);
363 fprintf(stderr,
"%d filament segments found\n",N);
378 for(
int i=0; i<f->
num_segs(); i++ )
383 for(
int i=0; i<f->
num_segs(); i++ ){
384 FILE *fhp = filHdls[0], *fhe = filHdls[1], *fhd = filHdls[2];
387 fprintf(fhp,
"%.3f %.3f %.3f # %d %d\n", fs.
p0.x,fs.
p0.y,fs.
p0.z,
391 fprintf(fhd,
"%d\n",fs.
eIndx);
399 fprintf(fhp,
"%.3f %.3f %.3f # %d %d\n", fs.
p1.x,fs.
p1.y,fs.
p1.z,
401 fprintf(fhd,
"%d\n",fs.
eIndx);
402 fprintf(fhe,
"Ln %d %d\n", ptCnt, ptCnt+1);
432 for(
int i=1;i<e->
Nnode;i++)
437 for(
int i=1;i<e->
Nnode;i++)
467 fprintf(stderr,
"%s: Element type not implemented yet.\n", __func__);
528 if((d[idx[1]]<th) || (d[idx[2]]<th)) tag =
true;
531 if((d[idx[1]]>=th) || (d[idx[2]]>=th)) tag =
true;
550 float d0_[3], d1_[3];
552 int FilamentType = 0;
554 int tagged[] = { 0, 0, 0, 0};
555 int tagIdx[] = {-1,-1,-1,-1};
563 tagIdx[FilamentType++] = i;
567 for(
int i=0;i<4;i++) {
568 for(
int j=0;j<3;j++) {
569 d0_[j] = d0[TetFaces[i][j]];
570 d1_[j] = d1[TetFaces[i][j]];
571 lp_[j] = lp[TetFaces[i][j]];
575 tagIdx[FilamentType++] = i;
580 fprintf(stderr,
"Element type not supported by %s.\n", __func__ );
584 sng->
ps.
type = FilamentType;
586 sng->
ps.
p0 = PhaseS[tagIdx[0]];
588 sng->
fs.
p1 = PhaseS[tagIdx[1]];
636 fprintf(stderr,
"Shape function method not implemented yet.\n");
671 Point p01 = lp[1] - lp[0];
672 pt[1].set(
mag(p01), 0., 0.);
673 Point p02 = lp[2] - lp[0];
674 double ptx =
dot(p02,p01)/pt[1].x;
675 pt[2].set(ptx, sqrt(
mag2(p02)-ptx*ptx),0.);
677 int tEdg0[] = {0,0,0};
678 int tEdg1[] = {0,0,0};
679 Point tSec0[3], tSec1[3];
696 for(
int i=0;i<3;i++) {
699 if(tEdg0[i]) t0s[c0++] = i;
700 if(tEdg1[i]) t1s[c1++] = i;
702 if((t0==2) && (t1==2)) {
719 Point &a0 = tSec0[t0s[0]];
720 Point &b0 = tSec0[t0s[1]];
721 Point &a1 = tSec1[t1s[0]];
722 Point &b1 = tSec1[t1s[1]];
724 Point b0ma0 = b0 - a0;
725 Point b1ma1 = a1 - b1;
726 Point a1ma0 = a1 - a0;
729 A.
Ent[0][0] = b0ma0.x; A.
Ent[0][1] = b1ma1.x;
730 A.
Ent[1][0] = b0ma0.y; A.
Ent[1][1] = b1ma1.y;
731 b[0] = a1ma0.x; b[1] = a1ma0.y;
752 PhaseS[0] = lp[0]*bcc.
x + lp[1]*bcc.y + lp[2]*bcc.z;
762 for(
int j=0; j<3; j++ )
763 ptb[j] =
dot(bcc,pt[j]);
789 return dot(cp1,cp2)>=0;
838 double dot00 = v0.x*v0.x+v0.y*v0.y;
839 double dot01 = v0.x*v1.x;
840 double dot02 = v0.x*v2.x+v0.y*v2.y;
841 double dot11 = v1.x*v1.x;
842 double dot12 = v1.x*v2.x;
845 double invDenom = 1/(dot00*dot11-dot01*dot01);
846 bcc.z = (dot11*dot02-dot01*dot12)*invDenom;
847 if( bcc.z < 0 )
return false;
848 bcc.y = (dot00*dot12-dot01*dot02)*invDenom;
849 bcc.x = 1. - bcc.z - bcc.y;
852 return (bcc.x>=0) && (bcc.y>=0);
880 Point v2 = pTest - p0;
883 double dot00 =
dot(v0,v0);
884 double dot01 =
dot(v0,v1);
885 double dot02 =
dot(v0,v2);
886 double dot11 =
dot(v1,v1);
887 double dot12 =
dot(v1,v2);
890 double invDenom = 1/(dot00*dot11-dot01*dot01);
891 bcc.z = (dot11*dot02-dot01*dot12)*invDenom;
892 bcc.y = (dot00*dot12-dot01*dot02)*invDenom;
893 bcc.x = 1. - bcc.z - bcc.y;
896 return (bcc.x>=0) && (bcc.y>=0) && (bcc.z>=0);
928 float sec = (d_p0-th)/(d_p0-d_p1);
929 *pSec = *p0 +
scal_X(l,sec);
948 bool isFilament =
false;
953 for (
int i=0;i<4;i++) {
955 M.
Ent[i][1] = p[i].x;
956 M.
Ent[i][2] = p[i].y;
957 M.
Ent[i][3] = p[i].z;
960 double v0[4], v1[4], vf[4];
961 for(
int i=0;i<4;i++) v0[i] = d0[i];
962 for(
int i=0;i<4;i++) v1[i] = d1[i];
973 int intersect = 0, NFaces = 4;
974 for(
int i=0;i<NFaces;i++) {
976 for(
int j=0;j<4;j++) vf[j] = th+1;
977 for(
int j=0;j<3;j++) vf[TetFaces[i][j]] = th;
988 for(
int j=0;j<3;j++) {
989 Id.
Ent[0][j] = v0[j+1];
990 Id.
Ent[1][j] = v1[j+1];
991 Id.
Ent[2][j] = vf[j+1];
1001 float xmn,xmx,ymn,ymx,zmn,zmx;
1006 for(
int j=1;j<4;j++) {
1007 if(p[j].x<xmn) xmn = p[j].x;
1008 if(p[j].x>xmx) xmx = p[j].x;
1009 if(p[j].y<ymn) ymn = p[j].y;
1010 if(p[j].y>ymx) ymx = p[j].y;
1011 if(p[j].z<zmn) zmn = p[j].z;
1012 if(p[j].z>zmx) zmx = p[j].z;
1015 if((r[0]>=xmn) && (r[0]<=xmx) &&
1016 (r[1]>=ymn) && (r[1]<=ymx) &&
1017 (r[2]>=zmn) && (r[2]<=zmx) ) {
1019 log_msg(NULL,0,0,
"Intersection found at [x,y,z]=[%.2f,%.2f,%.2f]",
1025 if( ((e->
type==
Tri) && (intersect==1)) ||
void dot(data_t *x, data_t *y, int n, int nc, FILE *out, bool pt)
perform dot product
void normalize(IGBheader *h, FILE *out, T *min, T *max)
normalize pixels over all time
bool decomposed
true if decomposed
Real ** Ent
matrix entries
void add_singularity(singularity *s, int)
std::vector< singularity > s
float fl_triArea(Point *pts)
int init_filament_IO(const char *meshname, int numT, FILE *fh[])
void interpolate_vm(int numNodes, float **d, int M, float **rd, float rdist)
Point UnTransformPoint(Point PTs, Point *opts, Point *spts)
bool fl_chkIso(float *d, float th, Elem *e)
int write_connections(ElemList *elst, NodeList *nlst, filament *f, FILE *filHdls[], float t)
int fl_FindFilament(float *d0, float *d1, float th, Point *lp, Elem *e, singularity *sng)
bool PtInTriangleBarycentricSP(Point pTest, Point p1, Point p2)
void interpolateTBuffer(tbuffer *tbf)
bool SameSideOfLine(Point pTest, Point p0, Point p1, Point p2)
void interpoate_vm(int numNodes, float **d, int M, float **rd, float rDist)
bool fl_IsoTagFaces(float *d, float th, Elem *e, bool *faceTags)
bool fl_triFindPS_ShpFnc(float *d0, float *d1, float th, Point *p, Point *PS)
void write_filaments(filament *f, FILE *filHdls[], float t)
bool fl_findIsoIntersect(float *d0, float *d1, float th, Point *p, Elem *e)
bool fl_IsoTagTriangle(float *d, float th, const int idx[])
void close_filament_IO(FILE *fh[])
bool PointInTriangle(Point pTest, Point p0, Point p1, Point p2)
bool fl_findEdgeSection(float d_p0, float d_p1, float th, Point *p0, Point *p1, Point *pSec)
void output_filaments(filament *f, FILE *fh[])
bool PointInTriangleBarycentric(Point pTest, Point p0, Point p1, Point p2)
bool compute_filament(float *d0, float *d1, float vth, ElemList *elst, NodeList *nlst, filament *f, SingularityDetector_t meth)
bool fl_triFindPS_Lines(float *d0, float *d1, float th, Point *p, Point *PS)
bool fl_IsoTagTetFaces(float *d, float th, bool *faceTags)
Point fl_triNormalLocal(Point *pts, bool u)
bool fl_IsoTagTriFaces(float *d, float th, bool *faceTags)
bool fl_triFindPS(float *d0, float *d1, float th, Point *p, Point *PS, int meth)
#define log_msg(F, L, O,...)
double mag(const Point &vect)
vector magnitude
Point cross(const Point &a, const Point &b)
cross product
vec3< V > scal_X(const vec3< V > &a, S k)
V mag2(const vec3< V > &vect)
Integer NElems
number of elements (owned+ghost in case of LOCAL_ELEM)
Point * Node
list of nodes*
time slice buffer for post processing
float ** dr
resampled data buffer
int wdth
width of buffer, always 2*h_wdth+1
float rdist
rel dist of sample to center
int nodes
number of nodes in time slice