[mapserver-commits] r13209 - sandbox/tb-labels
svn at osgeo.org
svn at osgeo.org
Wed Mar 7 12:23:57 EST 2012
Author: tbonfort
Date: 2012-03-07 09:23:56 -0800 (Wed, 07 Mar 2012)
New Revision: 13209
Modified:
sandbox/tb-labels/mapdraw.c
sandbox/tb-labels/mapfile.c
sandbox/tb-labels/maplabel.c
Log:
avoid some premature allocations on labelObj->poly
Modified: sandbox/tb-labels/mapdraw.c
===================================================================
--- sandbox/tb-labels/mapdraw.c 2012-03-07 11:52:51 UTC (rev 13208)
+++ sandbox/tb-labels/mapdraw.c 2012-03-07 17:23:56 UTC (rev 13209)
@@ -2792,17 +2792,36 @@
label_buffer = (labelPtr->buffer*image->resolutionfactor);
label_mindistance = (labelPtr->mindistance*image->resolutionfactor);
- /* copy the bounds into the cache's polygon */
- msCopyShape(&(cachePtr->labelpath->bounds), cachePtr->poly);
/* compare against image bounds, rendered labels and markers (sets cachePtr->status), if FORCE=TRUE then skip it */
cachePtr->status = MS_TRUE;
+ assert(cachePtr->poly == NULL);
+ /* use a ref to the bounds as the cache's polygon */
+ cachePtr->poly = &cachePtr->labelpath->bounds;
+
if(!labelPtr->force)
cachePtr->status = msTestLabelCacheCollisions(map,cachePtr,label_mindistance,priority,l);
- msFreeShape(&(cachePtr->labelpath->bounds));
+
- if(!cachePtr->status)
- continue;
+ if(!cachePtr->status) {
+ cachePtr->poly = NULL;
+ msFreeShape(&cachePtr->labelpath->bounds);
+ continue;
+ } else {
+ /* take ownership of cachePtr->poly*/
+ cachePtr->poly = (shapeObj*)msSmallMalloc(sizeof(shapeObj));
+ msInitShape(cachePtr->poly);
+ cachePtr->poly->type = MS_SHAPE_POLYGON;
+ cachePtr->poly->numlines = cachePtr->labelpath->bounds.numlines;
+ cachePtr->poly->line = cachePtr->labelpath->bounds.line;
+ cachePtr->labelpath->bounds.numlines = 0;
+ cachePtr->labelpath->bounds.line = NULL;
+ cachePtr->poly->bounds.minx = cachePtr->labelpath->bounds.bounds.minx;
+ cachePtr->poly->bounds.miny = cachePtr->labelpath->bounds.bounds.miny;
+ cachePtr->poly->bounds.maxx = cachePtr->labelpath->bounds.bounds.maxx;
+ cachePtr->poly->bounds.maxy = cachePtr->labelpath->bounds.bounds.maxy;
+ msFreeShape(&cachePtr->labelpath->bounds);
+ }
msDrawTextLine(image, labelPtr->annotext, labelPtr, cachePtr->labelpath, &(map->fontset), layerPtr->scalefactor); /* Draw the curved label */
@@ -2967,7 +2986,7 @@
if(labelPtr->force == MS_OFF) {
/* check for collisions inside the label group */
- if(cachePtr->poly->numlines && intersectLabelPolygons(&metrics_poly, cachePtr->poly) == MS_TRUE) {
+ if(cachePtr->poly && cachePtr->poly->numlines && intersectLabelPolygons(&metrics_poly, cachePtr->poly) == MS_TRUE) {
/* there was a self intersection */
continue; /* next position, labelPtr->status is left to MS_OFF */
}
@@ -3019,7 +3038,7 @@
} else {
if(labelPtr->force == MS_OFF) {
/* check for collisions inside the label group unless the label is FORCE GROUP */
- if(cachePtr->poly->numlines && intersectLabelPolygons(&metrics_poly, cachePtr->poly) == MS_TRUE) {
+ if(cachePtr->poly && cachePtr->poly->numlines && intersectLabelPolygons(&metrics_poly, cachePtr->poly) == MS_TRUE) {
break; /* collision within the group */
}
}
@@ -3041,6 +3060,10 @@
case we still want to compute the full cachePtr->poly to be used for offset tests */
labelPtr->status = MS_OFF;
} else {
+ if(!cachePtr->poly) {
+ cachePtr->poly = (shapeObj*)msSmallMalloc(sizeof(shapeObj));
+ msInitShape(cachePtr->poly);
+ }
if(labelPtr->annotext) {
msAddLine(cachePtr->poly, metrics_poly.line);
}
@@ -3052,11 +3075,6 @@
}
} /* next label in the group */
- /* add the marker polygon if we have one */
- if(marker_poly.numlines) {
- msAddLine(cachePtr->poly, marker_poly.line);
- }
- msComputeBounds(cachePtr->poly);
/*
* cachePtr->status can be set to ON only if all it's labels didn't collide
@@ -3068,8 +3086,22 @@
break;
}
}
+ if(cachePtr->status == MS_ON || classPtr->leader.maxdistance) {
+ /* add the marker polygon if we have one */
+ if(marker_poly.numlines) {
+ if(!cachePtr->poly) {
+ cachePtr->poly = (shapeObj*)msSmallMalloc(sizeof(shapeObj));
+ msInitShape(cachePtr->poly);
+ }
+ msAddLine(cachePtr->poly, marker_poly.line);
+ }
+ if(cachePtr->poly)
+ msComputeBounds(cachePtr->poly);
+ }
+
if(cachePtr->status == MS_OFF)
continue; /* next label, as we had a collision */
+
if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { /* need to draw a marker */
for(i=0; i<cachePtr->numstyles; i++)
Modified: sandbox/tb-labels/mapfile.c
===================================================================
--- sandbox/tb-labels/mapfile.c 2012-03-07 11:52:51 UTC (rev 13208)
+++ sandbox/tb-labels/mapfile.c 2012-03-07 17:23:56 UTC (rev 13209)
@@ -5441,8 +5441,10 @@
for(j=0;j<cacheslot->labels[i].numlabels; j++) freeLabel(&(cacheslot->labels[i].labels[j]));
msFree(cacheslot->labels[i].labels);
- msFreeShape(cacheslot->labels[i].poly); /* empties the shape */
- msFree(cacheslot->labels[i].poly); /* free's the pointer */
+ if(cacheslot->labels[i].poly) {
+ msFreeShape(cacheslot->labels[i].poly); /* empties the shape */
+ msFree(cacheslot->labels[i].poly); /* free's the pointer */
+ }
for(j=0;j<cacheslot->labels[i].numstyles; j++) freeStyle(&(cacheslot->labels[i].styles[j]));
msFree(cacheslot->labels[i].styles);
Modified: sandbox/tb-labels/maplabel.c
===================================================================
--- sandbox/tb-labels/maplabel.c 2012-03-07 11:52:51 UTC (rev 13208)
+++ sandbox/tb-labels/maplabel.c 2012-03-07 17:23:56 UTC (rev 13209)
@@ -405,8 +405,9 @@
cachePtr->featuresize = featuresize;
- cachePtr->poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
- msInitShape(cachePtr->poly);
+ //cachePtr->poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+ //msInitShape(cachePtr->poly);
+ cachePtr->poly = NULL;
cachePtr->status = MS_FALSE;
@@ -580,12 +581,13 @@
cachePtr->featuresize = featuresize;
- cachePtr->poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
- msInitShape(cachePtr->poly);
+ //cachePtr->poly = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+ //msInitShape(cachePtr->poly);
+ cachePtr->poly = NULL;
cachePtr->status = MS_FALSE;
- if(layerPtr->type == MS_LAYER_POINT) { /* cache the marker placement, it's already on the map */
+ if(layerPtr->type == MS_LAYER_POINT && classPtr->numstyles > 0) { /* cache the marker placement, it's already on the map */
rectObj rect;
double w, h;
@@ -673,7 +675,7 @@
int current_priority, int current_label) {
labelCacheObj *labelcache = &(map->labelcache);
int i, p, ll, pp;
- double label_width;
+ double label_width = 0;
labelCacheMemberObj *curCachePtr=NULL;
/*
More information about the mapserver-commits
mailing list