Skip to content

Commit

Permalink
Merge dev into master for 1.1 release (#190)
Browse files Browse the repository at this point in the history
* Updated ISD and tests  (#87)

* updated tests + RIP TestyMcTestFace

* keys updated

* Probably should not hard code .cpps in the CMakeLists.txt for GTest

* updated specs to mimic synthetic json

* appveyor assumed broken from standup, disabling until fixed

* eulers are now quats

* merge from jay's changes

* merge markers

* renamed quats as per Jessie's reccomendation

* only appends sensor_orientation to missing params

* stupid markers

* updated test ISD

* changes as per some comments

* updated as per comments

* defaults are all 0

* #pragma once to C style header guard

* stragler change

* missed some params

* missed another

* moving things around

* patched segfault error + added detector center as defined in json schema (#94)

* patched segfault error + added detector center as defined in the swagger schema

* verbose travi

* Fixed optical distortion and pixel to focal transforms. (#115)

* Update to use quaternions in test to match new ISD

* Fixes #121

* Fix 1 remaining failing omega rotation test

* Updates token to be in quotes

* Still trying to get the builds working.

* Updates to force upload

* Adds newline

* Update for formatting

* Trying to force travis to deploy with labels

I am editing this on the repo in order to get Travis to do its thing - I can not do this via a PR.

* Update .travis.yml

* Update meta.yaml

to try and force a dev tag on the builds to get labels to work.

* Update meta.yaml

* Update .travis.yml

* test x scaling for reset model state

* test FL500 conversion

* test FL500 conversion

* Add tests to include

* commit to force run of tests on mac with debug output

* switch to using tolerances from dev

* 0.5 pixel offset

* try moving set of filename into setup

* initialize differently test

* more debug output

* Add matrix to debug output

* Even more debug output from matrix calculation

* Add missing quaternion component to state string

* cleanup debug output now that problem is fixed

* fix added spacing

* Adds in check for PR for upload

* echo to check travis env

* fixes equality check for PR

* Clean up some spacing (non-functional) in UsgsAstroFrameModel

* Fixed canModelBeConstructedFromISD throwing an exception when the metadata file doesn't exist. (#134)

* fixed can be converted error

* Added not constructible test for frame plugin

* Removed old LS ISD header (#137)

* Update some of the tests that set a new state value to use a function in the fixture, rather than repeating code

* Windows Build (#139)

* adds win build

* Windows build

* Updates submodules

* Refactoring to move to one plugin and removed unused classes.  (#138)

* merge

* changed varrs

* reset test

* First iteration

* it compiles, although renaming this is still neccessary

* added source

* cleaned up, tests still need to pass

* post merge clean up

* validation updated, validation tests are now passing

* Addressed comments from Jesse

* last Jesse comment, convertISDToModelState doesn't check if pointer is invalid anymore as the sensor model should except

* model_name -> m_modelName for frame getState

* copy paste error in FrameSensorModel

* Resolve merge conflicts with FrameIsdTest vs. SimpleFrameIsdTest names

* Fix hopefully last merge problem

* Conda build on win (#143)

* Conda build on win

* Trying a straight build first

* Unneeded csmapi

* Now trying to upload build

* Trying a build and upload

* Trying syntax change

* trying ps

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update meta.yaml

* Update bld.bat

This is a test to see where appveyor is failing.

* Update bld.bat

* Update bld.bat

* Update meta.yaml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Update .appveyor.yml

* Adds if/else into appveyor (#146)

* Adds if/else into appveyor

* Update .appveyor.yml

* Updates to use gcc7

* Update .travis.yml

* Update .appveyor.yml

* Fixed Line Scan construction and condensed plugin tests (#145)

* First pass at test LS ISD

* Initial LS plugin test base

* fixed a test in frame plugin tests

* Initial LS plugin test suite

* Moved to single plugin test file

* Added some new plugin tests

* Fixed LS construction

* Re-updated submodules

* Reverted gtest

* removed debuf prints left in and made getModelName functional (#148)

* Changed line scan sensor model to new ISD spec (#149)

* Changed line scan sensor model to new ISD spec

* Updated LS to the proper spec

* Changed model_name to name_model

* Updated tests to use new name_ format in ISD

* Updated LS test data to new spec

* Fixed typo in ls test ISD

* Moved framer to new ISD format. Added bad debug statements.

* Updated LS to new spec

* Fixed focal length epsilon name

* Fixes 142 for framer

* Removes unused state keyword counter

* Updates Ls

* Updates for parametercov and ref point

* Adds sensor and platform names

* Updates with collection identifier

* updates for vector parameters in state

* Added model state test for framer (#152)

* Adds current param value and referencePt

* unsupported pushed in

* fixed nan issue (#153)

* fixed nan issue

* left in for loop

* Removed switch statement for ls distortion: (#150)

* Updated build recipe to use release and sha hash

* Copied distortion inversion from ISIS3 Distortion Map (#161)

* Fixed ground to image and image to ground not giving inverse results. (#162)

* Copied distortion inversion from ISIS3 Distortion Map

* mid-testing commit to fix LS i2g and g2i inconsistency

* Fixed ground to image taking excessive iterations. Added simple line scan test and test stubs

* Added more comments and replaced some hard coded tolerances

* Added debug output to ground to image error message. (#168)

* Initial steps to modularize losToEcf in UsgsAstroLsSensorModel

* Try changing line endings

* Re-converted line endings to dos

* Modularize some of computeViewingPixel

* Cleanup

* Reconvert to dos line endings

* Reformat member variables in header and switch more to use const pass-by-reference parameters to be consistent with rest of code

* Updates in response to code review (part 1)

* Update calculateRotationMatrixFromQuaternions -- removed invert parameter. Now, will always return the matrix that rotates the in the same direction as the quaternions.

* Updates the version number in the meta. (#159)

* Updates the version number in the meta.

* Update meta.yaml

* Build to hash

This should be using the short hash now.

* Update meta.yaml

* Update meta.yaml

* Finish Modularizing computeViewingPixel (#170)

* Finishing modularization of UsgsAstroLsSensorModel::computeViewingPixel

* Fixes per request

* Removing ISIS references in variable names while I'm here

* Example for LS testing (#171)

* Removed odd height gradient descent search from image to ground when not intersecting.

* Added first off body test.

* Added angular velocity line scan test

* Added failing, copy paste tests

* Commented out line scan pan tests until 0 velocity bug is addressed

* Removed extraneous focal epsilon from LS test ISDs

* Extracts distortion models from the Line Scanner and Framer cameras into its own function set (#172)

* Moved transverse distortion from line scanner into new file

* Updated fixtures for distortion tests

* Forgot a semicolon

* Extracted radial destortion, and built associated tests

* Removed invertDistortion commented code from Linescanner

* Reconstructed distortion functions return results

* Incorperated invertDistortion function

* Corrected spelling, and removed commented out functions

* Renamed all dpoint variables to distortionPoint

* Removed computeUndistortedFocalPlaneCoordinates function

* Renamed distortionPoint to undistortedPoint and distortedPoint where applicable

* Fixed typo

* Removed doc string parameters

* Further extracted transverse destortion out of the Framer

* Pulled losToEcf shared functions out into Utilities class (#174)

* Initial steps to pull common camera model or math utility functions into a separate Utilities file.

* dos2unix line endings again

* ../include/usgscsm/UsgsAstroLsSensorModel.h

* updates to modularized functions

* dos2unix UsgsAstroFrameSensorModel

* Forgot to actually add the Utilities class

* Keep needed to unix2dos to re-fix line ending caracters

* We have some dos line ending and some unix line endings in our code

* Copied unit conversion from framer to ls (#177)

* Makes GTest fully optional (#175)

* removes unused setup.py (#178)

* Refactored ISD parsing into utilities and added warnings (#179)

* Added utility ISD parsing functions

* ISD Parsing Test stub

* Added ISD parsing method tests

* Added ISD Parsing utilities to Framer

* Replaced framer ISD parsing

* added check for warning output to bad fram ISD test

* Added a bit more testing

* Removed ground to image 10m errormessage (#180)

* Fixed state being written out and read in differently (#183)

* Fixed state being written out and read in differently

* Fixed canModelBeConstructedFromState

* Updated README (#154)

* Updated README

* Added BAE license and removed open source license

* Gtests for Utilities.cpp (#181)

* Finishing modularization of UsgsAstroLsSensorModel::computeViewingPixel

* Fixes per request

* Removing ISIS references in variable names while I'm here

* Beginning to implement tests for modularization changes in LS sensor model class

* Adding tests for Utilities as well as a few minor modifications

* Making suggested changes and adding test for caculateAttitudeCorrection

* Fixing vector size

* Updated LS ISD parsing code to match Framer (#186)

* updated LS ISD parsing to match style in framer

* reverted the 1 to 0

* Fixed attitude test, removed all cerr lines

* removed image flip flag

* added tests

* Fixed computeDistortedFocalPlaneCoordinates test (#187)

* Distortion Integration (#184)

* Moved transverse distortion from line scanner into new file

* Extracted radial destortion, and built associated tests

* Reconstructed distortion functions return results

* Corrected spelling, and removed commented out functions

* Renamed all dpoint variables to distortionPoint

* Removed computeUndistortedFocalPlaneCoordinates function

* Renamed distortionPoint to undistortedPoint and distortedPoint where applicable

* Removed doc string parameters

* Added combined new distortion model

* Half way through redefining parameters

* Major update to distortion and coefficient storage

* More debugging

* More debugging

* More debugging

* debugging

* debugging

* Removed debugging messages and set the output value for remove distortion

* Brought changes inline with dev

* Updated isd parsing to handle either radial or transverse

* Added Distortion Parse function

* Split apply and remove distortion, and added the distortion type to each model state

* Removed cmath

* Removing prints, and other fixes

* Updated how coefficients are parsed

* Reverted notebook

* Function namespace and parameter clean up

* More function and parameter clean up

* Reverted old code and updated distortion defaults

* Small changes for distortion

* Updated utilities and fixed failing test

* Final LS tests and release prep (#188)

* Added image locus tests

* Pan LS tests now pass

* updated release date in plugin

* Forgot to update plugin release date test
  • Loading branch information
jessemapel authored and krlberry committed Feb 22, 2019
1 parent 9bcdc97 commit a3d433c
Show file tree
Hide file tree
Showing 27 changed files with 2,755 additions and 1,464 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.10)
project(usgscsm VERSION 0.0.1 DESCRIPTION "usgscsm library")

include(GoogleTest)
include(cmake/gtest.cmake)
include(GNUInstallDirs)
include(GoogleTest)

set(CMAKE_CXX_STANDARD 11)

Expand All @@ -18,15 +18,17 @@ else()
PATH_SUFFIXES "csm"
PATHS $ENV{CONDA_PREFIX}/include/)
find_library(CSM_LIBRARY csmapi PATHS $ENV{CONDA_PREFIX}/lib)

message("--Found CSM Library: ${CSM_LIBRARY}")
message("--Found CSM Include Directory: ${CSM_INCLUDE_DIR}")
endif(BUILD_CSM)

add_library(usgscsm SHARED
src/UsgsAstroPlugin.cpp
src/UsgsAstroFrameSensorModel.cpp
src/UsgsAstroLsSensorModel.cpp)
src/UsgsAstroLsSensorModel.cpp
src/Distortion.cpp
src/Utilities.cpp)

set_target_properties(usgscsm PROPERTIES
VERSION ${PROJECT_VERSION}
Expand All @@ -42,12 +44,8 @@ target_include_directories(usgscsm
${CSM_INCLUDE_DIR}
)

# Setup for GoogleTest
find_package (Threads)

target_link_libraries(usgscsm
${CSM_LIBRARY}
gtest ${CMAKE_THREAD_LIBS_INIT})
${CSM_LIBRARY})

if(WIN32)
install(TARGETS usgscsm RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand All @@ -60,6 +58,12 @@ install(DIRECTORY ${USGSCSM_INCLUDE_DIRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR
# Optional build or link against CSM
option (BUILD_TESTS "Build tests" ON)
if(BUILD_TESTS)

# Setup for GoogleTest
find_package (Threads)

target_link_libraries(usgscsm
gtest ${CMAKE_THREAD_LIBS_INIT})
include(CTest)
enable_testing()
add_subdirectory(tests)
Expand Down
24 changes: 0 additions & 24 deletions LICENSE

This file was deleted.

154 changes: 60 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,66 @@
# CSM-CameraModel

ISD Specification: https://github.com/USGS-Astrogeology/pfeffernusse/blob/master/swagger.yaml

## Setting up dependencies with conda (RECOMMENDED)

Install conda if you do not already have it.
```bash
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b
```
> You can add a `-p <install-prefix>` to choose where to install miniconda. By default, it will install it to `$HOME/miniconda3`.
### Setting up conda for bash
Copy and paste the following into a terminal running the `bash` shell:
```bash
echo -e "\n\n# Adding miniconda3 to PATH" >> $HOME/.bashrc && \
echo -e "export PATH=$HOME/miniconda3/bin:\$PATH" >> $HOME/.bashrc && \
source $HOME/.bashrc && \
which conda
```
> *For more information: [bash installation](https://conda.io/docs/user-guide/install/linux.html "Reference to bash conda install")*
### Setting up conda for tcsh
Copy and paste the following into a terminal running the `tcsh` shell:
```tcsh
echo "\n\n# Setting up miniconda3 for tcsh" >> $HOME/.cshrc && \
echo "source $HOME/miniconda3/etc/profile.d/conda.csh > /dev/null" >> $HOME/.cshrc && \
source $HOME/.cshrc && \
which conda
```
> *For more information: [tcsh installation](https://github.com/ESMValGroup/ESMValTool/issues/301 "Reference to tcsh conda install")*
### Creating an isolated conda environment
Run the following commands to create a self-contained dev environment for CSM-CameraModel (type `y` to confirm creation):
```bash
conda create -n csmdev -c usgs-astrogeology cmake libcsm
```
> *For more information: [conda environments](https://conda.io/docs/user-guide/tasks/manage-environments.html)*
### Activating the environment
After creating the `csmdev` environment and installing cmake and libcsm into it, we need to activate it. Right now, cmake, libcsm, and their dependencies are isolated to a conda environment and we need to tell conda that we want to use it. The activation command depends on your shell.
* **bash**: `source activate csmdev`
* **tcsh**: `conda activate csmdev`
> *You can add these to the end of your $HOME/.bashrc or $HOME/.cshrc if you want the `csmdev` environment to be active in every new terminal.*
Community Sensor Model (CSM) compliant sensor models created by USGS Astrogeology
Science Center.

## Building CSM-CameraModel
After you've set up conda, you can build CSM-CameraModel:

1. Fork `USGS-Astrogeology/CSM-CameraModel` if you don't already have a fork.
2. Clone your fork of `CSM-CameraModel` *with `--recursive` option to get the gtest submodule*.
```bash
git clone --recursive git@github.com:<your-username>/CSM-CameraModel.git
cd CSM-CameraModel
git remote add upstream git@github.com:USGS-Astrogeology/CSM-CameraModel.git
```
3. Sync your fork with `upstream` and ensure the gtest submodule is init'd if your fork is old.
```bash
git pull upstream master
git submodule update --init --recursive
git push -u origin master
```
4. `mkdir build && cd build`
5. `cmake .. && make`
6. `ctest`
CSM-CameraModel contains two different sensor models. The first, is a generic
framing camera model written from scratch. The second is a generic line scan
camera model based on code from BAE Systems Information and Electronic Systems
Integration Inc.

## Using CSM-CameraModel

This library is a CSM plugin library that is intended to be dynamically loaded
at run time along side the
[CSM API library](https://github.com/USGS-Astrogeology/csm).

Once, the library is loaded, it can be accessed through the CSM Plugin interface.
For an example of how to do through the CSM c++ interface see the SensorModelFactory
class in [SensorUtils](https://github.com/USGS-Astrogeology/SensorUtils).
For an example of how to do this through the CSM Python bindings see this
[notebook](http://nbviewer.jupyter.org/gist/thareUSGS/4c0eb72799edc33ff4816b2587027148).

From the CSM Plugin interface, a generic framing camera model
(USGS_ASTRO_FRAME_SENSOR_MODEL) or generic line scan camera model
(USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL) can be instantiated from suitable Image
Support Data (ISD). Under the CSM standard, each plugin library can define its
own ISD format. This library uses an auxiliary JSON formatted file that must be
next to the image file passed to the CSM::ISD class. We provide an OpenAPI
server for generating these,
[pfeffernusse](https://github.com/USGS-Astrogeology/pfeffernusse). The swagger
specification is located on
[swaggerhub](https://app.swaggerhub.com/apis/USGS-Astro/pfeffernusse2/0.1.4-oas3).

---

## Building without a package manager
To build:

1. Install [libcsmapi](https://github.com/sminster/csm "CSM API")
> You can install this with an `INSTDIR` of your choice, or let it default (see [libcsmapi README](https://github.com/sminster/csm/blob/master/README))
```bash
mkdir $HOME/csmenv
cd $HOME
git clone git@github.com:sminster/csm.git
cd csm
make -f Makefile.linux64 all install clean INSTDIR="$csmenv"
```
2. Install cmake >= 3.10
```bash
cd $HOME
wget https://cmake.org/files/v3.12/cmake-3.12.0-Linux-x86_64.tar.gz
tar xzf cmake-3.12.0-Linux-x86_64.tar.gz
rsync -azv cmake-3.12.0-Linux-x86_64/ $HOME/csmenv/
echo -e "\n#Prepending csm env to path\nsetenv PATH "$HOME/csmenv/bin:$PATH" >> $HOME/.cshrc
source $HOME/.cshrc
```
3. Fork and clone down this repo and its submodules (gtest)
```bash
git clone --recursive git@github.com:<username>/CSM-CameraModel.git
cd CSM-CameraModel
git remote add upstream git@github.com:USGS-Astrogeology/CSM-CameraModel.git
git pull upstream master
git submodule update --init --recursive
git push -u origin master
```
4. `mkdir build` && `cd build`
5. `cmake -DCSM_INCLUDE_DIR="${csmenv}/include/csm -DCSM_LIBRARY="${csmenv}/lib/libcsmapi.so .. && make`
## Build Requirements

* cmake 3.10 or newer
* GNU-compatible Make
* a c++11 compliant compiler

This repository has all of its external c++ dependencies included in it. The
excellent header-only JSON library
[JSON for Modern C++](https://github.com/nlohmann/json) is included directly in
the source code. The other two dependencies, the CSM API library, and gtest
are included as git submodules. When you clone this library make sure you add
the `--recursive` flag to your `git clone` command. Alaterntively, you can run
`git submodule update --init --recursive` after cloning. The library can also be
compiled against an installed versions of the CSM API by setting the BUILD_CSM
flag to OFF during cmake configuration.

## Building CSM-CameraModel

CSM-CameraModel uses a standard cmake build system. To compile the library, and
tests use the following commands:

1. `mkdir build && cd build`
2. `cmake .. && cmake --build .`

## Testing CSM-CameraModel

All of the tests for CSM-CameraModel are written in the googletests framework
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`.
30 changes: 30 additions & 0 deletions include/usgscsm/Distortion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef Distortion_h
#define Distortion_h

#include <vector>
#include <math.h>
#include <tuple>
#include <iostream>

enum DistortionType {
RADIAL,
TRANSVERSE
};

// Transverse Distortion
void distortionJacobian(double x, double y, double *jacobian,
const std::vector<double> opticalDistCoeffs);

void computeTransverseDistortion(double ux, double uy, double &dx, double &dy,
const std::vector<double> opticalDistCoeffs);

void removeDistortion(double dx, double dy, double &ux, double &uy,
const std::vector<double> opticalDistCoeffs,
DistortionType distortionType,
const double tolerance = 1.0E-6);

void applyDistortion(double ux, double uy, double &dx, double &dy,
const std::vector<double> opticalDistCoeffs,
DistortionType distortionType,
const double desiredPrecision = 0, const double tolerance = 1.0E-6);
#endif
22 changes: 14 additions & 8 deletions include/usgscsm/UsgsAstroFrameSensorModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include <gtest/gtest.h>
#include "RasterGM.h"
#include "CorrelationModel.h"
#include "Distortion.h"
#include "Utilities.h"

#include <json.hpp>
using json = nlohmann::json;


#include <json.hpp>
using json = nlohmann::json;
Expand Down Expand Up @@ -320,12 +326,6 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM {
FRIEND_TEST(FrameSensorModel, setFocalPlane_AlternatingOnes);
FRIEND_TEST(FrameSensorModel, distortMe_AlternatingOnes);

virtual bool setFocalPlane(double dx,double dy,double &undistortedX,double &undistortedY) const;
virtual void distortionFunction(double ux, double uy, double &dx, double &dy) const;
virtual void distortionJacobian(double x, double y, double &Jxx,
double &Jxy, double &Jyx, double &Jyy) const;



private:
// Input parameters
Expand All @@ -335,8 +335,8 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM {
std::vector<double> m_currentParameterCovariance;
std::vector<csm::param::Type> m_parameterType;
std::vector<double> m_noAdjustments;
std::vector<double> m_odtX;
std::vector<double> m_odtY;
DistortionType m_distortionType;
std::vector<double> m_opticalDistCoeffs;
std::vector<double> m_transX;
std::vector<double> m_transY;
std::vector<double> m_spacecraftVelocity;
Expand All @@ -356,6 +356,10 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM {
double m_startingDetectorLine;
std::string m_targetName;
std::string m_modelName;
std::string m_sensorName;
std::string m_platformName;
std::string m_imageIdentifier;
std::string m_collectionIdentifier;
double m_ifov;
std::string m_instrumentID;
double m_focalLengthEpsilon;
Expand All @@ -369,6 +373,8 @@ class UsgsAstroFrameSensorModel : public csm::RasterGM {
int m_nSamples;
int m_nParameters;

csm::EcefCoord m_referencePointXyz;

json _state;
static const int _NUM_STATE_KEYWORDS;
static const int NUM_PARAMETERS;
Expand Down
Loading

0 comments on commit a3d433c

Please sign in to comment.