OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ossimHdf5ImageDataset Class Reference

Class encapsulates a HDF5 Data set that can be loaded as an image. More...

#include <ossimHdf5ImageDataset.h>

Inheritance diagram for ossimHdf5ImageDataset:
ossimReferenced

Public Member Functions

 ossimHdf5ImageDataset (ossimHdf5ImageHandler *owner=0)
 default constructor More...
 
 ossimHdf5ImageDataset (const ossimHdf5ImageDataset &obj)
 copy constructor More...
 
 ~ossimHdf5ImageDataset ()
 destructor More...
 
void close ()
 Calls H5::DataSet::close then deletes data set. More...
 
const ossimHdf5ImageDatasetoperator= (const ossimHdf5ImageDataset &rhs)
 
bool initialize (const H5::DataSet &dataset)
 Opens datasetName and initializes all data members on success. More...
 
const H5::DataSet * getDataset () const
 Get const pointer to dataset. More...
 
H5::DataSet * getDataset ()
 Get pointer to dataset. More...
 
std::string getName () const
 
ossimScalarType getScalarType () const
 
ossim_uint32 getNumberOfBands () const
 
ossim_uint32 getNumberOfLines () const
 
ossim_uint32 getNumberOfSamples () const
 
bool getSwapFlag () const
 
const ossimIptgetSubImageOffset () const
 
const ossimIrectgetValidImageRect () const
 
double getMaxPixelValue (ossim_uint32 band=0) const
 
double getMinPixelValue (ossim_uint32 band=0) const
 
bool isMinPixelSet () const
 
bool isMaxPixelSet () const
 
void getTileBuf (void *buffer, const ossimIrect &rect, ossim_uint32 band, bool scale=true)
 Method to grab a tile(rectangle) from image. More...
 
std::ostream & print (std::ostream &out) const
 print method. More...
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Private Member Functions

bool determineExtents ()
 Returns true if datasets's endianness differs from this platform. More...
 
bool scanForValidImageRect ()
 
bool determineScalarType ()
 
bool scanForMinMax ()
 

Private Attributes

ossimRefPtr< ossimHdf5ImageHandlerm_handler
 
ossimRefPtr< ossimHdf5m_hdf5
 
H5::DataSet m_dataset
 
H5::DataSpace m_dataSpace
 
ossimScalarType m_scalar
 
ossim_uint32 m_bands
 
ossim_uint32 m_lines
 
ossim_uint32 m_samples
 
ossimEndianm_endian
 
std::vector< ossim_float32m_minValue
 
std::vector< ossim_float32m_maxValue
 
ossimIrect m_validRect
 H5 data can have null rows on the front or end. More...
 

Friends

OSSIMDLLEXPORT std::ostream & operator<< (std::ostream &out, const ossimHdf5ImageDataset &obj)
 

Additional Inherited Members

- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Detailed Description

Class encapsulates a HDF5 Data set that can be loaded as an image.

Definition at line 35 of file ossimHdf5ImageDataset.h.

Constructor & Destructor Documentation

◆ ossimHdf5ImageDataset() [1/2]

ossimHdf5ImageDataset::ossimHdf5ImageDataset ( ossimHdf5ImageHandler owner = 0)

default constructor

Definition at line 32 of file ossimHdf5ImageDataset.cpp.

References m_hdf5, ossimHdf5ImageHandler::m_hdf5, m_validRect, and ossimIrect::makeNan().

33 : m_handler(owner),
34  m_dataset(0),
36  m_bands(1),
37  m_lines(0),
38  m_samples(0),
39  m_endian(0)
40 {
41  if (owner)
42  m_hdf5 = owner->m_hdf5;
43 
45 }
ossimRefPtr< ossimHdf5 > m_hdf5
ossimIrect m_validRect
H5 data can have null rows on the front or end.
ossimRefPtr< ossimHdf5 > m_hdf5
void makeNan()
Definition: ossimIrect.h:329
ossimRefPtr< ossimHdf5ImageHandler > m_handler

◆ ossimHdf5ImageDataset() [2/2]

ossimHdf5ImageDataset::ossimHdf5ImageDataset ( const ossimHdf5ImageDataset obj)

copy constructor

Definition at line 47 of file ossimHdf5ImageDataset.cpp.

48 : m_handler(obj.m_handler),
49  m_hdf5 (obj.m_hdf5),
50  m_dataset(obj.m_dataset),
51  m_scalar(obj.m_scalar),
52  m_bands(obj.m_bands),
53  m_lines(obj.m_lines),
54  m_samples(obj.m_samples),
55  m_endian( obj.m_endian ? new ossimEndian() : 0 ),
57 {
58 }
ossimIrect m_validRect
H5 data can have null rows on the front or end.
ossimRefPtr< ossimHdf5 > m_hdf5
ossimRefPtr< ossimHdf5ImageHandler > m_handler

◆ ~ossimHdf5ImageDataset()

ossimHdf5ImageDataset::~ossimHdf5ImageDataset ( )

destructor

Definition at line 60 of file ossimHdf5ImageDataset.cpp.

References close().

61 {
62  close();
63 }
void close()
Calls H5::DataSet::close then deletes data set.

Member Function Documentation

◆ close()

void ossimHdf5ImageDataset::close ( )

Calls H5::DataSet::close then deletes data set.

Definition at line 493 of file ossimHdf5ImageDataset.cpp.

References m_dataset, and m_endian.

Referenced by initialize(), and ~ossimHdf5ImageDataset().

494 {
495  m_dataset.close();
496  delete m_endian;
497 }

◆ determineExtents()

bool ossimHdf5ImageDataset::determineExtents ( )
private

Returns true if datasets's endianness differs from this platform.

Definition at line 97 of file ossimHdf5ImageDataset.cpp.

References m_bands, m_dataset, m_lines, m_samples, m_validRect, ossimNotify(), and ossimNotifyLevel_WARN.

Referenced by initialize().

