Commit 5e1f4b7c authored by Kristin Berry's avatar Kristin Berry
Browse files

Minor fix to ControlPoint and addition of take() method to ControlNet to...

Minor fix to ControlPoint and addition of take() method to ControlNet to support efficiently combing control networks. Fixes #2392

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6571 41f8697f-d340-4b68-9986-7bafba869bb8
parent f0e26f08
Loading
Loading
Loading
Loading
+75 −7
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ namespace Isis {
    pointIds = new QStringList;

    p_invalid = false;
    m_ownPoints = true; 
    p_created = Application::DateTime();
    p_modified = Application::DateTime();
  }
@@ -73,6 +74,8 @@ namespace Isis {
      AddPoint(newPoint);
    }

    m_ownPoints = true; 

    p_targetName = other.p_targetName;
    p_targetRadii = other.p_targetRadii;
    p_networkId = other.p_networkId;
@@ -100,20 +103,50 @@ namespace Isis {
    pointIds = new QStringList;

    p_invalid = false;
    m_ownPoints = true;
    ReadControl(ptfile, progress);
  }


 /**
  *  @brief Destructor removes allocated memory
  * 
  * @author Kris Becker 
  */
  ControlNet::~ControlNet() {
    clear();

    delete points;
    delete cubeGraphNodes;
    delete pointIds;

    nullify(); 
  }
 

 /**
  *  @brief Clear the contents of this object
  * 
  *  The contents of the ControlNet object are deleted. The internal variables
  *  that hold the contents are not. See the destructor.
  * 
  * @author Kris Becker
  */
  void ControlNet::clear() {

    // Now must also own points to delete them. 
    if ( points ) {
      if ( GetNumPoints() > 0 ) {
        if ( m_ownPoints ) {
          QHashIterator<QString, ControlPoint*> i(*points); 
          while (i.hasNext()) {
            i.next();
            delete(*points)[i.key()];
            (*points)[i.key()] = NULL;
          }
      delete points;
      points = NULL;
        }
      }
      points->clear();
    }

    if (cubeGraphNodes) {
@@ -123,16 +156,51 @@ namespace Isis {
        delete(*cubeGraphNodes)[i.key()];
        (*cubeGraphNodes)[i.key()] = NULL;
      }
      delete cubeGraphNodes;
      cubeGraphNodes = NULL;
      cubeGraphNodes->clear();
    }

    if (pointIds) {
      delete pointIds;
      pointIds = NULL;
      pointIds->clear();
    }
 
    m_mutex = NULL;
    return;
  }


  /**
   * @brief Transfer ownership of all points to caller 
   *  
   * This method is used to transfer ownership to the caller. This method is not 
   * reintrant in the sense that if someone else has already made this call, it is 
   * an error to attempt to take ownership again. 
   *  
   * Note that it now becomes the responsibility of the caller to delete all the 
   * pointers to ControlPoints that are returned in the list. 
   *  
   * WARNING!!! This call alone can create a situation where the owner could 
   * delete point memory after the point list is exported from this class creating
   * a problem. For this reason, the clear() method be called!!!
   * 
   * @author Kris Becker 
   * 
   * @return QList<ControlPoint*> Returns the list of all control points to caller
   */
    QList< ControlPoint * > ControlNet::take() {
      // First check to see if someone else has taken ownership
      if ( !m_ownPoints ) {
        throw IException(IException::Programmer, "Ownership has already been taken",
                         _FILEINFO_);
      }

      QList<ControlPoint *> points = GetPoints();
      m_ownPoints = false;
      clear();

      // Disconnect the parent network reference
      for (int i = 0 ; i < points.size() ; i++) {
        points[i]->parentNetwork = NULL;
      }
      return (points);
    }


+10 −2
Original line number Diff line number Diff line
@@ -183,8 +183,12 @@ namespace Isis {
   *                           was expecting the method GetNumberOfMeasuresInImage to only return
   *                           the number of VALID (Ignore=False) measures.  Renamed
   *                           method to GetNumberOfValidMeasuresInImage and the private
   *                           variable p_cameraMeasuresMap to p_cameraValidMeasuresMap.
   *                           References #1603.
   *                           variable p_cameraMeasuresMap to p_cameraValidMeasuresMap. References
   *                           #1603.
   *    @history 2016-02-15 Kris Becker - Added feature to take ownership of
   *                           points from ControlNet. To support this option,
   *                           added clear() and take() methods.
   *                           (Merged by Kristin Berry. References #2392)
   */
  class ControlNet : public QObject {
      Q_OBJECT
@@ -199,6 +203,9 @@ namespace Isis {

      ~ControlNet();

      void clear();
      QList< ControlPoint * > take();

      void ReadControl(const QString &filename, Progress *progress = 0);
      void Write(const QString &filename, bool pvl = false);

@@ -414,6 +421,7 @@ namespace Isis {
      std::vector<Distance> p_targetRadii;        //!< Radii of target body

      bool p_invalid;  //!< If the Control Network is currently invalid
      bool m_ownPoints; //!< Specifies ownership of point list. True if owned by this object. 
  };
}

+7 −0
Original line number Diff line number Diff line
@@ -360,3 +360,10 @@ Testing MinimumSpanningTree()
    Included Measures = 0
    Excluded Measures = 1
      m9 (EPSILON -> p5, residual = 1.41421)

Testing take() functionality to take owernship of the points in a ControlNet:
Original control net number of points: 1
Number of points taken out: 1
Now there should be zero points in the original control net. There are: 0
And zero pointIDs in the original control net. There are: 0
And zero cubeGraphNodes in the original control net. There are: 0
+17 −0
Original line number Diff line number Diff line
@@ -458,6 +458,23 @@ int main() {

  testConnectivity();

  cout << "\nTesting take() functionality to take owernship of the points in a ControlNet:" << endl;

  cout << "Original control net number of points: " << QString::number(net.GetNumPoints()) << endl; 

  QList<ControlPoint*> points = net.take(); 
  
  cout << "Number of points taken out: " << QString::number(points.length()) << endl; 
  
  cout << "Now there should be zero points in the original control net. There are: " 
       << QString::number(net.GetNumPoints()) << endl; 

  cout << "And zero pointIDs in the original control net. There are: " 
       << QString::number(net.GetPointIds().length()) << endl; 

  cout << "And zero cubeGraphNodes in the original control net. There are: " 
       << QString::number(net.GetCubeGraphNodes().length()) << endl; 

  //system("cat unitTest.output | grep -v DateTime > temp.output; mv temp.output unitTest.output");
  //system("cat unitTest.output | sed -r s/`date +%Y-%m-%dT`\\[0-9:\\]\\{8\\}/2010-08-27T17:10:06/g > temp.output; mv temp.output unitTest.output");

+2 −1
Original line number Diff line number Diff line
@@ -117,10 +117,11 @@ namespace Isis {
   *
   * @history 2008-06-18  Debbie A. Cook, Swapped Init with SetRadii
   *          calls to avoid resetting the surface points with no radii
   * @history 2015-11-03  Kris Becker - invalid flag was not being initialized
   */
  ControlPoint::ControlPoint(const ControlPointFileEntryV0002 &fileEntry,
      const Distance &majorRad, const Distance &minorRad,
      const Distance &polarRad) {
      const Distance &polarRad) : invalid(false)  {
    measures = NULL;
    cubeSerials = NULL;
    referenceMeasure = NULL;
Loading