diff --git a/README.md b/README.md index 473f62dc546a357d68d3075bd82fe8f19ef86de3..646675803c54e60e6a1b12f9987c784504dfd3b0 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,21 @@ and are run via ctest. To run all of the tests simply run `ctest` in the build. All of the tests are purposefully written to use generic data that values have been hand validated for. This data can be found under `tests/data`. + +## Code Style + +This software package uses a modified form of the +[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). + +Here are some exceptions: + +1. Non-const pass-by-reference is allowed. +2. No copyright notice is necessary +3. Static/global string constants are allowed to be std::strings, rather than C-style strings + +To attempt to automatically format any new code to this style, run: +`clang-format -style=Google -i file.cpp` +For more information see: [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) + +To check for compliance, run: `cpplint file.cpp` and ignore errors in the list of exclusions above. +For more information, see: [cpplint](https://github.com/cpplint/cpplint) diff --git a/include/usgscsm/Distortion.h b/include/usgscsm/Distortion.h index 17d1a9142e9635874f507d9ca5ebc74e361370a5..b70859b9d24d7278bc88e75674b7dc7415d9a499 100644 --- a/include/usgscsm/Distortion.h +++ b/include/usgscsm/Distortion.h @@ -1,5 +1,5 @@ -#ifndef Distortion_h -#define Distortion_h +#ifndef INCLUDE_USGSCSM_DISTORTION_H_ +#define INCLUDE_USGSCSM_DISTORTION_H_ #include <math.h> #include <iostream> @@ -25,4 +25,4 @@ void applyDistortion(double ux, double uy, double &dx, double &dy, DistortionType distortionType, const double desiredPrecision = 1.0E-6, const double tolerance = 1.0E-6); -#endif +#endif // INCLUDE_USGSCSM_DISTORTION_H_ diff --git a/include/usgscsm/UsgsAstroFrameSensorModel.h b/include/usgscsm/UsgsAstroFrameSensorModel.h index 14ceea2ddc27a05e77db8e9e8ad2ac72ed399b06..575cc11ad511a5270ff5344e96bb30722e5ac493 100644 --- a/include/usgscsm/UsgsAstroFrameSensorModel.h +++ b/include/usgscsm/UsgsAstroFrameSensorModel.h @@ -1,11 +1,14 @@ +#ifndef INCLUDE_USGSCSM_USGSASTROFRAMESENSORMODEL_H_ +#define INCLUDE_USGSCSM_USGSASTROFRAMESENSORMODEL_H_ -#ifndef UsgsAstroFrameSensorModel_h -#define UsgsAstroFrameSensorModel_h - -#include <SettableEllipsoid.h> #include <cmath> #include <iostream> #include <vector> +#include <utility> +#include <memory> +#include <string> + +#include "SettableEllipsoid.h" #include "CorrelationModel.h" #include "Distortion.h" #include "RasterGM.h" @@ -331,7 +334,8 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, void losEllipsoidIntersect(double height, double xc, double yc, double zc, double xl, double yl, double zl, double &x, - double &y, double &z) const; + double &y, double &z, + csm::WarningList *warnings = NULL) const; static const std::string _SENSOR_MODEL_NAME; @@ -393,4 +397,4 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM, csm::NoCorrelationModel _no_corr_model; }; -#endif +#endif // INCLUDE_USGSCSM_USGSASTROFRAMESENSORMODEL_H_ diff --git a/include/usgscsm/UsgsAstroLsSensorModel.h b/include/usgscsm/UsgsAstroLsSensorModel.h index 18bba2c3a91c3e888897166569159e723853bb4e..0a3b721b41ca213ac0dbc08c9cccf557949df292 100644 --- a/include/usgscsm/UsgsAstroLsSensorModel.h +++ b/include/usgscsm/UsgsAstroLsSensorModel.h @@ -25,14 +25,19 @@ // //----------------------------------------------------------------------------- -#ifndef __USGS_ASTRO_LINE_SCANNER_SENSORMODEL_H -#define __USGS_ASTRO_LINE_SCANNER_SENSORMODEL_H +#ifndef INCLUDE_USGSCSM_USGSASTROLSSENSORMODEL_H_ +#define INCLUDE_USGSCSM_USGSASTROLSSENSORMODEL_H_ #include <CorrelationModel.h> #include <RasterGM.h> #include <SettableEllipsoid.h> #include "Distortion.h" +#include<utility> +#include<memory> +#include<string> +#include<vector> + #include "ale/Distortion.h" #include "ale/Orientations.h" #include "ale/States.h" @@ -939,7 +944,8 @@ class UsgsAstroLsSensorModel : public csm::RasterGM, const double& xl, const double& yl, const double& zl, double& x, double& y, double& z, double& achieved_precision, - const double& desired_precision) const; + const double& desired_precision, + csm::WarningList* warnings = NULL) const; // determines the sensor velocity accounting for parameter adjustments. void getAdjSensorPosVel(const double& time, const std::vector<double>& adj, @@ -951,8 +957,8 @@ class UsgsAstroLsSensorModel : public csm::RasterGM, std::vector<double> computeDetectorView( const double& time, // The time to use the EO at const csm::EcefCoord& groundPoint, // The ground coordinate - const std::vector<double>& adj // Parameter Adjustments for partials - ) const; + const std::vector<double>& adj) // Parameter Adjustments for partials + const; // The linear approximation for the sensor model is used as the starting point // for iterative rigorous calculations. @@ -982,4 +988,4 @@ class UsgsAstroLsSensorModel : public csm::RasterGM, bool _linear; // flag indicating if linear approximation is useful. }; -#endif +#endif // INCLUDE_USGSCSM_USGSASTROLSSENSORMODEL_H_ diff --git a/include/usgscsm/UsgsAstroPlugin.h b/include/usgscsm/UsgsAstroPlugin.h index acb13092d2b7f0a15e62bff509ea31ed1f7cb099..0a7b2a1c2d7109db2dc538049e0f0126ebcd3b4e 100644 --- a/include/usgscsm/UsgsAstroPlugin.h +++ b/include/usgscsm/UsgsAstroPlugin.h @@ -1,7 +1,9 @@ -#ifndef UsgsAstroPlugin_h -#define UsgsAstroPlugin_h +#ifndef INCLUDE_USGSCSM_USGSASTROPLUGIN_H_ +#define INCLUDE_USGSCSM_USGSASTROPLUGIN_H_ #include <string> +#include<map> +#include<memory> #include <Plugin.h> #include <Version.h> @@ -47,8 +49,6 @@ class UsgsAstroPlugin : public csm::Plugin { std::string loadImageSupportData( const csm::Isd &imageSupportDataOriginal) const; - // TODO when implementing, add any other necessary members. - private: static const UsgsAstroPlugin m_registeredPlugin; static const std::string _PLUGIN_NAME; @@ -61,4 +61,4 @@ class UsgsAstroPlugin : public csm::Plugin { std::shared_ptr<spdlog::logger> m_logger; }; -#endif +#endif // INCLUDE_USGSCSM_USGSASTROPLUGIN_H_ diff --git a/include/usgscsm/Utilities.h b/include/usgscsm/Utilities.h index 15c166f504275ebf5c7cfdb4f84aa66c9070eda8..9807ecd493d0cff8f59e926242b39338e38b1978 100644 --- a/include/usgscsm/Utilities.h +++ b/include/usgscsm/Utilities.h @@ -1,5 +1,5 @@ -#ifndef Utilities_h -#define Utilities_h +#ifndef INCLUDE_USGSCSM_UTILITIES_H_ +#define INCLUDE_USGSCSM_UTILITIES_H_ #include "Distortion.h" @@ -12,10 +12,7 @@ #include <Warning.h> #include <csm.h> -// methods pulled out of los2ecf and computeViewingPixel -// for now, put everything in here. -// TODO: later, consider if it makes sense to pull sample/line offsets out // Compute distorted focalPlane coordinates in mm void computeDistortedFocalPlaneCoordinates( const double &line, const double &sample, const double &sampleOrigin, @@ -169,4 +166,4 @@ std::vector<double> getSensorVelocities(nlohmann::json isd, std::vector<double> getSensorOrientations(nlohmann::json isd, csm::WarningList *list = nullptr); double getWavelength(nlohmann::json isd, csm::WarningList *list = nullptr); -#endif +#endif // INCLUDE_USGSCSM_UTILITIES_H_ diff --git a/src/UsgsAstroFrameSensorModel.cpp b/src/UsgsAstroFrameSensorModel.cpp index 8d5e339a8ee4bdeb1b7211426ce1bf9235d77b02..13b5e4ccecb222a1570e810fa7a1339f2407efbe 100644 --- a/src/UsgsAstroFrameSensorModel.cpp +++ b/src/UsgsAstroFrameSensorModel.cpp @@ -17,7 +17,6 @@ } using json = nlohmann::json; -using namespace std; // Declaration of static variables const std::string UsgsAstroFrameSensorModel::_SENSOR_MODEL_NAME = @@ -247,7 +246,7 @@ csm::EcefCoord UsgsAstroFrameSensorModel::imageToGround( // Intersect with some height about the ellipsoid. double x, y, z; - losEllipsoidIntersect(height, xc, yc, zc, xl, yl, zl, x, y, z); + losEllipsoidIntersect(height, xc, yc, zc, xl, yl, zl, x, y, z, warnings); MESSAGE_LOG("Resulting EcefCoordinate: {}, {}, {}", x, y, z); @@ -525,15 +524,9 @@ UsgsAstroFrameSensorModel::computeAllSensorPartials( with point: {}, {}, pset: {}, and desiredPrecision: {}", groundPt.x, groundPt.y, groundPt.z, imagePt.line, imagePt.samp, pset, desiredPrecision); - std::vector<int> indices = getParameterSetIndices(pset); - size_t num = indices.size(); - std::vector<csm::RasterGM::SensorPartials> partials; - for (int index = 0; index < num; index++) { - partials.push_back(computeSensorPartials(indices[index], imagePt, groundPt, - desiredPrecision, - achievedPrecision, warnings)); - } - return partials; + + return RasterGM::computeAllSensorPartials(imagePt, groundPt, pset, desiredPrecision, + achievedPrecision, warnings); } std::vector<csm::RasterGM::SensorPartials> @@ -1292,7 +1285,7 @@ void UsgsAstroFrameSensorModel::calcRotationMatrix( void UsgsAstroFrameSensorModel::losEllipsoidIntersect( const double height, const double xc, const double yc, const double zc, const double xl, const double yl, const double zl, double &x, double &y, - double &z) const { + double &z, csm::WarningList *warnings) const { MESSAGE_LOG( "Calculating losEllipsoidIntersect with height: {},\n\ xc: {}, yc: {}, zc: {}\n\ @@ -1323,7 +1316,15 @@ void UsgsAstroFrameSensorModel::losEllipsoidIntersect( if (0.0 > quadTerm) { quadTerm = 0.0; + std::string message = "Image ray does not intersect ellipsoid"; + if (warnings) { + warnings->push_back( + csm::Warning(csm::Warning::NO_INTERSECTION, message, + "UsgsAstroFrameSensorModel::losEllipsoidIntersect")); + } + MESSAGE_LOG(message); } + double scale; scale = (-bt - sqrt(quadTerm)) / (2.0 * at); // Compute ground point vector diff --git a/src/UsgsAstroLsSensorModel.cpp b/src/UsgsAstroLsSensorModel.cpp index cb4d570ebc3b7c75e3fa8b51a7eb398eb59deb03..a4cf4b6335a5f20ea75d033395c2643249f98138 100644 --- a/src/UsgsAstroLsSensorModel.cpp +++ b/src/UsgsAstroLsSensorModel.cpp @@ -29,7 +29,6 @@ #include <Error.h> #include <nlohmann/json.hpp> -#include <sstream> #include "ale/Util.h" @@ -39,7 +38,6 @@ } using json = nlohmann::json; -using namespace std; const std::string UsgsAstroLsSensorModel::_SENSOR_MODEL_NAME = "USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL"; @@ -793,7 +791,7 @@ csm::EcefCoord UsgsAstroLsSensorModel::imageToGround( double aPrec; double x, y, z; losEllipsoidIntersect(height, xc, yc, zc, xl, yl, zl, x, y, z, aPrec, - desired_precision); + desired_precision, warnings); if (achieved_precision) *achieved_precision = aPrec; @@ -802,13 +800,7 @@ csm::EcefCoord UsgsAstroLsSensorModel::imageToGround( csm::Warning::PRECISION_NOT_MET, "Desired precision not achieved.", "UsgsAstroLsSensorModel::imageToGround()")); } - - /* - MESSAGE_LOG("imageToGround for {} {} {} achieved precision {}", - image_pt.line, image_pt.samp, height, - achieved_precision) - */ - + MESSAGE_LOG("imageToGround for {} {} {}", image_pt.line, image_pt.samp, height); return csm::EcefCoord(x, y, z); } @@ -1135,15 +1127,8 @@ UsgsAstroLsSensorModel::computeAllSensorPartials( image_pt.line, image_pt.samp, ground_pt.x, ground_pt.y, ground_pt.z, desired_precision) - std::vector<int> indices = getParameterSetIndices(pSet); - size_t num = indices.size(); - std::vector<csm::RasterGM::SensorPartials> partials; - for (int index = 0; index < num; index++) { - partials.push_back(computeSensorPartials(indices[index], image_pt, - ground_pt, desired_precision, - achieved_precision, warnings)); - } - return partials; + return RasterGM::computeAllSensorPartials(image_pt, ground_pt, pSet, desired_precision, + achieved_precision, warnings); } //*************************************************************************** @@ -1244,9 +1229,7 @@ csm::EcefCoord UsgsAstroLsSensorModel::getSensorPosition( //*************************************************************************** // UsgsAstroLsSensorModel::getSensorPosition //*************************************************************************** -csm::EcefCoord UsgsAstroLsSensorModel::getSensorPosition(double time) const - -{ +csm::EcefCoord UsgsAstroLsSensorModel::getSensorPosition(double time) const { double x, y, z, vx, vy, vz; getAdjSensorPosVel(time, _no_adjustment, x, y, z, vx, vy, vz); @@ -1484,9 +1467,7 @@ std::string UsgsAstroLsSensorModel::getGeometricCorrectionName( // UsgsAstroLsSensorModel::setGeometricCorrectionSwitch //*************************************************************************** void UsgsAstroLsSensorModel::setGeometricCorrectionSwitch( - int index, bool value, csm::param::Type pType) - -{ + int index, bool value, csm::param::Type pType) { MESSAGE_LOG( "Setting geometric correction switch {} to {} " "with parameter type {}. " @@ -1840,12 +1821,12 @@ void UsgsAstroLsSensorModel::losEllipsoidIntersect( const double& height, const double& xc, const double& yc, const double& zc, const double& xl, const double& yl, const double& zl, double& x, double& y, double& z, double& achieved_precision, - const double& desired_precision) const { + const double& desired_precision, csm::WarningList* warnings) const { MESSAGE_LOG( "Computing losEllipsoidIntersect for camera position " - "{} {} {} looking {} {} {} with desired precision" - "{}", + "{} {} {} looking {} {} {} with desired precision {}", xc, yc, zc, xl, yl, zl, desired_precision) + // Helper function which computes the intersection of the image ray // with the ellipsoid. All vectors are in earth-centered-fixed // coordinate system with origin at the center of the earth. @@ -1873,6 +1854,12 @@ void UsgsAstroLsSensorModel::losEllipsoidIntersect( if (0.0 > quadTerm) { quadTerm = 0.0; + std::string message = "Image ray does not intersect ellipsoid"; + if (warnings) { + warnings->push_back(csm::Warning( + csm::Warning::NO_INTERSECTION, message, "UsgsAstroLsSensorModel::losElliposidIntersect")); + } + MESSAGE_LOG(message) } double scale, scale1, h; double sprev, hprev; @@ -2173,8 +2160,8 @@ void UsgsAstroLsSensorModel::setLinearApproximation() { double denom = determinant3x3(mat3x3); - if (fabs(denom) < 1.0e-8) // can not get derivatives this way - { + // Can not get derivatives this way + if (fabs(denom) < 1.0e-8) { MESSAGE_LOG( "setLinearApproximation: determinant3x3 of" "matrix of partials is {}; nonlinear", diff --git a/src/UsgsAstroPlugin.cpp b/src/UsgsAstroPlugin.cpp index 7d1c1afe74d11bdfbc8f951b8b39f9ddc4025738..e8c37730e6de266891c7258353a7b86b3084d927 100644 --- a/src/UsgsAstroPlugin.cpp +++ b/src/UsgsAstroPlugin.cpp @@ -110,7 +110,7 @@ bool UsgsAstroPlugin::canModelBeConstructedFromState( csm::WarningList *warnings) const { try { csm::Model *model = constructModelFromState(modelState, warnings); - return (bool)model; + return static_cast<bool>(model); } catch (std::exception &e) { std::string msg = "Could not create model ["; msg += modelName; @@ -144,7 +144,7 @@ bool UsgsAstroPlugin::canModelBeConstructedFromISD( try { csm::Model *model = constructModelFromISD(imageSupportData, modelName, warnings); - return (bool)model; + return static_cast<bool>(model); } catch (std::exception &e) { if (warnings) { std::string msg = "Could not create model ["; @@ -191,7 +191,6 @@ std::string UsgsAstroPlugin::loadImageSupportData( isd_sidecar >> jsonisd; jsonisd["image_identifier"] = filename; return jsonisd.dump(); - } catch (std::exception &e) { std::string errorMessage = "Could not read metadata file associated with image ["; diff --git a/src/Utilities.cpp b/src/Utilities.cpp index 57ce5ef8f5457011a4f8467d4cb11720f3cf7f33..b78f5f7dc5d3a73c289172767e89512248fe97bb 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -85,7 +85,7 @@ void computeDistortedFocalPlaneCoordinates( distortedX = p11 * t1 + p12 * t2; distortedY = p21 * t1 + p22 * t2; -}; +} // Compue the image pixel for a distorted focal plane coordinate // in - line @@ -110,7 +110,7 @@ void computePixel(const double &distortedX, const double &distortedY, double detLine = centeredLine + lineOrigin; sample = (detSample - startingSample) / sampleSumming; line = (detLine - startingLine) / lineSumming; -}; +} // Define imaging ray in image space (In other words, create a look vector in // camera space) in - undistortedFocalPlaneX in - undistortedFocalPlaneY in - @@ -150,7 +150,7 @@ void lagrangeInterp(const int &numTime, const double *valueArray, // Compute index double fndex = (time - startTime) / delTime; - int index = int(fndex); + int index = static_cast<int>(fndex); if (index < 0) { index = 0; @@ -269,9 +269,8 @@ double brentRoot(double lowerBound, double upperBound, nextPoint += (previousPoint * currentFunc * counterFunc) / ((previousFunc - counterFunc) * (previousFunc - currentFunc)); - } - // Secant method - else { + } else { + // Secant method nextPoint = currentPoint - currentFunc * (currentPoint - counterPoint) / (currentFunc - counterFunc); } @@ -388,10 +387,8 @@ double computeEllipsoidElevation(double x, double y, double z, double semiMajor, tanPhi = zz / d; ktr++; } while (MKTR > ktr && fabs(h - hPrev) > desired_precision); - } - - // Suited for points near the poles - else { + } else { + // Suited for points near the poles double cc, dd, nn; double cotPhi = d / z; do {