[QGIS Commit] r10266 - in branches/vector_overlay_branch/src: core
core/pal plugins/interpolation
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Mar 9 06:29:24 EDT 2009
Author: mhugent
Date: 2009-03-09 06:29:23 -0400 (Mon, 09 Mar 2009)
New Revision: 10266
Modified:
branches/vector_overlay_branch/src/core/pal/feature.cpp
branches/vector_overlay_branch/src/core/pal/feature.h
branches/vector_overlay_branch/src/core/pal/geomfunction.cpp
branches/vector_overlay_branch/src/core/pal/labelposition.cpp
branches/vector_overlay_branch/src/core/pal/layer.cpp
branches/vector_overlay_branch/src/core/pal/layer.h
branches/vector_overlay_branch/src/core/pal/pal.cpp
branches/vector_overlay_branch/src/core/pal/pal.h
branches/vector_overlay_branch/src/core/pal/palgeometry.h
branches/vector_overlay_branch/src/core/pal/pointset.h
branches/vector_overlay_branch/src/core/pal/problem.cpp
branches/vector_overlay_branch/src/core/pal/util.cpp
branches/vector_overlay_branch/src/core/pal/util.h
branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.cpp
branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.h
branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp
branches/vector_overlay_branch/src/core/qgsoverlayobjectpositionmanager.h
branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp
branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h
branches/vector_overlay_branch/src/plugins/interpolation/qgsinterpolator.cpp
branches/vector_overlay_branch/src/plugins/interpolation/qgstininterpolator.cpp
Log:
Update of the pal classes
Modified: branches/vector_overlay_branch/src/core/pal/feature.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/feature.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/feature.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -139,7 +139,7 @@
return uid;
}
- int Feature::setPositionForPoint (double x, double y, double scale, LabelPosition ***lPos) {
+ int Feature::setPositionForPoint (double x, double y, double scale, LabelPosition ***lPos, double delta_width) {
#ifdef _DEBUG_
std::cout << "SetPosition (point) : " << layer->name << "/" << uid << std::endl;
@@ -151,14 +151,16 @@
double xrm;
double yrm;
- if (layer->label_unit == PIXEL) {
- xrm = px2meters (label_x, dpi, scale);
- yrm = px2meters (label_y, dpi, scale);
- } else {
- xrm = label_x;
- yrm = label_y;
- }
+ xrm = unit_convert(label_x,
+ layer->label_unit,
+ layer->pal->map_unit,
+ dpi, scale, delta_width);
+ yrm = unit_convert(label_y,
+ layer->label_unit,
+ layer->pal->map_unit,
+ dpi, scale, delta_width);
+
int nbp = layer->pal->point_p;
//std::cout << "Nbp : " << nbp << std::endl;
@@ -174,7 +176,10 @@
//if (nbp==2)
// beta = M_PI/2;
- double distlabel = px2meters (double (this->distlabel), layer->pal->dpi, scale);
+ double distlabel = unit_convert(this->distlabel,
+ pal::PIXEL,
+ layer->pal->map_unit,
+ dpi, scale, delta_width);
double lx, ly; /* label pos */
@@ -274,22 +279,31 @@
}
// TODO work with squared distance by remonving call to sqrt or dist_euc2d
- int Feature::setPositionForLine (double scale, LabelPosition ***lPos, PointSet *mapShape) {
+ int Feature::setPositionForLine (double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width) {
#ifdef _DEBUG_
std::cout << "SetPosition (line) : " << layer->name << "/" << uid << std::endl;
#endif
int i;
int dpi = layer->pal->dpi;
double xrm, yrm;
- if (layer->label_unit == PIXEL) {
- xrm = px2meters (label_x, dpi, scale);
- yrm = px2meters (label_y, dpi, scale);
- } else {
- xrm = label_x;
- yrm = label_y;
- }
- double distlabel = px2meters (double (this->distlabel), layer->pal->dpi, scale);
+ xrm = unit_convert(label_x,
+ layer->label_unit,
+ layer->pal->map_unit,
+ dpi, scale, delta_width);
+
+ yrm = unit_convert(label_y,
+ layer->label_unit,
+ layer->pal->map_unit,
+ dpi, scale, delta_width);
+
+
+ double distlabel = unit_convert(this->distlabel,
+ pal::PIXEL,
+ layer->pal->map_unit,
+ dpi, scale, delta_width);
+
+
double *d; // segments lengths distance bw pt[i] && pt[i+1]
double *ad; // absolute distance bw pt[0] and pt[i] along the line
double ll; // line length
@@ -311,7 +325,7 @@
PointSet * line = mapShape;
#ifdef _DEBUG_FULL_
- std::cout << "New line of " << line->nbPoints << " points" << std::endl;
+ std::cout << "New line of " << line->nbPoints << " points with label " << xrm << "x" << yrm << std::endl;
#endif
nbPoints = line->nbPoints;
@@ -447,7 +461,7 @@
*
*/
- int Feature::setPositionForPolygon (double scale, LabelPosition ***lPos, PointSet *mapShape) {
+ int Feature::setPositionForPolygon (double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width) {
#ifdef _DEBUG_
std::cout << "SetPosition (polygon) : " << layer->name << "/" << uid << std::endl;
@@ -459,14 +473,16 @@
double xrm;
double yrm;
- if (layer->label_unit == PIXEL) {
- xrm = px2meters (label_x, layer->pal->dpi, scale);
- yrm = px2meters (label_y, layer->pal->dpi, scale);
- } else {
- xrm = label_x;
- yrm = label_y;
- }
+ xrm = unit_convert(label_x,
+ layer->label_unit,
+ layer->pal->map_unit,
+ layer->pal->dpi, scale, delta_width);
+ yrm = unit_convert(label_y,
+ layer->label_unit,
+ layer->pal->map_unit,
+ layer->pal->dpi, scale, delta_width);
+
//print();
//LinkedList<PointSet*> *shapes_toCut;
@@ -687,20 +703,23 @@
bbox[1] = bbox_min[1];
bbox[2] = bbox_max[0];
bbox[3] = bbox_max[1];
+
+ double delta = bbox_max[0] - bbox_min[0];
+
switch (type) {
case GEOS_POINT:
fetchCoordinates ();
- nbp = setPositionForPoint (x[0], y[0], scale, lPos);
+ nbp = setPositionForPoint (x[0], y[0], scale, lPos, delta);
#ifdef _EXPORT_MAP_
toSVGPath (nbPoints, type, x, y, dpi , scale,
- convert (bbox_min[0], scale, dpi),
- convert (bbox_max[1], scale, dpi),
+ convert2pt (bbox_min[0], scale, dpi),
+ convert2pt (bbox_max[1], scale, dpi),
layer->name, uid, svgmap);
#endif
releaseCoordinates();
break;
case GEOS_LINESTRING:
- nbp = setPositionForLine (scale, lPos, mapShape);
+ nbp = setPositionForLine (scale, lPos, mapShape, delta);
break;
case GEOS_POLYGON:
@@ -708,14 +727,14 @@
case P_POINT:
double cx, cy;
mapShape->getCentroid (cx, cy);
- nbp = setPositionForPoint (cx, cy, scale, lPos);
+ nbp = setPositionForPoint (cx, cy, scale, lPos, delta);
break;
case P_LINE:
case P_LINE_AROUND:
- nbp = setPositionForLine (scale, lPos, mapShape);
+ nbp = setPositionForLine (scale, lPos, mapShape, delta);
break;
default:
- nbp = setPositionForPolygon (scale, lPos, mapShape);
+ nbp = setPositionForPolygon (scale, lPos, mapShape, delta);
break;
}
}
Modified: branches/vector_overlay_branch/src/core/pal/feature.h
===================================================================
--- branches/vector_overlay_branch/src/core/pal/feature.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/feature.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -103,7 +103,7 @@
* \param lPos pointer to an array of candidates, will be filled by generated candidates
* \return the number of generated cadidates
*/
- int setPositionForPoint (double x, double y, double scale, LabelPosition ***lPos);
+ int setPositionForPoint (double x, double y, double scale, LabelPosition ***lPos, double delta_width);
/**
* \brief generate candidates for line feature
@@ -113,7 +113,7 @@
* \param mapShape a pointer to the line
* \return the number of generated cadidates
*/
- int setPositionForLine (double scale, LabelPosition ***lPos, PointSet *mapShape);
+ int setPositionForLine (double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width);
/**
* \brief generate candidates for point feature
@@ -123,7 +123,7 @@
* \param mapShape a pointer to the polygon
* \return the number of generated cadidates
*/
- int setPositionForPolygon (double scale, LabelPosition ***lPos, PointSet *mapShape);
+ int setPositionForPolygon (double scale, LabelPosition ***lPos, PointSet *mapShape, double delta_width);
Modified: branches/vector_overlay_branch/src/core/pal/geomfunction.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/geomfunction.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/geomfunction.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -522,9 +522,9 @@
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 " << convert (x[0], scale, dpi) - xmin << "," << ymax - convert (y[0], scale, dpi) << " ";
+ 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 " << convert (x[i], scale, dpi) - xmin << ", " << ymax - convert (y[i], scale, dpi) << " ";
+ out << "L " << convert2pt (x[i], scale, dpi) - xmin << ", " << ymax - convert2pt (y[i], scale, dpi) << " ";
}
if (geomType == GEOS_POLYGON) {
@@ -535,8 +535,8 @@
out << "id=\"" << layername << "-" << objectID << "\" ";
out << "inkscape:label=\"#path-" << layername << "-" << objectID << "\"/>\n";
} else {
- int cx = convert (x[0], scale, dpi) - xmin;
- int cy = ymax - convert (y[0], scale, dpi);
+ 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\"";
Modified: branches/vector_overlay_branch/src/core/pal/labelposition.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/labelposition.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/labelposition.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -250,10 +250,8 @@
bool obstacleCallback (PointSet *feat, void *ctx) {
-
LabelPosition::PolygonCostCalculator *pCost = (LabelPosition::PolygonCostCalculator*) ctx;
-
LabelPosition *lp = pCost->getLabel();
if ( (feat == lp->feature) || (feat->holeOf && feat->holeOf != lp->feature)) {
return true;
@@ -261,8 +259,6 @@
// if the feature is not a hole we have to fetch corrdinates
// otherwise holes coordinates are still in memory (feature->selfObs)
- // If the feature is not a hole, we have to fetch its coordinates
- // Otherwise the feat is ahole of this polygone, oordinates have already been fetched
if (feat->holeOf == NULL) {
( (Feature*) feat)->fetchCoordinates();
}
@@ -293,7 +289,6 @@
feature->fetchCoordinates();
pCost->update(feature);
- // TODO Make a constructor
PointSet *extent = new PointSet(4, bbx, bby);
pCost->update(extent);
@@ -301,18 +296,18 @@
delete extent;
// TODO Comment
- if (cost > (w*w + h*h) / 4.0) {
+ /*if (cost > (w*w + h*h) / 4.0) {
double dist = sqrt (cost);
amin[0] = (x[0] + x[2]) / 2.0 - dist;
amin[1] = (y[0] + y[2]) / 2.0 - dist;
amax[0] = amin[0] + 2 * dist;
amax[1] = amin[1] + 2 * dist;
- } else {
+ } else {*/
amin[0] = feature->xmin;
amin[1] = feature->ymin;
amax[0] = feature->xmax;
amax[1] = feature->ymax;
- }
+ //}
//std::cout << amin[0] << " " << amin[1] << " " << amax[0] << " " << amax[1] << std::endl;
obstacles->Search (amin, amax, obstacleCallback, pCost);
Modified: branches/vector_overlay_branch/src/core/pal/layer.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/layer.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/layer.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -491,7 +491,7 @@
}
void Layer::setLabelUnit (Units label_unit) {
- if (label_unit == PIXEL || label_unit == METERS)
+ if (label_unit == PIXEL || label_unit == METER)
this->label_unit = label_unit;
}
Modified: branches/vector_overlay_branch/src/core/pal/layer.h
===================================================================
--- branches/vector_overlay_branch/src/core/pal/layer.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/layer.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -174,6 +174,7 @@
/**
* \brief set unit for label size
+ *
*/
void setLabelUnit (Units label_unit);
Modified: branches/vector_overlay_branch/src/core/pal/pal.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/pal.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/pal.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -62,8 +62,9 @@
typedef struct {
//LabelPosition *lp;
+ double scale;
+ Pal* pal;
PointSet *obstacle;
- double scale;
} PruneCtx;
void geosError (const char *fmt, ...) {
@@ -78,12 +79,9 @@
vfprintf (stdout, fmt, list);
}
-
-
-
Pal::Pal() {
+ initGEOS (geosNotice, geosError);
- initGEOS (geosNotice, geosError);
layers = new std::list<Layer*>();
lyrsMutex = new SimpleMutex();
@@ -106,6 +104,8 @@
line_p = 8;
poly_p = 8;
+ this->map_unit = pal::METER;
+
std::cout.precision (12);
std::cerr.precision (12);
@@ -303,8 +303,8 @@
if (!svged) {
toSVGPath (shape->nbPoints, shape->type, shape->x, shape->y,
dpi , context->scale,
- convert (context->bbox_min[0], context->scale, dpi),
- convert (context->bbox_max[1], context->scale, dpi),
+ convert2pt (context->bbox_min[0], context->scale, dpi),
+ convert2pt (context->bbox_max[1], context->scale, dpi),
context->layer->name, ft_ptr->uid, *context->svgmap);
}
#endif
@@ -322,6 +322,9 @@
while (feats->size() > 0) {
Feats *ft = feats->pop_front();
+#ifdef _DEBUG_
+ std::cout << "Compute candidates for feat " << ft->feature->layer->name << "/" << ft->feature->uid << std::endl;
+#endif
ft->nblp = ft->feature->setPosition (context->scale, & (ft->lPos), context->bbox_min, context->bbox_max, ft->shape, context->candidates
#ifdef _EXPORT_MAP_
, *context->svgmap
@@ -335,9 +338,12 @@
// valid features are added to fFeats
ft->priority = context->priority;
context->fFeats->push_back (ft);
+#ifdef _DEBUG_
+ std::cout << ft->nblp << " labelPositions for feature : " << ft->feature->layer->name << "/" << ft->feature->uid << std::endl;
+#endif
} else {
// Others are deleted
-#ifndef _VERBOSE_
+#ifdef _VERBOSE_
std::cout << "Unable to generate labelPosition for feature : " << ft->feature->layer->name << "/" << ft->feature->uid << std::endl;
#endif
delete[] ft->lPos;
@@ -410,6 +416,7 @@
PointSet *feat = ( (PruneCtx*) ctx)->obstacle;
double scale = ( (PruneCtx*) ctx)->scale;
+ Pal* pal = ( (PruneCtx*) ctx)->pal;
if ( (feat == lp->feature) || (feat->holeOf && feat->holeOf != lp->feature)) {
return true;
@@ -426,9 +433,14 @@
//((Feature*)feat)->fetchCoordinates();
double dist;
- double distlabel = px2meters (double (lp->feature->distlabel), lp->feature->layer->pal->dpi, scale);
+ double distlabel = unit_convert(double(lp->feature->distlabel),
+ pal::PIXEL,
+ pal->map_unit,
+ pal->dpi, scale, 1);
+
+
switch (feat->type) {
//case geos::geom::GEOS_POINT:
case GEOS_POINT:
@@ -528,12 +540,14 @@
typedef struct _filterContext {
RTree<LabelPosition*, double, 2, double> *cdtsIndex;
double scale;
+ Pal* pal;
} FilterContext;
bool filteringCallback (PointSet *pset, void *ctx) {
RTree<LabelPosition*, double, 2, double> *cdtsIndex = ( (FilterContext*) ctx)->cdtsIndex;
double scale = ( (FilterContext*) ctx)->scale;
+ Pal* pal = ((FilterContext*)ctx)->pal;
if (pset->holeOf == NULL) {
( (Feature*) pset)->fetchCoordinates();
@@ -552,6 +566,7 @@
pruneContext.scale = scale;
pruneContext.obstacle = pset;
+ pruneContext.pal = pal;
cdtsIndex->Search (amin, amax, pruneLabelPositionCallback, (void*) &pruneContext);
if (pset->holeOf == NULL) {
@@ -727,6 +742,7 @@
FilterContext filterCtx;
filterCtx.cdtsIndex = prob->candidates;
filterCtx.scale = prob->scale;
+ filterCtx.pal = this;
obstacles->Search (amin, amax, filteringCallback, (void*) &filterCtx);
@@ -960,8 +976,8 @@
<< "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=\"" << convert (bbox[2] - bbox[0], scale, dpi) << "\"" << std::endl
- << "height=\"" << convert (bbox[3] - bbox[1], scale, dpi) << "\">" << std::endl; // TODO xmax ymax
+ << "width=\"" << convert2pt (bbox[2] - bbox[0], scale, dpi) << "\"" << std::endl
+ << "height=\"" << convert2pt (bbox[3] - bbox[1], scale, dpi) << "\">" << std::endl; // TODO xmax ymax
#endif
// First, extract the problem
@@ -1153,5 +1169,25 @@
}
}
+
+ /**
+ * \brief get current map unit
+ */
+ Units Pal::getMapUnit(){
+ return map_unit;
+ }
+
+ /**
+ * \brief set map unit
+ */
+ void Pal::setMapUnit(Units map_unit){
+ if (map_unit == pal::PIXEL || map_unit == pal::METER
+ || map_unit == pal::FOOT || map_unit == pal::DEGREE){
+ this->map_unit = map_unit;
+ }
+ }
+
+
+
} // namespace pal
Modified: branches/vector_overlay_branch/src/core/pal/pal.h
===================================================================
--- branches/vector_overlay_branch/src/core/pal/pal.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/pal.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -64,8 +64,10 @@
/** Units for label sizes and distlabel */
enum _Units {
- PIXEL = 0, /**< pixel*/
- METERS = 1 /**< meters [m]*/
+ PIXEL = 0, /**< pixel [px]*/
+ METER, /**< meter [m]*/
+ FOOT, /**< foot [ft]*/
+ DEGREE /**< degree [°] */
};
/** Typedef for _Units enumeration */
@@ -121,6 +123,8 @@
// TODO remove after tests !!!
clock_t tmpTime;
+ Units map_unit;
+
/**
* \brief maximum # candidates for a point
*/
@@ -236,7 +240,6 @@
*/
~Pal();
-
/**
* \brief add a new layer
*
@@ -374,8 +377,17 @@
*/
int getPolyP ();
+ /**
+ * \brief get current map unit
+ */
+ Units getMapUnit();
/**
+ * \brief set map unit
+ */
+ void setMapUnit(Units map_unit);
+
+ /**
* \brief Select the search method to use.
*
* For interactive mapping using CHAIN is a good
Modified: branches/vector_overlay_branch/src/core/pal/palgeometry.h
===================================================================
--- branches/vector_overlay_branch/src/core/pal/palgeometry.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/palgeometry.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -5,23 +5,23 @@
* University of Applied Sciences, Western Switzerland
* http://www.hes-so.ch
*
- * Contact:
+ * Contact:
* maxence.laurent <at> heig-vd <dot> ch
* or
* eric.taillard <at> heig-vd <dot> ch
*
* This file is part of libpal.
- *
+ *
* libpal is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* libpal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with libpal. If not, see <http://www.gnu.org/licenses/>.
*
@@ -34,54 +34,54 @@
#include <pal/label.h>
#include <geos_c.h>
-namespace pal{
+namespace pal {
-/**
- * \brief Interface that allow Pal to acces user's geometries
- */
-class PalGeometry {
-public:
- /*
- * \brief get the geometry in WKB hexa format
- * This method is called by Pal each time it needs a geom's coordinates
- *
- * @return WKB Hex buffer
- */
- //virtual char * getWkbHexBuffer() = 0;
-
- /**
- * \brief get the GEOSGeometry of the feature
- * This method is called by Pal each time it needs a geom's coordinates
- *
- * @return GEOSGeometry * a pointer the the geos geom
- */
- virtual GEOSGeometry* getGeosGeometry() = 0;
+ /**
+ * \brief Interface that allow Pal to acces user's geometries
+ */
+ class PalGeometry {
+ public:
+ /*
+ * \brief get the geometry in WKB hexa format
+ * This method is called by Pal each time it needs a geom's coordinates
+ *
+ * @return WKB Hex buffer
+ */
+ //virtual char * getWkbHexBuffer() = 0;
+ /**
+ * \brief get the GEOSGeometry of the feature
+ * This method is called by Pal each time it needs a geom's coordinates
+ *
+ * @return GEOSGeometry * a pointer the the geos geom
+ */
+ virtual GEOSGeometry* getGeosGeometry() = 0;
- /**
- * \brief Called by Pal when it doesn't need the coordinates anymore
- * @param the_geom is the geoms geom from PalGeometry::getfeomGeometry()
- */
- virtual void releaseGeosGeometry(GEOSGeometry *the_geom) = 0;
-
- /*
- * \brief Called by Pal when it doesn't need the coordinates anymore
- * @param wkbBuffer is the WkbBuffer from PalGeometry::getWkbHexBuffer()
- */
- //virtual void releaseWkbHexBuffer(char *wkbBuffer) = 0;
+ /**
+ * \brief Called by Pal when it doesn't need the coordinates anymore
+ * @param the_geom is the geoms geom from PalGeometry::getfeomGeometry()
+ */
+ virtual void releaseGeosGeometry (GEOSGeometry *the_geom) = 0;
- /*
- * \brief Give back a label to display
- * Pal call this method when label will no move anymore.
- *
- * @param label the label to disploy
- */
- //virtual void addLabel(Label *label) = 0;
- virtual ~PalGeometry(){}
-};
+ /*
+ * \brief Called by Pal when it doesn't need the coordinates anymore
+ * @param wkbBuffer is the WkbBuffer from PalGeometry::getWkbHexBuffer()
+ */
+ //virtual void releaseWkbHexBuffer(char *wkbBuffer) = 0;
+ /*
+ * \brief Give back a label to display
+ * Pal call this method when label will no move anymore.
+ *
+ * @param label the label to disploy
+ */
+ //virtual void addLabel(Label *label) = 0;
+
+ virtual ~PalGeometry() {}
+ };
+
} // end namespace pal
#endif
Modified: branches/vector_overlay_branch/src/core/pal/pointset.h
===================================================================
--- branches/vector_overlay_branch/src/core/pal/pointset.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/pointset.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -90,6 +90,7 @@
friend class Pal;
friend class Layer;
friend class LabelPosition;
+ friend class PolygonCostCalculator;
friend class Problem;
friend bool pruneLabelPositionCallback (LabelPosition *lp, void *ctx);
//friend Feat *splitButterflyPolygon (Feat *f, int pt_a, int pt_b, double cx, double cy);
@@ -100,30 +101,28 @@
friend void releaseAllInIndex (RTree<PointSet*, double, 2, double> *obstacles);
friend bool releaseCallback (PointSet *pset, void *ctx);
friend bool filteringCallback (PointSet*, void*);
- public:
+ protected:
int nbPoints;
double *x;
double *y; // points order is counterclockwise
- int type;
- protected:
-
int *status; // -1 means inside the bbox, +1 means outside and 0 is either in either out
int *cHull;
int cHullSize;
-
+ int type;
//PointSet *parent;
PointSet* holeOf;
PointSet* parent;
-public:
PointSet (double x, double y);
PointSet (PointSet &ps);
+
+//public:
double xmin;
double xmax;
double ymin;
Modified: branches/vector_overlay_branch/src/core/pal/problem.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/problem.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/problem.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -43,6 +43,7 @@
#include <cfloat>
#include <ctime>
#include <list>
+#include <limits.h> //for INT_MAX
#include <pal/pal.h>
#include <pal/palstat.h>
@@ -58,8 +59,8 @@
#include "util.h"
#include "priorityqueue.h"
-#include <limits.h>
+
namespace pal {
inline void delete_chain (Chain *chain) {
@@ -3044,7 +3045,7 @@
for (i = 0;i < nbft;i++) {
if (sol->s[i] >= 0) {
LabelPosition *lp = labelpositions[sol->s[i]];
- toSVGPath (4, 3, lp->x, lp->y, pal->getDpi(), scale, convert (bbox[0], scale, pal->getDpi()), convert (bbox[3], scale, pal->getDpi()), "label", lp->feature->uid, svgmap);
+ toSVGPath (4, 3, lp->x, lp->y, pal->getDpi(), scale, convert2pt (bbox[0], scale, pal->getDpi()), convert2pt (bbox[3], scale, pal->getDpi()), "label", lp->feature->uid, svgmap);
}
}
Modified: branches/vector_overlay_branch/src/core/pal/util.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/pal/util.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/util.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -352,6 +352,7 @@
f->minmax[3] = ymax;
+ // TODO make a function with that and add simplify() process
int new_nbPoints = f->nbPoints;
bool *ok = new bool[new_nbPoints];
Modified: branches/vector_overlay_branch/src/core/pal/util.h
===================================================================
--- branches/vector_overlay_branch/src/core/pal/util.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/pal/util.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -39,6 +39,8 @@
#include <stddef.h>
#include <geos_c.h>
+#include <pal/pal.h>
+
#include "rtree.hpp"
#include "pointset.h"
@@ -78,9 +80,6 @@
*/
LinkedList<Feat*> * splitGeom (GEOSGeometry *the_geom, const char *geom_id);
-
-
-
typedef struct _feats {
Feature *feature;
PointSet *shape;
@@ -116,18 +115,91 @@
inline double vabs (double x)
{ return x >= 0 ? x : -x; }
- inline double px2meters (double x, int dpi, double scale)
- { return ( (x / double (dpi)) * 0.0254) * scale; }
+
+ inline double degree2meter (double delta_deg){
+ double lat = delta_deg*0.5;
+ const static double rads = (4.0*atan(1.0))/180.0;
+ double a = cos(lat*rads);
+ a = a*a;
+ double c = 2.0*atan2(sqrt(a), sqrt(1.0 - a));
+ const static double ra = 6378000; // [m]
+ const static double e = 0.0810820288;
+ double radius = ra*(1.0 - e*e) / pow(1.0 - e*e*sin(lat*rads)*sin(lat*rads ), 1.5 );
+ double meters = (delta_deg) / 180.0 * radius * c; // [m]
+ return meters;
+ }
+
+ inline double unit_convert (double x, Units from, Units to, int dpi, double scale, double delta_canvas_width)
+ {
+ /* nothing to convert */
+ if (from == to){
+ return x;
+ }
+
+ switch (from){
+ case pal::PIXEL:
+ switch (to){
+ case pal::METER:
+ return ((x / double (dpi)) * 0.0254) * scale;
+ case pal::FOOT:
+ return ((x / double (dpi))*12) * scale;
+ case pal::DEGREE:
+ double iw = degree2meter(delta_canvas_width)*39.3700787;
+ return (x * delta_canvas_width * scale) / (iw * dpi);
+ }
+ break;
+ case pal::METER:
+ switch (to){
+ case pal::PIXEL:
+ return (x*dpi)/(2.54*scale);
+ case pal::FOOT:
+ return x/0.3048;
+ case pal::DEGREE:
+ double mw = degree2meter(delta_canvas_width);
+ return (x * delta_canvas_width) / mw;
+ }
+ break;
+ case pal::FOOT:
+ switch (to){
+ case pal::PIXEL:
+ return (x*dpi)/(12*scale);
+ case pal::METER:
+ return x*0.3048;
+ case pal::DEGREE:
+ double iw = degree2meter(delta_canvas_width)*39.3700787;
+ return (x * delta_canvas_width) / iw;
+ }
+ break;
+ case pal::DEGREE:
+ switch (to){
+ case pal::PIXEL:
+ fprintf (stderr, "Degree to pixel not yet implemented");
+ break;
+ case pal::METER:
+ fprintf (stderr, "Degree to meter not yet implemented");
+ break;
+ case pal::FOOT:
+ fprintf (stderr, "Degree to foot not yet implemented");
+ break;
+ }
+ break;
+ }
+
+ fprintf (stderr, "Unable to convert. Unknown units");
+ return 0.0;
+ }
+
+
/* From meters to PostScript Point */
- inline void convert (int *x, double scale, int dpi) {
+ inline void convert2pt (int *x, double scale, int dpi) {
*x = (int) ( ( (double) * x / scale) * 39.3700787402 * dpi + 0.5);
}
- inline int convert (double x, double scale, int dpi) {
+ inline int convert2pt (double x, double scale, int dpi) {
return (int) ( (x / scale) * 39.3700787402 * dpi + 0.5);
}
Modified: branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -41,7 +41,7 @@
mOverlays.clear();
}
-void QgsCentralPointPositionManager::findObjectPositions(const QgsRenderContext& context)
+void QgsCentralPointPositionManager::findObjectPositions(const QgsRenderContext& context, QGis::UnitType unitType)
{
QList<QgsVectorOverlay*>::iterator overlay_it = mOverlays.begin();
QgsVectorOverlay* currentOverlay = 0;
Modified: branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.h
===================================================================
--- branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/qgscentralpointpositionmanager.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -33,7 +33,7 @@
void addLayer(QgsVectorLayer* vl, QList<QgsVectorOverlay*>& overlays);
/**Removes all the overlays*/
void removeLayers();
- void findObjectPositions(const QgsRenderContext& context);
+ void findObjectPositions(const QgsRenderContext& context, QGis::UnitType unitType);
private:
/**Calculates the central point for points/lines/polygons. Returns 0 in case of success*/
Modified: branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/qgsmaprenderer.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -461,7 +461,7 @@
//find overlay positions and draw the vector overlays
if(overlayManager && allOverlayList.size() > 0)
{
- overlayManager->findObjectPositions(mRenderContext);
+ overlayManager->findObjectPositions(mRenderContext, mScaleCalculator->mapUnits());
//draw all the overlays
QList<QgsVectorOverlay*>::iterator allOverlayIt = allOverlayList.begin();
for(; allOverlayIt != allOverlayList.end(); ++allOverlayIt)
Modified: branches/vector_overlay_branch/src/core/qgsoverlayobjectpositionmanager.h
===================================================================
--- branches/vector_overlay_branch/src/core/qgsoverlayobjectpositionmanager.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/qgsoverlayobjectpositionmanager.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -19,6 +19,7 @@
#define QGSOVERLAYOBJECTPOSITIONMANAGER_H
#include <QList>
+#include "qgis.h"
class QgsRenderContext;
class QgsVectorLayer;
@@ -34,8 +35,10 @@
virtual void addLayer(QgsVectorLayer* vl, QList<QgsVectorOverlay*>& overlays) = 0;
/**Removes all the layers*/
virtual void removeLayers() = 0;
- /**Calculate positions for the overlay objects*/
- virtual void findObjectPositions(const QgsRenderContext& context) = 0;
+ /**Calculate positions for the overlay objects
+ @param context Context of rendering operation (Painter, scale factor)
+ @param unitType meters, feet, degrees*/
+ virtual void findObjectPositions(const QgsRenderContext& context, QGis::UnitType unitType) = 0;
};
#endif
Modified: branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp
===================================================================
--- branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -92,12 +92,31 @@
}
}
-void QgsPALObjectPositionManager::findObjectPositions(const QgsRenderContext& renderContext)
+void QgsPALObjectPositionManager::findObjectPositions(const QgsRenderContext& renderContext, QGis::UnitType unitType)
{
//trigger label placement
QgsRectangle viewExtent = renderContext.extent();
double bbox[4]; bbox[0] = viewExtent.xMinimum(); bbox[1] = viewExtent.yMinimum(); bbox[2] = viewExtent.xMaximum(); bbox[3] = viewExtent.yMaximum();
pal::PalStat* stat = 0;
+
+ //set map units
+ pal::Units mapUnits;
+ switch (unitType)
+ {
+ case QGis::Meters:
+ mapUnits = pal::METER;
+ break;
+
+ case QGis::Feet:
+ mapUnits = pal::FOOT;
+ break;
+
+ case QGis::Degrees:
+ mapUnits = pal::DEGREE;
+ break;
+ }
+ mPositionEngine.setMapUnit(mapUnits);
+
qWarning("**********************************starting calculation of overlay positions*****************************");
std::list<pal::Label*>* resultLabelList = mPositionEngine.labeller(renderContext.rendererScale(), bbox, &stat, true);
qWarning("**********************************calculation of overlay positions finished*****************************");
Modified: branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h
===================================================================
--- branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/core/qgspalobjectpositionmanager.h 2009-03-09 10:29:23 UTC (rev 10266)
@@ -27,7 +27,7 @@
QgsPALObjectPositionManager();
~QgsPALObjectPositionManager();
void addLayer(QgsVectorLayer* vl, QList<QgsVectorOverlay*>& overlays);
- void findObjectPositions(const QgsRenderContext& renderContext);
+ void findObjectPositions(const QgsRenderContext& renderContext, QGis::UnitType unitType);
void removeLayers();
/**Sets algorithm used for object placements. Possibilities are:
Modified: branches/vector_overlay_branch/src/plugins/interpolation/qgsinterpolator.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/interpolation/qgsinterpolator.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/plugins/interpolation/qgsinterpolator.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -18,6 +18,7 @@
#include "qgsinterpolator.h"
#include "qgsvectordataprovider.h"
#include "qgsgeometry.h"
+#include <cmath>
QgsInterpolator::QgsInterpolator( const QList<QgsVectorLayer*>& vlayers ): mDataIsCached( false ), mVectorLayers( vlayers ), zCoordInterpolation( false ), mValueAttribute( -1 )
{
@@ -76,6 +77,7 @@
QgsFeature theFeature;
double attributeValue = 0.0;
+ bool attributeConversionOk = false;
while ( provider->nextFeature( theFeature ) )
{
if ( !zCoordInterpolation )
@@ -86,7 +88,11 @@
{
return 3;
}
- attributeValue = att_it.value().toDouble();
+ attributeValue = att_it.value().toDouble(&attributeConversionOk);
+ if(!attributeConversionOk || isnan(attributeValue)) //don't consider vertices with attributes like 'nan' for the interpolation
+ {
+ continue;
+ }
}
if ( addVerticesToCache( theFeature.geometry(), attributeValue ) != 0 )
Modified: branches/vector_overlay_branch/src/plugins/interpolation/qgstininterpolator.cpp
===================================================================
--- branches/vector_overlay_branch/src/plugins/interpolation/qgstininterpolator.cpp 2009-03-09 00:20:39 UTC (rev 10265)
+++ branches/vector_overlay_branch/src/plugins/interpolation/qgstininterpolator.cpp 2009-03-09 10:29:23 UTC (rev 10266)
@@ -65,6 +65,20 @@
DualEdgeTriangulation* theDualEdgeTriangulation = new DualEdgeTriangulation( mCachedBaseData.size(), 0 );
mTriangulation = theDualEdgeTriangulation;
+ //do some randomisation on the base data to have better results with regular structures
+ vertexData vertex1, vertex2;
+
+ for(int i = 0; i <= mCachedBaseData.size() / 2; ++i)
+ {
+ vertex1 = mCachedBaseData[i];
+ Point3D* thePoint1 = new Point3D( vertex1.x, vertex1.y, vertex1.z );
+ mTriangulation->addPoint( thePoint1 );
+ vertex2 = mCachedBaseData[mCachedBaseData.size() - 1 - i];
+ Point3D* thePoint2 = new Point3D( vertex2.x, vertex2.y, vertex2.z );
+ mTriangulation->addPoint( thePoint2 );
+ }
+
+#if 0
//add all the vertices to the triangulation
QVector<vertexData>::const_iterator vertex_it = mCachedBaseData.constBegin();
for ( ; vertex_it != mCachedBaseData.constEnd(); ++vertex_it )
@@ -72,6 +86,7 @@
Point3D* thePoint = new Point3D( vertex_it->x, vertex_it->y, vertex_it->z );
mTriangulation->addPoint( thePoint );
}
+#endif //0
mTriangleInterpolator = new LinTriangleInterpolator( theDualEdgeTriangulation );
More information about the QGIS-commit
mailing list