//************************************************************************************************* //! 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; }
ossimIrect ossimNitfFile::getImageRect()const { if(theNitfFileHeader.valid()) { return theNitfFileHeader->getImageRect(); } return ossimIrect(ossimIpt(0,0), ossimIpt(0,0)); }
void ossimAnnotationMultiLineObject::draw(ossimRgbImage& anImage)const { if(anImage.getImageData().valid()) { anImage.setDrawColor(theRed, theGreen, theBlue); anImage.setThickness(theThickness); ossimDrect imageRect = anImage.getImageData()->getImageRectangle(); if(theBoundingRect.intersects(imageRect)) { // we need to extend it by a couple of pixels since // if a pixel lies on the edge and then another pixel is just off // the edge we will get a stair step and so for several pixels // the line might be inside the image rectangle but the clip // algorithm will only draw 1 pixel since it thinks the first // point is inside and the second point is outside and will // execute the clip algorithm keeping only the first // point. ossimDrect clipRect(imageRect.ul().x - 10, imageRect.ul().y - 10, imageRect.lr().x + 10, imageRect.lr().y + 10); for(ossim_uint32 i = 0; i < thePolyLineList.size(); ++i) { const vector<ossimDpt>& vList = thePolyLineList[i].getVertexList(); if(vList.size() == 1) { anImage.drawLine(ossimIpt(vList[0]), ossimIpt(vList[0])); } else { for(ossim_uint32 i2 = 0; i2 < (vList.size()-1); ++i2) { ossimDpt start = vList[i2]; ossimDpt end = vList[i2+1]; // now we can draw. if(clipRect.clip(start, end)) { anImage.drawLine(ossimIpt((int)start.x, (int)start.y), ossimIpt((int)end.x, (int)end.y)); } } } } } } }
void ossimGui::ImageScrollWidget::updateScrollBars() { if(!m_inputBounds.hasNans()) { if(m_inputBounds.width() > viewport()->size().width()) { horizontalScrollBar()->setRange(0,m_inputBounds.width()-viewport()->size().width()); horizontalScrollBar()->show(); } else { horizontalScrollBar()->setRange(0,0);//,viewport()->size().width()); horizontalScrollBar()->setVisible(false); horizontalScrollBar()->setValue(0); } if(m_inputBounds.height() > viewport()->size().height()) { verticalScrollBar()->setRange(0,m_inputBounds.height()-viewport()->size().height()); verticalScrollBar()->show(); } else { verticalScrollBar()->setRange(0,0);//viewport()->size().height()); verticalScrollBar()->setVisible(false); verticalScrollBar()->setValue(0); } m_scrollOrigin = ossimIpt(horizontalScrollBar()->value(), verticalScrollBar()->value()); } }
void ossimPolygon::roundToIntegerBounds(bool compress) { int i = 0; for(i = 0; i < (int)theVertexList.size(); ++i) { theVertexList[i] = ossimIpt(theVertexList[i]); } if(compress&&theVertexList.size()) { vector<ossimDpt> polyLine; polyLine.push_back(theVertexList[0]); ossimDpt testPt = theVertexList[0]; for(i=1; i < (int)theVertexList.size(); ++i) { if(testPt!=theVertexList[i]) { testPt = theVertexList[i]; polyLine.push_back(testPt); } } if(polyLine.size() == 1) { polyLine.push_back(polyLine[0]); } if(theVertexList.size() == 1) { polyLine.push_back(testPt); } theVertexList = polyLine; theCurrentVertex = 0; } }
ossimGui::ImageScrollWidget::ImageScrollWidget(QWidget* parent) :QScrollArea(parent), m_listener(new ConnectionListener(this)), m_jobQueue(new DisplayTimerJobQueue()) { m_trackPoint.makeNan(); m_oldTrackPoint.makeNan(); m_trackingFlag = true; m_mouseInsideFlag = false; m_layers = new Layers(); //m_connector->addListener(m_listener); m_widget = new ImageWidget(this, viewport()); //m_widget->setAttribute(Qt::WA_StaticContents); m_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // setWidget(m_widget); setWidgetResizable(false); m_widget->show(); m_trackingFlag = true; m_scrollOrigin = ossimDpt(0.0,0.0); m_tileSize = ossimIpt(64,64); //m_widget->setTileCache(new StaticTileImageCache(m_tileSize)); m_timerId = -1; viewport()->setCursor(Qt::CrossCursor); m_imageWidgetJob = new ImageWidgetJob();//this); m_imageWidgetJob->setCallback(new Callback(this)); // m_multiLayerAlgorithm = HORIZONTAL_SWIPE_ALGORITHM; // m_multiLayerAlgorithm = VERTICAL_SWIPE_ALGORITHM; // m_multiLayerAlgorithm = BOX_SWIPE_ALGORITHM; m_multiLayerAlgorithm = CIRCLE_SWIPE_ALGORITHM; // Initialize drawing control m_drawPts = false; // m_regOverlay = new RegistrationOverlay(); ///???????????? // m_scene = new QGraphicsScene(0,0,500,400,this); // m_view = new QGraphicsView(this); // m_view->setScene(m_scene); // m_view->setStyleSheet("background: transparent"); // QGraphicsRectItem* rect = m_scene->addRect(50,40,100,200); // rect->setFlags(QGraphicsItem::ItemIsMovable); // rect->setBrush(QBrush(Qt::blue)); // rect->setOpacity(0.3); // QGraphicsItem* item = m_scene->addText("QGraphicsTextItem"); // item->setFlags(QGraphicsItem::ItemIsMovable); // m_view->show(); }
void ossimScaleFilter::runFilterTemplate(T dummy, const ossimIrect& imageRect, const ossimIrect& viewRect) { ossimRefPtr<ossimImageData> inputData = theInputConnection->getTile(imageRect); if(!inputData.valid() || !inputData->getBuf() || (inputData->getDataObjectStatus() == OSSIM_EMPTY)) { return; } ossim_int32 h = imageRect.height(); ossimRefPtr<ossimImageData> tempData = ossimImageDataFactory::instance()->create(NULL, inputData->getScalarType(), inputData->getNumberOfBands(), viewRect.width(), h); tempData->setOrigin(ossimIpt(viewRect.ul().x, imageRect.ul().y)); tempData->initialize(); if((m_ScaleFactor.x != 1.0)|| (m_BlurFactor != 1.0)) { runHorizontalFilterTemplate(dummy, inputData, tempData); tempData->validate(); } else { tempData->loadTile(inputData.get()); } if((m_ScaleFactor.y != 1.0)|| (m_BlurFactor != 1.0)) { runVerticalFilterTemplate(dummy, tempData, m_Tile); } else { m_Tile->loadTile(tempData.get()); } m_Tile->validate(); }
void ossimGeoAnnotationBitmap::transform(ossimImageGeometry* projection) { if(projection) { projection->worldToLocal(theCenterPoint, theProjectedPoint); theProjectedPoint = ossimIpt(theProjectedPoint); if(theImageData.valid()) { ossimDpt origin(theProjectedPoint.x - theImageData->getWidth()/2.0, theProjectedPoint.y - theImageData->getHeight()/2.0); theImageData->setOrigin(origin); } } }
void ossim::defaultTileSize(ossimIpt& tileSize) { const char* tileSizeKw = ossimPreferences::instance()-> findPreference("tile_size"); if(tileSizeKw) { std::vector<ossimString> splitArray; ossimString tempString(tileSizeKw); tempString.split(splitArray, " "); bool hasX = true; if(splitArray.size() == 2) { tileSize.x = splitArray[0].toInt32(); tileSize.y = splitArray[1].toInt32(); } else if(splitArray.size() == 1) { tileSize.x = splitArray[0].toInt32(); tileSize.y = splitArray[0].toInt32(); } else { tileSize = ossimIpt(0,0); } if(tileSize.x < 1) { tileSize.x = OSSIM_DEFAULT_TILE_WIDTH; hasX = false; } if(tileSize.y < 1) { if(!hasX) { tileSize.y = OSSIM_DEFAULT_TILE_HEIGHT; } else { tileSize.y = tileSize.x; } } } else { tileSize.x = OSSIM_DEFAULT_TILE_WIDTH; tileSize.y = OSSIM_DEFAULT_TILE_HEIGHT; } }
ossim_int32 ossimQtStaticTileImageCache::getTileIndex(ossim_int32 x, ossim_int32 y)const { ossimIpt ul = getCacheRect().ul(); ossimIpt delta = ossimIpt(x,y) - ul; if((delta.x < 0) || (delta.y < 0) || (delta.x >= theCache.width())|| (delta.y >= theCache.height())) { return -1; } delta.x /= theTileSize.x; delta.y /= theTileSize.y; return delta.y*theNumberOfTiles.x + delta.x; }
ossimIpt ossimFixedTileCache::getTileOrigin(ossim_int32 tileId) { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theMutex); ossimIpt result; result.makeNan(); if(tileId < 0) { return result; } ossim_int32 ty = (tileId/theTilesHorizontal); ossim_int32 tx = (tileId%theTilesVertical); ossimIpt ul = theTileBoundaryRect.ul(); result = ossimIpt(ul.x + tx*theTileSize.x, ul.y + ty*theTileSize.y); return result; }
ossim_int32 ossimGui::StaticTileImageCache::getTileIndex(const ossimIrect& rect, const ossimIpt& numberOfTiles, ossim_int32 x, ossim_int32 y)const { ossimIpt ul = rect.ul(); ossimIpt delta = ossimIpt(x,y) - ul; if((delta.x < 0) || (delta.y < 0) || (delta.x >= (int)rect.width())|| (delta.y >= (int)rect.height())) { return -1; } delta.x /= m_tileSize.x; delta.y /= m_tileSize.y; return delta.y*numberOfTiles.x + delta.x; }
//************************************************************************************************** //! Sets the handler being adapted. //************************************************************************************************** void ossimImageHandlerMtAdaptor::setAdaptee(ossimImageHandler* handler) { m_adaptedHandler = handler; if (handler == NULL) return; // Fetch the adaptee's output list and make it our own: ConnectableObjectList output_list = handler->getOutputList(); if (d_useCache) { // Create the cache and connect this adaptor as its output: m_cache = new ossimCacheTileSource; m_cache->connectMyOutputTo(this, true, false); m_cache->changeOwner(this); m_cache->connectMyOutputTo(this, true, false); handler->disconnectMyOutputs(output_list, true, false); handler->connectMyOutputTo(m_cache.get(), true, true); } else { handler->disconnectMyOutputs(output_list, true, false); handler->connectMyOutputTo(this, true, false); } // Finally connect the adaptee's outputs to this and fire connection events: connectMyOutputTo(output_list, true, true); handler->changeOwner(this); if (d_useFauxTile) { d_fauxTile = (ossimImageData*) handler->getTile(ossimIpt(0,0), 0)->dup(); //d_fauxTile = new ossimImageData(this, // handler->getOutputScalarType(), // handler->getNumberOfOutputBands(), // handler->getTileWidth(), // handler->getTileHeight()); //d_fauxTile->fill(128.0); } }
ossimIpt ossimGui::StaticTileImageCache::getTileOrigin(const ossimIpt& pt)const { ossimIpt tempPt; if(pt.x < 0) { tempPt.x = pt.x - (m_tileSize.x-1); } else { tempPt.x = pt.x + (m_tileSize.x-1); } if(pt.y < 0) { tempPt.y = pt.y - (m_tileSize.y-1); } else { tempPt.y = pt.y + (m_tileSize.y-1); } return ossimIpt((tempPt.x/m_tileSize.x)*m_tileSize.x, (tempPt.y/m_tileSize.y)*m_tileSize.y); }
void setOverviewTileSize(int width, int height) { theOverviewTileSize = ossimIpt(width, height); }
void ossimImageSourceSequencer::setTileSize(int width, int height) { setTileSize(ossimIpt(width, height)); }
ossimIpt getOrigin()const { return theImageData.valid()?theImageData->getOrigin():ossimIpt(0,0); }
int main(int argc, char* argv[]) { #ifdef OSSIM_HAS_MPI # if OSSIM_HAS_MPI ossimMpi::instance()->initialize(&argc, &argv); if (ossimMpi::instance()->getRank() == 0) { ossimNotify(ossimNotifyLevel_INFO) << "MPI running with " << ossimMpi::instance()->getNumberOfProcessors() << " processors..." << std::endl; } # endif #endif std::string tempString; ossimArgumentParser::ossimParameter stringParam(tempString); ossimArgumentParser argumentParser(&argc, argv); ossimInit::instance()->addOptions(argumentParser); ossimInit::instance()->initialize(argumentParser); argumentParser.getApplicationUsage()->setApplicationName(argumentParser.getApplicationName()); argumentParser.getApplicationUsage()->setDescription(argumentParser.getApplicationName()+" flips any null pixels to a valid pixel"); argumentParser.getApplicationUsage()->setCommandLineUsage(argumentParser.getApplicationName()+" [options] <output_type> <input_file> <output_file> <target_value> <replacement_value>"); argumentParser.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); argumentParser.getApplicationUsage()->addCommandLineOption("-o or --create-overview", "Creates and overview for the output image"); argumentParser.getApplicationUsage()->addCommandLineOption("-c or --clamp-value", "clamp values (any pixel with value larger than input will be clamped to input)"); argumentParser.getApplicationUsage()->addCommandLineOption("-m", "Replacement mode (see notes below)"); argumentParser.getApplicationUsage()->addCommandLineOption("-w", "output tile width(only valid with tiled output types). Must be a multiply of 16"); static const char MODULE[] = "pixelflip:main"; if (traceDebug()) CLOG << " Entered..." << std::endl; ossimInit::instance()->initialize(argc, argv); // Keyword list to initialize image writers with. ossimKeywordlist kwl; const char* PREFIX = "imagewriter."; bool create_overview = false; ossim_int32 tile_width = 0; double clamp_value = 0.0; bool do_clamp = false; ossimPixelFlipper::ReplacementMode replacement_mode = ossimPixelFlipper::REPLACE_BAND_IF_TARGET; if(argumentParser.read("-h") || argumentParser.read("--help")||(argumentParser.argc() == 1)) { argumentParser.getApplicationUsage()->write(ossimNotify(ossimNotifyLevel_INFO)); usage(); exit(0); } while(argumentParser.read("-o") || argumentParser.read("--create-overview")) { create_overview = true; } while(argumentParser.read("-c", stringParam)) { clamp_value = ossimString(tempString).toDouble(); do_clamp = true; } while(argumentParser.read("-m", stringParam)) { ossimString mode = tempString; mode.downcase(); if (mode == "replace_band_if_target") { replacement_mode = ossimPixelFlipper::REPLACE_BAND_IF_TARGET; } else if (mode == "replace_band_if_partial_target") { replacement_mode = ossimPixelFlipper::REPLACE_BAND_IF_PARTIAL_TARGET; } else if (mode == "replace_all_bands_if_partial_target") { replacement_mode = ossimPixelFlipper::REPLACE_ALL_BANDS_IF_PARTIAL_TARGET; } else if (mode != "replace_all_targets") { ossimNotify(ossimNotifyLevel_WARN) << "Invalid mode: " << mode << "\nMode remains: replace_band_if_target" << std::endl; } } while(argumentParser.read("-w", stringParam)) { tile_width = ossimString(tempString).toInt32(); if (tile_width % 16) { ossimNotify(ossimNotifyLevel_WARN) << MODULE << " NOTICE:" << "\nTile width must be a multiple of 16!" << "\nDefaulting to 128" << std::endl; tile_width = 0; } } if(argumentParser.argc() != 6) { ossimMpi::instance()->finalize(); exit(0); } //*** // Set the writer type and the image type. //*** ossimString output_type = argumentParser.argv()[1]; output_type.downcase(); kwl.add(PREFIX, ossimKeywordNames::TYPE_KW, output_type.c_str()); // Get the input file. ossimFilename input_file = argumentParser.argv()[2]; // Get the output file. ossimFilename output_file = argumentParser.argv()[3]; // Get the value to replace. double target_value = ossimString(argumentParser.argv()[4]).toDouble(); // Get the replacement value. double replacement_value = ossimString(argumentParser.argv()[5]).toDouble(); bool master = true; if (ossimMpi::instance()->getRank() != 0) { master = false; } if (master) { ossimNotify(ossimNotifyLevel_INFO) << "pixelflip settings:" << "\noutput type: " << output_type << "\ninput file: " << input_file << "\noutput file: " << output_file << "\ntarget value: " << target_value << "\nreplacement value: " << replacement_value << std::endl; if (tile_width) { ossimNotify(ossimNotifyLevel_INFO) << "tile width: " << tile_width << std::endl; } if (do_clamp) { ossimNotify(ossimNotifyLevel_INFO) << "clamp value: " << clamp_value << std::endl; } } // Get an image handler for the input file. ossimRefPtr<ossimImageHandler> ih = ossimImageHandlerRegistry::instance()->open(ossimFilename(input_file)); if (!ih) { ossimNotify(ossimNotifyLevel_WARN) << "Unsupported image file: " << input_file << "\nExiting application..." << std::endl; ossimMpi::instance()->finalize(); exit(0); } // Initialize the if (ih->getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { ossimNotify(ossimNotifyLevel_WARN) << "Error reading image: " << input_file << "Exiting application..." << std::endl; ossimMpi::instance()->finalize(); exit(1); } ih->initialize(); if (traceDebug()) { CLOG << "DEBUG:" << "\nImage Handler: " << ih->getLongName() << std::endl; } // Capture the bounding rectangle of the image handler. ossimIrect output_rect = ih->getBoundingRect(0); // hook up the pixel flipper to the image handler. ossimRefPtr<ossimPixelFlipper> pf = new ossimPixelFlipper(); pf->connectMyInputTo(ih.get()); pf->initialize(); // Setup the pixel flipper target/replacement values, and replace mode. pf->setTargetValue(target_value); pf->setReplacementValue(replacement_value); pf->setReplacementMode(replacement_mode); // Setup pixel flipper clamp value if (do_clamp) { pf->setClampValue(clamp_value); } if (master) { ossimNotify(ossimNotifyLevel_INFO) << "replacement mode: " << pf->getReplacementModeString() << std::endl; } ossimImageSourceSequencer* sequencer = NULL; #ifdef OSSIM_HAS_MPI # if OSSIM_HAS_MPI // only allocate the slave connection if // the number of processors is larger than // 1 // if(ossimMpi::instance()->getNumberOfProcessors() > 1) { if(ossimMpi::instance()->getRank()!=0) { sequencer = new ossimImageMpiSWriterSequenceConnection(NULL, 4); } else { sequencer = new ossimImageMpiMWriterSequenceConnection(); } } else { sequencer = new ossimImageSourceSequencer(); } # else // we will just load a serial connection if MPI is not supported. sequencer = new ossimImageSourceSequencer(NULL); # endif #else sequencer = new ossimImageSourceSequencer(NULL); #endif ossimRefPtr<ossimImageWriter> writer = ossimImageWriterFactoryRegistry::instance()->createWriter(kwl, PREFIX); ossimImageFileWriter* fileWriter = PTR_CAST(ossimImageFileWriter, writer.get()); if( fileWriter == NULL ) { ossimNotify(ossimNotifyLevel_WARN) << "Error making an image writer..." << "\nExiting application..." << std::endl; ossimMpi::instance()->finalize(); exit(1); } // Change out the sequencer... fileWriter->changeSequencer(sequencer); // Hook up the pixel flipper to the file writer. fileWriter->connectMyInputTo(0, pf.get()); if (tile_width) { // Set the tile size... fileWriter->setTileSize(ossimIpt(tile_width, tile_width)); } fileWriter->open(output_file); // Add a listener to get percent complete. ossimStdOutProgress prog(0, true); fileWriter->addListener(&prog); if (fileWriter->getErrorStatus() == ossimErrorCodes::OSSIM_OK) { fileWriter->initialize(); fileWriter->setAreaOfInterest(output_rect); // Set the output rectangle. #ifdef OSSIM_HAS_MPI # if OSSIM_HAS_MPI double start_time = 0.0; if(ossimMpi::instance()->getRank() == 0) { start_time= MPI_Wtime(); } # endif #endif // Filter and write the file... fileWriter->execute(); #ifdef OSSIM_HAS_MPI # if OSSIM_HAS_MPI if(ossimMpi::instance()->getRank() == 0) { double stop_time = MPI_Wtime(); cout << "Elapsed time: " << (stop_time-start_time) << std::endl; } # endif #endif } else { cerr << "Error detected in the image writer..." << "\nExiting application..." << std::endl; exit(1); } if (create_overview == true) { fileWriter->writeOverviewFile(); } #ifdef OSSIM_HAS_MPI # if OSSIM_HAS_MPI ossimMpi::instance()->finalize(); # endif #endif exit(0); }
ossimIpt ossimGeneralRasterElevHandler::getSizeOfElevCell() const { return ossimIpt(theGeneralRasterInfo.theWidth, theGeneralRasterInfo.theHeight); }
//************************************************************************************************* int main(int argc, char *argv[]) { try { ossimInit::instance()->initialize(argc, argv); ossimFilename fname ("PixelFlipperTestChip.tif"); ossimRefPtr<ossimImageHandler> handler = ossimImageHandlerRegistry::instance()->open(fname); vector<ossimIpt> valid_vertices; valid_vertices.push_back(ossimIpt(0,0)); valid_vertices.push_back(ossimIpt(127,0)); valid_vertices.push_back(ossimIpt(127,127)); valid_vertices.push_back(ossimIpt(0,127)); handler->writeValidImageVertices(valid_vertices); // Fetch raw tile: ossimRefPtr<ossimPixelFlipper> flipper = new ossimPixelFlipper(); ossimIrect tile_rect(0,0,127,127); flipper->connectMyInputTo(handler.get()); ossimRefPtr<ossimImageData> tile = handler->getTile(tile_rect); cout<<"\nRaw Tile:"<<endl; showPixels(tile, expected_0); // Target Replacement: flipper->setTargetRange(0, 10); flipper->setReplacementValue(11); flipper->setReplacementMode(ossimPixelFlipper::REPLACE_BAND_IF_TARGET); tile = flipper->getTile(tile_rect); cout<<"\nTarget Replacement REPLACE_BAND_IF_TARGET:"<<endl; showPixels(tile, expected_1); // Target Replacement: flipper->setTargetRange(0, 10); flipper->setReplacementMode(ossimPixelFlipper::REPLACE_BAND_IF_PARTIAL_TARGET); tile = flipper->getTile(tile_rect); cout<<"\nTarget Replacement REPLACE_BAND_IF_PARTIAL_TARGET:"<<endl; showPixels(tile, expected_2); // Target Replacement: flipper->setTargetRange(0, 10); flipper->setReplacementMode(ossimPixelFlipper::REPLACE_ALL_BANDS_IF_PARTIAL_TARGET); tile = flipper->getTile(tile_rect); cout<<"\nTarget Replacement REPLACE_ALL_BANDS_IF_PARTIAL_TARGET:"<<endl; showPixels(tile, expected_3); // Target Replacement: flipper->setTargetRange(0, 10); flipper->setReplacementMode(ossimPixelFlipper::REPLACE_ONLY_FULL_TARGETS); tile = flipper->getTile(tile_rect); cout<<"\nTarget Replacement REPLACE_ONLY_FULL_TARGETS:"<<endl; showPixels(tile, expected_4); // Clamping: flipper->setClampValues(8, 200); tile = flipper->getTile(tile_rect); cout<<"\nClamping:"<<endl; showPixels(tile, expected_5); // Valid Vertices: valid_vertices.clear(); valid_vertices.push_back(ossimIpt(3,0)); valid_vertices.push_back(ossimIpt(127,0)); valid_vertices.push_back(ossimIpt(127,127)); valid_vertices.push_back(ossimIpt(3,127)); handler->writeValidImageVertices(valid_vertices); flipper->initialize(); flipper->setClipMode(ossimPixelFlipper::VALID_VERTICES); tile = flipper->getTile(tile_rect); cout<<"\nValid Vertices (with clamping):"<<endl; showPixels(tile, expected_6); } catch (const ossimException& e) { ossimNotify(ossimNotifyLevel_DEBUG) << e.what() << std::endl; } cout << "FINISHED" << endl; return 0; }
ossimIpt ossimDtedHandler::getSizeOfElevCell() const { return ossimIpt(m_numLonLines, m_numLatPoints); }
bool ossimQuickbirdNitfTileSource::open() { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimQuickbirdNitfTileSource::open(file) DEBUG: entered ..." << std::endl; } ossimFilename file = theImageFile; file = file.replaceAllThatMatch("_R[0-9]+C[0-9]+"); ossimQuickbirdTile tileFile; bool openedTileFile = false; file.setExtension("TIL"); if(!tileFile.open(file)) { file.setExtension("TIL"); if(tileFile.open(file)) { openedTileFile = true; } else { file.setExtension("til"); if(tileFile.open(file)) { openedTileFile = true; } } } else { openedTileFile = true; } if(openedTileFile) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimQuickbirdNitfTileSource::open(file) DEBUG:" << "\nOpened tile file" << std::endl; } // Call the base class open... if(!ossimNitfTileSource::open()) { return false; } ossimQuickbirdTileInfo info; ossimIrect tempBounds = getCurrentImageHeader()->getImageRect(); tempBounds = ossimIrect(0, 0, tempBounds.width() - 1, tempBounds.height() - 1); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimQuickbirdNitfTileSource::open(file) DEBUG:" << "\nheader rectangle = " << tempBounds << std::endl; } ossimIpt ulPt; ossimIpt urPt; ossimIpt lrPt; ossimIpt llPt; ossimDpt shift; if(tileFile.getInfo(info, theImageFile.file().upcase())) { ulPt.makeNan(); urPt.makeNan(); lrPt.makeNan(); llPt.makeNan(); if((info.theUlXOffset != OSSIM_INT_NAN) && (info.theUlYOffset != OSSIM_INT_NAN)) { shift = ossimIpt(info.theUlXOffset, info.theUlYOffset); } else { shift = ossimIpt(0,0); } m_transform = new ossim2dTo2dShiftTransform(shift); } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimQuickbirdNitfTileSource::open(file) DEBUG:" << "\nUl = " << ulPt << "\nUr = " << urPt << "\nLr = " << lrPt << "\nLl = " << llPt << "\ntheImageRect: " << getImageRectangle(0) << "\nExiting..." << std::endl; } } else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimQuickbirdNitfTileSource::open(file) DEBUG" << "Not opened..." << std::endl; } } return openedTileFile; }
void ossimImageSourceSequencer::setTileSize(ossim_int32 width, ossim_int32 height) { setTileSize(ossimIpt(width, height)); }
void ossimIgen::initializeAttributes() { theBuildThumbnailFlag = false; theThumbnailSize = ossimIpt(0,0); theTilingEnabled = false; if(ossimMpi::instance()->getRank() != 0) { ossimPreferences::instance()->addPreferences(theKwl, "preferences.", true); } const char* lookup = theKwl.find("igen.output_progress"); if (lookup) { ossimString os = lookup; theProgressFlag = os.toBool(); } const char* thumbnailStr = theKwl.find("igen.thumbnail"); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "Thumbnail string = " << ossimString(thumbnailStr) << std::endl; } if(thumbnailStr) { theBuildThumbnailFlag= ossimString(thumbnailStr).toBool(); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "Generate thumbnail attribute is set to " << theBuildThumbnailFlag << std::endl; } if(theBuildThumbnailFlag) { const char* resStr = theKwl.find("igen.thumbnail_res"); if(resStr) { theThumbnailSize = ossimIpt(0,0); std::istringstream in(resStr); ossimString x,y; in >> x >> y; ossim_int32 ix = x.toInt32(); ossim_int32 iy = y.toInt32(); if (ix > 0) { theThumbnailSize.x = ix; } else { theThumbnailSize.x = 128; } if (iy > 0) { theThumbnailSize.y = iy; } else { theThumbnailSize.y = theThumbnailSize.x; } } else { theThumbnailSize = ossimIpt(128, 128); } } }
ossimRefPtr<ossimImageData> ossimCFARFilter::getTile(const ossimIrect& tileRect, ossim_uint32 resLevel) { if(!theInputConnection) { return theTile; } if(!isSourceEnabled()) { return theInputConnection->getTile(tileRect, resLevel); } //--- // We have a 5x5 matrix so stretch the rect out to cover // the required pixels. We only need 2 pixels to the left // and right of the center pixel. //--- ossimIrect newRect(ossimIpt(tileRect.ul().x - 2, tileRect.ul().y - 2), ossimIpt(tileRect.lr().x + 2, tileRect.lr().y + 2)); ossimRefPtr<ossimImageData> data = theInputConnection->getTile(newRect, resLevel); if(!data.valid() || !data->getBuf()) { return data; } // First time through or after an initialize()... if (!theTile.valid()) { allocate(); if (!theTile.valid()) // Should never happen! { return data; } } // First time through, after an initialize() or a setKernel()... if (!theNullPixValue.size()) { computeNullMinMax(); if (!theNullPixValue.size()) // Should never happen! { return data; } } theTile->setImageRectangle(tileRect); theTile->makeBlank(); switch(data->getScalarType()) { case OSSIM_UCHAR: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<ossim_uint8>(0), data, theTile); } else { convolvePartial(static_cast<ossim_uint8>(0), data, theTile); } break; } case OSSIM_FLOAT: case OSSIM_NORMALIZED_FLOAT: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<float>(0), data, theTile); } else { convolvePartial(static_cast<float>(0), data, theTile); } break; } case OSSIM_USHORT16: case OSSIM_USHORT11: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<ossim_uint16>(0), data, theTile); } else { convolvePartial(static_cast<ossim_uint16>(0), data, theTile); } break; } case OSSIM_SSHORT16: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<ossim_sint16>(0), data, theTile); } else { convolvePartial(static_cast<ossim_sint16>(0), data, theTile); } break; } case OSSIM_DOUBLE: case OSSIM_NORMALIZED_DOUBLE: { if(data->getDataObjectStatus() == OSSIM_FULL) { convolveFull(static_cast<double>(0), data, theTile); } else { convolvePartial(static_cast<double>(0), data, theTile); } break; } default: { ossimNotify(ossimNotifyLevel_WARN) << "ossimCFARFilter::getTile WARNING:\n" << "Scalar type = " << theTile->getScalarType() << " Not supported by ossimCFARFilter" << endl; break; } } theTile->validate(); return theTile; }
int main(int argc, char* argv[]) { static const char MODULE[] = "band_merge:main"; std::string tempString; ossimArgumentParser::ossimParameter stringParam(tempString); ossimArgumentParser argumentParser(&argc, argv); ossimInit::instance()->addOptions(argumentParser); ossimInit::instance()->initialize(argumentParser); argumentParser.getApplicationUsage()->setApplicationName(argumentParser.getApplicationName()); argumentParser.getApplicationUsage()->setDescription(argumentParser.getApplicationName()+" merges band separate images to one image"); argumentParser.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); argumentParser.getApplicationUsage()->addCommandLineOption("-o or --create-overiew", "Creates and overview for the output image"); argumentParser.getApplicationUsage()->addCommandLineOption("-w or --tile-width", "Defines the tile width for the handlers that support tiled output"); if (traceDebug()) CLOG << " Entered..." << std::endl; if (argumentParser.read("-h") || argumentParser.read("--help")||(argumentParser.argc() < 2)) { argumentParser.getApplicationUsage()->write(std::cout); usage(); // for writer output types exit(0); } // Keyword list to initialize image writers with. ossimKeywordlist kwl; const char* PREFIX = "imagewriter."; ossim_uint32 tile_width = 32; bool create_overview = false; if (argumentParser.read("-o") || argumentParser.read("--crate-overview")) { create_overview = true; std::cout << "\nOutput overview building enabled." << std::endl; } if (argumentParser.read("-w", stringParam) || argumentParser.read("-tile-width", stringParam)) { tile_width = ossimString(tempString).toInt(); if ((tile_width % 16) != 0) { cerr << MODULE << " NOTICE:" << "\nTile width must be a multiple of 16!" << "\nDefaulting to 128" << std::endl; tile_width = 0; } std::cout << "Tile width set to: " << tile_width << std::endl; } argumentParser.reportRemainingOptionsAsUnrecognized(); // Three required args: output_type, input file, and output file. if (argumentParser.errors()) { argumentParser.writeErrorMessages(std::cout); exit(0); } if (argumentParser.argc() == 1) { argumentParser.getApplicationUsage()->write(std::cout); usage(); // for writer output types exit(0); } ossim_uint32 number_of_source_images = argumentParser.argc() - 3; if (traceDebug()) { CLOG << "DEBUG:" << "\nargc: " << argumentParser.argc() << "\nnumber_of_source_images: " << number_of_source_images << "\ntile_width: " << tile_width << "\ncreate_overview: " << (create_overview?"true":"false") << std::endl; } ossimString output_type = argv[1]; output_type.downcase(); std::cout << "Output type: " << output_type << std::endl; // Create the vector of image handlers. ossimConnectableObject::ConnectableObjectList ihs; for(ossim_uint32 h = 0; h < number_of_source_images; ++h) { ossimFilename f = argv[h + 2]; std::cout << "Input_image[" << h << "]: " << f << std::endl; ihs.push_back(ossimImageHandlerRegistry::instance()->open(f)); } // Get the output file. ossimFilename output_file = argv[argumentParser.argc() - 1]; std::cout << "Output file: " << output_file << std::endl; //--- // Set the output writer type and the image type. //--- kwl.add(PREFIX, ossimKeywordNames::TYPE_KW, output_type.c_str()); ossimRefPtr<ossimBandMergeSource> bm = new ossimBandMergeSource(ihs); ossimRefPtr<ossimImageFileWriter> fileWriter = ossimImageWriterFactoryRegistry::instance()->createWriter(kwl, PREFIX); if(!fileWriter) { bm->disconnect(); bm = 0; ossimConnectableObject::ConnectableObjectList::iterator i = ihs.begin(); while (i != ihs.end()) { (*i)->disconnect(); (*i) = 0; ++i; } cerr << "Error making an image writer..." << "\nExiting application..." << std::endl; exit(1); } // Write out a geometry file for new image. ossimKeywordlist bm_geom; ossimRefPtr<ossimImageGeometry> geom = bm->getImageGeometry(); geom->saveState(bm_geom); ossimFilename geom_file = output_file; geom_file.setExtension("geom"); bm_geom.write(geom_file); fileWriter->connectMyInputTo(0, bm.get()); if (tile_width) { // Set the tile size... fileWriter->setTileSize(ossimIpt(tile_width, tile_width)); } fileWriter->open(output_file); ossimStdOutProgress prog(2); fileWriter->addListener(&prog); fileWriter->setAreaOfInterest(bm->getBoundingRect()); if( fileWriter->canCastTo("ossimTiffWriter") ) { // ossimTiffWriter* twriter = PTR_CAST(ossimTiffWriter, fileWriter); if(fileWriter.valid()) { try { fileWriter->execute(); } catch(std::exception& e) { ossimNotify(ossimNotifyLevel_DEBUG) << "band_merge: ERROR exception caught:\n" << e.what() << std::endl; } catch (...) { ossimNotify(ossimNotifyLevel_DEBUG) << "band_merge: ERROR - Unknown exception caught!" << std::endl; } } } else if(fileWriter->canCastTo("ossimJpegWriter")) { ossimRefPtr<ossimScalarRemapper> remapper = NULL; if(PTR_CAST(ossimJpegWriter, fileWriter.get()) && (bm->getOutputScalarType() != OSSIM_UCHAR)) { remapper = new ossimScalarRemapper(bm.get(), OSSIM_UCHAR); remapper->initialize(); fileWriter->connectMyInputTo(0, remapper.get()); } fileWriter->initialize(); try { fileWriter->execute(); } catch(std::exception& e) { ossimNotify(ossimNotifyLevel_DEBUG) << "band_merge: ERROR exception caught:\n" << e.what() << std::endl; } catch (...) { ossimNotify(ossimNotifyLevel_DEBUG) << "band_merge: ERROR - Unknown exception caught!" << std::endl; } } else { try { fileWriter->execute(); } catch(std::exception& e) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "band_merge: ERROR exception caught:\n" << e.what() << std::endl; } } catch (...) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "band_merge: ERROR - Unknown exception caught!" << std::endl; } } } if (create_overview == true) { fileWriter->writeOverviewFile(); } fileWriter->disconnect(); fileWriter = 0; bm = 0; ossimConnectableObject::ConnectableObjectList::iterator it = ihs.begin(); while (it != ihs.end()) { (*it)->disconnect(); (*it) = 0; ++it; } exit(0); }
void ossimAnnotationMultiPolyObject::draw(ossimRgbImage& anImage)const { if(theMultiPolygon.size()<1) return; if(theBoundingRect.hasNans()) return; anImage.setDrawColor(theRed, theGreen, theBlue); anImage.setThickness(theThickness); ossimDrect imageRect = anImage.getImageData()->getImageRectangle(); if(theBoundingRect.intersects(imageRect)) { // we need to extend it by a couple of pixels since // if a pixel lies on the edge and then another pixel is just off // the edge we will get a stair step and so for several pixels // the line might be inside the image rectangle but the clip // algorithm will only draw 1 pixel since it thinks the first // point is inside and the second point is outside and will // execute the clip algorithm keeping only the first // point. ossimDrect clipRect(imageRect.ul().x - 10, imageRect.ul().y - 10, imageRect.lr().x + 10, imageRect.lr().y + 10); int j = 0; for(ossim_uint32 i = 0; i < theMultiPolygon.size(); ++i) { const ossimPolygon& poly = theMultiPolygon[i]; int vertexCount = poly.getVertexCount(); if(!theFillEnabled) { if(poly.getNumberOfVertices() == 1) { ossimDpt start, end; start = poly[0]; end = poly[0]; if(clipRect.clip(start, end)) { anImage.drawLine(ossimIpt(start), ossimIpt(end)); } } else if(poly.getNumberOfVertices() == 2) { ossimDpt start, end; start = poly[0]; end = poly[1]; if(clipRect.clip(start, end)) { anImage.drawLine(ossimIpt(start), ossimIpt(end)); } } else if(vertexCount > 2) { ossimDpt start, end; j = 0; while(j<vertexCount) { start = poly[j]; end = poly[(j+1)%vertexCount]; if(clipRect.clip(start, end)) { anImage.drawLine(ossimIpt(start), ossimIpt(end)); } ++j; } #if 0 ossimDpt start, end; start = poly[vertexCount-1]; end = poly[0]; j = 0; do { if(clipRect.clip(start, end)) { anImage.drawLine(ossimIpt(start), ossimIpt(end)); } ++j; start = poly[j-1]; end = poly[j]; } while(j < vertexCount); #endif } } else { vector<ossimPolygon> result; if(poly.clipToRect(result, imageRect)) { for(j = 0; j < (int)result.size(); ++j) { anImage.drawFilledPolygon(result[j].getVertexList()); } } } } } }
ossimRefPtr<ossimImageData> ossimKakaduJ2kReader::getTile( const ossimIrect& rect, ossim_uint32 resLevel) { // This tile source bypassed, or invalid res level, return a blank tile. if(!isSourceEnabled() || !isOpen() || !isValidRLevel(resLevel)) { return ossimRefPtr<ossimImageData>(); } if (theTile.valid()) { // Rectangle must be set prior to getOverviewTile call. theTile->setImageRectangle(rect); if (resLevel) { if ( getOverviewTile(resLevel, theTile.get() ) == false ) { theTile->makeBlank(); } } else { //--- // See if the whole tile is going to be filled, if not, start out with // a blank tile so data from a previous load gets wiped out. //--- if ( !rect.completely_within(theImageRect) ) { // Start with a blank tile. theTile->makeBlank(); } //--- // See if any point of the requested tile is in the image. //--- if ( rect.intersects(theImageRect) ) { ossimIrect clipRect = rect.clipToRect(theImageRect); ossimIrect exandedRect = clipRect; //--- // Shift the upper left corner of the "clip_rect" to the an even // j2k tile boundry. //--- exandedRect.stretchToTileBoundary(ossimIpt(theTileSizeX, theTileSizeY)); // Vertical tile loop. ossim_int32 y = exandedRect.ul().y; while (y < exandedRect.lr().y) { // Horizontal tile loop. ossim_int32 x = exandedRect.ul().x; while (x < exandedRect.lr().x) { if ( loadTileFromCache(x, y, clipRect) == false ) { if ( loadTile(x, y) ) { //--- // Note: Clip the cache tile to the image clipRect // since there are j2k tiles that go beyond the image // dimensions, i.e., edge tiles. //--- ossimIrect cr = theCacheTile->getImageRectangle(). clipToRect(clipRect); theTile->loadTile(theCacheTile->getBuf(), theCacheTile->getImageRectangle(), cr, OSSIM_BSQ); } } x += theTileSizeX; // Go to next tile. } y += theTileSizeY; // Go to next row of tiles. } // Set the tile status. theTile->validate(); } // matches: if ( rect.intersects(theImageRect) ) } // r0 block } // matches: if (theTile.valid()) return theTile; }
//************************************************************************************************* // I know what I am. I am a Quickbird TIFF image. I may be standalone or tiled with row-column // designation in the file name. My projection information is available (possibly) in an // accompanying RPC file and/or internal TIF tag, and my transform info (sub-image offset) is // available in a TILE info file (*.til) or internal TIF tag. Therefore, I (and not some outside // factory) am best qualified for establishing my image geometry. //************************************************************************************************* ossimRefPtr<ossimImageGeometry> ossimQuickbirdTiffTileSource::getImageGeometry() { if ( !theGeometry ) { //--- // Check factory for external geom: //--- theGeometry = getExternalImageGeometry(); if ( !theGeometry ) { theGeometry = new ossimImageGeometry(); // Fetch the tile info for this particular image: if ( m_tileInfoFilename.size() ) { ossimQuickbirdTile tileFile; if ( tileFile.open(m_tileInfoFilename) ) { ossimQuickbirdTileInfo info; bool infoStatus = tileFile.getInfo(info, theImageFile.file().upcase()); if ( !infoStatus ) { infoStatus = tileFile.getInfo(info, theImageFile.file().downcase()); } if ( infoStatus ) { // Establish sub-image offset (shift) for this tile: ossimDpt shift(0,0); if ((info.theUlXOffset != OSSIM_INT_NAN) && (info.theUlYOffset != OSSIM_INT_NAN)) shift = ossimIpt(info.theUlXOffset, info.theUlYOffset); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimQuickbirdTiffTileSource::open() DEBUG:" << "\nSub image offset = " << shift << std::endl; } // Create the transform and set it in the geometry object: ossimRefPtr<ossim2dTo2dTransform> transform = new ossim2dTo2dShiftTransform(shift); theGeometry->setTransform(transform.get()); // Next is the projection part of the image geometry. This should be available // as an external RPC file or internal RPC's in the tiff file. Otherwise use // the map projection specified in the // tiff file: theGeometry->setProjection(0); ossimRefPtr<ossimQuickbirdRpcModel> model = new ossimQuickbirdRpcModel; if (model->parseFile(theImageFile)) { theGeometry->setProjection(model.get()); } else { // Last resort to a projection factory: ossimRefPtr<ossimProjection> proj = ossimProjectionFactoryRegistry::instance()->createProjection(this); if (proj.valid()) theGeometry->setProjection(proj.get()); } } // Set image things the geometry object should know about. initImageParameters( theGeometry.get() ); } } } } return theGeometry; }
int main(int argc, char* argv[]) { static const char MODULE[] = "icp:main"; std::string tempString; ossimArgumentParser::ossimParameter stringParam(tempString); ossimArgumentParser ap(&argc, argv); ossimInit::instance()->addOptions(ap); ossimInit::instance()->initialize(ap); ossimApplicationUsage* au = ap.getApplicationUsage(); au->setApplicationName(ap.getApplicationName()); au->setDescription(ap.getApplicationName()+ " copies any supported input image format to any supported output image format format"); au->setCommandLineUsage(ap.getApplicationName()+ " [options] <output_type> <input_file> <output_file>"); au->addCommandLineOption("-h or --help", "Display this information"); au->addCommandLineOption("-a or --use-scalar-remapper", "Uses scalar remapper, transforms to 8-bit"); au->addCommandLineOption("-o or --create-overview", "Creates and overview for the output image"); au->addCommandLineOption("-b or --bands <n,n...>", "uses the specified bands: ex. \"1, 2, 4\" will select bands 1 2 and 4 of the input image. " "Note: it is 1 based"); au->addCommandLineOption("-c or --compression-type <type>", "Uses compression. Currently valid for only tiff output -c jpeg will use jpeg compression"); au->addCommandLineOption("-e or --entry <n>", "For multi image handlers which entry do you wish to extract"); au->addCommandLineOption("-q or --compression-quality <n>", "Uses compression. Valid for jpeg type. default is 75 where 100 is best and 1 is worst"); au->addCommandLineOption("--pixel-type <type>", "Valid values: area or point, this will determine if the tie point is upper left corner of " "the upper left pixel (area) or the center of the upper left corner (point), default=point. " "NOTE: This option will only affect the tiff writer."); au->addCommandLineOption("-r or --res-level <n>", "Which res level to extract from the input: ex -r 1 will get res level 1"); au->addCommandLineOption("-l or --start-line <n>", "Which start line do you wish to copy from the input. If none is given then 0 is used"); au->addCommandLineOption("-L or --end-line <n>", "Which end line do you wish to copy from the input. If none is given then max line is used"); au->addCommandLineOption("-s or --start-sample <n>", "Which start sample do you wish to copy from the input. If none is given then 0 is used"); au->addCommandLineOption("-p or --end-sample <n>", "The end sample you wish to copy from the input. If none is given then max sample is used"); au->addCommandLineOption("-t or --create-thumbnail <n>", "Takes an argument which is the maximum pixel dimension desired."); au->addCommandLineOption("-w or --tile-width <n>", "Defines the tile width for the handlers that support tiled output"); au->addCommandLineOption("--reader-prop <string>", "Adds a property to send to the reader. format is name=value"); au->addCommandLineOption("--writer-prop <string>", "Adds a property to send to the writer. format is name=value"); au->addCommandLineOption("--filter-spec <fname>", "This is an external file spec that describes a chain for filtering the input image."); au->addCommandLineOption("--use-mask [<fname>]", "Optionally specify name of mask file to use for masking the input image. If no filename " "given, then the default mask filename is used."); if (traceDebug()) CLOG << " Entered..." << std::endl; // Keyword list to initialize image writers with. ossimKeywordlist kwl; const char* PREFIX = "imagewriter."; bool lineEndIsSpecified = false; bool sampEndIsSpecified = false; bool lineStartIsSpecified = false; bool sampStartIsSpecified = false; bool create_overview = false; bool create_thumbnail = false; bool use_band_selector = false; bool use_scalar_remapper = false; bool use_mask = false; ossim_int32 tile_width = 0; ossim_int32 max_thumbnail_dimension = 0; ossim_int32 rr_level = 0; ossim_int32 line_start = 0; ossim_int32 line_stop = 0; ossim_int32 sample_start = 0; ossim_int32 sample_stop = 0; ossim_int32 cibcadrg_entry = 0; vector<ossimString> band_list(0); ossimFilename filterSpec, maskFile; std::map<ossimString, ossimString> readerPropertyMap; std::map<ossimString, ossimString> writerPropertyMap; if (ap.read("-h") || ap.read("--help")||(ap.argc() < 2)) { au->write(ossimNotify(ossimNotifyLevel_NOTICE)); usage(); // for writer output types finalize(0); } while(ap.read("--reader-prop", stringParam)) { std::vector<ossimString> nameValue; ossimString(tempString).split(nameValue, "="); if(nameValue.size() == 2) { readerPropertyMap.insert(std::make_pair(nameValue[0], massageQuotedValue(nameValue[1]))); } } while(ap.read("--writer-prop", stringParam)) { std::vector<ossimString> nameValue; ossimString(tempString).split(nameValue, "="); if(nameValue.size() == 2) { writerPropertyMap.insert(std::make_pair(nameValue[0], massageQuotedValue(nameValue[1]))); } } while(ap.read("-a") || ap.read("--use-scalar-remapper")) { use_scalar_remapper = true; } while(ap.read("--filter-spec",stringParam)) { filterSpec = ossimFilename(tempString); } while(ap.read("--use-mask") || ap.read("--use-mask",stringParam) ) { maskFile = ossimFilename(tempString); use_mask = true; } while(ap.read("-o") || ap.read("--create-overview")) { create_overview = true; } while(ap.read("-b", stringParam) || ap.read("--bands", stringParam)) { use_band_selector = true; ossimString s = tempString; band_list = s.split(","); } while(ap.read("-c", stringParam) || ap.read("--compression-type", stringParam)) { ossimString s = tempString; s.downcase(); kwl.add(PREFIX, ossimKeywordNames::COMPRESSION_TYPE_KW, s.c_str(), true); } while(ap.read("-e", stringParam) || ap.read("--entry", stringParam)) { cibcadrg_entry = ossimString(tempString).toInt(); } while(ap.read("-q", stringParam) || ap.read("--compression-quality", stringParam)) { // Set the jpeg compression quality level. kwl.add(PREFIX, ossimKeywordNames::COMPRESSION_QUALITY_KW, tempString.c_str(), true); } while(ap.read("-r", stringParam) || ap.read("--res-level", stringParam)) { rr_level = ossimString(tempString).toInt(); } while(ap.read("-l", stringParam) || ap.read("--start-line", stringParam)) { lineStartIsSpecified = true; line_start = ossimString(tempString).toInt(); } while(ap.read("-L", stringParam) || ap.read("--end-line", stringParam)) { lineEndIsSpecified = true; line_stop = ossimString(tempString).toInt(); } while(ap.read("-s", stringParam) || ap.read("--start-sample", stringParam)) { sampStartIsSpecified = true; sample_start = ossimString(tempString).toInt(); } while(ap.read("-p", stringParam) || ap.read("--end-sample", stringParam)) { sampEndIsSpecified = true; sample_stop = ossimString(tempString).toInt(); } while(ap.read("-t", stringParam) || ap.read("--create-thumbnail", stringParam)) { create_thumbnail = true; max_thumbnail_dimension=ossimString(tempString).toInt(); } while(ap.read("-w", stringParam) || ap.read("-tile-width", stringParam)) { tile_width = ossimString(tempString).toInt(); if ((tile_width % 16) != 0) { ossimNotify(ossimNotifyLevel_NOTICE) << MODULE << " NOTICE:" << "\nTile width must be a multiple of 16!" << "\nDefaulting to 128" << std::endl; tile_width = 0; } } if (ap.read("--pixel-type", stringParam)) { ossimString os = tempString; os.downcase(); if (os.contains("area")) { kwl.add(PREFIX, ossimKeywordNames::PIXEL_TYPE_KW, "area", true); } else { kwl.add(PREFIX, ossimKeywordNames::PIXEL_TYPE_KW, "point", true); } } ap.reportRemainingOptionsAsUnrecognized(); // Three required args: output_type, input file, and output file. if (ap.errors()) { ap.writeErrorMessages(ossimNotify(ossimNotifyLevel_NOTICE)); finalize(0); } if (ap.argc() < 4) { au->write(ossimNotify(ossimNotifyLevel_NOTICE)); usage(); // for writer output types finalize(0); } //--- // Set the writer type and the image type. //--- ossimString output_type = ap.argv()[ap.argc()-3]; // output_type.downcase(); kwl.add(PREFIX, ossimKeywordNames::TYPE_KW, output_type.c_str(), true); // Get the input file. const char* input_file = argv[ap.argc()-2]; // Get the output file. ossimFilename output_file = argv[ap.argc()-1]; if (traceDebug()) { CLOG << "DEBUG:" << "\noutput type: " << ap.argv()[ap.argc()-3] << "\ninput file: " << ap.argv()[ap.argc()-2] << "\noutput file: " << ap.argv()[ap.argc()-1] << std::endl; if (tile_width) ossimNotify(ossimNotifyLevel_NOTICE) << "tile_width: " << tile_width << std::endl; } // Get an image handler for the input file. ossimRefPtr<ossimImageHandler> ih = ossimImageHandlerRegistry::instance()->open(ossimFilename(input_file)); ossimCibCadrgTileSource* its = PTR_CAST(ossimCibCadrgTileSource, ih.get()); if (its) { if (cibcadrg_entry > 0) { its->setCurrentEntry(cibcadrg_entry); } } if (!ih) { ossimNotify(ossimNotifyLevel_NOTICE) << "Unsupported image file: " << input_file << "\nExiting application..." << std::endl; finalize(0); } if (ih->getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { ossimNotify(ossimNotifyLevel_FATAL) << "Error reading image: " << input_file << "Exiting application..." << std::endl; finalize(1); } // Set the reader properties if any. if ( readerPropertyMap.size() ) { ossimPropertyInterface* pi = (ossimPropertyInterface*)ih.get(); std::map<ossimString, ossimString>::iterator iter = readerPropertyMap.begin(); while(iter != readerPropertyMap.end()) { pi->setProperty(iter->first, iter->second); ++iter; } } ih->initialize(); ossimRefPtr<ossimImageSource> source = ih.get(); if (traceDebug()) { CLOG << "DEBUG:" << "\nImage Handler: " << ih->getLongName() << std::endl; } ossimRefPtr<ossimMaskFilter> mask_filter = 0; if (use_mask) { if (maskFile.empty()) maskFile = ih->getFilenameWithThisExtension("mask"); ossimRefPtr<ossimImageHandler> mh = ossimImageHandlerRegistry::instance()->open(maskFile); if (!mh.valid()) { ossimNotify(ossimNotifyLevel_FATAL)<<"ossim-icp -- Could not open raster mask file <" <<maskFile<<">. Maske request will be ignored. Aborting..."<<endl; finalize(1); } mask_filter = new ossimMaskFilter(ih.get(), mh.get()); source = mask_filter.get(); } ossimRefPtr<ossimBandSelector> bs = 0; if(!filterSpec.empty()&&filterSpec.exists()) { ossimKeywordlist kwl; if(kwl.addFile(filterSpec)) { ossimRefPtr<ossimObject> input = ossimObjectFactoryRegistry::instance()->createObject(kwl); if(input.valid()) { ossimImageSource* inputImageSource = dynamic_cast<ossimImageSource*> (input.get()); if(inputImageSource) { inputImageSource->connectMyInputTo(source.get()); source = inputImageSource; } } } } if (use_band_selector && (source->getNumberOfOutputBands() > 1)) { // Build the band list. ossim_uint32 bands = source->getNumberOfOutputBands(); vector<ossim_uint32> bl; ossim_uint32 i; for (i=0; i<band_list.size(); ++i) { bl.push_back(band_list[i].toULong()-1); } // Check the list. Make sure all the bands are within range. for (i=0; i<bl.size(); ++i) { if (bl[i] >= bands) { ossimNotify(ossimNotifyLevel_FATAL) << MODULE << " ERROR:" << "\nBand list range error!" << "\nHighest available band: " << bands << std::endl; finalize(1); } } bs = new ossimBandSelector(); bs->connectMyInputTo(source.get()); bs->setOutputBandList(bl); bs->enableSource(); bs->initialize(); source = bs.get(); if (traceDebug()) { CLOG << "DEBUG:" << "\nZero based output band list:" << std::endl; for (i=0; i<bl.size(); ++i) { ossimNotify(ossimNotifyLevel_NOTICE) << " band[" << i << "]: " << bl[i] << std::endl; } ossimNotify(ossimNotifyLevel_NOTICE) << std::endl; } } //--- // Get the image rectangle for the rrLevel selected. //--- ossimIrect output_rect; ossimRefPtr<ossimRLevelFilter> rlevelFilter = 0; if (create_thumbnail == true) { rlevelFilter = new ossimRLevelFilter; rlevelFilter->connectMyInputTo(source.get()); source = rlevelFilter.get(); // Get the rlevel that <= max thumbnail dimension. int max = 0; int level = 0; while (level < ((ossim_int32)ih->getNumberOfDecimationLevels()-1)) { int lines = ih->getNumberOfLines(level); int samples = ih->getNumberOfSamples(level); max = lines > samples ? lines : samples; if (max <= max_thumbnail_dimension) { break; } level++; } if (max > max_thumbnail_dimension) { ossimNotify(ossimNotifyLevel_NOTICE) << " NOTICE:" << "\nLowest rlevel not small enough to fullfill " << "max_thumbnail_dimension requirement!" << std::endl; } // Set the reduced res level. This will override the -r option. rr_level = level; rlevelFilter->setCurrentRLevel(rr_level); if (rr_level) { rlevelFilter->setOverrideGeometryFlag(true); } // Set the rectangle to that of the res level. output_rect = rlevelFilter->getBoundingRect(); } // end of "if (create_thumbnail == true) else { // modified to only do an rlevel if one is requested if(rr_level != 0) { //*** // Check for a valid reduced resolution level. // If the operator entered an invalid rr_level with the -r option, // spit out a warning and set to default "0". //*** if (rr_level >= (ossim_int32)(ih->getNumberOfDecimationLevels())) { ossimNotify(ossimNotifyLevel_NOTICE) << " WARNING:" << "\n\t Selected res level greater than available res levels." << "\n\t Defaulting to res level zero. " << std::endl; rr_level = 0; } rlevelFilter = new ossimRLevelFilter; rlevelFilter->connectMyInputTo(source.get()); source = rlevelFilter.get(); rlevelFilter->setCurrentRLevel(rr_level); if (rr_level) { rlevelFilter->setOverrideGeometryFlag(true); } } output_rect = source->getBoundingRect(rr_level); //*** // If any of these are true the user wants to cut the rectangle. //*** if ( lineStartIsSpecified || lineEndIsSpecified || sampStartIsSpecified || sampEndIsSpecified) { if (!lineStartIsSpecified) line_start = output_rect.ul().y; if (!lineEndIsSpecified) line_stop = output_rect.lr().y; if (!sampStartIsSpecified) sample_start = output_rect.ul().x; if (!sampEndIsSpecified) sample_stop = output_rect.lr().x; //*** // Check the start and stop points and make sure they are in // the right order; if not, swap them. //*** if (line_stop < line_start) { ossimNotify(ossimNotifyLevel_NOTICE) << " WARNING:\n" << "\t Line end is less than line start, swapping." << std::endl; int tmp = line_start; line_start = line_stop; line_stop = tmp; } if (sample_stop < sample_start) { ossimNotify(ossimNotifyLevel_WARN) << " WARNING:\n" << "\t Sample end is less than sample start, swapping." << std::endl; int tmp = sample_start; sample_start = sample_stop; sample_stop = tmp; } // if (sample_start > output_rect.ul().x && // sample_start < output_rect.lr().x) // { output_rect.set_ulx(sample_start); // } // if (sample_stop > output_rect.ul().x && // sample_start < output_rect.lr().x) // { output_rect.set_lrx(sample_stop); // } // if (line_start > output_rect.ul().y && // line_start < output_rect.lr().y) // { output_rect.set_uly(line_start); // } // if (line_stop > output_rect.ul().y && // line_start < output_rect.lr().y) // { output_rect.set_lry(line_stop); // } } // End of "if ((lineEndIsSpecified) ||..." } if (traceDebug()) { CLOG << "icp:main debug" << "\nrr_level: " << rr_level << "\noutput_rect: " << output_rect << "\nkeyword list: " << kwl << std::endl; } ossimRefPtr<ossimImageFileWriter> writer = ossimImageWriterFactoryRegistry::instance()->createWriter(kwl, PREFIX); if( writer == 0 ) { ossimNotify(ossimNotifyLevel_NOTICE) << "\nCould not create writer of type: " << output_type << std::endl; usage(); finalize(1); } writer->connectMyInputTo(0, source.get()); if (tile_width) { // Set the tile size... writer->setTileSize(ossimIpt(tile_width, tile_width)); } writer->open(output_file); // Add a listener to get percent complete. ossimStdOutProgress prog(0, true); writer->addListener(&prog); if (writer->getErrorStatus() == ossimErrorCodes::OSSIM_OK) { if( (ih->getOutputScalarType() != OSSIM_UCHAR) && ((PTR_CAST(ossimJpegWriter, writer.get())) || use_scalar_remapper)) { writer->setScaleToEightBitFlag(true); } ossimRefPtr<ossimCacheTileSource> cache = new ossimCacheTileSource; ossimIpt tileWidthHeight(ih->getImageTileWidth(), ih->getImageTileHeight()); // only use the cache if its stripped if(static_cast<ossim_uint32>(tileWidthHeight.x) == ih->getBoundingRect().width()) { cache->connectMyInputTo(0, source.get()); cache->setTileSize(tileWidthHeight); writer->connectMyInputTo(0, cache.get()); } else { writer->connectMyInputTo(0, source.get()); } writer->initialize(); writer->setAreaOfInterest(output_rect); // Set the output rectangle. try { if ( writerPropertyMap.size() ) { ossimPropertyInterface* propInterface = (ossimPropertyInterface*)writer.get(); std::map<ossimString, ossimString>::iterator iter = writerPropertyMap.begin(); while(iter!=writerPropertyMap.end()) { propInterface->setProperty(iter->first, iter->second); ++iter; } } writer->execute(); } catch(std::exception& e) { ossimNotify(ossimNotifyLevel_FATAL) << "icp:main ERROR:\n" << "Caught exception!\n" << e.what() << std::endl; } catch(...) { ossimNotify(ossimNotifyLevel_FATAL) << "icp:main ERROR:\n" << "Unknown exception caught!\n" << std::endl; } cache = 0; } else { ossimNotify(ossimNotifyLevel_FATAL) << "Error detected in the image writer..." << "\nExiting application..." << std::endl; finalize(1); } if (create_overview == true) { writer->writeOverviewFile(); } finalize(0); }