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   bool has_data_mask_table() const { return data_mask_table() != 0; }
00060   const vil_nitf2_data_mask_table* data_mask_table() const { return m_data_mask_table; }
00061 
00062   //:
00063   // Returns true if the ith image band in this image subheader has LUT info
00064   // and false otherwise.  If it returns true, then all the out parameters
00065   // will be populated from the header data.
00066   // \param n_luts: number of luts for this image band (NITF spec says
00067   //                it's in the range [1-4] (if luts present)
00068   // \param ne_lut: number of elements in each lut
00069   // \param lut_d: the LUT data indexed first by lut, then lut element
00070   //               ie, the last element would be lut_d[n_luts-1][ne_lut-1]
00071   //
00072   // See the NITF spec for exactly how this data is to be interpretted.  Here's
00073   // a summary:
00074   // LUTS always contain 8 bit unsigned data.  If n_luts is 1, then this band
00075   // is to be transformed into an 8-bit image plane.  Each pixel value in the
00076   // original image can be used as an index into lut_d.  (ie. lut_d[0][pixelVal])
00077   // If n_luts is 2, then the output image plate will be 16 bits.  The MSBs of
00078   // each of the output pixels will be obtained from lut_d[0] and the LSBs will
00079   // be obtained from lut_d[1].
00080   // If n_luts is 3, then this plane will be transformed into 3 planes: R, G and B.
00081   // lut_d[0] shall map to Red, lut_d[1] shall map to Green, and lut_d[2] shall map
00082   // to Blue.
00083   bool get_lut_info( unsigned int band, int& n_luts, int& ne_lut,
00084                      vcl_vector< vcl_vector< unsigned char > >& lut_d ) const;
00085 
00086   // I allocate the return value, but you own it after I return it to you
00087   // so you need to delete it.
00088   virtual vil_nitf2_field::field_tree* get_tree( int i = 0 ) const;
00089 
00090   //: Get RPC parameters, if present. User provides rpc_data array.
00091   // The parameters describe a camera projection based on the
00092   // ratio of cubic polynomials in (lon, lat, ele). All variables
00093   // are normalized to the range [-1, 1] using scale and offset parameters.
00094   // For further definition of parameters see
00095   // http://www.ismc.nima.mil/ntb/superceded/vimas/vimas.pdf
00096   // The returned rpc_data vector is encoded as:
00097   //  rpc_data[0]-rpc_data[19]         Line Numerator Cubic Coefficients
00098   //  rpc_data[20]-rpc_data[39]        Line Denominator Cubic Coefficients
00099   //  rpc_data[40]-rpc_data[59]        Sample Numerator Cubic Coefficients
00100   //  rpc_data[60]-rpc_data[79]        Sample Denominator Cubic Coefficients
00101   //  rpc_data[80] Line Offset         rpc_data[81] Sample Offset
00102   //  rpc_data[82] Latitude Offset     rpc_data[83] Longitude Offset
00103   //  rpc_data[84] Elevation Offset    rpc_data[85] Line Scale
00104   //  rpc_data[86] Sample Scale        rpc_data[87] Latitude Scale
00105   //  rpc_data[88] Longitude Scale     rpc_data[89] Elevation Scale
00106   //
00107   //  The ordering of coefficients can vary as indicated by rpc_type
00108   //  Defined extensions are RPC00A and RPC00B.
00109   bool get_rpc_params( vcl_string& rpc_type, vcl_string& image_id,
00110                        vcl_string& image_corner_geo_locations,
00111                        double* rpc_data );
00112 
00113   //: Return the elevation and azimuth angles of the sun
00114   //  \a sun_el --> sun elevation angle
00115   //  \a sun_az --> sun azimuthal angle
00116   bool get_sun_params( double& sun_el, double& sun_az);
00117 
00118 
00119   bool get_correction_offset(double & u_off, double & v_off);
00120 
00121  protected:
00122   vil_nitf2_field_sequence m_field_sequence;
00123   vil_nitf2_data_mask_table* m_data_mask_table;
00124 
00125   vil_nitf2_classification::file_version m_version;
00126 
00127   static const vil_nitf2_field_definitions* get_field_definitions_21();
00128   static const vil_nitf2_field_definitions* get_field_definitions_20();
00129 
00130  private:
00131   static void add_shared_field_defs_1( vil_nitf2_field_definitions* defs );
00132   static void add_shared_field_defs_2( vil_nitf2_field_definitions* defs );
00133   static void add_geo_field_defs( vil_nitf2_field_definitions* defs, const vil_nitf2_classification::file_version& version );
00134   static void add_shared_field_defs_3( vil_nitf2_field_definitions* defs );
00135   static void add_rpc_definitions();
00136   static void add_USE_definitions();
00137   static void add_ICHIPB_definitions();
00138   static void add_MPD26A_definitions();
00139   static void add_STDIDC_definitions();
00140   static void add_STDIDB_definitions();
00141 
00142   static vil_nitf2_field_definitions* s_field_definitions_21;
00143   static vil_nitf2_field_definitions* s_field_definitions_20;
00144   // so these static members can be cleaned up when the program is done
00145   // using nitf files
00146   friend void vil_nitf2::cleanup_static_members();
00147 };
00148 
00149 #endif // VIL_NITF2_IMAGE_SUBHEADER_H

Generated on Fri Nov 21 05:07:44 2008 for core/vil by  doxygen 1.5.1