- Timestamp:
- 05/10/18 10:24:27 (7 years ago)
- Location:
- issm/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk
- Property svn:mergeinfo changed
-
issm/trunk/src
- Property svn:mergeinfo changed
-
issm/trunk/src/c
- Property svn:ignore
-
old new 20 20 kriging 21 21 issm_slr 22 issm_ocean 23 lnb_param.mod 24 lovenb_sub.mod 25 model.mod 26 util.mod
-
- Property svn:ignore
-
issm/trunk/src/c/modules
- Property svn:ignore
-
old new 1 1 .deps 2 InputControlUpdatex 3 InputScalex 4 TriaSearchx
-
- Property svn:ignore
-
issm/trunk/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp
r21341 r22758 9 9 #endif 10 10 11 /*Include files : {{{*/11 /*Include files*/ 12 12 #include "./ExpToLevelSetx.h" 13 13 double minimum_distance(double x1, double y1, double x2, double y2, double x0, double y0); 14 void ContourToLevelSet(double* distance,double* contourx, double* contoury, int contournods, double* x, double* y, int i0, int i10); 15 /*}}}*/ 14 void ContourToLevelSet(double* distance,double* contourx, double* contoury, int contournods, double* x, double* y, int i0, int i10); 16 15 17 16 void* ExpToLevelSetxt(void* vpthread_handle){ … … 29 28 30 29 /*recover parameters :*/ 31 Contours* contours 32 int nods 33 double *distance 34 double *x 35 double *y 30 Contours* contours = gate->contours; 31 int nods = gate->nods; 32 double *distance = gate->distance; 33 double *x = gate->x; 34 double *y = gate->y; 36 35 37 36 /*distribute indices across threads :*/ … … 39 38 40 39 /*Loop through all contours: */ 41 for 40 for(i=0;i<contours->Size();i++){ 42 41 Contour<double>* contour=(Contour<double>*)contours->GetObjectByOffset(i); 43 42 ContourToLevelSet(distance,contour->x,contour->y,contour->nods,x,y,i0,i1); … … 48 47 49 48 void ContourToLevelSet(double* dist,double* contourx, double* contoury, int contournods, double* x, double* y, int i0, int i1){/*{{{*/ 50 int i,j; 49 51 50 double x0,y0; 52 51 double x1,y1; … … 54 53 double mind; 55 54 56 for(i=i0;i<i1;i++){ 55 for(int i=i0;i<i1;i++){ 56 57 /*Get current point*/ 57 58 x0=x[i]; y0=y[i]; 58 59 59 60 /*Figure out distance from (x0,y0) to contour: */ 60 61 mind=1e+50; 61 for (j=0;j<contournods-1;j++){ 62 x1=contourx[j]; y1=contoury[j]; 62 for(int j=0;j<contournods-1;j++){ 63 /*Get distance from current segment*/ 64 x1=contourx[j]; y1=contoury[j]; 63 65 x2=contourx[j+1]; y2=contoury[j+1]; 64 66 mind=min(mind,minimum_distance(x1,y1,x2,y2,x0,y0)); … … 66 68 dist[i]=min(dist[i],mind); 67 69 } 70 } 71 double minimum_distance(double x1, double y1, double x2, double y2, double x0, double y0){ 72 /* Return minimum distance between line segment [(x1,y1) (x2,y2)] and point (x0,y0) 73 * We use the following notations: 74 * segment: v=(x1,y1), w=(x2,y2) 75 * point: p=(x0,y0) 76 */ 68 77 69 } 70 double ddistance(double x1,double y1,double x2,double y2){ 71 return sqrt(pow(x2-x1,2)+pow(y2-y1,2)); 72 } 73 double ddot(double x1, double y1, double x2, double y2){ 74 return x1*x2+y1*y2; 75 } 78 /*Get segment length square (avoid sqrt) |w-v|^2*/ 79 double l2 = pow(x2-x1,2)+pow(y2-y1,2); 76 80 77 bool isPointLeftOfRay(double x, double y, double raySx, double raySy, double rayEx, double rayEy) { 78 return (y-raySy)*(rayEx-raySx) 79 > (x-raySx)*(rayEy-raySy); 80 } 81 /*segment is single point: v == w*/ 82 if(l2 == 0.) return sqrt(pow(x1-x0,2)+pow(y1-y0,2)); 81 83 82 double minimum_distance(double x1, double y1, double x2, double y2, double x0, double y0){ 84 /*Consider the line extending the segment, parameterized as v + t (w - v). 85 We find projection of point p onto the line. It falls where t = [(p-v) . (w-v)] / |w-v|^2*/ 86 double t = ((x0-x1)*(x2-x1) + (y0-y1)*(y2-y1)) / l2; 87 if(t < 0.){ 88 /*Beyond the 'v' end of the segment*/ 89 return sqrt(pow(x1-x0,2)+pow(y1-y0,2)); 90 } 91 else if(t > 1.){ 92 /*Beyond the 'w' end of the segment*/ 93 return sqrt(pow(x2-x0,2)+pow(y2-y0,2)); 94 } 83 95 84 // Return minimum distance between line segment [(x1,y1) (x2,y2)] and point (x0,y0) (v=(x1,y1), w=(x2,y2) and p=(x0,y0) 85 double projectionx; 86 double projectiony; 87 double l2; 88 double t; 89 90 l2 = pow(x2-x1,2)+pow(y2-y1,2); // i.e. |w-v|^2 - avoid a sqrt 91 92 if (l2 == 0.0) return ddistance(x0,y0, x1,y1); // v == w case 93 // Consider the line extending the segment, parameterized as v + t (w - v). 94 // // We find projection of point p onto the line. 95 // // It falls where t = [(p-v) . (w-v)] / |w-v|^2 96 t = ddot(x0-x1,y0-y1, x2-x1, y2-y1) / l2; 97 if (t < 0.0) return ddistance(x0,y0, x1, y1); // Beyond the 'v' end of the segment 98 else if (t > 1.0) return ddistance(x0,y0, x2,y2); // Beyond the 'w' end of the segment 99 100 projectionx= x1 + t* (x2-x1); // Projection falls on the segment 101 projectiony= y1 + t* (y2-y1); 102 return ddistance(x0, y0, projectionx, projectiony); 96 /*Projection falls on segment*/ 97 double projx= x1 + t* (x2-x1); 98 double projy= y1 + t* (y2-y1); 99 return sqrt(pow(projx-x0,2)+pow(projy-y0,2)); 103 100 } 104 101 /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.