21 #include <boost/algorithm/string.hpp>
39 if (sensorID.find(
"Formosat") != std::string::npos)
return true;
49 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
59 if (imageKeywordlist.
HasKey(
"support_data.instrument"))
61 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.instrument");
74 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
84 if (imageKeywordlist.
HasKey(
"support_data.instrument_index"))
86 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.instrument_index");
87 unsigned int value = atoi(valueString.c_str());
100 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
110 std::vector<double> outputValues;
111 if (imageKeywordlist.
HasKey(
"support_data.solar_irradiance"))
113 std::vector<std::string> outputValuesString;
114 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.solar_irradiance");
116 boost::split(outputValuesString, valueString, boost::is_any_of(
" "));
117 for (
unsigned int i = 0; i < outputValuesString.size(); ++i)
119 outputValues.push_back(atof(outputValuesString[i].c_str()));
124 outputValuesVariableLengthVector.
SetSize(outputValues.size());
125 outputValuesVariableLengthVector.
Fill(0);
128 if (outputValues.size() == 1)
131 outputValuesVariableLengthVector[0] = outputValues[0];
133 else if (outputValues.size() == 4)
135 outputValuesVariableLengthVector[0] = outputValues[2];
136 outputValuesVariableLengthVector[1] = outputValues[1];
137 outputValuesVariableLengthVector[2] = outputValues[0];
138 outputValuesVariableLengthVector[3] = outputValues[3];
142 itkExceptionMacro(
"Invalid Solar Irradiance");
145 return outputValuesVariableLengthVector;
154 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
164 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
169 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
170 std::vector<std::string> outputValues;
172 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
174 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Day");
176 int value = atoi(outputValues[2].c_str());
186 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
196 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
201 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
202 std::vector<std::string> outputValues;
203 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
205 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Month");
207 int value = atoi(outputValues[1].c_str());
217 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
227 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
232 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
233 std::vector<std::string> outputValues;
234 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
236 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Year");
238 int value = atoi(outputValues[0].c_str());
248 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
258 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
263 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
264 std::vector<std::string> outputValues;
265 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
267 if (outputValues.size() < 4) itkExceptionMacro(<<
"Invalid Hour");
269 int value = atoi(outputValues[3].c_str());
279 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
289 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
294 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
295 std::vector<std::string> outputValues;
296 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
298 if (outputValues.size() < 5) itkExceptionMacro(<<
"Invalid Minute");
300 int value = atoi(outputValues[4].c_str());
310 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
320 if (!imageKeywordlist.
HasKey(
"support_data.production_date"))
325 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.production_date");
326 std::vector<std::string> outputValues;
327 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
329 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Day");
331 int value = atoi(outputValues[2].c_str());
341 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
351 if (!imageKeywordlist.
HasKey(
"support_data.production_date"))
356 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.production_date");
357 std::vector<std::string> outputValues;
358 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
360 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Month");
362 int value = atoi(outputValues[1].c_str());
372 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
382 if (!imageKeywordlist.
HasKey(
"support_data.production_date"))
387 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.production_date");
388 std::vector<std::string> outputValues;
389 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
391 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Year");
393 int value = atoi(outputValues[0].c_str());
402 if (!this->CanRead())
404 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
414 std::vector<double> outputValues;
415 if (imageKeywordlist.
HasKey(
"support_data.physical_bias"))
417 std::vector<std::string> outputValuesString;
418 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.physical_bias");
420 boost::split(outputValuesString, valueString, boost::is_any_of(
" "));
421 for (
unsigned int i = 0; i < outputValuesString.size(); ++i)
423 outputValues.push_back(atof(outputValuesString[i].c_str()));
428 outputValuesVariableLengthVector.
SetSize(outputValues.size());
429 outputValuesVariableLengthVector.
Fill(0);
433 if (outputValues.size() == 1)
436 outputValuesVariableLengthVector[0] = outputValues[0];
438 else if (outputValues.size() == 4)
440 outputValuesVariableLengthVector[0] = outputValues[2];
441 outputValuesVariableLengthVector[1] = outputValues[1];
442 outputValuesVariableLengthVector[2] = outputValues[0];
443 outputValuesVariableLengthVector[3] = outputValues[3];
447 itkExceptionMacro(
"Invalid Physical Bias");
450 return outputValuesVariableLengthVector;
458 if (!this->CanRead())
460 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
470 std::vector<double> outputValues;
471 if (imageKeywordlist.
HasKey(
"support_data.physical_gain"))
473 std::vector<std::string> outputValuesString;
474 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.physical_gain");
476 boost::split(outputValuesString, valueString, boost::is_any_of(
" "));
477 for (
unsigned int i = 0; i < outputValuesString.size(); ++i)
479 outputValues.push_back(atof(outputValuesString[i].c_str()));
484 outputValuesVariableLengthVector.
SetSize(outputValues.size());
485 outputValuesVariableLengthVector.
Fill(0);
489 if (outputValues.size() == 1)
492 outputValuesVariableLengthVector[0] = outputValues[0];
494 else if (outputValues.size() == 4)
496 outputValuesVariableLengthVector[0] = outputValues[2];
497 outputValuesVariableLengthVector[1] = outputValues[1];
498 outputValuesVariableLengthVector[2] = outputValues[0];
499 outputValuesVariableLengthVector[3] = outputValues[3];
503 itkExceptionMacro(
"Invalid Physical Gain");
506 return outputValuesVariableLengthVector;
515 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
525 if (!imageKeywordlist.
HasKey(
"support_data.incident_angle"))
530 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.incident_angle");
531 double value = 90 - atof(valueString.c_str());
541 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
551 if (!imageKeywordlist.
HasKey(
"support_data.incident_angle"))
556 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.sat_azimuth_angle");
557 double satAz = atof(valueString.c_str());
561 std::string softVersion = imageKeywordlist.
GetMetadataByKey(
"support_data.software_version");
563 if( (softVersion ==
"R2P_02.03.P1") || (softVersion ==
"R2P_02.02") || (softVersion ==
"R2P_02.03") )
565 if (!imageKeywordlist.
HasKey(
"support_data.viewing_angle_across_track"))
569 if (!imageKeywordlist.
HasKey(
"support_data.viewing_angle_along_track"))
573 if (!imageKeywordlist.
HasKey(
"support_data.scene_orientation"))
578 valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.viewing_angle_across_track");
579 double viewingAngleAcrossTrack( atof(valueString.c_str()) );
580 valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.viewing_angle_along_track");
581 double viewingAngleAlongTrack( atof(valueString.c_str()) );
582 valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.scene_orientation");
583 double sceneOrientation( atof(valueString.c_str()) );
585 double alpha = vcl_atan( vcl_tan( viewingAngleAcrossTrack *
CONST_PI_180 ) / vcl_tan( viewingAngleAlongTrack * CONST_PI_180 ) ) *
CONST_180_PI;
587 if( viewingAngleAlongTrack < 0 )
599 alpha -= sceneOrientation;
619 if (!this->CanRead())
621 itkExceptionMacro(<<
"Invalid metadata, no Formosat2 Image");
634 int nbBands = this->GetNumberOfBands();
635 std::string sensorId = this->GetSensorID();
642 if (sensorId ==
"SPOT4") wavel.
Fill(0.610);
643 else if (sensorId ==
"SPOT5") wavel.
Fill(0.480);
644 else itkExceptionMacro(<<
"Invalid Formosat2 Sensor ID");
646 else if (nbBands > 1 && nbBands < 5)
655 else itkExceptionMacro(<<
"Invalid number of bands...");
665 if (!this->CanRead())
667 itkExceptionMacro(<<
"Invalid metadata, no Formosat2 Image");
680 int nbBands = this->GetNumberOfBands();
681 std::string sensorId = this->GetSensorID();
687 if (sensorId ==
"SPOT4") wavel.
Fill(0.680);
688 else if (sensorId ==
"SPOT5") wavel.
Fill(0.710);
689 else itkExceptionMacro(<<
"Invalid Formosat2 Sensor ID");
691 else if (nbBands > 1 && nbBands < 5)
700 else itkExceptionMacro(<<
"Invalid number of bands...");
710 if (i == 0)
return 2;
711 if (i == 2)
return 0;
715 std::vector<unsigned int>
718 std::vector<unsigned int> rgb(3);
730 std::list <std::vector<float> > tmpSpectralBandList;
733 if (!this->CanRead())
735 itkExceptionMacro(<<
"Invalid Metadata, no Formosat Image");
745 int nbBands = this->GetNumberOfBands();
746 std::string sensorId = this->GetSensorID();
751 const float b0[281] =
761 0, 0, 0.000219376, 0.000219425, 0.000231534, 0.000284519,
762 0.000550079, 0.001, 0.003, 0.006, 0.012, 0.0235,
763 0.035, 0.043, 0.0503893, 0.0525, 0.055, 0.0565,
764 0.058, 0.059, 0.059, 0.0608594, 0.061, 0.0615,
765 0.062, 0.063, 0.063, 0.064, 0.063, 0.064,
766 0.065, 0.066, 0.066, 0.066, 0.066, 0.0675,
767 0.069, 0.0708104, 0.0709615, 0.0709001, 0.071, 0.0715,
768 0.073, 0.074, 0.074, 0.073, 0.073, 0.0735,
769 0.075, 0.0765, 0.078, 0.078, 0.078, 0.0785,
770 0.0800145, 0.0815, 0.083, 0.083, 0.083, 0.083,
771 0.083, 0.0835, 0.085, 0.0865, 0.087, 0.088,
772 0.087, 0.087, 0.088, 0.0885, 0.0907023, 0.0915,
773 0.092, 0.092, 0.092, 0.092, 0.093, 0.094,
774 0.095, 0.096, 0.096, 0.096, 0.095, 0.095,
775 0.095, 0.095, 0.096, 0.0975, 0.098, 0.099,
776 0.099, 0.098, 0.098, 0.0965, 0.096, 0.0965,
777 0.098, 0.0985, 0.099, 0.0995, 0.099, 0.0975,
778 0.097, 0.0955, 0.095, 0.095, 0.095, 0.0965,
779 0.097, 0.098, 0.098, 0.0975, 0.097, 0.096,
780 0.095, 0.095, 0.094, 0.094, 0.095, 0.0955,
781 0.096, 0.097, 0.097, 0.097, 0.097, 0.097,
782 0.097, 0.096, 0.097, 0.097, 0.097, 0.098,
783 0.098, 0.096, 0.095, 0.094, 0.093, 0.092,
784 0.091, 0.0905658, 0.089, 0.089, 0.089, 0.088,
785 0.088, 0.0875, 0.087, 0.086, 0.085, 0.084,
786 0.083, 0.0825, 0.082, 0.081, 0.081, 0.0804051,
787 0.079, 0.078, 0.077, 0.077, 0.076, 0.075,
788 0.074, 0.0735, 0.073, 0.0725, 0.072, 0.071,
789 0.071, 0.0704136, 0.069, 0.0685, 0.068, 0.067,
790 0.066, 0.0645, 0.063, 0.062, 0.0607892, 0.059,
791 0.058, 0.057, 0.056, 0.0545, 0.052, 0.0455,
792 0.038, 0.0286994, 0.0202138, 0.0125, 0.007, 0.004,
793 0.002, 0.001, 0.000909856, 0.000512159, 0.000357051, 0.00029112,
794 0.000215752, 0.000187213, 0.000171918, 0.000169724, 0.000166392, 0.000163058,
795 0.000159726, 0.000156393, 0.000153061, 0.000149728, 0, 0,
803 const std::vector<float> vb0 (b0, b0 +
sizeof(b0) /
sizeof(
float) );
804 tmpSpectralBandList.push_back(vb0);
806 else if (nbBands > 1 && nbBands < 5)
808 const float b1[281] =
818 0, 0, 0.000354959, 0.000354603, 0.000376745, 0.000478212,
819 0.0009718, 0.002, 0.005, 0.0124297, 0.024, 0.0415,
820 0.057, 0.0685, 0.074, 0.074, 0.076, 0.0795695,
821 0.082, 0.084, 0.083, 0.0825, 0.086, 0.0910953,
822 0.094, 0.096, 0.096, 0.094, 0.094, 0.096,
823 0.099, 0.0995, 0.099, 0.098, 0.095, 0.092,
824 0.095, 0.0985, 0.092, 0.0695, 0.037, 0.025,
825 0.009, 0.0025, 0.001, 0.000847053, 0.000588401, 0.00051966,
826 0.00050602, 0, 0, 0, 0, 0,
859 const float b2[281] =
874 0, 0, 0.000324677, 0.000326475, 0.000331943, 0.000386303,
875 0.000447683, 0.001, 0.003, 0.0045, 0.012, 0.0205,
876 0.036, 0.0615, 0.075, 0.081, 0.082, 0.0845,
877 0.087, 0.0885, 0.088, 0.087, 0.086, 0.0875,
878 0.0908484, 0.0925, 0.094, 0.094, 0.093, 0.0925,
879 0.093, 0.0955, 0.097, 0.098, 0.099, 0.099,
880 0.099, 0.099, 0.099, 0.099, 0.095, 0.0815,
881 0.057, 0.032, 0.018, 0.0112534, 0.005, 0.0015,
882 0.000758484, 0.000604297, 0.000512471, 0.000475316, 0.000453283, 0.00044559,
910 const float b3[281] =
932 0, 0, 0, 0, 0, 0.000461752,
933 0.001, 0.001, 0.003, 0.006, 0.013, 0.0335,
934 0.063, 0.089, 0.098, 0.099, 0.099, 0.099,
935 0.099, 0.0985, 0.097, 0.0945, 0.092, 0.0906796,
936 0.089, 0.0907659, 0.093, 0.0965, 0.1, 0.097,
937 0.091, 0.0865, 0.086, 0.0910438, 0.094, 0.092,
938 0.093, 0.088, 0.064, 0.034, 0.015, 0.0075,
939 0.006, 0.0045, 0.003, 0.001, 0.000607601, 0.000202927,
961 const float b4[281] =
990 0, 0.000481456, 0.00071923, 0.00098303, 0.001, 0.000947915,
991 0.00090899, 0.000887367, 0.000576847, 0.000470858, 0.00052246, 0.000713811,
992 0.001, 0.0015, 0.003, 0.005, 0.008, 0.0145,
993 0.022, 0.035, 0.049, 0.0595, 0.075, 0.0905,
994 0.098, 0.0995, 0.097, 0.093, 0.091, 0.0925,
995 0.094, 0.096, 0.096, 0.0955, 0.094, 0.092,
996 0.0907811, 0.089, 0.088, 0.088, 0.088, 0.088,
997 0.088, 0.0875, 0.087, 0.086, 0.085, 0.084,
998 0.083, 0.083, 0.082, 0.081, 0.0806396, 0.079,
999 0.078, 0.077, 0.076, 0.075, 0.074, 0.073,
1000 0.072, 0.071, 0.0700369, 0.0685, 0.067, 0.0655,
1001 0.064, 0.063, 0.063, 0.062, 0.059, 0.054,
1002 0.043, 0.034, 0.025, 0.016, 0.009, 0.0055,
1003 0.003, 0.0015, 0.001, 0.000691333, 0.000432126, 0.000356974,
1004 0.000265441, 0.000219773, 0.000195346, 0.000192716, 0.000188932, 0.000185148,
1005 0.000181364, 0.00017758, 0.000173796, 0.000170011, 0.000166227, 0,
1013 const std::vector<float> vb1 (b1, b1 +
sizeof(b1) /
sizeof(
float) );
1014 tmpSpectralBandList.push_back(vb1);
1015 const std::vector<float> vb2 (b2, b2 +
sizeof(b2) /
sizeof(
float) );
1016 tmpSpectralBandList.push_back(vb2);
1017 const std::vector<float> vb3 (b3, b3 +
sizeof(b3) /
sizeof(
float) );
1018 tmpSpectralBandList.push_back(vb3);
1019 const std::vector<float> vb4 (b4, b4 +
sizeof(b4) /
sizeof(
float) );
1020 tmpSpectralBandList.push_back(vb4);
1023 for (std::list <std::vector<float> >::const_iterator it = tmpSpectralBandList.begin(); it != tmpSpectralBandList.end(); ++it)
1026 wavelengthSpectralBand->GetNthElement(j)->SetFilterFunctionValues(*it);
1027 wavelengthSpectralBand->GetNthElement(j)->SetMinSpectralValue(0.300);
1028 wavelengthSpectralBand->GetNthElement(j)->SetMaxSpectralValue(1.0);
1029 wavelengthSpectralBand->GetNthElement(j)->SetUserStep(0.0025);
1034 return wavelengthSpectralBand;