98 {
99  try
100  {
101  // Find the valid image rect. dataset may have null padding:
102  H5::DataSpace imageDataspace = m_dataset.getSpace();
103  int rank = imageDataspace.getSimpleExtentNdims();
104  if (rank < 2)
105  return false;
106 
107  // Get the extents. Assuming dimensions are same for lat lon dataset.
108  std::vector<hsize_t> inputSize(rank);
109  imageDataspace.getSimpleExtentDims( &inputSize.front(), 0 );
110  m_lines = inputSize[0];
111  m_samples = inputSize[1];
113  if ( rank >= 3 )
114  m_bands = inputSize[2];
115  else
116  m_bands = 1;
117 
118  if ( (m_lines == 0) || (m_samples == 0) )
119  return false;
120  }
121  catch( const H5::Exception& e )
122  {
123  std::cout << "ERROR:" << e.getDetailMsg()<< " \n";
124  ossimNotify(ossimNotifyLevel_WARN)<<e.getDetailMsg();
125  return false;
126  }
127 
128  return true;
129 }
ossimIrect m_validRect
H5 data can have null rows on the front or end.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ determineScalarType()

bool ossimHdf5ImageDataset::determineScalarType ( )
private

Definition at line 519 of file ossimHdf5ImageDataset.cpp.

References ossim::byteOrder(), ossimHdf5::getByteOrder(), m_dataset, m_endian, m_hdf5, m_scalar, OSSIM_FLOAT32, OSSIM_FLOAT64, OSSIM_SCALAR_UNKNOWN, OSSIM_SINT16, OSSIM_SINT32, OSSIM_SINT64, OSSIM_SINT8, OSSIM_UINT16, OSSIM_UINT32, OSSIM_UINT64, OSSIM_UINT8, ossimNotify(), and ossimNotifyLevel_WARN.

Referenced by initialize().

520 {
522 
523  try
524  {
525  H5T_class_t typeClass = m_dataset.getTypeClass();
526  if ( ( typeClass != H5T_INTEGER ) && ( typeClass != H5T_FLOAT ) )
527  return false;
528 
529  hid_t mem_type_id = H5Dget_type( m_dataset.getId() );
530  if( mem_type_id < 0 )
531  return false;
532 
533  hid_t native_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT);
534  if( H5Tequal(H5T_NATIVE_CHAR, native_type) )
536  else if ( H5Tequal( H5T_NATIVE_UCHAR, native_type) )
538  else if( H5Tequal( H5T_NATIVE_SHORT, native_type) )
540  else if(H5Tequal(H5T_NATIVE_USHORT, native_type))
542  else if(H5Tequal( H5T_NATIVE_INT, native_type))
544  else if(H5Tequal( H5T_NATIVE_UINT, native_type ) )
546  else if(H5Tequal( H5T_NATIVE_LONG, native_type))
548  else if(H5Tequal( H5T_NATIVE_ULONG, native_type))
550  else if(H5Tequal( H5T_NATIVE_LLONG, native_type))
552  else if(H5Tequal( H5T_NATIVE_ULLONG, native_type))
554  else if(H5Tequal( H5T_NATIVE_FLOAT, native_type))
556  else if(H5Tequal( H5T_NATIVE_DOUBLE, native_type))
558  // See if we need to swap bytes:
560  m_endian = new ossimEndian();
561  }
562  catch( const H5::Exception& e )
563  {
564  ossimNotify(ossimNotifyLevel_WARN)<<e.getDetailMsg();
565  return false;
566  }
567 
568  return true;
569 }
8 bit signed integer
64 bit floating point
16 bit unsigned integer
16 bit signed integer
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
32 bit floating point
32 bit unsigned integer
ossimRefPtr< ossimHdf5 > m_hdf5
static ossimByteOrder getByteOrder(const H5::AbstractDs *obj)
Definition: ossimHdf5.cpp:337
64 bit signed integer
32 bit signed integer
64 bit unsigned integer
8 bit unsigned integer
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getDataset() [1/2]

const H5::DataSet * ossimHdf5ImageDataset::getDataset ( ) const

Get const pointer to dataset.

This can be null if not open.

Returns
const pointer to dataset.

Definition at line 499 of file ossimHdf5ImageDataset.cpp.

References m_dataset.

500 {
501  return &m_dataset;
502 }

◆ getDataset() [2/2]

H5::DataSet * ossimHdf5ImageDataset::getDataset ( )

Get pointer to dataset.

This can be null if not open.

Returns
pointer to dataset.

Definition at line 504 of file ossimHdf5ImageDataset.cpp.

References m_dataset.

505 {
506  return &m_dataset;
507 }

◆ getMaxPixelValue()

double ossimHdf5ImageDataset::getMaxPixelValue ( ossim_uint32  band = 0) const

Definition at line 780 of file ossimHdf5ImageDataset.cpp.

References ossim::defaultMax(), m_maxValue, and m_scalar.

781 {
782  if (band < m_maxValue.size())
783  return m_maxValue[band];
784 
785  return ossim::defaultMax(m_scalar);
786 }
std::vector< ossim_float32 > m_maxValue
OSSIM_DLL double defaultMax(ossimScalarType scalarType)

◆ getMinPixelValue()

double ossimHdf5ImageDataset::getMinPixelValue ( ossim_uint32  band = 0) const

Definition at line 788 of file ossimHdf5ImageDataset.cpp.

References ossim::defaultMin(), m_minValue, and m_scalar.

789 {
790  if (band < m_minValue.size())
791  return m_minValue[band];
792  return ossim::defaultMin(m_scalar);
793 }
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
Definition: ossimCommon.cpp:73
std::vector< ossim_float32 > m_minValue

◆ getName()

string ossimHdf5ImageDataset::getName ( ) const
Returns
The dataset name. This is the full path used for open.

Definition at line 509 of file ossimHdf5ImageDataset.cpp.

References m_dataset.

510 {
511  return m_dataset.getObjName();
512 }

◆ getNumberOfBands()

ossim_uint32 ossimHdf5ImageDataset::getNumberOfBands ( ) const
Returns
the number of .

Definition at line 571 of file ossimHdf5ImageDataset.cpp.

References m_bands.

