Пример #1
0
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;
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
bool ossimNetCdfReader::getTile(ossimImageData* result,
                                  ossim_uint32 resLevel)
{
   bool status = false;
   status = getOverviewTile(resLevel, result);
   
   ossimIrect rect = result->getImageRectangle();
   if (!status) // Did not get an overview tile.
   {
      if(!theTile.valid()||!theMemoryTile.valid())
      {
         cacheImage();
      }
      if (theTile.valid())
      {
         // Image rectangle must be set prior to calling getTile.
         theTile->setImageRectangle(rect);
         
         theTile->makeBlank();
         
         ossimIrect memRect = theMemoryTile->getImageRectangle();
         
         if(memRect.intersects(rect))
         {
            ossimIrect clampRect = theMemoryTile->getImageRectangle().clipToRect(rect);
            
            theTile->loadTile(theMemoryTile->getBuf(),
                              memRect,
                              OSSIM_BSQ);
            
            theTile->validate();
            status = true;
         }
      }
   }
   return status;
}
Пример #6
0
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;
}
Пример #7
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;
}
Пример #8
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;
}
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;
}