[cig-commits] r8234 - in cs/spatialdata-0.1/trunk/libsrc: . geocoords spatialdb

brad at geodynamics.org brad at geodynamics.org
Wed Nov 7 17:52:46 PST 2007


Author: brad
Date: 2007-11-07 17:52:45 -0800 (Wed, 07 Nov 2007)
New Revision: 8234

Added:
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.hh
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc
Modified:
   cs/spatialdata-0.1/trunk/libsrc/Makefile.am
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh
   cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.hh
   cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh
   cs/spatialdata-0.1/trunk/libsrc/geocoords/Geoid.hh
   cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
Log:
Initial implementation of GravityField as a spatial database. Still need unit tests.

Modified: cs/spatialdata-0.1/trunk/libsrc/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/Makefile.am	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/Makefile.am	2007-11-08 01:52:45 UTC (rev 8234)
@@ -29,6 +29,7 @@
 	geocoords/CSPicklerAscii.cc \
 	geocoords/Geoid.cc \
 	geocoords/Projector.cc \
+	spatialdb/GravityField.cc \
 	spatialdb/SimpleDB.cc \
 	spatialdb/SpatialDB.cc \
 	spatialdb/SimpleDBQuery.cc \

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoLocalCart.hh	2007-11-08 01:52:45 UTC (rev 8234)
@@ -190,7 +190,5 @@
 
 #endif // spatialdata_geocoords_csgeolocalcart_hh
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSGeoProj.hh	2007-11-08 01:52:45 UTC (rev 8234)
@@ -114,7 +114,5 @@
 
 #endif // spatialdata_geocoords_csgeoproj_hh
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.hh	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/CSPicklerAscii.hh	2007-11-08 01:52:45 UTC (rev 8234)
@@ -55,7 +55,5 @@
 
 #endif // spatialdata_geocoords_cspicklerascii_hh
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/Converter.hh	2007-11-08 01:52:45 UTC (rev 8234)
@@ -87,7 +87,5 @@
 
 #endif // spatialdata_geocoords_converter_hh
 
-// version
-// $Id$
 
 // End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/geocoords/Geoid.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/geocoords/Geoid.hh	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/geocoords/Geoid.hh	2007-11-08 01:52:45 UTC (rev 8234)
@@ -128,7 +128,5 @@
 
 #endif // spatialdata_geocoords_geoid_hh
 
-// version
-// $Id$
 
 // End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.cc	2007-11-08 01:52:45 UTC (rev 8234)
