Isis 3 Programmer Reference
Mixed.cpp
1 #include <cmath>
2 #include "Mixed.h"
3 #include "SpecialPixel.h"
4 #include "IException.h"
5 
6 namespace Isis {
7  Mixed::Mixed(Pvl &pvl, PhotoModel &pmodel) : NormModel(pvl, pmodel) {
8  PvlGroup &algorithm = pvl.findObject("NormalizationModel").findGroup("Algorithm", Pvl::Traverse);
9 
10  // Set default value
11  SetNormPharef(0.0);
12  SetNormIncref(0.0);
13  SetNormEmaref(0.0);
14  SetNormPhamat(0.0);
15  SetNormIncmat(0.0);
16  SetNormEmamat(0.0);
17  SetNormThresh(30.0);
18  SetNormAlbedo(1.0);
19 
20  // Get value from user
21  if(algorithm.hasKeyword("Pharef")) {
22  SetNormPharef(algorithm["Pharef"]);
23  }
24 
25  if(algorithm.hasKeyword("Incref")) {
26  SetNormIncref(algorithm["Incref"]);
27  }
28 
29  if(algorithm.hasKeyword("Emaref")) {
30  SetNormEmaref(algorithm["Emaref"]);
31  }
32 
33  if(algorithm.hasKeyword("Incmat")) {
34  SetNormIncmat(algorithm["Incmat"]);
35  }
36 
37  if(algorithm.hasKeyword("Phamat")) {
38  SetNormPhamat(algorithm["Phamat"]);
39  } else {
40  p_normPhamat = p_normIncmat;
41  }
42 
43  if(algorithm.hasKeyword("Emamat")) {
44  SetNormEmamat(algorithm["Emamat"]);
45  }
46 
47  if(algorithm.hasKeyword("Thresh")) {
48  SetNormThresh(algorithm["Thresh"]);
49  }
50 
51  if(algorithm.hasKeyword("Albedo")) {
52  SetNormAlbedo(algorithm["Albedo"]);
53  }
54 
55  // First-time setup
56  // Calculate normalization at standard conditions
57  // Turn off Hapke opposition effect
58  GetPhotoModel()->SetStandardConditions(true);
59  p_psurfref = GetPhotoModel()->CalcSurfAlbedo(p_normPharef, p_normIncref, p_normEmaref);
60  double pprimeref = GetPhotoModel()->PhtTopder(p_normPharef, p_normIncref, p_normEmaref);
61 
62  if(p_psurfref == 0.0) {
63  std::string err = "Divide by zero error";
64  throw IException(IException::Unknown, err, _FILEINFO_);
65  }
66  else {
67  p_rhobar = p_normAlbedo / p_psurfref;
68  }
69 
70  // Calculate brightness and topo derivative at matchpoint incidence
71  p_psurfmatch = GetPhotoModel()->CalcSurfAlbedo(p_normPhamat, p_normIncmat, p_normEmamat);
72  p_pprimematch = GetPhotoModel()->PhtTopder(p_normPhamat, p_normIncmat, p_normEmamat);
73 
74  // Calculate numerator of the stretch coeff. a; if it is very
75  // large or small we haven't chosen a good reference state
76  double arg = pow(p_psurfref, 2.0) + pow(p_psurfmatch * pprimeref / std::max(1.0e-30, p_pprimematch), 2.0);
77  if((arg < 1.0e-10) || (arg > 1.0e10)) {
78  std::string err = "Bad reference state encountered";
79  throw IException(IException::Unknown, err, _FILEINFO_);
80  }
81 
82  p_anum = sqrt(arg);
83  GetPhotoModel()->SetStandardConditions(false);
84  }
85 
86  void Mixed::NormModelAlgorithm(double phase, double incidence, double emission,
87  double demincidence, double dememission, double dn,
88  double &albedo, double &mult, double &base) {
89  static double psurf;
90  static double pprime;
91  static double aden;
92 
93  static double old_phase = -9999;
94  static double old_incidence = -9999;
95  static double old_emission = -9999;
96  static double old_demincidence = -9999;
97  static double old_dememission = -9999;
98 
99  if (old_phase != phase || old_incidence != incidence || old_emission != emission ||
100  old_demincidence != demincidence || old_dememission != dememission) {
101 
102  // code for scaling each pixel
103  psurf = GetPhotoModel()->CalcSurfAlbedo(phase, demincidence, dememission);
104  pprime = GetPhotoModel()->PhtTopder(phase, demincidence, dememission);
105  double arg = pow(psurf, 2.0) + pow(p_psurfmatch * pprime / std::max(1.0e-30, p_pprimematch), 2.0);
106  aden = sqrt(std::max(1.0e-30, arg));
107 
108  old_phase = phase;
109  old_incidence = incidence;
110  old_emission = emission;
111  old_demincidence = demincidence;
112  old_dememission = dememission;
113  }
114 
115  // thresh is a parameter limiting how much we amplify the dns
116  // shouldn't actually get a large amplification in this mode because
117  // of the growing pprime term in the denominator.
118 
119  if(aden > p_anum * p_normThresh) {
120  albedo = NULL8;
121  }
122  else {
123  albedo = dn * p_anum / aden + p_rhobar * (p_psurfref - p_anum / aden * psurf);
124  }
125  }
126 
136  void Mixed::SetNormPharef(const double pharef) {
137  if(pharef < 0.0 || pharef >= 180.0) {
138  std::string msg = "Invalid value of normalization pharef [" +
139  IString(pharef) + "]";
141  }
142 
143  p_normPharef = pharef;
144  }
145 
155  void Mixed::SetNormIncref(const double incref) {
156  if(incref < 0.0 || incref >= 90.0) {
157  std::string msg = "Invalid value of normalization incref [" +
158  IString(incref) + "]";
160  }
161 
162  p_normIncref = incref;
163  }
164 
174  void Mixed::SetNormEmaref(const double emaref) {
175  if(emaref < 0.0 || emaref >= 90.0) {
176  std::string msg = "Invalid value of normalization emaref [" +
177  IString(emaref) + "]";
179  }
180 
181  p_normEmaref = emaref;
182  }
183 
194  void Mixed::SetNormPhamat(const double phamat) {
195  if(phamat < 0.0 || phamat >= 180.0) {
196  std::string msg = "Invalid value of normalization phamat [" +
197  IString(phamat) + "]";
199  }
200 
201  p_normPhamat = phamat;
202  }
203 
214  void Mixed::SetNormIncmat(const double incmat) {
215  if(incmat < 0.0 || incmat >= 90.0) {
216  std::string msg = "Invalid value of normalization incmat [" +
217  IString(incmat) + "]";
219  }
220 
221  p_normIncmat = incmat;
222  }
223 
234  void Mixed::SetNormEmamat(const double emamat) {
235  if(emamat < 0.0 || emamat >= 90.0) {
236  std::string msg = "Invalid value of normalization emamat [" +
237  IString(emamat) + "]";
239  }
240 
241  p_normEmamat = emamat;
242  }
243 
250  void Mixed::SetNormAlbedo(const double albedo) {
251  p_normAlbedo = albedo;
252  }
253 
268  void Mixed::SetNormThresh(const double thresh) {
269  p_normThresh = thresh;
270  }
271 }
272 
273 extern "C" Isis::NormModel *MixedPlugin(Isis::Pvl &pvl, Isis::PhotoModel &pmodel) {
274  return new Isis::Mixed(pvl, pmodel);
275 }
double CalcSurfAlbedo(double pha, double inc, double ema)
Calculate the surface brightness using photometric angle information.
Definition: PhotoModel.cpp:171
void SetNormEmamat(const double emamat)
Set the normalization function parameter.
Definition: Mixed.cpp:234
Search child objects.
Definition: PvlObject.h:170
void SetNormPhamat(const double phamat)
Set the normalization function parameter.
Definition: Mixed.cpp:194
double PhtTopder(double phase, double incidence, double emission)
Obtain topographic derivative of an arbitrary photometric function.
Definition: PhotoModel.cpp:58
void SetNormAlbedo(const double albedo)
Set the normalization function parameter.
Definition: Mixed.cpp:250
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:134
void SetNormIncref(const double incref)
Set the normalization function parameter.
Definition: Mixed.cpp:155
Container for cube-like labels.
Definition: Pvl.h:135
void SetNormPharef(const double pharef)
Set parameters needed for albedo normalization.
Definition: Mixed.cpp:136
void SetNormIncmat(const double incmat)
Set the normalization function parameter.
Definition: Mixed.cpp:214
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Mixed albedo/topo normalization without atmosphere.
Definition: Mixed.h:63
void SetNormEmaref(const double emaref)
Set the normalization function parameter.
Definition: Mixed.cpp:174
void SetNormThresh(const double thresh)
Set the normalization function parameter.
Definition: Mixed.cpp:268