[mapserver-commits] r10255 - sandbox/mapserver6

svn at osgeo.org svn at osgeo.org
Mon Jun 28 05:24:56 EDT 2010


Author: tbonfort
Date: 2010-06-28 09:24:56 +0000 (Mon, 28 Jun 2010)
New Revision: 10255

Modified:
   sandbox/mapserver6/mapgeomutil.cpp
   sandbox/mapserver6/maprendering.c
   sandbox/mapserver6/mapserver.h
Log:
polugon hatching


Modified: sandbox/mapserver6/mapgeomutil.cpp
===================================================================
--- sandbox/mapserver6/mapgeomutil.cpp	2010-06-25 20:22:33 UTC (rev 10254)
+++ sandbox/mapserver6/mapgeomutil.cpp	2010-06-28 09:24:56 UTC (rev 10255)
@@ -150,54 +150,57 @@
     return path;
 }
 
-shapeObj* msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle) {
+int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color) {
+   assert(MS_RENDERER_PLUGIN(img->format));
    mapserver::path_storage lines = createHatch(img->width, img->height, angle, spacing);
    polygon_adaptor polygons(poly);
-   shapeObj *shape = (shapeObj*)calloc(1,sizeof(shapeObj));
-   msInitShape(shape);
-   int nLinesApprox = MS_NINT(MS_MAX(img->width,img->height)*1.5 / spacing) +1;
-   lineObj *line = (lineObj*)calloc(nLinesApprox,sizeof(lineObj));
-   shape->line = line;
+   shapeObj shape;
+   msInitShape(&shape);
+   int allocated = 20;
+   lineObj line;
+   shape.line = &line;
+   shape.numlines = 1;
+   shape.line[0].point = (pointObj*)calloc(allocated,sizeof(pointObj));
+   shape.line[0].numpoints = 0;
    mapserver::conv_stroke<mapserver::path_storage> stroke(lines);
    stroke.width(width);
+   stroke.line_cap(mapserver::butt_cap);
    //mapserver::conv_clipper<mapserver::path_storage,polygon_adaptor> clipper(*lines,polygons, mapserver::clipper_and);
    //mapserver::conv_clipper<polygon_adaptor,mapserver::path_storage> clipper(polygons,lines, mapserver::clipper_and);
-   mapserver::conv_clipper<polygon_adaptor,mapserver::conv_stroke<mapserver::path_storage> > clipper(polygons,stroke, mapserver::clipper_and);
-      
-      
+   mapserver::conv_clipper<polygon_adaptor,mapserver::conv_stroke<mapserver::path_storage> > clipper(polygons,stroke, mapserver::clipper_and); 
    clipper.rewind(0);
-
-   shape->numlines = 0;
-      
+   
    double x,y;
-   unsigned int cmd,prevCmd=0;
+   unsigned int cmd, prevCmd=-1;
    while((cmd = clipper.vertex(&x,&y)) != mapserver::path_cmd_stop) {
       switch(cmd) {
       case mapserver::path_cmd_line_to:
-         //printf(" -> %f %f",x,y);
-         //assert(prevCmd == mapserver::path_cmd_move_to );
-         shape->line[shape->numlines-1].point[shape->line[shape->numlines-1].numpoints].x = x;
-         shape->line[shape->numlines-1].point[shape->line[shape->numlines-1].numpoints].y = y;
-         shape->line[shape->numlines-1].numpoints++;
+         if(shape.line[0].numpoints == allocated) {
+            allocated *= 2;
+            shape.line[0].point = (pointObj*)realloc(shape.line[0].point, allocated*sizeof(pointObj));
+         }
+         shape.line[0].point[shape.line[0].numpoints].x = x;
+         shape.line[0].point[shape.line[0].numpoints].y = y;
+         shape.line[0].numpoints++;
          break;
       case mapserver::path_cmd_move_to:
-         //printf("\n%f %f",x,y);
-         //assert(prevCmd == 0 || prevCmd == mapserver::path_cmd_line_to );
-         shape->line[shape->numlines].point = line->point = (pointObj*)calloc(100,sizeof(pointObj));
-         shape->line[shape->numlines].numpoints = 1;
-         shape->line[shape->numlines].point[0].x = x;
-         shape->line[shape->numlines].point[0].y = y;
-                  
-         shape->numlines++;
+         assert(shape.line[0].numpoints <= 1 || prevCmd == mapserver::path_cmd_line_to);
+         if(shape.line[0].numpoints > 2) {
+            MS_IMAGE_RENDERER(img)->renderPolygon(img,&shape,color);
+         }
+         shape.line[0].point[0].x = x;
+         shape.line[0].point[0].y = y;
+         shape.line[0].numpoints = 1;
          break;
       default:
          assert(0); //WTF?
       }
-      prevCmd = cmd; 
+      prevCmd = cmd;
    }
+   free(shape.line[0].point);
    //assert(prevCmd == mapserver::path_cmd_line_to);
    //delete lines;
-   return shape;
+   return MS_SUCCESS;
 }
 
 

