File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
SubArea.cpp
1
5
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
20using namespace std;
21namespace 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 if (proj->Has360Domain()) {
195 minlon = proj->ToPositiveWest(proj->Longitude(), 360);
196 }
197 else {
198 minlon = proj->ToPositiveWest(proj->Longitude(), 180);
199 }
200 }
201 proj->SetWorld(p_es+.5, p_el+.5);
202 if (proj->IsGood()) {
203 minlat = proj->UniversalLatitude();
204 if (proj->IsPlanetographic()) {
205 minlat = proj->ToPlanetographic(minlat);
206 }
207 if (proj->IsPositiveEast()) {
208 maxlon = proj->UniversalLongitude();
209 if (proj->Has180Domain()) {
210 maxlon = proj->To180Domain(maxlon);
211 }
212 }
213 else {
214 if (proj->Has360Domain()) {
215 maxlon = proj->ToPositiveWest(proj->Longitude(), 360);
216 }
217 else {
218 maxlon = proj->ToPositiveWest(proj->Longitude(), 180);
219 }
220 }
221 mapgroup.addKeyword(PvlKeyword("MinimumLatitude",toString(minlat)),Pvl::Replace);
222 mapgroup.addKeyword(PvlKeyword("MaximumLatitude",toString(maxlat)),Pvl::Replace);
223 mapgroup.addKeyword(PvlKeyword("MinimumLongitude",toString(minlon)),Pvl::Replace);
224 mapgroup.addKeyword(PvlKeyword("MaximumLongitude",toString(maxlon)),Pvl::Replace);
225 }
226 }
227 }
228 else {
229 if(mapgroup.hasKeyword("MinimumLatitude")) {
230 mapgroup.deleteKeyword("MinimumLatitude");
231 }
232 if(mapgroup.hasKeyword("MaximumLatitude")) {
233 mapgroup.deleteKeyword("MaximumLatitude");
234 }
235 if(mapgroup.hasKeyword("MinimumLongitude")) {
236 mapgroup.deleteKeyword("MinimumLongitude");
237 }
238 if(mapgroup.hasKeyword("MaximumLongitude")) {
239 mapgroup.deleteKeyword("MaximumLongitude");
240 }
241 }
242 }
243 }
244
245 // Make changes to the output cube label
246 if(ocube->hasGroup("Instrument")) {
247 ocube->deleteGroup("Instrument");
248 }
249 if(inlabel.findObject("IsisCube").hasGroup("Instrument")) {
250 PvlGroup inst;
251 inst = inlabel.findObject("IsisCube").findGroup("Instrument");
252 ocube->putGroup(inst);
253 }
254
255 if(ocube->hasGroup("Mapping")) {
256 ocube->deleteGroup("Mapping");
257 }
258 if(inlabel.findObject("IsisCube").hasGroup("Mapping")) {
259 PvlGroup mapgrp;
260 mapgrp = inlabel.findObject("IsisCube").findGroup("Mapping");
261 ocube->putGroup(mapgrp);
262 }
263
264 // Update the AlphaCube group - this group will only be updated if
265 // a Mapping group does not exist in the labels.
266 AlphaCube aCube(p_ns, p_nl, ocube->sampleCount(), ocube->lineCount(),
267 p_ss - 0.5, p_sl - 0.5, p_es + 0.5, p_el + 0.5);
268 aCube.UpdateGroup(*ocube);
269 }
270}
This class is used to rewrite the "alpha" keywords out of the AlphaCube group or Instrument group.
Definition AlphaCube.h:46
void UpdateGroup(Cube &cube)
Writes or update the Alpha keywords (AlphaLines, AlphaSamples, AlphaStartingSamples,...
IO Handler for Isis Cubes.
Definition Cube.h:168
void deleteGroup(const QString &group)
Deletes a group from the cube labels.
Definition Cube.cpp:2010
int lineCount() const
Definition Cube.cpp:1767
int sampleCount() const
Definition Cube.cpp:1840
void putGroup(const PvlGroup &group)
Adds a group in a Label to the cube.
Definition Cube.cpp:2089
bool hasGroup(const QString &group) const
Return if the cube has a specified group in the labels.
Definition Cube.cpp:2037
Projection * projection()
Definition Cube.cpp:1827
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition Cube.cpp:1734
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
double XCoord() const
This returns the projection X provided SetGround, SetCoordinate, SetUniversalGround,...
virtual bool SetWorld(const double x, const double y)
This method is used to set a world coordinate.
double YCoord() const
This returns the projection Y provided SetGround, SetCoordinate, SetUniversalGround,...
bool IsGood() const
This indicates if the last invocation of SetGround, SetCoordinate, SetUniversalGround,...
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
void deleteKeyword(const QString &name)
Remove a specified keyword.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
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
@ Traverse
Search child objects.
Definition PvlObject.h:158
double p_sinc
Sample increment for subarea.
Definition SubArea.h:69
int p_ss
Starting sample of subarea.
Definition SubArea.h:63
int p_el
Ending line of subarea.
Definition SubArea.h:64
double p_linc
Line increment for subarea.
Definition SubArea.h:68
int p_nl
Number of lines in original file.
Definition SubArea.h:66
int p_es
Ending sample of subarea.
Definition SubArea.h:65
int p_sl
Starting line of subarea.
Definition SubArea.h:62
void UpdateLabel(Cube *icube, Cube *ocube, PvlGroup &results)
Modifies a label for a file containing a subarea.
Definition SubArea.cpp:126
void SetSubArea(const int orignl, const int origns, const int sl, const int ss, const int el, const int es, const double linc, const double sinc)
Defines the subarea.
Definition SubArea.cpp:60
int p_ns
Number of samples in original file.
Definition SubArea.h:67
Base class for Map TProjections.
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).
virtual double UniversalLongitude()
This returns a universal longitude (positive east in 0 to 360 domain).
static double ToPositiveWest(const double lon, const int domain)
This method converts a longitude into the positive west direction.
bool IsPlanetographic() const
This indicates if the latitude type is planetographic (as opposed to planetocentric).
virtual bool IsEquatorialCylindrical()
This method returns true if the projection is equatorial cylindrical.
bool Has360Domain() const
This indicates if the longitude domain is 0 to 360 (as opposed to -180 to 180).
virtual double UniversalLatitude()
This returns a universal latitude (planetocentric).
bool IsPositiveEast() const
This indicates if the longitude direction type is positive west (as opposed to postive east).
virtual double Longitude() const
This returns a longitude with correct longitude direction and domain as specified in the label object...
double ToPlanetographic(const double lat) const
This method converts a planetocentric latitude to a planetographic latitude.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition IString.cpp:149
Namespace for the standard library.