core/vil/file_formats/vil_nitf2_image_subheader.h
Go to the documentation of this file.
00001 // vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for
00003 // Air Force Research Laboratory, 2005.
00004 #ifndef VIL_NITF2_IMAGE_SUBHEADER_H
00005 #define VIL_NITF2_IMAGE_SUBHEADER_H
00006 //:
00007 // \file
00008 
00009 #include <vcl_vector.h>
00010 
00011 #include "vil_nitf2_field_sequence.h"
00012 #include "vil_nitf2_classification.h"
00013 #include "vil_nitf2.h"
00014 
00015 class vil_stream;
00016 class vil_nitf2_data_mask_table;
00017 
00018 //:
00019 // This class is responsible for parsing a NITF 2.1 image header.
00020 // It is used by vil_nitf_image for this purpose.  You can access
00021 // any of the information in the header via the appropriate
00022 // get_property() function.  There are also some shortcut
00023 // functions for getting commonly needed data like nplanes()
00024 // etc.
00025 class vil_nitf2_image_subheader
00026 {
00027  public:
00028   vil_nitf2_image_subheader( vil_nitf2_classification::file_version version );
00029   virtual ~vil_nitf2_image_subheader();
00030 
00031   //: Read the image header starting at stream's current position.
00032   // \returns false if failed
00033   virtual bool read( vil_stream* stream );
00034 #if 0
00035   virtual bool write( vil_stream* stream );
00036 #endif // 0
00037 
00038   //: Sets \a out_value to the value of field specified by tag.
00039   // \returns 0 if such a field is not found or is of the wrong type.
00040   template< class T >
00041   bool get_property(vcl_string tag, T& out_value) const
00042   {
00043     return m_field_sequence.get_value( tag, out_value );
00044   }
00045 
00046   //: Sets out_value to the value of vcl_vector field element specified by tag and index.
00047   // \returns 0 if such a field is not found or is of the wrong type.
00048   template< class T >
00049   bool get_property(vcl_string tag, int i, T& out_value) const
00050   {
00051     return m_field_sequence.get_value( tag, i, out_value );
00052   }
00053 
00054   unsigned int nplanes() const;
00055   unsigned int get_pixels_per_block_x() const;
00056   unsigned int get_pixels_per_block_y() const;
00057   unsigned int get_num_blocks_x() const;
00058   unsigned int get_num_blocks_y() const;
00059   unsigned int get_number_of_bits_per_pixel() const;
00060   vcl_string get_image_source() const;
00061   vcl_string get_image_type() const;
00062   bool has_data_mask_table() const { return data_mask_table() != 0; }
00063   const vil_nitf2_data_mask_table* data_mask_table() const { return m_data_mask_table; }
00064 
00065   //:
00066   // Returns true if the ith image band in this image subheader has LUT info
00067   // and false otherwise.  If it returns true, then all the out parameters
00068   // will be populated from the header data.
00069   // \param n_luts: number of luts for this image band (NITF spec says
00070   //                it's in the range [1-4] (if luts present)
00071   // \param ne_lut: number of elements in each lut
00072   // \param lut_d: the LUT data indexed first by lut, then lut element
00073   //               ie, the last element would be lut_d[n_luts-1][ne_lut-1]
00074   //
00075   // See the NITF spec for exactly how this data is to be interpreted.  Here's
00076   // a summary:
00077   // LUTS always contain 8 bit unsigned data.  If n_luts is 1, then this band
00078   // is to be transformed into an 8-bit image plane.  Each pixel value in the
00079   // original image can be used as an index into lut_d.  (ie. lut_d[0][pixelVal])
00080   // If n_luts is 2, then the output image plate will be 16 bits.  The MSBs of
00081   // each of the output pixels will be obtained from lut_d[0] and the LSBs will
00082   // be obtained from lut_d[1].
00083   // If n_luts is 3, then this plane will be transformed into 3 planes: R, G and B.
00084   // lut_d[0] shall map to Red, lut_d[1] shall map to Green, and lut_d[2] shall map
00085   // to Blue.
00086   bool get_lut_info( unsigned int band, int& n_luts, int& ne_lut,
00087                      vcl_vector< vcl_vector< unsigned char > >& lut_d ) const;
00088 
00089   // I allocate the return value, but you own it after I return it to you
00090   // so you need to delete it.
00091   virtual vil_nitf2_field::field_tree* get_tree( int i = 0 ) const;
00092 
00093   //: Get RPC parameters, if present. User provides rpc_data array.
00094   // The parameters describe a camera projection based on the
00095   // ratio of cubic polynomials in (lon, lat, ele). All variables
00096   // are normalized to the range [-1, 1] using scale and offset parameters.
00097   // For further definition of parameters see
00098   // http://www.gwg.nga.mil/ntb/superseded/vimas/vimas.pdf
00099   // The returned rpc_data vector is encoded as:
00100   //  rpc_data[0]-rpc_data[19]         Line Numerator Cubic Coefficients
00101   //  rpc_data[20]-rpc_data[39]        Line Denominator Cubic Coefficients
00102   //  rpc_data[40]-rpc_data[59]        Sample Numerator Cubic Coefficients
00103   //  rpc_data[60]-rpc_data[79]        Sample Denominator Cubic Coefficients
00104   //  rpc_data[80] Line Offset         rpc_data[81] Sample Offset
00105   //  rpc_data[82] Latitude Offset     rpc_data[83] Longitude Offset
00106   //  rpc_data[84] Elevation Offset    rpc_data[85] Line Scale
00107   //  rpc_data[86] Sample Scale        rpc_data[87] Latitude Scale
00108   //  rpc_data[88] Longitude Scale     rpc_data[89] Elevation Scale
00109   //
00110   //  The ordering of coefficients can vary as indicated by rpc_type
00111   //  Defined extensions are RPC00A and RPC00B.
00112   bool get_rpc_params( vcl_string& rpc_type, vcl_string& image_id,
00113                        vcl_string& image_corner_geo_locations,
00114                        double* rpc_data );
00115 
00116   //: Return the elevation and azimuth angles of the sun
00117   //  \a sun_el --> sun elevation angle
00118   //  \a sun_az --> sun azimuthal angle
00119   bool get_sun_params( double& sun_el, double& sun_az);
00120 
00121   //: Extract the date and time
00122   bool get_date_time(int& year, int& month, int& day, int& hour, int& min);
00123 
00124   bool get_correction_offset(double & u_off, double & v_off);
00125 
00126  protected:
00127   vil_nitf2_field_sequence m_field_sequence;
00128   vil_nitf2_data_mask_table* m_data_mask_table;
00129 
00130   vil_nitf2_classification::file_version m_version;
00131 
00132   static const vil_nitf2_field_definitions* get_field_definitions_21();
00133   static const vil_nitf2_field_definitions* get_field_definitions_20();
00134 
00135  private:
00136   static void add_shared_field_defs_1( vil_nitf2_field_definitions* defs );
00137   static void add_shared_field_defs_2( vil_nitf2_field_definitions* defs );
00138   static void add_geo_field_defs( vil_nitf2_field_definitions* defs, const vil_nitf2_classification::file_version& version );
00139   static void add_shared_field_defs_3( vil_nitf2_field_definitions* defs );
00140   static void add_rpc_definitions();
00141   static void add_USE_definitions();
00142   static void add_ICHIPB_definitions();
00143   static void add_MPD26A_definitions();
00144   static void add_STDIDC_definitions();
00145   static void add_STDIDB_definitions();
00146 
00147   static vil_nitf2_field_definitions* s_field_definitions_21;
00148   static vil_nitf2_field_definitions* s_field_definitions_20;
00149   // so these static members can be cleaned up when the program is done
00150   // using nitf files
00151   friend void vil_nitf2::cleanup_static_members();
00152 };
00153 
00154 #endif // VIL_NITF2_IMAGE_SUBHEADER_H