Index: trunk/zoo-project/zoo-services/cgal/voronoi.c
===================================================================
--- trunk/zoo-project/zoo-services/cgal/service.c	(revision 425)
+++ trunk/zoo-project/zoo-services/cgal/voronoi.c	(revision 469)
@@ -36,37 +36,11 @@
 #include "ogrsf_frmts.h"
 #include "service.h"
-
-typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
-
-typedef CGAL::Delaunay_triangulation_2<K>  Triangulation;
+#include "cgal_service.h"
+
+typedef CGAL::Delaunay_triangulation_2<Kernel>  Triangulation;
 typedef Triangulation::Edge_iterator  Edge_iterator;
-typedef Triangulation::Point          Point;
-
-typedef CGAL::Constrained_Delaunay_triangulation_2<K> CDT;
-typedef CDT::Point Point;
-typedef CDT::Vertex_handle Vertex_handle;
-
-typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
-typedef CGAL::Triangulation_euclidean_traits_xy_3<K>  Gt;
-typedef CGAL::Delaunay_triangulation_2<Gt> DelaunayTriangulation;
-
 typedef Triangulation::Vertex_circulator Vertex_circulator;
 
-typedef K::Point_3   Point1;
-
 extern "C" {
-#include <libxml/tree.h>
-#include <libxml/parser.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-
-#include <openssl/sha.h>
-#include <openssl/hmac.h>
-#include <openssl/evp.h>
-#include <openssl/bio.h>
-#include <openssl/buffer.h>
-
-  xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
-  void printExceptionReportResponse(maps*,map*);
 
   int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
@@ -77,58 +51,15 @@
     OGRGeometryH geometry,res;
     int bufferDistance;
-    xmlInitParser();
     map* tmpm=NULL;
     tmpm=getMapFromMaps(inputs,"InputPoints","value");
-    
-    xmlInitParser();
-    xmlDocPtr doc =
-      xmlParseMemory(tmpm->value,strlen(tmpm->value));
-    xmlNodePtr cur = xmlDocGetRootElement(doc);
-    /**
-     * Parse every Input in DataInputs node.
-     */
-    maps* tempMaps=NULL;
-    xmlXPathContextPtr xpathCtx;
-    xmlXPathObjectPtr xpathObj;
-    xpathCtx = xmlXPathNewContext(doc);
-    xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx);
-    xmlXPathFreeContext(xpathCtx); 
-    xmlNodeSet* nSet=xpathObj->nodesetval;
-
-    if(nSet==NULL){
-      setMapInMaps(conf,"lenv","message","Unable to continue !!!");
-      return SERVICE_FAILED;
-    }
-    char filepath[2048];
-    map* tmpMap=getMapFromMaps(conf,"main","tmpPath");
-    if(tmpMap!=NULL){
-      sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid());
-    }
-    FILE *fo=fopen(filepath,"w");
-#ifdef DEBUG
-    fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr);
-#endif
-    for(int k=0;k<nSet->nodeNr;k++){
-      xmlNodePtr cur=nSet->nodeTab[k];
-      char *val=
-	(char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
-      char *tmp=strstr(val,",");
-      char tmp1[1024];
-      strncpy(tmp1,val,strlen(val)-strlen(tmp));
-      tmp1[strlen(val)-strlen(tmp)]=0;
-      char buff[1024];
-      sprintf(buff,"%s %s\n",tmp1,tmp+1);
-      fwrite(buff,1,strlen(buff)*sizeof(char),fo);
-    }
-    fclose(fo);
-#ifdef DEBUG
-    fprintf(stderr,"File Close (%s) OK\n",filepath);
-#endif
-
-    std::ifstream in(filepath);
-    std::istream_iterator<Point> begin(in);
-    std::istream_iterator<Point> end;
+
+    OGRRegisterAll();
+
+    std::vector<Point> points;
+    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
+      return res;
+    
     Triangulation T;
-    T.insert(begin, end);
+    T.insert(points.begin(), points.end());
 
     OGRRegisterAll();
@@ -142,5 +73,5 @@
     int                  iDriver;
 
-    tmpMap=getMapFromMaps(outputs,"Result","mimeType");
+    map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
     const char *oDriver;
     oDriver="GeoJSON";
@@ -192,7 +123,7 @@
     /* -------------------------------------------------------------------- */
     map* tpath=getMapFromMaps(conf,"main","tmpPath");
-    char *pszDestDataSource=(char*)malloc(strlen(tpath->value)+20);
+    char *pszDestDataSource=(char*)malloc(100);
     char **papszDSCO=NULL;
-    sprintf(pszDestDataSource,"%s/result_%d.json",tpath->value,getpid());
+    sprintf(pszDestDataSource,"/vsimem/result_%d.json",tpath->value,getpid());
     poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
     if( poODS == NULL ){
@@ -231,7 +162,7 @@
     for ( ; eit !=T.edges_end(); ++eit) {
       CGAL::Object o = T.dual(eit);
-      if (const K::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) {
-	const K::Point_2 p1=tmp->source();
-	const K::Point_2 p2=tmp->target();
+      if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) {
+	const Point p1=tmp->source();
+	const Point p2=tmp->target();
 #ifdef DEBUG
 	fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
@@ -250,8 +181,22 @@
 	++ns ;
       }
-      else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;}
+      else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) { 
+	const Point p1=tmp->source();
+	const Point p2=tmp->point(2);
+	OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
+	OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
+	OGR_G_AddPoint_2D(currLine,p1.x(),p1.y());
+	OGR_G_AddPoint_2D(currLine,p2.x(),p2.y());
+	OGR_F_SetGeometry( hFeature, currLine );
+	OGR_G_DestroyGeometry(currLine);
+	if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
+	  setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n");
+	  return SERVICE_FAILED;
+	}
+	OGR_F_Destroy( hFeature );
+	++nr; 
+      }
     }
     OGR_DS_Destroy( poODS );
-    OGRCleanupAll();
 
 #ifdef DEBUG
@@ -261,21 +206,8 @@
 #endif
     
-    char tmp1[1024];
-
-    FILE * fichier=fopen(pszDestDataSource,"r"); 
-    struct stat file_status;
-    stat(pszDestDataSource, &file_status);
-    char *res1=(char *)malloc(file_status.st_size*sizeof(char));
-    if(fichier==NULL){
-      char tmp[1024];
-      sprintf(tmp,"Failed to open file %s for reading purpose.\n",
-	      pszDestDataSource);
-      setMapInMaps(conf,"lenv","message",tmp);
-      return SERVICE_FAILED;
-    }
-    fread(res1,1,(file_status.st_size)*sizeof(char),fichier);
-    res1[strlen(res1)]=0;
-    fclose(fichier);
-    unlink(pszDestDataSource);
+
+    char *res1=readVSIFile(conf,pszDestDataSource);
+    if(res1==NULL)
+      return SERVICE_FAILED;
     
     setMapInMaps(outputs,"Result","value",res1);
@@ -290,5 +222,5 @@
     fprintf(stderr,"\nService internal print\n===\n");
 #endif
-    xmlCleanupParser();
+    OGRCleanupAll();
     return SERVICE_SUCCEEDED;
   }
