Skip to content
Permalink
Browse files

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.


git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11317 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Aug 9, 2009
1 parent fba9efc commit 5bde13b3f1065e5605fa75706906df75179418d1
Showing with 44 additions and 0 deletions.
  1. +3 −0 src/core/pal/costcalculator.cpp
  2. +38 −0 src/core/pal/feature.cpp
  3. +3 −0 src/core/pal/feature.h
@@ -188,6 +188,9 @@ namespace pal
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;
}

@@ -1279,6 +1279,44 @@ void FeaturePart::removeDuplicatePoints()
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)
{
@@ -266,6 +266,9 @@ namespace pal
/** 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

0 comments on commit 5bde13b

Please sign in to comment.
You can’t perform that action at this time.