Exemplo n.º 1
0
	bool intersects(PRECISION x, PRECISION y) const {
		if (x < minx() || maxx() < x || y < miny() || maxy() < y) {
			return false;
		} else {
			return true;
		}
	}
Exemplo n.º 2
0
    // arrange group members in x horizontal pairs of 2,
    // one to the left and one to the right of center in each pair
    void operator()(pair_layout const& layout) const
    {
        member_offsets_.resize(member_boxes_.size());
        double y_margin = layout.get_item_margin();
        double x_margin = y_margin / 2.0;

        if (member_boxes_.size() == 1)
        {
            member_offsets_[0] = pixel_position(0, 0) - input_origin_;
            return;
        }

        auto max_diff = layout.get_max_difference();
        auto layout_box = make_horiz_pair(0, 0.0, 0, x_margin, max_diff);
        auto y_shift = 0.5 * layout_box.height();

        for (size_t i = 2; i < member_boxes_.size(); i += 2)
        {
            auto y = layout_box.maxy() + y_margin;
            auto pair_box = make_horiz_pair(i, y, 1, x_margin, max_diff);
            layout_box.expand_to_include(pair_box);
        }

        // layout_box.center corresponds to the center of the first row;
        // shift offsets so that the whole group is centered vertically

        y_shift -= 0.5 * layout_box.height();

        for (auto & offset : member_offsets_)
        {
            offset.y += y_shift;
        }
    }
Exemplo n.º 3
0
bool Rect::intersects(const Rect& other) const {
    if (other.maxx() < minx() || other.minx() > maxx() ||
            other.maxy() < miny() || other.miny() > maxy()) {
        return false;
    } else {
        return true;
    }
}
Exemplo n.º 4
0
 // Offsets member bound box at [i] and align with (x, y), in direction <x_dir, y_dir>
 // stores corresponding offset, and returns modified bounding box
 bound_box box_offset_align(size_t i, double x, double y, int x_dir, int y_dir) const
 {
     auto box = member_boxes_[i];
     auto & offset = member_offsets_[i];
     offset.x = x - (x_dir == 0 ? input_origin_.x : (x_dir < 0 ? box.maxx() : box.minx()));
     offset.y = y - (y_dir == 0 ? input_origin_.y : (y_dir < 0 ? box.maxy() : box.miny()));
     box.move(offset.x, offset.y);
     return box;
 }
Exemplo n.º 5
0
 types::ndarray<T,N - 1 >
 max(types::ndarray<T,N> const& array, long axis)
 {
     if(axis<0 || axis >=long(N))
         throw types::ValueError("axis out of bounds");
     auto shape = array.shape;
     if(axis==0)
     {
         types::array<long, N> shp;
         shp[0] = 1;
         std::copy(shape.begin() + 1, shape.end(), shp.begin() + 1);
         types::ndarray<T,N> out(shp, std::numeric_limits<T>::lowest());
         return std::accumulate(array.begin(), array.end(), *out.begin(), numpy::proxy::maximum());
     }
     else
     {
         types::array<long, N-1> shp;
         std::copy(shape.begin(), shape.end() - 1, shp.begin());
         types::ndarray<T,N-1> maxy(shp, __builtin__::None);
         std::transform(array.begin(), array.end(), maxy.begin(), [=](types::ndarray<T,N-1> const& other) {return max(other, axis-1);});
         return maxy;
     }
 }
Exemplo n.º 6
0
/*
 * Intoarce coordonata x a centrului figurii.
 */
