Exemplo n.º 1
0
bool ossimHdfReader::getTile(ossimImageData* result,
                             ossim_uint32 resLevel)
{
   bool status = false;

   //---
   // Not open, this tile source bypassed, or invalid res level,
   // return a blank tile.
   //---
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      result->ref();  // Increment ref count.

      //---
      // Check for overview tile.  Some overviews can contain r0 so always
      // call even if resLevel is 0.  Method returns true on success, false
      // on error.
      //---
      status = getOverviewTile(resLevel, result);

      if (!status) // Did not get an overview tile.
      {
         status = true;

         ossimIrect tile_rect = result->getImageRectangle();     

         if (getImageRectangle().intersects(tile_rect))
         {
            // Make a clip rect.
            ossimIrect clipRect = tile_rect.clipToRect(getImageRectangle());

            if (tile_rect.completely_within(clipRect) == false)
            {
               // Not filling whole tile so blank it out first.
               result->makeBlank();
            }

            if (m_gdalTileSource.valid())
            {
               ossimRefPtr<ossimImageData> imageData =
                  m_gdalTileSource->getTile(tile_rect, resLevel);
               result->loadTile(imageData->getBuf(), tile_rect, clipRect, OSSIM_BSQ);
            }
     
         }
         else // No intersection...
         {
            result->makeBlank();
         }
      }
      result->validate();

      result->unref();  // Decrement ref count.
   }

   return status;
}
Exemplo n.º 2
0
bool ossimAdrgTileSource::getTile(ossimImageData* result,
                                  ossim_uint32 resLevel)
{
   bool status = false;

   //---
   // Not open, this tile source bypassed, or invalid res level,
   // return a blank tile.
   //---
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      result->ref();  // Increment ref count.

      //---
      // Check for overview tile.  Some overviews can contain r0 so always
      // call even if resLevel is 0.  Method returns true on success, false
      // on error.
      //---
      status = getOverviewTile(resLevel, result);
      
      if (!status) // Did not get an overview tile.
      {
         status = true;
         
         ossimIrect tile_rect = result->getImageRectangle();
         
         ossimIrect image_rect = getImageRectangle(resLevel);
         
         result->makeBlank();
         
         //---
         // See if any point of the requested tile is in the image.
         //---
         if ( tile_rect.intersects(image_rect) )
         {
            ossimIrect clip_rect = tile_rect.clipToRect(image_rect);
            
            // Load the tile buffer with data from the adrg.
            status = fillBuffer(tile_rect, clip_rect, result);

            if (status)
            {
               result->validate();
            }
         }
      }

      result->unref();  // Decrement ref count.
   }

   return status;
}
Exemplo n.º 3
0
bool rspfHdfReader::getTile(rspfImageData* result,
                             rspf_uint32 resLevel)
{
   bool status = false;
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      result->ref();  // Increment ref count.
      status = getOverviewTile(resLevel, result);
      if (!status) // Did not get an overview tile.
      {
         status = true;
         rspfIrect tile_rect = result->getImageRectangle();     
         if (getImageRectangle().intersects(tile_rect))
         {
            rspfIrect clipRect = tile_rect.clipToRect(getImageRectangle());
            if (tile_rect.completely_within(clipRect) == false)
            {
               result->makeBlank();
            }
            if (m_gdalTileSource.valid())
            {
               rspfRefPtr<rspfImageData> imageData =
                  m_gdalTileSource->getTile(tile_rect, resLevel);
               result->loadTile(imageData->getBuf(), tile_rect, clipRect, RSPF_BSQ);
            }
     
         }
         else // No intersection...
         {
            result->makeBlank();
         }
      }
      result->validate();
      result->unref();  // Decrement ref count.
   }
   return status;
}
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;
}
Exemplo n.º 5
0
bool ossimH5Reader::getTile(ossimImageData* result, ossim_uint32 resLevel)
{
   bool status = false;

   m_mutex.lock();
   
   //---
   // Not open, this tile source bypassed, or invalid res level,
   // return a blank tile.
   //---
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      result->ref(); // Increment ref count.
      
      //---
      // Check for overview tile.  Some overviews can contain r0 so always
      // call even if resLevel is 0.  Method returns true on success, false
      // on error.
      //---
      status = getOverviewTile(resLevel, result);

      if (!status) // Did not get an overview tile.
      {
         status = true;
         
         ossimIrect tile_rect = result->getImageRectangle();

         if ( ! tile_rect.completely_within(getImageRectangle(0)) )
         {
            // We won't fill totally so make blank first.
            result->makeBlank();
         }
         
         if (getImageRectangle(0).intersects(tile_rect))
         {
            // Make a clip rect.
            ossimIrect clipRect = tile_rect.clipToRect(getImageRectangle(0));
            
            if (tile_rect.completely_within( clipRect) == false)
            {
               // Not filling whole tile so blank it out first.
               result->makeBlank();
            }

            // Create buffer to hold the clip rect for a single band.
            ossim_uint32 clipRectSizeInBytes = clipRect.area() *
               ossim::scalarSizeInBytes( m_entries[m_currentEntry].getScalarType() );
            vector<char> dataBuffer(clipRectSizeInBytes);

            // Get the data.
            for (ossim_uint32 band = 0; band < getNumberOfInputBands(); ++band)
            {
               // Hdf5 file to buffer:
               m_entries[m_currentEntry].getTileBuf(&dataBuffer.front(), clipRect, band);

               if ( m_entries[m_currentEntry].getScalarType() == OSSIM_FLOAT32 )
               {
                  //---
                  // NPP VIIRS data has null of "-999.3".
                  // Scan and fix non-standard null value.
                  //---
                  const ossim_float32 NP = getNullPixelValue(band);
                  const ossim_uint32 COUNT = clipRect.area();
                  ossim_float32* float_buffer = (ossim_float32*)&dataBuffer.front();
                  for ( ossim_uint32 i = 0; i < COUNT; ++i )
                  {
                     if ( float_buffer[i] <= -999.0 ) float_buffer[i] = NP;
                  }
               }

               // Buffer to tile:
               result->loadBand((void*)&dataBuffer.front(), clipRect, band);
            }

            // Validate the tile, i.e. full, partial, empty.
            result->validate();
         }
         else // No intersection...
         {
            result->makeBlank();
         }
      }

      result->unref();  // Decrement ref count.
   }

   m_mutex.unlock();

   return status;
}
Exemplo n.º 6
0
void ossimPngReader::fillTile(const ossimIrect& clip_rect,
                              ossimImageData* tile)
{
   if (!tile || !m_str) return;

   ossimIrect buffer_rect = clip_rect;
   buffer_rect.stretchToTileBoundary(m_cacheSize);
   buffer_rect.set_ulx(0);
   buffer_rect.set_lrx(getImageRectangle(0).lr().x);

   ossim_int32 number_of_cache_tiles = buffer_rect.height()/m_cacheSize.y;

#if 0
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "tiles high:  " << number_of_cache_tiles
         << endl;
   }
