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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Jul 4 09:25:43 EDT 2009


Author: wonder
Date: 2009-07-04 09:25:43 -0400 (Sat, 04 Jul 2009)
New Revision: 11018

Modified:
   branches/symbology-ng-branch/src/core/pal/labelposition.h
   branches/symbology-ng-branch/src/core/pal/pal.cpp
   branches/symbology-ng-branch/src/core/pal/pal.h
   branches/symbology-ng-branch/src/core/pal/problem.h
   branches/symbology-ng-branch/src/core/pal/util.cpp
Log:
pal: added functions for more granular access to labeling. added possibility to use only initial solution (FALP algorithm). Added some timing.


Modified: branches/symbology-ng-branch/src/core/pal/labelposition.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-07-04 11:23:44 UTC (rev 11017)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-07-04 13:25:43 UTC (rev 11018)
@@ -103,6 +103,7 @@
       //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
        *
@@ -181,6 +182,8 @@
        */
       double getY();
 
+      double getWidth() { return w; }
+      double getHeight() { return h; }
 
       /**
        * \brief get alpha

Modified: branches/symbology-ng-branch/src/core/pal/pal.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pal.cpp	2009-07-04 11:23:44 UTC (rev 11017)
+++ branches/symbology-ng-branch/src/core/pal/pal.cpp	2009-07-04 13:25:43 UTC (rev 11018)
@@ -31,6 +31,10 @@
 #include <config.h>
 #endif
 
+//#define _VERBOSE_
+//#define _EXPORT_MAP_
+#include <QTime>
+
 #define _CRT_SECURE_NO_DEPRECATE
 
 #include <cstdarg>
@@ -38,7 +42,6 @@
 #include <fstream>
 #include <cstring>
 #include <cfloat>
-#include <ctime>
 #include <list>
 //#include <geos/geom/Geometry.h>
 #include <geos_c.h>
@@ -114,7 +117,6 @@
     std::cout.precision( 12 );
     std::cerr.precision( 12 );
 
-    tmpTime = 0;
   }
 
   std::list<Layer*> *Pal::getLayers()
@@ -154,8 +156,6 @@
   Pal::~Pal()
   {
 
-    std::cout << "Acces/Concvert time: " << ( double ) tmpTime / CLOCKS_PER_SEC << std::endl;
-
     lyrsMutex->lock();
     while ( layers->size() > 0 )
     {
@@ -280,6 +280,9 @@
 
         LinkedList<Feats*> *feats = new LinkedList<Feats*> ( ptrFeatsCompare );
 
+          QTime t;
+          t.start();
+
         if (( ft_ptr->type == GEOS_LINESTRING )
             || ft_ptr->type == GEOS_POLYGON )
         {
@@ -301,8 +304,6 @@
           ft_ptr->releaseCoordinates();
 
 
-
-
           if ( inside )
           {
             // no extra treatment required
@@ -771,7 +772,6 @@
     delete context;
     lyrsMutex->unlock();
 
-
     prob->nbLabelledLayers = labLayers->size();
     prob->labelledLayersName = new char*[prob->nbLabelledLayers];
     for ( i = 0;i < prob->nbLabelledLayers;i++ )
@@ -980,13 +980,6 @@
               << prob->nbOverlap << "\t";
 #endif
 
-    prob->reduce();
-
-#ifdef _VERBOSE_
-    std::cerr << prob->nblp << "\t"
-              << prob->nbOverlap;
-#endif
-
     return prob;
   }
 
@@ -1063,6 +1056,9 @@
     << "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,
@@ -1092,6 +1088,19 @@
       return new std::list<Label*>();
     }
 
+    std::cout << "PAL EXTRACT: " << t.elapsed() / 1000.0 << " s" << std::endl;
+    t.restart();
+
+    // reduce number of candidates
+    // (remove candidates which surely won't be used)
+    prob->reduce();
+
+#ifdef _VERBOSE_
+    std::cerr << prob->nblp << "\t"
+              << prob->nbOverlap;
+#endif
+
+
     prob->displayAll = displayAll;
 
 #ifdef _VERBOSE_
@@ -1102,11 +1111,16 @@
 #endif
 
     // search a solution
-    if ( searchMethod != CHAIN )
+    if ( searchMethod == FALP )
+      prob->init_sol_falp();
+    else if ( searchMethod == CHAIN )
+      prob->chain_search();
+    else
       prob->popmusic();
-    else
-      prob->chain_search();
 
+    std::cout << "PAL SEARCH (" << searchMethod << "): " << t.elapsed() / 1000.0 << " s" << std::endl;
+    t.restart();
+
     // Post-Optimization
     //prob->post_optimization();
 
@@ -1139,6 +1153,51 @@
     return solution;
   }
 
+  Problem* Pal::extractProblem(double scale, double bbox[4])
+  {
+    // find out: nbLayers, layersName, layersFactor
+    lyrsMutex->lock();
+    int nbLayers = layers->size();
+
+    char **layersName = new char*[nbLayers];
+    double *priorities = new double[nbLayers];
+    Layer *layer;
+    int i = 0;
+    for ( std::list<Layer*>::iterator it = layers->begin(); it != layers->end();it++ )
+    {
+      layer = *it;
+      layersName[i] = layer->name;
+      priorities[i] = layer->defaultPriority;
+      i++;
+    }
+    lyrsMutex->unlock();
+
+    Problem* prob = extract( nbLayers, layersName, priorities, bbox[0], bbox[1], bbox[2], bbox[3], scale, NULL);
+
+    delete[] layersName;
+    delete[] priorities;
+
+    return prob;
+  }
+
+  std::list<Label*>* Pal::solveProblem(Problem* prob)
+  {
+    if (prob == NULL)
+      return new std::list<Label*>();
+
+    prob->reduce();
+
+    if ( searchMethod == FALP )
+      prob->init_sol_falp();
+    else if ( searchMethod == CHAIN )
+      prob->chain_search();
+    else
+      prob->popmusic();
+
+    return prob->getSolution( false );
+  }
+
+
   void Pal::setPointP( int point_p )
   {
     if ( point_p > 0 )
@@ -1268,6 +1327,9 @@
         ejChainDeg = 50;
         candListSize = 0.2;
         break;
+      case FALP:
+        searchMethod = method;
+        break;
       default:
         std::cerr << "Unknown search method..." << std::endl;
     }

Modified: branches/symbology-ng-branch/src/core/pal/pal.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pal.h	2009-07-04 11:23:44 UTC (rev 11017)
+++ branches/symbology-ng-branch/src/core/pal/pal.h	2009-07-04 13:25:43 UTC (rev 11018)
@@ -84,7 +84,8 @@
     CHAIN = 0, /**< is the worst but fastest method */
     POPMUSIC_TABU_CHAIN = 1, /**< is the best but slowest */
     POPMUSIC_TABU = 2, /**< is a little bit better than CHAIN but slower*/
