Skip to content

Commit d6af8d4

Browse files
authored
CSM plugin updates (#759)
* Fix memory leak * Fix test after breaking changes to nitf::DESubheader * Update CSM plugin to save the state of several more model parameters * Bump version * Change to building against csm 1.3.0 * Method to ensure import when statically linked (for testing) * cmake build of CSM plugin and unit tests * Fix covariance and ap round-trip * Fixing handling of unmodeled error standard deviations * Removing getUnmodeledError() because it is not virtual in the base class and was therefore not being used. New attempt at getUnmodeledCrossCovariance() using the decorrelation parameters, but there is no documentation for guidance. * Fixing Windows builds for CSM unit tests * Stop linking SIX CSM plugin against libCSMAPI.so. This needed symbols will be found in the program loading the plugin. * Address code review requests * Update copyrights * Link windows CSM plugin against CSMAPI dll but linux not against CSMAPI shared object
1 parent 72db134 commit d6af8d4

25 files changed

+1710
-216
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ packages/
2222
target/
2323
target.dbg/
2424
install/
25+
install_waf/
2526
install.dbg/
2627
**/install-*/
2728
test_package/build/

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NGA is working to standardize Synthetic Aperture RADAR (SAR) systems in use thro
77
### Origin
88

99
The SIX (Sensor Independent XML) library was developed at the National Geospatial-Intelligence Agency (NGA) in collaboration
10-
with [Maxar](http://maxar.com) (formerly Radiant Solutions and MDA). The government has "unlimited rights" and is releasing
10+
with [Arka](http://arka.org) (formerly Maxar, Radiant Solutions, and MDA). The government has "unlimited rights" and is releasing
1111
this software to increase the impact of government investments by providing developers with the opportunity to take things
1212
in new directions. The software use, modification, and distribution rights are stipulated within the LGPL 3.0 license.
1313

@@ -17,7 +17,7 @@ is the official reference implementation library for the
1717
[SIDD](https://github.com/ngageoint/six-library/wiki/Sensor-Independent-Derived-Data-(SIDD)-Standard) format. The library
1818
also provides a [sensor model implementation](https://github.com/ngageoint/six-library/wiki) of many equations in the
1919
SICD and SIDD document. This sensor model implementation provides the foundations for the SICD and SIDD
20-
[CSM](https://github.com/sminster/csm) (Community Sensor Model) implementation.
20+
[CSM](https://github.com/ngageoint/csm) (Community Sensor Model) implementation.
2121

2222
It is available as open-source software under the Lesser GNU Public License (LGPL). This license is commonly used in the
2323
open-source community, and allows applications that are not open source to make use of the library without penalty. As with
@@ -26,13 +26,14 @@ other open source projects, the library is available as-is, with no warranty.
2626
See the [manual](https://github.com/ngageoint/six-library/blob/master/docs/six-manual.pdf) for detailed information including
2727
build instructions and API documentation.
2828

29-
A preliminary CMake build system is available on Linux and Windows. See [coda-oss CMake README.md](externals/coda-oss/cmake/README.md)
29+
A CMake build system is available on Linux and Windows. See [coda-oss CMake README.md](externals/coda-oss/cmake/README.md)
3030
and [nitro README.md](externals/nitro/README.md) for information on how to build using CMake. The same configuration options
3131
may be passed to SIX.
3232

3333
The latest version of the library is available at https://github.com/ngageoint/six-library.git.
3434

3535
### Releases
36+
3637
The master is considered stable, but official [releases](https://github.com/ngageoint/six-library/releases) also occur as
3738
major features are added.
3839

@@ -44,5 +45,3 @@ Software source code previously released under an open source license and then m
4445
"joint work" (see 17 USC 101); it is partially copyrighted, partially public domain, and as a whole is protected by the
4546
copyrights of the non-government authors and must be released according to the terms of the original open source license.
4647

47-
### Contact
48-
February 2022, Dan <dot> Smith <at> maxar <dot> <see><oh><em>

six/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory(modules)
2+
add_subdirectory(projects)

six/modules/c++/six.sicd/source/SICDVersionUpdater.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of six.sicd-c++
33
* =========================================================================
44
*
5-
* (C) Copyright 2004 - 2020, MDA Information Systems LLC
5+
* (C) Copyright 2004 - 2025, Arka Group, L.P.
66
*
77
* six.sicd-c++ is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as published by
@@ -179,7 +179,7 @@ void SICDVersionUpdater::updateSingleIncrement()
179179

180180
if (mData.scpcoa)
181181
{
182-
const auto *sceneGeometry = Utilities::getSceneGeometry(&mData);
182+
std::unique_ptr<scene::SceneGeometry> sceneGeometry(Utilities::getSceneGeometry(&mData));
183183
mData.scpcoa->azimAngle = sceneGeometry->getAzimuthAngle();
184184
mData.scpcoa->layoverAngle = sceneGeometry->getETPLayoverAngle();
185185
}

six/modules/c++/six/source/Utilities.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of six-c++
33
* =========================================================================
44
*
5-
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
5+
* (C) Copyright 2004 - 2025, Arka Group, L.P.
66
*
77
* six-c++ is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as published by
@@ -841,11 +841,12 @@ void six::getErrors(const ErrorStatistics* errorStats,
841841
auto&& Ycol = unmodeled.Ycol;
842842
auto&& XrowYcol = unmodeled.XrowYcol;
843843

844-
// From Bill: Here is the mapping from the UnmodeledError to the 2x2 covariance matrix:
845-
// [0][0] = Xrow; [1][1] = Ycol;
844+
// From Bill: Here is the mapping from the UnmodeledError to the 2x2
845+
// covariance matrix:
846+
// [0][0] = Xrow*Xrow; [1][1] = Ycol*Ycol;
846847
// [1][0] = [0][1] = XrowYcol * Xrow * Ycol
847-
unmodeledErrorCovar(0, 0) = Xrow;
848-
unmodeledErrorCovar(1, 1) = Ycol;
848+
unmodeledErrorCovar(0, 0) = math::square(Xrow);
849+
unmodeledErrorCovar(1, 1) = math::square(Ycol);
849850
unmodeledErrorCovar(0, 1) = unmodeledErrorCovar(1, 0) = XrowYcol * Xrow * Ycol;
850851
}
851852
}
@@ -871,7 +872,7 @@ std::filesystem::path six::testing::findRootDir(const std::filesystem::path& dir
871872
{
872873
return externals;
873874
}
874-
875+
875876
const auto parent = dir.parent_path();
876877
return findRootDir(parent);
877878
}
@@ -912,7 +913,7 @@ std::filesystem::path six::testing::getNitfPath(const std::filesystem::path& fil
912913
}
913914

914915
std::vector<std::filesystem::path> six::testing::getSchemaPaths()
915-
{
916+
{
916917
static const auto modulePath = std::filesystem::path("six") / "modules" / "c++" / "six.sicd" / "conf" / "schema";
917918
static const auto filename = getModuleFile(modulePath, "SICD_schema_V1.3.0.xsd");
918919
static const auto schemaPath = filename.parent_path();
@@ -938,8 +939,10 @@ std::unique_ptr<six::Data> six::DataParser::DataParser::fromXML(::io::InputStrea
938939
return six_parseData<std::unique_ptr<Data>>(xmlReg, xmlParser, dataType, mpSchemaPaths, mLog);
939940
}
940941

941-
std::unique_ptr<six::Data> six::DataParser::DataParser::fromXML(const std::filesystem::path& pathname,
942-
const XMLControlRegistry& xmlReg, DataType dataType) const
942+
std::unique_ptr<six::Data> six::DataParser::DataParser::fromXML(
943+
const std::filesystem::path& pathname,
944+
const XMLControlRegistry& xmlReg,
945+
DataType dataType) const
943946
{
944947
io::FileInputStream inStream(pathname.string());
945948
return fromXML(inStream, xmlReg, dataType);

six/projects/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(csm)

six/projects/csm/CMakeLists.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
if (MSVC)
2+
# We are including headers from an external library (CSMAPI) and we can't change it to fix these problems
3+
add_compile_options(/wd4251) # class '...' needs to have dll-interface to be used by clients of class '...'
4+
add_compile_options(/wd4275) # non dll-interface class '...' used as base for dll-interface class '...'
5+
add_compile_options(/wd4267) # conversion from '...' to '...'
6+
add_compile_options(/wd4996) # '...': This function or variable may be unsafe
7+
add_compile_options(/wd4244) # 'return': conversion from '...' to '...'
8+
endif()
9+
10+
add_subdirectory(external)
11+
12+
set(MODULE_NAME csm-plugin)
13+
14+
# construct final plugin filename
15+
file(READ "source/SICDSensorModel.cpp" version_source)
16+
string(REGEX MATCH "SICDSensorModel::VERSION\\(([0-9]), ([0-9]), ([0-9])\\)" _ ${version_source})
17+
set(PLUGIN_VERSION "${CMAKE_MATCH_1}${CMAKE_MATCH_2}${CMAKE_MATCH_3}")
18+
19+
if ("${PLUGIN_VERSION}" STREQUAL "")
20+
message(FATAL_ERROR "Could not extract CSM plugin version string from source code.")
21+
endif()
22+
23+
file(READ "source/SIDDSensorModel.cpp" version_source)
24+
string(REGEX MATCH "SIDDSensorModel::VERSION\\(([0-9]), ([0-9]), ([0-9])\\)" _ ${version_source})
25+
set(PLUGIN_VERSION2 "${CMAKE_MATCH_1}${CMAKE_MATCH_2}${CMAKE_MATCH_3}")
26+
27+
if (NOT "${PLUGIN_VERSION}" STREQUAL "${PLUGIN_VERSION2}")
28+
message(FATAL_ERROR "CSM plugin SICD and SIDD sensor model version numbers should match.")
29+
endif()
30+
31+
message("Extracted CSM plugin version string ${PLUGIN_VERSION} from source")
32+
33+
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
34+
set(PLATFORM_NAME "linux")
35+
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
36+
set(PLATFORM_NAME "win")
37+
else()
38+
message(FATAL_ERROR "Platform not recognized. Unable to determine CSM plugin filename.")
39+
endif()
40+
41+
set(PLUGIN_FILENAME "SIX_SAR_ARKA_${PLUGIN_VERSION}_${PLATFORM_NAME}_CSM${csmapi_VERSION}")
42+
43+
# Build two libraries:
44+
#
45+
# (1) A shared library which is the CSM plugin itself. This receives a special
46+
# name which is the delivered file name.
47+
#
48+
# (2) A static library, which is to only be used for unit testing.
49+
file(GLOB SOURCES source/*.cpp)
50+
51+
# Shared library version (the CSM plugin)
52+
#
53+
# This cannot use coda_add_module because we need to set the final filename so
54+
# it is not libcsm-plugin.so. This means some of these are duplicated from
55+
# CodaBuild.cmake.
56+
add_library(${MODULE_NAME} SHARED ${SOURCES})
57+
target_link_libraries(${MODULE_NAME} scene-c++ six.sicd-c++ six.sidd-c++ CSMAPI)
58+
target_include_directories(${MODULE_NAME} PUBLIC
59+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
60+
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "" OUTPUT_NAME "${PLUGIN_FILENAME}")
61+
62+
# Manually need to create install target
63+
set(CODA_EXPORT_SET_NAME "${CMAKE_PROJECT_NAME}Targets")
64+
install(TARGETS ${MODULE_NAME}
65+
EXPORT ${CODA_EXPORT_SET_NAME}
66+
LIBRARY DESTINATION "share/CSM/plugins/")
67+
68+
# Static library version
69+
#
70+
# The unit test is statically linked against the CSMAPI and the SIX CSM
71+
# functionality. This is the only use for the static version of those two
72+
# libraries. By statically linking them, the unit test can run without any
73+
# problems encountered in needing to specify where the two plugins (CSMAPI and
74+
# SIX_CSM) exist.
75+
set(TARGET_LANGUAGE c++)
76+
coda_add_module(
77+
${MODULE_NAME}-static
78+
SOURCES ${SOURCES}
79+
DEPS scene-c++ six.sicd-c++ six.sidd-c++ CSMAPI-static)
80+
coda_add_tests(
81+
MODULE_NAME ${MODULE_NAME}-static
82+
DIRECTORY "tests")
83+
coda_add_tests(
84+
MODULE_NAME ${MODULE_NAME}-static
85+
DIRECTORY "unittests"
86+
UNITTEST)

six/projects/csm/external/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
csm-3.1.0/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
if (MSVC)
2+
# This is not our code, so we are not going to change it to eliminate these problems
3+
add_compile_options(/wd4251) # class '...' needs to have dll-interface to be used by clients of class '...'
4+
add_compile_options(/wd4275) # non dll-interface class '...' used as base for dll-interface class '...'
5+
add_compile_options(/wd4267) # conversion from '...' to '...'
6+
add_compile_options(/wd4996) # '...': This function or variable may be unsafe
7+
add_compile_options(/wd4244) # 'return': conversion from '...' to '...'
8+
add_compile_options(/wd4005) # '...': macro redefinition
9+
endif()
10+
11+
set(TARGET_NAME CSMAPI)
12+
string(TOLOWER ${TARGET_NAME} target_name_lc)
13+
14+
coda_fetch_driver(
15+
NAME ${TARGET_NAME}
16+
ARCHIVE "csm_v3.1.0.zip"
17+
HASH "SHA256=7c2359f4ec911cedc3bbf6221f8dbe0914479c9af8184f0d79ecc60f6c1d5ad3"
18+
)
19+
20+
set("${target_name_lc}_VERSION" "310" CACHE INTERNAL "version string for ${target_name_lc}")
21+
set(SOURCE_DIR "${${CMAKE_PROJECT_NAME}_${target_name_lc}_SOURCE_DIR}")
22+
23+
file(GLOB SOURCES "${SOURCE_DIR}/*.cpp")
24+
set(CODA_EXPORT_SET_NAME "${CMAKE_PROJECT_NAME}Targets")
25+
26+
if (MSVC)
27+
add_library(${TARGET_NAME} SHARED ${SOURCES})
28+
else()
29+
add_library(${TARGET_NAME} INTERFACE)
30+
endif()
31+
target_include_directories(${TARGET_NAME} INTERFACE
32+
$<BUILD_INTERFACE:${SOURCE_DIR}>
33+
$<INSTALL_INTERFACE:>)
34+
install(TARGETS ${TARGET_NAME})
35+
install(TARGETS ${TARGET_NAME} EXPORT ${CODA_EXPORT_SET_NAME})
36+
37+
# The static version of CSMAPI exists only to support unit tests on the plugin.
38+
# See the comments in the CMakeLists.txt file in the parent directory. Using
39+
# this version for any other purpose will almost surely break the plugin
40+
# functionality.
41+
add_library(${TARGET_NAME}-static ${SOURCES})
42+
target_include_directories(${TARGET_NAME}-static INTERFACE
43+
$<BUILD_INTERFACE:${SOURCE_DIR}>
44+
$<INSTALL_INTERFACE:>)
45+
if (MSVC)
46+
# Define CSM_LIBRARY so the symbols are not marked as being imported from a
47+
# shared library/dll. Fixes Windows link problems where they are expected
48+
# to be defined externally.
49+
target_compile_options(${TARGET_NAME}-static PUBLIC /DCSM_LIBRARY)
50+
endif()
51+
install(TARGETS ${TARGET_NAME}-static EXPORT ${CODA_EXPORT_SET_NAME})
52+
104 KB
Binary file not shown.

0 commit comments

Comments
 (0)