Exemplo n.º 1
0
void ossimH5ImageDataset::getTileBuf(void* buffer, const ossimIrect& rect, ossim_uint32 band)
{
   static const char MODULE[] = "ossimH5ImageDataset::getTileBuf";

   if ( m_dataset )
   {
      try
      {
         // Shift rectangle by the sub image offse (if any) from the m_validRect.
         ossimIrect irect = rect + m_validRect.ul();
         
         //--
         // Turn off the auto-printing when failure occurs so that we can
         // handle the errors appropriately
         //---
         // H5::Exception::dontPrint();

         // NOTE: rank == array dimensions in hdf5 documentation lingo.

         // Get dataspace of the dataset.
         H5::DataSpace imageDataSpace = m_dataset->getSpace();
      
         // Number of dimensions of the input dataspace.:
         const ossim_int32 IN_DIM_COUNT = imageDataSpace.getSimpleExtentNdims();

         // Native type:
         H5::DataType dataType = m_dataset->getDataType();
      
         std::vector<hsize_t> inputCount(IN_DIM_COUNT);
         std::vector<hsize_t> inputOffset(IN_DIM_COUNT);

         if ( IN_DIM_COUNT == 2 )
         {
            inputOffset[0] = irect.ul().y;
            inputOffset[1] = irect.ul().x;
         
            inputCount[0] = irect.height();
            inputCount[1] = irect.width();
         }
         else
         {
            inputOffset[0] = band;
            inputOffset[1] = irect.ul().y;
            inputOffset[2] = irect.ul().x;
         
            inputCount[0] = 1;
            inputCount[1] = irect.height();
            inputCount[2] = irect.width();
         }
      
         // Define hyperslab in the dataset; implicitly giving strike strike and block NULL.
         imageDataSpace.selectHyperslab( H5S_SELECT_SET,
                                         &inputCount.front(),
                                         &inputOffset.front() );
      
         // Output dataspace dimensions.
         const ossim_int32 OUT_DIM_COUNT = 3;
         std::vector<hsize_t> outputCount(OUT_DIM_COUNT);
         outputCount[0] = 1;             // single band
         outputCount[1] = irect.height(); // lines
         outputCount[2] = irect.width();  // samples

         // Output dataspace offset.
         std::vector<hsize_t> outputOffset(OUT_DIM_COUNT);
         outputOffset[0] = 0;
         outputOffset[1] = 0;
         outputOffset[2] = 0;
      
         // Output dataspace.
         H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front());
         bufferDataSpace.selectHyperslab( H5S_SELECT_SET,
                                          &outputCount.front(),
                                          &outputOffset.front() );
      
         // Read data from file into the buffer.
         m_dataset->read( buffer, dataType, bufferDataSpace, imageDataSpace );

         if ( m_endian )
         {
            // If the m_endian pointer is initialized(not zero) swap the bytes.
            m_endian->swap( m_scalar, buffer, irect.area() );
         }
      
         // Cleanup:
         bufferDataSpace.close();
         dataType.close();
         imageDataSpace.close();
         
         // memSpace.close();
         // dataType.close();
         // dataSpace.close();
      }
      catch( const H5::FileIException& error )
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " caught H5::FileIException!" << std::endl;
         error.printError();
      }
   
      // catch failure caused by the DataSet operations
      catch( const H5::DataSetIException& error )
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " caught H5::DataSetIException!" << std::endl;
         error.printError();
      }
   
      // catch failure caused by the DataSpace operations
      catch( const H5::DataSpaceIException& error )
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " caught H5::DataSpaceIException!" << std::endl;
         error.printError();
      }
   
      // catch failure caused by the DataSpace operations
      catch( const H5::DataTypeIException& error )
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " caught H5::DataTypeIException!" << std::endl;
         error.printError();
      }
      catch( ... )
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " caught unknown exception !" << std::endl;
      }
      
   } // Matches: if ( m_dataset )
   
} // End: ossimH5ImageDataset::getTileBuf