-    POPMUSIC_CHAIN = 3 /**< is slower and best than TABU, worse and faster than TABU_CHAIN */
+    POPMUSIC_CHAIN = 3, /**< is slower and best than TABU, worse and faster than TABU_CHAIN */
+    FALP = 4 /** only initial solution */
   };
 
   /** Typedef for _Units enumeration */
@@ -330,6 +331,11 @@
                                    PalStat **stat,
                                    bool displayAll );
 
+
+      Problem* extractProblem(double scale, double bbox[4]);
+
+      std::list<Label*>* solveProblem(Problem* prob);
+
       /**
        * \brief Set map resolution
        *

Modified: branches/symbology-ng-branch/src/core/pal/problem.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/problem.h	2009-07-04 11:23:44 UTC (rev 11017)
+++ branches/symbology-ng-branch/src/core/pal/problem.h	2009-07-04 13:25:43 UTC (rev 11018)
@@ -170,20 +170,29 @@
       void solution_cost();
       void check_solution();
 
+  public:
       Problem();
 
       //Problem(char *lorena_file, bool displayAll);
 
       ~Problem();
 
+      /////////////////
+      // problem inspection functions
+      int getNumFeatures() { return nbft; }
+      // features counted 0...n-1
+      int getFeatureCandidateCount(int i) { return featNbLp[i]; }
+      // both features and candidates counted 0..n-1
+      LabelPosition* getFeatureCandidate(int fi, int ci) { return labelpositions[ featStartId[fi] + ci]; }
+      /////////////////
 
+
       void reduce();
 
 
       void post_optimization();
 
 
-
       /**
        * \brief popmusic framework
        */

Modified: branches/symbology-ng-branch/src/core/pal/util.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/util.cpp	2009-07-04 11:23:44 UTC (rev 11017)
+++ branches/symbology-ng-branch/src/core/pal/util.cpp	2009-07-04 13:25:43 UTC (rev 11018)
@@ -467,6 +467,7 @@
       // ignore invalid geometries (e.g. polygons with self-intersecting rings)
       if (check_valid && GEOSisValid( geom ) != 1) // 0=invalid, 1=valid, 2=exception
       {
+        std::cerr << "ignoring invalid feature " << geom_id << std::endl;
         continue;
       }
 



More information about the QGIS-commit mailing list