/home/andreas/src/svn/mapnik/include/mapnik/placement_finder.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * 
00003  * This file is part of Mapnik (c++ mapping toolkit)
00004  *
00005  * Copyright (C) 2006 Artem Pavlenko
00006  * Copyright (C) 2006 10East Corp.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  *****************************************************************************/
00023 
00024 //$Id$
00025 
00026 #ifndef __PLACEMENT_FINDER__
00027 #define __PLACEMENT_FINDER__
00028 
00029 #include <queue>
00030 
00031 #include <mapnik/ctrans.hpp>
00032 #include <mapnik/label_collision_detector.hpp>
00033 #include <mapnik/text_symbolizer.hpp>
00034 #include <mapnik/geometry.hpp>
00035 #include <mapnik/text_path.hpp>
00036 
00037 namespace mapnik
00038 {
00039 
00040    struct placement_element
00041    {
00042          double starting_x;
00043          double starting_y;
00044     
00045          text_path path;
00046    };
00047 
00048    struct placement
00049    {
00050          typedef  coord_transform2<CoordTransform,geometry_type> path_type;
00051          
00052          //For shields
00053          placement(string_info *info_, 
00054                    CoordTransform *ctrans_, 
00055                    const proj_transform *proj_trans_, 
00056                    geometry_ptr geom_, 
00057                    std::pair<double, double> dimensions_);
00058     
00059          //For text
00060          placement(string_info *info_, 
00061                    CoordTransform *ctrans_, 
00062                    const proj_transform *proj_trans_, 
00063                    geometry_ptr geom_,
00064                    position const& displacement,
00065                    label_placement_e placement_);
00066          
00067          ~placement();
00068         
00069          unsigned path_size() const;
00070          string_info *info;
00071     
00072          CoordTransform *ctrans;
00073          const proj_transform *proj_trans;
00074 
00075          geometry_ptr geom;
00076          position displacement_;
00077          label_placement_e label_placement;
00078          std::pair<double, double> dimensions;
00079 
00080          bool has_dimensions;
00081     
00082          path_type shape_path;
00083          std::queue< Envelope<double> > envelopes;
00084     
00085          //output
00086          std::vector<placement_element> placements;
00087 
00088          // caching output
00089          placement_element current_placement;
00090     
00091          //helpers
00092          std::pair<double, double> get_position_at_distance(double target_distance);
00093          double get_total_distance();
00094          void clear_envelopes();
00095     
00096          double total_distance_; //cache for distance
00097     
00098          int wrap_width;
00099          int text_ratio;
00100 
00101          int label_spacing; // distance between repeated labels on a single geometry
00102          unsigned label_position_tolerance; //distance the label can be moved on the line to fit, if 0 the default is used
00103          bool force_odd_labels; //Always try render an odd amount of labels
00104 
00105          double max_char_angle_delta;
00106     
00107          bool avoid_edges;
00108    };
00109 
00110 
00111   
00112    class placement_finder : boost::noncopyable
00113    {
00114       public:
00115          //e is the dimensions of the map, buffer is the buffer used for collission detection.
00116          placement_finder(Envelope<double> e, unsigned buffer);
00117          bool find_placements(placement *p);
00118          void clear();
00119          
00120       protected:
00121          bool find_placement_follow(placement *p);
00122          bool find_placement_horizontal(placement *p);
00123          bool build_path_follow(placement *p, double target_distance);
00124          bool build_path_horizontal(placement *p, double target_distance);
00125          void update_detector(placement *p);
00126          Envelope<double> dimensions_;
00127          label_collision_detector3 detector_;
00128    };  
00129 }
00130 
00131 #endif
00132 

Generated on Thu Jul 19 17:59:27 2007 for Mapnik by  doxygen 1.4.7