572 {
573  return m_bands;
574 }

◆ getNumberOfLines()

ossim_uint32 ossimHdf5ImageDataset::getNumberOfLines ( ) const
Returns
The number of lines.

Definition at line 576 of file ossimHdf5ImageDataset.cpp.

References ossimIrect::height(), and m_validRect.

577 {
578  return m_validRect.height();
579 }
ossim_uint32 height() const
Definition: ossimIrect.h:487
ossimIrect m_validRect
H5 data can have null rows on the front or end.

◆ getNumberOfSamples()

ossim_uint32 ossimHdf5ImageDataset::getNumberOfSamples ( ) const
Returns
The number of samples.

Definition at line 581 of file ossimHdf5ImageDataset.cpp.

References m_validRect, and ossimIrect::width().

582 {
583  return m_validRect.width();
584 }
ossimIrect m_validRect
H5 data can have null rows on the front or end.
ossim_uint32 width() const
Definition: ossimIrect.h:500

◆ getScalarType()

ossimScalarType ossimHdf5ImageDataset::getScalarType ( ) const
Returns
The output scalar type.

Definition at line 514 of file ossimHdf5ImageDataset.cpp.

References m_scalar.

Referenced by getTileBuf(), scanForMinMax(), and scanForValidImageRect().

515 {
516  return m_scalar;
517 }

◆ getSubImageOffset()

const ossimIpt & ossimHdf5ImageDataset::getSubImageOffset ( ) const

Definition at line 591 of file ossimHdf5ImageDataset.cpp.

References m_validRect, and ossimIrect::ul().

592 {
593  return m_validRect.ul();
594 }
const ossimIpt & ul() const
Definition: ossimIrect.h:274
ossimIrect m_validRect
H5 data can have null rows on the front or end.

◆ getSwapFlag()

bool ossimHdf5ImageDataset::getSwapFlag ( ) const
Returns
The swap flag.

Definition at line 586 of file ossimHdf5ImageDataset.cpp.

References m_endian.

587 {
588  return (m_endian ? true: false);
589 }

◆ getTileBuf()

void ossimHdf5ImageDataset::getTileBuf ( void *  buffer,
const ossimIrect rect,
ossim_uint32  band,
bool  scale = true 
)

Method to grab a tile(rectangle) from image.

Parameters
bufferBuffer for data for this method to copy data to. Should be the size of rect * bytes_per_pixel for scalar type.
rectThe zero based rectangle to grab. Rectangle is relative to any sub image offset. E.g. A request for 0,0 is the upper left corner of the valid image rect.
scaleIf true, uses min and max to stretch the data to a UINT16 range.

Definition at line 601 of file ossimHdf5ImageDataset.cpp.

References ossim::almostEqual(), ossimIrect::area(), ossimHdf5ImageHandler::getNullPixelValue(), getScalarType(), ossimIrect::height(), m_bands, m_dataset, m_endian, m_handler, m_maxValue, m_minValue, m_scalar, OSSIM_FLOAT32, OSSIM_FLOAT64, OSSIM_SINT16, OSSIM_SINT32, OSSIM_SINT8, OSSIM_UINT16, OSSIM_UINT32, OSSIM_UINT8, ossimNotify(), ossimNotifyLevel_WARN, ossimEndian::swap(), ossimIrect::ul(), ossimIrect::width(), ossimIpt::x, and ossimIpt::y.

Referenced by scanForMinMax().

