NitfHeader.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef NITFHEADER_H
00011 #define NITFHEADER_H
00012 
00013 #include <ossim/base/ossimDateProperty.h>
00014 #include <ossim/base/ossimContainerProperty.h>
00015 #include <ossim/base/ossimPropertyInterface.h>
00016 
00017 #include "ObjectResource.h"
00018 #include "StringUtilities.h"
00019 #include "NitfUtilities.h"
00020 
00021 #include <string>
00022 #include <vector>
00023 
00024 class DateTime;
00025 class DynamicObject;
00026 class RasterDataDescriptor;
00027 
00028 class ossimContainerProperty;
00029 class ossimPropertyInterface;
00030 
00031 namespace Nitf
00032 {
00033    /**
00034     * The Header class contains all knowledge needed to succesfully
00035     * import or export a given NITF header.
00036     *
00037     * To be useful, this class must be subclassed to provide behavior
00038     * for a specific header or subheader.  Subclass behavior must
00039     * include a public import method, which calls the protected one on
00040     * this class.
00041     *
00042     * When importing or exporting, the Header iterates over the contents
00043     * of Header::mElements, calling the appropriate functions to import/export.
00044     */
00045    class Header
00046    {
00047    public:
00048       /**
00049        * Destructs the object.
00050        */
00051       virtual ~Header();
00052 
00053       /**
00054        * Import the metadata from OSSIM into a given DynamicObject.
00055        *
00056        * Subclasses must provide a public import method, which eventually
00057        * calls this one.
00058        *
00059        * Imports according to the specification in Header::mElements.
00060        *
00061        * @param pProperties
00062        *        The header to import from.
00063        * @param pDescriptor
00064        *        The Descriptor to import to.
00065        * @param pDynObj
00066        *        The DynamicObject to import according to the specification.
00067        *
00068        * @return True if the operation succeeded, false otherwise.
00069        */
00070       bool importMetadata(const ossimPropertyInterface* pProperties,
00071          RasterDataDescriptor* pDescriptor, DynamicObject* pDynObj);
00072 
00073       /**
00074        * Export all metadata from the given descriptor to the export header.
00075        *
00076        * This is performed by exporting two DynamicObjects.  First,
00077        * the DynamicObject created by createDefaultsDynamicObject is
00078        * exported.  This should contain any defaults to be exported.
00079        * This is most useful if the RasterElement wasn't originally a NITF file.
00080        *
00081        * Second, the DynamicObject for this header from the DataDescriptor's metadata 
00082        * object is exported.  This should contain metadata as imported from a NITF.
00083        *
00084        * @param pDescriptor
00085        *        The descriptor to export.
00086        * @param pExportHeader
00087        *        The OSSIM header to export to.
00088        *
00089        * @return True if the operation was successful, false otherwise.
00090        */
00091       bool exportMetadata(const RasterDataDescriptor *pDescriptor, 
00092          ossimContainerProperty *pExportHeader);
00093 
00094    protected:
00095       /**
00096        * Construct a Header with a given name.
00097        *
00098        * @param fileVersion
00099        *        The version of this NITF file.
00100        */
00101       Header(const std::string &fileVersion);
00102 
00103       /**
00104        * Returns the metadata location.
00105        *
00106        * @return The name to place and retrieve the main metadata DynamicObject for this header.
00107        */
00108       virtual std::string getMetadataPath() const = 0;
00109 
00110       /**
00111        * Create defaults to export from the given DataDescriptor.
00112        *
00113        * @param pDescriptor
00114        *        Descriptor which will be exported.  May be needed to
00115        *        create defaults.
00116        *
00117        * @return The defaults DynamicObject, wrapped in a FactoryResource to prevent leaks.
00118        */
00119       virtual FactoryResource<DynamicObject> createDefaultsDynamicObject(
00120          const RasterDataDescriptor *pDescriptor) = 0;
00121 
00122       /**
00123        * Exports a provided DynamicObject according to the specification in Header::mElements.
00124        *
00125        * @param pDescriptor
00126        *        The Descriptor to export
00127        * @param pDynObj
00128        *        The DynamicObject to export from.
00129        * @param pProperties
00130        *        The OSSIM header to export to.
00131        *
00132        * @return True if the operation succeeded, false otherwise.
00133        */
00134       bool exportMetadata(const RasterDataDescriptor *pDescriptor,
00135          const DynamicObject *pDynObj, 
00136          ossimContainerProperty *pProperties);
00137 
00138       /**
00139        * Typedef for function pointer to use to import a specific piece of
00140        * metadata.
00141        *
00142        * Write functions which follow this typedef to add custom behavior
00143        * for import.  See importMetadataValue for an example.
00144        */
00145       typedef bool(*ImportFunction)(const ossimPropertyInterface *pProperties,
00146          RasterDataDescriptor *pDescriptor, 
00147          DynamicObject *pDynObj, const std::string& appName, 
00148          const std::string& ossimName);
00149 
00150       /**
00151        * Typedef for function pointer to use to export a specific piece of
00152        * metadata.
00153        *
00154        * Write functions which follow this typedef to add custom behavior
00155        * for import.  See exportMetadataValue for an example.
00156        */
00157       typedef bool(*ExportFunction)(const RasterDataDescriptor *pDescriptor, 
00158          const DataVariant &prop, 
00159          ossimContainerProperty *pProperties, const std::string& appName,
00160          const std::string& ossimName);
00161 
00162       /**
00163        * Generic function to import most metadata.
00164        *
00165        * This function is templated on type to import to the DynamicObject.
00166        *
00167        * @param pPropertyInterface
00168        *        OSSIM property interface to import from.
00169        * @param pDescriptor
00170        *        Descriptor to import to.
00171        * @param pDynObj
00172        *        DynamicObject to import to.
00173        * @param appName
00174        *        The name which is used internally.
00175        * @param ossimName
00176        *        The name which OSSIM uses to access the property.
00177        *
00178        * @return True if the metadata was successfully imported, false otherwise.
00179        */
00180       template<typename T>
00181       static bool importMetadataValue(const ossimPropertyInterface *pPropertyInterface,
00182          RasterDataDescriptor *pDescriptor,
00183          DynamicObject *pDynObj, const std::string& appName,
00184          const std::string& ossimName)
00185       {
00186          if (pPropertyInterface == NULL)
00187          {
00188             return false;
00189          }
00190 
00191          ossimRefPtr<ossimProperty> pProperty = pPropertyInterface->getProperty(ossimName);
00192          ossimProperty* pProp = pProperty.get();
00193          if (pProp == NULL)
00194          {
00195             return false;
00196          }
00197 
00198          DataVariant var;
00199          string value = pProp->valueToString();
00200          if (var.fromXmlString(TypeConverter::toString<T>(), value) == DataVariant::SUCCESS)
00201          {
00202             return pDynObj->setAttribute(appName, var);
00203          }
00204 
00205          return false;
00206       }
00207 
00208       /**
00209        * Generic function to export most metadata.
00210        *
00211        * This function is templated on type stored in the DynamicObject.
00212        *
00213        * @param pDescriptor
00214        *        Descriptor to export from.
00215        * @param prop
00216        *        DataVariant with stored metadata.
00217        * @param pProperties
00218        *        ossimContainerProperty to export the metadata to.
00219        * @param appName
00220        *        The name which is used internally.
00221        * @param ossimName
00222        *        The name which OSSIM uses to access the property.
00223        *
00224        * @return True if the metadata was successfully exported, false otherwise.
00225        */
00226       template<typename T>
00227       static bool exportMetadataValue(const RasterDataDescriptor *pDescriptor, 
00228          const DataVariant &prop, 
00229          ossimContainerProperty *pProperties, const std::string& appName,
00230          const std::string& ossimName)
00231       {
00232          const T *pT = prop.getPointerToValue<T>();
00233          if (pT == NULL)
00234          {
00235             return false;
00236          }
00237 
00238          string stringValue = StringUtilities::toXmlString(*pT);
00239          if (!stringValue.empty())
00240          {
00241             ossimRefPtr<ossimProperty> pProperty = pProperties->getProperty(ossimName);
00242             if (pProperty.get() != NULL)
00243             {
00244                return pProperty->setValue(stringValue);
00245             }
00246          }
00247 
00248          return false;
00249       }
00250 
00251       /**
00252        * Import an ossimBinaryDataProperty object as a vector<unsigned char>.
00253        *
00254        * @param pPropertyInterface
00255        *        OSSIM property interface to import from.
00256        * @param pDescriptor
00257        *        Descriptor to import to.
00258        * @param pDynObj
00259        *        DynamicObject to import to.
00260        * @param appName
00261        *        The name which is used internally.
00262        * @param ossimName
00263        *        The name which OSSIM uses to access the property.
00264        *
00265        * @return True if the metadata was successfully imported, false otherwise.
00266        */
00267       static bool importBinaryData(const ossimPropertyInterface *pPropertyInterface,
00268          RasterDataDescriptor *pDescriptor,
00269          DynamicObject *pDynObj, const std::string& appName,
00270          const std::string& ossimName);
00271 
00272       /**
00273        * Export vector<unsigned char> to an ossimBinaryDataProperty object.
00274        *
00275        * @param pDescriptor
00276        *        Descriptor to export from.
00277        * @param prop
00278        *        DataVariant with stored metadata.
00279        * @param pProperties
00280        *        ossimContainerProperty to export the metadata to.
00281        * @param appName
00282        *        The name which is used internally.
00283        * @param ossimName
00284        *        The name which OSSIM uses to access the property.
00285        *
00286        * @return True if the metadata was successfully exported, false otherwise.
00287        */
00288       static bool exportBinaryData(const RasterDataDescriptor *pDescriptor, 
00289          const DataVariant &prop,
00290          ossimContainerProperty *pProperties, const std::string& appName,
00291          const std::string& ossimName);
00292 
00293       /**
00294        * Import ossimColorProperty objects as ColorType objects.
00295        *
00296        * @param pPropertyInterface
00297        *        OSSIM property interface to import from.
00298        * @param pDescriptor
00299        *        Descriptor to import to.
00300        * @param pDynObj
00301        *        DynamicObject to import to.
00302        * @param appName
00303        *        The name which is used internally.
00304        * @param ossimName
00305        *        The name which OSSIM uses to access the property.
00306        *
00307        * @return True if the metadata was successfully imported, false otherwise.
00308        */
00309       static bool importColor(const ossimPropertyInterface *pPropertyInterface,
00310          RasterDataDescriptor *pDescriptor,
00311          DynamicObject *pDynObj, const std::string& appName,
00312          const std::string& ossimName);
00313 
00314       /**
00315        * Export ColorType objects to ossimColorProperty objects.
00316        *
00317        * @param pDescriptor
00318        *        Descriptor to export from.
00319        * @param prop
00320        *        DataVariant with stored metadata.
00321        * @param pProperties
00322        *        ossimContainerProperty to export the metadata to.
00323        * @param appName
00324        *        The name which is used internally.
00325        * @param ossimName
00326        *        The name which OSSIM uses to access the property.
00327        *
00328        * @return True if the metadata was successfully exported, false otherwise.
00329        */
00330       static bool exportColor(const RasterDataDescriptor *pDescriptor, 
00331          const DataVariant &prop,
00332          ossimContainerProperty *pProperties, const std::string& appName,
00333          const std::string& ossimName);
00334 
00335       /**
00336        * Import dates stored in CCYYMMDDhhmmss format.
00337        *
00338        * @param pPropertyInterface
00339        *        OSSIM property interface to import from.
00340        * @param pDescriptor
00341        *        Descriptor to import to.
00342        * @param pDynObj
00343        *        DynamicObject to import to.
00344        * @param appName
00345        *        The name which is used internally.
00346        * @param ossimName
00347        *        The name which OSSIM uses to access the property.
00348        *
00349        * @return True if the metadata was successfully imported, false otherwise.
00350        */
00351       static bool importDateCCYYMMDDhhmmss(const ossimPropertyInterface *pPropertyInterface,
00352          RasterDataDescriptor *pDescriptor,
00353          DynamicObject *pDynObj, const std::string& appName,
00354          const std::string& ossimName);
00355 
00356       /**
00357        * Export dates stored in CCYYMMDDhhmmss format.
00358        *
00359        * @param pDescriptor
00360        *        Descriptor to export from.
00361        * @param prop
00362        *        DataVariant with stored metadata.
00363        * @param pProperties
00364        *        ossimContainerProperty to export the metadata to.
00365        * @param appName
00366        *        The name which is used internally.
00367        * @param ossimName
00368        *        The name which OSSIM uses to access the property.
00369        *
00370        * @return True if the metadata was successfully exported, false otherwise.
00371        */
00372       static bool exportDateCCYYMMDDhhmmss(const RasterDataDescriptor *pDescriptor, 
00373          const DataVariant &prop,
00374          ossimContainerProperty *pProperties, const std::string& appName,
00375          const std::string& ossimName);
00376 
00377       /**
00378        * Import dates stored in CCYYMMDD format.
00379        *
00380        * @param pPropertyInterface
00381        *        OSSIM property interface to import from.
00382        * @param pDescriptor
00383        *        Descriptor to import to.
00384        * @param pDynObj
00385        *        DynamicObject to import to.
00386        * @param appName
00387        *        The name which is used internally.
00388        * @param ossimName
00389        *        The name which OSSIM uses to access the property.
00390        *
00391        * @return True if the metadata was successfully imported, false otherwise.
00392        */
00393       static bool importDateCCYYMMDD(const ossimPropertyInterface *pPropertyInterface,
00394          RasterDataDescriptor *pDescriptor, 
00395          DynamicObject *pDynObj, const std::string& appName, 
00396          const std::string& ossimName);
00397 
00398       /**
00399        * Export dates stored in CCYYMMDD format.
00400        *
00401        * @param pDescriptor
00402        *        Descriptor to export from.
00403        * @param prop
00404        *        DataVariant with stored metadata.
00405        * @param pProperties
00406        *        ossimContainerProperty to export the metadata to.
00407        * @param appName
00408        *        The name which is used internally.
00409        * @param ossimName
00410        *        The name which OSSIM uses to access the property.
00411        *
00412        * @return True if the metadata was successfully exported, false otherwise.
00413        */
00414       static bool exportDateCCYYMMDD(const RasterDataDescriptor *pDescriptor, 
00415          const DataVariant &prop,
00416          ossimContainerProperty *pProperties, const std::string& appName,
00417          const std::string& ossimName);
00418 
00419       /**
00420        * Import dates stored in DDHHMMSSZMONYY format.
00421        *
00422        * @param pPropertyInterface
00423        *        OSSIM property interface to import from.
00424        * @param pDescriptor
00425        *        Descriptor to import to.
00426        * @param pDynObj
00427        *        DynamicObject to import to.
00428        * @param appName
00429        *        The name which is used internally.
00430        * @param ossimName
00431        *        The name which OSSIM uses to access the property.
00432        *
00433        * @return True if the metadata was successfully imported, false otherwise.
00434        */
00435       static bool importDateDDHHMMSSZMONYY(const ossimPropertyInterface *pPropertyInterface,
00436          RasterDataDescriptor *pDescriptor, 
00437          DynamicObject *pDynObj, const std::string& appName, 
00438          const std::string& ossimName);
00439 
00440       /**
00441        * Import dates stored in YYMMDD format.
00442        *
00443        * @param pPropertyInterface
00444        *        OSSIM property interface to import from.
00445        * @param pDescriptor
00446        *        Descriptor to import to.
00447        * @param pDynObj
00448        *        DynamicObject to import to.
00449        * @param appName
00450        *        The name which is used internally.
00451        * @param ossimName
00452        *        The name which OSSIM uses to access the property.
00453        *
00454        * @return True if the metadata was successfully imported, false otherwise.
00455        */
00456       static bool importDateYYMMDD(const ossimPropertyInterface *pPropertyInterface,
00457          RasterDataDescriptor *pDescriptor, 
00458          DynamicObject *pDynObj, const string& appName, 
00459          const string& ossimName);
00460 
00461       /**
00462        * An Element contains all information needed to import
00463        * and export a piece of metadata.
00464        */
00465       struct Element
00466       {
00467          /**
00468           * The name used internally.
00469           */
00470          std::string mAppName;
00471 
00472          /**
00473           * The name used in OSSIM.
00474           */
00475          std::string mOssimName;
00476 
00477          /**
00478           * The function used to import the metadata.
00479           */
00480          ImportFunction mImportFunction;
00481 
00482          /**
00483           * The function used to export the metadata.
00484           */
00485          ExportFunction mExportFunction;
00486 
00487          /**
00488           * Constructor to fully populate the object.
00489           */
00490          Element(const std::string &appName, const std::string &ossimName,
00491             ImportFunction importFunction, ExportFunction exportFunction);
00492 
00493          /**
00494           * Constructor to populate the object with only an ImportFunction and ExportFunction.
00495           */
00496          Element(ImportFunction importFunction, ExportFunction exportFunction);
00497       };
00498 
00499       /**
00500        * Contains all Element objects for import and/or export.
00501        */
00502       std::vector<Element> mElements;
00503 
00504       /**
00505        * The version of the NITF file - either Nitf::VERSION_02_00 or Nitf::VERSION_02_10.
00506        */
00507       const std::string mFileVersion;
00508 
00509    private:
00510       Header& operator=(const Header& rhs);
00511    };
00512 }
00513 
00514 #endif

Software Development Kit - Opticks 4.9.0 Build 16218