[QGIS Commit] r11317 - branches/symbology-ng-branch/src/core/pal

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Aug 9 10:21:38 EDT 2009


Author: wonder
Date: 2009-08-09 10:21:38 -0400 (Sun, 09 Aug 2009)
New Revision: 11317

Modified:
   branches/symbology-ng-branch/src/core/pal/costcalculator.cpp
   branches/symbology-ng-branch/src/core/pal/feature.cpp
   branches/symbology-ng-branch/src/core/pal/feature.h
Log:
Penalize small lines/polygons with additional cost for all candidates of the feature part.
This has the effect that larger objects get higher chance of being labeled.


Modified: branches/symbology-ng-branch/src/core/pal/costcalculator.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/costcalculator.cpp	2009-08-09 14:09:05 UTC (rev 11316)
+++ branches/symbology-ng-branch/src/core/pal/costcalculator.cpp	2009-08-09 14:21:38 UTC (rev 11317)
@@ -188,6 +188,9 @@
           setPolygonCandidatesCost( stop, (LabelPosition**) feat->lPos, max_p, obstacles, bbx, bby );
       }
 
+      // add size penalty (small lines/polygons get higher cost)
+      feat->feature->addSizePenalty(max_p, feat->lPos, bbx, bby);
+
       return max_p;
    }
 

Modified: branches/symbology-ng-branch/src/core/pal/feature.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-08-09 14:09:05 UTC (rev 11316)
+++ branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-08-09 14:21:38 UTC (rev 11317)
@@ -1279,7 +1279,45 @@
     return rnbp;
   }
 
+  void FeaturePart::addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4])
+  {
+    int geomType = GEOSGeomTypeId(the_geom);
 
+    double sizeCost = 0;
+    if (geomType == GEOS_LINESTRING)
+    {
+      double length;
+      if (GEOSLength(the_geom, &length) != 1)
+        return; // failed to calculate length
+      double bbox_length = max(bbx[2]-bbx[0], bby[2]-bby[0]);
+      if (length >= bbox_length/4)
+        return; // the line is longer than quarter of height or width - don't penalize it
+
+      sizeCost = 1 - (length / (bbox_length/4)); // < 0,1 >
+    }
+    else if (geomType == GEOS_POLYGON)
+    {
+      double area;
+      if (GEOSArea(the_geom, &area) != 1)
+        return;
+      double bbox_area = (bbx[2]-bbx[0])*(bby[2]-bby[0]);
+      if (area >= bbox_area/16)
+        return; // covers more than 1/16 of our view - don't penalize it
+
+      sizeCost = 1 - (area / (bbox_area/16)); // < 0, 1 >
+    }
+    else
+      return; // no size penalty for points
+
+    std::cout << "size cost " << sizeCost << std::endl;
+
+    // apply the penalty
+    for (int i = 0; i < nbp; i++)
+    {
+      lPos[i]->setCost( lPos[i]->getCost() + sizeCost / 100 );
+    }
+  }
+
   bool FeaturePart::isConnected(FeaturePart* p2)
   {
     return (GEOSTouches(the_geom, p2->the_geom) == 1);

Modified: branches/symbology-ng-branch/src/core/pal/feature.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/feature.h	2009-08-09 14:09:05 UTC (rev 11316)
+++ branches/symbology-ng-branch/src/core/pal/feature.h	2009-08-09 14:21:38 UTC (rev 11317)
@@ -266,6 +266,9 @@
       /** merge other (connected) part with this one and save the result in this part (other is unchanged).
        * Return true on success, false if the feature wasn't modified */
       bool mergeWithFeaturePart(FeaturePart* other);
+
+      void addSizePenalty( int nbp, LabelPosition** lPos, double bbx[4], double bby[4]);
+
   };
 
 } // end namespace pal



More information about the QGIS-commit mailing list