Skip to content

Commit

Permalink
[pal] Remove #ifdef svg debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 29, 2015
1 parent 44724f9 commit 277605b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 267 deletions.
10 changes: 1 addition & 9 deletions src/core/pal/feature.cpp
Expand Up @@ -1322,20 +1322,12 @@ namespace pal

int FeaturePart::setPosition( double scale, LabelPosition ***lPos,
double bbox_min[2], double bbox_max[2],
PointSet *mapShape, RTree<LabelPosition*, double, 2, double> *candidates
#ifdef _EXPORT_MAP_
, std::ofstream &svgmap
#endif
)
PointSet *mapShape, RTree<LabelPosition*, double, 2, double> *candidates )
{
int nbp = 0;
int i;
double bbox[4];

#ifdef _EXPORT_MAP_
int dpi = layer->pal->getDpi();
#endif

bbox[0] = bbox_min[0];
bbox[1] = bbox_min[1];
bbox[2] = bbox_max[0];
Expand Down
34 changes: 15 additions & 19 deletions src/core/pal/feature.h
Expand Up @@ -127,28 +127,28 @@ namespace pal
//FeaturePart** parts;
};

/**
/**
* \brief Main class to handle feature
*/
class CORE_EXPORT FeaturePart : public PointSet
{

public:

/**
/**
* \brief create a new generic feature
*
* \param feat a pointer for a Feat which contains the spatial entites
* \param geom a pointer to a GEOS geometry
*/
FeaturePart( Feature *feat, const GEOSGeometry* geom );

/**
/**
* \brief Delete the feature
*/
virtual ~FeaturePart();

/**
/**
* \brief generate candidates for point feature
* Generate candidates for point features
* \param x x coordinates of the point
Expand All @@ -161,12 +161,12 @@ namespace pal
*/
int setPositionForPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );

/**
/**
* generate one candidate over specified point
*/
int setPositionOverPoint( double x, double y, double scale, LabelPosition ***lPos, double delta_width, double angle );

/**
/**
* \brief generate candidates for line feature
* Generate candidates for line features
* \param scale map scale is 1:scale
Expand All @@ -180,12 +180,12 @@ namespace pal
LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
int orientation, int index, double distance );

/**
/**
* Generate curved candidates for line features
*/
int setPositionForLineCurved( LabelPosition ***lPos, PointSet* mapShape );

/**
/**
* \brief generate candidates for point feature
* Generate candidates for point features
* \param scale map scale is 1:scale
Expand All @@ -196,25 +196,25 @@ namespace pal
*/
int setPositionForPolygon( double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width );

/**
/**
* \brief return the feature
* \return the feature
*/
Feature* getFeature() { return f; }

/**
/**
* \brief return the geometry
* \return the geometry
*/
const GEOSGeometry* getGeometry() const { return the_geom; }

/**
/**
* \brief return the layer that feature belongs to
* \return the layer of the feature
*/
Layer * getLayer();

/**
/**
* \brief generic method to generate candidates
* This method will call either setPositionFromPoint(), setPositionFromLine or setPositionFromPolygon
* \param scale the map scale is 1:scale
Expand All @@ -225,20 +225,16 @@ namespace pal
* \param candidates index for candidates
* \return the number of candidates in *lPos
*/
int setPosition( double scale, LabelPosition ***lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates
#ifdef _EXPORT_MAP_
, std::ofstream &svgmap
#endif
);
int setPosition( double scale, LabelPosition ***lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates );

/**
/**
* \brief get the unique id of the feature
* \return the feature unique identifier
*/
const char *getUID();


/**
/**
* \brief Print feature information
* Print feature unique id, geometry type, points, and holes on screen
*/
Expand Down
46 changes: 0 additions & 46 deletions src/core/pal/geomfunction.cpp
Expand Up @@ -573,52 +573,6 @@ namespace pal
return c;
}

