This page describes the basic RasterElement importer provided in the plug-in sampler. This is a basic importer which simulates loading from a file and provides a fixed 1 band data array. The header file contains declarations for three classes.
class SampleRasterPage : public RasterPage class SampleRasterPager : public RasterPager class SampleRasterElementImporter : public RasterElementImporterShell
Now we'll exam the implementation of these classes.
#define NUM_ROWS 10 #define NUM_COLS 5 SampleRasterPage::SampleRasterPage(int row, int col) : mRow(row), mCol(col) { for (unsigned char r = 0; r < NUM_ROWS; ++r) { for (unsigned char c = 0; c < NUM_COLS; ++c) { mData.push_back(r * NUM_COLS + c); } } } SampleRasterPage::~SampleRasterPage() { } void* SampleRasterPage::getRawData() { return reinterpret_cast<void*>(&mData[mRow * NUM_COLS + mCol]); } unsigned int SampleRasterPage::getNumRows() { return NUM_ROWS - mRow; } unsigned int SampleRasterPage::getNumColumns() { return NUM_COLS; } unsigned int SampleRasterPage::getNumBands() { return 1; } unsigned int SampleRasterPage::getInterlineBytes() { return 0; } // End of SampleRasterPage
SampleRasterPager::SampleRasterPager()
{
}
SampleRasterPager::~SampleRasterPager()
{
}
RasterPage* SampleRasterPager::getPage(DataRequest* pOriginalRequest,
DimensionDescriptor startRow,
DimensionDescriptor startColumn,
DimensionDescriptor startBand)
{
return new SampleRasterPage(startRow.getOriginalNumber(), startColumn.getOriginalNumber());
}
void SampleRasterPager::releasePage(RasterPage* pPage)
{
delete dynamic_cast<SampleRasterPage*>(pPage);
}
int SampleRasterPager::getSupportedRequestVersion() const
{
return 1;
}
// End of SampleRasterPager
REGISTER_PLUGIN_BASIC(OpticksPlugInSampler, SampleRasterElementImporter); SampleRasterElementImporter::SampleRasterElementImporter() { setName("Sample RasterElement Importer"); setCreator("Opticks Community"); setVersion("Sample"); setCopyright("Copyright (C) 2008, Ball Aerospace & Technologies Corp."); setExtensions("Sample Files (*.sample)"); setDescription("Import sample data. It's really a static in-memory array that simulates an importer."); setSubtype("Sample"); setDescriptorId("{D1EBFE37-E365-4E49-92B5-B8DE0CA0B03D}");
unsigned char SampleRasterElementImporter::getFileAffinity(const std::string& filename) { FactoryResource<Filename> pFilename; pFilename->setFullPathAndName(filename); if (pFilename->getExtension() == "sample") { return Importer::CAN_LOAD; } return Importer::CAN_NOT_LOAD; } // End getFileAffinity
The getImportDescriptors() method may be time consuming. If this is the case, getFileAffinity() should use another, faster method and make a best guess about the file. This method is not called if the importer is explicitly selected.
bool SampleRasterElementImporter::isProcessingLocationSupported(ProcessingLocation location) const { return location == IN_MEMORY; } // End isProcessingLocationSupported
std::vector<ImportDescriptor*> SampleRasterElementImporter::getImportDescriptors(const std::string& filename) { std::vector<ImportDescriptor*> descriptors; ImportDescriptorResource pDesc(filename, TypeConverter::toString<RasterElement>()); VERIFYRV(pDesc.get() != NULL, descriptors); RasterDataDescriptor* pDataDesc = RasterUtilities::generateRasterDataDescriptor(filename, NULL, NUM_ROWS, NUM_COLS, INT1UBYTE, IN_MEMORY); if (pDataDesc == NULL) { return descriptors; } pDesc->setDataDescriptor(pDataDesc); if (RasterUtilities::generateAndSetFileDescriptor(pDataDesc, filename, "", LITTLE_ENDIAN_ORDER) == NULL) { return descriptors; } descriptors.push_back(pDesc.release()); return descriptors; } // End getImportDescriptors
An ImportDescriptorResource is created and populated with a DataDescriptor. RasterUtilities contains a number of functions which are usually used to create the DataDescriptor and FileDescriptor for a raster data set. If a file format's data can be loaded with the generic importer, all of the relevant attributes should be set on the FileDescriptor to indicate the header bytes, inter-line bytes, etc. This information is used by the generic RasterPager to map the data from disk to memory. The metadata for the data set should also be set in this method. A DynamicObject is created using a FactoryResource and the appropriate fields are populated. Call DataDescriptor::setMetadata() to assign the DynamicObject as the data set's metadata.
Often a file will contain multiple data sets which need to be created in a hierarchy. If a parent DataElement is also a part of the same file, it won't be available to set as the parent when creating a DataDescriptor. If this is the case, the ImportDescriptorResource contructor which takes a vector of strings should be used. The strings in the vector declare a parent path where each string is the name of a parent in the path. This is used to define a hierarchy before all the elements in the hierarchy have been created. The entire hierarchy must either exist before the importer is called or must be created by the importer.
bool SampleRasterElementImporter::createRasterPager(RasterElement* pRaster) const { VERIFY(pRaster != NULL); SampleRasterPager* pPager = new SampleRasterPager(); return pRaster->setPager(pPager); }