double get_centery()
{
    return miny()+(maxy()-miny())/2;
}
Exemplo n.º 7
0
bool Rect::containsPoint(Point point) const {
    return point.x >= minx() && point.x <= maxx() && point.y >= miny() &&
           point.y <= maxy();
}
Exemplo n.º 8
0
int main (int argc, char** argv)
{
    //using namespace mapnik;
    namespace po = boost::program_options;
    bool verbose = false;
    bool validate_features = false;
    unsigned int depth = DEFAULT_DEPTH;
    double ratio = DEFAULT_RATIO;
    std::vector<std::string> files;
    char separator = 0;
    char quote = 0;
    std::string manual_headers;
    try
    {
        po::options_description desc("Mapnik CSV/GeoJSON index utility");
        desc.add_options()
            ("help,h", "produce usage message")
            ("version,V","print version string")
            ("verbose,v","verbose output")
            ("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)")
            ("ratio,r",po::value<double>(),"split ratio (default 0.55)")
            ("separator,s", po::value<char>(), "CSV columns separator")
            ("quote,q", po::value<char>(), "CSV columns quote")
            ("manual-headers,H", po::value<std::string>(), "CSV manual headers string")
            ("files",po::value<std::vector<std::string> >(),"Files to index: file1 file2 ...fileN")
            ("validate-features", "Validate GeoJSON features")
            ;

        po::positional_options_description p;
        p.add("files",-1);
        po::variables_map vm;
        po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
        po::notify(vm);

        if (vm.count("version"))
        {
            std::clog << "version 1.0.0" << std::endl;
            return 1;
        }
        if (vm.count("help"))
        {
            std::clog << desc << std::endl;
            return 1;
        }
        if (vm.count("verbose"))
        {
            verbose = true;
        }
        if (vm.count("validate-features"))
        {
            validate_features = true;
        }
        if (vm.count("depth"))
        {
            depth = vm["depth"].as<unsigned int>();
        }
        if (vm.count("ratio"))
        {
            ratio = vm["ratio"].as<double>();
        }
        if (vm.count("separator"))
        {
            separator = vm["separator"].as<char>();
        }
        if (vm.count("quote"))
        {
            quote = vm["quote"].as<char>();
        }
        if (vm.count("manual-headers"))
        {
            manual_headers = vm["manual-headers"].as<std::string>();
        }
        if (vm.count("files"))
        {
            files=vm["files"].as<std::vector<std::string> >();
        }
    }
    catch (std::exception const& ex)
    {
        std::clog << "Error: " << ex.what() << std::endl;
        return EXIT_FAILURE;
    }

    std::vector<std::string> files_to_process;

    for (auto const& filename : files)
    {
        if (!mapnik::util::exists(filename))
        {
            continue;
        }

        if (mapnik::detail::is_csv(filename) || mapnik::detail::is_geojson(filename))
        {
            files_to_process.push_back(filename);
        }
    }

    if (files_to_process.size() == 0)
    {
        std::clog << "no files to index" << std::endl;
        return EXIT_FAILURE;
    }

    std::clog << "max tree depth:" << depth << std::endl;
    std::clog << "split ratio:" << ratio << std::endl;

    using box_type = mapnik::box2d<float>;
    using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>;

    for (auto const& filename : files_to_process)
    {
        if (!mapnik::util::exists(filename))
        {
            std::clog << "Error : file " << filename << " does not exist" << std::endl;
            continue;
        }

        std::vector<item_type> boxes;
        box_type extent;
        if (mapnik::detail::is_csv(filename))
        {
            std::clog << "processing '" << filename << "' as CSV\n";
            auto result = mapnik::detail::process_csv_file(boxes, filename, manual_headers, separator, quote);
            if (!result.first) continue;
            extent = result.second;
        }
        else if (mapnik::detail::is_geojson(filename))
        {
            std::clog << "processing '" << filename << "' as GeoJSON\n";
            auto result = mapnik::detail::process_geojson_file(boxes, filename, validate_features, verbose);
            if (!result.first)
            {
                std::clog << "Error: failed to process " << filename << std::endl;
                continue;
            }
            extent = result.second;
        }

        if (extent.valid())
        {
            std::clog << extent << std::endl;
            mapnik::box2d<double> extent_d(extent.minx(), extent.miny(), extent.maxx(), extent.maxy());
            mapnik::quad_tree<std::pair<std::size_t, std::size_t>> tree(extent_d, depth, ratio);
            for (auto const& item : boxes)
            {
                auto ext_f = std::get<0>(item);
                tree.insert(std::get<1>(item), mapnik::box2d<double>(ext_f.minx(), ext_f.miny(), ext_f.maxx(), ext_f.maxy()));
            }

            std::fstream file((filename + ".index").c_str(),
                              std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
            if (!file)
            {
                std::clog << "cannot open index file for writing file \""
                          << (filename + ".index") << "\"" << std::endl;
            }
            else
            {
                tree.trim();
                std::clog <<  "number nodes=" << tree.count() << std::endl;
                std::clog <<  "number element=" << tree.count_items() << std::endl;
                file.exceptions(std::ios::failbit | std::ios::badbit);
                tree.write(file);
                file.flush();
                file.close();
            }
        }
    }
    std::clog << "done!" << std::endl;
    return EXIT_SUCCESS;
}
Exemplo n.º 9
0
	PRECISION get_height() const { return maxy() - miny(); }
Exemplo n.º 10
0
	PRECISION get_ycenter() const { return (maxy() + miny()) / 2; }
Exemplo n.º 11
0
int EmbedVision(TopologicalGraph &G)
  {int morg = G.ne();
  if(!G.CheckConnected())G.MakeConnected();
  if(!G.FindPlanarMap())
      {Tprintf("Not Planar Graph");
      for(tedge e = G.ne(); e > morg; e--) G.DeleteEdge(e);
      return -1;
      }
  if(!G.CheckBiconnected())G.Biconnect();
  bool alreadyBipolarOriented = false;
  bool stConnected = false; 
   tvertex s,t;
   tbrin bs,bt;
   bool already2Connected = (morg == G.ne());
   if(already2Connected && (alreadyBipolarOriented = CheckBipolarlyOriented(G,s,t,stConnected,bs,true)) == true)
      {if(stConnected)Tprintf("Using original orientation (s,t are connected)");
      else Tprintf("Using original orientation (s,t are not connected)");
      bt = -bs;
      }
  else
      {// Find reasonable s t vertices
      tedge e;
      tbrin b;
      int len;
      G.LongestFace(bs,len);
      s = G.vin[bs];
      bt = bs;
      for(int i = 1 ;i <= len/2; i++)bt = G.cir[-bt];
      t = G.vin[bt];
      // Check if s an t are connected
      b = bs;
      do
          {if(G.vin[-b] == t){stConnected = true;break;}
          }while((b = G.cir[b]) != bs);
      if(!stConnected)
          {G.NewEdge(bs,bt);
          bs = (tbrin)G.ne();
          }
      s = G.vin[bs];   t = G.vin[-bs];
      // BipolarOrient the graph
      G.BipolarPlan(bs);
      G.FixOrientation();
      }
  
  int n = G.nv();  int m = G.ne();
  // if bs has been reoriented as the packing  suppose that vin[bst]= source
  tbrin bst = (G.vin[bs] != s) ? -bs : bs;
  
  // Compute y coords
  Prop<int> y(G.Set(tvertex()),PROP_DRAW_INT_5); y.clear();
  MaxPath *MP=new MaxPath(n,m);
  for(tedge e = 1; e <= m; e++)
      MP->insert(G.vin[e.firsttbrin()](),G.vin[e.secondtbrin()](),1);
  
  MP->solve(y);
  delete MP;
  int maxyval = y[t];
  
  // compute MaxPath for edges
  svector<int> x(0,m); x.clear();
  MP=new MaxPath(m,2*m);
  svector<tbrin> &Fpbrin = G.ComputeFpbrin();
  tbrin b0,b;
  // out == positif
 
  for(int i = 1; i <= Fpbrin.n(); i++)
      {b0 = Fpbrin[i];
      if(b0.out())
          while((b=-G.acir[b0]).out())
              b0=b;
      else
          do
              {b0=G.cir[-b0];}
          while(b0.in());
      // b0 is the lowest tbrin on the left of the face
      if(b0 == G.cir[bst])continue; // face exterieure
      
      // référence : e
      tedge e = (G.acir[b0]).GetEdge();
      b=b0;
      while (b.out())
          {if(stConnected || b != bst) 
              MP->insert(b.GetEdge()(),e(),1);
          b=G.cir[-b];
          }
      while (b.GetEdge()!=e)
          {MP->insert(e(),b.GetEdge()(),0);
          b=G.cir[-b];
          }
      }


  MP->solve(x);
  delete &Fpbrin;
  delete MP; 

  // computes extremities of vertices
  Prop<int> x1(G.Set(tvertex()),PROP_DRAW_INT_1);
  Prop<int> x2(G.Set(tvertex()),PROP_DRAW_INT_2);
  int maxxval=ComputeExtremities(G,x,x1,x2,morg);

  Prop1<int> m_org(G.Set(),PROP_TMP);
  m_org() = morg;
  for(tedge e = G.ne(); e > morg; e--)
      G.DeleteEdge(e);

  Prop1<int> maxx(G.Set(),PROP_DRAW_INT_1);
  Prop1<int> maxy(G.Set(),PROP_DRAW_INT_2);
  maxx()=maxxval;  maxy()=maxyval;
  Prop1<Tpoint> pmin(G.Set(),PROP_POINT_MIN);
  Prop1<Tpoint> pmax(G.Set(),PROP_POINT_MAX);
  pmin() = Tpoint(-1,-1);
  pmax() = Tpoint(maxxval+1,maxyval+1);


  Prop<Tpoint> P1(G.Set(tedge()),PROP_DRAW_POINT_1);
  Prop<Tpoint> P2(G.Set(tedge()),PROP_DRAW_POINT_2);
  for (tedge e=1; e<= G.ne(); e++)
      {P1[e]=Tpoint(x[e],y[G.vin[e.firsttbrin()]]);
      P2[e]=Tpoint(x[e],y[G.vin[e.secondtbrin()]]);
      }
  
  return 0;
  }