VR-Vantage 3.1 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Eigenmaterials.h
Go to the documentation of this file.
1 /* 2007 JRM Technologies, Inc.*/
2 /* CF071031 */
3 #ifndef _EIGENMATERIALS_H_
4 #define _EIGENMATERIALS_H_
5 
6 #ifdef __cplusplus
7 extern "C"
8 {
9 #endif
10 
11 #include <time.h>
12 
13 #include "JRMDefines.h"
14 #include "JRMlibrary.h"
15 #include "JRMKMeans.h"
16 #include "SigSimDefines.h"
17 #include "sigsim.h"
18 #include "sigsimDLLstub.h"
19 
20 #define NCOEFF 6
21 
22 
23  // ------------------- STANDARD EIGENMATERIALS - CF 071031 --------------------------------------------------------------------------
24 
25 //#ifndef NEIGENMATERIALS
26 //#define NEIGENMATERIALS 7
27 //#endif
28 #define USE_AVERANGE_AREAS FALSE /* Specifies whether to use {Amin,Amax} or {Aave,Aspan} as evapotranspiration axes. */
29 #define LOTOL 0.005 /* Value of (max-min)/(max+min) below which an axis is considered degenerate. */
30 
31 
32  //int WriteFractionFile(char *outfilebasename, MATERIAL_EIGENFRACTIONS *matlfraction, long nmatls, int neigenmaterials);
33  //int ReadFractionFile(char *outfilebasename, MATERIAL_EIGENFRACTIONS **matlfraction, long *nmatls, int *neigenmaterials);
34  //int ActiveIndex(int OriginalIndex, SPACE *space);
35  //int ConvertDegeneratePoint(NPOINT *degenerate, NPOINT *nondegenerate, SPACE *ndspace);
36  //int CreateEigenMaterialsInMemory(char *sigsim_data_dir, char *matl_sys_file, char *outputbasename, MATERIAL_EIGENFRACTIONS **matlfraction, long *nmatls, MATL_PROP_TABLE **eig_table, int *neigenmaterials, double env_update_interval);
37  //int CreateEigenMaterialsOnDisk(char *sigsim_data_dir, char *matl_sys_file, char *outfilebasename, double env_update_interval);
38  //int ReconstructMaterials(char *sigsim_data_dir, char *eigmatl_sys_file, char *outfilebasename, double env_update_interval);
39  //int ReconstructThermalSpinup(char *outfilebasename, int neigenmaterials);
40  //int CreateMaterialsWhichDifferAlongOneAxis(char *sigsim_data_dir, char *matl_sys_file, int referencems, char *outfilebasename, int diffaxis, double minfrac, double maxfrac, int nmatlsout, double env_update_interval);
41 
42  // -------------------- BASIS-FUNCTION TEST - SIMPLE STAND-ALONE VERSION - CF080204 ------------------------------------------------------
43  /*
44  double xphase(double tod);
45  double ThetaLessThan(double x, double y);
46  double Sunshine(double tod);
47  double Skyshine(double tod);
48  double Earthshine(double tod);
49  double Evapotranspiration(double tod);
50  double Constant(double tod);
51  double FitCurve(double tod, double coeff[5], double todL);
52  double TestCurve(double tod);
53  void FillBasisFunctionMatrix(double F[25], double todlag);
54  void FillTestCurveArray(double test[5]);
55  int FitToBasisFunctions(double F[25], double test[5], double coeff[5]);
56  double RMSerror(double todlag, double coeff[5]);
57  int main();
58  */
59 
60 
61  // -------------------- BASIS-FUNCTION TEST - FULL SIGSIM VERSION - CF080205 ------------------------------------------------------
62 
63 #define NCOEFF 6
64 #define HOTOBJECT_EMISSION (CM_SQUARED_2_M_SQUARED*SIGMA * power(500.0, 4)) // Full-band Planck emission of 500degK object, for use as constant irradiance standard.
65 #define CONST300K_EMISSION (CM_SQUARED_2_M_SQUARED*SIGMA * power(300.0, 4)) // Full-band Planck emission of 300degK object, for use as constant irradiance standard.
66 
67  //double FitCurve(double tod, double coeff[NCOEFF], double todL, THERMAL_CACHE *tc, double env_update_interval);
68  //void FillBasisFunctionMatrix(double F[NCOEFF*NCOEFF], double todlag, THERMAL_CACHE *tc, double env_update_interval);
69  //void FillTestCurveArray(double test[NCOEFF], MATL_PROP_TABLE *mp_table);
70  //int FitToBasisFunctions(double F[NCOEFF*NCOEFF], double test[NCOEFF], double coeff[NCOEFF]);
71  //double TestCurve(double tod, MATL_PROP_TABLE *mp_table);
72  //double RMSerror(double todlag, double coeff[NCOEFF], MATL_PROP_TABLE *mp_table, THERMAL_CACHE *tc, double env_update_interval);
73  //void FindOptimumCoefficientsAndLag(MATL_PROP_TABLE *mp_table, THERMAL_CACHE *tc, double env_update_interval, double optcoeff[NCOEFF], double *optlag);
74 
75 
76  // -------------------- ITERATIVE-FIT TEST - FULL SIGSIM VERSION - CF080212 ------------------------------------------------------
77 #define NITCOEFF 4
78 #define TEMPFLUXMAX ((2000.0)*(5000.0)*(10.0)) // [J/m2/degK]
79 #define CONVECTMAX (4.0 + 3.8*pow(100.0, 0.8)) // [W/m2/degK] for windspeedmax=100.0 m/s.
80 #define CONSTEIMAX (CM_SQUARED_2_M_SQUARED*SIGMA*power(500.0,4)) // [W/m2] for 500.0 degK BB
81 
82  //double TemperatureIterativeFitFunction(NPOINT coeff, double *auxiliary, int nauxiliary)
83  //double PolynomialTestIterativeFitFunction(NPOINT coeff, double *auxiliary, int nauxiliary)
84  //void FindOptimalIterativeFitCoeffs(MATL_PROP_TABLE *mp_table, THERMAL_CACHE *tc, double env_update_interval, NPOINT *optcoeff)
85  //double TemperatureFunction(double tod, NPOINT coeff, double startdegK, THERMAL_CACHE *tc, double env_update_interval);
86 
87  // -------------------- BOUNDED-EIGENMATERIAL TEST - FULL SIGSIM VERSION - CF080214 ------------------------------------------------------
88 
89 
90 //#ifndef NEIGENMATERIALS
91 //#define NEIGENMATERIALS 7
92 //#endif
93 
94 typedef struct
95 {
96  char matlname[50];
97  double *eigenfraction;
99 
100  #define NUM_PHYSPROPS 5
101 
102  typedef struct
103  {
109  } AXISSELECT;
110 
111  double GetMaterialNameAxisValue(char *name);
113  int ClusterMaterialSystemsInPhysicalPropertySpace(int mingroups, int maxgroups, MATL_PROP_TABLE *mp_table, int nmatls, int *group_index, int *ngroups, int MIN_MTLSPERGROUP, AXISSELECT axisselect, double EmatTolerance);
114  double RMSDifference(double *a, double *b, long nelements);
116  double RadianceBoundedFitFunction(NPOINT coeff, double *auxiliary, int nauxiliary);
117  //double BoundedFitRadiance(double tod, MATL_PROP_TABLE *mp_table, int *eig_index, int neigenmaterials, MATERIAL_EIGENFRACTIONS *mtlfractions);
118  //double ActualBBRadiance(double tod, MATL_PROP_TABLE *mp_table);
119  void FindOptimalBoundedFitCoeffs(MATL_PROP_TABLE **emat, int nemats, MATL_PROP_TABLE *tofit, NPOINT *optcoeff);
120  void FindExactBoundedFitCoeffs(MATL_PROP_TABLE **emat, int nemats, MATL_PROP_TABLE *tofit, NPOINT *optcoeff);
121  //double RMSFitDifference(MATL_PROP_TABLE *mp_table, int *eig_index, int neigenmaterials, MATERIAL_EIGENFRACTIONS *mtlfractions, int indextotest);
122  int FindExtremalMaterialsInGroup(MATL_PROP_TABLE *mp_table_in, int nmatls_in, int *group_index, int group, int *mtl1, int *mtl2, int *ngroupmtls, double EmatTolerance);
123  int FindEigenmaterialsAndFit(MATL_PROP_TABLE *mp_table_in, int nmatls_in, int *group_index, int ngroups, int **eig_index_out, int *neigenmaterials, MATERIAL_EIGENFRACTIONS **mtlfractions_out, jrmbool MATRIX, jrmbool FITINGROUP, jrmbool ALLOWSINGLEGROUPEMAT, double EmatTolerance);
124  //int BoundedEigenMaterialAnalysis(MATL_PROP_TABLE *mp_table, long nmatls, MATERIAL_EIGENFRACTIONS **mtlfraction, int **eig_index_out, int *neigenmaterials, int maxrequestedemats, int mingroups, int maxgroups, int MIN_MTLSPERGROUP, jrmbool MATRIX, jrmbool FITINGROUP, jrmbool ALLOWSINGLEGROUPEMAT, AXISSELECT axisselect, double EmatTolerance);
125  //int BoundedEigenMaterialFitToKnownGrouping(MATL_PROP_TABLE *mp_table, long nmatls, MATERIAL_EIGENFRACTIONS **mtlfraction, int **eig_index_out, int *neigenmaterials, int *group_index, int ngroups, jrmbool MATRIX, jrmbool ALLOWSINGLEGROUPEMAT, double EmatTolerance);
126  int FindNumberOfMatsInGroup(int whichgroup, int *group_index, int totmatls);
127  int FindNumberOfEmatsInGroup(int whichgroup, int *group_index, int *emat_index, int neigenmaterials);
128  jrmbool IsEmat(int matl_index, int *emat_index, int neigenmaterials);
129  jrmbool DonateMatsToOtherGroups(int ngroups, int *group_index, int nmatls, int **emat_index, int *neigenmaterials, int MIN_MTLSPERGROUP, MATL_PROP_TABLE *mp_table, MATERIAL_EIGENFRACTIONS **mtlfraction, jrmbool ALLOWSINGLEGROUPEMAT);
130  //int WriteEigenmaterialMSFile(char *sigsim_data_dir, char *ms_filename, char *dbname, MATL_PROP_TABLE *mp_table, int *eig_index, int neigenmaterials);
131 
132 
133  // -------------------- STAGED-EIGENMATERIAL ALGORITHM - FULL SIGSIM VERSION - CF110816 ------------------------------------------------------
134 
135 #ifndef NEIGENMATERIALS
136 #define NEIGENMATERIALS 6
137 #endif
138 
139 typedef struct
140 {
141  int MSID; // material system index in final combined output MS file
142  char MSName[50]; // material system name
143  int GroupID; // group index identifier
144  double GroupPopulationPercentage; // normalized pixel percentage of this MSID in the final combined output MS file
146 
147 
148 typedef struct
149 {
150  int MSID; // material system index in final combined output MS file
151  char MSName[50]; // material system name
152  int EmatID[NEIGENMATERIALS]; // MSIDs chosen as Emats to mix for this material system
153 } EMAT_SELECT;
154 
155 SIGSIM_API int AddEMAT_SELECT(EMAT_SELECT **c, int *nc, EMAT_SELECT toadd);
157 SIGSIM_API int RemoveEMAT_SELECT(EMAT_SELECT **P, int *np, int index);
158 SIGSIM_API int ReadEmatSelectFile(const char *infile, EMAT_SELECT **eselect, int *neselects);
159 SIGSIM_API int FitToKnownEigenmaterials(MATL_PROP_TABLE *mp_table_in, int nmatls_in, EMAT_SELECT *eselect, int neselects, int *neigenmaterials, int **eig_index_out, MATERIAL_EIGENFRACTIONS **mtlfractions_out, jrmbool MATRIX);
160 
161 
162  // ----- The following routines employ the proprietary JRM Eigenmaterial approach. BE SURE TO USE FreeMATERIAL_EIGENFRACTIONSArray, FreeIntArray, and Free_MatlPropTables to free this memory!
163 
164 SIGSIM_API int AllocateMATERIAL_EIGENFRACTIONSArray(MATERIAL_EIGENFRACTIONS **matlfraction, long nmatls, int neigenmaterials);
165 SIGSIM_API int AllocateMATERIAL_EIGENFRACTIONSFractionArrays(MATERIAL_EIGENFRACTIONS **matlfraction, long nmatls, int neigenmaterials);
167 SIGSIM_API int WriteFractionFileWithEmatNameHeader(char *outfilebasename, MATERIAL_EIGENFRACTIONS *matlfraction, long nmatls, int *ematIndices, int neigenmaterials);
168 SIGSIM_API int WriteFractionFile(char *outfilebasename, MATERIAL_EIGENFRACTIONS *matlfraction, long nmatls, int neigenmaterials);
169 SIGSIM_API int ReadFractionFile(char *outfilebasename, MATERIAL_EIGENFRACTIONS **matlfraction, long *nmatls, int *neigenmaterials);
170 SIGSIM_API int CreateEigenMaterialsInMemory(char *sigsim_data_dir, char *matl_sys_file, char *outputbasename, MATERIAL_EIGENFRACTIONS **matlfraction, long *nmatls, MATL_PROP_TABLE **eig_table, int *neigenmaterials, double env_update_interval);
171 SIGSIM_API int CreateEigenMaterialsOnDisk(char *sigsim_data_dir, char *matl_sys_file, char *outfilebasename, double env_update_interval);
172 SIGSIM_API int ReconstructMaterials(char *sigsim_data_dir, char *eigmatl_sys_file, char *outfilebasename, double env_update_interval);
173 SIGSIM_API int ReconstructThermalSpinup(char *outfilebasename, int neigenmaterials);
174 SIGSIM_API int CreateMaterialsWhichDifferAlongOneAxis(char *sigsim_data_dir, char *matl_sys_file, int referencems, char *outfilebasename, int diffaxis, double minfrac, double maxfrac, int nmatlsout, double env_update_interval);
175 SIGSIM_API double FitCurve(double tod, double coeff[NCOEFF], double todL, THERMAL_CACHE *tc, double env_update_interval);
176 SIGSIM_API void FillBasisFunctionMatrix(double F[NCOEFF*NCOEFF], double todlag, THERMAL_CACHE *tc, double env_update_interval);
177 SIGSIM_API void FillTestCurveArray(double test[NCOEFF], MATL_PROP_TABLE *mp_table);
178 SIGSIM_API int FitToBasisFunctions(double F[NCOEFF*NCOEFF], double test[NCOEFF], double coeff[NCOEFF]);
179 SIGSIM_API double TestCurve(double tod, MATL_PROP_TABLE *mp_table);
180 SIGSIM_API double RMSerror(double todlag, double coeff[NCOEFF], MATL_PROP_TABLE *mp_table, THERMAL_CACHE *tc, double env_update_interval);
181 SIGSIM_API void FindOptimumCoefficientsAndLag(MATL_PROP_TABLE *mp_table, THERMAL_CACHE *tc, double env_update_interval, double optcoeff[NCOEFF], double *optlag);
182 SIGSIM_API double TemperatureFunction(double tod, NPOINT coeff, double startdegK, THERMAL_CACHE *tc, double env_update_interval);
183 SIGSIM_API double TemperatureIterativeFitFunction(NPOINT coeff, double *auxiliary, int nauxiliary);
184 SIGSIM_API double PolynomialTestIterativeFitFunction(NPOINT coeff, double *auxiliary, int nauxiliary);
185 SIGSIM_API void FindOptimalIterativeFitCoeffs(MATL_PROP_TABLE *mp_table, THERMAL_CACHE *tc, double env_update_interval, NPOINT *optcoeff);
186 SIGSIM_API int BoundedEigenMaterialAnalysis(MATL_PROP_TABLE *mp_table, long nmatls, MATERIAL_EIGENFRACTIONS **mtlfraction, int **eig_index_out, int *neigenmaterials, int maxrequestedemats, int mingroups, int maxgroups, int MIN_MTLSPERGROUP, jrmbool MATRIX, jrmbool FITINGROUP, jrmbool ALLOWSINGLEGROUPEMAT, AXISSELECT axisselect, double EmatTolerance);
187 SIGSIM_API int BoundedEigenMaterialFitToKnownGrouping(MATL_PROP_TABLE *mp_table, long nmatls, MATERIAL_EIGENFRACTIONS **mtlfraction, int **eig_index_out, int *neigenmaterials, int *group_index, int ngroups, jrmbool MATRIX, jrmbool ALLOWSINGLEGROUPEMAT, double EmatTolerance);
188 SIGSIM_API double BoundedFitRadiance(double tod, MATL_PROP_TABLE *mp_table, int *eig_index, int neigenmaterials, MATERIAL_EIGENFRACTIONS *mtlfractions);
189 SIGSIM_API double ActualBBRadiance(double tod, MATL_PROP_TABLE *mp_table);
190 SIGSIM_API double RMSFitDifference(MATL_PROP_TABLE *mp_table, int *eig_index, int neigenmaterials, MATERIAL_EIGENFRACTIONS *mtlfractions, int indextotest);
191 SIGSIM_API int WriteEigenmaterialMSFile(char *sigsim_data_dir, char *ms_filename, char *dbname, MATL_PROP_TABLE *mp_table, int *eig_index, int neigenmaterials);
192 
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 
199 #endif // _EIGENMATERIALS_H_


Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)