Isis 3 Programmer Reference
QnetCubeDistanceFilter.cpp
1#include "QnetCubeDistanceFilter.h"
2
3#include <vector>
4#include <cmath>
5
6#include <QGridLayout>
7#include <QLabel>
8#include <QLineEdit>
9#include <QMessageBox>
10#include <QRadioButton>
11
12#include "QnetNavTool.h"
13#include "Camera.h"
14#include "ControlNet.h"
15#include "ControlPoint.h"
16#include "ControlMeasure.h"
17#include "Distance.h"
18#include "Latitude.h"
19#include "Longitude.h"
20#include "SerialNumberList.h"
21#include "SurfacePoint.h"
22
23namespace Isis {
40 QnetFilter(navTool, parent) {
41 p_lineEdit = NULL;
42 p_pixels = NULL;
43 p_meters = NULL;
44
45 // Create components for the filter window
46 QLabel *label = new QLabel("Filter by distance between points in cube");
47 QLabel *lessThan = new QLabel("Contains points within ");
48 p_lineEdit = new QLineEdit;
49 p_pixels = new QRadioButton("pixels");
50 p_meters = new QRadioButton("meters");
51 p_pixels->setChecked(true);
52 QLabel *pad = new QLabel();
53
54 // create layout for radio buttons
55 QVBoxLayout *units = new QVBoxLayout();
56 units->addWidget(p_pixels);
57 units->addWidget(p_meters);
58
59 // Create the layout and add the components to it
60 QGridLayout *gridLayout = new QGridLayout();
61 gridLayout->addWidget(label, 0, 0, 1, 2);
62 gridLayout->addWidget(lessThan, 1, 0);
63 gridLayout->addWidget(p_lineEdit, 1, 1);
64 gridLayout->addLayout(units, 1, 2);
65 gridLayout->addWidget(pad, 2, 0);
66 gridLayout->setRowStretch(2, 50);
67 this->setLayout(gridLayout);
68 }
69
89 // Make sure we have a list of files to filter
90 if (serialNumberList() == NULL) {
91 QMessageBox::information((QWidget *)parent(),
92 "Error", "No cubes to filter");
93 return;
94 }
95
96 // Make sure the user entered a filtering value
97 if (p_lineEdit->text() == "") {
98 QMessageBox::information((QWidget *)parent(),
99 "Error", "Distance value must be entered");
100 return;
101 }
102
103 // Get the user entered value for filtering
104 int userEntered = p_lineEdit->text().toInt();
105
106 // create temporary QList to contain new filtered images
107 QList <int> temp;
108 // Loop through each image in the currently filtered list
109 // Loop in reverse order for consistency with other filters
110 for (int i = filteredImages().size() - 1; i >= 0; i--) {
111
112 // Loop through every control point in the control net
113 for (int cp1 = 0; cp1 < controlNet()->GetNumPoints(); cp1++) {
114 ControlPoint controlPt1 = *(*controlNet())[cp1];
115 ControlMeasure controlMeas1;
116 // Loop through each control measure of this point until we find this image
117 for (int cm1 = 0; cm1 < controlPt1.GetNumMeasures(); cm1++) {
118 // Check control measure to see if this point is in the current image
119 if (controlPt1[cm1]->GetCubeSerialNumber() == serialNumberList()->serialNumber(filteredImages()[i])) {
120 // this measure matches the image, set controlMeas1 variable and break out of loop
121 controlMeas1 = *controlPt1[cm1];
122 break;
123 }
124 // this measure does not match this cube, keep looking, continue to next measure
125 else
126 continue;
127 } // if no matching measure was found, controlMeas1 defaults to sample,line = 0
128
129 // If the measure for this image has no line/sample values,
130 // we can not measure distance, so continue to the next control point, cp1
131 if (controlMeas1.GetSample() == 0 && controlMeas1.GetLine() == 0)
132 continue;
133 // if the user chooses distance in meters, create camera to find lat/lon for this measure
134 double rad = 0, lat1 = 0, lon1 = 0;
135 if (p_meters->isChecked()) {
136 Camera *cam1;
137 cam1 = controlNet()->Camera(filteredImages()[i]);
138 // try to set image using sample/line values
139 if (cam1->SetImage(controlMeas1.GetSample(), controlMeas1.GetLine())) {
140 rad = cam1->LocalRadius().meters();
141 lat1 = cam1->UniversalLatitude();
142 lon1 = cam1->UniversalLongitude();
143 }
144 else {
145 // if SetImage fails for this measure, don't calculate the distance from this point
146 // continue to next control point, cp1
147 continue;
148 }
149 }
150 // Loop through the remaining control points to compute distances
151 for (int cp2 = (cp1 + 1); cp2 < controlNet()->GetNumPoints(); cp2++) {
152 ControlPoint &controlPt2 = *(*controlNet())[cp2];
153 ControlMeasure controlMeas2;
154 // Loop through each measure of the second point until we find this image
155 for (int cm2 = 0; cm2 < controlPt2.GetNumMeasures(); cm2++) {
156 // Check to see if this point is in the image
157 if (controlPt2[cm2]->GetCubeSerialNumber() == serialNumberList()->serialNumber(filteredImages()[i])) {
158 // this measure matches the image, set controlMeas2 variable and break out of loop
159 controlMeas2 = *controlPt2[cm2];
160 break;
161 }
162 // this measure does not match this cube, keep looking, continue to next measure
163 else
164 continue;
165 } // if no matching measure was found, controlMeas1 defaults to sample,line = 0
166
167 // If the measure has no samp/line values, continue to next point, cp2
168 if (controlMeas2.GetSample() == 0 && controlMeas2.GetLine() == 0)
169 continue;
170
171 // Now determine distance based on the units chosen
172 double dist = 0;
173 if (p_pixels->isChecked()) {
174 double deltaSamp = controlMeas1.GetSample() - controlMeas2.GetSample();
175 double deltaLine = controlMeas1.GetLine() - controlMeas2.GetLine();
176 // use the distance formula for cartesian coordinates
177 dist = sqrt((deltaSamp * deltaSamp) + (deltaLine * deltaLine));
178 }
179 else
180 // meters is checked
181 {
182 // create camera to find lat/lon for this measure
183 double lat2 = 0, lon2 = 0;
184 Camera *cam2;
185 cam2 = controlNet()->Camera(filteredImages()[i]);
186 // try to set image using sample/line values
187 if (cam2->SetImage(controlMeas2.GetSample(), controlMeas2.GetLine())) {
188 lat2 = cam2->UniversalLatitude();
189 lon2 = cam2->UniversalLongitude();
190 }
191 else {
192 // if SetImage fails, don't calculate the distance to this point
193 // continue to the next control point, cp2
194 continue;
195 }
196 // Calculate the distance between the two points
197 // Get the distance from the camera class
198 SurfacePoint point1(
202 SurfacePoint point2(
206 dist = point1.GetDistanceToPoint(point2,
207 Distance(rad, Distance::Meters)).meters();
208 }
209
210 if (dist == 0) {
211 // distance not calculated, continue to next cp2
212 continue;
213 }
214
215 // If the distance is less than the value entered by the user,
216 // keep the cube in the list
217 if (dist < userEntered) {
218 if (!temp.contains(filteredImages()[i])) {
219 // this image is added to the filtered list
220 temp.push_back(filteredImages()[i]);
221 }
222 }
223 if (temp.contains(filteredImages()[i])) {
224 // (*filteredImages())[i] is already added to the filtered list,
225 // no point in checking other distances,
226 // break out of cp2 loop and continue to next cp1
227 break;
228 }
229 } // this ends cp2 loop
230
231 if (temp.contains(filteredImages()[i])) {
232 // (*filteredImages())[i] is already added to the filtered list,
233 // no point in checking other distances,
234 // break out of cp1 loop and continue to next value of i
235 break;
236 }
237 } // this ends cp1 loop
238 } // this ends i loop
239
240 // Sort QList of filtered points before displaying list to user
241 qSort(temp.begin(), temp.end());
242 // replace existing filter list with this one
243 filteredImages() = temp;
244
245 // Tell the nav tool that a list has been filtered and it needs to updated
246 emit filteredListModified();
247 return;
248 }
249}
250
251
252
253
254
255
256
257
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
Definition Angle.h:56
a control measurement
int GetNumPoints() const
Return the number of control points in the network.
Isis::Camera * Camera(int index)
Returns the camera list from the given image number.
A single control point.
Distance measurement, usually in meters.
Definition Distance.h:34
@ Meters
The distance is being specified in meters.
Definition Distance.h:43
double meters() const
Get the distance in meters.
Definition Distance.cpp:85
This class is designed to encapsulate the concept of a Latitude.
Definition Latitude.h:51
This class is designed to encapsulate the concept of a Longitude.
Definition Longitude.h:40
virtual void filter()
Filters a list of images for images that have points that are less than the user entered distance fro...
QnetCubeDistanceFilter(QnetNavTool *navTool, QWidget *parent=0)
Contructor for the Cube Distance filter.
Qnet Navigation Tool.
virtual double UniversalLatitude() const
Returns the planetocentric latitude, in degrees, at the surface intersection point in the body fixed ...
Definition Sensor.cpp:212
Distance LocalRadius() const
Returns the local radius at the intersection point.
Definition Sensor.cpp:269
QString serialNumber(const QString &filename)
Return a serial number given a filename.
This class defines a body-fixed surface point.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16