603 {
604  static const char MODULE[] = "ossimHdf5ImageDataset::getTileBuf";
605 
606  if (band >= m_bands)
607  return;
608 
609  // Shift rectangle by the sub image offse (if any) from the m_validRect.
610  // NOTE: The rect coming in seems to be alreadyt in image space so no need to offset (OLK 09/2016)
611  ossimIrect irect = rect;// + m_validRect.ul();
612 
613  try
614  {
615  // Turn off the auto-printing when failure occurs so that we can
616  // handle the errors appropriately
617  // H5::Exception::dontPrint();
618 
619  // Get dataspace of the dataset.
620  H5::DataSpace imageDataSpace = m_dataset.getSpace();
621 
622  // Number of dimensions of the input dataspace.:
623  const ossim_int32 IN_DIM_COUNT = imageDataSpace.getSimpleExtentNdims();
624 
625  // Native type:
626  H5::DataType dataType = m_dataset.getDataType();
627 
628  std::vector<hsize_t> inputCount(IN_DIM_COUNT);
629  std::vector<hsize_t> inputOffset(IN_DIM_COUNT);
630 
631  if ( IN_DIM_COUNT == 2 )
632  {
633  inputOffset[0] = irect.ul().y;
634  inputOffset[1] = irect.ul().x;
635 
636  inputCount[0] = irect.height();
637  inputCount[1] = irect.width();
638  }
639  else
640  {
641  inputOffset[0] = band;
642  inputOffset[1] = irect.ul().y;
643  inputOffset[2] = irect.ul().x;
644 
645  inputCount[0] = 1;
646  inputCount[1] = irect.height();
647  inputCount[2] = irect.width();
648  }
649 
650  // Define hyperslab in the dataset; implicitly giving strike strike and block NULL.
651  imageDataSpace.selectHyperslab( H5S_SELECT_SET,
652  &inputCount.front(),
653  &inputOffset.front() );
654 
655  // Output dataspace dimensions.
656  const ossim_int32 OUT_DIM_COUNT = 3;
657  std::vector<hsize_t> outputCount(OUT_DIM_COUNT);
658  outputCount[0] = 1; // single band
659  outputCount[1] = irect.height(); // lines
660  outputCount[2] = irect.width(); // samples
661 
662  // Output dataspace offset.
663  std::vector<hsize_t> outputOffset(OUT_DIM_COUNT);
664  outputOffset[0] = band;
665  outputOffset[1] = 0;
666  outputOffset[2] = 0;
667 
668  // Output dataspace.
669  H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front());
670  bufferDataSpace.selectHyperslab( H5S_SELECT_SET,
671  &outputCount.front(),
672  &outputOffset.front() );
673 
674  // Read data from file into the buffer.
675  m_dataset.read( buffer, dataType, bufferDataSpace, imageDataSpace );
676 
677  if ( m_endian )
678  {
679  // If the m_endian pointer is initialized(not zero) swap the bytes.
680  m_endian->swap( m_scalar, buffer, irect.area() );
681  }
682 
683 
684  //#define NEVER
685 #ifdef NEVER
686  if (scale)
687  {
688  const ossim_float32 TOLERANCE = 0.1e-9; // For ossim::almostEqual()
689  // Scale the data:
690 #if 1
691  // Assumes float32 datatype:
692  double gain = 1.0/( m_maxValue[band] - m_minValue[band] );
693  ossim_float32 null_value = m_handler->getNullPixelValue(band);
694  ossim_float32 value;
695  for (ossim_uint32 i=0; i<irect.area(); ++i)
696  {
697  value = ((ossim_float32*)buffer)[i];
698 
699  if (!ossim::almostEqual(value,null_value, TOLERANCE))
700  {
701  value = gain*(value - m_minValue[band]);
702  ((ossim_float32*)buffer)[i] =value;
703  }
704  }
705 #else
706  // Does not assume float32:
707  ossimScalarType scalarType = getScalarType();
708  double null_value = m_handler->getNullPixelValue(band);
709  for (ossim_uint32 i=0; i<irect.area(); ++i)
710  {
711  switch (scalarType)
712  {
713  case OSSIM_FLOAT32:
714  if (!ossim::almostEqual(((ossim_float32*)buffer)[i], (ossim_float32)null_value))
715  ((ossim_float32*)buffer)[i] =
716  (ossim_float32)(gain*(((ossim_float32*)buffer)[i] - m_minValue[band]));
717  break;
718  case OSSIM_FLOAT64:
719  if (!ossim::almostEqual(((ossim_float64*)buffer)[i], null_value))
720  ((ossim_float64*)buffer)[i] =
721  (ossim_float64)(gain*(((ossim_float64*)buffer)[i] - m_minValue[band]));
722  break;
723  case OSSIM_UINT8:
724  if (((ossim_uint8*)buffer)[i] != (ossim_uint8)null_value)
725  ((ossim_uint8*)buffer)[i] =
726  (ossim_uint8)(gain*(((ossim_uint8*)buffer)[i] - m_minValue[band]));
727  break;
728  case OSSIM_SINT8:
729  if (((ossim_sint8*)buffer)[i] != (ossim_sint8)null_value)
730  ((ossim_sint8*)buffer)[i] =
731  (ossim_sint8)(gain*(((ossim_sint8*)buffer)[i] - m_minValue[band]));
732  break;
733  case OSSIM_UINT16:
734  if (((ossim_uint16*)buffer)[i] != (ossim_uint16)null_value)
735  ((ossim_uint16*)buffer)[i] =
736  (ossim_uint16)(gain*(((ossim_uint16*)buffer)[i] - m_minValue[band]));
737  break;
738  case OSSIM_SINT16:
739  if (((ossim_sint16*)buffer)[i] != (ossim_sint16)null_value)
740  ((ossim_sint16*)buffer)[i] =
741  (ossim_sint16)(gain*(((ossim_sint16*)buffer)[i] - m_minValue[band]));
742  break;
743  case OSSIM_UINT32:
744  if (((ossim_uint32*)buffer)[i] != (ossim_uint32)null_value)
745  ((ossim_uint32*)buffer)[i] =
746  (ossim_uint32)(gain*(((ossim_uint32*)buffer)[i] - m_minValue[band]));
747  break;
748  case OSSIM_SINT32:
749  if (((ossim_sint32*)buffer)[i] != (ossim_sint32)null_value)
750  ((ossim_sint32*)buffer)[i] =
751  (ossim_sint32)(gain*(((ossim_sint32*)buffer)[i] - m_minValue[band]));
752  break;
753  default:
754  break;
755  }
756  }
757 #endif
758  }
759 #endif
760 
761  // Cleanup:
762  bufferDataSpace.close();
763  dataType.close();
764  imageDataSpace.close();
765  }
766  catch( const H5::Exception& error )
767  {
768  ossimNotify(ossimNotifyLevel_WARN) << MODULE << " caught H5 Exception!" << std::endl;
769  error.printError();
770  }
771 
772  catch( ... )
773  {
774  ossimNotify(ossimNotifyLevel_WARN)<< MODULE << " caught unknown exception !" << std::endl;
775  }
776 
777 } // End: ossimH5ImageDataset::getTileBuf
8 bit signed integer
64 bit floating point
16 bit unsigned integer
float ossim_float32
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
ossim_uint32 height() const
Definition: ossimIrect.h:487
16 bit signed integer
const ossimIpt & ul() const
Definition: ossimIrect.h:274
signed char ossim_sint8
32 bit floating point
unsigned short ossim_uint16
32 bit unsigned integer
double ossim_float64
signed short ossim_sint16
32 bit signed integer
unsigned int ossim_uint32
std::vector< ossim_float32 > m_maxValue
signed int ossim_sint32
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimScalarType
ossim_int32 y
Definition: ossimIpt.h:142
ossim_uint32 area() const
Definition: ossimIrect.h:396
ossimScalarType getScalarType() const
ossim_int32 x
Definition: ossimIpt.h:141
std::vector< ossim_float32 > m_minValue
8 bit unsigned integer
virtual double getNullPixelValue(ossim_uint32 band=0) const
ossimRefPtr< ossimHdf5ImageHandler > m_handler
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

◆ getValidImageRect()

const ossimIrect & ossimHdf5ImageDataset::getValidImageRect ( ) const

Definition at line 596 of file ossimHdf5ImageDataset.cpp.

References m_validRect.

597 {
598  return m_validRect;
599 }
ossimIrect m_validRect
H5 data can have null rows on the front or end.

◆ initialize()

bool ossimHdf5ImageDataset::initialize ( const H5::DataSet &  dataset)

Opens datasetName and initializes all data members on success.

Returns
true on success, false on error.

