21 #include <boost/algorithm/string.hpp>
25 #include <boost/lexical_cast.hpp>
30 using boost::lexical_cast;
31 using boost::bad_lexical_cast;
42 if (sensorID.find(
"PHR") != std::string::npos)
54 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
64 if (imageKeywordlist.
HasKey(
"support_data.instrument"))
66 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.instrument");
79 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
88 if (imageKeywordlist.
HasKey(
"support_data.instrument_index"))
90 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.instrument_index");
103 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
113 std::vector<double> outputValues;
114 if (imageKeywordlist.
HasKey(
"support_data.solar_irradiance"))
116 std::vector<std::string> outputValuesString;
117 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.solar_irradiance");
119 boost::split(outputValuesString, valueString, boost::is_any_of(
" "));
120 for (
unsigned int i = 0; i < outputValuesString.size(); ++i)
122 outputValues.push_back(atof(outputValuesString[i].c_str()));
127 outputValuesVariableLengthVector.
SetSize(outputValues.size());
128 outputValuesVariableLengthVector.
Fill(0);
132 const double defaultRadianceP = 1548.71;
134 const double defaultRadianceMS[4] =
142 double tolerance = 0.05;
144 if (outputValues.size() == 1)
147 if (vcl_abs(outputValues[0] - defaultRadianceP) > (tolerance * defaultRadianceP))
149 outputValuesVariableLengthVector[0] = defaultRadianceP;
153 outputValuesVariableLengthVector[0] = outputValues[0];
159 for (
unsigned int i = 0; i < outputValues.size(); ++i)
162 if (vcl_abs(outputValues[wavelenghPos] - defaultRadianceMS[wavelenghPos]) >
163 (tolerance * defaultRadianceMS[wavelenghPos]))
165 outputValuesVariableLengthVector[i] = defaultRadianceMS[wavelenghPos];
169 outputValuesVariableLengthVector[i] = outputValues[wavelenghPos];
174 return outputValuesVariableLengthVector;
183 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
193 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
198 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
199 std::vector<std::string> outputValues;
201 boost::split(outputValues, valueString, boost::is_any_of(
" T:-."));
206 value = lexical_cast<
int> (outputValues[2]);
208 catch (bad_lexical_cast &)
210 itkExceptionMacro(<<
"Invalid Day");
222 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
232 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
237 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
238 std::vector<std::string> outputValues;
239 boost::split(outputValues, valueString, boost::is_any_of(
" T:-."));
244 value = lexical_cast<
int> (outputValues[1]);
246 catch (bad_lexical_cast &)
248 itkExceptionMacro(<<
"Invalid Month");
259 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
269 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
274 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
275 std::vector<std::string> outputValues;
276 boost::split(outputValues, valueString, boost::is_any_of(
" T:-."));
281 value = lexical_cast<
int> (outputValues[0]);
283 catch (bad_lexical_cast &)
285 itkExceptionMacro(<<
"Invalid Year");
296 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
306 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
311 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
312 std::vector<std::string> outputValues;
313 boost::split(outputValues, valueString, boost::is_any_of(
" T:-."));
318 value = lexical_cast<
int> (outputValues[3]);
320 catch (bad_lexical_cast &)
322 itkExceptionMacro(<<
"Invalid Hour");
333 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
343 if (!imageKeywordlist.
HasKey(
"support_data.image_date"))
348 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.image_date");
349 std::vector<std::string> outputValues;
350 boost::split(outputValues, valueString, boost::is_any_of(
" T:-."));
355 value = lexical_cast<
int> (outputValues[4]);
357 catch (bad_lexical_cast &)
359 itkExceptionMacro(<<
"Invalid Minute");
370 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
380 if (!imageKeywordlist.
HasKey(
"support_data.production_date"))
385 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.production_date");
386 std::vector<std::string> outputValues;
387 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
392 value = lexical_cast<
int> (outputValues[2]);
394 catch (bad_lexical_cast &)
396 itkExceptionMacro(<<
"Invalid Day");
407 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
417 if (!imageKeywordlist.
HasKey(
"support_data.production_date"))
422 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.production_date");
423 std::vector<std::string> outputValues;
424 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
429 value = lexical_cast<
int> (outputValues[1]);
431 catch (bad_lexical_cast &)
433 itkExceptionMacro(<<
"Invalid Month");
444 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
454 if (!imageKeywordlist.
HasKey(
"support_data.production_date"))
459 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.production_date");
460 std::vector<std::string> outputValues;
461 boost::split(outputValues, valueString, boost::is_any_of(
" T:-"));
463 if (outputValues.size() <= 2) itkExceptionMacro(<<
"Invalid Year");
468 value = lexical_cast<
int> (outputValues[0]);
470 catch (bad_lexical_cast &)
472 itkExceptionMacro(<<
"Invalid Year");
482 if (!this->CanRead())
484 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
494 std::vector<double> outputValues;
495 if (imageKeywordlist.
HasKey(
"support_data.physical_bias"))
497 std::vector<std::string> outputValuesString;
498 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.physical_bias");
500 boost::split(outputValuesString, valueString, boost::is_any_of(
" "));
501 for (
unsigned int i = 0; i < outputValuesString.size(); ++i)
503 outputValues.push_back(atof(outputValuesString[i].c_str()));
508 outputValuesVariableLengthVector.
SetSize(outputValues.size());
509 outputValuesVariableLengthVector.
Fill(0);
512 for (
unsigned int i = 0; i < outputValues.size(); ++i)
514 outputValuesVariableLengthVector[i] = outputValues[this->BandIndexToWavelengthPosition(i)];
518 return outputValuesVariableLengthVector;
526 if (!this->CanRead())
528 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
538 std::vector<double> outputValues;
539 if (imageKeywordlist.
HasKey(
"support_data.physical_gain"))
541 std::vector<std::string> outputValuesString;
542 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.physical_gain");
544 boost::split(outputValuesString, valueString, boost::is_any_of(
" "));
545 for (
unsigned int i = 0; i < outputValuesString.size(); ++i)
547 outputValues.push_back(atof(outputValuesString[i].c_str()));
552 outputValuesVariableLengthVector.
SetSize(outputValues.size());
553 outputValuesVariableLengthVector.
Fill(0);
556 for (
unsigned int i = 0; i < outputValues.size(); ++i)
558 outputValuesVariableLengthVector[i] = outputValues[this->BandIndexToWavelengthPosition(i)];
561 return outputValuesVariableLengthVector;
570 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
580 if (!imageKeywordlist.
HasKey(
"support_data.incident_angle"))
586 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.incident_angle");
587 double value = atof(valueString.c_str());
597 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
607 if (!imageKeywordlist.
HasKey(
"support_data.scene_orientation"))
613 std::string valueString = imageKeywordlist.
GetMetadataByKey(
"support_data.scene_orientation");
614 double satAz = atof(valueString.c_str());
624 if (!this->CanRead())
626 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
639 int nbBands = this->GetNumberOfBands();
640 std::string sensorId = this->GetSensorID();
648 else if (nbBands > 1 && nbBands < 5)
656 else itkExceptionMacro(<<
"Invalid number of bands...");
666 if (!this->CanRead())
668 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
681 int nbBands = this->GetNumberOfBands();
689 else if (nbBands > 1 && nbBands < 5)
697 else itkExceptionMacro(<<
"Invalid number of bands...");
709 int nbBands = this->GetNumberOfBands();
718 if (i == 0)
return 2;
719 if (i == 2)
return 0;
725 std::vector<std::string>
729 std::vector<std::string> enhBandNames;
730 std::vector<std::string> rawBandNames = this->Superclass::GetBandName();
732 if(rawBandNames.size())
734 for (std::vector<std::string>::iterator it = rawBandNames.begin(); it != rawBandNames.end(); ++it)
737 if ( (rawBandNames.size() == 1) && !(*it).compare(
"P") )
739 enhBandNames.push_back(
"PAN");
742 else if ((rawBandNames.size() != 1) && !(*it).compare(
"P"))
745 itkExceptionMacro(<<
"Invalid Metadata, we cannot provide an consistent name to the band");
749 if ( !(*it).compare(
"B0") )
751 enhBandNames.push_back(
"Blue");
753 else if ( !(*it).compare(
"B1") )
755 enhBandNames.push_back(
"Green");
757 else if ( !(*it).compare(
"B2") )
759 enhBandNames.push_back(
"Red");
761 else if ( !(*it).compare(
"B3") )
763 enhBandNames.push_back(
"NIR");
767 enhBandNames.push_back(
"Unknown");
776 std::vector<unsigned int>
781 if (!this->CanRead())
783 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
793 int nbBands = this->GetNumberOfBands();
795 std::string key =
"support_data.band_name_list";
796 std::vector<unsigned int> rgb(3);
800 bool realProduct =
false;
803 if (imageKeywordlist.
HasKey(key) && (nbBands > 1))
805 std::string keywordStringBandNameList = imageKeywordlist.
GetMetadataByKey(key);
806 std::vector<std::string> bandNameList;
808 boost::split(bandNameList, keywordStringBandNameList, boost::is_any_of(
" "));
810 for (
int i = 0; i < nbBands && i < 3; i++)
813 found = bandNameList[i].find_first_not_of(
"B");
814 rgb[i] = lexical_cast<
int> (bandNameList[i].at(found));
844 std::list <std::vector<float> > tmpSpectralBandList;
847 if (!this->CanRead())
849 itkExceptionMacro(<<
"Invalid Metadata, no Pleiades Image");
859 int nbBands = this->GetNumberOfBands();
860 std::string sensorId = this->GetSensorID();
865 if (sensorId ==
"PHR 1A")
867 const float b0[209] =
1080 const std::vector<float> vb0 (b0, b0 +
sizeof(b0) /
sizeof(
float) );
1081 tmpSpectralBandList.push_back(vb0);
1085 itkExceptionMacro(<<
"Invalid Pleiades Sensor ID");
1088 else if (nbBands > 1 && nbBands < 5)
1092 const float b1[209] =
1304 const float b2[209] =
1516 const float b3[209] =
1728 const float b4[209] =
1941 const std::vector<float> vb1 (b1, b1 +
sizeof(b1) /
sizeof(
float) );
1942 tmpSpectralBandList.push_back(vb1);
1943 const std::vector<float> vb2 (b2, b2 +
sizeof(b2) /
sizeof(
float) );
1944 tmpSpectralBandList.push_back(vb2);
1945 const std::vector<float> vb3 (b3, b3 +
sizeof(b3) /
sizeof(
float) );
1946 tmpSpectralBandList.push_back(vb3);
1947 const std::vector<float> vb4 (b4, b4 +
sizeof(b4) /
sizeof(
float) );
1948 tmpSpectralBandList.push_back(vb4);
1953 itkExceptionMacro(<<
"Invalid number of bands...");
1957 for (std::list <std::vector<float> >::const_iterator it = tmpSpectralBandList.begin(); it != tmpSpectralBandList.end(); ++it)
1960 wavelengthSpectralBand->GetNthElement(j)->SetFilterFunctionValues(*it);
1961 wavelengthSpectralBand->GetNthElement(j)->SetMinSpectralValue(0.430);
1962 wavelengthSpectralBand->GetNthElement(j)->SetMaxSpectralValue(0.950);
1963 wavelengthSpectralBand->GetNthElement(j)->SetUserStep(0.0025);
1967 return wavelengthSpectralBand;