| 1 | #include <iostream>
 | 
|---|
| 2 | #include <fstream>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include <vector>
 | 
|---|
| 5 | #include <string>
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #include <boost/geometry.hpp> 
 | 
|---|
| 8 | #include <boost/geometry/geometries/point.hpp> 
 | 
|---|
| 9 | #include <boost/geometry/geometries/box.hpp> 
 | 
|---|
| 10 | #include <boost/geometry/index/rtree.hpp>
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include <boost/archive/binary_iarchive.hpp>
 | 
|---|
| 13 | #include <boost/serialization/vector.hpp>
 | 
|---|
| 14 | 
 | 
|---|
| 15 | namespace bg = boost::geometry;
 | 
|---|
| 16 | namespace bgi = boost::geometry::index;
 | 
|---|
| 17 | 
 | 
|---|
| 18 | 
 | 
|---|
| 19 | using namespace std;
 | 
|---|
| 20 | 
 | 
|---|
| 21 | /*! Coordinate point definition */
 | 
|---|
| 22 | typedef bg::model::point<float, 3, bg::cs::cartesian> boost_pnt;
 | 
|---|
| 23 | 
 | 
|---|
| 24 | /*! Bounding box definition */
 | 
|---|
| 25 | typedef bg::model::box<boost_pnt> boost_box;
 | 
|---|
| 26 | 
 | 
|---|
| 27 | /*! Cell details which will be stored in R-Tree */
 | 
|---|
| 28 | typedef std::pair<boost_box, int> rtree_elem;
 | 
|---|
| 29 | 
 | 
|---|
| 30 | /*! R-Tree for finding points in cells */
 | 
|---|
| 31 | typedef bgi::rtree<rtree_elem, bgi::rstar<2> > boost_rtree;
 | 
|---|
| 32 | 
 | 
|---|
| 33 | 
 | 
|---|
| 34 | int main()
 | 
|---|
| 35 | {
 | 
|---|
| 36 |      //--------- Read box elements ----------------------------------
 | 
|---|
| 37 |     string fname = "../testfile.dat";
 | 
|---|
| 38 |     ifstream vecfile_in(fname.c_str(), std::ios::in | std::ofstream::binary);
 | 
|---|
| 39 |     vector<float> boxes;
 | 
|---|
| 40 | 
 | 
|---|
| 41 |     std::ifstream os_in(fname.c_str(), std::ios::in | std::ofstream::binary);
 | 
|---|
| 42 |     boost::archive::binary_iarchive oi(os_in, boost::archive::no_header);
 | 
|---|
| 43 |     {
 | 
|---|
| 44 |         oi >> boxes;
 | 
|---|
| 45 |     }
 | 
|---|
| 46 |     os_in.close();
 | 
|---|
| 47 | 
 | 
|---|
| 48 |     std::vector<rtree_elem> bounding_boxes;
 | 
|---|
| 49 | 
 | 
|---|
| 50 |     cout << "nboxes available: " << boxes.size()/6 << endl;
 | 
|---|
| 51 | 
 | 
|---|
| 52 | 
 | 
|---|
| 53 |     //-------- Create rtree elements --------------------------
 | 
|---|
| 54 |     //for(int i = 0; i < 30684; ++i) // Works
 | 
|---|
| 55 |     //for(int i = 200; i < 30685+200; ++i) // Does not work
 | 
|---|
| 56 |     for(int i = 0; i < 30685; ++i) // Does not work
 | 
|---|
| 57 |     {
 | 
|---|
| 58 |         float *bb = &(boxes[i*6]);
 | 
|---|
| 59 |         boost_pnt p1(bb[0], bb[1], bb[2]);
 | 
|---|
| 60 |         boost_pnt p2(bb[3], bb[4], bb[5]);
 | 
|---|
| 61 |         boost_box box(p1, p2);
 | 
|---|
| 62 |         bounding_boxes.emplace_back(box, i);
 | 
|---|
| 63 |     }
 | 
|---|
| 64 | 
 | 
|---|
| 65 |     cout << "nelems for rtree: " << bounding_boxes.size() << endl;
 | 
|---|
| 66 | 
 | 
|---|
| 67 |     //--------- Create rtree (where the error occurs) --------
 | 
|---|
| 68 |     boost_rtree tree(bounding_boxes);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |     // Using the following lines instead of the previous line works
 | 
|---|
| 71 |     //boost_rtree tree;
 | 
|---|
| 72 |     //tree.insert(bounding_boxes);
 | 
|---|
| 73 | 
 | 
|---|
| 74 | }
 | 
|---|