1 // This is brl/bbas/volm/volm_category_io.h
2 #ifndef volm_category_io_h_
3 #define volm_category_io_h_
4 //:
5 // \file
6 // \brief A io to read the pre-defined available land types for volumetric matcher related
7 // \author Yi Dong
8 // \date July 26, 2013
9 //
10 // \verbatim
11 //  Modifications
12 //   <none yet>
13 // \endverbatim
14 //
15 
16 #include <string>
17 #include <iostream>
18 #include <utility>
19 #include <map>
20 #include <set>
21 #ifdef _MSC_VER
22 #  include <vcl_msvc_warnings.h>
23 #endif
24 #include <bres/bres_find.h>
25 #include <vil/vil_rgb.h>
26 #include <vxl_config.h>
27 #include <bvrml/bvrml_write.h>
28 #include "volm_export.h"
29 
30 //: class to store all available land categories
31 class volm_land_layer
32 {
33 public:
34   //: default constructor creates an invalid land category
volm_land_layer()35   volm_land_layer() : id_(0), name_("invalid"), level_(0), color_(vil_rgb<vxl_byte>(0,0,0)), width_(0.0) {}
36   //: constructor
volm_land_layer(unsigned char const & id,std::string name,unsigned char const & level,double const & width,vil_rgb<vxl_byte> const & color)37   volm_land_layer(unsigned char const& id, std::string  name,
38                   unsigned char const& level, double const& width, vil_rgb<vxl_byte> const& color)
39                   : id_(id), name_(std::move(name)), level_(level), color_(color), width_(width) {}
volm_land_layer(unsigned char const & id,std::string name,unsigned char const & level,double const & width)40   volm_land_layer(unsigned char const& id, std::string  name, unsigned char const& level, double const& width)
41     : id_(id), name_(std::move(name)), level_(level),
42       color_(bvrml_color::heatmap_classic[id][0], bvrml_color::heatmap_classic[id][1], bvrml_color::heatmap_classic[id][2]),
43       width_(width) {}
44 
45   //: destructor
46   ~volm_land_layer() = default;
47 
48   //: check the existence of certain land layer
49   bool contains(const std::string& name);
50   //: screen print
print()51   void print() const
52   {
53     std::cout << " (id: " << (int)id_ << ", name: " << name_
54              << ", level: " << (int)level_ <<  ", width: " << width_ << ", color: " << color_ << ')';
55   }
56   //: land id
57   unsigned char id_;
58   //: land name
59   std::string name_;
60   //: layer priority
61   unsigned char level_;
62   //: assigned color for this land
63   vil_rgb<vxl_byte> color_;
64   //: width (non zero for road and zero for all others)
65   double width_;
66 
67 };
68 
69 class volm_osm_category_io
70 {
71 public:
72   enum nlcd_values {NLCD_WATER = 11, NLCD_ICE_SNOW = 12, NLCD_SAND = 31, NLCD_INVALID = 0,
73                     NLCD_DEVELOPED_LOW = 22, NLCD_DEVELOPED_MED = 23, NLCD_DEVELOPED_HIGH = 24, NLCD_DEVELOPED_OPEN = 21,
74                     NLCD_DECIDUOUS_FOREST = 41, NLCD_EVERGREEN_FOREST = 42, NLCD_MIXED_FOREST = 43,
75                     NLCD_DWARF_SCRUB = 51, NLCD_SHRUB = 52,
76                     NLCD_GRASSLAND = 71, NLCD_SEDGE = 72, NLCD_LICHENS = 73, NLCD_MOSS = 74,
77                     NLCD_PASTURE = 81, NLCD_CROPS = 82,
78                     NLCD_WOODY_WETLAND = 90, NLCD_EMERGENT_WETLAND = 95,
79                     BUILDING_TALL = 119};
80 
81   enum geo_cover_values {GEO_DECIDUOUS_FOREST = 1, GEO_EVERGREEN_FOREST = 2, GEO_SHRUB = 3,
82                          GEO_GRASSLAND = 4,  GEO_BARREN = 5,  GEO_URBAN = 6,
83                          GEO_AGRICULTURE_GENERAL = 7, GEO_AGRICULTURE_RICE = 8,
84                          GEO_WETLAND = 9, GEO_MANGROVE = 10,
85                          GEO_WATER = 11, GEO_ICE = 12, GEO_CLOUD = 13};
86 
87   //: table to transfer open street map (osm) to volm available land table
88   static bool load_category_table(std::string const& filename, std::map<std::pair<std::string, std::string>, volm_land_layer>& land_category_table);
89 
90   //: table of all defined road junctions loaded from text file
91   static volm_EXPORT_DATA std::map<std::pair<int, int>, volm_land_layer> road_junction_table;
92 
93   //: function to load road junction file
94   static bool load_road_junction_table(std::string const& filename, std::map<std::pair<int, int>, volm_land_layer>& road_junction_table);
95 
96   //: table to define default width of road loaded from open street map
97   static bool load_road_width_table(std::string const& filename, std::map<std::pair<std::string, std::string>, float>& road_width_table);
98 
99   //: table to transfer nlcd label to volm label
100   static volm_EXPORT_DATA std::map<int, volm_land_layer> nlcd_land_table;
101 
102   //: table to transfer geo_cover
103   static volm_EXPORT_DATA std::map<int, volm_land_layer> geo_land_table;
104 
105   //: table of all possible volm_object
106   static volm_EXPORT_DATA std::vector<std::string> volm_category_name_table;
107 
108   //: table of all defined volm_land_layer from NLCD, GEO_COVER and OSM list (key is the land_layer id)
109   static volm_EXPORT_DATA std::map<unsigned, volm_land_layer> volm_land_table;
110 
111   //: table of all defined volm_land_layer from NLCD, GEO_COVER and OSM list (key is the land_layer name, note that the land name is unique)
112   static volm_EXPORT_DATA std::map<std::string, volm_land_layer> volm_land_table_name;
113 
114   //: use the corresponding increment during hypotheses generation,
115   //  the unit of the increments is in meters (user of this table shall convert to degrees if necessary depending on lat, lon of the area)
116   static volm_EXPORT_DATA std::map<int, double> geo_land_hyp_increments;
117 
118   //: table to transfer land tags in xml file to volm land category
119   static volm_EXPORT_DATA std::map<std::string, volm_land_layer> tag_to_volm_land_table;
120 
121   //: location of table files
122   static const std::string osm_to_volm_labels_txt;      // ("osm_to_volm_labels.txt")
123   static const std::string user_to_volm_labels_txt;     // user defined land category converting to volm land category
124   static const std::string road_junction_labels_txt;    // road junction category
125 };
126 
127 #endif // volm_category_io_h_
128