Definition at line 81 of file ossimHdf5ImageDataset.cpp.

References close(), determineExtents(), determineScalarType(), and m_dataset.

82 {
83  close();
84 
85  m_dataset = dataset;
86 
88 
89 // if (!determineExtents() || !scanForValidImageRect() || !scanForMinMax())
90  if (!determineExtents())// || !scanForMinMax())
91  return false;
92 
93  return true;
94 
95 } // End: ossimH5ImageDataset::initialize
bool determineExtents()
Returns true if datasets&#39;s endianness differs from this platform.
void close()
Calls H5::DataSet::close then deletes data set.

◆ isMaxPixelSet()

bool ossimHdf5ImageDataset::isMaxPixelSet ( ) const

Definition at line 800 of file ossimHdf5ImageDataset.cpp.

References m_maxValue.

801 {
802  return (!m_maxValue.empty());
803 }
std::vector< ossim_float32 > m_maxValue

◆ isMinPixelSet()

bool ossimHdf5ImageDataset::isMinPixelSet ( ) const

Definition at line 795 of file ossimHdf5ImageDataset.cpp.

References m_minValue.

796 {
797  return (!m_minValue.empty());
798 }
std::vector< ossim_float32 > m_minValue

◆ operator=()

const ossimHdf5ImageDataset & ossimHdf5ImageDataset::operator= ( const ossimHdf5ImageDataset rhs)

Definition at line 65 of file ossimHdf5ImageDataset.cpp.

References m_bands, m_dataset, m_dataSpace, m_endian, m_lines, m_samples, m_scalar, and m_validRect.

66 {
67  if ( this != &rhs )
68  {
69  m_dataset = rhs.m_dataset;
71  m_scalar = rhs.m_scalar;
72  m_bands = rhs.m_bands;
73  m_lines = rhs.m_lines;
74  m_samples = rhs.m_samples;
76  m_endian = ( rhs.m_endian ? new ossimEndian() : 0 );
77  }
78  return *this;
79 }
ossimIrect m_validRect
H5 data can have null rows on the front or end.

◆ print()

std::ostream & ossimHdf5ImageDataset::print ( std::ostream &  out) const

print method.

Returns
std::ostream&

Definition at line 805 of file ossimHdf5ImageDataset.cpp.

References ossimLookUpTable::getEntryString(), ossimScalarTypeLut::instance(), m_bands, m_dataset, m_endian, m_lines, m_samples, m_scalar, m_validRect, ossimNotify(), and ossimNotifyLevel_WARN.

Referenced by operator<<().

806 {
807  try
808  {
809  out << "ossimH5ImageDataset: "
810  << "\nH5::DataSet::id: " << m_dataset.getId()
811  << "\nname: " << m_dataset.getObjName()
812  << "\nscalar: " << ossimScalarTypeLut::instance()->getEntryString( m_scalar )
813  << "\nbands: " << m_bands
814  << "\nlines: " << m_lines
815  << "\nsamples: " << m_samples
816  << "\nvalid rect: " << m_validRect
817  << "\nswap_flage: " << (m_endian?"true":"false")
818  << std::endl;
819  }
820  catch( const H5::Exception& e )
821  {
822  ossimNotify(ossimNotifyLevel_WARN)<<e.getDetailMsg();
823  }
824 
825  return out;
826 }
virtual ossimString getEntryString(ossim_int32 entry_number) const
ossimIrect m_validRect
H5 data can have null rows on the front or end.
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ scanForMinMax()

bool ossimHdf5ImageDataset::scanForMinMax ( )
private

Definition at line 401 of file ossimHdf5ImageDataset.cpp.

References ossimHdf5ImageHandler::getNullPixelValue(), getScalarType(), getTileBuf(), ossimIrect::lr(), m_bands, m_handler, m_maxValue, m_minValue, m_validRect, OSSIM_DEFAULT_MAX_PIX_FLOAT, OSSIM_DEFAULT_MIN_PIX_FLOAT, OSSIM_FLOAT32, OSSIM_FLOAT64, OSSIM_SCALAR_UNKNOWN, OSSIM_SINT16, OSSIM_SINT32, OSSIM_SINT64, OSSIM_SINT8, OSSIM_UINT16, OSSIM_UINT32, OSSIM_UINT64, OSSIM_UINT8, ossim::scalarSizeInBytes(), ossimIrect::ul(), ossimIrect::ur(), ossimIrect::width(), x, and y.

