Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debugs into problem.cpp #1

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ Thumb.db
Testing/*
.cache/
compile_commands.json

cmake-build-debug/
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ set(CMAKE_LINK_DEPENDS_NO_SHARED ON)
#############################################################
# Project and version
set(CPACK_PACKAGE_VERSION_MAJOR "3")
set(CPACK_PACKAGE_VERSION_MINOR "27")
set(CPACK_PACKAGE_VERSION_MINOR "28")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(COMPLETE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(RELEASE_NAME "Master")
set(RELEASE_NAME "Firenze")
project(qgis VERSION ${COMPLETE_VERSION})

if (APPLE)
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ For the QGIS build you need to install following packages from cygwin:

and from OSGeo4W (select *Advanced Install*):

* qgis-dev-deps
* qgis-ltr-deps

* This will also select packages the above packages depend on.

Expand Down
10 changes: 8 additions & 2 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
qgis (3.27.0) UNRELEASED; urgency=medium
qgis (3.28.0) UNRELEASED; urgency=medium

* Release of 3.28.0

-- Jürgen E. Fischer <[email protected]> Fri, 21 Oct 2022 14:11:09 +0200

qgis (3.27.0) unstable; urgency=medium

* New development version 3.27 after branch of 3.26

-- Jürgen E. Fischer <[email protected]> Fri, 17 Jun 2022 14:08:27 +0200
-- Jürgen E. Fischer <[email protected]> Fri, 21 Oct 2022 14:11:09 +0200

qgis (3.26.0) unstable; urgency=medium

Expand Down
Binary file modified images/splash/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 70 additions & 8 deletions src/core/pal/costcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "layer.h"
#include <json.hpp>
#include "pal.h"
#include "feature.h"
#include "geomfunction.h"
Expand All @@ -27,19 +28,31 @@ using namespace pal;

bool CostCalculator::candidateSortGrow( const std::unique_ptr< LabelPosition > &c1, const std::unique_ptr< LabelPosition > &c2 )
{
// literally just a comparison function used for sorting
// printf("CandidateSortGrow \n");

// nlohmann::json debug = {
// {"c1", c1->cost()},
// {"c2", c2->cost()},
// };
// std::cout << debug << std::endl;
return c1->cost() < c2->cost();
}

void CostCalculator::addObstacleCostPenalty( LabelPosition *lp, FeaturePart *obstacle, Pal *pal )
{
printf("==================addObstacleCostPenalty \n");
int n = 0;
double dist;
const double distlabel = lp->feature->getLabelDistance();

printf("CostCalculator::addObstacleCostPenalty lp->getId() == %d, obstacle->featureId=%lld",
lp->getId(), obstacle->featureId());

switch ( obstacle->getGeosType() )
{
case GEOS_POINT:

printf("case GEOS_POINT \n");
dist = lp->getDistanceToPoint( obstacle->x[0], obstacle->y[0] );
if ( dist < 0 )
n = 2;
Expand All @@ -52,12 +65,13 @@ void CostCalculator::addObstacleCostPenalty( LabelPosition *lp, FeaturePart *obs
break;

case GEOS_LINESTRING:

printf("case GEOS_LINESTRING \n");
// Is one of label's borders crossing the line ?
n = ( lp->crossesLine( obstacle ) ? 1 : 0 );
break;

case GEOS_POLYGON:
printf("case GEOS_POLYGON \n");
// behavior depends on obstacle avoid type
switch ( obstacle->layer()->obstacleType() )
{
Expand Down Expand Up @@ -95,22 +109,26 @@ void CostCalculator::addObstacleCostPenalty( LabelPosition *lp, FeaturePart *obs
const double obstaclePriority = obstacle->obstacleSettings().factor();

// if feature priority is < obstaclePriorty, there's a hard conflict...
printf(" check priority n=%d, priority=%lf, obstaclePriority=%lf\n", n, priority, obstaclePriority);
if ( n > 0 && ( priority < obstaclePriority && !qgsDoubleNear( priority, obstaclePriority, 0.001 ) ) )
{
printf(" setHasHardObstacleConflict true\n");
lp->setHasHardObstacleConflict( true );
}
break;
}
}

// label cost is penalized
printf("addObstacleCost %d, %lf\n", lp->getId(), obstacleCost);
lp->setCost( lp->cost() + obstacleCost );
}

//internal function
void CostCalculator::calculateCandidatePolygonRingDistanceCosts( std::vector< std::unique_ptr< LabelPosition > > &lPos, double bbx[4], double bby[4] )
{
// first we calculate the ring distance cost for all candidates for this feature. We then use the range
// of distance costs to calculate a standardised scaling for the costs
printf("====================calculateCandidatePolygonRingDistanceCosts \n");
QHash< LabelPosition *, double > polygonRingDistances;
double minCandidateRingDistance = std::numeric_limits< double >::max();
double maxCandidateRingDistance = std::numeric_limits< double >::lowest();
Expand Down Expand Up @@ -139,9 +157,10 @@ void CostCalculator::calculateCandidatePolygonRingDistanceCosts( std::vector< st
pos->setCost( pos->cost() + 0.002 - ( polygonRingDistanceCost - minCandidateRingDistance ) * normalizer );
}
}

//internal function
void CostCalculator::calculateCandidatePolygonCentroidDistanceCosts( pal::FeaturePart *feature, std::vector<std::unique_ptr<LabelPosition> > &lPos )
{
printf("=======================calculateCandidatePolygonCentroidDistanceCosts \n");
double cx, cy;
feature->getCentroid( cx, cy );

Expand Down Expand Up @@ -179,9 +198,10 @@ void CostCalculator::calculateCandidatePolygonCentroidDistanceCosts( pal::Featur
pos->setCost( pos->cost() + ( polygonCentroidDistance - minCandidateCentroidDistance ) * normalizer );
}
}

//internal function
double CostCalculator::calculatePolygonRingDistance( LabelPosition *candidate, double bbx[4], double bby[4] )
{
printf("=====================calculatePolygonRingDistance \n");
// TODO 1: Consider whether distance calculation should use min distance to the candidate rectangle
// instead of just the center
CandidatePolygonRingDistanceCalculator ringDistanceCalculator( candidate );
Expand All @@ -207,11 +227,39 @@ double CostCalculator::calculatePolygonRingDistance( LabelPosition *candidate, d
return ringDistanceCalculator.minimumDistance();
}

void printCandidates(Feats *feat) {
std::size_t count = 0;
for( count = 0; count < feat->candidates.size(); count++) {
nlohmann::json candidateJson = {
{"id", feat->candidates[count]->getId()},
{"cost", feat->candidates[count]->cost()},
//{"geometry", feat->candidates[count]->feature},
};
std::cout << "candidate" << candidateJson << std::endl;
//std::cout << "id: " << feat->candidates[count]->getId() <<" candidate cost " << feat->candidates[count]->cost() << std::endl;
}
}

void CostCalculator::finalizeCandidatesCosts( Feats *feat, double bbx[4], double bby[4] )
{
printf("=============================finalizeCandidatesCosts %lld\n", feat->feature->featureId());
printf("feat priority = %f \n", feat->priority);
std::cout << "feature geos type = " << feat->feature->getGeosType() << std::endl;
printf("bbx = %f %f %f %f and bby= %f %f %f %f \n",bbx[0], bbx[1], bbx[2], bbx[3], bby[0], bby[1], bby[2], bby[3]);

nlohmann::json debug = {
{"candidate Sizes", feat->candidates.size()},
{"feature type", feat->feature->getGeosType()},
{"feature length", feat->feature->length()},
{"feature area", feat->feature->area()},
{"Arrangement", feat->feature->layer()->arrangement()},
};
std::cout << "Feature details " << debug << std::endl;

// sort candidates list, best label to worst
std::sort( feat->candidates.begin(), feat->candidates.end(), candidateSortGrow );

printCandidates(feat);

// Original nonsense comment from pal library:
// "try to exclude all conflitual labels (good ones have cost < 1 by pruning)"
// my interpretation: it appears this scans through the candidates and chooses some threshold
Expand All @@ -228,24 +276,33 @@ void CostCalculator::finalizeCandidatesCosts( Feats *feat, double bbx[4], double
;
}
while ( stop == 0 && discrim < feat->candidates.back()->cost() + 2.0 );

printf("discrim = %f \n", discrim);
// THIS LOOKS SUSPICIOUS -- it clamps all costs to a fixed value??
if ( discrim > 1.5 )
{
for ( std::size_t k = 0; k < stop; k++ )
feat->candidates[ k ]->setCost( 0.0021 );
}

printf("stop = %lu and size = %lu\n", stop, feat->candidates.size());
printf("After Discrim \n");
printCandidates(feat);

if ( feat->candidates.size() > stop )
{
feat->candidates.resize( stop );
feat->candidates.resize( stop );
}

printf("After resize \n");
printCandidates(feat);

// Sets costs for candidates of polygon

if ( feat->feature->getGeosType() == GEOS_POLYGON )
{
printf("Special polygon functionality \n");
const Qgis::LabelPlacement arrangement = feat->feature->layer()->arrangement();
//printf("arrangement = %d \n", arrangement);
if ( arrangement == Qgis::LabelPlacement::Free || arrangement == Qgis::LabelPlacement::Horizontal )
{
// prefer positions closer to the pole of inaccessibilities
Expand All @@ -257,16 +314,20 @@ void CostCalculator::finalizeCandidatesCosts( Feats *feat, double bbx[4], double

// add size penalty (small lines/polygons get higher cost)
feat->feature->addSizePenalty( feat->candidates, bbx, bby );
printf("after penalty \n");
printCandidates(feat);
}

CandidatePolygonRingDistanceCalculator::CandidatePolygonRingDistanceCalculator( LabelPosition *candidate )
: mPx( ( candidate->x[0] + candidate->x[2] ) / 2.0 )
, mPy( ( candidate->y[0] + candidate->y[2] ) / 2.0 )
{
printf("====================CandidatePolygonRingDistanceCalculator \n");
}

void CandidatePolygonRingDistanceCalculator::addRing( const pal::PointSet *ring )
{
printf("==================addRing \n");
const double d = ring->minDistanceToPoint( mPx, mPy );
if ( d < mMinDistance )
{
Expand All @@ -276,5 +337,6 @@ void CandidatePolygonRingDistanceCalculator::addRing( const pal::PointSet *ring

double CandidatePolygonRingDistanceCalculator::minimumDistance() const
{
printf("=======================minimumDistance \n");
return mMinDistance;
}
20 changes: 20 additions & 0 deletions src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,9 @@ std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments( std::vec
std::vector< double > &x = line->x;
std::vector< double > &y = line->y;

printf("createCandidatesAlongLineNearStraightSegments %lf,%lf -> %lf,%lf\n", x[0], y[0], x[nbPoints-1], y[nbPoints-1]);


// closed line? if so, we need to handle the final node angle
bool closedLine = qgsDoubleNear( x[0], x[ numberNodes - 1] ) && qgsDoubleNear( y[0], y[numberNodes - 1 ] );
for ( int i = 1; i <= numberNodes - ( closedLine ? 1 : 2 ); ++i )
Expand Down Expand Up @@ -946,10 +949,12 @@ std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments( std::vec
const std::size_t candidateTargetCount = maximumLineCandidates();
double lineStepDistance = ( totalLineLength - labelWidth ); // distance to move along line with each candidate
lineStepDistance = std::min( std::min( labelHeight, labelWidth ), lineStepDistance / candidateTargetCount );
printf(" lineStepDistance=%lf, totalLineLength=%lf\n", lineStepDistance, totalLineLength);

double distanceToEndOfSegment = 0.0;
int lastNodeInSegment = 0;
// finally, loop through all these straight segments. For each we create candidates along the straight segment.
printf(" straightSegmentLengths.count=%d\n", straightSegmentLengths.count());
for ( int i = 0; i < straightSegmentLengths.count(); ++i )
{
currentStraightSegmentLength = straightSegmentLengths.at( i );
Expand All @@ -964,6 +969,8 @@ std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments( std::vec
continue;

double currentDistanceAlongLine = distanceToStartOfSegment;
printf(" placing currentDistanceAlongLine = %lf\n", currentDistanceAlongLine);

double candidateStartX, candidateStartY, candidateEndX, candidateEndY;
double candidateLength = 0.0;
double cost = 0.0;
Expand Down Expand Up @@ -1100,6 +1107,10 @@ std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments( std::vec
}
}

printf(" returns %ld\n", lPos.size());
for ( std::unique_ptr< LabelPosition > &lp : lPos ) {
printf(" %d: %lf,%lf,%lf,%lf,%lf\n", lp->getId(), lp->getX(), lp->getY(), lp->getWidth(), lp->getHeight(), lp->getAlpha());
}
return lPos.size();
}

Expand All @@ -1122,6 +1133,8 @@ std::size_t FeaturePart::createCandidatesAlongLineNearMidpoint( std::vector< std
std::vector< double > &x = line->x;
std::vector< double > &y = line->y;

printf("createCandidatesAlongLineNearMidpoint %lf,%lf -> %lf,%lf\n", x[0], y[0], x[nbPoints-1], y[nbPoints-1]);

std::vector< double > segmentLengths( nbPoints - 1 ); // segments lengths distance bw pt[i] && pt[i+1]
std::vector< double >distanceToSegment( nbPoints ); // absolute distance bw pt[0] and pt[i] along the line

Expand All @@ -1139,6 +1152,8 @@ std::size_t FeaturePart::createCandidatesAlongLineNearMidpoint( std::vector< std
distanceToSegment[line->nbPoints - 1] = totalLineLength;

double lineStepDistance = ( totalLineLength - labelWidth ); // distance to move along line with each candidate
printf(" lineStepDistance=%lf\n", lineStepDistance);

double currentDistanceAlongLine = 0;

const QgsLabelLineSettings::AnchorTextPoint textPoint = mLF->lineAnchorTextPoint();
Expand Down Expand Up @@ -1306,6 +1321,11 @@ std::size_t FeaturePart::createCandidatesAlongLineNearMidpoint( std::vector< std
break;
}

printf(" returns %ld\n", lPos.size());
for ( std::unique_ptr< LabelPosition > &lp : lPos ) {
printf(" %d: %lf,%lf,%lf,%lf,%lf\n", lp->getId(), lp->getX(), lp->getY(), lp->getWidth(), lp->getHeight(), lp->getAlpha());
}

return lPos.size();
}

Expand Down
Loading