#endif

   ossimIpt origin = buffer_rect.ul();
   
   for (int tileIdx = 0; tileIdx < number_of_cache_tiles; ++tileIdx)
   {
      // See if it's in the cache already.
      ossimRefPtr<ossimImageData> tempTile;
      tempTile = ossimAppFixedTileCache::instance()->
         getTile(m_cacheId, origin);
      if (tempTile.valid())
      {
         tile->loadTile(tempTile.get());
      }
      else
      {
         // Have to read from the png file.
         ossim_uint32 startLine = static_cast<ossim_uint32>(origin.y);
         ossim_uint32 stopLine  = 
            static_cast<ossim_uint32>( min(origin.y+m_cacheSize.y-1,
                                           getImageRectangle().lr().y) );
         ossimIrect cache_rect(origin.x,
                               origin.y,
                               origin.x+m_cacheSize.x-1,
                               origin.y+m_cacheSize.y-1);
         
         m_cacheTile->setImageRectangle(cache_rect);

         if ( !m_cacheTile->getImageRectangle().
              completely_within(getImageRectangle()) )
         {
            m_cacheTile->makeBlank();
         }

         if (startLine < m_currentRow)
         {
            // Must restart the compression process again.
            restart();
         }

         // Gobble any not needed lines.
         while(m_currentRow < startLine)
         {
            png_read_row(m_pngReadPtr, m_lineBuffer, NULL);
            ++m_currentRow;
         }
            
         switch (m_readMode)
         {
            case ossimPngRead8:
            {
               copyLines(ossim_uint8(0), stopLine);
               break;
            }
            case ossimPngRead16:
            {
               copyLines(ossim_uint16(0), stopLine);
               break;
            }
            case ossimPngRead8a:
            {
               if (m_useAlphaChannelFlag)
               {
                  copyLines(ossim_uint8(0), stopLine);
               }
               else
               {
                  // Will burn alpha value into the other bands.
                  copyLinesWithAlpha(ossim_uint8(0), stopLine);
               }
               break;
            }
            case ossimPngRead16a:
            {
               if (m_useAlphaChannelFlag)
               {
                  copyLines(ossim_uint16(0), stopLine); 
               }
               else
               {
                  // Will burn alpha value into the other bands.
                  copyLinesWithAlpha(ossim_uint16(0), stopLine);
               }
               break;
            }
            case ossimPngReadUnknown:
            default:
            {
               break; // should never happen.
            }
         }

         m_cacheTile->validate();
         
         tile->loadTile(m_cacheTile.get());
         
         // Add it to the cache for the next time.
         ossimAppFixedTileCache::instance()->addTile(m_cacheId,
                                                     m_cacheTile);
         
      } // End of reading for png file.
      
      origin.y += m_cacheSize.y;
      
   } // for (int tile = 0; tile < number_of_cache_tiles; ++tile)
   
   tile->validate();
}
Exemplo n.º 7
0
bool ossimPngReader::getTile(ossimImageData* result,
                             ossim_uint32 resLevel)
{
   bool status = false;
   
   //---
   // Not open, this tile source bypassed, or invalid res level,
   // return a blank tile.
   //---
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel) &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      result->ref(); // Increment ref count.
      
      //---
      // Check for overview tile.  Some overviews can contain r0 so always
      // call even if resLevel is 0.  Method returns true on success, false
      // on error.
      //---
      status = getOverviewTile(resLevel, result);

      if (status)
      {
         if(m_outputScalarType == OSSIM_UINT16)
         {
            //---
            // Temp fix:
            // The overview handler could return a tile of OSSIM_USHORT11 if
            // the max sample value was not set to 2047.
            //
            // To prevent a scalar mismatch set 
            //---
            result->setScalarType(m_outputScalarType);
         }
      }
      
      if (!status) // Did not get an overview tile.
      {
         status = true;
         
         ossimIrect tile_rect = result->getImageRectangle();

         if ( ! tile_rect.completely_within(getImageRectangle(0)) )
         {
            // We won't fill totally so make blank first.
            m_tile->makeBlank();
         }
         
         if (getImageRectangle(0).intersects(tile_rect))
         {
            // Make a clip rect.
            ossimIrect clip_rect = tile_rect.clipToRect(getImageRectangle(0));
            
            // This will validate the tile at the end.
            fillTile(clip_rect, result);
         }
      }

      result->unref();  // Decrement ref count.
   }

   return status;
}
Exemplo n.º 8
0
toprsIRect toprsImageReader::getBoundingRect( int resLevel /*= 0*/ ) const
{
    return getImageRectangle(resLevel);
}
bool ossimGeneralRasterTileSource::getTile(ossimImageData* result,
                                           ossim_uint32 resLevel)
{
   bool status = false;
   
   //---
   // Not open, this tile source bypassed, or invalid res level,
   // return a blank tile.
   //---
   if( isOpen() && isSourceEnabled() && isValidRLevel(resLevel)  &&
       result && (result->getNumberOfBands() == getNumberOfOutputBands()) )
   {
      //---
      // Check for overview tile.  Some overviews can contain r0 so always
      // call even if resLevel is 0.  Method returns true on success, false
      // on error.
      //---
      status = getOverviewTile(resLevel, result);
      if (status)
      {
         if(getOutputScalarType() == OSSIM_USHORT11)
         {
            //---
            // Temp fix:
            // The overview handler could return a tile of OSSIM_UINT16 if
            // the max sample value was not set to 2047.
            //---
            result->setScalarType(OSSIM_USHORT11);
         }
      }
      
      if (!status) // Did not get an overview tile.
      {
         status = true;
         
         //---
         // Subtract any sub image offset to get the zero based image space
         // rectangle.
         //---
         ossimIrect tile_rect = result->getImageRectangle();
         
         // This should be the zero base image rectangle for this res level.
         ossimIrect image_rect = getImageRectangle(resLevel);
         
         //---
         // See if any point of the requested tile is in the image.
         //---
         if ( tile_rect.intersects(image_rect) )
         {
            // Make the tile rectangle zero base.
            result->setImageRectangle(tile_rect);

            // Initialize the tile if needed as we're going to stuff it.
            if (result->getDataObjectStatus() == OSSIM_NULL)
            {
               result->initialize();
            }

            ossimIrect clip_rect = tile_rect.clipToRect(image_rect);

            if ( ! tile_rect.completely_within(m_bufferRect) )
            {
               // A new buffer must be loaded.
               if ( !tile_rect.completely_within(clip_rect) )
               {
                  //---
                  // Start with a blank tile since the whole tile buffer will
                  // not be
                  // filled.
                  //---
                  result->makeBlank();
               }

               // Reallocate the buffer if needed.
               if ( m_bufferSizeInPixels != result->getSize() )
               {
                  allocateBuffer( result );
               }

               ossimIpt size(static_cast<ossim_int32>(result->getWidth()),
                             static_cast<ossim_int32>(result->getHeight()));

               if( !fillBuffer(clip_rect.ul(), size) )
               {
                  ossimNotify(ossimNotifyLevel_WARN)
                     << "Error from fill buffer..."
                     << std::endl;
                  //---
                  // Error in filling buffer.
                  //---
                  setErrorStatus();
                  status = false;
               }
            }
            
            result->loadTile(m_buffer,
                             m_bufferRect,
                             clip_rect,
                             m_bufferInterleave);
            result->validate();

            // Set the rectangle back.
            result->setImageRectangle(tile_rect);
            
         }
         else // No intersection.
         {
            result->makeBlank();
         }
      }
   }
   return status;
}