File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
SubArea.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include <float.h>
8 #include <iostream>
9 #include <string>
10 #include <sstream>
11 
12 #include "SubArea.h"
13 #include "AlphaCube.h"
14 #include "Projection.h"
15 #include "ProjectionFactory.h"
16 #include "TProjection.h"
17 #include "IException.h"
18 #include "IString.h"
19 
20 using namespace std;
21 namespace Isis {
22 
60  void SubArea::SetSubArea(const int orignl, const int origns,
61  const int sl, const int ss, const int el,
62  const int es, const double linc, const double sinc) {
63 
64  // Save size of original image file
65  p_nl = orignl;
66  p_ns = origns;
67 
68  // Save the subarea information
69  p_sl = sl;
70  p_ss = ss;
71  p_el = el;
72  p_es = es;
73 
74  if(p_sl > p_el) {
75  string msg = "Invalid start/end line range [sl,el] specified for subarea";
76  throw IException(IException::Programmer, msg, _FILEINFO_);
77  }
78 
79  if(p_ss > p_es) {
80  string msg = "Invalid start/end sample range [ss,es] specified for subarea";
81  throw IException(IException::Programmer, msg, _FILEINFO_);
82  }
83 
84  p_linc = linc;
85  if(p_linc <= 0.0) {
86  string msg = "Invalid line increment [linc] specified for subarea";
87  throw IException(IException::Programmer, msg, _FILEINFO_);
88  }
89 
90  p_sinc = sinc;
91  if(p_sinc <= 0.0) {
92  string msg = "Invalid sample increment [sinc] specified for subarea";
93  throw IException(IException::Programmer, msg, _FILEINFO_);
94  }
95  }
96 
126  void SubArea::UpdateLabel(Cube *icube, Cube *ocube, PvlGroup &results) {
127 
128  Pvl inlabel = *icube->label();
129 
130  // If the linc and sinc are not equal, then the Instrument and
131  // Mapping groups are no longer valid.
132  if(p_linc != p_sinc) {
133  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
134  inlabel.findObject("IsisCube").deleteGroup("Mapping");
135  results += PvlKeyword("MappingGroupDeleted", "True");
136 
137  // We don't want to think our projected cube is unprojected, so if we
138  // delete a mapping group and we have a camera there is a problem.
139  // Remove the camera.
140  if(inlabel.findObject("IsisCube").hasGroup("Instrument")) {
141  inlabel.findObject("IsisCube").deleteGroup("Instrument");
142  results += PvlKeyword("InstrumentGroupDeleted", "True");
143  }
144  }
145  }
146 
147  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
148  // Update the upper left corner X,Y values if the starting line or
149  // starting sample are changed.
150  TProjection *proj = (TProjection *) icube->projection();
151  if(p_sl != 1 || p_ss != 1) {
152  proj->SetWorld(p_ss - 0.5, p_sl - 0.5);
153  PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
154  mapgroup.addKeyword(PvlKeyword("UpperLeftCornerX", toString(proj->XCoord())),
155  Pvl::Replace);
156  mapgroup.addKeyword(PvlKeyword("UpperLeftCornerY", toString(proj->YCoord())),
157  Pvl::Replace);
158  }
159 
160  // If the linc and sinc are not equal to 1, then update the
161  // mapping scale and resolution.
162  if(p_linc == p_sinc && p_linc != 1.0) {
163  PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
164  QString pixresUnit = mapgroup["PixelResolution"].unit();
165  double pixres = toDouble(mapgroup["PixelResolution"][0]);
166  mapgroup["PixelResolution"] = toString(pixres * p_linc);
167  mapgroup["PixelResolution"].setUnits(pixresUnit);
168  QString scaleUnit = mapgroup["Scale"].unit();
169  double scale = mapgroup["Scale"];
170  mapgroup["Scale"] = toString(scale / p_linc);
171  mapgroup["Scale"].setUnits(scaleUnit);
172  }
173 
174  // If the outer bounds of the image are changed, then the
175  // latitude,longitude range is no longer valid.
176  if(p_sl != 1 || p_ss != 1 || p_el != p_nl || p_es != p_ns) {
177  PvlGroup &mapgroup = inlabel.findObject("IsisCube").findGroup("Mapping", Pvl::Traverse);
178  if (proj->IsEquatorialCylindrical()) {
179  double minlat, maxlat;
180  double minlon, maxlon;
181  proj->SetWorld(p_ss-.5, p_sl-.5);
182  if (proj->IsGood()) {
183  maxlat = proj->UniversalLatitude();
184  if (proj->IsPlanetographic()) {
185  maxlat = proj->ToPlanetographic(maxlat);
186  }
187  if (proj->IsPositiveEast()) {
188  minlon = proj->UniversalLongitude();
189  if (proj->Has180Domain()) {
190  minlon = proj->To180Domain(minlon);
191  }
192  }
193  else {
194  minlon = proj->ToPositiveWest(proj->UniversalLongitude(), 360);
195  if (proj->Has180Domain()) {
196  minlon = proj->To180Domain(proj->ToPositiveWest(proj->UniversalLongitude(), 360));
197  }
198  }
199  proj->SetWorld(p_es+.5, p_el+.5);
200  if (proj->IsGood()) {
201  minlat = proj->UniversalLatitude();
202  if (proj->IsPlanetographic()) {
203  minlat = proj->ToPlanetographic(minlat);
204  }
205  if (proj->IsPositiveEast()) {
206  maxlon = proj->UniversalLongitude();
207  if (proj->Has180Domain()) {
208  maxlon = proj->To180Domain(maxlon);
209  }
210  }
211  else {
212  maxlon = proj->ToPositiveWest(proj->UniversalLongitude(), 360);
213  if (proj->Has180Domain()) {
214  maxlon = proj->To180Domain(proj->ToPositiveWest(proj->UniversalLongitude(), 360));
215  }
216  }
217  mapgroup.addKeyword(PvlKeyword("MinimumLatitude",toString(minlat)),Pvl::Replace);
218  mapgroup.addKeyword(PvlKeyword("MaximumLatitude",toString(maxlat)),Pvl::Replace);
219  mapgroup.addKeyword(PvlKeyword("MinimumLongitude",toString(minlon)),Pvl::Replace);
220  mapgroup.addKeyword(PvlKeyword("MaximumLongitude",toString(maxlon)),Pvl::Replace);
221  }
222  }
223  }
224  else {
225  if(mapgroup.hasKeyword("MinimumLatitude")) {
226  mapgroup.deleteKeyword("MinimumLatitude");
227  }
228  if(mapgroup.hasKeyword("MaximumLatitude")) {
229  mapgroup.deleteKeyword("MaximumLatitude");
230  }
231  if(mapgroup.hasKeyword("MinimumLongitude")) {
232  mapgroup.deleteKeyword("MinimumLongitude");
233  }
234  if(mapgroup.hasKeyword("MaximumLongitude")) {
235  mapgroup.deleteKeyword("MaximumLongitude");
236  }
237  }
238  }
239  }
240 
241  // Make changes to the output cube label
242  if(ocube->hasGroup("Instrument")) {
243  ocube->deleteGroup("Instrument");
244  }
245  if(inlabel.findObject("IsisCube").hasGroup("Instrument")) {
246  PvlGroup inst;
247  inst = inlabel.findObject("IsisCube").findGroup("Instrument");
248  ocube->putGroup(inst);
249  }
250 
251  if(ocube->hasGroup("Mapping")) {
252  ocube->deleteGroup("Mapping");
253  }
254  if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
255  PvlGroup mapgrp;
256  mapgrp = inlabel.findObject("IsisCube").findGroup("Mapping");
257  ocube->putGroup(mapgrp);
258  }
259 
260  // Update the AlphaCube group - this group will only be updated if
261  // a Mapping group does not exist in the labels.
262  AlphaCube aCube(p_ns, p_nl, ocube->sampleCount(), ocube->lineCount(),
263  p_ss - 0.5, p_sl - 0.5, p_es + 0.5, p_el + 0.5);
264  aCube.UpdateGroup(*ocube);
265  }
266 }
Isis::TProjection::ToPositiveWest
static double ToPositiveWest(const double lon, const int domain)
This method converts a longitude into the positive west direction.
Definition: TProjection.cpp:587
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::TProjection::UniversalLatitude
virtual double UniversalLatitude()
This returns a universal latitude (planetocentric).
Definition: TProjection.cpp:908
Isis::PvlContainer::addKeyword
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Definition: PvlContainer.cpp:202
Isis::Cube::deleteGroup
void deleteGroup(const QString &group)
Deletes a group from the cube labels.
Definition: Cube.cpp:1977
Isis::Cube::putGroup
void putGroup(const PvlGroup &group)
Adds a group in a Label to the cube.
Definition: Cube.cpp:2056
Isis::TProjection::IsPlanetographic
bool IsPlanetographic() const
This indicates if the latitude type is planetographic (as opposed to planetocentric).
Definition: TProjection.cpp:403
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::Projection::IsGood
bool IsGood() const
This indicates if the last invocation of SetGround, SetCoordinate, SetUniversalGround,...
Definition: Projection.cpp:374
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::TProjection::IsPositiveEast
bool IsPositiveEast() const
This indicates if the longitude direction type is positive west (as opposed to postive east).
Definition: TProjection.cpp:520
Isis::Cube::lineCount
int lineCount() const
Definition: Cube.cpp:1734
Isis::AlphaCube::UpdateGroup
void UpdateGroup(Cube &cube)
Writes or update the Alpha keywords (AlphaLines, AlphaSamples, AlphaStartingSamples,...
Definition: AlphaCube.cpp:134
Isis::Cube::hasGroup
bool hasGroup(const QString &group) const
Return if the cube has a specified group in the labels.
Definition: Cube.cpp:2004
Isis::TProjection
Base class for Map TProjections.
Definition: TProjection.h:166
Isis::PvlObject::findObject
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:274
Isis::Cube::sampleCount
int sampleCount() const
Definition: Cube.cpp:1807
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::AlphaCube
This class is used to rewrite the "alpha" keywords out of the AlphaCube group or Instrument group.
Definition: AlphaCube.h:46
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Projection::SetWorld
virtual bool SetWorld(const double x, const double y)
This method is used to set a world coordinate.
Definition: Projection.cpp:497
Isis::TProjection::To180Domain
static double To180Domain(const double lon)
This method converts a longitude into the -180 to 180 domain.
Definition: TProjection.cpp:657
Isis::TProjection::Has180Domain
bool Has180Domain() const
This indicates if the longitude domain is -180 to 180 (as opposed to 0 to 360).
Definition: TProjection.cpp:632
Isis::PvlContainer::deleteKeyword
void deleteKeyword(const QString &name)
Remove a specified keyword.
Definition: PvlContainer.cpp:97
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
std
Namespace for the standard library.
Isis::Cube::label
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1701
Isis::TProjection::UniversalLongitude
virtual double UniversalLongitude()
This returns a universal longitude (positive east in 0 to 360 domain).
Definition: TProjection.cpp:922
Isis::TProjection::ToPlanetographic
double ToPlanetographic(const double lat) const
This method converts a planetocentric latitude to a planetographic latitude.
Definition: TProjection.cpp:463
Isis::Projection::YCoord
double YCoord() const
This returns the projection Y provided SetGround, SetCoordinate, SetUniversalGround,...
Definition: Projection.cpp:400
Isis::TProjection::IsEquatorialCylindrical
virtual bool IsEquatorialCylindrical()
This method returns true if the projection is equatorial cylindrical.
Definition: TProjection.cpp:381
Isis::Projection::XCoord
double XCoord() const
This returns the projection X provided SetGround, SetCoordinate, SetUniversalGround,...
Definition: Projection.cpp:387
Isis::Cube::projection
Projection * projection()
Definition: Cube.cpp:1794
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:17:20