402 {
403  // Create buffer to hold the clip rect for a single band.
404  ossimScalarType scalarType = getScalarType();
405 
406  if((scalarType == OSSIM_SCALAR_UNKNOWN)||
407  (scalarType == OSSIM_UINT64) ||
408  (scalarType == OSSIM_SINT64)
409  )
410  {
411  return false;
412  }
413  // if ((scalarType != OSSIM_FLOAT32) && (scalarType != OSSIM_FLOAT64) &&
414  // (scalarType != OSSIM_UINT32) && (scalarType != OSSIM_SINT32) &&
415  // (scalarType != OSSIM_UINT8) && (scalarType != OSSIM_SINT8) &&
416  // (scalarType != OSSIM_UINT16) && (scalarType != OSSIM_SINT16))
417  // {
418  // return false;
419  // }
420 
421  ossim_uint32 bufSizeInBytes = m_validRect.width()*ossim::scalarSizeInBytes(scalarType);
422  vector<char> dataBuffer(bufSizeInBytes);
423 
424  // Get the extents. Assuming dimensions are same for lat lon dataset.
425  ossimIpt ulIpt (m_validRect.ul());
426  ossimIpt lrIpt (m_validRect.lr());
427  const ossim_float32 nullpix = m_handler->getNullPixelValue();
428  ossim_float32 epsilon = (ossim_float32)0.1e-9; // For ossim::almostEqual()
429 
430  if (nullpix == 0.0)
431  epsilon = 0;
432 
433  m_minValue.clear();
434  m_maxValue.clear();
435 
436  ossimIrect clipRect (m_validRect.ul(), m_validRect.ur());
437  for (ossim_uint32 band=0; band<m_bands; ++band)
438  {
441 
442  for (int y=ulIpt.y; y<=lrIpt.y; y++)
443  {
444  clipRect.set_uly(y);
445  clipRect.set_lry(y);
446 
447  getTileBuf(&dataBuffer.front(), clipRect, band, false);
448 
449  // Scan and fix non-standard null value:
450  ossim_float32 value = 0;
451  for ( ossim_uint32 x=0; x<m_validRect.width(); ++x )
452  {
453  switch (scalarType)
454  {
455  case OSSIM_FLOAT32:
456  value = ((ossim_float32*)&dataBuffer.front())[x];
457  break;
458  case OSSIM_FLOAT64:
459  value = (ossim_float32) ((ossim_float64*)&dataBuffer.front())[x];
460  break;
461  case OSSIM_UINT8:
462  case OSSIM_SINT8:
463  value = (ossim_float32) ((char*)&dataBuffer.front())[x];
464  break;
465  case OSSIM_UINT16:
466  case OSSIM_SINT16:
467  value = (ossim_float32) ((ossim_int16*)&dataBuffer.front())[x];
468  break;
469  case OSSIM_UINT32:
470  case OSSIM_SINT32:
471  value = (ossim_float32) ((ossim_int32*)&dataBuffer.front())[x];
472  break;
473  default:
474  break;
475  }
476 
477  if (ossim::almostEqual<ossim_float32>(value, nullpix, epsilon))
478  continue;
479  if (value > m_maxValue[band])
480  m_maxValue[band] = value;
481  if (value < m_minValue[band])
482  m_minValue[band] = value;
483  }
484  }
485  }
486 
487  //cout<<"ossimHdf5ImageDataset:"<<__LINE__<<"\n\tminValue="<<m_minValue[0]<<
488  // "\n\tmaxValue="<<m_maxValue[0]<<"\n\tnullValue="<<m_handler->getNullPixelValue()<<endl; // TODO REMOVE
489 
490  return true;
491 }
8 bit signed integer
ossim_uint32 x
64 bit floating point
16 bit unsigned integer
ossim_uint32 y
float ossim_float32
void getTileBuf(void *buffer, const ossimIrect &rect, ossim_uint32 band, bool scale=true)
Method to grab a tile(rectangle) from image.
16 bit signed integer
const ossimIpt & ul() const
Definition: ossimIrect.h:274
32 bit floating point
ossimIrect m_validRect
H5 data can have null rows on the front or end.
32 bit unsigned integer
double ossim_float64
64 bit signed integer
32 bit signed integer
unsigned int ossim_uint32
std::vector< ossim_float32 > m_maxValue
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
const ossimIpt & lr() const
Definition: ossimIrect.h:276
ossim_uint32 width() const
Definition: ossimIrect.h:500
const ossimIpt & ur() const
Definition: ossimIrect.h:275
ossimScalarType
#define OSSIM_DEFAULT_MAX_PIX_FLOAT
short ossim_int16
#define OSSIM_DEFAULT_MIN_PIX_FLOAT
64 bit unsigned integer
ossimScalarType getScalarType() const
std::vector< ossim_float32 > m_minValue
8 bit unsigned integer
virtual double getNullPixelValue(ossim_uint32 band=0) const
ossimRefPtr< ossimHdf5ImageHandler > m_handler
int ossim_int32

◆ scanForValidImageRect()

bool ossimHdf5ImageDataset::scanForValidImageRect ( )
private

Definition at line 131 of file ossimHdf5ImageDataset.cpp.

References ossim::almostEqual(), ossimLookUpTable::getEntryString(), getScalarType(), ossimScalarTypeLut::instance(), ossimIrect::lr(), m_dataset, m_endian, m_lines, m_samples, m_validRect, OSSIM_FLOAT32, ossimNotify(), ossimNotifyLevel_WARN, ossimIrect::set_lr(), ossimIrect::set_ul(), ossimEndian::swap(), ossimIrect::ul(), ossimIrect::width(), ossimIpt::x, and ossimIpt::y.