#ifdef _EXPORT_MAP_
void toSVGPath( int nbPoints, int geomType, double *x, double *y,
int dpi, double scale, int xmin, int ymax,
char *layername, char *objectID,
std::ostream &out )
{
int i;

if ( nbPoints > 1 )
{
out << " <path style=\"fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1\" d=\"M " << convert2pt( x[0], scale, dpi ) - xmin << "," << ymax - convert2pt( y[0], scale, dpi ) << " ";
for ( i = 1; i < nbPoints; i++ )
{
out << "L " << convert2pt( x[i], scale, dpi ) - xmin << ", " << ymax - convert2pt( y[i], scale, dpi ) << " ";
}

if ( geomType == GEOS_POLYGON )
{
out << " z ";
}

out << "\" ";
out << "id=\"" << layername << "-" << objectID << "\" ";
out << "inkscape:label=\"#path-" << layername << "-" << objectID << "\"/>\n";
}
else
{
int cx = convert2pt( x[0], scale, dpi ) - xmin;
int cy = ymax - convert2pt( y[0], scale, dpi );
out << " <path ";
out << " sodipodi:type=\"arc\" ";
out << " style=\"opacity:1;fill:#bcbcbc;fill-opacity:l;stroke:#000000;stroke-opacity:1;stroke-width:0.5;stroke-linejoin:miter;stroke-dasharray:none;display:inline\"";
out << " id=\"" << layername << "-" << objectID << "\" ";
out << " sodipodi:cx=\"" << cx << "\" ";
out << " sodipodi:cy=\"" << cy << "\" ";
out << " sodipodi:rx=\"1\" ";
out << " sodipodi:ry=\"1\" ";
out << " d=\"M " << cx + 1 << " " << cy << " A 1 1 0 1 1 "
<< cx - 1 << "," << cy << " A 1 1 0 1 1 "
<< cx + 1 << " " << cy << " z\" ";
out << " inkscape:label=\"#path-" << layername << "-" << objectID << "\" />\n";
}
}
#endif


void findLineCircleIntersection( double cx, double cy, double radius,
double x1, double y1, double x2, double y2,
double& xRes, double& yRes )
Expand Down
25 changes: 0 additions & 25 deletions src/core/pal/geomfunction.h
Expand Up @@ -122,31 +122,6 @@ namespace pal
double x3, double y3, double x4, double y4, // 2nd line segment
double *x, double *y );

#ifdef _EXPORT_MAP_
/**
* \brief generate SVG code for a geometry
*
* @param nbPoints # points in x and y vector
* @param typeID from geos
* @param x x coordinates
* @param y y coordinates
* @param dpi map resolution
* @param scale map scale is 1:scale
* @param xmin minimum x value in mapExtent
* @param ymax maximum y value in mapExtent
* @param layername SVG layer name
* @param objectID SVG ID
* @param out stream to write
*/
void toSVGPath( int nbPoints, int geomType,
double *x, double *y,
int dpi, double scale,
int xmin, int ymax,
char *layername,
char *objectID,
std::ostream &out );
#endif

int reorderPolygon( int nbPoints, double *x, double *y );

} // end namespace
Expand Down
85 changes: 4 additions & 81 deletions src/core/pal/pal.cpp
Expand Up @@ -28,7 +28,6 @@
*/

//#define _VERBOSE_
//#define _EXPORT_MAP_
#include <QTime>

#define _CRT_SECURE_NO_DEPRECATE
Expand Down Expand Up @@ -211,9 +210,6 @@ namespace pal
double priority;
double bbox_min[2];
double bbox_max[2];
#ifdef _EXPORT_MAP_
std::ofstream *svgmap;
#endif
} FeatCallBackCtx;


Expand All @@ -229,12 +225,6 @@ namespace pal

FeatCallBackCtx *context = ( FeatCallBackCtx* ) ctx;

#ifdef _EXPORT_MAP_
bool svged = false; // is the feature has been written into the svg map?
int dpi = context->layer->pal->getDpi();
#endif


#ifdef _DEBUG_FULL_
std::cout << "extract feat : " << ft_ptr->getLayer()->getName() << "/" << ft_ptr->getUID() << std::endl;
#endif
Expand Down Expand Up @@ -276,11 +266,7 @@ namespace pal

// generate candidates for the feature part
LabelPosition** lPos = NULL;
int nblp = ft_ptr->setPosition( context->scale, &lPos, context->bbox_min, context->bbox_max, ft_ptr, context->candidates
#ifdef _EXPORT_MAP_
, *context->svgmap
#endif
);
int nblp = ft_ptr->setPosition( context->scale, &lPos, context->bbox_min, context->bbox_max, ft_ptr, context->candidates );

if ( nblp > 0 )
{
Expand Down Expand Up @@ -335,23 +321,8 @@ namespace pal
return true;
}


