Unverified Commit 6bea53b7 authored by kledmundson's avatar kledmundson Committed by GitHub
Browse files

Cnetthinner application bug fix resolving divide by zero in CnetManager.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.
parent 9e135db4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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)
@@ -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)
+109 −110
Original line number Diff line number Diff line
@@ -27,9 +27,6 @@ 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 {
@@ -92,7 +89,7 @@ namespace Isis {
    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
@@ -109,8 +106,10 @@ 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) ) );
+28 −29
Original line number Diff line number Diff line
@@ -30,11 +30,7 @@ find files of those names at the top level of this repository. **/
#include "ControlNet.h"
#include "ControlPoint.h"
#include "ControlMeasure.h"
#include "ControlMeasureLogData.h"


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

namespace Isis {

@@ -48,6 +44,12 @@ namespace Isis {
   * @internal
   *   @history 2016-09-30 Kris Becker - Original Version
   *   @history 2016-12-28 Kristin Berry - Added documentation and tests for checkin
   *   @history 2020-01-20 Kris Becker - Fix failed assert/abort in point depth
   *                            weight calculation
   *   @history 2023-11-28 Ken Edmundson - Moved Kris Beckers fix of 2020-01-20 from
   *                            UofA code base to USGS code base. Removed all BOOST
   *                            ASSERTS from CnetManager.cpp;h per Kris' suggestion.
   *                            Removed all unused #include.
   *
   */
  class KPoint {
@@ -104,13 +106,12 @@ namespace Isis {

    private:
      ControlPoint *m_point; //! The original ControlPoint used to construct the KPoint.
      double        m_strength; //! The calulated strength of this KPoint.
      double        m_strength; //! The calculated strength of this KPoint.
      int           m_sourceIndex; //! The original index of this KPoint.
      int           m_index; //! The calculated index of this KPoint.
      bool          m_selected; //! Flag to indicated whether to use this KPoint or not.

      double calculateStrength(const ControlPoint *point, const double &weight) const;

  };


@@ -169,8 +170,6 @@ namespace Isis {
            return  ( a.strength() >  b.strength() );
          }
      };


  };


+222 −211
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ find files of those names at the top level of this repository. **/
#include <QPair>
#include <QRectF>
#include <QSizeF>
#include <QSharedPointer>
#include <QString>
#include <QStringList>

@@ -27,9 +26,6 @@ find files of those names at the top level of this repository. **/
#include "IException.h"
#include "Progress.h"

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

#define EARLY_TERMINATION  true
#define RADIUS_CELLS        100

@@ -46,7 +42,7 @@ namespace Isis {
                                       m_area() { }

  /**
 * Constructs a CentSuppression object using a filename and a weight.
   * Constructs a CnetSuppression object using a filename and a weight.
   *
   * @param cnetfile Filename of the controlnet file.
   * @param weight Weight to apply to all points in controlnet.
@@ -59,6 +55,7 @@ namespace Isis {
                                   m_area() {

    Progress progress;

    try {
      m_cnet.reset(new ControlNet(cnetfile, &progress));
    }
@@ -71,6 +68,25 @@ namespace Isis {
  }


  /**
   * Constructs a CnetSuppression object using a QSharedPointer to a
   * ControlNet object and a weight.
   *
   * @param cnet QSharedPointer to ControlNet object.
   * @param weight Weight to apply to all points in ControlNet.
   */
  CnetSuppression::CnetSuppression(QSharedPointer<ControlNet> &cnet, const double &weight) :
                                   CnetManager( ), m_cnet(), m_points(), m_results(),
                                   m_early_term(EARLY_TERMINATION),
                                   m_area() {

    m_cnet = cnet;

    m_points = m_cnet->take();
    load(m_points, weight);
  }


  /**
   * Constructs a CnetSuppression object using a CnetManager
   *
@@ -85,18 +101,14 @@ namespace Isis {

  /**
   *
 * Destructor. Cleans up dynamically allocated control points.
   * Destructor.
   *
   */
   CnetSuppression::~CnetSuppression() {
     BOOST_FOREACH ( ControlPoint *p, m_points ) {
       delete p;
     }
   }
  CnetSuppression::~CnetSuppression() { }


  /**
 * Sets the early termiation flag
   * Sets the early termination flag
   *
   * @param state Will terminate early if true
   */
@@ -357,9 +369,9 @@ namespace Isis {
   * Write out a Results object to an output control network.
   *
   * @param onetfile Filename for output control network
 * @param result Object containin the results of a suppression calculation
   * @param result Object containing the results of a suppression calculation
   * @param saveall If true, copies all points to the output control net, even if ignored.
 * @param netid Control networkd id
   * @param netid Control network id
   */
  void CnetSuppression::write(const QString &onetfile, const Results &result,
                              const bool saveall, const QString &netid) {
@@ -439,8 +451,8 @@ namespace Isis {
   * @param nbits The size of a BitMask to create.
   * @param p The PointSet used to create a BitMask.
   *
 * @return @b CnetSuppression::BitMask A bit mask with entires set to true if their index is in the
 *                             input PointSet.
   * @return @b CnetSuppression::BitMask A bit mask with entires set to true if their index is in
   *                             the input PointSet.
   */
  CnetSuppression::BitMask CnetSuppression::maskPoints(int nbits,
                                                        const CnetSuppression::PointSet &p)
@@ -468,7 +480,6 @@ namespace Isis {
    PointSet result;
    if ( bm.dim1() == 0 ) { return (result); }


    BOOST_FOREACH ( const IndexPoint &p, pset) {
      BOOST_ASSERT ( index(p) < bm.dim1() );
      if ( bm[index(p)] == true) {
@@ -502,8 +513,8 @@ namespace Isis {
   *
   * @param grid The grid to calculate the number of covered points from.
   *
 * @return @b int The number of convered points; the number of (x,y) positions for which the bitmask
 *                is set to true.
   * @return @b int The number of convered points; the number of (x,y) positions for which the
   *                bitmask is set to true.
   */
  int CnetSuppression::nCovered(const CnetSuppression::GridMask &grid) const {
    int ncov(0);
+3 −3
Original line number Diff line number Diff line
@@ -24,10 +24,8 @@ find files of those names at the top level of this repository. **/
#include <boost/foreach.hpp>

#include "CnetManager.h"
#include "Progress.h"

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

namespace Isis {

@@ -41,6 +39,7 @@ namespace Isis {
 *   @history 2016-12-28 Kristin Berry - Added documentation and tests for checkin
 *   @history 2017-08-09 Summer Stapleton - Added a try-catch in constructor to throw proper
 *                         error for invalid control net. Fixes #5068.
 *   @history 2023-11-28 Ken Edmundson - Removed all BOOST_ASSERTS and unnecessary #includes.
 *
 */
  class CnetSuppression : public CnetManager {
@@ -123,6 +122,7 @@ namespace Isis {

      CnetSuppression();
      CnetSuppression(const QString &cnetfile, const double &weight = 0.0);
      CnetSuppression(QSharedPointer<ControlNet> &cnet, const double &weight = 0.0);
      CnetSuppression(const CnetManager &cman);

      virtual ~CnetSuppression();
@@ -152,7 +152,7 @@ namespace Isis {
      const ControlNet *net() const;

    private:
      QScopedPointer<ControlNet> m_cnet; //!
      QSharedPointer<ControlNet> m_cnet; //!
      QList<ControlPoint *>      m_points; //!
      BitMask                    m_saved; //!
      QVector<Results>           m_results; //!
Loading