Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

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 // This class is responsible for parsing a NITF 2.1 image header.
00019 // It is used by vil_nitf_image for this purpose.  You can access
00020 // any of the information in the header via the appropriate
00021 // get_property() function.  There are also some shortcut
00022 // functions for getting commonly needed data like nplanes()
00023 // etc.
00024 class vil_nitf2_image_subheader
00025 {
00026  public:
00027   vil_nitf2_image_subheader( vil_nitf2_classification::file_version version );
00028   virtual ~vil_nitf2_image_subheader();
00029 
00030   //: Read the image header starting at stream's current position.
00031   // \returns false if failed
00032   virtual bool read( vil_stream* stream );
00033   //virtual bool write( vil_stream* stream );
00034 
00035   //: Sets \a out_value to the value of field specified by tag.
00036   // \returns 0 if such a field is not found or is of the wrong type.
00037   template< class T >
00038   bool get_property(vcl_string tag, T& out_value) const
00039   {
00040     return m_field_sequence.get_value( tag, out_value );
00041   }
00042 
00043   //: Sets out_value to the value of vcl_vector field element specified by tag and index.
00044   // \returns 0 if such a field is not found or is of the wrong type.
00045   template< class T >
00046   bool get_property(vcl_string tag, int i, T& out_value) const
00047   {
00048     return m_field_sequence.get_value( tag, i, out_value );
00049   }
00050 
00051   unsigned int nplanes() const;
00052   unsigned int get_pixels_per_block_x() const;
00053   unsigned int get_pixels_per_block_y() const;
00054   unsigned int get_num_blocks_x() const;
00055   unsigned int get_num_blocks_y() const;
00056   bool has_data_mask_table() const { return data_mask_table() != 0; }
00057   const vil_nitf2_data_mask_table* data_mask_table() const { return m_data_mask_table; }
00058 
00059   //:
00060   // Returns true if the ith image band in this image subheader has LUT info
00061   // and false otherwise.  If it returns true, then all the out parameters
00062   // will be populated from the header data.
00063   // \param n_luts: number of luts for this image band (NITF spec says
00064   //                it's in the range [1-4] (if luts present)
00065   // \param ne_lut: number of elements in each lut
00066   // \param lut_d: the LUT data indexed first by lut, then lut element
00067   //               ie, the last element would be lut_d[n_luts-1][ne_lut-1]
00068   //
00069   // See the NITF spec for exactly how this data is to be interpretted.  Here's
00070   // a summary:
00071   // LUTS always contain 8 bit unsigned data.  If n_luts is 1, then this band
00072   // is to be transformed into an 8-bit image plane.  Each pixel value in the
00073   // original image can be used as an index into lut_d.  (ie. lut_d[0][pixelVal])
00074   // If n_luts is 2, then the output image plate will be 16 bits.  The MSBs of
00075   // each of the output pixels will be obtained from lut_d[0] and the LSBs will
00076   // be obtained from lut_d[1].
00077   // If n_luts is 3, then this plane will be transformed into 3 planes: R, G and B.
00078   // lut_d[0] shall map to Red, lut_d[1] shall map to Green, and lut_d[2] shall map
00079   // to Blue.
00080   bool get_lut_info( unsigned int band, int& n_luts, int& ne_lut,
00081                      vcl_vector< vcl_vector< unsigned char > >& lut_d ) const;
00082 
00083   // I allocate the return value, but you own it after I return it to you
00084   // so you need to delete it.
00085   virtual vil_nitf2_field::field_tree* get_tree( int i = 0 ) const;
00086 
00087   //
00088   //: Get RPC parameters, if present. User provides rpc_data array.
00089   // The parameters describe a camera projection based on the 
00090   // ratio of cubic polynomials in (lon, lat, ele). All variables
00091   // are normalized to the range [-1, 1] using scale and offset parameters.
00092   // For further definition of parameters see 
00093   // http://www.ismc.nima.mil/ntb/superceded/vimas/vimas.pdf 
00094   // The returned rpc_data vector is encoded as:
00095   //  rpc_data[0]-rpc_data[19]         Line Numerator Cubic Coefficients
00096   //  rpc_data[20]-rpc_data[39]        Line Denominator Cubic Coefficients
00097   //  rpc_data[40]-rpc_data[59]        Sample Numerator Cubic Coefficients
00098   //  rpc_data[60]-rpc_data[79]        Sample Denominator Cubic Coefficients
00099   //  rpc_data[80] Line Offset         rpc_data[81] Sample Offset     
00100   //  rpc_data[82] Latitude Offset     rpc_data[83] Longitude Offset     
00101   //  rpc_data[84] Elevation Offset    rpc_data[85] Line Scale
00102   //  rpc_data[86] Sample Scale        rpc_data[87] Latitude Scale
00103   //  rpc_data[88] Longitude Scale     rpc_data[89] Elevation Scale     
00104   //
00105   //  The ordering of coefficients can vary as indicated by rpc_type
00106   //  Defined extensions are RPC00A and RPC00B.
00107   bool get_rpc_params( vcl_string& rpc_type, vcl_string& image_id, 
00108                        vcl_string& image_corner_geo_locations,
00109                        double* rpc_data );
00110 
00111  protected:
00112   vil_nitf2_field_sequence m_field_sequence;
00113   vil_nitf2_data_mask_table* m_data_mask_table;
00114 
00115   vil_nitf2_classification::file_version m_version;
00116 
00117   static const vil_nitf2_field_definitions* get_field_definitions_21();
00118   static const vil_nitf2_field_definitions* get_field_definitions_20();
00119 
00120  private:
00121   static void add_shared_field_defs_1( vil_nitf2_field_definitions* defs );
00122   static void add_shared_field_defs_2( vil_nitf2_field_definitions* defs );
00123   static void add_geo_field_defs( vil_nitf2_field_definitions* defs, const vil_nitf2_classification::file_version& version );
00124   static void add_shared_field_defs_3( vil_nitf2_field_definitions* defs );
00125   static void add_rpc_definitions();
00126   static vil_nitf2_field_definitions* s_field_definitions_21;
00127   static vil_nitf2_field_definitions* s_field_definitions_20;
00128   // so these static members can be cleaned up when the program is done
00129   // using nitf files
00130   friend void vil_nitf2::cleanup_static_members();
00131 };
00132 
00133 #endif // VIL_NITF2_IMAGE_SUBHEADER_H

Generated on Thu Jan 10 14:40:00 2008 for core/vil by  doxygen 1.4.4