@@ -0,0 +1,152 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "GravityField.hh" // Implementation of class methods
+
+#include "spatialdata/geocoords/CoordSys.hh" // USES CoordSys
+#include "spatialdata/geocoords/CSGeo.hh" // USES CSGeo
+#include "spatialdata/geocoords/Converter.hh" // USES Converter
+
+#include <math.h> // USES sqrt()
+
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringsgream
+#include <assert.h> // USES assert()
+
+// ----------------------------------------------------------------------
+/// Default constructor
+spatialdata::spatialdb::GravityField::GravityField(void) :
+  SpatialDB("Gravity field"),
+  _acceleration(9.80665), // m/s^2
+  _csECEF(new geocoords::CSGeo),
+  _queryVals(0),
+  _querySize(0)
+{ // constructor
+  _upDir[0] = 0.0;
+  _upDir[1] = 0.0;
+  _upDir[2] = 0.0;
+
+  if (0 == _csECEF)
+    throw std::runtime_error("Error while initializing ECEF coordinate "
+			     "system.");
+  _csECEF->isGeocentric(true);
+} // constructor
+
+// ----------------------------------------------------------------------
+/// Default destructor
+spatialdata::spatialdb::GravityField::~GravityField(void)
+{ // destructor
+  delete _csECEF; _csECEF = 0;
+  delete[] _queryVals; _queryVals = 0;
+  _querySize = 0;
+} // destructor
+
+// ----------------------------------------------------------------------
+// Set values to be returned by queries.
+void
+spatialdata::spatialdb::GravityField::queryVals(const char** names,
+					     const int numVals)
+{ // queryVals
+  if (0 == numVals) {
+    std::ostringstream msg;
+    msg
+      << "Number of values for query in spatial database " << label()
+      << "\n must be positive.\n";
+    throw std::runtime_error(msg.str());
+  } // if
+  assert(0 != names && 0 < numVals);
+  
+  _querySize = numVals;
+  delete[] _queryVals; _queryVals = new int[numVals];
+  for (int iVal=0; iVal < numVals; ++iVal) {
+    if (0 == strcasecmp(names[iVal], "x"))
+      _queryVals[iVal] = 0;
+    else if (0 == strcasecmp(names[iVal], "y"))
+      _queryVals[iVal] = 1;
+    else if (0 == strcasecmp(names[iVal], "z"))
+      _queryVals[iVal] = 2;
+    else {
+      std::ostringstream msg;
+      msg
+	<< "Could not find value " << names[iVal] << " in spatial database\n"
+	<< label() << ". Available values are: 'x', 'y', 'z'.";
+      throw std::runtime_error(msg.str());
+    } // if
+  } // for
+} // queryVals
+
+// ----------------------------------------------------------------------
+// Query the database.
+int
+spatialdata::spatialdb::GravityField::query(
+			      double* vals,
+			      const int numVals,
+			      const double* coords,
+			      const int numDims,
+			      const spatialdata::geocoords::CoordSys* cs)
+{ // query
+  assert(0 != cs);
+
+  if (0 == _querySize) {
+    std::ostringstream msg;
+    msg
+      << "Values to be returned by spatial database " << label() << "\n"
+      << "have not been set. Please call queryVals() before query().\n";
+    throw std::runtime_error(msg.str());
+  } // if
+  else if (numVals != _querySize) {
+    std::ostringstream msg;
+    msg
+      << "Number of values to be returned by spatial database "
+      << label() << "\n"
+      << "(" << _querySize << ") does not match size of array provided ("
+      << numVals << ").\n";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  if (geocoords::CoordSys::CARTESIAN == cs->csType())
+    for (int i=0; i < _querySize; ++i)
+      vals[i] = -_acceleration*_upDir[_queryVals[i]];
+  else {
+    const geocoords::CSGeo* csGeo = dynamic_cast<const geocoords::CSGeo*>(cs);
+    if (!csGeo->isGeocentric())
+      for (int i=0; i < _querySize; ++i)
+	vals[i] = -_acceleration*_upDir[_queryVals[i]];
+    else {
+      // cs is either CSGeo (geocentric) or CSGeoLocalCart
+      const int numLocs = 1;
+      const int spaceDim = 3;
+      assert(spaceDim == csGeo->spaceDim());
+
+      // Convert coordinates to Earth-centered/Earth-fixed (ECEF)
+      double xyzECEF[spaceDim];
+      for (int i=0; i < spaceDim; ++i)
+	xyzECEF[i] = coords[i];
+      geocoords::Converter::convert(xyzECEF, numLocs, spaceDim,
+				    _csECEF, csGeo);
+
+      // Compute outward radial direction by computing
+      const double mag = sqrt(xyzECEF[0]*xyzECEF[0] +
+			      xyzECEF[1]*xyzECEF[1] +
+			      xyzECEF[2]*xyzECEF[2]);
+      for (int i=0; i < _querySize; ++i)
+	vals[i] = -_acceleration*xyzECEF[i] / mag;
+    } // else
+  } // if/else
+
+  return 0;
+} // query
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.hh
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.hh	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.hh	2007-11-08 01:52:45 UTC (rev 8234)
@@ -0,0 +1,124 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+/** @file libsrc/spatialdb/GravityField.hh
+ *
+ * @brief C++ manager for simple spatial database.
+ */
+
+#if !defined(spatialdata_spatialdb_gravityfield_hh)
+#define spatialdata_spatialdb_gravityfield_hh
+
+#include "SpatialDB.hh"
+
+namespace spatialdata {
+  namespace spatialdb {
+    class SpatialDB; // ISA SpatialDB
+    class GravityField;
+    class TestGravityField; // unit testing
+  } // spatialdb
+
+  namespace geocoords {
+    class CSGeo; // USES CSGeo
+  } // geocoords
+} // spatialdata
+
+/// C++ manager for simple spatial database.
+class spatialdata::spatialdb::GravityField : public SpatialDB
+{ // class GravityField
+  friend class TestGravityField; // unit testing
+
+ public :
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+
+  /// Default constructor.
+  GravityField(void);
+  
+  /// Default destructor.
+  ~GravityField(void);
+  
+  /** Set up direction (direction opposite of gravity) in database.
+   *
+   * @param x X component of up direction
+   * @param y Y component of up direction
+   * @param z Z component of up direction
+   */
+  void upDir(const double x,
+	     const double y,
+	     const double z);
+
+  /** Set gravitational acceleration.
+   *
+   * @param acceleration Gravitational acceleration.
+   */
+  void gravAcceleration(const double acceleration);
+
+  /// Open the database and prepare for querying.
+  void open(void);
+
+  /// Close the database.
+  void close(void);
+
+  /** Set values to be returned by queries.
+   *
+   * Valid values for use in names are {'x', 'y', 'z'}.
+   *
+   * @pre Must call open() before queryVals()
+   *
+   * @param names Names of values to be returned in queries
+   * @param numVals Number of values to be returned in queries
+   */
+  void queryVals(const char** names,
+		 const int numVals);
+
+  /** Query the database.
+   *
+   * @pre Must call open() before query()
+   *
+   * @param vals Array for computed values (output from query), vals
+   *   must be allocated BEFORE calling query().
+   * @param numVals Number of values expected (size of pVals array)
+   * @param coords Coordinates of point for query
+   * @param numDims Number of dimensions for coordinates
+   * @param cs Coordinate system of coordinates
+   *
+   * @returns 0 on success, 1 on failure (i.e., could not interpolate
+   *   so values set to 0)
+   */
+  int query(double* vals,
+	    const int numVals,
+	    const double* coords,
+	    const int numDims,
+	    const spatialdata::geocoords::CoordSys* cs);
+
+ private :
+  // PRIVATE METHODS ////////////////////////////////////////////////////
+
+  GravityField(const GravityField& data); ///< Not implemented
+  const GravityField& operator=(const GravityField& data); ///< Not implemented
+  
+private :
+ // PRIVATE MEMBERS /////////////////////////////////////////////////////
+
+  double _upDir[3]; ///< Up direction for use with Cartesian coordinates.
+  double _acceleration; ///< Acceleration due to gravity.
+  geocoords::CSGeo* _csECEF; ///< Earth-centered/Earth-fixed coordinate system.
+  int* _queryVals; ///< Indices of values to be returned in queries.
+  int _querySize; ///< Number of values requested to be returned in queries.
+}; // class GravityField
+
+#include "GravityField.icc"
+
+#endif // spatialdata_spatialdb_gravityfield_hh
+
+
+// End of file 

Added: cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/GravityField.icc	2007-11-08 01:52:45 UTC (rev 8234)
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// <LicenseText>
+//
+// ----------------------------------------------------------------------
+//
+
+#if !defined(spatialdata_spatialdb_gravityfield_hh)
+#error "GravityField.icc must only be included from GravityField.hh"
+#endif
+
+// Set up direction (direction opposite of gravity) in database.
+void
+spatialdata::spatialdb::GravityField::upDir(const double x,
+					    const double y,
+					    const double z) {
+  _upDir[0] = x;
+  _upDir[1] = y;
+  _upDir[2] = z;
+}
+
+// Set gravitational acceleration.
+void
+spatialdata::spatialdb::GravityField::gravAcceleration(
+					       const double acceleration) {
+  _acceleration = acceleration;
+}
+
+// Open the database and prepare for querying.
+void
+spatialdata::spatialdb::GravityField::open(void) {
+}
+
+// Close the database.
+void
+spatialdata::spatialdb::GravityField::close(void) {
+}
+
+
+// End of file 

Modified: cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am
===================================================================
--- cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am	2007-11-07 23:54:01 UTC (rev 8233)
+++ cs/spatialdata-0.1/trunk/libsrc/spatialdb/Makefile.am	2007-11-08 01:52:45 UTC (rev 8234)
@@ -16,6 +16,8 @@
 subpkginclude_HEADERS = \
 	Exception.hh \
 	Exception.icc \
+	GravityField.hh \
+	GravityField.icc \
 	SpatialDB.hh \
 	SpatialDB.icc \
 	SimpleDB.hh \



More information about the cig-commits mailing list