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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jul 11 12:32:37 EDT 2009


Author: wonder
Date: 2009-07-11 12:32:37 -0400 (Sat, 11 Jul 2009)
New Revision: 11044

Modified:
   branches/symbology-ng-branch/src/core/pal/feature.cpp
   branches/symbology-ng-branch/src/core/pal/feature.h
   branches/symbology-ng-branch/src/core/pal/labelposition.cpp
   branches/symbology-ng-branch/src/core/pal/labelposition.h
   branches/symbology-ng-branch/src/core/pal/layer.cpp
   branches/symbology-ng-branch/src/core/pal/pal.cpp
   branches/symbology-ng-branch/src/core/pal/pointset.cpp
   branches/symbology-ng-branch/src/core/pal/pointset.h
   branches/symbology-ng-branch/src/core/pal/problem.cpp
   branches/symbology-ng-branch/src/core/pal/util.cpp
   branches/symbology-ng-branch/src/core/pal/util.h
Log:
First round of refactoring:
Made pal::Feature and pal::LabelPosition less friendly: prefer access to internal variables through access functions.
Removed some dead functions, moved some functions, less code duplication.
Shouldn't affect functionality in any way.


Modified: branches/symbology-ng-branch/src/core/pal/feature.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -869,7 +869,7 @@
       }
     }
 
-    sort(( void** )( *lPos ), nbp, costGrow );
+    sort(( void** )( *lPos ), nbp, LabelPosition::costGrow );
 
     for ( i = rnbp;i < nbp;i++ )
     {
@@ -944,10 +944,7 @@
       y = NULL;
       for ( i = 0;i < nbSelfObs;i++ )
       {
-        delete[] selfObs[i]->x;
-        delete[] selfObs[i]->y;
-        selfObs[i]->x = NULL;
-        selfObs[i]->y = NULL;
+        selfObs[i]->deleteCoords();
       }
     }
   }

Modified: branches/symbology-ng-branch/src/core/pal/feature.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/feature.h	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/feature.h	2009-07-11 16:32:37 UTC (rev 11044)
@@ -60,19 +60,6 @@
   class Feature : public PointSet
   {
 
-      friend class Pal;
-      friend class Layer;
-      friend class Problem;
-      friend class LabelPosition;
-
-      friend bool extractFeatCallback( Feature *ft_ptr, void *ctx );
-      friend bool pruneLabelPositionCallback( LabelPosition *lp, void *ctx );
-      friend bool obstacleCallback( PointSet *feat, void *ctx );
-      //friend void setCost (int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4]);
-      friend void releaseAllInIndex( RTree<PointSet*, double, 2, double, 8, 4>* );
-      friend bool releaseCallback( PointSet *pset, void *ctx );
-      friend bool filteringCallback( PointSet*, void* );
-
     protected:
       //int id;   /* feature no id into layer */
       double label_x;
@@ -96,6 +83,7 @@
 
       SimpleMutex *accessMutex;
 
+public:
       /**
        * \brief generate candidates for point feature
        * Generate candidates for point features
@@ -244,6 +232,23 @@
 
       void fetchCoordinates();
       void releaseCoordinates();
+
+
+
+      PalGeometry* getUserGeometry() { return userGeom; }
+
+      void setLabelSize(double x, double y) { label_x = x; label_y = y; }
+      double getLabelWidth() const { return label_x; }
+      double getLabelHeight() const { return label_y; }
+
+      int getNumParts() const { return nPart; }
+
+      void setLabelDistance(double dist) { distlabel = dist; }
+      double getLabelDistance() const { return distlabel; }
+
+      int getNumSelfObstacles() const { return nbSelfObs; }
+      PointSet* getSelfObstacle(int i) { return selfObs[i]; }
+
   };
 
 } // end namespace pal

Modified: branches/symbology-ng-branch/src/core/pal/labelposition.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -213,37 +213,50 @@
     return cost;
   }
 
-  Feature * LabelPosition::getFeature()
+  void LabelPosition::validateCost()
   {
-    return feature;
+    if ( cost >= 1 )
+    {
+      std::cout << " Warning: lp->cost == " << cost << " (from feat: " << feature->getUID() << "/" << getLayerName() << ")" << std::endl;
+      cost -= int ( cost ); // label cost up to 1
+    }
   }
 
-  bool xGrow( void *l, void *r )
+  Feature * LabelPosition::getFeature()
   {
-    return (( LabelPosition* ) l )->x[0] > (( LabelPosition* ) r )->x[0];
+    return feature;
   }
 
-  bool yGrow( void *l, void *r )
+  void LabelPosition::getBoundingBox(double amin[2], double amax[2]) const
   {
-    return (( LabelPosition* ) l )->y[0] > (( LabelPosition* ) r )->y[0];
+    amin[0] = DBL_MAX;
+    amax[0] = -DBL_MAX;
+    amin[1] = DBL_MAX;
+    amax[1] = -DBL_MAX;
+    for ( int c = 0;c < 4;c++ )
+    {
+      if ( x[c] < amin[0] )
+        amin[0] = x[c];
+      if ( x[c] > amax[0] )
+        amax[0] = x[c];
+      if ( y[c] < amin[1] )
+        amin[1] = y[c];
+      if ( y[c] > amax[1] )
+        amax[1] = y[c];
+    }
   }
 
-  bool xShrink( void *l, void *r )
+  char* LabelPosition::getLayerName() const
   {
-    return (( LabelPosition* ) l )->x[0] < (( LabelPosition* ) r )->x[0];
+    return feature->getLayer()->name;
   }
 
-  bool yShrink( void *l, void *r )
+  bool LabelPosition::costShrink( void *l, void *r )
   {
-    return (( LabelPosition* ) l )->y[0] < (( LabelPosition* ) r )->y[0];
-  }
-
-  bool costShrink( void *l, void *r )
-  {
     return (( LabelPosition* ) l )->cost < (( LabelPosition* ) r )->cost;
   }
 
-  bool costGrow( void *l, void *r )
+  bool LabelPosition::costGrow( void *l, void *r )
   {
     return (( LabelPosition* ) l )->cost > (( LabelPosition* ) r )->cost;
   }
@@ -269,23 +282,23 @@
 //#warning retourner les coord projeté ou pas ?
     //feature->layer->pal->proj->getLatLong(this->x[0], this->y[0], &x, &y);
 
-    return new Label( this->x, this->y, alpha, feature->uid, feature->layer->name, feature->userGeom );
+    return new Label( this->x, this->y, alpha, feature->getUID(), feature->getLayer()->getName(), feature->getUserGeometry() );
   }
 
 
-  bool obstacleCallback( PointSet *feat, void *ctx )
+  bool LabelPosition::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 ) )
+    if (( feat == lp->feature ) || ( feat->getHoleOf() && feat->getHoleOf() != lp->feature ) )
     {
       return true;
     }
 
     // if the feature is not a hole we have to fetch corrdinates
     // otherwise holes coordinates are still in memory (feature->selfObs)
-    if ( feat->holeOf == NULL )
+    if ( feat->getHoleOf() == NULL )
     {
       (( Feature* ) feat )->fetchCoordinates();
     }
@@ -293,7 +306,7 @@
     pCost->update( feat );
 
 
-    if ( feat->holeOf == NULL )
+    if ( feat->getHoleOf() == NULL )
     {
       (( Feature* ) feat )->releaseCoordinates();
     }
@@ -332,10 +345,7 @@
         amax[0] = amin[0] + 2 * dist;
         amax[1] = amin[1] + 2 * dist;
     } else {*/
-    amin[0] = feature->xmin;
-    amin[1] = feature->ymin;
-    amax[0] = feature->xmax;
-    amax[1] = feature->ymax;
+    feature->getBoundingBox(amin, amax);
     //}
 
     //std::cout << amin[0] << " " << amin[1] << " " << amax[0] << " " <<  amax[1] << std::endl;
@@ -351,24 +361,7 @@
   {
     double amin[2];
     double amax[2];
-    int c;
-
-    amin[0] = DBL_MAX;
-    amax[0] = -DBL_MAX;
-    amin[1] = DBL_MAX;
-    amax[1] = -DBL_MAX;
-    for ( c = 0;c < 4;c++ )
-    {
-      if ( x[c] < amin[0] )
-        amin[0] = x[c];
-      if ( x[c] > amax[0] )
-        amax[0] = x[c];
-      if ( y[c] < amin[1] )
-        amin[1] = y[c];
-      if ( y[c] > amax[1] )
-        amax[1] = y[c];
-    }
-
+    getBoundingBox(amin, amax);
     index->Remove( amin, amax, this );
   }
 
@@ -377,24 +370,7 @@
   {
     double amin[2];
     double amax[2];
-    int c;
-
-    amin[0] = DBL_MAX;
-    amax[0] = -DBL_MAX;
-    amin[1] = DBL_MAX;
-    amax[1] = -DBL_MAX;
-    for ( c = 0;c < 4;c++ )
-    {
-      if ( x[c] < amin[0] )
-        amin[0] = x[c];
-      if ( x[c] > amax[0] )
-        amax[0] = x[c];
-      if ( y[c] < amin[1] )
-        amin[1] = y[c];
-      if ( y[c] > amax[1] )
-        amax[1] = y[c];
-    }
-
+    getBoundingBox(amin, amax);
     index->Insert( amin, amax, this );
   }
 
@@ -603,5 +579,56 @@
     //return (a+b+c+d);
     return ( a*b*c*d );
   }
