OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimHdf5ImageDataset.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: David Burken
8 //
9 // Description: OSSIM HDF5 Image DataSet.
10 //
11 //----------------------------------------------------------------------------
12 // $Id
13 
15 #include <ossim/base/ossimCommon.h>
16 #include <ossim/base/ossimEndian.h>
17 #include <ossim/base/ossimIpt.h>
18 #include <ossim/base/ossimIrect.h>
19 #include <ossim/base/ossimNotify.h>
22 
23 //---
24 // This includes everything! Note the H5 includes are order dependent; hence,
25 // the mongo include.
26 //---
27 #include <hdf5.h>
28 #include <H5Cpp.h>
29 
30 #include <iostream>
31 
33 : m_handler(owner),
34  m_dataset(0),
35  m_scalar(OSSIM_SCALAR_UNKNOWN),
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 }
46 
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 ),
56  m_validRect(obj.m_validRect)
57 {
58 }
59 
61 {
62  close();
63 }
64 
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 }
80 
81 bool ossimHdf5ImageDataset::initialize( const H5::DataSet& 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
96 
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 }
130 
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 }
400 
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 }
492 
494 {
495  m_dataset.close();
496  delete m_endian;
497 }
498 
499 const H5::DataSet* ossimHdf5ImageDataset::getDataset() const
500 {
501  return &m_dataset;
502 }
503 
505 {
506  return &m_dataset;
507 }
508 
510 {
511  return m_dataset.getObjName();
512 }
513 
515 {
516  return m_scalar;
517 }
518 
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 }
570 
572 {
573  return m_bands;
574 }
575 
577 {
578  return m_validRect.height();
579 }
580 
582 {
583  return m_validRect.width();
584 }
585 
587 {
588  return (m_endian ? true: false);
589 }
590 
592 {
593  return m_validRect.ul();
594 }
595 
597 {
598  return m_validRect;
599 }
600 
601 void ossimHdf5ImageDataset::getTileBuf(void* buffer, const ossimIrect& rect,
602  ossim_uint32 band, bool /* scale */)
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
778 
779 
781 {
782  if (band < m_maxValue.size())
783  return m_maxValue[band];
784 
785  return ossim::defaultMax(m_scalar);
786 }
787 
789 {
790  if (band < m_minValue.size())
791  return m_minValue[band];
792  return ossim::defaultMin(m_scalar);
793 }
794 
796 {
797  return (!m_minValue.empty());
798 }
799 
801 {
802  return (!m_maxValue.empty());
803 }
804 
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 }
827 
829 {
830  return obj.print( out );
831 }
832 
8 bit signed integer
bool initialize(const H5::DataSet &dataset)
Opens datasetName and initializes all data members on success.
ossim_uint32 x
const H5::DataSet * getDataset() const
Get const pointer to dataset.
ossimHdf5ImageDataset(ossimHdf5ImageHandler *owner=0)
default constructor
64 bit floating point
16 bit unsigned integer
ossim_uint32 y
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
bool determineExtents()
Returns true if datasets&#39;s endianness differs from this platform.
const ossimIrect & getValidImageRect() const
double getMinPixelValue(ossim_uint32 band=0) const
This is the base class for all imagery using HDF5 as the file format.
ossim_uint32 height() const
Definition: ossimIrect.h:487
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
std::ostream & print(std::ostream &out) const
print method.
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
signed char ossim_sint8
void close()
Calls H5::DataSet::close then deletes data set.
Class encapsulates a HDF5 Data set that can be loaded as an image.
ossimRefPtr< ossimHdf5 > m_hdf5
32 bit floating point
unsigned short ossim_uint16
ossimIrect m_validRect
H5 data can have null rows on the front or end.
32 bit unsigned integer
ossimRefPtr< ossimHdf5 > m_hdf5
double getMaxPixelValue(ossim_uint32 band=0) const
void set_ul(const ossimIpt &pt)
Definition: ossimIrect.h:589
double ossim_float64
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
OSSIM_DLL double defaultMin(ossimScalarType scalarType)
Definition: ossimCommon.cpp:73
static ossimByteOrder getByteOrder(const H5::AbstractDs *obj)
Definition: ossimHdf5.cpp:337
64 bit signed integer
signed short ossim_sint16
32 bit signed integer
unsigned int ossim_uint32
std::vector< ossim_float32 > m_maxValue
signed int ossim_sint32
std::ostream & operator<<(std::ostream &out, const ossimHdf5ImageDataset &obj)
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
ossim_uint32 getNumberOfSamples() const
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
OSSIM_DLL double defaultMax(ossimScalarType scalarType)
void set_lr(const ossimIpt &pt)
Definition: ossimIrect.h:623
const ossimHdf5ImageDataset & operator=(const ossimHdf5ImageDataset &rhs)
ossim_uint32 getNumberOfLines() const
64 bit unsigned integer
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
ossim_uint32 area() const
Definition: ossimIrect.h:396
const ossimIpt & getSubImageOffset() const
long long ossim_int64
ossimScalarType getScalarType() const
ossim_uint32 getNumberOfBands() 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)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32