1 // This is brl/bbas/volm/volm_osm_objects.h 2 #ifndef volm_osm_objects_h_ 3 #define volm_osm_objects_h_ 4 //: 5 // \file 6 // \brief A class to contain all objects defined in an oepn street map file 7 // 8 // \author Yi Dong 9 // \date August 06, 2013 10 // 11 // \verbatim 12 // Modifications 13 // <none yet> 14 // \endverbatim 15 16 #include <iostream> 17 #include <utility> 18 #include <vector> 19 #include "volm_category_io.h" 20 #include "volm_osm_parser.h" 21 #include "volm_osm_object_point.h" 22 #include "volm_osm_object_line.h" 23 #include "volm_osm_object_polygon.h" 24 #include <vsl/vsl_binary_io.h> 25 #ifdef _MSC_VER 26 # include <vcl_msvc_warnings.h> 27 #endif 28 #include <vbl/vbl_ref_count.h> 29 #include <vbl/vbl_smart_ptr.h> 30 31 class volm_osm_objects 32 { 33 public: 34 //: default constructor 35 volm_osm_objects() = default; 36 37 //: create volm_osm_objects from open street map file 38 volm_osm_objects(std::string const& osm_file, std::string const& osm_to_volm_file); 39 40 //: create volm_osm_objects from binary file 41 volm_osm_objects(std::string const& bin_file_name); 42 43 //: create volm_osm_objects from multiple volm_locs, lines and regions volm_osm_objects(std::vector<volm_osm_object_point_sptr> loc_pts,std::vector<volm_osm_object_line_sptr> loc_lines,std::vector<volm_osm_object_polygon_sptr> loc_polys)44 volm_osm_objects(std::vector<volm_osm_object_point_sptr> loc_pts, 45 std::vector<volm_osm_object_line_sptr> loc_lines, 46 std::vector<volm_osm_object_polygon_sptr> loc_polys) 47 : loc_pts_(std::move(loc_pts)), loc_lines_(std::move(loc_lines)), loc_polys_(std::move(loc_polys)) {} 48 49 //: write all volm_osm_object into binary file 50 bool write_osm_objects(std::string const& bin_file); 51 52 //: asscessors loc_pts()53 std::vector<volm_osm_object_point_sptr>& loc_pts() { return loc_pts_; } loc_lines()54 std::vector<volm_osm_object_line_sptr>& loc_lines() { return loc_lines_; } loc_polys()55 std::vector<volm_osm_object_polygon_sptr>& loc_polys() { return loc_polys_; } 56 57 //: number of location points num_locs()58 unsigned num_locs() const { return (unsigned)loc_pts_.size(); } num_roads()59 unsigned num_roads() const { return (unsigned)loc_lines_.size(); } num_regions()60 unsigned num_regions() const { return (unsigned)loc_polys_.size(); } 61 62 //: write location points to kml 63 bool write_pts_to_kml(std::string const& kml_file); 64 65 //: write lines to kml 66 bool write_lines_to_kml(std::string const& kml_file); 67 68 //: write regions to kml 69 bool write_polys_to_kml(std::string const& kml_file); 70 71 72 // =========== binary I/O ================ 73 74 //: version version()75 short version() const { return 1; } 76 77 //: binary IO write 78 void b_write(vsl_b_ostream& os); 79 80 //: binary IO read 81 void b_read(vsl_b_istream& is); 82 83 private: 84 std::vector<volm_osm_object_point_sptr> loc_pts_; 85 std::vector<volm_osm_object_line_sptr> loc_lines_; 86 std::vector<volm_osm_object_polygon_sptr> loc_polys_; 87 88 }; 89 90 91 class volm_osm_object_ids; 92 typedef vbl_smart_ptr<volm_osm_object_ids> volm_osm_object_ids_sptr; 93 94 class volm_osm_object_ids : public vbl_ref_count 95 { 96 public: 97 98 //: default constructor volm_osm_object_ids()99 volm_osm_object_ids() {pt_ids_.clear(); line_ids_.clear(); region_ids_.clear(); } 100 101 //: constuctor volm_osm_object_ids(std::vector<unsigned> pt_ids,std::vector<unsigned> line_ids,std::vector<unsigned> region_ids)102 volm_osm_object_ids(std::vector<unsigned> pt_ids, std::vector<unsigned> line_ids, std::vector<unsigned> region_ids) 103 : pt_ids_(std::move(pt_ids)), line_ids_(std::move(line_ids)), region_ids_(std::move(region_ids)) {} 104 105 //: construct by reading from a binary file 106 volm_osm_object_ids(std::string const& bin_file); 107 108 //: accessors pt_ids()109 std::vector<unsigned>& pt_ids() { return pt_ids_; } line_ids()110 std::vector<unsigned>& line_ids() { return line_ids_; } region_ids()111 std::vector<unsigned>& region_ids() { return region_ids_; } 112 num_pts()113 unsigned num_pts() { return (unsigned)pt_ids_.size(); } num_lines()114 unsigned num_lines() { return (unsigned)line_ids_.size(); } num_regions()115 unsigned num_regions() { return (unsigned)region_ids_.size(); } 116 117 //: add a location point 118 void add_pt(unsigned const& pt_id); 119 void add_line(unsigned const& line_id); 120 void add_region(unsigned const& region_id); 121 is_empty()122 bool is_empty() 123 { 124 return (pt_ids_.empty() && line_ids_.empty() && region_ids_.empty()); 125 } 126 127 //: binary io 128 bool write_osm_ids(std::string const& bin_file); 129 130 //: Binary save self to stream. 131 void b_write(vsl_b_ostream &os) const; 132 133 //: Binary load self from stream. 134 void b_read(vsl_b_istream &is); 135 136 //: Return IO version number; version()137 short version() const { return 1; } 138 139 private: 140 std::vector<unsigned> pt_ids_; 141 std::vector<unsigned> line_ids_; 142 std::vector<unsigned> region_ids_; 143 }; 144 145 #endif // volm_osm_objects_h_ 146