Skip to content

Commit

Permalink
Created hdf5 directory directly under src, and improved the HDF5 impl…
Browse files Browse the repository at this point in the history
…ementation. File parsing is working. Initial commit of modified coarse grid model is untested.
  • Loading branch information
oscarkramer committed Aug 9, 2016
1 parent f8910e6 commit 7eb18f8
Show file tree
Hide file tree
Showing 23 changed files with 2,771 additions and 99 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ else ( ZLIB_FOUND )
message( WARNING "Could not find optional zlib package!" )
endif ( ZLIB_FOUND )

# HDF5 - Optional
set( OSSIM_HAS_HDF5 0 )
if (BUILD_OSSIM_HDF5_SUPPORT)
message( STATUS "Native HDF5 support requested. Searching for HDF5 library..." )
find_package( HDF5 )
if ( HDF5_FOUND )
include_directories( ${HDF5_INCLUDE_DIR} )
set( ossimDependentLibs ${ossimDependentLibs} ${HDF5_LIBRARIES} )
set( OSSIM_HAS_HDF5 1 )
else ( HDF5_FOUND )
message( WARNING "Could not find optional HDF5 package. Excluding native support." )
endif ( HDF5_FOUND )
endif (BUILD_OSSIM_HDF5_SUPPORT)

#---
# Call the OSSIM macros in OssimUtilities.cmake
#---
Expand Down
75 changes: 75 additions & 0 deletions cmake/CMakeModules/FindHDF5.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#---
# File: FindHDF5.cmake
#
# Find the native HDF5 includes and libraries.
#
# This module defines:
#
# HDF5_INCLUDE_DIR, where to find geos.h, etc.
# HDF5_LIBRARIES, libraries to link against to use HDF5.
# HDF5_FOUND, True if found, false if one of the above are not found.
#
# NOTE:
#
# This script is specialized for ossim. HDF5 rpm created to fix conflict with
# system installed hdf5 packages that do NOT have compression(szip) support.
#
# $Id$
#---

# Find include path:
find_path( HDF5_INCLUDE_DIR hdf5.h
PATHS
$ENV{HDF5_DIR}/include
/usr/include
/usr/local/include
/usr/local/ossim/include )

# Find HDF5 library:
find_library( HDF5_LIB NAMES hdf5
PATHS
$ENV{HDF5_DIR}/lib64
$ENV{HDF5_DIR}/lib
/usr/lib64
/usr/lib
/usr/local/lib
/usr/local/ossim/lib )

# Find HDF5 CPP library:
find_library( HDF5_CPP_LIB NAMES hdf5_cpp
PATHS
$ENV{HDF5_DIR}/lib64
$ENV{HDF5_DIR}/lib
/usr/lib64
/usr/lib
/usr/local/lib
/usr/local/ossim/lib )

# Set the HDF5_LIBRARIES:
if( HDF5_LIB AND HDF5_CPP_LIB )
set( HDF5_LIBRARIES ${HDF5_LIB} ${HDF5_CPP_LIB} CACHE STRING INTERNAL )
endif(HDF5_LIB AND HDF5_CPP_LIB )

#---
# This function sets HDF5_FOUND if variables are valid.
#---
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args( HDF5 DEFAULT_MSG
HDF5_LIBRARIES
HDF5_INCLUDE_DIR )

if( HDF5_FOUND )
if( NOT HDF5_FIND_QUIETLY )
message( STATUS "Found HDF5..." )
endif( NOT HDF5_FIND_QUIETLY )
else( HDF5_FOUND )
if( NOT HDF5_FIND_QUIETLY )
message( WARNING "Could not find HDF5" )
endif( NOT HDF5_FIND_QUIETLY )
endif( HDF5_FOUND )

if( NOT HDF5_FIND_QUIETLY )
message( STATUS "HDF5_INCLUDE_DIR=${HDF5_INCLUDE_DIR}" )
message( STATUS "HDF5_LIBRARIES=${HDF5_LIBRARIES}" )
endif( NOT HDF5_FIND_QUIETLY )

6 changes: 6 additions & 0 deletions cmake/scripts/ossim-cmake-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ fi
# Additional stuff for ECLIPSE CDT4 users:
CMAKE_G_ARG="Unix Makefiles"
if [ "$BUILD_TYPE_ARG" == "ECLIPSE" ]; then
echo "Generating eclipse project files."
CMAKE_G_ARG="Eclipse CDT4 - Unix Makefiles"
cp -f $CMAKE_DIR/CMakeLists.txt $OSSIM_DEV_HOME
CMAKE_DIR=$OSSIM_DEV_HOME
Expand Down Expand Up @@ -127,6 +128,10 @@ fi
if [ -z $BUILD_OSSIM_APPS ] ; then
export BUILD_OSSIM_APPS=ON
fi
if [ -z $BUILD_OSSIM_HDF5_SUPPORT ] ; then
export BUILD_OSSIM_HDF5_SUPPORT=OFF
fi

