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 SIMPLEAPIDATAACCESSOR_H 00011 #define SIMPLEAPIDATAACCESSOR_H 00012 00013 #include "AppConfig.h" 00014 00015 class DataAccessorImpl; 00016 class DataElement; 00017 class RasterElement; 00018 00019 #ifdef __cplusplus 00020 extern "C" 00021 { 00022 #endif 00023 /** \addtogroup simple_api */ 00024 /*@{*/ 00025 00026 /** 00027 * @file RasterData.h 00028 * This file contains API utilities for accessing raster data. Many of these methods are wrappers around methods in 00029 * RasterElement, RasterDataDescriptor, RasterUtilities, DataRequest, and DataAccessorImpl. 00030 */ 00031 00032 /** 00033 * Descriptor for data dimensions. The values returned here reflect currently active values, not necessarily those 00034 * found in the file. This can occur if the data set was subcubed or if the interleave was converted during import. 00035 */ 00036 struct DataInfo 00037 { 00038 uint32_t numRows; /**< The number of rows in the data. */ 00039 uint32_t numColumns; /**< The number of columns in the data. */ 00040 uint32_t numBands; /**< The number of bands in the data. */ 00041 uint32_t interleaveFormat; /**< 0 -> BSQ, 1 -> BIP, 2 -> BIL. @see InterleaveFormatType */ 00042 uint32_t encodingType; /**< 0 -> char, 1 -> unsigned char, 2 -> short, 3 -> unsigned short, 00043 4 -> complex short, 5 -> int, 6 -> unsigned int, 7 -> float, 00044 8 -> complex float, 9 -> double. @see EncodingType */ 00045 uint32_t encodingTypeSize; /**< The number of bytes per element. @see RasterUtilities::bytesInEncoding() */ 00046 uint32_t numBadValues; /**< The number of entries in pBadValues. */ 00047 int32_t* pBadValues; /**< Array containing bad values for this data 00048 set or \c NULL if no bad values exist. */ 00049 }; 00050 00051 /** 00052 * Obtain data dimensions for the given RasterElement. 00053 * 00054 * @param pElement 00055 * The RasterElement to query. 00056 * @return A fully populated DataInfo for the given RasterElement. 00057 * On failure, \c NULL is returned and getLastError() may be queried for information on the error. 00058 * Ownership is transfered to the called and the memory must be freed by calling destroyDataInfo(). 00059 * 00060 * @see getDataElement(), destroyDataInfo() 00061 */ 00062 EXPORT_SYMBOL DataInfo* createDataInfo(DataElement* pElement); 00063 00064 /** 00065 * Destroy a pointer obtained by calling createDataInfo(). 00066 * 00067 * Suitable for use as a cleanup callback. 00068 * 00069 * @param pDataInfo 00070 * A DataInfo obtained by calling createDataInfo. 00071 * 00072 * @see createDataInfo() 00073 */ 00074 EXPORT_SYMBOL void destroyDataInfo(DataInfo* pDataInfo); 00075 00076 /** 00077 * Descriptor for creating a RasterElement. 00078 */ 00079 struct RasterElementArgs 00080 { 00081 uint32_t numRows; /**< The number of rows in the data. */ 00082 uint32_t numColumns; /**< The number of columns in the data. */ 00083 uint32_t numBands; /**< The number of bands in the data. */ 00084 uint32_t interleaveFormat; /**< 0 -> BSQ, 1 -> BIP, 2 -> BIL. @see InterleaveFormatType */ 00085 uint32_t encodingType; /**< 0 -> char, 1 -> unsigned char, 2 -> short, 3 -> unsigned short, 00086 4 -> complex short, 5 -> int, 6 -> unsigned int, 7 -> float, 00087 8 -> complex float, 9 -> double. @see EncodingType */ 00088 uint32_t location; /**< 0 -> Prefer RAM but allow on-disk, 1 -> Only RAM, 2 -> Only on-disk */ 00089 DataElement* pParent; /**< The parent of this RasterElement or \c NULL if it has no parent. */ 00090 uint32_t numBadValues; /**< The number of entries in pBadValues. */ 00091 int32_t* pBadValues; /**< Array containing bad values for this data set or 00092 \c NULL if no bad values exist. */ 00093 }; 00094 00095 /** 00096 * Creates a RasterElement with the given parameters that can be immediately used. This method 00097 * should only be used by plug-ins that need to programmatically create a RasterElement to store 00098 * results of an algorithm. It should NOT be used by importers or exporters to create a RasterElement 00099 * It should also NOT be used to create a RasterElement that corresponds to a data file on the filesystem. 00100 * 00101 * @param pName 00102 * A \c NULL terminated C-style string containing the name for the new RasterElement. This cannot be \c NULL. 00103 * @param args 00104 * The structure containing information to process the request. 00105 * @return A RasterElement created with the given parameters that requires no additional initialization. 00106 * 00107 * @see destroyDataElement() 00108 */ 00109 EXPORT_SYMBOL DataElement* createRasterElement(const char* pName, RasterElementArgs args); 00110 00111 /** 00112 * Descriptor for data access. 00113 * Rows, columns, and bands are all 0-based and reflect active numbers. 00114 * 00115 * @see DataRequest 00116 */ 00117 struct DataPointerArgs 00118 { 00119 uint32_t rowStart; /**< The first row to access. */ 00120 uint32_t rowEnd; /**< The last row to access. */ 00121 00122 uint32_t columnStart; /**< The first column to access. */ 00123 uint32_t columnEnd; /**< The last column to access. */ 00124 00125 uint32_t bandStart; /**< The first band to access. */ 00126 uint32_t bandEnd; /**< The last band to access. */ 00127 00128 uint32_t interleaveFormat; /**< 0 -> BSQ, 1 -> BIP, 2 -> BIL. @see InterleaveFormatType */ 00129 }; 00130 00131 /** 00132 * Obtain a writable pointer to raw data in memory which must be destroyed by calling destroyDataPointer(). 00133 * In some cases this method returns a pointer to the original data. In other cases a copy must be created. 00134 * 00135 * @param pElement 00136 * The RasterElement to access. 00137 * @param pArgs 00138 * The structure containing information to process the request or \c NULL to access the entire cube. 00139 * @param pOwn 00140 * An output parameter which will contain 0 if the caller does not take ownership of the return value 00141 * and a non-zero if the caller takes ownership of the return value. If this is non-zero, the caller 00142 * must release the memory by calling destroyDataPointer(). If this is 0, the return value points to 00143 * the original data and any modifications to this buffer will modify the original data. 00144 * @return A writable pointer to a three-dimensional matrix containing raster data. 00145 * On failure, \c NULL is returned and getLastError() may be queried for information on the error. 00146 * @see getDataElement(), destroyDataPointer(), createDataAccessor(), 00147 * updateDataElement(), RasterElement::getRawData() 00148 */ 00149 EXPORT_SYMBOL void* createDataPointer(DataElement* pElement, DataPointerArgs* pArgs, int* pOwn); 00150 00151 /** 00152 * Destroy a pointer obtained by calling createDataPointer(). 00153 * 00154 * Suitable for use as a cleanup callback. 00155 * 00156 * @param pData 00157 * The value returned by createDataPointer(). 00158 * 00159 * @see createDataPointer(), updateDataElement() 00160 */ 00161 EXPORT_SYMBOL void destroyDataPointer(void* pData); 00162 00163 /** 00164 * Copy data from a contiguous C array in a RasterElement. 00165 * 00166 * The caller should call updateRasterElement() to redisplay the data. 00167 * 00168 * @param pElement 00169 * The RasterElement to access. 00170 * @param pArgs 00171 * The structure containing information to process the request. 00172 * This specifies the parameters for the DataAccessor which will 00173 * be used to write to the RasterElement. If this is \c NULL and 00174 * RasterElement::getRawData() returns a valid pointer, a single 00175 * memcpy() will be used to replace the contents of the RasterElement. 00176 * @param pData 00177 * A pointer to a three-dimensional matrix containing raster data. 00178 * The format of this data must match the information in pArgs or the RasterElement 00179 * parameters if pArgs is \c NULL. If necessary, the caller must reformat this data 00180 * prior to copying it to the RasterElement. 00181 * @return a non-zero on failure or a zero on success. 00182 * @see updateDataElement() 00183 */ 00184 EXPORT_SYMBOL int copyDataToRasterElement(DataElement* pElement, DataPointerArgs* pArgs, void* pData); 00185 00186 /** 00187 * Notfiy %Opticks that a RasterElement's data has changed. 00188 * 00189 * @param pElement 00190 * The RasterElement to update. 00191 */ 00192 EXPORT_SYMBOL void updateRasterElement(DataElement* pElement); 00193 00194 /** 00195 * Descriptor for data access. 00196 * Rows, columns, and bands are all 0-based and reflect active numbers. 00197 * 00198 * @see DataRequest 00199 */ 00200 struct DataAccessorArgs 00201 { 00202 uint32_t rowStart; /**< The first row to access. */ 00203 uint32_t rowEnd; /**< The last row to access. */ 00204 uint32_t concurrentRows; /**< The number of rows to access concurrently or 0 to use the default. */ 00205 00206 uint32_t columnStart; /**< The first column to access. */ 00207 uint32_t columnEnd; /**< The last column to access. */ 00208 uint32_t concurrentColumns;/**< The number of columns to access concurrently or 0 to use the default. */ 00209 00210 uint32_t bandStart; /**< The first band to access. */ 00211 uint32_t bandEnd; /**< The last band to access. */ 00212 uint32_t concurrentBands; /**< The number of bands to access concurrently or 0 to use the default. */ 00213 00214 uint32_t interleaveFormat; /**< 0 -> BSQ, 1 -> BIP, 2 -> BIL. @see InterleaveFormatType */ 00215 uint32_t writable; /**< 0 -> Do not request write access, Any other value -> Request write access. */ 00216 }; 00217 00218 /** 00219 * Create a DataAccessor for accessing raster data which must be destroyed by calling destroyDataAccessor(). 00220 * 00221 * @param pElement 00222 * The RasterElement to access. 00223 * 00224 * @param pArgs 00225 * The structure containing information to process the request or \c NULL to use default arguments. 00226 * Default arguments are determined heuristically based on the data set. 00227 * 00228 * @return A newly-created DataAccessor which must be destroyed by calling destroyDataAccessor. 00229 * On failure, \c NULL is returned and getLastError() may be queried for information on the error. 00230 * Note this is actually a DataAccessorImpl since DataAccessor is used for reference counting in C++. 00231 * 00232 * @see getDataElement(), destroyDataAccessor() 00233 */ 00234 EXPORT_SYMBOL DataAccessorImpl* createDataAccessor(DataElement* pElement, DataAccessorArgs* pArgs); 00235 00236 /** 00237 * Destroy a DataAccessorImpl created with createDataAccessor(). 00238 * 00239 * Suitable for use as a cleanup callback. 00240 * 00241 * @param pAccessor 00242 * The DataAccessorImpl to destroy. 00243 */ 00244 EXPORT_SYMBOL void destroyDataAccessor(DataAccessorImpl* pAccessor); 00245 00246 /** 00247 * Determines if the DataAccessor is valid. 00248 * 00249 * @param pAccessor 00250 * The DataAccessorImpl to use. 00251 * @return Returns 0 if the data accessor is not valid or non-zero if it is valid. 00252 * 00253 * @see DataAccessor::isValid() 00254 */ 00255 EXPORT_SYMBOL int isDataAccessorValid(DataAccessorImpl* pAccessor); 00256 00257 /** 00258 * Gets a row of values. 00259 * 00260 * This method returns a pointer to the first element in an array that is 00261 * guaranteed to be at least (concurrent columns * number of bands) in size 00262 * for BIP data and (concurrent columns) in size for BSQ data. 00263 * 00264 * @param pAccessor 00265 * The DataAccessorImpl to use. 00266 * @return Pointer to the raw block of data from the dataset. 00267 * On failure, \c NULL is returned and getLastError() may be queried for information on the error. 00268 * 00269 * @see isValid(), DataAccessorImpl::getRow() 00270 */ 00271 EXPORT_SYMBOL void* getDataAccessorRow(DataAccessorImpl* pAccessor); 00272 00273 /** 00274 * Advances to a succeeding row in the dataset. 00275 * 00276 * @param pAccessor 00277 * The DataAccessorImpl to use. 00278 * @param count 00279 * The number of rows to advance. 00280 * @param resetColumn 00281 * non-zero -> Reset the column to the beginning column of the accessor, 0 -> Maintain the current column. 00282 * 00283 * @see DataAccessorImpl::nextRow(int, bool) 00284 */ 00285 EXPORT_SYMBOL void nextDataAccessorRow(DataAccessorImpl* pAccessor, uint32_t count, int resetColumn); 00286 00287 /** 00288 * Gets a column of values. 00289 * 00290 * This method returns a pointer to the first element in an array 00291 * that is guaranteed to be at least the number of bands in size 00292 * for BIP data and one in size for BSQ data. 00293 * 00294 * @param pAccessor 00295 * The DataAccessorImpl to use. 00296 * @return Pointer to the raw block of data from the data set. 00297 * On failure, \c NULL is returned and getLastError() may be queried for information on the error. 00298 * 00299 * @see DataAccessorImpl::getColumn() 00300 */ 00301 EXPORT_SYMBOL void* getDataAccessorColumn(DataAccessorImpl* pAccessor); 00302 00303 /** 00304 * Advances to a succeeding column in the dataset. 00305 * 00306 * @param pAccessor 00307 * The DataAccessorImpl to use. 00308 * @param count 00309 * The number of columns to advance. 00310 * 00311 * @see DataAccessorImpl::nextColumn(int) 00312 */ 00313 EXPORT_SYMBOL void nextDataAccessorColumn(DataAccessorImpl* pAccessor, uint32_t count); 00314 00315 /** 00316 * Jumps to the specified pixel. 00317 * 00318 * @param pAccessor 00319 * The DataAccessorImpl to use. 00320 * @param row 00321 * The row to access. This must be less than the total number of rows. 00322 * @param column 00323 * The column to access. This must be less than the total number of columns. 00324 * 00325 * @see DataAccessorImpl::toPixel(int, int) 00326 */ 00327 EXPORT_SYMBOL void toDataAccessorPixel(DataAccessorImpl* pAccessor, uint32_t row, uint32_t column); 00328 00329 /** 00330 * Returns the RasterElement associated with this DataAccessor. 00331 * 00332 * @param pAccessor 00333 * The DataAccessor to use. 00334 * @return Returns the RasterElement associated with this class. 00335 * On failure, \c NULL is returned and getLastError() may be queried for information on the error. 00336 * 00337 * @see DataAccessorImpl::getAssociatedRasterElement() 00338 */ 00339 EXPORT_SYMBOL RasterElement* getDataAccessorRasterElement(DataAccessorImpl* pAccessor); 00340 00341 /** 00342 * Access the size in bytes of a row of data. 00343 * 00344 * This includes the number of bytes of actual data in a row 00345 * and excludes preline and postline bytes. 00346 * 00347 * @note If using this information to access an entire row 00348 * of data with getDataAccessorRow(), you must ensure that the DataAccessor's 00349 * concurrent columns (and concurrent bands if the accessor is BIP) 00350 * is equal to the number of columns in the data set. 00351 * 00352 * @param pAccessor 00353 * The DataAccessorImpl to use. 00354 * @return The number of bytes in a row of data excluding preline and postline bytes. 00355 * 00356 * @see DataAccessorImpl::getRowSize() 00357 */ 00358 EXPORT_SYMBOL uint32_t getDataAccessorRowSize(DataAccessorImpl* pAccessor); 00359 00360 /*@}*/ 00361 #ifdef __cplusplus 00362 } 00363 #endif 00364 00365 #endif