+
+  //////////
+
+  bool LabelPosition::countOverlapCallback( LabelPosition *lp, void *ctx )
+  {
+    LabelPosition *lp2 = ( LabelPosition* ) ctx;
+
+    if ( lp2->isInConflict( lp ) )
+    {
+      lp2->nbOverlap++;
+    }
+
+    return true;
+  }
+
+  bool LabelPosition::countFullOverlapCallback( LabelPosition *lp, void *ctx )
+  {
+    LabelPosition *lp2 = (( CountContext* ) ctx )->lp;
+    double *cost = (( CountContext* ) ctx )->cost;
+    //int *feat = ((CountContext*)ctx)->feat;
+    int *nbOv = (( CountContext* ) ctx )->nbOv;
+    double *inactiveCost = (( CountContext* ) ctx )->inactiveCost;
+    if ( lp2->isInConflict( lp ) )
+    {
+#ifdef _DEBUG_FULL_
+      std::cout <<  "count overlap : " << lp->id << "<->" << lp2->id << std::endl;
+#endif
+      ( *nbOv ) ++;
+      *cost += inactiveCost[lp->probFeat] + lp->getCost();
+
+    }
+
+    return true;
+  }
+
+
+  bool LabelPosition::removeOverlapCallback( LabelPosition *lp, void *ctx )
+  {
+    LabelPosition *lp2 = ( LabelPosition * ) ctx;
+
+    if ( lp2->isInConflict( lp ) )
+    {
+      //std::cout << "   hit !" << std::endl;
+      lp->nbOverlap--;
+      lp2->nbOverlap--;
+    }
+
+    return true;
+  }
+
+
 } // end namespace
 

Modified: branches/symbology-ng-branch/src/core/pal/labelposition.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-07-11 16:32:37 UTC (rev 11044)
@@ -54,39 +54,15 @@
   class LabelPosition
   {
 
-      friend bool extractFeatCallback( Feature *ft_ptr, void*ctx );
-      friend bool xGrow( void *l, void *r );
-      friend bool yGrow( void *l, void *r );
-      friend bool xShrink( void *l, void *r );
-      friend bool yShrink( void *l, void *r );
-      friend bool costShrink( void *l, void *r );
-      friend bool costGrow( void *l, void *r );
       friend bool pruneLabelPositionCallback( LabelPosition *lp, void *ctx );
-      //friend void setCost (int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4]);
-      friend bool countOverlapCallback( LabelPosition *lp, void *ctx );
-      friend bool countFullOverlapCallback( LabelPosition *lp, void *ctx );
-      friend bool removeOverlapCallback( LabelPosition *lp, void *ctx );
-      friend bool falpCallback1( LabelPosition *lp, void * ctx );
-      friend bool falpCallback2( LabelPosition *lp, void * ctx );
-      friend bool subPartCallback( LabelPosition *lp, void *ctx );
-      friend bool chainCallback( LabelPosition *lp, void *context );
-      friend void ignoreLabel( LabelPosition*, PriorityQueue*, RTree<LabelPosition*, double, 2, double, 8, 4>* );
-      friend bool obstacleCallback( PointSet *feat, void *ctx );
-
-      friend bool updateCandidatesCost( LabelPosition *lp, void *context );
-      friend bool nokCallback( LabelPosition*, void* );
-
+      friend double dist_pointToLabel( double, double, LabelPosition* );
       friend class Pal;
-      friend class Problem;
       friend class Feature;
-      friend double dist_pointToLabel( double, double, LabelPosition* );
+
     private:
-      //LabelPosition **overlaped;
-      //int nbOverlap;
 
       int id;
       double cost;
-      //double workingCost;
       double x[4], y[4];
 
       double alpha;
@@ -100,9 +76,6 @@
       double w;
       double h;
 
-      //LabelPosition (int id, double x1, double y1, double w, double h, double cost, Feature *feature);
-      //LabelPosition (int id, int nbPart, double *x, double *y, double *alpha,
-
     public:
       /**
        * \brief create a new LabelPosition
@@ -160,12 +133,7 @@
        */
       int getId();
 
-      /** \brief return the feature id which the labelposition is
-       * \return feature id
-       */
-      //int getFeatureId();
 
-
       /** \brief return the feature corresponding to this labelposition
        * \return the feature
        */
@@ -185,6 +153,16 @@
       double getWidth() { return w; }
       double getHeight() { return h; }
 
+      double getNumOverlaps() const { return nbOverlap; }
+      void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
+
+      int getProblemFeatureId() const { return probFeat; }
+      /** set problem feature ID. called from pal.cpp during extraction */
+      void setProblemFeatureId( int probFid ) { probFeat = probFid; }
+
+      /** return pointer to layer's name. used for stats */
+      char* getLayerName() const;
+
       /**
        * \brief get alpha
        * \return alpha to rotate text (in rad)
@@ -196,6 +174,12 @@
        */
       double getCost();
 
+      /** Make sure the cost is less than 1 */
+      void validateCost();
+
+      /** return bounding box - amin: xmin,ymin - amax: xmax,ymax */
+      void getBoundingBox(double amin[2], double amax[2]) const;
+
       /**
        * \brief get a final lable from this
        * \return a new Label() object
@@ -238,57 +222,33 @@
       };
 
 
+      // for sorting
+      static bool costShrink( void *l, void *r );
+      static bool costGrow( void *l, void *r );
 
-  };
+      // for counting number of overlaps
+      typedef struct
+      {
+        LabelPosition *lp;
+        int *nbOv;
+        double *cost;
+        double *inactiveCost;
+        //int *feat;
+      } CountContext;
 
-  /**
-   * \brief LabelPosition cmp
-   *
-   * \return true if l.id < r.id
-   * \see Util::sort()
-   */
-  bool idGrow( void *l, void *r );
-  /**
-   * \brief LabelPosition cmp
-   *
-   * \return true if l.id < r.id
-   * \see sort
-   */
-  bool xGrow( void *l, void *r );
-  /**
-   * \brief LabelPosition cmp
-   *
-   * \return true if l.id > r.id
-   * \see sort
-   */
-  bool yGrow( void *l, void *r );
-  /**
-   * \brief LabelPosition cmp
-   *
-   * \return true if l.id < r.id
-   * \see sort
-   */
-  bool xShrink( void *l, void *r );
-  /**
-   * \brief LabelPosition cmp
-   *
-   * \return true if l.id < r.id
-   * \see sort
-   */
-  bool yShrink( void *l, void *r );
-  /**
-   * \brief LabelPosition cmp
-   *
-   * \return true if l.id < r.id
-   * \see sort
-   */
-//bool nboGrow (void *l, void *r);
+      /*
+       * count overlap, ctx = p_lp
+       */
+      static bool countOverlapCallback( LabelPosition *lp, void *ctx );
 
+      static bool countFullOverlapCallback( LabelPosition *lp, void *ctx );
 
-  bool costShrink( void *l, void *r );
-  bool costGrow( void *l, void *r );
+      static bool removeOverlapCallback( LabelPosition *lp, void *ctx );
 
+      // for polygon cost calculation
+      static bool obstacleCallback( PointSet *feat, void *ctx );
 
+  };
 } // end namespac
 
 #endif

