1 // This is contrib/brl/bbas/bkml/bkml_write.h 2 #ifndef bkml_write_h 3 #define bkml_write_h 4 5 //: 6 // \file 7 // \brief A class with kml utilities 8 // \author Ozge C. Ozcanli ozge@visionsystemsinc.com 9 // \date July 28, 2012 10 // 11 // \verbatim 12 // Modifications 13 // Yi Dong --- Feb, 2013 added method to write Photo overlay 14 // Yi Dong --- Oct, 2014 added method to write Polygon with inner boundary 15 // Yi Dong --- Oct, 2014 added method to write a point as a 2-d box 16 // Yi Dong --- Dec, 2015 update box write method to have 'fill' option 17 // \endverbatim 18 19 #include <iostream> 20 #include <fstream> 21 #include <string> 22 #include <iomanip> 23 #include <functional> 24 #ifdef _MSC_VER 25 # include <vcl_msvc_warnings.h> 26 #endif 27 #include <vnl/vnl_double_2.h> 28 #include <vgl/vgl_box_2d.h> 29 #include <vgl/vgl_polygon.h> 30 31 class bkml_write 32 { 33 public: 34 35 //: Write KML header and open document tag 36 static void open_document(std::ofstream& str); 37 38 //: end document tag 39 static void close_document(std::ofstream& str); 40 41 //: Write a box 42 static void write_box(std::ofstream &ofs, const std::string& name, const std::string& description, vnl_double_2 ul, vnl_double_2 ur, vnl_double_2 ll, vnl_double_2 lr); 43 static void write_box(std::ofstream &ofs, std::string name, std::string description, vgl_box_2d<double> bbox); 44 45 //: Write a box with color, color is in hexadecimale format: 0 - 255 --> 00 to ff, aabbggrr --> alpha alpha, blue blue, gree green , red red.. alpha is the opacity, ffffffff is white fully opaque 46 static void write_box(std::ofstream &ofs, const std::string& name, const std::string& description, vnl_double_2 ul, vnl_double_2 ur, vnl_double_2 ll, vnl_double_2 lr, const std::string& hex_color, 47 unsigned const& fill = 0); 48 static void write_box(std::ofstream &ofs, std::string name, std::string description, vnl_double_2 ul, vnl_double_2 ur, vnl_double_2 ll, vnl_double_2 lr, 49 unsigned char const& r, unsigned char const& g, unsigned char const& b, unsigned char const&a = 85, 50 unsigned const& fill = 0); 51 52 //: put a pin at the given location 53 static void write_location(std::ofstream& ofs, const std::string& name, const std::string& description, double lat, double lon, double elev); 54 static void write_location(std::ofstream& ofs, double lat, double lon, double elev, 55 std::string const& name = "location", 56 std::string const& description = "", 57 double const& scale = 1.0, 58 unsigned char const& r = 255, 59 unsigned char const& g = 131, 60 unsigned char const& b = 250); 61 // write location as a small box 62 static void write_location_as_box(std::ofstream& ofs, double lat, double lon, double elev, 63 std::string const& name = "location", 64 std::string const& description = "", 65 double const& size = 1E-5, 66 unsigned char const& r = 255, 67 unsigned char const& g = 131, 68 unsigned char const& b = 250); 69 70 //: put a pin at the given location (x = lon and y = lat) 71 static void write_location(std::ofstream& ofs, vgl_point_2d<double> const& loc, 72 std::string const& name = "location", 73 std::string const& description = "", 74 double const& scale = 1.0, 75 unsigned char const& r = 255, 76 unsigned char const& g = 131, 77 unsigned char const& b = 250); 78 79 80 //: Write a photooverlay without img and correct near parameter though) 81 static void write_photo_overlay(std::ofstream& ofs, const std::string& name, 82 double lon, double lat, double alt, 83 double head, double tilt, double roll, 84 double t_fov, double r_fov, 85 double value = 0.0); 86 87 //: Write a polygon with color, line style 88 static void write_polygon(std::ofstream& ofs, vgl_polygon<double> const& poly, 89 std::string const& name = "polygon", 90 std::string const& description = "", 91 double const& scale = 1.0, 92 double const& line_width = 3.0, 93 double const& alpha = 0.45, 94 unsigned char const& r = 0, 95 unsigned char const& g = 255, 96 unsigned char const& b = 0); 97 98 //: Write a polygon with inner boundary 99 // (first element in pair is the outer boundary (single sheet), second element in pair is the inner boundary) 100 static void write_polygon(std::ofstream& ofs, 101 std::vector<std::pair<vgl_polygon<double>, vgl_polygon<double> > > const& polygon, 102 std::string const& name = "polygon", 103 std::string const& description = "", 104 double const& scale = 1.0, 105 double const& line_width = 3.0, 106 double const& alpha = 0.45, 107 unsigned char const& r = 0, 108 unsigned char const& g = 255, 109 unsigned char const& b = 0); 110 111 //: Write a (path) with color and line style 112 static void write_path(std::ofstream& ofs, std::vector<vgl_point_2d<double> > path, 113 std::string const& name = "paths", 114 std::string const& description = "", 115 double const& scale = 1.0, 116 double const& line_width = 3.0, 117 double const& alpha = 0.35, 118 unsigned char const& r = 255, 119 unsigned char const& g = 0, 120 unsigned char const& b = 0); 121 122 123 //: Write a style include LineStyle and PolyStyle 124 static void write_kml_style(std::ofstream& ofs, 125 const std::string& style_name = "kml_style", 126 double const& scale = 1.0, 127 double const& line_width = 3.0, 128 double const& alpha = 0.45, 129 unsigned char const& r = 0, 130 unsigned char const& g = 255, 131 unsigned char const& b = 0); 132 133 }; 134 135 #endif 136