/**
* \brief Problem Factory
* Select features from user's choice layers within
* a specific bounding box
* @param nbLayers # wanted layers
* @param layersFactor layers importance
* @param layersName layers in problem
* @param lambda_min west bbox
* @param phi_min south bbox
* @param lambda_max east bbox
* @param phi_max north bbox
* @param scale the scale
*/
Problem* Pal::extract( int nbLayers, char **layersName, double *layersFactor, double lambda_min, double phi_min, double lambda_max, double phi_max, double scale, std::ofstream *svgmap )
Problem* Pal::extract( int nbLayers, char **layersName, double *layersFactor, double lambda_min, double phi_min, double lambda_max, double phi_max, double scale )
{
Q_UNUSED( svgmap );
// to store obstacles
RTree<PointSet*, double, 2, double> *obstacles = new RTree<PointSet*, double, 2, double>();

Expand Down Expand Up @@ -392,10 +363,6 @@ namespace pal
context->bbox_max[0] = amax[0];
context->bbox_max[1] = amax[1];

#ifdef _EXPORT_MAP_
context->svgmap = svgmap;
#endif

#ifdef _VERBOSE_
std::cout << nbLayers << "/" << layers->size() << " layers to extract " << std::endl;
std::cout << "scale is 1:" << scale << std::endl << std::endl;
Expand Down Expand Up @@ -436,20 +403,10 @@ namespace pal
context->priority = layersFactor[i];
// lookup for feature (and generates candidates list)

#ifdef _EXPORT_MAP_
*svgmap << "<g inkscape:label=\"" << layer->name << "\"" << std::endl
<< " inkscape:groupmode=\"layer\"" << std::endl
<< " id=\"" << layer->name << "\">" << std::endl << std::endl;
#endif

context->layer->mMutex.lock();
context->layer->rtree->Search( amin, amax, extractFeatCallback, ( void* ) context );
context->layer->mMutex.unlock();

#ifdef _EXPORT_MAP_
*svgmap << "</g>" << std::endl << std::endl;
#endif

#ifdef _VERBOSE_
std::cout << "Layer's name: " << layer->getName() << std::endl;
std::cout << " scale range: " << layer->getMinScale() << "->" << layer->getMaxScale() << std::endl;
Expand Down Expand Up @@ -708,35 +665,12 @@ namespace pal
std::cout << std::endl << "bbox: " << bbox[0] << " " << bbox[1] << " " << bbox[2] << " " << bbox[3] << std::endl;
#endif

#ifdef _EXPORT_MAP_
// TODO this is not secure
std::ofstream svgmap( "pal-map.svg" );

svgmap << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl
<< "<svg" << std::endl
<< "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" << std::endl
<< "xmlns:cc=\"http://creativecommons.org/ns#\"" << std::endl
<< "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" << std::endl
<< "xmlns:svg=\"http://www.w3.org/2000/svg\"" << std::endl
<< "xmlns=\"http://www.w3.org/2000/svg\"" << std::endl
<< "xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"" << std::endl
<< "xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"" << std::endl
<< "width=\"" << convert2pt( bbox[2] - bbox[0], scale, dpi ) << "\"" << std::endl
<< "height=\"" << convert2pt( bbox[3] - bbox[1], scale, dpi ) << "\">" << std::endl; // TODO xmax ymax
#endif

QTime t;
t.start();

// First, extract the problem
// TODO which is the minimum scale? (> 0, >= 0, >= 1, >1 )
if ( scale < 1 || ( prob = extract( nbLayers, layersName, layersFactor, bbox[0], bbox[1], bbox[2], bbox[3], scale,
#ifdef _EXPORT_MAP_
& svgmap
#else
NULL
#endif
) ) == NULL )
if ( scale < 1 || ( prob = extract( nbLayers, layersName, layersFactor, bbox[0], bbox[1], bbox[2], bbox[3], scale ) ) == NULL )
{

#ifdef _VERBOSE_
Expand All @@ -746,11 +680,6 @@ namespace pal
std::cout << "empty problem... finishing" << std::endl;
#endif

#ifdef _EXPORT_MAP_
svgmap << "</svg>" << std::endl;
svgmap.close();
#endif

// nothing to be done => return an empty result set
if ( stats )
( *stats ) = new PalStat();
Expand Down Expand Up @@ -799,12 +728,6 @@ namespace pal
if ( stats )
*stats = prob->getStats();

#ifdef _EXPORT_MAP_
prob->drawLabels( svgmap );
svgmap << "</svg>" << std::endl;
svgmap.close();
#endif

#ifdef _VERBOSE_
clock_t total_time = clock() - start;
std::cout << " Total time: " << double( total_time ) / double( CLOCKS_PER_SEC ) << std::endl;
Expand Down Expand Up @@ -847,7 +770,7 @@ namespace pal
}
mMutex.unlock();

Problem* prob = extract( nbLayers, layersName, priorities, bbox[0], bbox[1], bbox[2], bbox[3], scale, NULL );
Problem* prob = extract( nbLayers, layersName, priorities, bbox[0], bbox[1], bbox[2], bbox[3], scale );

delete[] layersName;
delete[] priorities;
Expand Down

0 comments on commit 277605b

Please sign in to comment.