Skip to content

Commit b861a95

Browse files
authored
Proj Speed Up (#479)
* Moved around model construction * Added verbose option to usgscsm_cam_test * Cleaned up model instantiation * Fixed warning from getUsgsModel function * Removed commented out code * Removed last line of commented out code * Fix linux builds * Removed m_camera delete on reset * Proj sensor now carries an identifier for the underlying csm model * Added basic projected sensor model tests * Added warning for users using the projected model * Hide dependent library symbols * Defined proj env var * Adjusted proj camera tests for specific OSs * Set proj data dir in tests * Fixed ConstVelocityProjectedSensorModel, RemoteImageLocus test * Removed duplicate comment from other test
1 parent 568ea46 commit b861a95

13 files changed

+566
-133
lines changed

.github/workflows/ci_testing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
branches:
99
- main
1010

11+
env:
12+
PROJ_IGNORE_CELESTIAL_BODY: Yes
13+
1114
jobs:
1215
Build-and-Test-LinuxOsX:
1316
runs-on: ${{ matrix.os }}
@@ -38,6 +41,7 @@ jobs:
3841
run: |
3942
mkdir -p build
4043
cd build
44+
export PROJ_DATA=$PWD/PROJ/data
4145
cmake -DCMAKE_BUILD_TYPE=RELEASE -DUSGSCSM_EXTERNAL_DEPS=OFF -DUSGSCSM_BUILD_DOCS=OFF ..
4246
cmake --build .
4347
- name: Test Package

CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ message(STATUS "CMake Module Path: " ${CMAKE_MODULE_PATH})
77

88
include(GNUInstallDirs)
99

10-
set(CMAKE_CXX_STANDARD 11)
10+
set(CMAKE_CXX_STANDARD 14)
1111

1212
# Set a default build type if none was specified
1313
set(default_build_type "Release")
@@ -17,6 +17,8 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1717
STRING "Choose the type of build." FORCE)
1818
endif()
1919

20+
set(VISIBILITY_INLINES_HIDDEN 1)
21+
2022
# Use external or embedded dependencies
2123
option(USGSCSM_EXTERNAL_DEPS "If the library should be built with external or embedded dependencies" OFF)
2224
option(ENABLE_CURL "Set to build the curl components of proj" OFF)
@@ -61,7 +63,7 @@ if(USGSCSM_EXTERNAL_DEPS)
6163
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
6264

6365
# ALE
64-
find_package(ale REQUIRED)
66+
find_package(ale REQUIRED CONFIG)
6567
set(ALE_TARGET ale::ale)
6668

6769
# Proj
@@ -160,7 +162,7 @@ else()
160162

161163
# default config is shared
162164
option(BUILD_SHARED_LIBS
163-
"Build PROJ library shared." ON)
165+
"Build PROJ library shared." OFF)
164166

165167
find_package(Threads QUIET)
166168
if(Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
@@ -516,7 +518,6 @@ else()
516518
${ALL_LIBPROJ_HEADERS}
517519
${PROJ_RESOURCES}
518520
)
519-
add_library(PROJ::proj ALIAS proj)
520521

521522
if(MSVC OR MINGW)
522523
target_compile_definitions(proj PRIVATE -DNOMINMAX)
@@ -570,7 +571,9 @@ else()
570571

571572
set_target_properties(proj
572573
PROPERTIES
573-
LINKER_LANGUAGE CXX)
574+
LINKER_LANGUAGE CXX
575+
CXX_VISIBILITY_PRESET hidden
576+
)
574577

575578
##############################################
576579
# Link properties
@@ -628,6 +631,7 @@ else()
628631
# ALE
629632
# Use Eigen included with ALE
630633
add_library (eigen INTERFACE)
634+
set_target_properties(eigen PROPERTIES CXX_VISIBILITY_PRESET hidden)
631635
add_library (Eigen3::Eigen ALIAS eigen)
632636
target_include_directories (eigen INTERFACE
633637
${CMAKE_CURRENT_SOURCE_DIR}/ale/eigen)
@@ -643,6 +647,7 @@ else()
643647
${CMAKE_CURRENT_SOURCE_DIR}/ale/src/Vectors.cpp)
644648

