Changeset 469 for trunk/zoo-project/zoo-services/cgal
- Timestamp:
- May 1, 2014, 1:28:14 AM (10 years ago)
- Location:
- trunk/zoo-project/zoo-services/cgal
- Files:
-
- 3 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-services/cgal/Makefile
r284 r469 1 ZRPATH=../.. /..1 ZRPATH=../.. 2 2 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts 3 3 CFLAGS=${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG 4 4 CC=gcc 5 5 6 cgi-env/cgal_service.zo: service.c 7 g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS} -lCGAL 6 cgi-env/cgal_service.zo: delaunay.c voronoi.c cgal_service.o 7 g++ ${CFLAGS} -c ./delaunay.c 8 g++ ${CFLAGS} -c ./voronoi.c 9 g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${MACOS_LD_FLAGS} -lCGAL -lgmp 10 11 cgal_service.o: cgal_service.c cgal_service.h 12 g++ ${CFLAGS} -c ./cgal_service.c 13 8 14 9 15 clean: 10 rm -f cgi-env/*.zo 16 rm -f cgi-env/*.zo *.o -
trunk/zoo-project/zoo-services/cgal/voronoi.c
r468 r469 36 36 #include "ogrsf_frmts.h" 37 37 #include "service.h" 38 39 typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 40 41 typedef CGAL::Delaunay_triangulation_2<K> Triangulation; 38 #include "cgal_service.h" 39 40 typedef CGAL::Delaunay_triangulation_2<Kernel> Triangulation; 42 41 typedef Triangulation::Edge_iterator Edge_iterator; 43 typedef Triangulation::Point Point;44 45 typedef CGAL::Constrained_Delaunay_triangulation_2<K> CDT;46 typedef CDT::Point Point;47 typedef CDT::Vertex_handle Vertex_handle;48 49 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;50 typedef CGAL::Triangulation_euclidean_traits_xy_3<K> Gt;51 typedef CGAL::Delaunay_triangulation_2<Gt> DelaunayTriangulation;52 53 42 typedef Triangulation::Vertex_circulator Vertex_circulator; 54 43 55 typedef K::Point_3 Point1;56 57 44 extern "C" { 58 #include <libxml/tree.h>59 #include <libxml/parser.h>60 #include <libxml/xpath.h>61 #include <libxml/xpathInternals.h>62 63 #include <openssl/sha.h>64 #include <openssl/hmac.h>65 #include <openssl/evp.h>66 #include <openssl/bio.h>67 #include <openssl/buffer.h>68 69 xmlNodeSet* extractFromDoc(xmlDocPtr,char*);70 void printExceptionReportResponse(maps*,map*);71 45 72 46 int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){ … … 77 51 OGRGeometryH geometry,res; 78 52 int bufferDistance; 79 xmlInitParser();80 53 map* tmpm=NULL; 81 54 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 82 83 xmlInitParser(); 84 xmlDocPtr doc = 85 xmlParseMemory(tmpm->value,strlen(tmpm->value)); 86 xmlNodePtr cur = xmlDocGetRootElement(doc); 87 /** 88 * Parse every Input in DataInputs node. 89 */ 90 maps* tempMaps=NULL; 91 xmlXPathContextPtr xpathCtx; 92 xmlXPathObjectPtr xpathObj; 93 xpathCtx = xmlXPathNewContext(doc); 94 xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx); 95 xmlXPathFreeContext(xpathCtx); 96 xmlNodeSet* nSet=xpathObj->nodesetval; 97 98 if(nSet==NULL){ 99 setMapInMaps(conf,"lenv","message","Unable to continue !!!"); 100 return SERVICE_FAILED; 101 } 102 char filepath[2048]; 103 map* tmpMap=getMapFromMaps(conf,"main","tmpPath"); 104 if(tmpMap!=NULL){ 105 sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid()); 106 } 107 FILE *fo=fopen(filepath,"w"); 108 #ifdef DEBUG 109 fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr); 110 #endif 111 for(int k=0;k<nSet->nodeNr;k++){ 112 xmlNodePtr cur=nSet->nodeTab[k]; 113 char *val= 114 (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1); 115 char *tmp=strstr(val,","); 116 char tmp1[1024]; 117 strncpy(tmp1,val,strlen(val)-strlen(tmp)); 118 tmp1[strlen(val)-strlen(tmp)]=0; 119 char buff[1024]; 120 sprintf(buff,"%s %s\n",tmp1,tmp+1); 121 fwrite(buff,1,strlen(buff)*sizeof(char),fo); 122 } 123 fclose(fo); 124 #ifdef DEBUG 125 fprintf(stderr,"File Close (%s) OK\n",filepath); 126 #endif 127 128 std::ifstream in(filepath); 129 std::istream_iterator<Point> begin(in); 130 std::istream_iterator<Point> end; 55 56 OGRRegisterAll(); 57 58 std::vector<Point> points; 59 if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED) 60 return res; 61 131 62 Triangulation T; 132 T.insert( begin, end);63 T.insert(points.begin(), points.end()); 133 64 134 65 OGRRegisterAll(); … … 142 73 int iDriver; 143 74 144 tmpMap=getMapFromMaps(outputs,"Result","mimeType");75 map* tmpMap=getMapFromMaps(outputs,"Result","mimeType"); 145 76 const char *oDriver; 146 77 oDriver="GeoJSON"; … … 192 123 /* -------------------------------------------------------------------- */ 193 124 map* tpath=getMapFromMaps(conf,"main","tmpPath"); 194 char *pszDestDataSource=(char*)malloc( strlen(tpath->value)+20);125 char *pszDestDataSource=(char*)malloc(100); 195 126 char **papszDSCO=NULL; 196 sprintf(pszDestDataSource," %s/result_%d.json",tpath->value,getpid());127 sprintf(pszDestDataSource,"/vsimem/result_%d.json",tpath->value,getpid()); 197 128 poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); 198 129 if( poODS == NULL ){ … … 231 162 for ( ; eit !=T.edges_end(); ++eit) { 232 163 CGAL::Object o = T.dual(eit); 233 if (const K ::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) {234 const K::Point_2p1=tmp->source();235 const K::Point_2p2=tmp->target();164 if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) { 165 const Point p1=tmp->source(); 166 const Point p2=tmp->target(); 236 167 #ifdef DEBUG 237 168 fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y()); … … 250 181 ++ns ; 251 182 } 252 else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;} 183 else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) { 184 const Point p1=tmp->source(); 185 const Point p2=tmp->point(2); 186 OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) ); 187 OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString); 188 OGR_G_AddPoint_2D(currLine,p1.x(),p1.y()); 189 OGR_G_AddPoint_2D(currLine,p2.x(),p2.y()); 190 OGR_F_SetGeometry( hFeature, currLine ); 191 OGR_G_DestroyGeometry(currLine); 192 if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){ 193 setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n"); 194 return SERVICE_FAILED; 195 } 196 OGR_F_Destroy( hFeature ); 197 ++nr; 198 } 253 199 } 254 200 OGR_DS_Destroy( poODS ); 255 OGRCleanupAll();256 201 257 202 #ifdef DEBUG … … 261 206 #endif 262 207 263 char tmp1[1024]; 264 265 FILE * fichier=fopen(pszDestDataSource,"r"); 266 struct stat file_status; 267 stat(pszDestDataSource, &file_status); 268 char *res1=(char *)malloc(file_status.st_size*sizeof(char)); 269 if(fichier==NULL){ 270 char tmp[1024]; 271 sprintf(tmp,"Failed to open file %s for reading purpose.\n", 272 pszDestDataSource); 273 setMapInMaps(conf,"lenv","message",tmp); 274 return SERVICE_FAILED; 275 } 276 fread(res1,1,(file_status.st_size)*sizeof(char),fichier); 277 res1[strlen(res1)]=0; 278 fclose(fichier); 279 unlink(pszDestDataSource); 208 209 char *res1=readVSIFile(conf,pszDestDataSource); 210 if(res1==NULL) 211 return SERVICE_FAILED; 280 212 281 213 setMapInMaps(outputs,"Result","value",res1); … … 290 222 fprintf(stderr,"\nService internal print\n===\n"); 291 223 #endif 292 xmlCleanupParser();224 OGRCleanupAll(); 293 225 return SERVICE_SUCCEEDED; 294 226 }
Note: See TracChangeset
for help on using the changeset viewer.