Isis 3 Programmer Reference
SubArea.cpp
Go to the documentation of this file.
1 
23 #include <float.h>
24 #include <iostream>
25 #include <string>
26 #include <sstream>
27 
28 #include "SubArea.h"
29 #include "AlphaCube.h"
30 #include "Projection.h"
31 #include "ProjectionFactory.h"
32 #include "TProjection.h"
33 #include "IException.h"
34 #include "IString.h"
35 
36 using namespace std;
37 namespace Isis {
38 
76  void SubArea::SetSubArea(const int orignl, const int origns,
77  const int sl, const int ss, const int el,
78  const int es, const double linc, const double sinc) {
79 
80  // Save size of original image file
81  p_nl = orignl;
82  p_ns = origns;
83 
84  // Save the subarea information
85  p_sl = sl;
86  p_ss = ss;
87  p_el = el;
88  p_es = es;
89 
90  if(p_sl > p_el) {
91  string msg = "Invalid start/end line range [sl,el] specified for subarea";
92  throw IException(IException::Programmer, msg, _FILEINFO_);
93  }
94 
95  if(p_ss > p_es) {
96  string msg = "Invalid start/end sample range [ss,es] specified for subarea";
97  throw IException(IException::Programmer, msg, _FILEINFO_);
98  }
99 
100  p_linc = linc;
101  if(p_linc <= 0.0) {
102  string msg = "Invalid line increment [linc] specified for subarea";
103  throw IException(IException::Programmer, msg, _FILEINFO_);
104  }
105 
106  p_sinc = sinc;
107  if(p_sinc <= 0.0) {
108  string msg = "Invalid sample increment [sinc] specified for subarea";
109  throw IException(IException::Programmer, msg, _FILEINFO_);
110  }
111  }
112 
142  void SubArea::UpdateLabel(Cube *icube, Cube *ocube, PvlGroup &results) {
143 
144  Pvl inlabel = *icube->label();
145 
146  // If the linc and sinc are not equal, then the Instrument and
147  // Mapping groups are no longer valid.
148  if(p_linc != p_sinc) {
149  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
150  inlabel.findObject("IsisCube").deleteGroup("Mapping");
151  results += PvlKeyword("MappingGroupDeleted", "True");
152 
153  // We don't want to think our projected cube is unprojected, so if we
154  // delete a mapping group and we have a camera there is a problem.
155  // Remove the camera.
156  if(inlabel.findObject("IsisCube").hasGroup("Instrument")) {
157  inlabel.findObject("IsisCube").deleteGroup("Instrument");
158  results += PvlKeyword("InstrumentGroupDeleted", "True");
159  }
160  }
161  }
162 
163  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
164  // Update the upper left corner X,Y values if the starting line or
165  // starting sample are changed.
166  TProjection *proj = (TProjection *) icube->projection();
167  if(p_sl != 1 || p_ss != 1) {
168  proj->SetWorld(p_ss - 0.5, p_sl - 0.5);
169  PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
170  mapgroup.addKeyword(PvlKeyword("UpperLeftCornerX", toString(proj->XCoord())),
171  Pvl::Replace);
172  mapgroup.addKeyword(PvlKeyword("UpperLeftCornerY", toString(proj->YCoord())),
173  Pvl::Replace);
174  }
175 
176  // If the linc and sinc are not equal to 1, then update the
177  // mapping scale and resolution.
178  if(p_linc == p_sinc && p_linc != 1.0) {
179  PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
180  QString pixresUnit = mapgroup["PixelResolution"].unit();
181  double pixres = toDouble(mapgroup["PixelResolution"][0]);
182  mapgroup["PixelResolution"] = toString(pixres * p_linc);
183  mapgroup["PixelResolution"].setUnits(pixresUnit);
184  QString scaleUnit = mapgroup["Scale"].unit();
185  double scale = mapgroup["Scale"];
186  mapgroup["Scale"] = toString(scale / p_linc);
187  mapgroup["Scale"].setUnits(scaleUnit);
188  }
189 
190  // If the outer bounds of the image are changed, then the
191  // latitude,longitude range is no longer valid.
192  if(p_sl != 1 || p_ss != 1 || p_el != p_nl || p_es != p_ns) {
193  PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
194  if (proj->IsEquatorialCylindrical()) {
195  double minlat, maxlat;
196  double minlon, maxlon;
197  proj->SetWorld(p_ss-.5, p_sl-.5);
198  if (proj->IsGood()) {
199  maxlat = proj->UniversalLatitude();
200  if (proj->IsPlanetographic()) {
201  maxlat = proj->ToPlanetographic(maxlat);
202  }
203  if (proj->IsPositiveEast()) {
204  minlon = proj->UniversalLongitude();
205  if (proj->Has180Domain()) {
206  minlon = proj->To180Domain(minlon);
207  }
208  }
209  else {
210  minlon = proj->ToPositiveWest(proj->UniversalLongitude(), 360);
211  if (proj->Has180Domain()) {
212  minlon = proj->To180Domain(proj->ToPositiveWest(proj->UniversalLongitude(), 360));
213  }
214  }
215  proj->SetWorld(p_es+.5, p_el+.5);
216  if (proj->IsGood()) {
217  minlat = proj->UniversalLatitude();
218  if (proj->IsPlanetographic()) {
219  minlat = proj->ToPlanetographic(minlat);
220  }
221  if (proj->IsPositiveEast()) {
222  maxlon = proj->UniversalLongitude();
223  if (proj->Has180Domain()) {
224  maxlon = proj->To180Domain(maxlon);
225  }
226  }
227  else {
228  maxlon = proj->ToPositiveWest(proj->UniversalLongitude(), 360);
229  if (proj->Has180Domain()) {
230  maxlon = proj->To180Domain(proj->ToPositiveWest(proj->UniversalLongitude(), 360));
231  }
232  }
233  mapgroup.addKeyword(PvlKeyword("MinimumLatitude",toString(minlat)),Pvl::Replace);
234  mapgroup.addKeyword(PvlKeyword("MaximumLatitude",toString(maxlat)),Pvl::Replace);
235  mapgroup.addKeyword(PvlKeyword("MinimumLongitude",toString(minlon)),Pvl::Replace);
236  mapgroup.addKeyword(PvlKeyword("MaximumLongitude",toString(maxlon)),Pvl::Replace);
237  }
238  }
239  }
240  else {
241  if(mapgroup.hasKeyword("MinimumLatitude")) {
242  mapgroup.deleteKeyword("MinimumLatitude");
243  }
244  if(mapgroup.hasKeyword("MaximumLatitude")) {
245  mapgroup.deleteKeyword("MaximumLatitude");
246  }
247  if(mapgroup.hasKeyword("MinimumLongitude")) {
248  mapgroup.deleteKeyword("MinimumLongitude");
249  }
250  if(mapgroup.hasKeyword("MaximumLongitude")) {
251  mapgroup.deleteKeyword("MaximumLongitude");
252  }
253  }
254  }
255  }
256 
257  // Make changes to the output cube label
258  if(ocube->hasGroup("Instrument")) {
259  ocube->deleteGroup("Instrument");
260  }
261  if(inlabel.findObject("IsisCube").hasGroup("Instrument")) {
262  PvlGroup inst;
263  inst = inlabel.findObject("IsisCube").findGroup("Instrument");
264  ocube->putGroup(inst);
265  }
266 
267  if(ocube->hasGroup("Mapping")) {
268  ocube->deleteGroup("Mapping");
269  }
270  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
271  PvlGroup mapgrp;
272  mapgrp = inlabel.findObject("IsisCube").findGroup("Mapping");
273  ocube->putGroup(mapgrp);
274  }
275 
276  // Update the AlphaCube group - this group will only be updated if
277  // a Mapping group does not exist in the labels.
278  AlphaCube aCube(p_ns, p_nl, ocube->sampleCount(), ocube->lineCount(),
279  p_ss - 0.5, p_sl - 0.5, p_es + 0.5, p_el + 0.5);
280  aCube.UpdateGroup(*ocube);
281  }
282 }
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
bool IsPositiveEast() const
This indicates if the longitude direction type is positive west (as opposed to postive east)...
Base class for Map TProjections.
Definition: TProjection.h:182
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:286
int sampleCount() const
Definition: Cube.cpp:1452
virtual bool IsEquatorialCylindrical()
This method returns true if the projection is equatorial cylindrical.
Namespace for the standard library.
double UniversalLongitude()
This returns a universal longitude (positive east in 0 to 360 domain).
bool IsGood() const
This indicates if the last invocation of SetGround, SetCoordinate, SetUniversalGround, or SetWorld was with successful or not.
Definition: Projection.cpp:389
double XCoord() const
This returns the projection X provided SetGround, SetCoordinate, SetUniversalGround, or SetWorld returned with success.
Definition: Projection.cpp:402
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Projection * projection()
Definition: Cube.cpp:1439
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
This class is used to rewrite the "alpha" keywords out of the AlphaCube group or Instrument group...
Definition: AlphaCube.h:62
static double ToPositiveWest(const double lon, const int domain)
This method converts a longitude into the positive west direction.
static double To180Domain(const double lon)
This method converts a longitude into the -180 to 180 domain.
bool Has180Domain() const
This indicates if the longitude domain is -180 to 180 (as opposed to 0 to 360).
bool IsPlanetographic() const
This indicates if the latitude type is planetographic (as opposed to planetocentric).
bool hasGroup(const QString &group) const
Return if the cube has a specified group in the labels.
Definition: Cube.cpp:1649
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A single keyword-value pair.
Definition: PvlKeyword.h:98
double YCoord() const
This returns the projection Y provided SetGround, SetCoordinate, SetUniversalGround, or SetWorld returned with success.
Definition: Projection.cpp:415
Container for cube-like labels.
Definition: Pvl.h:135
double ToPlanetographic(const double lat) const
This method converts a planetocentric latitude to a planetographic latitude.
double UniversalLatitude()
This returns a universal latitude (planetocentric).
void UpdateGroup(Cube &cube)
Writes or update the Alpha keywords (AlphaLines, AlphaSamples, AlphaStartingSamples, etc) in the proper group in a PVL object.
Definition: AlphaCube.cpp:149
bool SetWorld(const double x, const double y)
This method is used to set a world coordinate.
Definition: Projection.cpp:512
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1346
int lineCount() const
Definition: Cube.cpp:1379
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void putGroup(const PvlGroup &group)
Adds a group in a Label to the cube.
Definition: Cube.cpp:1688
void deleteGroup(const QString &group)
Deletes a group from the cube labels.
Definition: Cube.cpp:1622
void deleteKeyword(const QString &name)
Remove a specified keyword.
IO Handler for Isis Cubes.
Definition: Cube.h:170