645649
add_library(ale OBJECT ${ALE_SOURCE_FILES})
650+
set_target_properties(ale PROPERTIES CXX_VISIBILITY_PRESET hidden)
646651
set(ALE_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/ale/include/ale/")
647652

648653
target_include_directories(ale
@@ -693,10 +698,12 @@ target_include_directories(usgscsm
693698
)
694699

695700
target_link_libraries(usgscsm
701+
PUBLIC
702+
nlohmann_json::nlohmann_json
696703
${CSM_LIBRARY}
697704
${ALE_TARGET}
698-
${PROJ_TARGET}
699-
nlohmann_json::nlohmann_json)
705+
PRIVATE
706+
${PROJ_TARGET})
700707

701708
add_executable(usgscsm_cam_test bin/usgscsm_cam_test.cc)
702709
target_link_libraries(usgscsm_cam_test
@@ -718,6 +725,7 @@ if(USGSCSM_BUILD_TESTS)
718725
find_package (Threads)
719726

720727
target_link_libraries(usgscsm
728+
PUBLIC
721729
gtest ${CMAKE_THREAD_LIBS_INIT})
722730
include(CTest)
723731
enable_testing()

bin/usgscsm_cam_test.cc

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ struct Options {
2828
std::string modify_sup_file; // the .sup file needing a modified model state
2929
std::string output_model_state; // the output model state in .json format
3030
int sample_rate;
31+
bool verbose;
3132
double subpixel_offset, height_above_datum, desired_precision;
32-
Options(): sample_rate(0), subpixel_offset(0.0), height_above_datum(0.0), desired_precision(0.0)
33+
Options(): sample_rate(0), subpixel_offset(0.0), height_above_datum(0.0), desired_precision(0.0), verbose(false)
3334
{}
3435
};
3536

@@ -45,10 +46,15 @@ bool parseOptions(int argc, char **argv, Options & opt) {
4546

4647
std::vector<std::string> params;
4748
for (int it = 1; it < argc; it++) {
48-
if (std::string(argv[it]) == std::string("--help")) {
49+
std::string arg = std::string(argv[it]);
50+
if (arg == std::string("--help")) {
4951
printUsage(argv[0]);
5052
return false;
5153
}
54+
if (arg == std::string("--verbose") || arg == std::string("-v")) {
55+
opt.verbose = true;
56+
continue;
57+
}
5258
params.push_back(argv[it]);
5359
}
5460

@@ -132,7 +138,8 @@ double pixDiffNorm(csm::ImageCoord const& a, csm::ImageCoord const& b) {
132138

133139
// Load a CSM camera model from an ISD or state file. Return true on success.
134140
bool loadCsmCameraModel(std::string const& model_file,
135-
std::shared_ptr<csm::RasterGM> & model) {
141+
std::shared_ptr<csm::RasterGM> & model,
142+
Options & opt) {
136143

137144
// This is needed to trigger loading libusgscsm.so. Otherwise 0
138145
// plugins are detected.
@@ -163,10 +170,11 @@ bool loadCsmCameraModel(std::string const& model_file,
163170

164171
// First try to construct the model from isd, and if that fails, from the state
165172
csm::Model *csm = NULL;
166-
csm::WarningList* warnings = NULL;
173+
csm::WarningList *warnings = new csm::WarningList;
167174
for (size_t i = 0; i < num_models; i++) {
168175

169176
std::string model_name = (*iter)->getModelName(i);
177+
170178
if (csm_plugin->canModelBeConstructedFromISD(isd, model_name, warnings)) {
171179
// Try to construct the model from the isd
172180
csm = csm_plugin->constructModelFromISD(isd, model_name, warnings);
@@ -180,10 +188,20 @@ bool loadCsmCameraModel(std::string const& model_file,
180188
<< model_file << ".\n";
181189
success = true;
182190
} else {
183-
// No luck so far
191+
if (opt.verbose) {
192+
std::string startStr = "<<<<<< Warnings from " + model_name + " <<<<<<";
193+
std::cout << startStr << std::endl;
194+
for (auto warning : *warnings)
195+
std::cout << warning.getMessage() << std::endl;
196+
std::string endStr(startStr.size(), '<');
197+
std::cout << endStr << std::endl;
198+
}
199+
warnings->clear();
184200
continue;
185201
}
186202

203+
delete warnings;
204+
187205
csm::RasterGM *modelPtr = dynamic_cast<csm::RasterGM*>(csm);
188206
if (modelPtr == NULL) {
189207
// Normally earlier checks should be enough and this should not happen
@@ -192,6 +210,7 @@ bool loadCsmCameraModel(std::string const& model_file,
192210
} else {
193211
// Assign to a smart pointer which will handle deallocation
194212
model = std::shared_ptr<csm::RasterGM>(modelPtr);
213+
std::cout << "Final model: " << model->getModelName() << std::endl;
195214
break;
196215
}
197216
}
@@ -240,7 +259,7 @@ int main(int argc, char **argv) {
240259
// specific model types inherit.
241260
std::shared_ptr<csm::RasterGM> model;
242261

243-
if (!loadCsmCameraModel(opt.model, model))
262+
if (!loadCsmCameraModel(opt.model, model, opt))
244263
return 1;
245264

246265
if (opt.output_model_state != "") {

include/usgscsm/UsgsAstroPluginSupport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <RasterGM.h>
55
#include <csm/Plugin.h>
66

7-
csm::RasterGM *getUsgsCsmModel(const std::string &stringIsd, const std::string &modelName, csm::WarningList *warnings);
7+
csm::RasterGM *getUsgsCsmModelFromIsd(const std::string &stringIsd, const std::string &modelName, csm::WarningList *warnings);
8+
csm::RasterGM *getUsgsCsmModelFromState(const std::string &stringState, const std::string &modelName, csm::WarningList *warnings);
89

910
#endif // INCLUDE_USGSCSM_USGSASTROPLUGINSUPPORT_H_

include/usgscsm/UsgsAstroProjectedSensorModel.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838

3939
#include "spdlog/spdlog.h"
4040

41+
#include <proj.h>
42+
4143
#include "UsgsAstroLsSensorModel.h"
4244

4345
class UsgsAstroProjectedSensorModel : public csm::RasterGM,
@@ -66,14 +68,19 @@ class UsgsAstroProjectedSensorModel : public csm::RasterGM,
6668
// in the input state string.
6769
static std::string getModelNameFromModelState(const std::string &model_state);
6870

69-
std::string constructStateFromIsd(const std::string imageSupportData,
71+
std::string constructStateFromIsd(const std::string imageSupportData,
72+
const std::string modelName,
7073
csm::WarningList *list);
7174

7275
// State data elements;
7376
double m_majorAxis;
7477
double m_minorAxis;
78+
PJ *m_isdProj = NULL;
79+
PJ *m_ecefProj = NULL;
80+
PJ *m_isdProj2ecefProj = NULL;
7581
std::vector<double> m_geoTransform;
7682
std::string m_projString;
83+
std::string m_subModelName;
7784

7885
// Define logging pointer and file content
7986
std::shared_ptr<spdlog::logger> m_logger = spdlog::get("usgscsm_logger");
@@ -822,7 +829,7 @@ class UsgsAstroProjectedSensorModel : public csm::RasterGM,
822829
//<
823830

824831
protected:
825-
csm::RasterGM *m_camera;
832+
csm::RasterGM *m_camera = NULL;
826833
};
827834

828835
#endif // INCLUDE_USGSCSM_USGSASTROPROJECTEDSENSORMODEL_H_

src/UsgsAstroPlugin.cpp

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -329,34 +329,29 @@ csm::Model *UsgsAstroPlugin::constructModelFromISD(
329329
MESSAGE_LOG(spdlog::level::info, "Running constructModelFromISD");
330330
std::string stringIsd = loadImageSupportData(imageSupportDataOriginal);
331331

332-
csm::Model *model = getUsgsCsmModel(stringIsd, modelName, warnings);
333-
334332
// Try to get the projected model, if not return the the unprojected model
333+
UsgsAstroProjectedSensorModel *projModel = new UsgsAstroProjectedSensorModel();
334+
335335
try {
336-
UsgsAstroProjectedSensorModel *projModel = new UsgsAstroProjectedSensorModel();
337-
try {
338-
MESSAGE_LOG(spdlog::level::debug, "Trying to construct a UsgsAstroProjectedSensorModel");
339-
projModel->replaceModelState(
340-
projModel->constructStateFromIsd(stringIsd, warnings));
341-
MESSAGE_LOG(spdlog::level::debug, "Constructed model: {}", modelName);
342-
return projModel;
343-
} catch (std::exception &e) {
344-
delete projModel;
345-
csm::Error::ErrorType aErrorType =
346-
csm::Error::SENSOR_MODEL_NOT_CONSTRUCTIBLE;
347-
std::string aMessage = "Could not construct model [";
348-
aMessage += modelName;
349-
aMessage += "] with error [";
350-
aMessage += e.what();
351-
aMessage += "]";
352-
MESSAGE_LOG(spdlog::level::err, aMessage);
353-
std::string aFunction = "UsgsAstroPlugin::getUsgsCsmModel()";
354-
throw csm::Error(aErrorType, aMessage, aFunction);
355-
}
356-
} catch(std::exception &e) {
357-
MESSAGE_LOG(spdlog::level::info, "Failed to make projected model with error: \n{}", e.what());
358-
return model;
336+
MESSAGE_LOG(spdlog::level::debug, "Trying to construct a UsgsAstroProjectedSensorModel");
337+
projModel->replaceModelState(
338+
projModel->constructStateFromIsd(stringIsd, modelName, warnings));
339+
MESSAGE_LOG(spdlog::level::debug, "Constructed model: {}", modelName);
340+
return projModel;
341+
} catch (std::exception &e) {
342+
delete projModel;
343+
csm::Error::ErrorType aErrorType =
344+
csm::Error::SENSOR_MODEL_NOT_CONSTRUCTIBLE;
345+
std::string aMessage = "Could not construct model [";
346+
aMessage += modelName;
347+
aMessage += "] with error [";
348+
aMessage += e.what();
349+
aMessage += "]";
350+
MESSAGE_LOG(spdlog::level::err, aMessage);
359351
}
352+
353+
csm::Model *model = getUsgsCsmModelFromIsd(stringIsd, modelName, warnings);
354+
return model;
360355
}
361356

362357
csm::Model *UsgsAstroPlugin::constructModelFromState(
@@ -366,29 +361,15 @@ csm::Model *UsgsAstroPlugin::constructModelFromState(
366361
std::string modelName = state["m_modelName"];
367362
MESSAGE_LOG(spdlog::level::debug, "Using model name: {}", modelName);
368363

369-
if (modelName == UsgsAstroFrameSensorModel::_SENSOR_MODEL_NAME) {
370-
MESSAGE_LOG(spdlog::level::debug, "Constructing a UsgsAstroFrameSensorModel");
371-
UsgsAstroFrameSensorModel *model = new UsgsAstroFrameSensorModel();
372-
model->replaceModelState(modelState);
373-
return model;
374-
} else if (modelName == UsgsAstroLsSensorModel::_SENSOR_MODEL_NAME) {
375-
MESSAGE_LOG(spdlog::level::debug, "Constructing a UsgsAstroLsSensorModel");
376-
UsgsAstroLsSensorModel *model = new UsgsAstroLsSensorModel();
377-
model->replaceModelState(modelState);
378-
return model;
379-
} else if (modelName == UsgsAstroProjectedSensorModel::_SENSOR_MODEL_NAME) {
380-
MESSAGE_LOG(spdlog::level::debug, "Constructing a UsgsAstroProjectedSensorModel");
381-
UsgsAstroProjectedSensorModel *model = new UsgsAstroProjectedSensorModel();
382-
model->replaceModelState(modelState);
383-
return model;
384-
}else if (modelName == UsgsAstroSarSensorModel::_SENSOR_MODEL_NAME) {
385-
MESSAGE_LOG(spdlog::level::debug, "Constructing a UsgsAstroSarSensorModel");
386-
UsgsAstroSarSensorModel *model = new UsgsAstroSarSensorModel();
387-
model->replaceModelState(modelState);
388-
return model;
389-
} else {
364+
try {
365+
return getUsgsCsmModelFromState(modelState, modelName, warnings);
366+
}
367+
catch (std::exception &e) {
390368
csm::Error::ErrorType aErrorType = csm::Error::ISD_NOT_SUPPORTED;
391-
std::string aMessage = "Model" + modelName + " not supported: ";
369+
std::string aMessage = "Model " + modelName + " not supported";
370+
aMessage += " with error: [";
371+
aMessage += e.what();
372+
aMessage += "]";
392373
std::string aFunction = "UsgsAstroPlugin::constructModelFromState()";
393374
MESSAGE_LOG(spdlog::level::err, aMessage);
394375
throw csm::Error(aErrorType, aMessage, aFunction);

0 commit comments

Comments
 (0)