USGS

Isis 3.0 Application Source Code Reference

Home

QnetPointDistanceFilter.cpp

Go to the documentation of this file.
00001 #include "QnetPointDistanceFilter.h"
00002 
00003 #include <QGridLayout>
00004 #include <QList>
00005 #include <QMessageBox>
00006 
00007 #include "Camera.h"
00008 #include "ControlMeasure.h"
00009 #include "ControlNet.h"
00010 #include "Distance.h"
00011 #include "Latitude.h"
00012 #include "Longitude.h"
00013 #include "qnet.h"
00014 #include "QnetNavTool.h"
00015 #include "SerialNumberList.h"
00016 #include "SurfacePoint.h"
00017 
00018 using namespace Isis::Qnet;
00019 
00020 namespace Isis {
00021   /**
00022    * Contructor for the Point Distance filter.  It creates the
00023    * Distance filter window found in the navtool
00024    *
00025    * @param parent The parent widget for the point distance
00026    *               filter
00027    * @internal
00028    *   @history 2008-11-26 Jeannie Walldren - Clarified label for
00029    *                          distance filter value.
00030    *   @history 2010-06-03 Jeannie Walldren - Initialized pointers
00031    *                          to null.
00032    *   @history 2011-03-17 Tracie Sucharski - Changed text on filter gui.
00033    *
00034    */
00035   QnetPointDistanceFilter::QnetPointDistanceFilter(QWidget *parent) : QnetFilter(parent) {
00036     p_lineEdit = NULL;
00037 
00038     // Create the labels and widgets to be added to the main window
00039     QLabel *label = new QLabel("Filter points that are within given distance of another point.");
00040     QLabel *lessThan = new QLabel("Distance to another point is less than");
00041     p_lineEdit = new QLineEdit();
00042     QLabel *meters = new QLabel("meters");
00043     QLabel *pad = new QLabel();
00044 
00045     // Create the layout and add the widgets to the window
00046     QGridLayout *gridLayout = new QGridLayout();
00047     gridLayout->addWidget(label, 0, 0, 1, 2);
00048     gridLayout->addWidget(lessThan, 1, 0);
00049     gridLayout->addWidget(p_lineEdit, 1, 1);
00050     gridLayout->addWidget(meters, 1, 2);
00051     gridLayout->addWidget(pad, 2, 0);
00052     gridLayout->setRowStretch(2, 50);
00053     this->setLayout(gridLayout);
00054   }
00055 
00056   /**
00057    * Filters a list of points for points that are less than the user entered
00058    * distance from another point in the control net.  The filtered list will
00059    * appear in the navtools point list display.
00060    * @internal
00061    *   @history 2008-11-26 Jeannie Walldren - Modified code to
00062    *                          handle case in which the lat/lon of
00063    *                          the point is Null. In this event,
00064    *                          the Camera class will be used to
00065    *                          determine lat/lon/rad for the
00066    *                          reference measure or for the first
00067    *                          measure. Changed variable names for
00068    *                          clarity.  Adjusted inner "for" loop
00069    *                          to reduce number of iterations.
00070    *   @history 2009-01-08 Jeannie Walldren - Modified to replace
00071    *                          existing filtered list with a subset
00072    *                          of that list. Previously, a new
00073    *                          filtered list was created from the
00074    *                          entire control net each time.
00075    *   @history 2011-03-17 Tracie Sucharski - Use surface point from camera
00076    *                          and updated for changes to SurfacePoint.
00077    */
00078   void QnetPointDistanceFilter::filter() {
00079     // Make sure we have a control network to filter through
00080     if (g_controlNetwork == NULL) {
00081       QMessageBox::information((QWidget *)parent(),
00082           "Error", "No points to filter");
00083       return;
00084     }
00085 
00086     // Make sure the user entered a filtering value
00087     if (p_lineEdit->text() == "") {
00088       QMessageBox::information((QWidget *)parent(),
00089           "Error", "Distance value must be entered");
00090       return;
00091     }
00092     // Get the user entered value for filtering
00093     double userEntered = p_lineEdit->text().toDouble();
00094 
00095     // create temporary QList to contain new filtered images
00096     QList <int> temp;
00097     // Loop through each value of the filtered points list
00098     // Loop in reverse order for consistency with other filter methods
00099     for (int i = g_filteredPoints.size() - 1; i >= 0; i--) {
00100       ControlPoint &cp1 = *(*g_controlNetwork)[g_filteredPoints[i]];
00101       // Get necessary info from the control point for later use
00102       //  First check if an adjusted point from jigsaw exists.  If not, use
00103       //  the apriori values.
00104       
00105       SurfacePoint sp1 = cp1.GetBestSurfacePoint();
00106 
00107       // If no lat/lon for this point, use lat/lon of first measure
00108       if (!sp1.Valid()) {
00109         Camera *cam1;
00110         ControlMeasure cm1;
00111 
00112         cm1 = *cp1.GetRefMeasure();
00113 
00114         int camIndex1 = g_serialNumberList->SerialNumberIndex(cm1.GetCubeSerialNumber());
00115         cam1 = g_controlNetwork->Camera(camIndex1);
00116         cam1->SetImage(cm1.GetSample(), cm1.GetLine());
00117         sp1 = cam1->GetSurfacePoint();
00118       }
00119       // Loop through each control point, comparing it to the initial point
00120       // from the filtered list
00121       for (int j = 0; j < g_controlNetwork->GetNumPoints(); j++) {
00122         if (j == g_filteredPoints[i]) {
00123           // cp1 = cp2, go to next value of j
00124           continue;
00125         }
00126         ControlPoint cp2 = *(*g_controlNetwork)[j];
00127         SurfacePoint sp2 = cp2.GetBestSurfacePoint();
00128 
00129         // If no lat/lon for this point, use lat/lon of first measure
00130         if (!sp2.Valid()) {
00131           Camera *cam2;
00132           ControlMeasure cm2;
00133           cm2 = *cp2.GetRefMeasure();
00134           int camIndex2 = g_serialNumberList->SerialNumberIndex(cm2.GetCubeSerialNumber());
00135           cam2 = g_controlNetwork->Camera(camIndex2);
00136           cam2->SetImage(cm2.GetSample(), cm2.GetLine());
00137           sp2 = cam2->GetSurfacePoint();
00138         }
00139         // Get the distance from the camera class
00140         double dist = sp1.GetDistanceToPoint(sp2,sp1.GetLocalRadius()).meters();
00141 
00142         // If the distance found is less than the input number, add the
00143         // control points' indices to the new filtered points list
00144         if (dist < userEntered) {
00145           if (!temp.contains(g_filteredPoints[i])) {
00146             temp.push_back(g_filteredPoints[i]);
00147           }
00148           break;
00149         }
00150       }
00151     }
00152 
00153     // Sort QList of filtered points before displaying list to user
00154     qSort(temp.begin(), temp.end());
00155     // replace existing filter list with this one
00156     g_filteredPoints = temp;
00157 
00158     // Tell the nav tool that a list has been filtered and needs to be updated
00159     emit filteredListModified();
00160     return;
00161   }
00162 }