Modified: branches/symbology-ng-branch/src/core/pal/layer.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/layer.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/layer.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -371,15 +371,10 @@
 
       double bmin[2];
       double bmax[2];
-      bmin[0] = ft->xmin;
-      bmin[1] = ft->ymin;
+      ft->getBoundingBox(bmin, bmax);
 
-      bmax[0] = ft->xmax;
-      bmax[1] = ft->ymax;
+      ft->setLabelSize(label_x, label_y);
 
-      ft->label_x = label_x;
-      ft->label_y = label_y;
-
       features->push_back( ft );
 
       if ( first_feat )
@@ -442,12 +437,12 @@
   {
     // log
     Feature *feat = it->item;
-    int nb = feat->nPart;
+    int nb = feat->getNumParts();
 
     for ( i = 0;i < nb;i++ )
     {
       feat = it->item;
-      feat->distlabel = distlabel;
+      feat->setLabelDistance(distlabel);
       it = it->next;
     }
   }
@@ -468,7 +463,7 @@
 
   int ret = -1;
   if ( it )
-    ret = it->item->distlabel;
+    ret = it->item->getLabelDistance();
   else
   {
     modMutex->unlock();
@@ -496,13 +491,12 @@
   if ( it )
   {
     Feature *feat = it->item;
-    int nb = feat->nPart;
+    int nb = feat->getNumParts();
 
     for ( i = 0;i < nb;i++ )
     {
       feat = it->item;
-      feat->label_x = label_x;
-      feat->label_y = label_y;
+      feat->setLabelSize(label_x, label_y);
       it = it->next;
     }
   }
@@ -523,7 +517,7 @@
   double ret = -1;
 
   if ( it )
-    ret = it->item->label_y;
+    ret = it->item->getLabelHeight();
   else
   {
     modMutex->unlock();
@@ -542,7 +536,7 @@
   double ret = -1;
 
   if ( it )
-    ret = it->item->label_x;
+    ret = it->item->getLabelWidth();
   else
   {
     modMutex->unlock();

Modified: branches/symbology-ng-branch/src/core/pal/pal.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pal.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/pal.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -244,10 +244,7 @@
     // all feature which are obstacle will be inserted into obstacles
     if ( context->layer->obstacle )
     {
-      min[0] = ft_ptr->xmin;
-      min[1] = ft_ptr->ymin;
-      max[0] = ft_ptr->xmax;
-      max[1] = ft_ptr->ymax;
+      ft_ptr->getBoundingBox(min, max);
       context->obstacles->Insert( min, max, ft_ptr );
 
       ft_ptr->fetchCoordinates();
@@ -258,20 +255,17 @@
     if ( context->layer->toLabel && context->layer->isScaleValid( context->scale ) )
     {
       // is the feature well defined ? // TODO Check epsilon
-      if ( ft_ptr->label_x > 0.0000001 && ft_ptr->label_y > 0.0000001 )
+      if ( ft_ptr->getLabelWidth() > 0.0000001 && ft_ptr->getLabelHeight() > 0.0000001 )
       {
 
         int i;
         // Hole of the feature are obstacles
-        for ( i = 0;i < ft_ptr->nbSelfObs;i++ )
+        for ( i = 0;i < ft_ptr->getNumSelfObstacles();i++ )
         {
-          min[0] = ft_ptr->selfObs[i]->xmin;
-          min[1] = ft_ptr->selfObs[i]->ymin;
-          max[0] = ft_ptr->selfObs[i]->xmax;
-          max[1] = ft_ptr->selfObs[i]->ymax;
-          context->obstacles->Insert( min, max, ft_ptr->selfObs[i] );
+          ft_ptr->getSelfObstacle(i)->getBoundingBox(min, max);
+          context->obstacles->Insert( min, max, ft_ptr->getSelfObstacle(i) );
 
-          if ( !ft_ptr->selfObs[i]->holeOf )
+          if ( !ft_ptr->getSelfObstacle(i)->getHoleOf() )
           {
             std::cout << "ERROR: SHOULD HAVE A PARENT!!!!!" << std::endl;
           }
@@ -283,8 +277,8 @@
           QTime t;
           t.start();
 
-        if (( ft_ptr->type == GEOS_LINESTRING )
-            || ft_ptr->type == GEOS_POLYGON )
+        if (( ft_ptr->getGeosType() == GEOS_LINESTRING )
+            || ft_ptr->getGeosType() == GEOS_POLYGON )
         {
 
           double bbx[4], bby[4];
@@ -312,7 +306,7 @@
           else
           {
             // feature isn't completly in the math
-            if ( ft_ptr->type == GEOS_LINESTRING )
+            if ( ft_ptr->getGeosType() == GEOS_LINESTRING )
               PointSet::reduceLine( shape, shapes, bbx, bby );
             else
             {
@@ -462,7 +456,7 @@
     double scale = (( PruneCtx* ) ctx )->scale;
     Pal* pal = (( PruneCtx* ) ctx )->pal;
 
-    if (( feat == lp->feature ) || ( feat->holeOf && feat->holeOf != lp->feature ) )
+    if (( feat == lp->feature ) || ( feat->getHoleOf() && feat->getHoleOf() != lp->feature ) )
     {
       return true;
     }
@@ -479,7 +473,7 @@
 
     double dist;
 
-    double distlabel = lp->feature->distlabel;
+    double distlabel = lp->feature->getLabelDistance();
     /*unit_convert( double( lp->feature->distlabel ),
                                      pal::PIXEL,
                                      pal->map_unit,
@@ -487,7 +481,7 @@
 
 
 
-    switch ( feat->type )
+    switch ( feat->getGeosType() )
     {
         //case geos::geom::GEOS_POINT:
       case GEOS_POINT:
@@ -515,7 +509,7 @@
         // Is one of label's boarder cross the line ?
         for ( i = 0;i < 4;i++ )
         {
-          for ( j = 0;j < feat->nbPoints - 1;j++ )
+          for ( j = 0;j < feat->getNumPoints() - 1;j++ )
           {
             ca = cross_product( lp->x[i], lp->y[i], lp->x[( i+1 ) %4], lp->y[( i+1 ) %4],
                                 feat->x[j], feat->y[j] );
@@ -543,7 +537,7 @@
 #ifdef _DEBUG_FULL
         std::cout << "    POLY" << std::endl;
 #endif
-        n =  nbLabelPointInPolygon( feat->nbPoints, feat->x, feat->y, lp->x, lp->y );
+        n =  nbLabelPointInPolygon( feat->getNumPoints(), feat->x, feat->y, lp->x, lp->y );
 
         //n<1?n=0:n=1;
         break;
@@ -560,7 +554,7 @@
 
   bool releaseCallback( PointSet *pset, void *ctx )
   {
-    if ( pset->holeOf == NULL )
+    if ( pset->getHoleOf() == NULL )
     {
       (( Feature* ) pset )->releaseCoordinates();
     }
@@ -605,22 +599,18 @@
     double scale = (( FilterContext* ) ctx )->scale;
     Pal* pal = (( FilterContext* )ctx )->pal;
 
-    if ( pset->holeOf == NULL )
+    if ( pset->getHoleOf() == NULL )
     {
       (( Feature* ) pset )->fetchCoordinates();
     }
     else
     {
-      (( Feature* ) pset->holeOf )->fetchCoordinates();
+      (( Feature* ) pset->getHoleOf() )->fetchCoordinates();
     }
 
     double amin[2], amax[2];
+    pset->getBoundingBox(amin, amax);
 
-    amin[0] = pset->xmin;
-    amin[1] = pset->ymin;
-    amax[0] = pset->xmax;
-    amax[1] = pset->ymax;
-
     PruneCtx pruneContext;
 
     pruneContext.scale = scale;
@@ -628,13 +618,13 @@
     pruneContext.pal = pal;
     cdtsIndex->Search( amin, amax, pruneLabelPositionCallback, ( void* ) &pruneContext );
 
-    if ( pset->holeOf == NULL )
+    if ( pset->getHoleOf() == NULL )
     {
       (( Feature* ) pset )->releaseCoordinates();
     }
     else
     {
-      (( Feature* ) pset->holeOf )->releaseCoordinates();
+      (( Feature* ) pset->getHoleOf() )->releaseCoordinates();
     }
 
     return true;
@@ -825,7 +815,7 @@
       prob->featStartId[i] = idlp;
       prob->inactiveCost[i] = pow( 2, 10 - 10 * feat->priority );
 
-      switch ( feat->feature->type )
+      switch ( feat->feature->getGeosType() )
       {
         case GEOS_POINT:
           max_p = point_p;
@@ -843,7 +833,7 @@
         max_p = feat->nblp;
       //
       // sort candidates list, best label to worst
-      sort(( void** ) feat->lPos, feat->nblp, costGrow );
+      sort(( void** ) feat->lPos, feat->nblp, LabelPosition::costGrow );
 
       // try to exclude all conflitual labels (good ones have cost < 1 by pruning)
       double discrim = 0.0;
@@ -851,9 +841,9 @@
       do
       {
         discrim += 1.0;
-        for ( stop = 0;stop < feat->nblp && feat->lPos[stop]->cost < discrim;stop++ );
+        for ( stop = 0;stop < feat->nblp && feat->lPos[stop]->getCost() < discrim;stop++ );
       }
-      while ( stop == 0 && discrim < feat->lPos[feat->nblp-1]->cost + 2.0 );
+      while ( stop == 0 && discrim < feat->lPos[feat->nblp-1]->getCost() + 2.0 );
 
       if ( discrim > 1.5 )
       {
@@ -870,7 +860,7 @@
 #endif
 
       // Sets costs for candidates of polygon
-      if ( feat->feature->type == GEOS_POLYGON && ( feat->feature->layer->arrangement == P_FREE || feat->feature->layer->arrangement == P_HORIZ ) )
+      if ( feat->feature->getGeosType() == GEOS_POLYGON && ( feat->feature->getLayer()->arrangement == P_FREE || feat->feature->getLayer()->arrangement == P_HORIZ ) )
         LabelPosition::setCost( stop, feat->lPos, max_p, obstacles, bbx, bby );
 
 #ifdef _DEBUG_FULL_
@@ -895,7 +885,7 @@
         lp = feat->lPos[j];
         //lp->insertIntoIndex(prob->candidates);
         lp->id = idlp;
-        lp->probFeat = i; // bugfix #1 (maxence 10/23/2008)
+        lp->setProblemFeatureId( i ); // bugfix #1 (maxence 10/23/2008)
       }
       fFeats->push_back( feat );
     }
@@ -922,37 +912,20 @@
       for ( i = 0;i < feat->nblp;i++, idlp++ )  // foreach label candidate
       {
         lp = feat->lPos[i];
-        lp->nbOverlap = 0;
+        lp->resetNumOverlaps();
 
-        if ( lp->cost >= 1 )
-        {
-          std::cout << " Warning: lp->cost == " << lp->cost << " (from feat: " << lp->feature->uid << "/" << lp->feature->layer->name << ")" << std::endl;
-          lp->cost -= int ( lp->cost ); // label cost up to 1
-        }
+        // make sure that candidate's cost is less than 1
+        lp->validateCost();
 
         prob->labelpositions[idlp] = lp;
         //prob->feat[idlp] = j;
 
+        lp->getBoundingBox(amin, amax);
 
-        amin[0] = DBL_MAX;
-        amax[0] = -DBL_MAX;
-        amin[1] = DBL_MAX;
-        amax[1] = -DBL_MAX;
-        for ( c = 0;c < 4;c++ )
-        {
-          if ( lp->x[c] < amin[0] )
-            amin[0] = lp->x[c];
-          if ( lp->x[c] > amax[0] )
-            amax[0] = lp->x[c];
-          if ( lp->y[c] < amin[1] )
-            amin[1] = lp->y[c];
-          if ( lp->y[c] > amax[1] )
-            amax[1] = lp->y[c];
-        }
         // lookup for overlapping candidate
-        prob->candidates->Search( amin, amax, countOverlapCallback, ( void* ) lp );
+        prob->candidates->Search( amin, amax, LabelPosition::countOverlapCallback, ( void* ) lp );
 
-        nbOverlaps += lp->nbOverlap;
+        nbOverlaps += lp->getNumOverlaps();
 #ifdef _DEBUG_FULL_
         std::cout << "Nb overlap for " << idlp << "/" << prob->nblp - 1 << " : " << lp->nbOverlap << std::endl;
 #endif

Modified: branches/symbology-ng-branch/src/core/pal/pointset.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pointset.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/pointset.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -1747,6 +1747,14 @@
     py = cy / (3*A);
   }
 
+  void PointSet::deleteCoords()
+  {
+    delete[] x;
+    delete[] y;
+    x = NULL;
+    y = NULL;
+  }
+
 } // end namespace
 
 #endif

Modified: branches/symbology-ng-branch/src/core/pal/pointset.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pointset.h	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/pointset.h	2009-07-11 16:32:37 UTC (rev 11044)
@@ -93,22 +93,11 @@
   class PointSet
   {
       friend class Feature;
-      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);
-      friend bool obstacleCallback( PointSet *feat, void *ctx );
-      friend bool extractFeatCallback( Feature*, void* );
       friend void extractXYCoord( Feat *f );
-      friend LinkedList<Feat*> * splitGeom( GEOSGeometry *the_geom, const char *geom_id, bool check_valid );
-      friend void releaseAllInIndex( RTree<PointSet*, double, 2, double> *obstacles );
-      friend bool releaseCallback( PointSet *pset, void *ctx );
-      friend bool filteringCallback( PointSet*, void* );
-      /*protected*/
-    public:
+
+    protected:
       int nbPoints;
       double *x;
       double *y;   // points order is counterclockwise
@@ -128,13 +117,12 @@
 
       PointSet( PointSet &ps );
 
-
-//public:
       double xmin;
       double xmax;
       double ymin;
       double ymax;
 
+public:
       PointSet();
       PointSet( int nbPoints, double *x, double *y );
       ~PointSet();
@@ -196,8 +184,22 @@
       void getCentroid( double &px, double &py );
 
 
+      /** delete x and y coordinate arrays */
+      void deleteCoords();
 
+      int getGeosType() const { return type; }
 
+      void getBoundingBox(double min[2], double max[2]) const
+      {
+          min[0] = xmin; min[1] = ymin;
+          max[0] = xmax; max[1] = ymax;
+      }
+
+      /** returns NULL if this isn't a hole. Otherwise returns pointer to parent pointset. */
+      PointSet* getHoleOf() { return holeOf; }
+
+      int getNumPoints() const { return nbPoints; }
+
       /*
        * Iterate on line by real step of dl on x,y points
        * @param nbPoint # point in line

Modified: branches/symbology-ng-branch/src/core/pal/problem.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/problem.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/problem.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -157,27 +157,7 @@
   }
 
 
-  typedef struct
-  {
-    LabelPosition *lp;
-    int *nbOverlaps;
-  } RemoveOverlapContext;
 
-  bool removeOverlapCallback( LabelPosition *lp, void *ctx )
-  {
-    LabelPosition *lp2 = ( LabelPosition * ) ctx;
-
-    if ( lp2->isInConflict( lp ) )
-    {
-      //std::cout << "   hit !" << std::endl;
-      lp->nbOverlap--;
-      lp2->nbOverlap--;
-    }
-
-    return true;
-  }
-
-
   void Problem::reduce()
   {
 
@@ -213,7 +193,7 @@
         {
           if ( !ok[featStartId[i] + j] )
           {
-            if (( lp = labelpositions[featStartId[i] + j] )->nbOverlap == 0 ) // if candidate has no overlap
+            if (( lp = labelpositions[featStartId[i] + j] )->getNumOverlaps() == 0 ) // if candidate has no overlap
             {
               run = true;
               ok[featStartId[i] + j] = true;
@@ -228,24 +208,10 @@
                 ok[lpid] = true;
                 lp2 = labelpositions[lpid];
 
-                amin[0] = DBL_MAX;
-                amax[0] = -DBL_MAX;
-                amin[1] = DBL_MAX;
-                amax[1] = -DBL_MAX;
-                for ( c = 0;c < 4;c++ )
-                {
-                  if ( lp2->x[c] < amin[0] )
-                    amin[0] = lp2->x[c];
-                  if ( lp2->x[c] > amax[0] )
-                    amax[0] = lp2->x[c];
-                  if ( lp2->y[c] < amin[1] )
-                    amin[1] = lp2->y[c];
-                  if ( lp2->y[c] > amax[1] )
-                    amax[1] = lp2->y[c];
-                }
+                lp2->getBoundingBox(amin, amax);
 
-                nbOverlap -= lp2->nbOverlap;
-                candidates->Search( amin, amax, removeOverlapCallback, ( void* ) lp2 );
+                nbOverlap -= lp2->getNumOverlaps();
+                candidates->Search( amin, amax, LabelPosition::removeOverlapCallback, ( void* ) lp2 );
                 lp2->removeFromIndex( candidates );
               }
 
@@ -304,9 +270,9 @@
     LabelPosition *lp2 = (( FalpContext* ) ctx )->lp;
     PriorityQueue *list = (( FalpContext* ) ctx )->list;
 
-    if ( lp->id != lp2->id && list->isIn( lp->id ) && lp->isInConflict( lp2 ) )
+    if ( lp->getId() != lp2->getId() && list->isIn( lp->getId() ) && lp->isInConflict( lp2 ) )
     {
-      list->decreaseKey( lp->id );
+      list->decreaseKey( lp->getId() );
     }
     return true;
   }
@@ -323,25 +289,12 @@
     double amax[2];
     int c;
 
-    if ( list->isIn( lp->id ) )
+    if ( list->isIn( lp->getId() ) )
     {
-      list->remove( lp->id );
+      list->remove( lp->getId() );
 
-      amin[0] = DBL_MAX;
-      amax[0] = -DBL_MAX;
-      amin[1] = DBL_MAX;
-      amax[1] = -DBL_MAX;
-      for ( c = 0;c < 4;c++ )
-      {
-        if ( lp->x[c] < amin[0] )
-          amin[0] = lp->x[c];
-        if ( lp->x[c] > amax[0] )
-          amax[0] = lp->x[c];
-        if ( lp->y[c] < amin[1] )
-          amin[1] = lp->y[c];
-        if ( lp->y[c] > amax[1] )
-          amax[1] = lp->y[c];
-      }
+      lp->getBoundingBox(amin, amax);
+
       context->lp = lp;
       candidates->Search( amin, amax, falpCallback2, context );
     }
@@ -396,7 +349,7 @@
       for ( j = 0;j < featNbLp[i];j++ )
       {
         label = featStartId[i] + j;
-        list->insert( label, ( double ) labelpositions[label]->nbOverlap );
+        list->insert( label, ( double ) labelpositions[label]->getNumOverlaps() );
       }
 
     while ( list->getSize() > 0 ) // O (log size)
@@ -406,40 +359,27 @@
 
       lp = labelpositions[label];
 
-      if ( lp->id != label )
+      if ( lp->getId() != label )
       {
-        std::cout << "Error: " << lp->id << " <--> " << label << std::endl;
+        std::cout << "Error: " << lp->getId() << " <--> " << label << std::endl;
       }
 
+      int probFeatId = lp->getProblemFeatureId();
+      sol->s[probFeatId] = label;
 
-      sol->s[lp->probFeat] = label;
-
 #ifdef _DEBUG_FULL_
       std::cout << "sol->s[" << lp->probFeat << "] :" << label << std::endl;
 #endif
 
-      for ( i = featStartId[lp->probFeat];i < featStartId[lp->probFeat] + featNbLp[lp->probFeat];i++ )
+      for ( i = featStartId[probFeatId];i < featStartId[probFeatId] + featNbLp[probFeatId];i++ )
       {
         ignoreLabel( labelpositions[i], list, candidates );
 
       }
 
 
-      amin[0] = DBL_MAX;
-      amax[0] = -DBL_MAX;
-      amin[1] = DBL_MAX;
-      amax[1] = -DBL_MAX;
-      for ( c = 0;c < 4;c++ )
-      {
-        if ( lp->x[c] < amin[0] )
-          amin[0] = lp->x[c];
-        if ( lp->x[c] > amax[0] )
-          amax[0] = lp->x[c];
-        if ( lp->y[c] < amin[1] )
-          amin[1] = lp->y[c];
-        if ( lp->y[c] > amax[1] )
-          amax[1] = lp->y[c];
-      }
+      lp->getBoundingBox(amin, amax);
+
       context->lp = lp;
       candidates->Search( amin, amax, falpCallback1, ( void* ) context );
       candidates_sol->Insert( amin, amax, lp );
@@ -466,33 +406,20 @@
           for ( p = 0;p < featNbLp[i];p++ )
           {
             lp = labelpositions[start_p+p];
-            lp->nbOverlap = 0;
-            amin[0] = DBL_MAX;
-            amax[0] = -DBL_MAX;
-            amin[1] = DBL_MAX;
-            amax[1] = -DBL_MAX;
-            for ( c = 0;c < 4;c++ )
-            {
-              if ( lp->x[c] < amin[0] )
-                amin[0] = lp->x[c];
-              if ( lp->x[c] > amax[0] )
-                amax[0] = lp->x[c];
-              if ( lp->y[c] < amin[1] )
-                amin[1] = lp->y[c];
-              if ( lp->y[c] > amax[1] )
-                amax[1] = lp->y[c];
-            }
+            lp->resetNumOverlaps();
 
+            lp->getBoundingBox(amin, amax);
 
-            candidates_sol->Search( amin, amax, countOverlapCallback, lp );
 
-            if ( lp->nbOverlap < nbOverlap )
+            candidates_sol->Search( amin, amax, LabelPosition::countOverlapCallback, lp );
+
+            if ( lp->getNumOverlaps() < nbOverlap )
             {
               retainedLabel = lp;
-              nbOverlap = lp->nbOverlap;
+              nbOverlap = lp->getNumOverlaps();
             }
           }
-          sol->s[i] = retainedLabel->id;
+          sol->s[i] = retainedLabel->getId();
 
           retainedLabel->insertIntoIndex( candidates_sol );
 
@@ -724,7 +651,7 @@
     LinkedList<int> *queue = (( SubPartContext* ) ctx )->queue;
 
 
-    int id = lp->probFeat;
+    int id = lp->getProblemFeatureId();
     if ( !isIn[id] && lp->isInConflict((( SubPartContext* ) ctx )->lp ) )
     {
       queue->push_back( id );
@@ -774,21 +701,9 @@
       for ( i = featS;i < featS + p;i++ )  // foreach candidat of feature 'id'
       {
         lp = labelpositions[i];
-        amin[0] = DBL_MAX;
-        amax[0] = -DBL_MAX;
-        amin[1] = DBL_MAX;
-        amax[1] = -DBL_MAX;
-        for ( c = 0;c < 4;c++ )
-        {
-          if ( lp->x[c] < amin[0] )
-            amin[0] = lp->x[c];
-          if ( lp->x[c] > amax[0] )
-            amax[0] = lp->x[c];
-          if ( lp->y[c] < amin[1] )
-            amin[1] = lp->y[c];
-          if ( lp->y[c] > amax[1] )
-            amax[1] = lp->y[c];
-        }
+
+        lp->getBoundingBox(amin, amax);
+
         context.lp = lp;
         candidates->Search( amin, amax, subPartCallback, ( void* ) &context );
       }
@@ -839,7 +754,7 @@
 
     int c;
 
-    CountContext context;
+    LabelPosition::CountContext context;
     context.inactiveCost = inactiveCost;
     context.nbOv = nbOverlap;
     context.cost = &cost;
@@ -854,25 +769,12 @@
     {
       lp = labelpositions[label_id];
 
-      amin[0] = DBL_MAX;
-      amax[0] = -DBL_MAX;
-      amin[1] = DBL_MAX;
-      amax[1] = -DBL_MAX;
-      for ( c = 0;c < 4;c++ )
-      {
-        if ( lp->x[c] < amin[0] )
-          amin[0] = lp->x[c];
-        if ( lp->x[c] > amax[0] )
-          amax[0] = lp->x[c];
-        if ( lp->y[c] < amin[1] )
-          amin[1] = lp->y[c];
-        if ( lp->y[c] > amax[1] )
-          amax[1] = lp->y[c];
-      }
+      lp->getBoundingBox(amin, amax);
+
       context.lp = lp;
-      candidates_subsol->Search( amin, amax, countFullOverlapCallback, ( void* ) &context );
+      candidates_subsol->Search( amin, amax, LabelPosition::countFullOverlapCallback, ( void* ) &context );
 
-      cost += lp->cost;
+      cost += lp->getCost();
     }
     else
     {
@@ -980,15 +882,15 @@
 
     if ( ctx->lp->isInConflict( lp ) )
     {
-      ctx->labelPositionCost[lp->id] += ctx->diff_cost;
+      ctx->labelPositionCost[lp->getId()] += ctx->diff_cost;
       if ( ctx->diff_cost > 0 )
-        ctx->nbOlap[lp->id]++;
+        ctx->nbOlap[lp->getId()]++;
       else
-        ctx->nbOlap[lp->id]--;
+        ctx->nbOlap[lp->getId()]--;
 
-      int feat_id = ctx->featWrap[ctx->lp->probFeat];
+      int feat_id = ctx->featWrap[ctx->lp->getProblemFeatureId()];
       int feat_id2;
-      if ( feat_id >= 0 && ctx->sol[feat_id] == lp->id ) // this label is in use
+      if ( feat_id >= 0 && ctx->sol[feat_id] == lp->getId() ) // this label is in use
       {
         if (( feat_id2 = feat_id - ctx->borderSize ) >= 0 )
         {
@@ -1184,13 +1086,13 @@
             else
             {
               delta = -labelPositionCost[sol[feat_id]];
-              delta -= nbOlap[sol[feat_id]] * ( inactiveCost[feat_sub_id] + labelpositions[label_id]->cost );
+              delta -= nbOlap[sol[feat_id]] * ( inactiveCost[feat_sub_id] + labelpositions[label_id]->getCost() );
             }
 
             if ( j >= 0 )
             {
               delta += labelPositionCost[featStartId[feat_sub_id] + j];
-              delta += nbOlap[featStartId[feat_sub_id] + j] * ( inactiveCost[feat_sub_id] + labelpositions[featStartId[feat_sub_id] + j]->cost );
+              delta += nbOlap[featStartId[feat_sub_id] + j] * ( inactiveCost[feat_sub_id] + labelpositions[featStartId[feat_sub_id] + j]->getCost() );
             }
             else
             {
@@ -1305,23 +1207,9 @@
         {
           lp = labelpositions[old_label];
 
+          lp->getBoundingBox(amin, amax);
 
-          amin[0] = DBL_MAX;
-          amax[0] = -DBL_MAX;
-          amin[1] = DBL_MAX;
-          amax[1] = -DBL_MAX;
-          for ( c = 0;c < 4;c++ )
-          {
-            if ( lp->x[c] < amin[0] )
-              amin[0] = lp->x[c];
-            if ( lp->x[c] > amax[0] )
-              amax[0] = lp->x[c];
-            if ( lp->y[c] < amin[1] )
-              amin[1] = lp->y[c];
-            if ( lp->y[c] > amax[1] )
-              amax[1] = lp->y[c];
-          }
-          context.diff_cost = -local_inactive - labelpositions[old_label]->cost;
+          context.diff_cost = -local_inactive - labelpositions[old_label]->getCost();
           context.lp = labelpositions[old_label];
 
           candidates->Search( amin, amax, updateCandidatesCost, &context );
@@ -1331,24 +1219,9 @@
         {
           lp = labelpositions[choosed_label];
 
+          lp->getBoundingBox(amin, amax);
 
-          amin[0] = DBL_MAX;
-          amax[0] = -DBL_MAX;
-          amin[1] = DBL_MAX;
-          amax[1] = -DBL_MAX;
-          for ( c = 0;c < 4;c++ )
-          {
-            if ( lp->x[c] < amin[0] )
-              amin[0] = lp->x[c];
-            if ( lp->x[c] > amax[0] )
-              amax[0] = lp->x[c];
-            if ( lp->y[c] < amin[1] )
-              amin[1] = lp->y[c];
-            if ( lp->y[c] > amax[1] )
-              amax[1] = lp->y[c];
-          }
-
-          context.diff_cost = local_inactive + labelpositions[choosed_label]->cost;
+          context.diff_cost = local_inactive + labelpositions[choosed_label]->getCost();
           context.lp = labelpositions[choosed_label];
 
 
@@ -1449,7 +1322,7 @@
       int feat, rfeat;
       bool sub = ctx->featWrap != NULL;
 
-      feat = lp->probFeat;
+      feat = lp->getProblemFeatureId();
       if ( sub )
       {
         rfeat = feat;
@@ -1463,7 +1336,7 @@
       std::cout << "    sol: " << ctx->tmpsol[feat] << "/" << lp->id << std::endl;
       std::cout << "    border:" << ctx->borderSize << std::endl;
 #endif
-      if ( feat >= 0 && ctx->tmpsol[feat] == lp->id )
+      if ( feat >= 0 && ctx->tmpsol[feat] == lp->getId() )
       {
         if ( sub && feat < ctx->borderSize )
         {
@@ -1492,7 +1365,7 @@
       if ( !ctx->conflicts->isIn( feat ) )
       {
         ctx->conflicts->push_back( feat );
-        *ctx->delta_tmp += lp->cost + ctx->inactiveCost[rfeat];
+        *ctx->delta_tmp += lp->getCost() + ctx->inactiveCost[rfeat];
       }
     }
     return true;
@@ -1563,7 +1436,7 @@
       if ( tmpsol[seed] == -1 )
         delta -= inactiveCost[subseed];
       else
-        delta -= labelpositions[tmpsol[seed]]->cost;
+        delta -= labelpositions[tmpsol[seed]]->getCost();
 
       // TODO modify to handle displayAll param
       for ( i = -1;i < seedNbLp;i++ )
@@ -1581,21 +1454,8 @@
               lp = labelpositions[lid];
 
               // evaluate conflicts graph in solution after moving seed's label
-              amin[0] = DBL_MAX;
-              amax[0] = -DBL_MAX;
-              amin[1] = DBL_MAX;
-              amax[1] = -DBL_MAX;
-              for ( c = 0;c < 4;c++ )
-              {
-                if ( lp->x[c] < amin[0] )
-                  amin[0] = lp->x[c];
-                if ( lp->x[c] > amax[0] )
-                  amax[0] = lp->x[c];
-                if ( lp->y[c] < amin[1] )
-                  amin[1] = lp->y[c];
-                if ( lp->y[c] > amax[1] )
-                  amax[1] = lp->y[c];
-              }
+              lp->getBoundingBox(amin, amax);
+
               context.lp = lp;
 
               if ( conflicts->size() != 0 )
@@ -1610,7 +1470,7 @@
               // no conflict -> end of chain
               if ( conflicts->size() == 0 )
               {
-                if ( !retainedChain || delta + labelpositions[lid]->cost < delta_best )
+                if ( !retainedChain || delta + labelpositions[lid]->getCost() < delta_best )
                 {
 
                   if ( retainedChain )
@@ -1623,7 +1483,7 @@
                     retainedChain = new Chain(); // HERE
                   }
 
-                  delta_best = delta + labelpositions[lid]->cost;
+                  delta_best = delta + labelpositions[lid]->getCost();
 
                   retainedChain->degree = currentChain->size() + 1;
                   retainedChain->feat  = new int[retainedChain->degree]; // HERE
@@ -1641,7 +1501,7 @@
                   }
                   retainedChain->feat[j] = seed;
                   retainedChain->label[j] = lid;
-                  retainedChain->delta = delta + labelpositions[retainedChain->label[j]]->cost;
+                  retainedChain->delta = delta + labelpositions[retainedChain->label[j]]->getCost();
                 }
               }
 
@@ -1681,7 +1541,7 @@
 
                 newChain->feat[j] = seed;
                 newChain->label[j] = lid;
-                newChain->delta = delta + labelpositions[newChain->label[j]]->cost;
+                newChain->delta = delta + labelpositions[newChain->label[j]]->getCost();
                 j++;
 
 
@@ -1785,7 +1645,7 @@
         }
 
         tmpsol[seed] = retainedLabel;
-        delta += labelpositions[retainedLabel]->cost;
+        delta += labelpositions[retainedLabel]->getCost();
         seed = next_seed;
       }
     }
@@ -1871,7 +1731,7 @@
       if ( tmpsol[seed] == -1 )
         delta -= inactiveCost[seed];
       else
-        delta -= labelpositions[tmpsol[seed]]->cost;
+        delta -= labelpositions[tmpsol[seed]]->getCost();
 
       for ( i = -1;i < seedNbLp;i++ )
       {
@@ -1888,21 +1748,8 @@
               lp = labelpositions[lid];
 
               // evaluate conflicts graph in solution after moving seed's label
-              amin[0] = DBL_MAX;
-              amax[0] = -DBL_MAX;
-              amin[1] = DBL_MAX;
-              amax[1] = -DBL_MAX;
-              for ( c = 0;c < 4;c++ )
-              {
-                if ( lp->x[c] < amin[0] )
-                  amin[0] = lp->x[c];
-                if ( lp->x[c] > amax[0] )
-                  amax[0] = lp->x[c];
-                if ( lp->y[c] < amin[1] )
-                  amin[1] = lp->y[c];
-                if ( lp->y[c] > amax[1] )
-                  amax[1] = lp->y[c];
-              }
+              lp->getBoundingBox(amin, amax);
+
               context.lp = lp;
               if ( conflicts->size() != 0 )
                 std::cerr << "Conflicts not empty" << std::endl;
@@ -1912,7 +1759,7 @@
               // no conflict -> end of chain
               if ( conflicts->size() == 0 )
               {
-                if ( !retainedChain || delta + labelpositions[lid]->cost < delta_best )
+                if ( !retainedChain || delta + labelpositions[lid]->getCost() < delta_best )
                 {
                   if ( retainedChain )
                   {
@@ -1924,7 +1771,7 @@
                     retainedChain = new Chain();
                   }
 
-                  delta_best = delta + labelpositions[lid]->cost;
+                  delta_best = delta + labelpositions[lid]->getCost();
 
                   retainedChain->degree = currentChain->size() + 1;
                   retainedChain->feat  = new int[retainedChain->degree];
@@ -1942,7 +1789,7 @@
                   }
                   retainedChain->feat[j] = seed;
                   retainedChain->label[j] = lid;
-                  retainedChain->delta = delta + labelpositions[lid]->cost;
+                  retainedChain->delta = delta + labelpositions[lid]->getCost();
                 }
               }
 
@@ -1984,7 +1831,7 @@
                 // add the current candidates into the chain
                 newChain->feat[j] = seed;
                 newChain->label[j] = lid;
-                newChain->delta = delta + labelpositions[newChain->label[j]]->cost;
+                newChain->delta = delta + labelpositions[newChain->label[j]]->getCost();
                 j++;
 
                 // hide all conflictual candidates
@@ -2088,7 +1935,7 @@
 
 
         tmpsol[seed] = retainedLabel;
-        delta += labelpositions[retainedLabel]->cost;
+        delta += labelpositions[retainedLabel]->getCost();
         seed = next_seed;
       }
     }
@@ -2367,7 +2214,7 @@
       candidates[i]->feat_id = i + borderSize;
       candidatesUnsorted[i] = candidates[i];
 
-      candidates[i]->cost = ( sol[i+borderSize] == -1 ? inactiveCost[i+borderSize] : labelpositions[sol[i+borderSize]]->cost );
+      candidates[i]->cost = ( sol[i+borderSize] == -1 ? inactiveCost[i+borderSize] : labelpositions[sol[i+borderSize]]->getCost() );
     }
 
     sort(( void** ) candidates, probSize, decreaseCost );
@@ -2492,7 +2339,7 @@
             std::cout << "label[lid]->cost: " << labelpositions[lid]->cost << std::endl;
           }
 #endif
-          candidatesUnsorted[fid-borderSize]->cost = ( lid == -1 ? inactiveCost[sub[fid]] : labelpositions[lid]->cost );
+          candidatesUnsorted[fid-borderSize]->cost = ( lid == -1 ? inactiveCost[sub[fid]] : labelpositions[lid]->getCost() );
 
         }
 
@@ -2602,15 +2449,16 @@
 
     while ( list->size() > 0 )
     {
+      int probFeatId = lp->getProblemFeatureId();
       lp = list->pop_front();
-      if ( solution[lp->probFeat] >= 0 )
+      if ( solution[probFeatId] >= 0 )
       {
-        std::cerr << "Doublon : " << lp->probFeat << " "
-                  << solution[lp->probFeat]  << "<->"
-                  << lp->id << std::endl;
+        std::cerr << "Doublon : " << probFeatId << " "
+                  << solution[probFeatId]  << "<->"
+                  << lp->getId() << std::endl;
       }
 
-      solution[lp->probFeat] = lp->id;
+      solution[probFeatId] = lp->getId();
       //std::cout << "lp->id:" << lp->id <<;
     }
 
@@ -2641,11 +2489,11 @@
     {
       if ( wrap )
       {
-        ok[wrap[lp->probFeat]] = false;
+        ok[wrap[lp->getProblemFeatureId()]] = false;
       }
       else
       {
-        ok[lp->probFeat] = false;
+        ok[lp->getProblemFeatureId()] = false;
       }
     }
 
@@ -2911,23 +2759,8 @@
             LabelPosition *old = labelpositions[sol->s[fid]];
             old->removeFromIndex( candidates_sol );
 
+            old->getBoundingBox(amin, amax);
 
-            amin[0] = DBL_MAX;
-            amax[0] = -DBL_MAX;
-            amin[1] = DBL_MAX;
-            amax[1] = -DBL_MAX;
-            for ( c = 0;c < 4;c++ )
-            {
-              if ( old->x[c] < amin[0] )
-                amin[0] = old->x[c];
-              if ( old->x[c] > amax[0] )
-                amax[0] = old->x[c];
-              if ( old->y[c] < amin[1] )
-                amin[1] = old->y[c];
-              if ( old->y[c] > amax[1] )
-                amax[1] = old->y[c];
-            }
-
             context.lp = old;
             candidates->Search( amin, amax, nokCallback, &context );
           }
@@ -3085,21 +2918,7 @@
             LabelPosition *old = labelpositions[sol[fid]];
             old->removeFromIndex( candidates_subsol );
 
-            amin[0] = DBL_MAX;
-            amax[0] = -DBL_MAX;
-            amin[1] = DBL_MAX;
-            amax[1] = -DBL_MAX;
-            for ( c = 0;c < 4;c++ )
-            {
-              if ( old->x[c] < amin[0] )
-                amin[0] = old->x[c];
-              if ( old->x[c] > amax[0] )
-                amax[0] = old->x[c];
-              if ( old->y[c] < amin[1] )
-                amin[1] = old->y[c];
-              if ( old->y[c] > amax[1] )
-                amax[1] = old->y[c];
-            }
+            old->getBoundingBox(amin, amax);
 
             context.lp = old;
             candidates->Search( amin, amax, nokCallback, &context );
@@ -3186,7 +3005,7 @@
     int k;
     for ( i = 0;i < nbft;i++ )
     {
-      lyrName = labelpositions[featStartId[i]]->feature->layer->name;
+      lyrName = labelpositions[featStartId[i]]->getLayerName();
       k = -1;
       for ( j = 0;j < stats->nbLayers;j++ )
       {
@@ -3304,10 +3123,9 @@
 
     int nbOv;
 
-    int c;
     int i;
 
-    CountContext context;
+    LabelPosition::CountContext context;
     context.inactiveCost = inactiveCost;
     context.nbOv = &nbOv;
     context.cost = &sol->cost;
@@ -3329,25 +3147,12 @@
         nbOv = 0;
         lp = labelpositions[sol->s[i]];
 
-        amin[0] = DBL_MAX;
-        amax[0] = -DBL_MAX;
-        amin[1] = DBL_MAX;
-        amax[1] = -DBL_MAX;
-        for ( c = 0;c < 4;c++ )
-        {
-          if ( lp->x[c] < amin[0] )
-            amin[0] = lp->x[c];
-          if ( lp->x[c] > amax[0] )
-            amax[0] = lp->x[c];
-          if ( lp->y[c] < amin[1] )
-            amin[1] = lp->y[c];
-          if ( lp->y[c] > amax[1] )
-            amax[1] = lp->y[c];
-        }
+        lp->getBoundingBox(amin, amax);
+
         context.lp = lp;
-        candidates_sol->Search( amin, amax, countFullOverlapCallback, &context );
+        candidates_sol->Search( amin, amax, LabelPosition::countFullOverlapCallback, &context );
 
-        sol->cost += lp->cost;
+        sol->cost += lp->getCost();
 
         if ( nbOv == 0 )
           nbActive++;

Modified: branches/symbology-ng-branch/src/core/pal/util.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/util.cpp	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/util.cpp	2009-07-11 16:32:37 UTC (rev 11044)
@@ -185,39 +185,7 @@
 
 
 
-  bool countOverlapCallback( LabelPosition *lp, void *ctx )
-  {
-    LabelPosition *lp2 = ( LabelPosition* ) ctx;
 
-    if ( lp2->isInConflict( lp ) )
-    {
-      lp2->nbOverlap++;
-    }
-
-    return true;
-  }
-
-  bool countFullOverlapCallback( LabelPosition *lp, void *ctx )
-  {
-    LabelPosition *lp2 = (( CountContext* ) ctx )->lp;
-    double *cost = (( CountContext* ) ctx )->cost;
-    //int *feat = ((CountContext*)ctx)->feat;
-    int *nbOv = (( CountContext* ) ctx )->nbOv;
-    double *inactiveCost = (( CountContext* ) ctx )->inactiveCost;
-    if ( lp2->isInConflict( lp ) )
-    {
-#ifdef _DEBUG_FULL_
-      std::cout <<  "count overlap : " << lp->id << "<->" << lp2->id << std::endl;
-#endif
-      ( *nbOv ) ++;
-      *cost += inactiveCost[lp->probFeat] + lp->cost;
-
-    }
-
-    return true;
-  }
-
-
 //inline bool ptrGeomEq (const geos::geom::Geometry *l, const geos::geom::Geometry *r){
   inline bool ptrGeomEq( const GEOSGeometry *l, const GEOSGeometry *r )
   {

Modified: branches/symbology-ng-branch/src/core/pal/util.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/util.h	2009-07-11 12:37:27 UTC (rev 11043)
+++ branches/symbology-ng-branch/src/core/pal/util.h	2009-07-11 16:32:37 UTC (rev 11044)
@@ -298,22 +298,6 @@
                const double* const prob, int *cx, int *cy, double *p );
 
 
-  typedef struct
-  {
-    LabelPosition *lp;
-    int *nbOv;
-    double *cost;
-    double *inactiveCost;
-    //int *feat;
-  } CountContext;
-
-  /*
-   * count overlap, ctx = p_lp
-   */
-  bool countOverlapCallback( LabelPosition *lp, void *ctx );
-
-  bool countFullOverlapCallback( LabelPosition *lp, void *ctx );
-
 } // namespace
 
 #endif



More information about the QGIS-commit mailing list