132 {
133 #if 0
134  // THIS IS ORIGINAL BURKEN CODE -- SEEMS TO SCAN TOO MUCH BUT MAYBE NEEDED IN POLAR PROJECTION
135  // CASES SO KEEPING AROUND (OLK 09/2016)
136  bool result = false;
137  H5::DataSpace imageDataspace = m_dataset.getSpace();
138  const ossim_int32 IN_DIM_COUNT = imageDataspace.getSimpleExtentNdims();
139 
140  if ( IN_DIM_COUNT == 2 )
141  {
142  // Get the extents. Assuming dimensions are same for lat lon dataset.
143  std::vector<hsize_t> dimsOut(IN_DIM_COUNT);
144  imageDataspace.getSimpleExtentDims( &dimsOut.front(), 0 );
145 
146  if ( dimsOut[0] && dimsOut[1] )
147  {
148 
149  //---
150  // Capture the rectangle:
151  // dimsOut[0] is height, dimsOut[1] is width:
152  //---
153  m_validRect = ossimIrect( 0, 0,
154  static_cast<ossim_int32>( dimsOut[1]-1 ),
155  static_cast<ossim_int32>( dimsOut[0]-1 ) );
156 
157  const ossim_int32 WIDTH = m_validRect.width();
158 
159  std::vector<hsize_t> inputCount(IN_DIM_COUNT);
160  std::vector<hsize_t> inputOffset(IN_DIM_COUNT);
161 
162  inputOffset[0] = 0;
163  inputOffset[1] = 0;
164 
165  inputCount[0] = 1;
166  inputCount[1] = WIDTH;
167 
168  // Output dataspace dimensions.
169  const ossim_int32 OUT_DIM_COUNT = 3;
170  std::vector<hsize_t> outputCount(OUT_DIM_COUNT);
171  outputCount[0] = 1; // single band
172  outputCount[1] = 1; // single line
173  outputCount[2] = WIDTH; // whole line
174 
175  // Output dataspace offset.
176  std::vector<hsize_t> outputOffset(OUT_DIM_COUNT);
177  outputOffset[0] = 0;
178  outputOffset[1] = 0;
179  outputOffset[2] = 0;
180 
181  ossimScalarType scalar = getScalarType();
182  if ( scalar == OSSIM_FLOAT32 )
183  {
184  // Native type:
185  H5::DataType datatype = m_dataset.getDataType();
186 
187  // Output dataspace always the same one line.
188  H5::DataSpace bufferDataSpace( OUT_DIM_COUNT, &outputCount.front());
189  bufferDataSpace.selectHyperslab( H5S_SELECT_SET,
190  &outputCount.front(),
191  &outputOffset.front() );
192 
193  //---
194  // Dataset sample has NULL lines at the end so scan for valid rect.
195  // Use "<= -999" for test as per NOAA as it seems the NULL value is
196  // fuzzy. e.g. -999.3.
197  //---
198  const ossim_float32 NULL_VALUE = -999.0;
199 
200  //---
201  // VIIRS Radiance data has a -1.5e-9 in the first column.
202  // Treat this as a null.
203  //---
204  ossimString name = m_dataset.getObjName();
205  const ossim_float32 NULL_VALUE2 = ( name == "/All_Data/VIIRS-DNB-SDR_All/Radiance" )
206  ? -1.5e-9 : NULL_VALUE;
207  const ossim_float32 TOLERANCE = 0.1e-9; // For ossim::almostEqual()
208 
209  // Hold one line:
210  std::vector<ossim_float32> values( WIDTH );
211 
212  // Find the ul pixel:
213  ossimIpt ulIpt = m_validRect.ul();
214  bool found = false;
215 
216  // Line loop to find upper left pixel:
217  while ( ulIpt.y <= m_validRect.lr().y )
218  {
219  inputOffset[0] = static_cast<hsize_t>(ulIpt.y);
220  imageDataspace.selectHyperslab( H5S_SELECT_SET,
221  &inputCount.front(),
222  &inputOffset.front() );
223 
224  // Read data from file into the buffer.
225  m_dataset.read( (void*)&values.front(), datatype, bufferDataSpace, imageDataspace );
226 
227  if ( m_endian )
228  {
229  // If the endian pointer is initialized(not zero) swap the bytes.
230  m_endian->swap( scalar, (void*)&values.front(), WIDTH );
231  }
232 
233  // Sample loop:
234  ulIpt.x = m_validRect.ul().x;
235  ossim_int32 index = 0;
236  while ( ulIpt.x <= m_validRect.lr().x )
237  {
238  if ( !ossim::almostEqual(values[index], NULL_VALUE2, TOLERANCE) &&
239  ( values[index] > NULL_VALUE ) )
240  {
241  found = true; // Found valid pixel.
242  break;
243  }
244  ++ulIpt.x;
245  ++index;
246 
247  } // End: sample loop
248 
249  if ( found )
250  {
251  break;
252  }
253 
254  ++ulIpt.y;
255 
256  } // End line loop to find ul pixel:
257 
258  // Find the lower right pixel:
259  ossimIpt lrIpt = m_validRect.lr();
260  found = false;
261 
262  // Line loop to find last pixel:
263  while ( lrIpt.y >= m_validRect.ul().y )
264  {
265  inputOffset[0] = static_cast<hsize_t>(lrIpt.y);
266  imageDataspace.selectHyperslab( H5S_SELECT_SET,
267  &inputCount.front(),
268  &inputOffset.front() );
269 
270  // Read data from file into the buffer.
271  m_dataset.read( (void*)&values.front(), datatype, bufferDataSpace, imageDataspace );
272 
273  if ( m_endian )
274  {
275  // If the endian pointer is initialized(not zero) swap the bytes.
276  m_endian->swap( scalar, (void*)&values.front(), WIDTH );
277  }
278 
279  // Sample loop:
280  lrIpt.x = m_validRect.lr().x;
281  ossim_int32 index = WIDTH-1;
282 
283  while ( lrIpt.x >= m_validRect.ul().x )
284  {
285  if ( !ossim::almostEqual(values[index], NULL_VALUE2, TOLERANCE) &&
286  ( values[index] > NULL_VALUE ) )
287  {
288  found = true; // Found valid pixel.
289  break;
290  }
291  --lrIpt.x;
292  --index;
293 
294  } // End: sample loop
295 
296  if ( found )
297  {
298  break;
299  }
300 
301  --lrIpt.y;
302 
303  } // End line loop to find lower right pixel.
304 
305  m_validRect = ossimIrect( ulIpt, lrIpt );
306  result = true;
307 
308  }
309  else // Matches: if ( scalar == OSSIM_FLOAT32 ){...}
310  {
312  << "ossimHdf5ImageDataset:"<<__LINE__<<" WARNING!"
313  << "\nUnhandled scalar type: "
315  << std::endl;
316  }
317 
318  } // Matches: if ( dimsOut...
319 
320  } // Matches: if ( IN_DIM_COUNT == 2 )
321 
322  //cout << "ossimHdf5ImageDataset:"<<__LINE__<<" m_validRect = "<<m_validRect<<endl;
323  return true;
324 
325 #else
326  // REFACTORED
327  try
328  {
329  // Find the valid image rect. dataset may have null padding:
330  H5::DataSpace imageDataspace = m_dataset.getSpace();
331  H5::DataType dataType = m_dataset.getDataType();
332  ossim_uint32 elem_size = (ossim_uint32)dataType.getSize();
333 
334  // Get the extents. Assuming dimensions are same for lat lon dataset.
335  hsize_t rowSize[2] = { 1, m_samples };
336  hsize_t imageOffset[2] = { 0, 0 };
337 
338  // Allocate space for read buffer:
339  char *rowBuf = new char[elem_size*m_samples];
340  char *fill_value = new char[elem_size];
341 
342  // Output dataspace always the same one line.
343  H5::DataSpace bufferDataSpace( 2, rowSize);
344  bufferDataSpace.selectHyperslab( H5S_SELECT_SET, rowSize, imageOffset ); // offset = (0,0) here
345 
346  // Figure out the null pixel value (unswapped since doing byte compare below):
347  H5Pget_fill_value(m_dataset.getId(), dataType.getId(), fill_value);
348 
349  // Find the ul pixel. Loop over rows:
350  ossimIpt ulIpt (0,0);
351  bool found_valid = false;
352  for (; (ulIpt.y<(int)m_lines) && !found_valid; ulIpt.y++)
353  {
354  imageOffset[0] = ulIpt.y;
355  imageDataspace.selectHyperslab( H5S_SELECT_SET, rowSize, imageOffset);
356  m_dataset.read(rowBuf, dataType, bufferDataSpace, imageDataspace );
357 
358  // Scan row for valid pixel:
359  ossim_int64 rowOffset = 0;
360  for (ulIpt.x=0; (ulIpt.x<(int)m_samples) && !found_valid; ulIpt.x++, rowOffset+=elem_size)
361  found_valid = (memcmp(&rowBuf[rowOffset], fill_value, elem_size) != 0);
362  }
363  if (!found_valid)
364  ulIpt = ossimIpt(0,0);
365 
366  // Find the lr pixel. Loop over rows:
367  ossimIpt lrIpt (m_samples-1, m_lines-1);
368  found_valid = false;
369  for (; (lrIpt.y>ulIpt.y) && !found_valid; lrIpt.y--)
370  {
371  imageOffset[0] = lrIpt.y;
372  imageDataspace.selectHyperslab( H5S_SELECT_SET, rowSize, imageOffset);
373  m_dataset.read(rowBuf, dataType, bufferDataSpace, imageDataspace );
374 
375  // Scan row for valid pixel:
376  ossim_int64 rowOffset = m_samples*elem_size - 1;
377  for (lrIpt.x=m_samples-1; (lrIpt.x>ulIpt.x) && !found_valid; lrIpt.x-- , rowOffset-=elem_size)
378  found_valid = (memcmp(&rowBuf[rowOffset], fill_value, elem_size) != 0);
379  }
380  if (!found_valid)
381  lrIpt = ossimIpt (m_samples-1, m_lines-1);
382 
383  m_validRect.set_ul(ulIpt);
384  m_validRect.set_lr(lrIpt);
385 
386  imageDataspace.close();
387 
388  delete [] rowBuf;
389  delete [] fill_value;
390  return true;
391  }
392  catch( const H5::Exception& e )
393  {
394  ossimNotify(ossimNotifyLevel_WARN)<<e.getDetailMsg();
395  return false;
396  }
397 
398 #endif
399 }
float ossim_float32
virtual ossimString getEntryString(ossim_int32 entry_number) const
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
const ossimIpt & ul() const
Definition: ossimIrect.h:274
32 bit floating point
ossimIrect m_validRect
H5 data can have null rows on the front or end.
void set_ul(const ossimIpt &pt)
Definition: ossimIrect.h:589
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
unsigned int ossim_uint32
const ossimIpt & lr() const
Definition: ossimIrect.h:276
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimScalarType
void set_lr(const ossimIpt &pt)
Definition: ossimIrect.h:623
ossim_int32 y
Definition: ossimIpt.h:142
long long ossim_int64
ossimScalarType getScalarType() const
ossim_int32 x
Definition: ossimIpt.h:141
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
int ossim_int32

