Index: ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp	(revision 0)
+++ ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp	(revision 19010)
@@ -0,0 +1,104 @@
+/*!\file:  ExpToLevelSetxt.cpp
+ * \brief  "thread" core code for figuring out level set value from a contour and a cloud of points.
+ */ 
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+/*Include files: {{{*/
+#include "./ExpToLevelSetx.h"
+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){
+
+	/*gate variables :*/
+	ExpToLevelSetxThreadStruct *gate        = NULL;
+	pthread_handle             *handle      = NULL;
+	int  i,i1,i0;
+
+	/*recover handle and gate: */
+	handle          = (pthread_handle*)vpthread_handle;
+	gate            = (ExpToLevelSetxThreadStruct*)handle->gate;
+	int my_thread   = handle->id;
+	int num_threads = handle->num;
+
+	/*recover parameters :*/
+	Contours* contours  = gate->contours;
+	int       nods      = gate->nods;
+	double   *distance    = gate->distance;
+	double   *x         = gate->x;
+	double   *y         = gate->y;
+
+	/*distribute indices across threads :*/
+	PartitionRange(&i0,&i1,nods,num_threads,my_thread);
+
+	/*Loop through all contours: */
+	for (i=0;i<contours->Size();i++){
+		Contour<double>* contour=(Contour<double>*)contours->GetObjectByOffset(i);
+		ContourToLevelSet(distance,contour->x,contour->y,contour->nods,x,y,i0,i1);
+	}
+
+	return NULL;
+}
+
+void ContourToLevelSet(double* dist,double* contourx, double* contoury, int contournods, double* x, double* y, int i0, int i1){/*{{{*/
+	int i,j;
+	double x0,y0;
+	double x1,y1;
+	double x2,y2;
+	double mind;
+	
+	for(i=i0;i<i1;i++){
+		x0=x[i]; y0=y[i];
+
+		/*Figure out distance from (x0,y0) to contour: */
+		mind=INFINITY;
+		for (j=0;j<contournods-1;j++){
+			x1=contourx[j]; y1=contoury[j];
+			x2=contourx[j+1]; y2=contoury[j+1];
+			mind=min(mind,minimum_distance(x1,y1,x2,y2,x0,y0));
+		}
+		dist[i]=mind;
+	}
+
+}
+double ddistance(double x1,double y1,double x2,double y2){
+	return sqrt(pow(x2-x1,2)+pow(y2-y1,2));
+}
+double ddot(double x1, double y1, double x2, double y2){
+	return x1*x2+y1*y2;
+}
+
+bool isPointLeftOfRay(double x, double y, double raySx, double raySy, double rayEx, double rayEy) {
+	  return (y-raySy)*(rayEx-raySx)
+		    >      (x-raySx)*(rayEy-raySy); 
+}
+
+double minimum_distance(double x1, double y1, double x2, double y2, double x0, double y0){
+	
+	// Return minimum distance between line segment [(x1,y1) (x2,y2)] and point (x0,y0) (v=(x1,y1), w=(x2,y2) and p=(x0,y0)
+	double projectionx; 
+	double projectiony; 
+	double l2;
+	double t;
+
+	l2 = pow(x2-x1,2)+pow(y2-y1,2); // i.e. |w-v|^2 -  avoid a sqrt
+
+	if (l2 == 0.0) return ddistance(x0,y0, x1,y1); // v == w case
+	// Consider the line extending the segment, parameterized as v + t (w - v).
+	//         // We find projection of point p onto the line. 
+	//           // It falls where t = [(p-v) . (w-v)] / |w-v|^2
+	t = ddot(x0-x1,y0-y1, x2-x1, y2-y1) / l2;
+	if (t < 0.0) return ddistance(x0,y0, x1, y1);       // Beyond the 'v' end of the segment
+	else if (t > 1.0) return ddistance(x0,y0, x2,y2);  // Beyond the 'w' end of the segment
+	
+	projectionx= x1 + t* (x2-x1);  // Projection falls on the segment
+	projectiony= y1 + t* (y2-y1);
+	return ddistance(x0, y0, projectionx, projectiony);
+}
+/*}}}*/
Index: ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetx.h
===================================================================
--- ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetx.h	(revision 0)
+++ ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetx.h	(revision 19010)
@@ -0,0 +1,27 @@
+/*
+	ExpToLevelSetx.h
+*/
+
+#ifndef _EXPTOLEVELSETX_H
+#define _EXPTOLEVELSETX_H
+
+#include "../../shared/shared.h"
+#include "../../classes/classes.h"
+
+/*threading: */
+typedef struct{
+
+	Contours *contours;
+	int       nods;
+	double   *distance;
+	double   *x;
+	double   *y;
+
+} ExpToLevelSetxThreadStruct;
+
+/* local prototypes: */
+int ExpToLevelSetx(double** pdistance,double* x, double* y,int nods, Contours* contours);
+
+void* ExpToLevelSetxt(void* vExpToLevelSetxThreadStruct);
+
+#endif /* _EXPTOLEVELSETX_H */
Index: ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetx.cpp
===================================================================
--- ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetx.cpp	(revision 0)
+++ ../trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetx.cpp	(revision 19010)
@@ -0,0 +1,36 @@
+/*! \file  ExpToLevelSetx.c
+ */
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+#include "./ExpToLevelSetx.h"
+
+int ExpToLevelSetx(double** pdistance,double* x, double* y, int nods, Contours* contours){
+
+	/*Contour:*/
+	double value;
+
+	/*output: */
+	double*  distance;
+	distance   = xNewZeroInit<double>(nods);
+
+	/*initialize thread parameters: */
+	ExpToLevelSetxThreadStruct gate;
+	gate.contours  = contours;
+	gate.nods      = nods;
+	gate.distance    = distance;
+	gate.x         = x;
+	gate.y         = y;
+
+	/*launch the thread manager with ExpToLevelSetxt as a core: */
+	LaunchThread(ExpToLevelSetxt,(void*)&gate,_NUMTHREADS_);
+
+	/*Assign output pointers: */
+	*pdistance=distance;
+
+	return 1;
+}
Index: ../trunk-jpl/src/c/Makefile.am
===================================================================
--- ../trunk-jpl/src/c/Makefile.am	(revision 19009)
+++ ../trunk-jpl/src/c/Makefile.am	(revision 19010)
@@ -821,6 +821,9 @@
 			./modules/ContourToMeshx/ContourToMeshx.cpp\
 			./modules/ContourToMeshx/ContourToMeshxt.cpp\
 			./modules/ContourToMeshx/ContourToMeshx.h\