Modified: sandbox/mapserver6/maprendering.c
===================================================================
--- sandbox/mapserver6/maprendering.c	2010-06-25 20:22:33 UTC (rev 10254)
+++ sandbox/mapserver6/maprendering.c	2010-06-28 09:24:56 UTC (rev 10255)
@@ -514,7 +514,7 @@
          rendererVTableObj *renderer = image->format->vtable;
          shapeObj *offsetPolygon = NULL;
          symbolObj *symbol = symbolset->symbol[style->symbol];
-
+         int ret = MS_SUCCESS;
          /* store a reference to the renderer to be used for freeing */
          if(style->symbol)
             symbol->renderer = renderer;
@@ -531,7 +531,8 @@
           * also draws an optional outline */
          if(style->symbol == 0 || symbol->type == MS_SYMBOL_SIMPLE) {
             style->color.alpha = MS_NINT(style->opacity*2.55);
-            renderer->renderPolygon(image,offsetPolygon,&style->color);
+            ret = renderer->renderPolygon(image,offsetPolygon,&style->color);
+            if(ret != MS_SUCCESS) goto cleanup;
             if(MS_VALID_COLOR(style->outlinecolor)) {
                strokeStyleObj s;
                MS_COPYCOLOR(&s.color,&style->outlinecolor);
@@ -539,15 +540,21 @@
                s.width = (style->width == 0)?scalefactor:style->width*scalefactor;
 
                s.color.alpha = style->color.alpha;
-               renderer->renderLine(image,offsetPolygon,&s);
+               ret = renderer->renderLine(image,offsetPolygon,&s);
             }
             goto cleanup; /*finished plain polygon*/
+         } else if(symbol->type == MS_SYMBOL_HATCH){
+            double width = (style->width <= 0)?scalefactor:style->width*scalefactor;
+            style->color.alpha = MS_NINT(style->opacity*2.55);;
+            double spacing = (style->size <= 0)?scalefactor:style->size*scalefactor;
+            ret = msHatchPolygon(image,offsetPolygon,spacing,width,style->angle, &style->color);
          }
          else {
             switch(symbol->type) {
             case MS_SYMBOL_PIXMAP:
                if(MS_SUCCESS != msPreloadImageSymbol(renderer,symbol)) {
-                  return MS_FAILURE;
+                  ret = MS_FAILURE;
+                  goto cleanup;
                }
                break;
             case MS_SYMBOL_TRUETYPE:
@@ -556,21 +563,17 @@
                         symbol->font));
                if(!symbol->full_font_path) {
                   msSetError(MS_MEMERR,"allocation error", "msDrawMArkerSymbol()");
-                  return MS_FAILURE;
+                  ret = MS_FAILURE;
+                  goto cleanup;
                }
                break;
-            case MS_SYMBOL_HATCH:
-            {
-               double width = (style->width <= 0)?scalefactor:style->width*scalefactor;
-               style->color.alpha = MS_NINT(style->opacity*2.55);;
-               double spacing = (style->size <= 0)?scalefactor:style->size*scalefactor;
-               shapeObj *lines = msHatchPolygon(image,offsetPolygon,spacing,width,style->angle);
-               int ret = renderer->renderPolygon(image,lines,&style->color);
-               //msFreeShape(lines);
-               //free(lines);
-               return ret;
+            case MS_SYMBOL_VECTOR:
+               break;
+            default:
+               msSetError(MS_MISCERR,"unsupported symbol type %d", "msDrawShadeSymbol()", style->symbol);
+               ret = MS_FAILURE;
+               goto cleanup;
             }
-            }
             symbolStyleObj s;
             computeSymbolStyle(&s,style,symbol,scalefactor);
             int pw,ph;
@@ -589,14 +592,14 @@
             pw += style->gap;
             ph += style->gap;
             tile = getTile(image,symbol,&s,pw,ph);
-            renderer->renderPolygonTiled(image,offsetPolygon, tile);
+            ret = renderer->renderPolygonTiled(image,offsetPolygon, tile);
          }
 
          cleanup:
-         if (style->offsety == -99) {
+         if (offsetPolygon != p) {
             msFreeShape(offsetPolygon);
          }
-         return MS_SUCCESS;
+         return ret;
       }
       else if( MS_RENDERER_IMAGEMAP(image->format) )
          msDrawShadeSymbolIM(symbolset, image, p, style, scalefactor);

Modified: sandbox/mapserver6/mapserver.h
===================================================================
--- sandbox/mapserver6/mapserver.h	2010-06-25 20:22:33 UTC (rev 10254)
+++ sandbox/mapserver6/mapserver.h	2010-06-28 09:24:56 UTC (rev 10255)
@@ -2100,7 +2100,7 @@
 /*      Prototypes for functions in mapgeomutil.cpp                       */
 /* ==================================================================== */
 MS_DLL_EXPORT shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, double endAngle, int isSlice);
-MS_DLL_EXPORT shapeObj* msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle);
+MS_DLL_EXPORT int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double angle, colorObj *color);
 
 
 



More information about the mapserver-commits mailing list