void ossimEdgeFilter::adjustRequestRect(ossimIrect& requestRect)const { ossimString filterType = theFilterType; filterType = filterType.downcase(); ossimIrect rect = requestRect; if(filterType.contains("sob")|| filterType.contains("lap")|| filterType.contains("pre")|| filterType.contains("localmax")) { requestRect = ossimIrect(rect.ul().x - 1, rect.ul().y - 1, rect.lr().x + 1, rect.lr().y + 1); } else if(filterType.contains("rob")) { requestRect = ossimIrect(rect.ul().x, rect.ul().y, rect.lr().x + 1, rect.lr().y + 1); } else { requestRect = ossimIrect(rect.ul().x - 1, rect.ul().y - 1, rect.lr().x + 1, rect.lr().y + 1); } }
//************************************************************************************************* //! Reads the TIL file for pertinent info. Returns TRUE if successful //************************************************************************************************* bool ossimQuickbirdRpcModel::parseTileData(const ossimFilename& image_file) { ossimFilename tileFile (image_file); tileFile.setExtension("TIL"); if (!findSupportFile(tileFile)) return false; ossimQuickbirdTile tileHdr; if(!tileHdr.open(tileFile)) return false; ossimQuickbirdTileInfo info; if(!tileHdr.getInfo(info, image_file.file())) return false; if((info.theUlXOffset != OSSIM_INT_NAN) && (info.theUlYOffset != OSSIM_INT_NAN) && (info.theLrXOffset != OSSIM_INT_NAN) && (info.theLrYOffset != OSSIM_INT_NAN) && (info.theLlXOffset != OSSIM_INT_NAN) && (info.theLlYOffset != OSSIM_INT_NAN) && (info.theUrXOffset != OSSIM_INT_NAN) && (info.theUrYOffset != OSSIM_INT_NAN)) { theImageClipRect = ossimIrect(ossimIpt(info.theUlXOffset, info.theUlYOffset), ossimIpt(info.theUrXOffset, info.theUrYOffset), ossimIpt(info.theLrXOffset, info.theLrYOffset), ossimIpt(info.theLlXOffset, info.theLlYOffset)); } else if ((info.theUlXOffset != OSSIM_INT_NAN) && (info.theUlYOffset != OSSIM_INT_NAN) && (theImageClipRect.width() != OSSIM_INT_NAN) && (theImageClipRect.height() != OSSIM_INT_NAN)) { theImageClipRect = ossimIrect(info.theUlXOffset, info.theUlYOffset, info.theUlXOffset+theImageClipRect.width()-1, info.theUlYOffset+theImageClipRect.height()-1); } return true; }
void ossim::getRect(const kdu_core::kdu_dims& dims, ossimIrect& rect) { rect = ossimIrect(dims.pos.x, dims.pos.y, dims.pos.x + dims.size.x - 1, dims.pos.y + dims.size.y - 1); }
bool ossimKakaduJ2kReader::loadTile(ossim_uint32 x, ossim_uint32 y) { bool result = true; ossimIpt ul(x, y); ossimIpt lr(ul.x + theTileSizeX - 1, ul.y + theTileSizeY - 1); // Set the cache rectangle to be an even j2k tile. theCacheTile->setImageRectangle(ossimIrect(ul, lr)); //--- // Let the getOverviewTile do the rest of the work. if ( getOverviewTile(0, theCacheTile.get()) ) { // Add it to the cache for the next time. ossimAppFixedTileCache::instance()->addTile(theCacheId, theCacheTile); } else { ossimNotify(ossimNotifyLevel_WARN) << __FILE__ << __LINE__ << " ossimKakaduJ2kReader::loadBlock failed!" << std::endl; result = false; } return result; }
void ossimGui::StaticTileImageCache::flush(const ossimIpt& pt) { flush(ossimIrect(pt.x, pt.y, pt.x, pt.y)); }
void ossimTilingPoly::setRect() { ossimIrect rect = m_exteriorCut->getRectangle(); if (rect.intersects(theImageRect)) { m_featureBoundingIntersect = true; if (!rect.completely_within(theImageRect)) { ossimIrect clipRect = rect.clipToRect(theImageRect); m_exteriorCut->setRectangle(clipRect); rect = clipRect; } } else { m_featureBoundingIntersect = false; } if (m_useMbr) { if (thePaddingSizeInPixels.x > 0 && thePaddingSizeInPixels.y > 0) { ossimIrect newRect = ossimIrect(rect.ul().x-(ossim_int32)thePaddingSizeInPixels.x, rect.ul().y-(ossim_int32)thePaddingSizeInPixels.y, rect.lr().x + (ossim_int32)thePaddingSizeInPixels.x, rect.lr().y + (ossim_int32)thePaddingSizeInPixels.y); ossimIrect clipRect = newRect.clipToRect(theImageRect);//in case the bounding is larger than input image after adding buffer m_exteriorCut->setRectangle(clipRect); } } }
//******************************************************************* // Public Method: //******************************************************************* ossimIrect ossimAdrgTileSource::getImageRectangle(ossim_uint32 reduced_res_level) const { return ossimIrect(0, // upper left x 0, // upper left y getNumberOfSamples(reduced_res_level) - 1, // lower right x getNumberOfLines(reduced_res_level) - 1); // lower right y }
ossimIrect ossimH5Reader::getImageRectangle(ossim_uint32 reduced_res_level) const { return ossimIrect(0, 0, getNumberOfSamples(reduced_res_level) - 1, getNumberOfLines(reduced_res_level) - 1); }
ossimIrect ossimMaskedImageHandler::getImageRectangle(ossim_uint32 reduced_res_level) const { if (m_inputImageSource != 0) { return m_inputImageSource->getImageRectangle(reduced_res_level); } return ossimIrect(0,0,0,0); }
ossimIrect ossimNitfFile::getImageRect()const { if(theNitfFileHeader.valid()) { return theNitfFileHeader->getImageRect(); } return ossimIrect(ossimIpt(0,0), ossimIpt(0,0)); }
ossimIrect ossimQtStaticTileImageCache::getCacheRect()const { QPoint pt = theCache.offset(); return ossimIrect( pt.x(), pt.y(), pt.x() + theCache.width() - 1, pt.y() + theCache.height() - 1); }
void ossimPolygon::getBoundingRect(ossimIrect& rect)const { ossim_int32 minX; ossim_int32 minY; ossim_int32 maxX; ossim_int32 maxY; getIntegerBounds(minX, minY, maxX, maxY); rect = ossimIrect(minX, minY, maxX, maxY); }
//************************************************************************************************** ossimRefPtr<ossimImageData> ossimScaleFilter::getTile( const ossimIrect& tileRect, ossim_uint32 resLevel) { if((!isSourceEnabled())|| (!theInputConnection)|| ((m_ScaleFactor.x == 1.0)&& (m_ScaleFactor.y == 1.0)&& (m_BlurFactor == 1.0))) { return ossimImageSourceFilter::getTile(tileRect, resLevel); } if(!m_Tile.valid()) { allocate(); } if(!m_Tile) { return ossimImageSourceFilter::getTile(tileRect, resLevel); } m_Tile->makeBlank(); ossimIrect imageRect = tileRect*m_InverseScaleFactor; m_Tile->setImageRectangle(tileRect); m_BlankTile->setImageRectangle(tileRect); double xSupport; double ySupport; getSupport(xSupport, ySupport); ossimIpt deltaPt; deltaPt.x = (ossim_int32)ceil(xSupport); deltaPt.y = (ossim_int32)ceil(ySupport); imageRect = ossimIrect(imageRect.ul().x - (deltaPt.x), imageRect.ul().y - (deltaPt.y), imageRect.lr().x + (deltaPt.x), imageRect.lr().y + (deltaPt.y)); runFilter(imageRect, tileRect); m_Tile->validate(); return m_Tile; }
ossimIrect ossimQtRoiRectAnnotator::getRoiRect() const { if (thePoints.size() == 2 && theImageWidget) { // Sort the points. ossim_int32 ulx = (thePoints[0].x < thePoints[1].x) ? thePoints[0].x : thePoints[1].x; ossim_int32 uly = (thePoints[0].y < thePoints[1].y) ? thePoints[0].y : thePoints[1].y; ossim_int32 lrx = (thePoints[1].x > thePoints[0].x) ? thePoints[1].x : thePoints[0].x; ossim_int32 lry = (thePoints[1].y > thePoints[0].y) ? thePoints[1].y : thePoints[0].y; return ossimIrect(ulx, uly, lrx, lry); } return ossimIrect(0,0,0,0); }
void ossimMemoryImageSource::setRect(ossim_uint32 ulx, ossim_uint32 uly, ossim_uint32 width, ossim_uint32 height) { if(m_image.valid()) { m_image->setImageRectangle(ossimIrect(ulx, uly, ulx + (width-1), uly + (height-1))); m_boundingRect = m_image->getImageRectangle(); } }
//************************************************************************************************** ossimIrect ossimScaleFilter::getBoundingRect(ossim_uint32 resLevel)const { ossimIrect result = ossimImageSourceFilter::getBoundingRect(resLevel); if(!result.hasNans()) { result = ossimIrect(result.ul().x, result.ul().y, result.lr().x+1, result.lr().y+1); result *= m_ScaleFactor; } return result; }
//************************************************************************************************** ossimIrect ossimScaleFilter::scaleRect(const ossimIrect input, const ossimDpt& scaleFactor)const { ossimIpt origin(ossim::round<int>(input.ul().x*scaleFactor.x), ossim::round<int>(input.ul().y*scaleFactor.y)); ossim_int32 w = ossim::round<int>(input.width()*scaleFactor.x); ossim_int32 h = ossim::round<int>(input.height()*scaleFactor.y); if(w < 1) w = 1; if(h < 1) h = 1; return ossimIrect(origin.x, origin.y, origin.x + (w-1), origin.y + (h-1)); }
void ossimAnnotationFontObject::computeBoundingRect() { setFontInfo(); if(theFont.valid()) { ossimIrect textRect; theFont->getBoundingBox(textRect); ossim_int32 w = textRect.width(); ossim_int32 h = textRect.height(); ossim_int32 ulx = thePosition.x; ossim_int32 uly = thePosition.y; theBoundingRect = ossimIrect(ulx, uly, ulx + w - 1, uly + h - 1); } }
ossimRefPtr<ossimImageData> ossimFftFilter::getTile(const ossimIrect& rect, ossim_uint32 resLevel) { if(!isSourceEnabled()) return ossimImageSourceFilter::getTile(rect, resLevel); ossimIrect tempRequest = rect; ossim_uint32 w = rect.width(); ossim_uint32 h = rect.height(); if(w & 1) ++w; if(h&1) ++h; tempRequest = ossimIrect(rect.ul().x, rect.ul().y, rect.ul().x + (w-1), rect.ul().y + (h-1)); ossimRefPtr<ossimImageData> inTile = theScalarRemapper->getTile(tempRequest, resLevel); if(!inTile.valid()) return inTile; if(!theTile.valid()) initialize(); if(!theTile.valid() || !inTile->getBuf()) return theTile; theTile->setImageRectangle(rect); ossimRefPtr<ossimImageData> tempTile = theTile; if(rect != tempRequest) { tempTile = (ossimImageData*)theTile->dup(); tempTile->setImageRectangle(tempRequest); } runFft(inTile, tempTile); if(tempTile != theTile) { theTile->loadTile(tempTile.get()); } theTile->validate(); return theTile; }
ossimIrect ossimGui::RoiSelection::getRectImg() const { // Sort points ossim_int32 ulx = (m_imgPos[0].x < m_imgPos[1].x) ? m_imgPos[0].x : m_imgPos[1].x; ossim_int32 uly = (m_imgPos[0].y < m_imgPos[1].y) ? m_imgPos[0].y : m_imgPos[1].y; ossim_int32 lrx = (m_imgPos[1].x > m_imgPos[0].x) ? m_imgPos[1].x : m_imgPos[0].x; ossim_int32 lry = (m_imgPos[1].y > m_imgPos[0].y) ? m_imgPos[1].y : m_imgPos[0].y; return ossimIrect(ulx, uly, lrx, lry); }
//************************************************************************************************* //! Common initialization code for all construction methods. //************************************************************************************************* void ossimVideoImageSource::initialize() { ossimVideoSource* video = dynamic_cast<ossimVideoSource*>(getInput()); if (!video) return; // Establish the frame rect: ossimIpt frame_size (video->frameSize()); m_frameRect = ossimIrect(0, 0, frame_size.x-1, frame_size.y-1); // Initialize the tile data buffer: m_tile = ossimImageDataFactory::instance()->create(this, this); m_tile->setWidth(frame_size.x); m_tile->setHeight(frame_size.y); m_tile->initialize(); }
bool ossimQtIgenController::getAreaOfInterest(ossimIrect& rect) const { bool status = true; if ( (theOutputGeoPolygon.size() == 4) && theOutputView.valid() ) { ossimDpt dpt; theOutputView->worldToLineSample(theOutputGeoPolygon[0], dpt); ossim_int32 ulx = static_cast<ossim_int32>(dpt.x); ossim_int32 uly = static_cast<ossim_int32>(dpt.y); ossim_int32 lrx = ulx + static_cast<ossim_int32>(theSamples) - 1; ossim_int32 lry = uly + static_cast<ossim_int32>(theLines) - 1; rect = ossimIrect(ulx, uly, lrx, lry); } else { status = false; } return status; }
bool ossimGui::StaticTileImageCache::nextInvalidTile(ossimIrect& rect)const { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); ossim_uint32 idx = 0; ossimIpt origin = m_cacheRect.ul(); for(idx = 0; idx < m_validTileArray.size(); ++idx) { if(!m_validTileArray[idx]) { ossim_uint32 yOffset = idx/m_numberOfTiles.x; ossim_uint32 xOffset = idx%m_numberOfTiles.x; ossimIpt ul(origin.x + xOffset*m_tileSize.x, origin.y + yOffset*m_tileSize.y); rect = ossimIrect(ul.x, ul.y, ul.x + m_tileSize.x-1, ul.y + m_tileSize.y -1); return true; } } return false; }
ossimGui::StaticTileImageCache::StaticTileImageCache(const ossimIpt& tileSize) :m_tileSize(tileSize) { if(m_tileSize.x <=0) { m_tileSize.x = 64; } if(m_tileSize.y <=0) { m_tileSize.y = 64; } m_cache = new QImage(m_tileSize.x, m_tileSize.y, QImage::Format_RGB32); m_validTileArray.resize(1); m_cache->fill(0); m_actualRect = ossimIrect(0,0,m_tileSize.x-1, m_tileSize.y-1); m_cacheRect = m_actualRect; m_numberOfTiles.x = 1; m_numberOfTiles.y = 1; m_validTileArray[0] = false; }
void ossimGeneralRasterTileSource::allocateBuffer( const ossimImageData* tile ) { if( m_buffer ) { delete [] m_buffer; m_buffer = 0; m_bufferSizeInPixels = 0; // Must zero out for check in getTile method. } if ( m_lineBuffer ) { delete [] m_lineBuffer; m_lineBuffer = 0; } if ( tile ) { // Store the size of the buffer in pixels for swapping bytes. m_bufferSizeInPixels = tile->getSize(); if ( m_bufferSizeInPixels ) { // Initialize buffer. This is bytes, not pixels. m_buffer = new ossim_uint8[ tile->getSizeInBytes() ]; // Zero out the buffer rect. m_bufferRect = ossimIrect(0, 0, 0, 0); } if ( m_rasterInfo.interleaveType() == OSSIM_BIP ) { // Big enough to hold a whole line all bands. ossim_uint32 widthInBytes = tile->getWidth() * m_rasterInfo.getImageMetaData().getNumberOfBands() * m_rasterInfo.getImageMetaData().getBytesPerPixel(); m_lineBuffer = new ossim_uint8[ widthInBytes ]; } } }
bool ossimGeneralRasterInfo::initializeFromHdr( const ossimFilename& imageFile, const ossimFilename& headerFile ) { bool result = false; ossimKeywordlist kwl; char delimeter = ' '; kwl.change_delimiter(delimeter); if ( kwl.addFile(headerFile) ) { kwl.downcaseKeywords(); ossimString value; while( 1 ) { //--- // Go through the data members in order. // If a required item is not found break from loop. //-- theMetaData.clear(); // scalar ( default ) - adjusted below : theMetaData.setScalarType( OSSIM_UINT8 ); // Image file name: theImageFileList.clear(); theImageFileList.push_back( imageFile ); // interleave ( not required - default=BIL) theInterleaveType = OSSIM_BIL; value.string() = kwl.findKey( std::string("layout") ); if ( value.size() ) { ossimInterleaveTypeLut lut; ossim_int32 intrlv = lut.getEntryNumber( value.string().c_str(), true ); if ( intrlv != ossimLookUpTable::NOT_FOUND ) { theInterleaveType = static_cast<ossimInterleaveType>(intrlv); } } // bands ( required ): ossim_uint32 bands = 0; value.string() = kwl.findKey( std::string("nbands") ); if ( value.size() ) { bands = value.toUInt32(); } if ( !bands ) { break; } theMetaData.setNumberOfBands( bands ); // lines ( required ): ossim_int32 lines = 0; value.string() = kwl.findKey( std::string("nrows") ); if ( value.size() ) { lines = value.toInt32(); } if ( !lines ) { break; } // samples ( required ): ossim_int32 samples = 0; value.string() = kwl.findKey( std::string("ncols") ); if ( value.size() ) { samples = value.toInt32(); } if ( !samples ) { break; } // nodata or null value ( not required ) value.string() = kwl.findKey( std::string("nodata") ); if ( value.empty() ) { value.string() = kwl.findKey( std::string("nodata_value") ); } if ( value.size() ) { ossim_float64 nullValue = value.toUInt32(); for ( ossim_uint32 band = 0; band < theMetaData.getNumberOfBands(); ++band ) { theMetaData.setNullPix( band, nullValue ); } theMetaData.setNullValuesValid(true); } // Set the rectangles: theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 ); theValidImageRect = theRawImageRect; theImageRect = theRawImageRect; // sample start ( not required ): theSubImageOffset.x = 0; // line start ( not required ): theSubImageOffset.y = 0; // header offset ( not required ): theHeaderSize = 0; // null mode: theSetNullsMode = ossimGeneralRasterInfo::NONE; // pixels to chop: thePixelsToChop = 0; // Byte order, ( not required - defaulted to system if not found. theImageDataByteOrder = ossim::byteOrder(); value.string() = kwl.findKey( std::string("byteorder") ); if ( value.size() ) { ossim_uint32 i = value.toUInt32(); if ( i == 0 ) { theImageDataByteOrder = OSSIM_LITTLE_ENDIAN; } else { theImageDataByteOrder = OSSIM_BIG_ENDIAN; } } // Pixel type used for scalar below: std::string pixelType = "N"; // not defined value.string() = kwl.findKey( std::string("pixeltype") ); if ( value.size() ) { pixelType = value.string(); } ossim_int32 nbits = -1; value.string() = kwl.findKey( std::string("nbits") ); if ( value.size() ) { nbits = value.toInt32(); } else { nbits = getBitsPerPixel( imageFile ); } switch( nbits ) { case 8: { theMetaData.setScalarType( OSSIM_UINT8 ); break; } case 16: { if (pixelType == "S") { theMetaData.setScalarType( OSSIM_SINT16 ); } else { theMetaData.setScalarType( OSSIM_UINT16 ); } break; } case 32: { if( pixelType == "S") { theMetaData.setScalarType( OSSIM_SINT32 ); } else if( pixelType == "F") { theMetaData.setScalarType( OSSIM_FLOAT32 ); } else { theMetaData.setScalarType( OSSIM_UINT32 ); } break; } default: { if( (nbits < 8) && (nbits >= 1 ) ) { theMetaData.setScalarType( OSSIM_UINT8 ); } break; } } result = true; break; // Trailing break to get out. } } return result; } // End: ossimGeneralRasterInfo::initializeFromHdr
bool ossimGeneralRasterInfo::loadState(const ossimKeywordlist& kwl, const char* prefix) { static const char MODULE[] = "ossimGeneralRasterInfo::loadState"; if ( traceDebug() ) { CLOG << "DEBUG: entered..." << "\nprefix: " << (prefix ? prefix : "") << "\nInput keyword list:\n" << kwl << std::endl; } bool result = false; //--- // Look for required and option keyword. Break from loop if required // keyword is not found. //--- while( 1 ) { // Check for errors in the ossimKeywordlist. if(kwl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " ERROR:\n" << "Detected an error in the keywordlist: " << kwl << std::endl; break; } std::string key; ossimString value; // Use for keyword list lookups. ossim_int32 lines = 0; ossim_int32 samples = 0; // Lines (required): key = NUMBER_LINES; value.string() = kwl.findKey( key ); // Required to have this. if ( value.size() ) { lines = value.toInt32(); if ( !lines ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:\n" << "Required number of lines is 0!" << std::endl; } break; } } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:\n" << "Required keyword not found: " << key << std::endl; } break; } // Samples (required): key = NUMBER_SAMPLES; value.string() = kwl.findKey( key ); // Required to have this. if ( value.size() ) { samples = value.toInt32(); if ( !samples ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:\n" << "Required number of samples is 0!" << std::endl; } break; } } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:\n" << "Required keyword not found: " << key << std::endl; } break; } // Bands ossimImageMetaData::loadState checks for required bands: if(!theMetaData.loadState(kwl, prefix)) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << " Error loading meta data!\n" << std::endl; } break; } // If we get here assign the rectangles: theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 ); theValidImageRect = theRawImageRect; theImageRect = theRawImageRect; int tmp = INTERLEAVE_TYPE_LUT.getEntryNumber(kwl); if (tmp == ossimLookUpTable::NOT_FOUND) { theInterleaveType = OSSIM_BIL; } else { theInterleaveType = static_cast<ossimInterleaveType>(tmp); } // Get the image files. if (theInterleaveType != OSSIM_BSQ_MULTI_FILE) { // Look for "filename" first, then deprecated "image_file". key = ossimKeywordNames::FILENAME_KW; value.string() = kwl.findKey( key ); if ( value.empty() ) { // deprecated keyword... key = ossimKeywordNames::IMAGE_FILE_KW; value.string() = kwl.findKey( key ); } if ( value.size() ) { //--- // omd (ossim metadata) files can have just the base filename, e.g. image.ras, // in which case open will fail if not in the image dir. So only put it in // the list if it doesn't exits. //--- ossimFilename f = value; if ( f.exists() ) { theImageFileList.clear(); theImageFileList.push_back(ossimFilename(value)); } } if ( theImageFileList.empty() ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "ERROR:\n" << "Required keyword not found: " << ossimKeywordNames::FILENAME_KW << std::endl; } break; } } else { // multiple file names. ossim_int32 count = 0; // look for image file key word with no number. // Required to have this. key = ossimKeywordNames::FILENAME_KW; value.string() = kwl.findKey( key ); if ( value.empty() ) { // deprecated keyword... key = ossimKeywordNames::IMAGE_FILE_KW; value.string() = kwl.findKey( key ); } if ( value.size() ) { theImageFileList.push_back(ossimFilename(value)); ++count; } ossim_int32 i = 0; while ( (count < numberOfBands()) && (i < 1000) ) { key = ossimKeywordNames::FILENAME_KW; key += ossimString::toString(i).string(); value.string() = kwl.findKey( key ); if ( value.empty() ) { // Lookup for deprecated keyword. key = ossimKeywordNames::IMAGE_FILE_KW; key += ossimString::toString(i).string(); value.string() = kwl.findKey( key ); } if ( value.size() ) { theImageFileList.push_back(ossimFilename(value)); ++count; } ++i; } if (count != numberOfBands()) // Error, count should equal bands! { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:\n" << "Required keyword not found: " << ossimKeywordNames::FILENAME_KW << "\nInterleave type is multi file; however," << " not enough were pick up!" << std::endl; } break; } } key = VALID_START_LINE; value.string() = kwl.findKey( key ); // Default is zero. if ( value.size() ) { theValidImageRect.set_uly( value.toInt32() ); } key = VALID_STOP_LINE; value.string() = kwl.findKey( key ); // Default is last line. if ( value.size() ) { theValidImageRect.set_lry( value.toInt32() ); } if (theValidImageRect.lr().y < theValidImageRect.ul().y) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:" << "\nValid stop line < start line." << "\nValid start line: " << theValidImageRect.ul().y << "\nValid stop line: " << theValidImageRect.lr().y << "\nError status has been set. Returning." << std::endl; break; } key = VALID_START_SAMPLE; value.string() = kwl.findKey( key ); // Default is zero. if ( value.size() ) { theValidImageRect.set_ulx( value.toInt32() ); } key = VALID_STOP_SAMPLE; value.string() = kwl.findKey( key ); // Default is last sample. if ( value.size() ) { theValidImageRect.set_lrx( value.toInt32() ); } if (theValidImageRect.lr().x < theValidImageRect.ul().x) { ossimNotify(ossimNotifyLevel_WARN) << " ERROR:" << "\nValid stop samp < start samp." << "\nValid start samp: " << theValidImageRect.ul().x << "\nValid stop samp: " << theValidImageRect.lr().x << "\nError status has been set. Returning." << std::endl; break; } theImageRect.set_lry(theValidImageRect.lr().y - theValidImageRect.ul().y); theImageRect.set_lrx(theValidImageRect.lr().x - theValidImageRect.ul().x); key = SUB_IMAGE_OFFSET_LINE; value.string() = kwl.findKey( key ); // Default is zero. if ( value.size() ) { theSubImageOffset.line = value.toInt32(); } key = SUB_IMAGE_OFFSET_SAMP; value.string() = kwl.findKey( key ); // Default is zero. if ( value.size() ) { theSubImageOffset.samp = atoi(value); } key = HEADER_SIZE; value.string() = kwl.findKey( key ); // Default is zero. if ( value.size() ) { theHeaderSize = value.toInt32(); } key = SET_NULLS; value.string() = kwl.findKey( key ); // Default is 2. if ( value.size() ) { int tmp; tmp = atoi(value); if ((tmp < 3) && (tmp > -1)) { theSetNullsMode = (ossimFillMode)tmp; } else { theSetNullsMode = ZEROES_TO_NULL_EDGES_ONLY; // 2 ossimNotify(ossimNotifyLevel_WARN) << " WARNING:" << "\nset_fill_to_nulls_mode value out of range." << "\nDefaulted to 2" << std::endl; } } key = PIXELS_TO_CHOP; value.string() = kwl.findKey( key ); // Default is zero. if ( value.size() ) { thePixelsToChop = value.toInt32(); } if (bytesPerPixel() > 1) { // get the byte order of the data. key = ossimKeywordNames::BYTE_ORDER_KW; value.string() = kwl.findKey( key ); if ( value.size() ) { ossimString s(value); if (s.trim() != "") // Check for empty string. { s.downcase(); if (s.contains("big")) { theImageDataByteOrder = OSSIM_BIG_ENDIAN; } else if(s.contains("little")) { theImageDataByteOrder = OSSIM_LITTLE_ENDIAN; } } } } // End of while forever loop. result = true; break; } // Matches: while (1) if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " Exit status: " << (result?"true":"false") << std::endl; } return result; } // End: bool ossimGeneralRasterInfo::loadState
bool ossimGeneralRasterInfo::initializeFromXml( const ossimFilename& imageFile, const ossimFilename& headerFile ) { bool result = false; ossimFgdcXmlDoc file; if (file.open( headerFile )) { while( 1 ) { //--- // Go through the data members in order. // If a required item is not found break from loop. //-- theMetaData.clear(); // scalar ( default ) - adjusted below : theMetaData.setScalarType( OSSIM_UINT8 ); // Image file name: theImageFileList.clear(); theImageFileList.push_back( imageFile ); // interleave ( defaulted ): theInterleaveType = OSSIM_BIL; // bands ( required ): if ( !file.getNumberOfBands() ) { break; } theMetaData.setNumberOfBands( file.getNumberOfBands() ); ossimIpt size; if ( file.getImageSize(size) ) // Lines, samples not image file size. { // lines, samples ( required ): if ( !size.x || !size.y ) { break; } } else { break; } // Set the rectangles: theRawImageRect = ossimIrect( 0, 0, size.x - 1, size.y - 1 ); theValidImageRect = theRawImageRect; theImageRect = theRawImageRect; // sample start ( not required ): theSubImageOffset.x = 0; // line start ( not required ): theSubImageOffset.y = 0; // header offset ( not required ): theHeaderSize = 0; // null mode: theSetNullsMode = ossimGeneralRasterInfo::NONE; // pixels to chop: thePixelsToChop = 0; // Byte order *** need this ***, defaulting to system for now: theImageDataByteOrder = ossim::byteOrder(); // Adjust scalar if needed, note defaulted to 8 bit above: ossimString eainfo; file.getPath("/metadata/eainfo/detailed/enttyp/enttypd", eainfo); ossim_int32 numBits = 0; ossim_int64 fileSize = imageFile.fileSize(); // Image file size. ossim_int32 numBytes = fileSize / size.x / size.y / numberOfBands(); if( numBytes > 0 && numBytes != 3 ) { numBits = numBytes*8; } if( numBits == 16 ) { theMetaData.setScalarType( OSSIM_UINT16 ); } else if( numBits == 32 ) { if(eainfo.contains("float")) { theMetaData.setScalarType( OSSIM_FLOAT32 ); } else { theMetaData.setScalarType( OSSIM_UINT32 ); } } result = true; break; // Trailing break to get out. } } return result; } // End: ossimGeneralRasterInfo::initializeFromXml
bool ossimGeneralRasterInfo::initializeFromEnviHdr( const ossimEnviHeader& enviHdr ) { bool result = false; while( 1 ) { //--- // Go through the data members in order. // If a required item is not found break from loop. //-- theMetaData.clear(); // scalar ( required ) : if( enviHdr.getOssimScalarType() != OSSIM_SCALAR_UNKNOWN ) { theMetaData.setScalarType( enviHdr.getOssimScalarType() ); } else { break; } theImageFileList.clear(); // interleave ( required ): theInterleaveType = enviHdr.getOssimInterleaveType(); if ( theInterleaveType == OSSIM_INTERLEAVE_UNKNOWN ) { break; } // bands ( required ): if ( !enviHdr.getBands() ) { break; } theMetaData.setNumberOfBands( enviHdr.getBands() ); // lines ( required ): ossim_uint32 lines = enviHdr.getLines(); if ( !lines ) { break; } // samples ( required ): ossim_uint32 samples = enviHdr.getSamples(); if ( !samples ) { break; } // Set the rectangles: theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 ); theValidImageRect = theRawImageRect; theImageRect = theRawImageRect; // sample start ( not required ): theSubImageOffset.x = enviHdr.getXStart(); // line start ( not required ): theSubImageOffset.y = enviHdr.getYStart(); // header offset ( not required ): theHeaderSize = enviHdr.getHeaderOffset(); // null mode: theSetNullsMode = ossimGeneralRasterInfo::NONE; // pixels to chop: thePixelsToChop = 0; // Byte order, this will be system if not found. theImageDataByteOrder = enviHdr.getByteOrder(); result = true; break; // Trailing break to get out. } return result; } // End: ossimGeneralRasterInfo::initializeFromEnviHdr( const ossimEnviHeader& )
bool ossimKakaduJ2kReader::open() { static const char MODULE[] = "ossimKakaduJ2kReader::open"; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n"; } bool result = false; if(isOpen()) { closeEntry(); } // Open up a stream to the file. theFileStr.open(theImageFile.c_str(), ios::in | ios::binary); if ( theFileStr.good() ) { //--- // Check for the Start Of Codestream (SOC) and Size (SIZ) markers which // are required as first and second fields in the main header. //--- ossim_uint16 soc; ossim_uint16 siz; theFileStr.read((char*)&soc, 2); theFileStr.read((char*)&siz, 2); if (ossim::byteOrder() == OSSIM_LITTLE_ENDIAN) // Alway big endian. { ossimEndian().swap(soc); ossimEndian().swap(siz); } if ( (soc == SOC_MARKER) && (siz == SIZ_MARKER) ) { // Read in and store the size record. theSizRecord.parseStream(theFileStr); // Position to start of code stream prior to create call. theFileStr.seekg(0); //--- // Initialize the codestream. The class ossimKakaduNitfReader is a // kdu_compressed source so we feed ourself to the codestream. // // TODO: Currently no kdu_thread_env. This should be implemented for // speed... //--- //--- // Construct multi-threaded processing environment if required. // Temp hard coded to a single thread. //--- if (theThreadEnv) { theThreadEnv->terminate(NULL, true); theThreadEnv->destroy(); } else { theThreadEnv = new kdu_thread_env(); } theThreadEnv->create(); // Creates the single "owner" thread // Check for threads in prefs file. ossim_uint32 threads = 1; const char* lookup = ossimPreferences::instance()->findPreference("kakadu_threads"); if ( lookup ) { threads = ossimString::toUInt32(lookup); if ( threads > 1 ) { for (ossim_uint32 nt=1; nt < threads; ++nt) { if ( !theThreadEnv->add_thread() ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "Unable to create thread!\n"; } } } } } theOpenTileThreadQueue = theThreadEnv->add_queue(NULL,NULL,"open_tile_q"); theCodestream.create(this, theThreadEnv); if ( theCodestream.exists() ) { //--- // We have to store things here in this non-const method because // NONE of the kakadu methods are const. //--- theMinDwtLevels = theCodestream.get_min_dwt_levels(); theCodestream.set_persistent(); // ???? theCodestream.enable_restart(); // ???? kdu_dims region_of_interest; region_of_interest.pos.x = 0; region_of_interest.pos.y = 0; region_of_interest.size.x = getNumberOfSamples(0); region_of_interest.size.y = getNumberOfLines(0); theCodestream.apply_input_restrictions( 0, // first_component 0, // max_components (0 = all remaining will appear) 0, // highest resolution level 0, // max_layers (0 = all layers retained) ®ion_of_interest, // expanded out to block boundary. //KDU_WANT_CODESTREAM_COMPONENTS); KDU_WANT_OUTPUT_COMPONENTS); // Set the scalar: theScalarType = theSizRecord.getScalarType(); if (theScalarType != OSSIM_SCALAR_UNKNOWN) { //--- // NOTE: Please leave commented out code for now. //--- // Capture the sub image offset. // theSubImageOffset.x = theSizRecord.theXOsiz; // theSubImageOffset.y = theSizRecord.theYOsiz; // Initialize the image rect. theImageRect = ossimIrect(0, 0, theSizRecord.theXsiz-1, theSizRecord.theYsiz-1); // Initialize the cache. if (theCacheId != -1) { ossimAppFixedTileCache::instance()->deleteCache(theCacheId); theCacheId = -1; } ossimIpt tileSize(theSizRecord.theXTsiz, theSizRecord.theYTsiz); // Stretch to tile boundary for the cache. ossimIrect fullImgRect = theImageRect; fullImgRect.stretchToTileBoundary(tileSize); // Set up the tile cache. theCacheId = ossimAppFixedTileCache::instance()-> newTileCache(fullImgRect, tileSize); // Add the sub image rect after the // Initialize the tile we will return. initializeTile(); // Call the base complete open to pick up overviews. completeOpen(); // We should be good now so set the return result to true. result = true; if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "\nSIZ marker segment" << theSizRecord << "theCodestream.get_num_components(false): " << theCodestream.get_num_components(false) << "\ntheCodestream.get_num_components(true): " << theCodestream.get_num_components(true) << "\ntheCodestream.get_bit_depth(0, true): " << theCodestream.get_bit_depth(0, true) << "\ntheCodestream.get_signed(0, true): " << theCodestream.get_signed(0, true) << "\ntheCodestream.get_min_dwt_levels(): " << theCodestream.get_min_dwt_levels() << "\ntheImageRect: " << theImageRect << "\nFull image rect: " << fullImgRect << "\nthreads: " << threads << "\n"; vector<ossimDpt> decimations; getDecimationFactors(decimations); for (ossim_uint32 i = 0; i < decimations.size(); ++i) { ossimNotify(ossimNotifyLevel_DEBUG) << theCodestream.get_min_dwt_levels() << "Decimation factor[" << i << "]: " << decimations[i] << "\nsamples[" << i << "]: " << getNumberOfSamples(i) << "\nlines[" << i << "]: " << getNumberOfLines(i) << std::endl; } } } } // matches: if ( theCodestream.exists() ) } // matches: if ( (soc == SOC_MARKER) && (siz == SIZ_MARKER) ) } // matches: if ( theFileStr.good() ) else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " ERROR:" << "\nCannot open: " << theImageFile.c_str() << endl; } } if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status = " << (result?"true":"false\n") << std::endl; } return result; }