if [ -z $BUILD_OSSIM_CURL_APPS ] ; then
export BUILD_OSSIM_CURL_APPS=OFF
fi
Expand Down Expand Up @@ -239,6 +244,7 @@ cmake -G "$CMAKE_G_ARG" \
-DBUILD_OSSIM_PLANET=$BUILD_OSSIM_PLANET \
-DBUILD_OSSIM_APPS=$BUILD_OSSIM_APPS \
-DBUILD_OSSIM_CURL_APPS=$BUILD_OSSIM_CURL_APPS \
-DBUILD_OSSIM_HDF5_SUPPORT=$BUILD_OSSIM_HDF5_SUPPORT \
-DOSSIM_BUILD_ADDITIONAL_DIRECTORIES=$OSSIM_BUILD_ADDITIONAL_DIRECTORIES \
$CMAKE_DIR

Expand Down
86 changes: 86 additions & 0 deletions include/ossim/hdf5/ossimHdf5.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*****************************************************************************
* *
* O S S I M *
* Open Source, Geospatial Image Processing Project *
* License: MIT, see LICENSE at the top-level directory *
* *
******************************************************************************/

#ifndef ossimHdf5_HEADER
#define ossimHdf5_HEADER 1

#include <ossim/base/ossimConstants.h>
#include <ossim/base/ossimReferenced.h>
#include <ossim/base/ossimFilename.h>
#include <ossim/plugin/ossimPluginConstants.h>
#include <ostream>
#include <iosfwd>
#include <string>
#include <vector>
#include <H5Cpp.h>

/**
* Low-level OSSIM interface to HDF5 libraries. Catches HDF5 exceptions on common operations.
* Note, all methods return by value as that is the way HDF5 returns objects. This seems very
* inefficient, particularly for large datasets. Hopefully they are shallow copies.
*/
class OSSIMDLLEXPORT ossimHdf5 : public ossimReferenced
{
public:
ossimHdf5();
~ossimHdf5();

/** Opens specified HDF5 file. */
bool open(const ossimFilename& hdf5File);

bool isOpen() const { return (m_h5File != NULL); }

/** Closes the file and deletes all pointers.
* @return True if close successful. */
bool close();

/** Assigns the root group.
* @return True if result valid */
bool getRoot(H5::Group& root) const;

/** Assigns list of groups under specified group.
* @param recursive If true, recursively visits all subgroups
* @return True if result valid */
bool getChildGroups(const H5::Group& group,
std::vector<H5::Group>& groupList,
bool recursive=false) const;

/** Assigns list of datasets under current active group.
* @param recursive If true, recursively visits all datasets for this group and subgroups
* @return True if result valid */
bool getDatasets(const H5::Group& group,
std::vector<H5::DataSet>& datasetList,
bool recursive=false) const;

/** Assigns list of all multi-dimensional datasets under current active group.
* @param recursive If true, recursively visits all datasets for this group and subgroups
* @return True if result valid */
bool getNdimDatasets(const H5::Group& group,
std::vector<H5::DataSet>& datasetList,
bool recursive=false) const;

/** Assigns map of attributes (key, value) for the specified object.
* @param objPath Either relative or absolute path in file to object.
* @return True if result valid */
bool getAttributes(const H5::H5Object& obj, std::vector<H5::Attribute>& attrList) const;

/** Finds a dataset by name. The first object with specified name (can be relative path -- a
* naive string comparison is performed) under the specified group is returned.
* @param group If null, implies root group.
* @param recursive If true, recursively visits all subgroups.
* @return result Set to valid dataset object if found (caller assumes ownership), else NULL. */
H5::DataSet* findDatasetByName(const char* dataset_name,
const H5::Group* group=0,
bool recursive=false);

private:
ossimFilename m_filename;
H5::H5File* m_h5File;
};

#endif /* #ifndef ossimHdf5_HEADER */
62 changes: 62 additions & 0 deletions include/ossim/hdf5/ossimHdf5GridModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//*****************************************************************************
// FILE: ossimHdf5GridModel.h
//
// License: LGPL
//
// See LICENSE.txt file in the top level directory for more details.
//
// AUTHOR: David Burken
//
// Copied from Mingjie Su's ossimHdfGridModel.
//
// DESCRIPTION:
// Contains declaration of class ossimHdfGridModel. This is an
// implementation of an interpolation sensor model.
//
//*****************************************************************************
// $Id$

#ifndef ossimHdf5GridModel_HEADER
#define ossimHdf5GridModel_HEADER 1
#include <ossim/base/ossimPolygon.h>
#include <ossim/projection/ossimCoarseGridModel.h>
#include <ossim/plugin/ossimPluginConstants.h>
#include <ossim/hdf5/ossimHdf5.h>
#include <string>


/******************************************************************************
*
* CLASS: ossimHdf5GridModel
*
*****************************************************************************/
class OSSIM_PLUGINS_DLL ossimHdf5GridModel : public ossimCoarseGridModel
{
public:

/** @brief default constructor. */
ossimHdf5GridModel();

/** @brief virtual destructor */
virtual ~ossimHdf5GridModel();

/** Initializes from an open HDF5 file */
bool initialize(ossimRefPtr<ossimHdf5>& hdf5);

protected:

bool initCoarseGrid(ossimHdf5* hdf5, const char* datasetName, ossimDblGrid& coarseGrid);

bool m_crossesDateline;

//---
// This polygon differs from base "theBoundGndPolygon" in that if the
// scene crosses the dateline the longitude values are stored between
// 0 and 360 degress as opposed to -180 to 180.
//---
ossimPolygon m_boundGndPolygon;

TYPE_DATA
};

#endif /* Matches: #ifndef ossimHdf5GridModel_HEADER */
Loading

0 comments on commit 7eb18f8

Please sign in to comment.