Ice Sheet System Model  4.18
Code documentation
Functions
ExpToLevelSetxt.cpp File Reference

"thread" core code for figuring out level set value from a contour and a cloud of points. More...

#include "./ExpToLevelSetx.h"

Go to the source code of this file.

Functions

double minimum_distance (double x1, double y1, double x2, double y2, double x0, double y0)
 
void ContourToLevelSet (double *distance, double *contourx, double *contoury, int contournods, double *x, double *y, int i0, int i10)
 
void * ExpToLevelSetxt (void *vpthread_handle)
 

Detailed Description

"thread" core code for figuring out level set value from a contour and a cloud of points.

Definition in file ExpToLevelSetxt.cpp.

Function Documentation

◆ minimum_distance()

double minimum_distance ( double  x1,
double  y1,
double  x2,
double  y2,
double  x0,
double  y0 
)

Definition at line 71 of file ExpToLevelSetxt.cpp.

71  {
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  */
77 
78  /*Get segment length square (avoid sqrt) |w-v|^2*/
79  double l2 = pow(x2-x1,2)+pow(y2-y1,2);
80 
81  /*segment is single point: v == w*/
82  if(l2 == 0.) return sqrt(pow(x1-x0,2)+pow(y1-y0,2));
83 
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  }
95 
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));
100 }

◆ ContourToLevelSet()

void ContourToLevelSet ( double *  distance,
double *  contourx,
double *  contoury,
int  contournods,
double *  x,
double *  y,
int  i0,
int  i10 
)

Definition at line 48 of file ExpToLevelSetxt.cpp.

48  {/*{{{*/
49 
50  double x0,y0;
51  double x1,y1;
52  double x2,y2;
53  double mind;
54 
55  for(int i=i0;i<i1;i++){
56 
57  /*Get current point*/
58  x0=x[i]; y0=y[i];
59 
60  /*Figure out distance from (x0,y0) to contour: */
61  mind=1e+50;
62  for(int j=0;j<contournods-1;j++){
63  /*Get distance from current segment*/
64  x1=contourx[j]; y1=contoury[j];
65  x2=contourx[j+1]; y2=contoury[j+1];
66  mind=min(mind,minimum_distance(x1,y1,x2,y2,x0,y0));
67  }
68  dist[i]=min(dist[i],mind);
69  }
70 }

◆ ExpToLevelSetxt()

void* ExpToLevelSetxt ( void *  vpthread_handle)

Definition at line 16 of file ExpToLevelSetxt.cpp.

16  {
17 
18  /*gate variables :*/
19  ExpToLevelSetxThreadStruct *gate = NULL;
20  pthread_handle *handle = NULL;
21  int i,i1,i0;
22 
23  /*recover handle and gate: */
24  handle = (pthread_handle*)vpthread_handle;
25  gate = (ExpToLevelSetxThreadStruct*)handle->gate;
26  int my_thread = handle->id;
27  int num_threads = handle->num;
28 
29  /*recover parameters :*/
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;
35 
36  /*distribute indices across threads :*/
37  PartitionRange(&i0,&i1,nods,num_threads,my_thread);
38 
39  /*Loop through all contours: */
40  for(i=0;i<contours->Size();i++){
41  Contour<double>* contour=(Contour<double>*)contours->GetObjectByOffset(i);
42  ContourToLevelSet(distance,contour->x,contour->y,contour->nods,x,y,i0,i1);
43  }
44 
45  return NULL;
46 }
pthread_handle::id
int id
Definition: issm_threads.h:12
pthread_handle::num
int num
Definition: issm_threads.h:13
Contours
Declaration of Contours class.
Definition: Contours.h:10
ExpToLevelSetxThreadStruct
Definition: ExpToLevelSetx.h:12
Contour
Definition: Contour.h:15
minimum_distance
double minimum_distance(double x1, double y1, double x2, double y2, double x0, double y0)
Definition: ExpToLevelSetxt.cpp:71
ExpToLevelSetxThreadStruct::x
double * x
Definition: ExpToLevelSetx.h:17
ExpToLevelSetxThreadStruct::distance
double * distance
Definition: ExpToLevelSetx.h:16
ExpToLevelSetxThreadStruct::contours
Contours * contours
Definition: ExpToLevelSetx.h:14
pthread_handle
Definition: issm_threads.h:10
PartitionRange
void PartitionRange(int *pi0, int *pi1, int num_el, int num_threads, int my_thread)
Definition: PartitionRange.cpp:13
ExpToLevelSetxThreadStruct::y
double * y
Definition: ExpToLevelSetx.h:18
Contour::nods
int nods
Definition: Contour.h:20
ExpToLevelSetxThreadStruct::nods
int nods
Definition: ExpToLevelSetx.h:15
Contour::y
doubletype * y
Definition: Contour.h:22
min
IssmDouble min(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:14
Contour::x
doubletype * x
Definition: Contour.h:21
pthread_handle::gate
void * gate
Definition: issm_threads.h:11
ContourToLevelSet
void ContourToLevelSet(double *distance, double *contourx, double *contoury, int contournods, double *x, double *y, int i0, int i10)
Definition: ExpToLevelSetxt.cpp:48