vil_nitf2_image_subheader.h
Go to the documentation of this file.
1 // vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
2 // Stellar Science Ltd. Co. (stellarscience.com) for
3 // Air Force Research Laboratory, 2005.
4 #ifndef VIL_NITF2_IMAGE_SUBHEADER_H
5 #define VIL_NITF2_IMAGE_SUBHEADER_H
6 //:
7 // \file
8 
9 #include <vector>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 
16 #include "vil_nitf2.h"
17 
18 class vil_stream;
20 
21 //:
22 // This class is responsible for parsing a NITF 2.1 image header.
23 // It is used by vil_nitf_image for this purpose. You can access
24 // any of the information in the header via the appropriate
25 // get_property() function. There are also some shortcut
26 // functions for getting commonly needed data like nplanes()
27 // etc.
29 {
30  public:
33 
34  //: Read the image header starting at stream's current position.
35  // \returns false if failed
36  virtual bool read( vil_stream* stream );
37 #if 0
38  virtual bool write( vil_stream* stream );
39 #endif // 0
40 
41  //: Sets \a out_value to the value of field specified by tag.
42  // \returns 0 if such a field is not found or is of the wrong type.
43  template< class T >
44  bool get_property(std::string tag, T& out_value) const
45  {
46  return m_field_sequence.get_value( tag, out_value );
47  }
48 
49  //: Sets out_value to the value of std::vector field element specified by tag and index.
50  // \returns 0 if such a field is not found or is of the wrong type.
51  template< class T >
52  bool get_property(std::string tag, int i, T& out_value) const
53  {
54  return m_field_sequence.get_value( tag, i, out_value );
55  }
56 
57  unsigned int nplanes() const;
58  unsigned int get_pixels_per_block_x() const;
59  unsigned int get_pixels_per_block_y() const;
60  unsigned int get_num_blocks_x() const;
61  unsigned int get_num_blocks_y() const;
62  unsigned int get_number_of_bits_per_pixel() const;
63  std::string get_image_source() const;
64  std::string get_image_type() const;
65  bool has_data_mask_table() const { return data_mask_table() != nullptr; }
67 
68  //:
69  // Returns true if the ith image band in this image subheader has LUT info
70  // and false otherwise. If it returns true, then all the out parameters
71  // will be populated from the header data.
72  // \param n_luts: number of luts for this image band (NITF spec says
73  // it's in the range [1-4] (if luts present)
74  // \param ne_lut: number of elements in each lut
75  // \param lut_d: the LUT data indexed first by lut, then lut element
76  // ie, the last element would be lut_d[n_luts-1][ne_lut-1]
77  //
78  // See the NITF spec for exactly how this data is to be interpreted. Here's
79  // a summary:
80  // LUTS always contain 8 bit unsigned data. If n_luts is 1, then this band
81  // is to be transformed into an 8-bit image plane. Each pixel value in the
82  // original image can be used as an index into lut_d. (ie. lut_d[0][pixelVal])
83  // If n_luts is 2, then the output image plate will be 16 bits. The MSBs of
84  // each of the output pixels will be obtained from lut_d[0] and the LSBs will
85  // be obtained from lut_d[1].
86  // If n_luts is 3, then this plane will be transformed into 3 planes: R, G and B.
87  // lut_d[0] shall map to Red, lut_d[1] shall map to Green, and lut_d[2] shall map
88  // to Blue.
89  bool get_lut_info( unsigned int band, int& n_luts, int& ne_lut,
90  std::vector< std::vector< unsigned char > >& lut_d ) const;
91 
92  // I allocate the return value, but you own it after I return it to you
93  // so you need to delete it.
94  virtual vil_nitf2_field::field_tree* get_tree( int i = 0 ) const;
95 
96  //: Get RPC parameters, if present. User provides rpc_data array.
97  // The parameters describe a camera projection based on the
98  // ratio of cubic polynomials in (lon, lat, ele). All variables
99  // are normalized to the range [-1, 1] using scale and offset parameters.
100  // For further definition of parameters see
101  // http://www.gwg.nga.mil/ntb/superseded/vimas/vimas.pdf
102  // The returned rpc_data vector is encoded as:
103  // rpc_data[0]-rpc_data[19] Line Numerator Cubic Coefficients
104  // rpc_data[20]-rpc_data[39] Line Denominator Cubic Coefficients
105  // rpc_data[40]-rpc_data[59] Sample Numerator Cubic Coefficients
106  // rpc_data[60]-rpc_data[79] Sample Denominator Cubic Coefficients
107  // rpc_data[80] Line Offset rpc_data[81] Sample Offset
108  // rpc_data[82] Latitude Offset rpc_data[83] Longitude Offset
109  // rpc_data[84] Elevation Offset rpc_data[85] Line Scale
110  // rpc_data[86] Sample Scale rpc_data[87] Latitude Scale
111  // rpc_data[88] Longitude Scale rpc_data[89] Elevation Scale
112  //
113  // The ordering of coefficients can vary as indicated by rpc_type
114  // Defined extensions are RPC00A and RPC00B.
115  bool get_rpc_params( std::string& rpc_type, std::string& image_id,
116  std::string& image_corner_geo_locations,
117  double* rpc_data );
118 
119  //: Return the elevation and azimuth angles of the sun
120  // \a sun_el --> sun elevation angle
121  // \a sun_az --> sun azimuthal angle
122  bool get_sun_params( double& sun_el, double& sun_az);
123 
124  //: Extract the date and time
125  bool get_date_time(int& year, int& month, int& day, int& hour, int& min, int& sec);
126 
127  bool get_correction_offset(double & u_off, double & v_off);
128 
129  protected:
132 
134 
137 
138  private:
143  static void add_rpc_definitions();
144  static void add_USE_definitions();
145  static void add_ICHIPB_definitions();
146  static void add_MPD26A_definitions();
147  static void add_STDIDC_definitions();
148  static void add_STDIDB_definitions();
149 
152  // so these static members can be cleaned up when the program is done
153  // using nitf files
154  friend void vil_nitf2::cleanup_static_members();
155 };
156 
157 #endif // VIL_NITF2_IMAGE_SUBHEADER_H
bool get_correction_offset(double &u_off, double &v_off)
This class is responsible for parsing a NITF 2.1 data mask table.
static const vil_nitf2_field_definitions * get_field_definitions_20()
static void add_shared_field_defs_1(vil_nitf2_field_definitions *defs)
static vil_nitf2_field_definitions * s_field_definitions_20
static void add_shared_field_defs_3(vil_nitf2_field_definitions *defs)
This class is responsible for parsing a NITF 2.1 image header.
const vil_nitf2_data_mask_table * data_mask_table() const
unsigned int get_number_of_bits_per_pixel() const
bool get_rpc_params(std::string &rpc_type, std::string &image_id, std::string &image_corner_geo_locations, double *rpc_data)
Get RPC parameters, if present. User provides rpc_data array.
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
bool get_property(std::string tag, int i, T &out_value) const
Sets out_value to the value of std::vector field element specified by tag and index.
vil_nitf2_field_sequence m_field_sequence
static vil_nitf2_field_definitions * s_field_definitions_21
vil_nitf2_classification::file_version m_version
static void add_geo_field_defs(vil_nitf2_field_definitions *defs, const vil_nitf2_classification::file_version &version)
bool get_sun_params(double &sun_el, double &sun_az)
Return the elevation and azimuth angles of the sun.
bool get_lut_info(unsigned int band, int &n_luts, int &ne_lut, std::vector< std::vector< unsigned char > > &lut_d) const
Returns true if the ith image band in this image subheader has LUT info and false otherwise.
virtual vil_nitf2_field::field_tree * get_tree(int i=0) const
unsigned int get_pixels_per_block_x() const
vil_nitf2_data_mask_table * m_data_mask_table
bool get_property(std::string tag, T &out_value) const
Sets out_value to the value of field specified by tag.
bool get_date_time(int &year, int &month, int &day, int &hour, int &min, int &sec)
Extract the date and time.
bool get_value(std::string tag, int &out_value) const
static void add_shared_field_defs_2(vil_nitf2_field_definitions *defs)
static void cleanup_static_members()
Call this function to flush all of the nitf2 classes statically allocated memory.
Definition: vil_nitf2.cxx:14
virtual bool read(vil_stream *stream)
Read the image header starting at stream's current position.
static const vil_nitf2_field_definitions * get_field_definitions_21()
vil_nitf2_image_subheader(vil_nitf2_classification::file_version version)
unsigned int get_pixels_per_block_y() const