Friends And Related Function Documentation

◆ operator<<

OSSIMDLLEXPORT std::ostream& operator<< ( std::ostream &  out,
const ossimHdf5ImageDataset obj 
)
friend

Definition at line 828 of file ossimHdf5ImageDataset.cpp.

829 {
830  return obj.print( out );
831 }
std::ostream & print(std::ostream &out) const
print method.

Member Data Documentation

◆ m_bands

ossim_uint32 ossimHdf5ImageDataset::m_bands
private

◆ m_dataset

H5::DataSet ossimHdf5ImageDataset::m_dataset
private

◆ m_dataSpace

H5::DataSpace ossimHdf5ImageDataset::m_dataSpace
private

Definition at line 137 of file ossimHdf5ImageDataset.h.

Referenced by operator=().

◆ m_endian

ossimEndian* ossimHdf5ImageDataset::m_endian
private

◆ m_handler

ossimRefPtr<ossimHdf5ImageHandler> ossimHdf5ImageDataset::m_handler
private

Definition at line 134 of file ossimHdf5ImageDataset.h.

Referenced by getTileBuf(), and scanForMinMax().

◆ m_hdf5

ossimRefPtr<ossimHdf5> ossimHdf5ImageDataset::m_hdf5
private

Definition at line 135 of file ossimHdf5ImageDataset.h.

Referenced by determineScalarType(), and ossimHdf5ImageDataset().

◆ m_lines

ossim_uint32 ossimHdf5ImageDataset::m_lines
private

Definition at line 140 of file ossimHdf5ImageDataset.h.

Referenced by determineExtents(), operator=(), print(), and scanForValidImageRect().

◆ m_maxValue

std::vector<ossim_float32> ossimHdf5ImageDataset::m_maxValue
private

◆ m_minValue

std::vector<ossim_float32> ossimHdf5ImageDataset::m_minValue
private

◆ m_samples

ossim_uint32 ossimHdf5ImageDataset::m_samples
private

Definition at line 141 of file ossimHdf5ImageDataset.h.

Referenced by determineExtents(), operator=(), print(), and scanForValidImageRect().

◆ m_scalar

ossimScalarType ossimHdf5ImageDataset::m_scalar
private

◆ m_validRect

ossimIrect ossimHdf5ImageDataset::m_validRect
private

H5 data can have null rows on the front or end.

The valid rect is the scanned rectangle disregarding leading or trailing nulls. This doesn't handle nulls in the middle of image.

Definition at line 149 of file ossimHdf5ImageDataset.h.

Referenced by determineExtents(), getNumberOfLines(), getNumberOfSamples(), getSubImageOffset(), getValidImageRect(), operator=(), ossimHdf5ImageDataset(), print(), scanForMinMax(), and scanForValidImageRect().


The documentation for this class was generated from the following files: