USGS

Isis 3.0 Object Programmers' Reference

Home

Enlarge.cpp
Go to the documentation of this file.
1 
20 #include "Enlarge.h"
21 
22 #include <cmath>
23 
24 #include "Cube.h"
25 #include "IException.h"
26 #include "PvlGroup.h"
27 #include "SubArea.h"
28 
29 using namespace std;
30 
31 namespace Isis {
32 
40  Enlarge::Enlarge(Cube *pInCube, const double sampleScale,
41  const double lineScale) {
42  // Input Cube
43  mInCube = pInCube;
44 
45  // Set input image area to defaults
46  mdStartSample = 1;
47  mdEndSample = mInCube->sampleCount();
48  mdStartLine = 1;
49  mdEndLine = mInCube->lineCount();
50 
51  // Save off the sample and line magnification
52  mdSampleScale = sampleScale;
53  mdLineScale = lineScale;
54 
55  miOutputSamples = (int)ceil(mInCube->sampleCount() * mdSampleScale);
56  miOutputLines = (int)ceil(mInCube->lineCount() * mdLineScale);
57  }
58 
70  bool Enlarge::Xform(double &inSample, double &inLine,
71  const double outSample, const double outLine) {
72  inSample = (outSample - 0.5) / mdSampleScale + 0.5 + (mdStartSample - 1);
73  inLine = (outLine - 0.5) / mdLineScale + 0.5 + (mdStartLine - 1);
74 
75  return true;
76  }
77 
89  void Enlarge::SetInputArea(double pdStartSample, double pdEndSample,
90  double pdStartLine, double pdEndLine) {
91  // Check for the right image dimensions
92  if (pdStartSample > pdEndSample || pdStartLine > pdEndLine) {
93  string sErrMsg = "Error in Input Area Dimesions";
94  throw IException(IException::Programmer, sErrMsg, _FILEINFO_);
95  }
96 
97  if (pdStartSample >= 1) {
98  mdStartSample = pdStartSample;
99  }
100  if (pdEndSample <= mInCube->sampleCount()) {
101  mdEndSample = pdEndSample;
102  }
103  if (pdStartLine >= 1) {
104  mdStartLine = pdStartLine;
105  }
106  if (pdEndLine <= mInCube->lineCount()) {
107  mdEndLine = pdEndLine;
108  }
109 
110  miOutputSamples = (int)ceil((mdEndSample - mdStartSample + 1) * mdSampleScale);
111  miOutputLines = (int)ceil((mdEndLine - mdStartLine + 1) * mdLineScale);
112  }
113 
127  PvlGroup Enlarge::UpdateOutputLabel(Cube *pOutCube) {
128  int iNumSamples= mInCube->sampleCount();
129  int iNumLines = mInCube->lineCount();
130  // Construct a label with the results
131  // This is the Results group that will go into the application
132  // log file. This group must be created by the calling application.
133  // Information will be added to it if the Mapping or Instrument
134  // groups are deleted from the output image label
135  PvlGroup resultsGrp("Results");
136  resultsGrp += PvlKeyword("InputLines", toString(iNumLines));
137  resultsGrp += PvlKeyword("InputSamples", toString(iNumSamples));
138  resultsGrp += PvlKeyword("StartingLine", toString((int)mdStartLine));
139  resultsGrp += PvlKeyword("StartingSample", toString((int)mdStartSample));
140  resultsGrp += PvlKeyword("EndingLine", toString((int)mdEndLine));
141  resultsGrp += PvlKeyword("EndingSample", toString((int)mdEndSample));
142  resultsGrp += PvlKeyword("LineIncrement", toString(1. / mdLineScale));
143  resultsGrp += PvlKeyword("SampleIncrement", toString(1. / mdSampleScale));
144  resultsGrp += PvlKeyword("OutputLines", toString(miOutputSamples));
145  resultsGrp += PvlKeyword("OutputSamples", toString(miOutputLines));
146 
147  SubArea subArea;
148  subArea.SetSubArea(mInCube->lineCount(), mInCube->sampleCount(), (int)mdStartLine, (int)mdStartSample,
149  (int)mdEndLine, (int)mdEndSample, 1.0 / mdLineScale, 1.0 / mdSampleScale);
150  subArea.UpdateLabel(mInCube, pOutCube, resultsGrp);
151 
152  return resultsGrp;
153  }
154 }
155 
156