Isis 3 Programmer Reference
Enlarge.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "Enlarge.h"
8 
9 #include <cmath>
10 
11 #include "Cube.h"
12 #include "IException.h"
13 #include "PvlGroup.h"
14 #include "SubArea.h"
15 
16 using namespace std;
17 
18 namespace Isis {
19 
27  Enlarge::Enlarge(Cube *pInCube, const double sampleScale,
28  const double lineScale) {
29  // Input Cube
30  mInCube = pInCube;
31 
32  // Set input image area to defaults
33  mdStartSample = 1;
34  mdEndSample = mInCube->sampleCount();
35  mdStartLine = 1;
36  mdEndLine = mInCube->lineCount();
37 
38  // Save off the sample and line magnification
39  mdSampleScale = sampleScale;
40  mdLineScale = lineScale;
41 
42  miOutputSamples = (int)ceil(mInCube->sampleCount() * mdSampleScale);
43  miOutputLines = (int)ceil(mInCube->lineCount() * mdLineScale);
44  }
45 
57  bool Enlarge::Xform(double &inSample, double &inLine,
58  const double outSample, const double outLine) {
59  inSample = (outSample - 0.5) / mdSampleScale + 0.5 + (mdStartSample - 1);
60  inLine = (outLine - 0.5) / mdLineScale + 0.5 + (mdStartLine - 1);
61 
62  return true;
63  }
64 
76  void Enlarge::SetInputArea(double pdStartSample, double pdEndSample,
77  double pdStartLine, double pdEndLine) {
78  // Check for the right image dimensions
79  if (pdStartSample > pdEndSample || pdStartLine > pdEndLine) {
80  string sErrMsg = "Error in Input Area Dimesions";
81  throw IException(IException::Programmer, sErrMsg, _FILEINFO_);
82  }
83 
84  if (pdStartSample >= 1) {
85  mdStartSample = pdStartSample;
86  }
87  if (pdEndSample <= mInCube->sampleCount()) {
88  mdEndSample = pdEndSample;
89  }
90  if (pdStartLine >= 1) {
91  mdStartLine = pdStartLine;
92  }
93  if (pdEndLine <= mInCube->lineCount()) {
94  mdEndLine = pdEndLine;
95  }
96 
97  miOutputSamples = (int)ceil((mdEndSample - mdStartSample + 1) * mdSampleScale);
98  miOutputLines = (int)ceil((mdEndLine - mdStartLine + 1) * mdLineScale);
99  }
100 
114  PvlGroup Enlarge::UpdateOutputLabel(Cube *pOutCube) {
115  int iNumSamples= mInCube->sampleCount();
116  int iNumLines = mInCube->lineCount();
117  // Construct a label with the results
118  // This is the Results group that will go into the application
119  // log file. This group must be created by the calling application.
120  // Information will be added to it if the Mapping or Instrument
121  // groups are deleted from the output image label
122  PvlGroup resultsGrp("Results");
123  resultsGrp += PvlKeyword("InputLines", toString(iNumLines));
124  resultsGrp += PvlKeyword("InputSamples", toString(iNumSamples));
125  resultsGrp += PvlKeyword("StartingLine", toString((int)mdStartLine));
126  resultsGrp += PvlKeyword("StartingSample", toString((int)mdStartSample));
127  resultsGrp += PvlKeyword("EndingLine", toString((int)mdEndLine));
128  resultsGrp += PvlKeyword("EndingSample", toString((int)mdEndSample));
129  resultsGrp += PvlKeyword("LineIncrement", toString(1. / mdLineScale));
130  resultsGrp += PvlKeyword("SampleIncrement", toString(1. / mdSampleScale));
131  resultsGrp += PvlKeyword("OutputLines", toString(miOutputLines));
132  resultsGrp += PvlKeyword("OutputSamples", toString(miOutputSamples));
133 
134  SubArea subArea;
135  subArea.SetSubArea(mInCube->lineCount(), mInCube->sampleCount(), (int)mdStartLine, (int)mdStartSample,
136  (int)mdEndLine, (int)mdEndSample, 1.0 / mdLineScale, 1.0 / mdSampleScale);
137  subArea.UpdateLabel(mInCube, pOutCube, resultsGrp);
138 
139  return resultsGrp;
140  }
141 }
142 
143 
Isis::SubArea::SetSubArea
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
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::SubArea::UpdateLabel
void UpdateLabel(Cube *icube, Cube *ocube, PvlGroup &results)
Modifies a label for a file containing a subarea.
Definition: SubArea.cpp:126
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Cube::sampleCount
int sampleCount() const
Definition: Cube.cpp:1807
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::IException
Isis exception class.
Definition: IException.h:91
std
Namespace for the standard library.
Isis::SubArea
Apply corrections to a cube label for subarea extraction.
Definition: SubArea.h:47
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16