Skip to content

Commit

Permalink
Cnetthinner application bug fix resolving divide by zero in CnetManag…
Browse files Browse the repository at this point in the history
…er.cpp. (#5356)

* Bug fix for a divide by zero in CnetManager.cpp. Additionally, the cnetthinner app has been converted to a callable function and Makefile tests converted to gtests. Addresses #5354.

* Updated CHANGELOG.md. Addresses #5354.

* Minor change to cnetthinner.xml. Addresses #5354.
  • Loading branch information
kledmundson authored Dec 4, 2023
1 parent 9e135db commit 6bea53b
Show file tree
Hide file tree
Showing 18 changed files with 19,268 additions and 515 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ release.
## [Unreleased]

### Changed
- Cnetthinner has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5354](https://github.com/USGS-Astrogeology/ISIS3/issues/5354),
- Cnetedit has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5346](https://github.com/USGS-Astrogeology/ISIS3/issues/5346),
- Cnetdiff has been refactored to be callable; old Makefile tests have been removed and replaced by gtests. Issue: [#5322](https://github.com/USGS-Astrogeology/ISIS3/issues/5322),
- Removed the `.py` extention from the _isisdataeval_ tool `isisdata_mockup` for consistency and install it in $ISISROOT/bin; added the `--tojson` and `--hasher` option to _isisdata_mockup_ tool improve utility; updated the tool `README.md` documentation to reflect this change, removed help output and trimmed example results; fixed paths to test data in `make_isisdata_mockup.sh`. [#5163](https://github.com/DOI-USGS/ISIS3/pull/5163)
Expand Down Expand Up @@ -67,6 +68,7 @@ release.
### Removed

### Fixed
- Bug fix for Cnetthinner app resolving divide by zero in CnetManager.cpp. Issue: [#5354](https://github.com/USGS-Astrogeology/ISIS3/issues/5354),
- Updated photomet MinnaertEmpirical model to support photemplate-style PVL format [#3621](https://github.com/DOI-USGS/ISIS3/issues/3621)
- Fix matrix inversion errors in <i>findfeatures</i> due to bad FASTGEOM matrix transforms using a more robust implementation to detect these errors and throw exceptions. Images with these errors are captured and logged to the <b>TONOTMATCHED</b> file. Fixes [#4639](https://github.com/DOI-USGS/ISIS3/issues/4639)
- Fixed <i>findfeatures</i> use of projected mosaics with correct check for <b>TargetName</b> in the Mapping labels. [#4772](https://github.com/DOI-USGS/ISIS3/issues/4772)
Expand Down
219 changes: 109 additions & 110 deletions isis/src/control/apps/cnetthinner/CnetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ find files of those names at the top level of this repository. **/
#include "ControlMeasure.h"
#include "ControlMeasureLogData.h"

#include "tnt/tnt_array2d.h"
#include "tnt/tnt_array2d_utils.h"

///#define DEBUG 1

namespace Isis {

// KPoint implementation
// KPoint implementation

/**
* Empty Constructor. Disabled at runtime.
*
*/
/**
* Empty Constructor. Disabled at runtime.
*
*/
KPoint::KPoint() {
m_point = 0;
m_strength = -3;
Expand All @@ -49,14 +46,14 @@ namespace Isis {
}


/**
* Constructs a KPoint.
*
* @param point The control point to make a KPoint from.
* @param index The source index.
* @param weight The point's weight.
*
*/
/**
* Constructs a KPoint.
*
* @param point The control point to make a KPoint from.
* @param index The source index.
* @param weight The point's weight.
*
*/
KPoint::KPoint(ControlPoint *point, const int &index, const double &weight) {
BOOST_ASSERT ( point != 0 );
m_point = point;
Expand All @@ -66,40 +63,40 @@ namespace Isis {
}


/**
* Set the status of the KPoint to true for selected or
* false for unselected.
*
* @param state If true, the KPoint is set to selected.
*/
/**
* Set the status of the KPoint to true for selected or
* false for unselected.
*
* @param state If true, the KPoint is set to selected.
*/
void KPoint::select(const bool &state) {
m_selected = state;
}


/**
* Calculate the strength of a control point. A negative return value indicates
* an invalid result.
*
* @param point
* @param weight
*
* @return double
*/
/**
* Calculate the strength of a control point. A negative return value indicates
* an invalid result.
*
* @param point
* @param weight
*
* @return double
*/
double KPoint::calculateStrength(const ControlPoint *point,
const double &weight) const {
const double &weight) const {
// Gut check for validity
if ( !point ) return (-2.0);

// Don't use points which have only 1 valid measure or fewer, since
// we don't use refIncides in the strength calculation.
// we don't use reference measures in the strength calculation.
if ( point->GetNumValidMeasures() < 2.0 ) return (-1.0);

// Got some good ones, compute strength
double sum(0.0);
int count(0);
int refIndex = point->IndexOfRefMeasure();
for ( int i = 0 ; i < point->GetNumMeasures() ; i++) {
for (int i = 0 ; i < point->GetNumMeasures(); i++) {
if ( i != refIndex ) { // Check all but the reference measure
const ControlMeasure *m = point->GetMeasure(i);
if ( !m->IsIgnored() && m->HasLogData(ControlMeasureLogData::GoodnessOfFit) ) {
Expand All @@ -109,60 +106,62 @@ namespace Isis {
}
}

// Check for valid count
if ( count <= 0 ) return ( 0 );

// Compute the weighted strength
BOOST_ASSERT ( count > 0 );
double v_count(count);
double v_strength = sum / v_count;
return ( v_strength * ( 1.0 + (qLn(v_count) * weight) ) );
}

// CnetManager implementation
// CnetManager implementation

/**
* Constructs an emtpy CnetManager.
*
*/
/**
* Constructs an emtpy CnetManager.
*
*/
CnetManager::CnetManager() : m_kpts() { }


/**
* Constructs a CnetManager using an input control network and a weight.
*
* @param cnet Input control network to be managed.
* @param weight Weights to apply to the control network.
*/
/**
* Constructs a CnetManager using an input control network and a weight.
*
* @param cnet Input control network to be managed.
* @param weight Weights to apply to the control network.
*/
CnetManager::CnetManager(ControlNet &cnet, const double &weight) {
load(cnet.GetPoints(), weight);
}


/**
*
* Default Destructor
*
*/
/**
*
* Default Destructor
*
*/
CnetManager::~CnetManager() { }


/**
* The number of points managed by CnetManager.
*
* @return @b int The number of points in this CnetManager.
*/
int CnetManager::size() const {
/**
* The number of points managed by CnetManager.
*
* @return @b int The number of points in this CnetManager.
*/
int CnetManager::size() const {
return ( m_kpts.size() );
}


/**
* Loads a list of control points into the CnetManager.
*
* @param pts The QList of ControlPoints to load into the CnetManager.
* @param weight The weight to apply to each ControlPoint in the list.
*
* @return @b int The number of ControlPoints loaded into the CnetManager.
*/
int CnetManager::load(const QList<ControlPoint *> &pts, const double &weight) {
/**
* Loads a list of control points into the CnetManager.
*
* @param pts The QList of ControlPoints to load into the CnetManager.
* @param weight The weight to apply to each ControlPoint in the list.
*
* @return @b int The number of ControlPoints loaded into the CnetManager.
*/
int CnetManager::load(const QList<ControlPoint *> &pts, const double &weight) {
m_kpts.clear();

for (int i = 0; i < pts.size(); i++) {
Expand All @@ -176,7 +175,7 @@ namespace Isis {
qSort(m_kpts.begin(), m_kpts.end(), SortStrengthDescending());

#if defined(DEBUG)
for (int p = 0 ; p < qMin(m_kpts.size(), 5) ; p++) {
for (int p = 0; p < qMin(m_kpts.size(), 5); p++) {
std::cout << "Point: " << p << " - Strength: " << m_kpts[p].strength() << "\n";
}
#endif
Expand All @@ -190,12 +189,12 @@ namespace Isis {
}


/**
* Get a list of control points in this CnetManager.
*
* @return @b const QList<ControlPoint*> List of control points in CnetManager.
*/
const QList<ControlPoint *> CnetManager::getControlPoints() const {
/**
* Get a list of control points in this CnetManager.
*
* @return @b const QList<ControlPoint*> List of control points in CnetManager.
*/
const QList<ControlPoint *> CnetManager::getControlPoints() const {
QList<ControlPoint *> pts;
BOOST_FOREACH ( const KPoint &p, m_kpts ) {
pts.append( p.point() );
Expand All @@ -204,11 +203,11 @@ namespace Isis {
}


/**
* Return a map of the number of measures per cube.
*
* @return @b QMap<QString,int> Serial number, number of measures per that serial number (cube)
*/
/**
* Return a map of the number of measures per cube.
*
* @return @b QMap<QString,int> Serial number, number of measures per that serial number (cube)
*/
QMap<QString, int> CnetManager::getCubeMeasureCount() const {
QMap<QString, int> k_map;
BOOST_FOREACH ( const KPoint &p, m_kpts ) {
Expand All @@ -223,13 +222,13 @@ namespace Isis {
}


/**
* Returns control measures and their associated indicies for a given cube (serial number.)
*
* @param serialNo Serial number (indicates a specific cube) to get the measure indicies for.
*
* @return @b CnetManager::PointSet Data structure containing the calculated index and measure.
*/
/**
* Returns control measures and their associated indicies for a given cube (serial number.)
*
* @param serialNo Serial number (indicates a specific cube) to get the measure indicies for.
*
* @return @b CnetManager::PointSet Data structure containing the calculated index and measure.
*/
CnetManager::PointSet CnetManager::getCubeMeasureIndices(const QString &serialNo) const {
PointSet cubeNdx;
BOOST_FOREACH ( const KPoint &p, m_kpts ) {
Expand All @@ -242,48 +241,48 @@ namespace Isis {
}


/**
* Will return the KPoint at an input index.
*
* @return @b const KPoint& The KPoint at the requested index.
*/
/**
* Will return the KPoint at an input index.
*
* @return @b const KPoint& The KPoint at the requested index.
*/
const KPoint &CnetManager::operator()(const int index) const {
BOOST_ASSERT ( index < m_kpts.size() );
return ( m_kpts.at(index) );
}


/**
*
* Get a point at a specificed index.
*
* @param index Index of the point to get.
*
* @return @b const ControlPoint* The point at the requested index.
*/
/**
*
* Get a point at a specificed index.
*
* @param index Index of the point to get.
*
* @return @b const ControlPoint* The point at the requested index.
*/
const ControlPoint *CnetManager::point(const int &index) const {
BOOST_ASSERT ( index < m_kpts.size() );
return ( m_kpts.at(index).point() );
}


/**
* Gets the list of KPoints managed by this CubeManager.
*
* @return @b const QList<KPoint>& List of KPoints managed by this CnetManager.
*/
/**
* Gets the list of KPoints managed by this CubeManager.
*
* @return @b const QList<KPoint>& List of KPoints managed by this CnetManager.
*/
const QList<KPoint> &CnetManager::pointList() const {
return ( m_kpts );
}


/**
* Get a point at a specificed index.
*
* @param index Index of the point.
*
* @return @b ControlPoint* The point at the requested index.
*/
/**
* Get a point at a specificed index.
*
* @param index Index of the point.
*
* @return @b ControlPoint* The point at the requested index.
*/
ControlPoint *CnetManager::point(const int index) {
BOOST_ASSERT ( index < m_kpts.size() );
return ( m_kpts.at(index).point() );
Expand Down
Loading

0 comments on commit 6bea53b

Please sign in to comment.