+			./modules/ExpToLevelSetx/ExpToLevelSetx.cpp\
+			./modules/ExpToLevelSetx/ExpToLevelSetxt.cpp\
+			./modules/ExpToLevelSetx/ExpToLevelSetx.h\
 			./modules/ContourToNodesx/ContourToNodesx.cpp\
 			./modules/ContourToNodesx/ContourToNodesx.h\
 			./modules/NodeConnectivityx/NodeConnectivityx.cpp\
Index: ../trunk-jpl/src/wrappers/ExpToLevelSet/ExpToLevelSet.cpp
===================================================================
--- ../trunk-jpl/src/wrappers/ExpToLevelSet/ExpToLevelSet.cpp	(revision 0)
+++ ../trunk-jpl/src/wrappers/ExpToLevelSet/ExpToLevelSet.cpp	(revision 19010)
@@ -0,0 +1,76 @@
+/*! \file  ContourtoMesh
+    \brief: takes a  contour file, a cloud of points, and figures out a levelset dependent on the distance between the contour and 
+	the cloud.
+*/
+
+#include "./ExpToLevelSet.h"
+
+void ExpToLevelSetUsage(void){/*{{{*/
+	_printf_("EXPTOLEVELSET - determien levelset distance between a contour and a cloud of points\n");
+	_printf_("\n");
+	_printf_("      Usage: \n");
+	_printf_("         distance=ExpToLevelSet(x,y,contourname)\n");
+	_printf_("\n");
+	_printf_("         x,y: cloud point.\n");
+	_printf_("         contourname: name of .exp file containing the contours.\n");
+	_printf_("         distance: distance vector representing a levelset where the 0 level is one the contour segments', \n");
+	_printf_("\n");
+	_printf_("      Example: \n");
+	_printf_("         distance=ExpToLevelSet(md.mesh.x,md.mesh.y,'Contour.exp')\n");
+	_printf_("\n");
+}/*}}}*/
+WRAPPER(ExpToLevelSet){
+
+	/*diverse: */
+	int i;
+
+	/* required input: */
+	int       nods;
+	double   *x           = NULL;
+	double   *y           = NULL;
+	char     *interptype  = NULL;
+	double *flags = NULL;
+	Contours *contours    = NULL;
+
+	/* output: */
+	double *distance  = NULL;
+
+	/*Boot module: */
+	MODULEBOOT();
+
+	/*check on input arguments: */
+	if(nrhs!=NRHS | nlhs!=NLHS){
+		ExpToLevelSetUsage();
+		_error_("usage. See above");
+	}
+
+	/*Fetch inputs: */
+	FetchData(&x,&nods,NULL,X);
+	FetchData(&y,NULL,NULL,Y);
+	FetchData(&contours,CONTOUR);
+
+	/*Run interpolation routine: */
+	ExpToLevelSetx( &distance,x,y,nods,contours);
+	ContourToNodesx(&flags,x,y,nods,contours,2);
+
+	/*Make flags into a sign, left or right, or nill: */
+	for(i=0;i<nods;i++){
+		if (flags[i]==0) flags[i]=-1;
+		else if (flags[i]==2) flags[i]=0;
+	}
+
+	/*Multiply flags and distance: */
+	for(i=0;i<nods;i++)distance[i]*=flags[i];
+
+	/* output: */
+	WriteData(PLHS0,distance,nods);
+
+	/*Clean up*/
+	xDelete<double>(x);
+	xDelete<double>(y);
+	delete contours;
+	delete distance;
+	
+	/*end module: */
+	MODULEEND();
+}
Index: ../trunk-jpl/src/wrappers/ExpToLevelSet/ExpToLevelSet.h
===================================================================
--- ../trunk-jpl/src/wrappers/ExpToLevelSet/ExpToLevelSet.h	(revision 0)
+++ ../trunk-jpl/src/wrappers/ExpToLevelSet/ExpToLevelSet.h	(revision 19010)
@@ -0,0 +1,56 @@
+/*
+	ExpToLevelSet.h
+*/
+
+#ifndef _EXPTOLEVELSET_H
+#define _EXPTOLEVELSET_H
+
+#ifdef HAVE_CONFIG_H
+	#include <config.h>
+#else
+	#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
+#endif
+
+/*For python modules: needs to come before header files inclusion*/
+#ifdef _HAVE_PYTHON_
+#define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol
+#endif
+
+/*Header files: */
+#include "../bindings.h"
+#include "../../c/main/globals.h"
+#include "../../c/toolkits/toolkits.h"
+#include "../../c/modules/modules.h"
+#include "../../c/shared/shared.h"
+#include "../../c/shared/io/io.h"
+#include "../../c/shared/Enum/Enum.h"
+
+#undef __FUNCT__
+#define __FUNCT__ "ExpToLevelSet"
+
+#ifdef _HAVE_MATLAB_MODULES_
+/* serial input macros: */
+#define X           prhs[0]
+#define Y           prhs[1]
+#define CONTOUR     prhs[2]
+
+/* serial output macros: */
+#define PLHS0 (mxArray**)&plhs[0]
+#endif
+
+#ifdef _HAVE_PYTHON_MODULES_
+/* serial input macros: */
+#define X           PyTuple_GetItem(args,0)
+#define Y           PyTuple_GetItem(args,1)
+#define CONTOUR     PyTuple_GetItem(args,2)
+/* serial output macros: */
+#define PLHS0 output,0
+#endif
+
+/* serial arg counts: */
+#undef NLHS
+#define NLHS  1
+#undef NRHS
+#define NRHS 3
+
+#endif  /* _EXPTOLEVELSET_H */
