void ossimAdjustableParameterInterface::resetAdjustableParameters(bool notify)
{
    if(!theAdjustmentList.size())
    {
       return;
    }
    
    ossim_uint32 saveCurrent = theCurrentAdjustment;
    copyAdjustment();
    initAdjustableParameters();
    ossim_uint32 numberOfAdjustables = getNumberOfAdjustableParameters();
    ossim_uint32 idx = 0;
    
    for(idx = 0; idx < numberOfAdjustables; ++idx)
    {
       theAdjustmentList[saveCurrent].getParameterList()[idx].setParameter(theAdjustmentList[theAdjustmentList.size()-1].getParameterList()[idx].getParameter());
    }

    setCurrentAdjustment(saveCurrent);

    eraseAdjustment((ossim_uint32)theAdjustmentList.size()-1, false);
    
    if(notify)
    {
       adjustableParametersChanged();
    }
}
//*************************************************************************************************
//! Initializes the change flags to false.
//*************************************************************************************************
void ossimAdjustableParameterInterface::initChangeFlags()
{
   // Need to resize the flag list?
   ossim_uint32 num_params = getNumberOfAdjustableParameters();
   if (theChangeFlags.size() != num_params)
      theChangeFlags.resize(num_params);
   setAllChangeFlags(true);
}
void ossimCsmSensorModel::updateModel()
{
   if(!m_model) return;
   
   int nParams = getNumberOfAdjustableParameters();
   
   
   int idx = 0;
   for(idx = 0; idx < nParams; ++idx)
   {
      m_model->setCurrentParameterValue(idx, computeParameterOffset(idx));
   }
}
示例#4
0
ossim_uint32
ossimRpcProjection::degreesOfFreedom()const
{
   ossim_uint32 dof = 0;
   ossim_uint32 idx = 0;
   ossim_uint32 numAdj = getNumberOfAdjustableParameters();
   for(idx = 0; idx < numAdj; ++idx)
   {
      if(!isParameterLocked(idx))
      {
         ++dof;
      }
   }
   
   return dof;
}
示例#5
0
void ossimRpcModel::initAdjustableParameters()
{
    resizeAdjustableParameterArray(NUM_ADJUSTABLE_PARAMS);
    int numParams = getNumberOfAdjustableParameters();
    for (int i=0; i<numParams; i++)
    {
        setAdjustableParameter(i, 0.0);
        setParameterDescription(i, PARAM_NAMES[i]);
        setParameterUnit(i,PARAM_UNITS[i]);
    }
    setParameterSigma(INTRACK_OFFSET, 50.0);
    setParameterSigma(CRTRACK_OFFSET, 50.0);
    setParameterSigma(INTRACK_SCALE, 50.0);
    setParameterSigma(CRTRACK_SCALE, 50.0);
    setParameterSigma(MAP_ROTATION, 0.1);
//   setParameterSigma(YAW_OFFSET, 0.001);
}
示例#6
0
void rspfLandSatModel::initAdjustableParameters()
{
   if (traceExec())  rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::initAdjustableParameters: entering..." << std::endl;
   resizeAdjustableParameterArray(NUM_ADJUSTABLE_PARAMS);
   int numParams = getNumberOfAdjustableParameters();
   for (int i=0; i<numParams; i++)
   {
      setAdjustableParameter(i, 0.0);
      setParameterDescription(i, PARAM_NAMES[i]);
      setParameterUnit(i,PARAM_UNITS[i]);
   }
   setParameterSigma(INTRACK_OFFSET, 500.0); //change for Landsat 5
   setParameterSigma(CRTRACK_OFFSET, 500.0); //change for Landsat 5
   setParameterSigma(LINE_GSD_CORR, 0.005);  
   setParameterSigma(SAMP_GSD_CORR, 0.005);  
   setParameterSigma(ROLL_OFFSET, 0.01);  
   setParameterSigma(YAW_OFFSET, 0.01);  
   setParameterSigma(YAW_RATE, 0.05);  
   setParameterSigma(MAP_ROTATION, 0.1);
   if (traceExec())  rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::initAdjustableParameters: returning..." << std::endl;
}
示例#7
0
bool ossimAlphaSensorHSI::loadState(const ossimKeywordlist& kwl, const char* prefix)
{
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimAlphaSensorHSI::loadState DEBUG:" << std::endl;
   }

   ossimAlphaSensor::loadState(kwl, prefix);
   if(getNumberOfAdjustableParameters() < 1)
   {
      initAdjustableParameters();
   }
   
   updateModel();
   
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimAlphaSensorHSI::loadState complete..." << std::endl;
   }
   
   return true;
}
bool ossimSpectraboticsRedEdgeModel::loadState(const ossimKeywordlist& kwl,
                                       const char* prefix)
{
   if(traceDebug())
   {
      std::cout << "ossimSpectraboticsRedEdgeModel::loadState: ......... entered" << std::endl;
   }
   //ossimSensorModel::loadState(kwl,prefix);

   ossimSensorModel::loadState(kwl, prefix);
   if(getNumberOfAdjustableParameters() < 1)
   {

      initAdjustableParameters();
   }
   m_ecefPlatformPosition    = ossimGpt(0.0,0.0,1000.0);
   m_adjEcefPlatformPosition = ossimGpt(0.0,0.0,1000.0);
   m_roll    = 0.0;
   m_pitch   = 0.0;
   m_heading = 0.0;


   // bool computeGsdFlag = false;
   const char* roll              = kwl.find(prefix, "Roll");
   const char* pitch             = kwl.find(prefix, "Pitch");
   const char* heading           = kwl.find(prefix, "Yaw");
   const char* focalLength       = kwl.find(prefix, "Focal Length");
   const char* imageWidth        = kwl.find(prefix, "Image Width");
   const char* imageHeight       = kwl.find(prefix, "Image Height");
   const char* fov               = kwl.find(prefix, "Field Of View");
   const char* gpsPos            = kwl.find(prefix, "GPS Position");
   const char* gpsAlt            = kwl.find(prefix, "GPS Altitude");
   const char* imageCenter       = kwl.find(prefix, "Image Center");
   const char* fx                = kwl.find(prefix, "fx");
   const char* fy                = kwl.find(prefix, "fy");
   const char* cx                = kwl.find(prefix, "cx");
   const char* cy                = kwl.find(prefix, "cy");
   const char* k                 = kwl.find(prefix, "k");
   const char* p                 = kwl.find(prefix, "p");

   bool result = true;

#if 0
   std::cout << "roll: " << roll << "\n";
   std::cout << "pitch: " << pitch << "\n";
   std::cout << "heading: " << heading << "\n";
   std::cout << "focalLength: " << focalLength << "\n";
   std::cout << "imageWidth: " << imageWidth << "\n";
   std::cout << "imageHeight: " << imageHeight << "\n";
  // std::cout << "fov: " << fov << "\n";
   std::cout << "gpsPos: " << gpsPos << "\n";
   std::cout << "gpsAlt: " << gpsAlt << "\n";
   #endif
   //
  if(k&&p)
  {
    m_lensDistortion = new ossimTangentialRadialLensDistortion();
    m_lensDistortion->loadState(kwl, prefix);
  }

   if(roll&&
      pitch&&
      heading&&
      focalLength&&
      imageWidth&&
      imageHeight&&
      gpsPos&&
      gpsAlt)
   {
      theSensorID = "MicaSense RedEdge";
      m_roll = ossimString(roll).toDouble();
      m_pitch = ossimString(pitch).toDouble();
      m_heading = ossimString(heading).toDouble();
      m_focalLength = ossimString(focalLength).toDouble();
      m_fov = fov?ossimString(fov).toDouble():48.8;
      theImageSize.x = ossimString(imageWidth).toDouble();
      theImageSize.y = ossimString(imageHeight).toDouble();


      theImageClipRect = ossimDrect(0,0,theImageSize.x-1,theImageSize.y-1);
      theRefImgPt      = ossimDpt(theImageSize.x/2.0, theImageSize.y/2.0);
     
     m_calibratedCenter = theImageClipRect.midPoint();
      // now lets use the field of view and the focal length to 
      // calculate the pixel size on the ccd in millimeters
      double d = tan((m_fov*0.5)*M_PI/180.0)*m_focalLength;
      d*=2.0;
      double tempRadiusPixel = theImageSize.length();
      m_pixelSize.x = (d)/tempRadiusPixel;
      m_pixelSize.y = m_pixelSize.x;
      if(imageCenter)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(imageCenter);
         tempString.split(splitString, ossimString(" "));
         if(splitString.size() == 2)
         {
            theRefImgPt = ossimDpt(splitString[0].toDouble(), splitString[1].toDouble());
         }
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No Image Center found" << std::endl;
        //    result = false;
         }
      }

      // now extract the GPS position and shift it to the ellipsoidal height.
      std::vector<ossimString> splitArray;

      ossimString(gpsPos).split(splitArray, ",");
      splitArray[0] = splitArray[0].replaceAllThatMatch("deg", " ");
      splitArray[1] = splitArray[1].replaceAllThatMatch("deg", " ");

      ossimDms dmsLat;
      ossimDms dmsLon;
      double h = ossimString(gpsAlt).toDouble();
      dmsLat.setDegrees(splitArray[0]);
      dmsLon.setDegrees(splitArray[1]);
      double lat = dmsLat.getDegrees();
      double lon = dmsLon.getDegrees();

      h = h+ossimGeoidManager::instance()->offsetFromEllipsoid(ossimGpt(lat,lon));
      m_ecefPlatformPosition = ossimGpt(lat,lon,h);
      // double height1 = ossimElevManager::instance()->getHeightAboveEllipsoid(ossimGpt(lat, lon));
     
//std::cout << "PLATFORM HEIGHT: " << h << "\n" 
//          << "ELEVATION: " << height1 << "\n";
     // std::cout << m_ecefPlatformPosition << std::endl;
     // std::cout << "POINT: " << ossimGpt(lat,lon,h) << std::endl;
     // std::cout << "MSL:   " << height1 << "\n";

      theRefGndPt = m_ecefPlatformPosition;
      theRefGndPt.height(0.0);

     m_norm = ossim::nan();

    // lens parameters
    if(m_lensDistortion.valid()&&cx&&cy&&fx&&fy)
    {
      m_focalX = ossimString(fx).toDouble();
      m_focalY = ossimString(fy).toDouble();

      // our lens distorion assume center point.  So
      // lets shift to center and then set calibrated relative to 
      // image center.  We will then normalize.
      //
      ossimDpt focal(m_focalX,m_focalY);
      m_norm = focal.length()*0.5; // convert from diameter to radial
      m_calibratedCenter = ossimDpt(ossimString(cx).toDouble(), ossimString(cy).toDouble());
      m_principalPoint = m_calibratedCenter-theImageClipRect.midPoint();
      m_principalPoint.x /= m_norm;
      m_principalPoint.y /= m_norm;

      // lets initialize the root to be about one pixel norm along the diagonal
      // and the convergence will be approximately 100th of a pixel.
      //
      double temp = m_norm;
      if(temp < FLT_EPSILON) temp = 1.0;
      else temp = 1.0/temp;
      m_lensDistortion->setCenter(m_principalPoint);
      m_lensDistortion->setDxDy(ossimDpt(temp,temp));
      m_lensDistortion->setConvergenceThreshold(temp*0.001);
    }
    else
    {
      m_lensDistortion = 0;
      m_calibratedCenter = theImageClipRect.midPoint();
      m_norm = theImageSize.length()*0.5;
      m_principalPoint = ossimDpt(0,0);
    }
     updateModel();
   }
   else // load from regular save state
   {
      const char* principal_point   = kwl.find(prefix, "principal_point");
      const char* pixel_size        = kwl.find(prefix, "pixel_size");
      const char* ecef_platform_position = kwl.find(prefix, "ecef_platform_position");
      const char* latlonh_platform_position = kwl.find(prefix, "latlonh_platform_position");
      // const char* compute_gsd_flag  = kwl.find(prefix, "compute_gsd_flag");
      roll              = kwl.find(prefix, "roll");
      pitch             = kwl.find(prefix, "pitch");
      heading           = kwl.find(prefix, "heading");
      fov               = kwl.find(prefix, "field_of_view");
      focalLength       = kwl.find(prefix, "focal_length");

      if(roll)
      {
         m_roll = ossimString(roll).toDouble();
      }
      if(pitch)
      {
         m_pitch = ossimString(pitch).toDouble();
      }
      if(heading)
      {
         m_heading = ossimString(heading).toDouble();
      }

      if(cx&&cy)
      {
         m_calibratedCenter = ossimDpt(ossimString(cx).toDouble(), ossimString(cy).toDouble());
      }
      if(principal_point)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(principal_point);
         tempString.split(splitString, ossimString(" "));
         if(splitString.size() == 2)
         {
            m_principalPoint.x = splitString[0].toDouble();
            m_principalPoint.y = splitString[1].toDouble();
         }
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No principal_point found" << std::endl;
           // result = false;
         }
      }

      if(pixel_size)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(pixel_size);
         tempString.split(splitString, ossimString(" "));
         if(splitString.size() == 1)
         {
            m_pixelSize.x = splitString[0].toDouble();
            m_pixelSize.y = m_pixelSize.x;
         }
         else if(splitString.size() == 2)
         {
            m_pixelSize.x = splitString[0].toDouble();
            m_pixelSize.y = splitString[1].toDouble();
         }
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No pixel size found" << std::endl;
           // result = false;
         }
      }
      if(ecef_platform_position)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(ecef_platform_position);
         tempString.split(splitString, ossimString(" "));
         if(splitString.size() > 2)
         {
            m_ecefPlatformPosition  = ossimEcefPoint(splitString[0].toDouble(),
                                                      splitString[1].toDouble(),
                                                      splitString[2].toDouble());
         }
      }
      else if(latlonh_platform_position)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(latlonh_platform_position);
         tempString.split(splitString, ossimString(" "));
         std::string datumString;
         double lat=0.0, lon=0.0, h=0.0;
         if(splitString.size() > 2)
         {
            lat = splitString[0].toDouble();
            lon = splitString[1].toDouble();
            h = splitString[2].toDouble();
         }
         
         m_ecefPlatformPosition = ossimGpt(lat,lon,h);
      }
      if(focalLength)
      {
         m_focalLength = ossimString(focalLength).toDouble();
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No focal length found" << std::endl;
            result = false;
         }
      }
      if(fov)
      {
         m_fov = ossimString(fov).toDouble();
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No field of view found" << std::endl;
            result = false;
         }
      }
      theRefGndPt = m_ecefPlatformPosition;
    if(m_lensDistortion.valid()&&cx&&cy&&fx&&fy)
    {
      m_focalX = ossimString(fx).toDouble();
      m_focalY = ossimString(fy).toDouble();

      // our lens distorion assume center point.  So
      // lets shift to center and then set calibrated relative to 
      // image center.  We will then normalize.
      //
      ossimDpt focal(m_focalX,m_focalY);
      m_norm = focal.length()*0.5;
      m_calibratedCenter = ossimDpt(ossimString(cx).toDouble(), ossimString(cy).toDouble());
     // m_principalPoint = m_calibratedCenter-theImageClipRect.midPoint();
     // m_principalPoint.x /= m_norm;
     // m_principalPoint.y /= m_norm;

      // lets initialize the root to be about one pixel norm along the diagonal
      // and the convergence will be approximately 100th of a pixel.
      //
      double temp = m_norm;
      if(temp < FLT_EPSILON) temp = 1.0;
      else temp = 1.0/temp;
      m_lensDistortion->setCenter(m_principalPoint);
      m_lensDistortion->setDxDy(ossimDpt(temp,temp));
      m_lensDistortion->setConvergenceThreshold(temp*0.001);
    }
    else
    {
      m_lensDistortion = 0;
    }
      updateModel();
   }
    try
    {
       //---
       // This will set theGSD and theMeanGSD. Method throws
       // ossimException.
       //---
       computeGsd();
    }
    catch (const ossimException& e)
    {
       ossimNotify(ossimNotifyLevel_WARN)
          << "ossimSpectraboticsRedEdgeModel::loadState Caught Exception:\n"
          << e.what() << std::endl;
    }
   // std::cout << "METERS PER PIXEL :    " << getMetersPerPixel() << std::endl;
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG) << std::setprecision(15) << std::endl;
      ossimNotify(ossimNotifyLevel_DEBUG) << "roll:     " << m_roll << std::endl
                                          << "pitch:    " << m_pitch << std::endl
                                          << "heading:  " << m_heading << std::endl
                                          << "platform: " << m_ecefPlatformPosition << std::endl
                                          << "latlon Platform: " << ossimGpt(m_ecefPlatformPosition) << std::endl
                                          << "focal len: " << m_focalLength << std::endl
                                          << "FOV      : " << m_fov << std::endl
                                          << "principal: " << m_principalPoint << std::endl
                                          << "Ground:    " << ossimGpt(m_ecefPlatformPosition) << std::endl;
   }

   // ossimGpt wpt;
   // ossimDpt dpt(100,100);
   // lineSampleToWorld(dpt, wpt);
   // std::cout << "dpt: " << dpt << "\n"
   //           << "wpt: " << wpt << "\n";
   // worldToLineSample(wpt,dpt);
   // std::cout << "dpt: " << dpt << "\n"
   //           << "wpt: " << wpt << "\n";
   return result;
}
示例#9
0
bool ossimApplanixUtmModel::loadState(const ossimKeywordlist& kwl,
                                   const char* prefix)
{
   if(traceDebug())
   {
      std::cout << "ossimApplanixUtmModel::loadState: ......... entered" << std::endl;
   }
   theImageClipRect = ossimDrect(0,0,4076,4091);
   theRefImgPt      = ossimDpt(2046.0, 2038.5);
   
   ossimSensorModel::loadState(kwl, prefix);

   if(getNumberOfAdjustableParameters() < 1)
   {
      initAdjustableParameters();
   }

   const char* eo_file           = kwl.find(prefix, "eo_file");
   const char* eo_id             = kwl.find(prefix, "eo_id");
   const char* omega             = kwl.find(prefix, "omega");
   const char* phi               = kwl.find(prefix, "phi");
   const char* kappa             = kwl.find(prefix, "kappa");
   const char* bore_sight_tx     = kwl.find(prefix, "bore_sight_tx");
   const char* bore_sight_ty     = kwl.find(prefix, "bore_sight_ty");
   const char* bore_sight_tz     = kwl.find(prefix, "bore_sight_tz");
   
   const char* principal_point   = kwl.find(prefix, "principal_point");
   const char* pixel_size        = kwl.find(prefix, "pixel_size");
   const char* focal_length      = kwl.find(prefix, "focal_length");
   const char* latlonh_platform_position = kwl.find(prefix, "latlonh_platform_position");
   const char* utm_platform_position = kwl.find(prefix, "utm_platform_position");
   const char* compute_gsd_flag  = kwl.find(prefix, "compute_gsd_flag");
   const char* utm_zone          = kwl.find(prefix, "utm_zone");
   const char* utm_hemisphere    = kwl.find(prefix, "utm_hemisphere");
   const char* camera_file       = kwl.find(prefix, "camera_file");
   const char* shift_values      = kwl.find(prefix, "shift_values");
   
   theCompositeMatrix          = ossimMatrix3x3::createIdentity();
   theCompositeMatrixInverse   = ossimMatrix3x3::createIdentity();
   theOmega                    = 0.0;
   thePhi                      = 0.0;
   theKappa                    = 0.0;
   theBoreSightTx              = 0.0;
   theBoreSightTy              = 0.0;
   theBoreSightTz              = 0.0;
   theFocalLength              = 55.0;
   thePixelSize = ossimDpt(.009, .009);
   theEcefPlatformPosition = ossimGpt(0.0,0.0, 1000.0);

   bool loadedFromEoFile = false;

   if(eo_id)
   {
      theImageID = eo_id;
   }
   // loading from standard eo file with given record id
   //
   if(eo_file)
   {
      ossimApplanixEOFile eoFile;
      
      if(eoFile.parseFile(ossimFilename(eo_file)))
      {
         ossimRefPtr<ossimApplanixEORecord> record = eoFile.getRecordGivenId(theImageID);

         if(record.valid())
         {
            loadedFromEoFile = true;
            theBoreSightTx = eoFile.getBoreSightTx()/60.0;
            theBoreSightTy = eoFile.getBoreSightTy()/60.0;
            theBoreSightTz = eoFile.getBoreSightTz()/60.0;
            theShiftValues = ossimEcefVector(eoFile.getShiftValuesX(),
                                             eoFile.getShiftValuesY(),
                                             eoFile.getShiftValuesZ());
            ossim_int32 easting  = eoFile.getFieldIdxLike("EASTING");
            ossim_int32 northing = eoFile.getFieldIdxLike("NORTHING");
            ossim_int32 height   = eoFile.getFieldIdxLike("HEIGHT");
            ossim_int32 omega    = eoFile.getFieldIdxLike("OMEGA");
            ossim_int32 phi      = eoFile.getFieldIdxLike("PHI");
            ossim_int32 kappa    = eoFile.getFieldIdxLike("KAPPA");

            if((omega>=0)&&
               (phi>=0)&&
               (kappa>=0)&&
               (height>=0)&&
               (easting>=0)&&
               (northing>=0))
            {
               theOmega = (*record)[omega].toDouble();
               thePhi   = (*record)[phi].toDouble();
               theKappa = (*record)[kappa].toDouble();
               double h = (*record)[height].toDouble();
               ossimString heightType = kwl.find(prefix, "height_type");
               if(eoFile.isUtmFrame())
               {
                  theUtmZone = eoFile.getUtmZone();
                  theUtmHemisphere = eoFile.getUtmHemisphere()=="North"?'N':'S';
                  ossimUtmProjection utmProj;
                  utmProj.setZone(theUtmZone);
                  utmProj.setHemisphere((char)theUtmHemisphere);
                  theUtmPlatformPosition.x = (*record)[easting].toDouble();
                  theUtmPlatformPosition.y = (*record)[northing].toDouble();
                  theUtmPlatformPosition.z = h;
                  thePlatformPosition = utmProj.inverse(ossimDpt(theUtmPlatformPosition.x,
                                                                 theUtmPlatformPosition.y));
                  thePlatformPosition.height(h);

                  if(eoFile.isHeightAboveMSL())
                  {
                     double offset = ossimGeoidManager::instance()->offsetFromEllipsoid(thePlatformPosition);
                     if(!ossim::isnan(offset))
                     {
                        thePlatformPosition.height(h + offset);
                        theUtmPlatformPosition.z = h + offset;
                     }
                  }
               }
               else
               {
                  return false;
               }
            }
            theEcefPlatformPosition = thePlatformPosition;
         }
         else
         {
            return false;
         }
      }
   }
   if(!loadedFromEoFile)
   {
      if(shift_values)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(shift_values);
         tempString = tempString.trim();
         tempString.split(splitString, " " );
         if(splitString.size() == 3)
         {
            theShiftValues = ossimEcefVector(splitString[0].toDouble(),
                                             splitString[1].toDouble(),
                                             splitString[2].toDouble());
         }
      }
      if(omega&&phi&&kappa)
      {
         theOmega = ossimString(omega).toDouble();
         thePhi   = ossimString(phi).toDouble();
         theKappa = ossimString(kappa).toDouble();
      }
      if(bore_sight_tx&&bore_sight_ty&&bore_sight_tz)
      {
         theBoreSightTx = ossimString(bore_sight_tx).toDouble()/60.0;
         theBoreSightTy = ossimString(bore_sight_ty).toDouble()/60.0;
         theBoreSightTz = ossimString(bore_sight_tz).toDouble()/60.0;
      }
      double lat=0.0, lon=0.0, h=0.0;
      if(utm_zone)
      {
         theUtmZone = ossimString(utm_zone).toInt32();
      }
      if(utm_hemisphere)
      {
         ossimString hem = utm_hemisphere;
         hem = hem.trim();
         hem = hem.upcase();
         theUtmHemisphere = *(hem.begin());
      }
      if(utm_platform_position)
      {
         ossimUtmProjection utmProj;
         std::vector<ossimString> splitString;
         ossimString tempString(utm_platform_position);
         tempString = tempString.trim();
         ossimString datumString;
         utmProj.setZone(theUtmZone);
         utmProj.setHemisphere((char)theUtmHemisphere);
         tempString.split(splitString, " ");
         if(splitString.size() > 2)
         {
            theUtmPlatformPosition.x = splitString[0].toDouble();
            theUtmPlatformPosition.y = splitString[1].toDouble();
            theUtmPlatformPosition.z = splitString[2].toDouble();
         }
         if(splitString.size() > 3)
         {
            datumString = splitString[3];
         }
         const ossimDatum* datum = ossimDatumFactory::instance()->create(datumString);
         if(datum)
         {
            utmProj.setDatum(datum);
         }
         
         thePlatformPosition = utmProj.inverse(ossimDpt(theUtmPlatformPosition.x,
                                                        theUtmPlatformPosition.y));
         thePlatformPosition.height(theUtmPlatformPosition.z);
         
         ossimString heightType = kwl.find(prefix, "height_type");
         if(heightType == "msl")
         {
            double offset = ossimGeoidManager::instance()->offsetFromEllipsoid(thePlatformPosition);
            if(ossim::isnan(offset) == false)
            {
               thePlatformPosition.height(thePlatformPosition.height() + offset);
               theUtmPlatformPosition.z = thePlatformPosition.height();
            }
         }
         theEcefPlatformPosition = thePlatformPosition;
      }
      else if(latlonh_platform_position)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(latlonh_platform_position);
         std::string datumString;
         tempString = tempString.trim();
         tempString.split(splitString, " ");
         if(splitString.size() > 2)
         {
            lat = splitString[0].toDouble();
            lon = splitString[1].toDouble();
            h = splitString[2].toDouble();
         }
         if(splitString.size() > 3)
         {
            datumString = splitString[3];
         }
         thePlatformPosition.latd(lat);
         thePlatformPosition.lond(lon);
         thePlatformPosition.height(h);
         const ossimDatum* datum = ossimDatumFactory::instance()->create(datumString);
         if(datum)
         {
            thePlatformPosition.datum(datum);
         }
         ossimString heightType = kwl.find(prefix, "height_type");
         if(heightType == "msl")
         {
            double offset = ossimGeoidManager::instance()->offsetFromEllipsoid(thePlatformPosition);
            if(ossim::isnan(offset) == false)
            {
               thePlatformPosition.height(thePlatformPosition.height() + offset);
            }
         }
         theEcefPlatformPosition = thePlatformPosition;
      }
   }
   if(principal_point)
   {
      std::vector<ossimString> splitString;
      ossimString tempString(principal_point);
      tempString = tempString.trim();
      tempString.split(splitString, " ");
      if(splitString.size() == 2)
      {
         thePrincipalPoint.x = splitString[0].toDouble();
         thePrincipalPoint.y = splitString[1].toDouble();
      }
   }
   if(pixel_size)
   {
      std::vector<ossimString> splitString;
      ossimString tempString(principal_point);
      tempString = tempString.trim();
      tempString.split(splitString, " ");
      if(splitString.size() == 2)
      {
         thePixelSize.x = splitString[0].toDouble();
         thePixelSize.y = splitString[1].toDouble();
      }
   }
   if(focal_length)
   {
      theFocalLength = ossimString(focal_length).toDouble();
   }

   if(camera_file)
   {
      ossimKeywordlist cameraKwl;
      ossimKeywordlist lensKwl;
      cameraKwl.add(camera_file);
      const char* sensor = cameraKwl.find("sensor");
      const char* image_size      = cameraKwl.find(prefix, "image_size");
      principal_point = cameraKwl.find("principal_point");
      focal_length    = cameraKwl.find("focal_length");
      pixel_size      = cameraKwl.find(prefix, "pixel_size");
      focal_length    = cameraKwl.find(prefix, "focal_length");
      const char* distortion_units = cameraKwl.find(prefix, "distortion_units");
      ossimUnitConversionTool tool;
      ossimUnitType unitType = OSSIM_MILLIMETERS;

      if(distortion_units)
      {
         unitType = (ossimUnitType)ossimUnitTypeLut::instance()->getEntryNumber(distortion_units);

         if(unitType == OSSIM_UNIT_UNKNOWN)
         {
            unitType = OSSIM_MILLIMETERS;
         }
      }
      if(image_size)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(image_size);
         tempString = tempString.trim();
         tempString.split(splitString, " ");
         double w=1, h=1;
         if(splitString.size() == 2)
         {
            w = splitString[0].toDouble();
            h = splitString[1].toDouble();
         }
         theImageClipRect = ossimDrect(0,0,w-1,h-1);
         theRefImgPt      = ossimDpt(w/2.0, h/2.0);
      }
      if(sensor)
      {
         theSensorID = sensor;
      }
      if(principal_point)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(principal_point);
         tempString = tempString.trim();
         tempString.split(splitString, " ");
         if(splitString.size() == 2)
         {
            thePrincipalPoint.x = splitString[0].toDouble();
            thePrincipalPoint.y = splitString[1].toDouble();
         }
      }
      if(pixel_size)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(pixel_size);
         tempString = tempString.trim();
         tempString.split(splitString, " ");
         if(splitString.size() == 1)
         {
            thePixelSize.x = splitString[0].toDouble();
            thePixelSize.y = thePixelSize.x;
         }
         else if(splitString.size() == 2)
         {
            thePixelSize.x = splitString[0].toDouble();
            thePixelSize.y = splitString[1].toDouble();
         }
      }
      if(focal_length)
      {
         theFocalLength = ossimString(focal_length).toDouble();
      }

      ossim_uint32 idx = 0;
      for(idx = 0; idx < 26; ++idx)
      {
         const char* value = cameraKwl.find(ossimString("d")+ossimString::toString(idx));

         if(value)
         {
            std::vector<ossimString> splitString;
            ossimString tempString(value);
            double distance=0.0, distortion=0.0;
            tempString = tempString.trim();
            tempString.split(splitString, " ");
            if(splitString.size() == 2)
            {
               distance = splitString[0].toDouble();
               distortion = splitString[1].toDouble();
            }
            
            tool.setValue(distortion, unitType);
            lensKwl.add(ossimString("distance") + ossimString::toString(idx),
                        distance,
                        true);
            lensKwl.add(ossimString("distortion") + ossimString::toString(idx),
                        tool.getMillimeters(),
                        true);
         }
         lensKwl.add("convergence_threshold",
                     .00001,
                     true);
         if(pixel_size)
         {
            lensKwl.add("dxdy",
                        ossimString(pixel_size) + " " + ossimString(pixel_size),
                        true);
         }
         else
         {
            lensKwl.add("dxdy",
                        ".009 .009",
                        true);
         }
      }
      if(theLensDistortion.valid())
      {
         theLensDistortion->loadState(lensKwl,"");
      }
   }
   else
   {
      
      if(principal_point)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(principal_point);
         tempString = tempString.trim();
         tempString.split(splitString, " ");
         if(splitString.size() == 2)
         {
            thePrincipalPoint.x = splitString[0].toDouble();
            thePrincipalPoint.y = splitString[1].toDouble();
         }
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No principal_point found" << std::endl;
            return false;
         }
      }
      if(pixel_size)
      {
         std::vector<ossimString> splitString;
         ossimString tempString(pixel_size);
         tempString = tempString.trim();
         tempString.split(splitString, " ");
         if(splitString.size() == 1)
         {
            thePixelSize.x = splitString[0].toDouble();
            thePixelSize.y = thePixelSize.x;
         }
         else if(splitString.size() == 2)
         {
            thePixelSize.x = splitString[0].toDouble();
            thePixelSize.y = splitString[1].toDouble();
         }
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No pixel size found" << std::endl;
            return false;
         }
      }
      if(focal_length)
      {
         theFocalLength = ossimString(focal_length).toDouble();
      }
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "No focal length found" << std::endl;
            return false;
         }
      }
      
      if(theLensDistortion.valid())
      {
         ossimString lensPrefix = ossimString(prefix)+"distortion.";
         theLensDistortion->loadState(kwl,
                                      lensPrefix.c_str());
      }
   }
   theRefGndPt = thePlatformPosition;
   
   updateModel();

   lineSampleToWorld(theRefImgPt, theRefGndPt);
   if(compute_gsd_flag)
   {
      if(ossimString(compute_gsd_flag).toBool())
      {
         ossimGpt right;
         ossimGpt top;
         lineSampleToWorld(theRefImgPt + ossimDpt(1.0, 0.0),
                           right);
         lineSampleToWorld(theRefImgPt + ossimDpt(1.0, 0.0),
                           top);

         ossimEcefVector horizontal = ossimEcefPoint(theRefGndPt)-ossimEcefPoint(right);
         ossimEcefVector vertical   = ossimEcefPoint(theRefGndPt)-ossimEcefPoint(top);

         theGSD.x = horizontal.length();
         theGSD.y = vertical.length();
         theMeanGSD = (theGSD.x+theGSD.y)*.5;
      }
   }
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG) << "theOmega:              " << theOmega << std::endl
                                          << "thePhi:                " << thePhi   << std::endl
                                          << "theKappa:              " << theKappa << std::endl;
      std::cout << "platform position:     " << thePlatformPosition << std::endl;
      std::cout << "platform position ECF: " << theEcefPlatformPosition << std::endl;
      std::cout << "ossimApplanixModel::loadState: ......... leaving" << std::endl;
   }

   return true;
}
示例#10
0
void
ossimRpcProjection::buildNormalEquation(const ossimTieGptSet& tieSet,
                                      NEWMAT::SymmetricMatrix& A,
                                      NEWMAT::ColumnVector& residue,
                                      NEWMAT::ColumnVector& projResidue,
                                      double pstep_scale)
{
   //goal:       build Least Squares system
   //constraint: never store full Jacobian matrix in memory (can be huge)
   //            so we build the matrices incrementally
   // the system can be built using forward() or inverse() depending on the projection capabilities : useForward()
   //
   //TBD : add covariance matrix for each tie point

   //init
   int np = getNumberOfAdjustableParameters();
   int dimObs;
   bool useImageObs = useForward(); //caching
   if (useImageObs)
   {
      dimObs = 2; //image observation
   } else {
      dimObs = 3; //ground observations
   }
   int no = dimObs * tieSet.size(); //number of observations

   A.ReSize(np);
   residue.ReSize(no);
   projResidue.ReSize(np);
   //Zeroify matrices that will be accumulated
   A           = 0.0;
   projResidue = 0.0;

   const vector<ossimRefPtr<ossimTieGpt> >& theTPV = tieSet.getTiePoints();
   vector<ossimRefPtr<ossimTieGpt> >::const_iterator tit;
   unsigned long c=1;

   if (useImageObs)
   { 
     //image observations 
     ossimDpt* imDerp = new ossimDpt[np];
     ossimDpt resIm;
     // loop on tie points
      for (tit = theTPV.begin() ; tit != theTPV.end() ; ++tit)
      {
         //compute residue
         resIm = (*tit)->tie - forward(*(*tit));
         residue(c++) = resIm.x;
         residue(c++) = resIm.y;

         //compute all image derivatives regarding parametres for the tie point position
         for(int p=0;p<np;++p)
         {
            imDerp[p] = getForwardDeriv( p , *(*tit) , pstep_scale);
         }

         //compute influence of tie point on all sytem elements
         for(int p1=0;p1<np;++p1)
         {        
            //proj residue: J * residue
            projResidue.element(p1) += imDerp[p1].x * resIm.x + imDerp[p1].y * resIm.y;

            //normal matrix A = transpose(J)*J
            for(int p2=p1;p2<np;++p2)
            {
               A.element(p1,p2) += imDerp[p1].x * imDerp[p2].x + imDerp[p1].y * imDerp[p2].y;
            }
         }
      }
      delete []imDerp;
   }
   else
   {
      // ground observations
      std::vector<ossimGpt> gdDerp(np);
      ossimGpt gd, resGd;
      // loop on tie points
      for (tit = theTPV.begin() ; tit != theTPV.end() ; ++tit)
      {
         //compute residue
         gd = inverse((*tit)->tie);
         residue(c++) = resGd.lon = ((*tit)->lon - gd.lon) * 100000.0;
         residue(c++) = resGd.lat = ((*tit)->lat - gd.lat) * 100000.0 * cos(gd.lat / 180.0 * M_PI);
         residue(c++) = resGd.hgt = (*tit)->hgt - gd.hgt; //TBD : normalize to meters?

         //compute all image derivatives regarding parametres for the tie point position
         for(int p=0;p<np;++p)
         {
            gdDerp[p] = getInverseDeriv( p , (*tit)->tie, pstep_scale);
         }

         //compute influence of tie point on all sytem elements
         for(int p1=0;p1<np;++p1)
         {        
            //proj residue: J * residue
            projResidue.element(p1) += gdDerp[p1].lon * resGd.lon + gdDerp[p1].lat * resGd.lat + gdDerp[p1].hgt * resGd.hgt; //TBC

            //normal matrix A = transpose(J)*J
            for(int p2=p1;p2<np;++p2)
            {
               A.element(p1,p2) += gdDerp[p1].lon * gdDerp[p2].lon + gdDerp[p1].lat * gdDerp[p2].lat + gdDerp[p1].hgt * gdDerp[p2].hgt;
            }
         }
      }
   } //end of if (useImageObs)
}
示例#11
0
double
ossimRpcProjection::optimizeFit(const ossimTieGptSet& tieSet, double* /* targetVariance */)
{
#if 1
   //NOTE : ignore targetVariance
   ossimRefPtr<ossimRpcSolver> solver = new ossimRpcSolver(false, false); //TBD : choices should be part of setupFromString

   std::vector<ossimDpt> imagePoints;
   std::vector<ossimGpt> groundPoints;
   tieSet.getSlaveMasterPoints(imagePoints, groundPoints);
   solver->solveCoefficients(imagePoints, groundPoints);

   ossimRefPtr< ossimImageGeometry > optProj = solver->createRpcProjection();
   if (!optProj)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::optimizeFit(): error when optimizing the RPC with given tie points"
                                             << std::endl;
      return -1.0;
   }

   if(optProj->hasProjection())
   {
      ossimKeywordlist kwl;
      optProj->getProjection()->saveState(kwl);
      this->loadState(kwl);
   }

   return std::pow(solver->getRmsError(), 2); //variance in pixel^2
#else
   // COPIED from ossimRpcProjection
   //
   //
   //use a simple Levenberg-Marquardt non-linear optimization
   //note : please limit the number of tie points
   //
   //INPUTS: requires Jacobian matrix (partial derivatives with regards to parameters)
   //OUTPUTS: will also compute parameter covariance matrix
   //
   //TBD: use targetVariance!
 
   int np = getNumberOfAdjustableParameters();
   int nobs = tieSet.size();

   //setup initail values
   int iter=0;
   int iter_max = 200;
   double minResidue = 1e-10; //TBC
   double minDelta = 1e-10; //TBC

   //build Least Squares initial normal equation
   // don't waste memory, add samples one at a time
   NEWMAT::SymmetricMatrix A;
   NEWMAT::ColumnVector residue;
   NEWMAT::ColumnVector projResidue;
   double deltap_scale = 1e-4; //step_Scale is 1.0 because we expect parameters to be between -1 and 1
   buildNormalEquation(tieSet, A, residue, projResidue, deltap_scale);
   double ki2=residue.SumSquare();

   //get current adjustment (between -1 and 1 normally) and convert to ColumnVector
   ossimAdjustmentInfo cadj;
   getAdjustment(cadj);
   std::vector< ossimAdjustableParameterInfo >& parmlist = cadj.getParameterList();
   NEWMAT::ColumnVector cparm(np), nparm(np);
   for(int n=0;n<np;++n)
   {
      cparm(n+1) = parmlist[n].getParameter();
   }

   double damping_speed = 2.0;
   //find max diag element for A
   double maxdiag=0.0;
   for(int d=1;d<=np;++d) {
      if (maxdiag < A(d,d)) maxdiag=A(d,d);
   }
   double damping = 1e-3 * maxdiag;
   double olddamping = 0.0;
   bool found = false;

//DEBUG TBR
cout<<"rms="<<sqrt(ki2/nobs)<<" ";
cout.flush();

   while ( (!found) && (iter < iter_max) ) //non linear optimization loop
   {
      bool decrease = false;

      do
      {
         //add damping update to normal matrix
         for(int d=1;d<=np;++d) A(d,d) += damping - olddamping;
         olddamping = damping;

         NEWMAT::ColumnVector deltap = solveLeastSquares(A, projResidue);

         if (deltap.NormFrobenius() <= minDelta) 
         {
            found = true;
         } else {
            //update adjustment
            nparm = cparm + deltap;
            for(int n=0;n<np;++n)
            {
               setAdjustableParameter(n, nparm(n+1), false); //do not update now, wait
            }
            adjustableParametersChanged();

            //check residue is reduced
            NEWMAT::ColumnVector newresidue = getResidue(tieSet);
            double newki2=newresidue.SumSquare();
            double res_reduction = (ki2 - newki2) / (deltap.t()*(deltap*damping + projResidue)).AsScalar();
 //DEBUG TBR
       cout<<sqrt(newki2/nobs)<<" ";
       cout.flush();

            if (res_reduction > 0)
            {
               //accept new parms
               cparm = nparm;
               ki2=newki2;

               deltap_scale = max(1e-15, deltap.NormInfinity()*1e-4);

               buildNormalEquation(tieSet, A, residue, projResidue, deltap_scale);
               olddamping = 0.0;

               found = ( projResidue.NormInfinity() <= minResidue );
               //update damping factor
               damping *= std::max( 1.0/3.0, 1.0-std::pow((2.0*res_reduction-1.0),3));
               damping_speed = 2.0;
               decrease = true;
            } else {
               //cancel parameter update
               for(int n=0;n<np;++n)
               {
                  setAdjustableParameter(n, nparm(n+1), false); //do not update right now
               }
               adjustableParametersChanged();

               damping *= damping_speed;
               damping_speed *= 2.0;
            }
         }
      } while (!decrease && !found);
      ++iter;
   }

//DEBUG TBR
cout<<endl;

   //compute parameter correlation
   // use normal matrix inverse
   //TBD

   return ki2/nobs;
#endif
}
bool rspfApplanixEcefModel::loadState(const rspfKeywordlist& kwl,
                                       const char* prefix)
{
   if(traceDebug())
   {
      std::cout << "rspfApplanixEcefModel::loadState: ......... entered" << std::endl;
   }

   theImageClipRect = rspfDrect(0,0,4076,4091);
   theRefImgPt      = rspfDpt(2046.0, 2038.5);

   rspfSensorModel::loadState(kwl, prefix);
   if(getNumberOfAdjustableParameters() < 1)
   {
      initAdjustableParameters();
   }
   theEcefPlatformPosition    = rspfGpt(0.0,0.0,1000.0);
   theAdjEcefPlatformPosition = rspfGpt(0.0,0.0,1000.0);
   theRoll    = 0.0;
   thePitch   = 0.0;
   theHeading = 0.0;
   // bool computeGsdFlag = false;
   const char* roll              = kwl.find(prefix, "roll");
   const char* pitch             = kwl.find(prefix, "pitch");
   const char* heading           = kwl.find(prefix, "heading");
   const char* principal_point   = kwl.find(prefix, "principal_point");
   const char* pixel_size        = kwl.find(prefix, "pixel_size");
   const char* focal_length      = kwl.find(prefix, "focal_length");
   const char* ecef_platform_position = kwl.find(prefix, "ecef_platform_position");
   const char* latlonh_platform_position = kwl.find(prefix, "latlonh_platform_position");
   const char* compute_gsd_flag  = kwl.find(prefix, "compute_gsd_flag");
   const char* eo_file           = kwl.find(prefix, "eo_file");
   const char* camera_file       = kwl.find(prefix, "camera_file");
   const char* eo_id             = kwl.find(prefix, "eo_id");
   bool result = true;
   if(eo_id)
   {
      theImageID = eo_id;
   }
   if(eo_file)
   {
      rspfApplanixEOFile eoFile;
      if(eoFile.parseFile(rspfFilename(eo_file)))
      {
         rspfRefPtr<rspfApplanixEORecord> record = eoFile.getRecordGivenId(theImageID);
         if(record.valid())
         {
            rspf_int32 rollIdx    = eoFile.getFieldIdx("ROLL");
            rspf_int32 pitchIdx   = eoFile.getFieldIdx("PITCH");
            rspf_int32 headingIdx = eoFile.getFieldIdx("HEADING");
            rspf_int32 xIdx       = eoFile.getFieldIdx("X");
            rspf_int32 yIdx       = eoFile.getFieldIdx("Y");
            rspf_int32 zIdx       = eoFile.getFieldIdx("Z");

            if((rollIdx >= 0)&&
               (pitchIdx >= 0)&&
               (headingIdx >= 0)&&
               (xIdx >= 0)&&
               (yIdx >= 0)&&
               (zIdx >= 0))
            {
               theRoll    = (*record)[rollIdx].toDouble();
               thePitch   = (*record)[pitchIdx].toDouble();
               theHeading = (*record)[headingIdx].toDouble();
               theEcefPlatformPosition = rspfEcefPoint((*record)[xIdx].toDouble(),
                                                        (*record)[yIdx].toDouble(),
                                                        (*record)[zIdx].toDouble());
               theAdjEcefPlatformPosition = theEcefPlatformPosition;
            }
            else
            {
               return false;
            }
         }
         else
         {
            rspfNotify(rspfNotifyLevel_WARN) << "rspfApplanixEcefModel::loadState()  Image id " << theImageID << " not found in eo file " << eo_file << std::endl;
            
            return false;
         }
      }
      else
      {
         return false;
      }
      // computeGsdFlag = true;
   }
   else
   {
      if(roll)
      {
         theRoll = rspfString(roll).toDouble();
      }
      if(pitch)
      {
         thePitch = rspfString(pitch).toDouble();
      }
      if(heading)
      {
         theHeading = rspfString(heading).toDouble();
      }
      if(ecef_platform_position)
      {
         std::vector<rspfString> splitString;
         rspfString tempString(ecef_platform_position);
         tempString.split(splitString, rspfString(" "));
         if(splitString.size() > 2)
         {
            theEcefPlatformPosition  = rspfEcefPoint(splitString[0].toDouble(),
                                                      splitString[1].toDouble(),
                                                      splitString[2].toDouble());
         }
      }
      else if(latlonh_platform_position)
      {
         std::vector<rspfString> splitString;
         rspfString tempString(latlonh_platform_position);
         tempString.split(splitString, rspfString(" "));
         std::string datumString;
         double lat=0.0, lon=0.0, h=0.0;
         if(splitString.size() > 2)
         {
            lat = splitString[0].toDouble();
            lon = splitString[1].toDouble();
            h = splitString[2].toDouble();
         }
         
         theEcefPlatformPosition = rspfGpt(lat,lon,h);
      }
   }

   if(camera_file)
   {
      rspfKeywordlist cameraKwl;
      rspfKeywordlist lensKwl;
      cameraKwl.add(camera_file);
      const char* sensor = cameraKwl.find("sensor");
      const char* image_size      = cameraKwl.find(prefix, "image_size");
      principal_point = cameraKwl.find("principal_point");
      focal_length    = cameraKwl.find("focal_length");
      pixel_size      = cameraKwl.find(prefix, "pixel_size");
      focal_length    = cameraKwl.find(prefix, "focal_length");
      const char* distortion_units = cameraKwl.find(prefix, "distortion_units");
      rspfUnitConversionTool tool;
      rspfUnitType unitType = RSPF_MILLIMETERS;

      if(distortion_units)
      {
         unitType = (rspfUnitType)rspfUnitTypeLut::instance()->getEntryNumber(distortion_units);

         if(unitType == RSPF_UNIT_UNKNOWN)
         {
            unitType = RSPF_MILLIMETERS;
         }
      }
      if(image_size)
      {
         std::vector<rspfString> splitString;
         rspfString tempString(image_size);
         tempString.split(splitString, rspfString(" "));
         double w=1, h=1;
         if(splitString.size() == 2)
         {
            w = splitString[0].toDouble();
            h = splitString[1].toDouble();
         }
         theImageClipRect = rspfDrect(0,0,w-1,h-1);
         theRefImgPt      = rspfDpt(w/2.0, h/2.0);
      }
      if(sensor)
      {
         theSensorID = sensor;
      }
      if(principal_point)
      {
         std::vector<rspfString> splitString;
         rspfString tempString(principal_point);
         tempString.split(splitString, rspfString(" "));
         if(splitString.size() == 2)
         {
            thePrincipalPoint.x = splitString[0].toDouble();
            thePrincipalPoint.y = splitString[1].toDouble();
         }
      }
      if(pixel_size)
      {
         std::vector<rspfString> splitString;
         rspfString tempString(pixel_size);
         tempString.split(splitString, rspfString(" "));
         if(splitString.size() == 1)
         {
            thePixelSize.x = splitString[0].toDouble();
            thePixelSize.y = thePixelSize.x;
         }
         else if(splitString.size() == 2)
         {
            thePixelSize.x = splitString[0].toDouble();
            thePixelSize.y = splitString[1].toDouble();
         }
      }
      if(focal_length)
      {
         theFocalLength = rspfString(focal_length).toDouble();
      }

      cameraKwl.trimAllValues();
      
      
      rspfString regExpression =  rspfString("^(") + "d[0-9]+)";
      vector<rspfString> keys;
      cameraKwl.getSubstringKeyList( keys, regExpression );
      long numberOfDistortions = (long)keys.size();
      int offset = (int)rspfString("d").size();
      rspf_uint32 idx = 0;
      std::vector<int> numberList(numberOfDistortions);
      for(idx = 0; idx < (int)numberList.size();++idx)
      {
         rspfString numberStr(keys[idx].begin() + offset,
                               keys[idx].end());
         numberList[idx] = numberStr.toInt();
      }
      std::sort(numberList.begin(), numberList.end());
      double distance=0.0, distortion=0.0;

      for(idx = 0; idx < numberList.size(); ++idx)
      {
         rspfString value = cameraKwl.find(rspfString("d")+rspfString::toString(numberList[idx]));

         if(!value.empty())
         {
            std::istringstream inStr(value.c_str());
            inStr >> distance;
            rspf::skipws(inStr);
            inStr >> distortion;
#if 0
            std::vector<rspfString> splitString;
            rspfString tempString(value);
            tempString = tempString.trim();
            tempString.split(splitString, " ");
            std::cout << splitString.size() << std::endl;
            if(splitString.size() >= 2)
            {
               distance = splitString[0].toDouble();
               distortion = splitString[1].toDouble();
            }
#endif
            
            tool.setValue(distortion, unitType);
            lensKwl.add(rspfString("distance") + rspfString::toString(idx),
                        distance,
                        true);
            lensKwl.add(rspfString("distortion") + rspfString::toString(idx),
                        tool.getMillimeters(),
                        true);
         }
         lensKwl.add("convergence_threshold",
                     .00001,
                     true);
         if(pixel_size)
         {
            lensKwl.add("dxdy",
                        rspfString(pixel_size) + " " + rspfString(pixel_size),
                        true);
         }
         else
         {
            lensKwl.add("dxdy",
                        ".009 .009",
                        true);
         }
      }
      if(theLensDistortion.valid())
      {
         theLensDistortion->loadState(lensKwl,"");
      }
   }
示例#13
0
bool ossimPpjFrameSensor::loadState(const ossimKeywordlist& kwl, const char* prefix)
{
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimPpjFrameSensor::loadState DEBUG:" << std::endl;
   }

   theGSD.makeNan();
   theRefImgPt.makeNan();
   ossimSensorModel::loadState(kwl, prefix);
   if(getNumberOfAdjustableParameters() < 1)
   {
      initAdjustableParameters();
   }
   ossimString principal_point = kwl.find(prefix, "principal_point");
   ossimString focal_length_x = kwl.find(prefix, "focal_length_x");
   ossimString focal_length_y = kwl.find(prefix, "focal_length_y");
   ossimString number_samples = kwl.find(prefix, "number_samples");
   ossimString number_lines = kwl.find(prefix, "number_lines");
   ossimString ecf_to_cam_row1 = kwl.find(prefix, "ecf_to_cam_row1");
   ossimString ecf_to_cam_row2 = kwl.find(prefix, "ecf_to_cam_row2");
   ossimString ecf_to_cam_row3 = kwl.find(prefix, "ecf_to_cam_row3");
   ossimString platform_position = kwl.find(prefix, "ecef_camera_position");
   ossimString averageProjectedHeight = kwl.find(prefix, "average_projected_height");

   // ossimString roll;
   // ossimString pitch;
   // ossimString yaw;
   // m_roll    = 0;
   // m_pitch   = 0;
   // m_yaw     = 0;
   // roll      = kwl.find(prefix, "roll"); 
   // pitch     = kwl.find(prefix, "pitch"); 
   // yaw       = kwl.find(prefix, "yaw"); 

   bool result = (!principal_point.empty()&&
                  !focal_length_x.empty()&&
                  !platform_position.empty()&&
                  !ecf_to_cam_row1.empty()&&
                  !ecf_to_cam_row2.empty()&&
                  !ecf_to_cam_row3.empty());
   if(!averageProjectedHeight.empty())
   {
      m_averageProjectedHeight = averageProjectedHeight.toDouble();
   }
   if(!number_samples.empty())
   {
      theImageSize = ossimIpt(number_samples.toDouble(), number_lines.toDouble());
      theRefImgPt = ossimDpt(theImageSize.x*.5, theImageSize.y*.5);
      theImageClipRect = ossimDrect(0,0,theImageSize.x-1, theImageSize.y-1);
   }
   if(theImageClipRect.hasNans())
   {
      theImageClipRect = ossimDrect(0,0,theImageSize.x-1,theImageSize.y-1);
   }
   if(theRefImgPt.hasNans())
   {
      theRefImgPt = theImageClipRect.midPoint();
   }
   if(!focal_length_x.empty())
   {
      m_focalLengthX = focal_length_x.toDouble();
      m_focalLength = m_focalLengthX;
   }
   if(!focal_length_y.empty())
   {
      m_focalLengthY = focal_length_y.toDouble();
   }

   std::vector<ossimString> row;
   if(!ecf_to_cam_row1.empty())
   {
      row = ecf_to_cam_row1.explode(" ");
      for (int i=0; i<3; ++i)
         m_ecef2Cam[0][i] = row[i].toDouble();
      row = ecf_to_cam_row2.explode(" ");
      for (int i=0; i<3; ++i)
         m_ecef2Cam[1][i] = row[i].toDouble();
      row = ecf_to_cam_row3.explode(" ");
      for (int i=0; i<3; ++i)
         m_ecef2Cam[2][i] = row[i].toDouble();
      m_ecef2CamInverse = m_ecef2Cam.t();
   }

   // if(!roll.empty())
   // {
   //    m_roll = roll.toDouble();
   // }
   // if(!pitch.empty())
   // {
   //    m_pitch = pitch.toDouble();
   // }
   // if(!yaw.empty())
   // {
   //    m_yaw   = yaw.toDouble();
   // }

   if(!principal_point.empty())
   {
      m_principalPoint.toPoint(principal_point);
   }
   if(!platform_position.empty())
   {
      m_ecefCameraPosition.toPoint(platform_position);
      m_cameraPositionEllipsoid = ossimGpt(m_ecefCameraPosition);
   }

   
   updateModel();
   
   if(theGSD.isNan())
   {
      try
      {
         computeGsd();
      }
      catch (const ossimException& e)
      {
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG)
            << "ossimPpjFrameSensor::loadState Caught Exception:\n"
            << e.what() << std::endl;
         }
      }
   }
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimPpjFrameSensor::loadState complete..." << std::endl;
   }
   
   return result;
}
示例#14
0
bool ossimBuckeyeSensor::loadState(const ossimKeywordlist& kwl,
	const char* prefix)
{
	if (traceDebug())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimBuckeyeSensor::loadState: entering..." << std::endl;

	theImageClipRect = ossimDrect(0,0,8984,6732);
	theRefImgPt      = ossimDpt(4492, 3366);

	ossimSensorModel::loadState(kwl, prefix);
	if(getNumberOfAdjustableParameters() < 1)
	{
		initAdjustableParameters();
	}
	theEcefPlatformPosition    = ossimGpt(0.0,0.0,1000.0);
	theAdjEcefPlatformPosition = ossimGpt(0.0,0.0,1000.0);
	theRoll    = 0.0;
	thePitch   = 0.0;
	theHeading = 0.0;

	ossimString framemeta_gsti = kwl.find(prefix, "framemeta_gsti");
	ossimString framemeta = kwl.find(prefix,"framemeta");
	ossimString frame_number = kwl.find(prefix, "frame_number");
	ossimString pixel_size = kwl.find(prefix, "pixel_size");
	ossimString principal_point = kwl.find(prefix, "principal_point");
	ossimString focal_length = kwl.find(prefix, "focal_length");
	ossimString smac_radial = kwl.find(prefix, "smac_radial");
	ossimString smac_decent = kwl.find(prefix, "smac_decent");
	ossimString roll;
	ossimString pitch;
	ossimString yaw;
	ossimString platform_position;
	ossimFilename file_to_load;

	ossimString FRAME_STRING	= "Frame#";
	ossimString ROLL_STRING		= "Roll(deg)";
	ossimString PITCH_STRING	= "Pitch(deg)";
	ossimString YAW_STRING		= "Yaw(deg)";
	ossimString LAT_STRING		= "Lat(deg)";
	ossimString LON_STRING		= "Lon(deg)";
	ossimString HAE_STRING		= "HAE(m)";

	// Deal with the fact that there are 3 different types of 'FrameMeta' file
	if (framemeta_gsti.empty() && !framemeta.empty() && !frame_number.empty())
	{
		file_to_load.setFile(framemeta);
		YAW_STRING	= "Azimuth(deg)";
	}
	else if (!framemeta_gsti.empty() && framemeta.empty() && !frame_number.empty())
	{
		file_to_load.setFile(framemeta_gsti);
	}

	if (file_to_load.exists() && !frame_number.empty())
	{
		ossimCsvFile csv(" \t"); // we will use tab or spaces as seaparator
		if(csv.open(file_to_load))
		{
			if(csv.readHeader())
			{
				ossimCsvFile::StringListType heads = csv.fieldHeaderList();
				// Try to see if you can find the first header item, if not, then you either have a file that doesn't work in this case, or it's uppercase
				if (std::find(heads.begin(), heads.end(), FRAME_STRING) == heads.end())
				{
					FRAME_STRING	= FRAME_STRING.upcase();
					ROLL_STRING		= ROLL_STRING.upcase();
					PITCH_STRING	= PITCH_STRING.upcase();
					YAW_STRING		= YAW_STRING.upcase();
					LAT_STRING		= LAT_STRING.upcase();
					LON_STRING		= LON_STRING.upcase();
					HAE_STRING		= HAE_STRING.upcase();
				}

				ossimRefPtr<ossimCsvFile::Record> record;
				bool foundFrameNumber = false;
				while( ((record = csv.nextRecord()).valid()) && !foundFrameNumber)
				{
					if( (*record)[FRAME_STRING] == frame_number)
					{
						foundFrameNumber = true;
						roll = (*record)[ROLL_STRING];
						pitch = (*record)[PITCH_STRING];
						yaw = (*record)[YAW_STRING];
						platform_position = (*record)[LAT_STRING] + " " 
							+ (*record)[LON_STRING]+ " "
							+ (*record)[HAE_STRING] + " WGE";
					}
				}
			}
		}
		csv.close();
	}
	else
	{
		roll = kwl.find(prefix, "roll"); 
		pitch = kwl.find(prefix, "pitch"); 
		yaw = kwl.find(prefix, "heading"); 
		platform_position = kwl.find(prefix, "ecef_platform_position");
	}

	bool result = (!pixel_size.empty()&&
		!principal_point.empty()&&
		!focal_length.empty()&&
		!platform_position.empty());

	if(!focal_length.empty())
	{
		theFocalLength = focal_length.toDouble();
	}
	if(!pixel_size.empty())
	{
		thePixelSize.toPoint(pixel_size);
	}
	if(!roll.empty())
	{
		theRoll = roll.toDouble();
	}
	if(!pitch.empty())
	{
		thePitch = pitch.toDouble();
	}
	if(!yaw.empty())
	{
		theHeading   = yaw.toDouble();
	}
	if(!principal_point.empty())
	{
		thePrincipalPoint.toPoint(principal_point);
	}
	if(platform_position.contains("WGE"))
	{
		std::vector<ossimString> splitString;
		ossimString tempString(platform_position);
		tempString.split(splitString, ossimString(" "));
		std::string datumString;
		double lat=0.0, lon=0.0, h=0.0;
		if(splitString.size() > 2)
		{
			lat = splitString[0].toDouble();
			lon = splitString[1].toDouble();
			h = splitString[2].toDouble();
		}

		theEcefPlatformPosition = ossimGpt(lat,lon,h);
	} else {
		std::vector<ossimString> splitString;
		ossimString tempString(platform_position);
		tempString.split(splitString, ossimString(" "));
		std::string datumString;
		double x=0.0, y=0.0, z=0.0;
		if(splitString.size() > 2)
		{
			x = splitString[0].toDouble();
			y = splitString[1].toDouble();
			z = splitString[2].toDouble();
		}
		theEcefPlatformPosition = ossimEcefPoint(x, y, z);
	}
	theLensDistortion = 0;
	if(!smac_radial.empty()&&
		!smac_decent.empty())
	{
		std::vector<ossimString> radial;
		std::vector<ossimString> decent;
		smac_radial.split(radial, " ");
		smac_decent.split(decent, " ");
		if((radial.size() == 5)&&
			(decent.size() == 4))
		{
			// Just for debugging really.. optomization will make this sleeker
			double k0 = radial[0].toDouble();
			double k1 = radial[1].toDouble();
			double k2 = radial[2].toDouble();
			double k3 = radial[3].toDouble();
			double k4 = radial[4].toDouble();

			double p0 = decent[0].toDouble();
			double p1 = decent[1].toDouble();
			double p2 = decent[2].toDouble();
			double p3 = decent[3].toDouble();

			//theLensDistortion = new ossimSmacCallibrationSystem(radial[0].toDouble(),
			//	radial[1].toDouble(),
			//	radial[2].toDouble(),
			//	radial[3].toDouble(),
			//	radial[4].toDouble(),
			//	decent[0].toDouble(),
			//	decent[1].toDouble(),
			//	decent[2].toDouble(),
			//	decent[3].toDouble());

			theLensDistortion = new ossimSmacCallibrationSystem(k0,k1,k2,k3,k4,p0,p1,p2,p3);
		}
	}
	theImageSize = ossimDpt(theImageClipRect.width(),
		theImageClipRect.height());

	updateModel();

	if(theGSD.isNan())
	{
		try
		{
			// This will set theGSD and theMeanGSD. Method throws ossimException.
			computeGsd();
		}
		catch (const ossimException& e)
		{
			if (traceDebug())
			{
				ossimNotify(ossimNotifyLevel_DEBUG)
					<< "ossimBuckeyeSensor::loadState Caught Exception:\n"
					<< e.what() << std::endl;
			}
		}
	}
	if (traceDebug())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimBuckeyeSensor::loadState: returning..." << std::endl;
	return result;
}
示例#15
0
bool rspfLandSatModel::loadState(const rspfKeywordlist& kwl,
                                  const char* prefix) 
{
   if (traceExec())  rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::loadState: entering..." << std::endl;
   if (traceDebug())
   {
      rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::loadState:"
                                          << "\nInput kwl:  " << kwl
                                          << std::endl;
   }
   const char* value = NULL;
   const char* keyword =NULL;
   bool success;
   value = kwl.find(prefix, rspfKeywordNames::TYPE_KW);
   if (!value || (strcmp(value, TYPE_NAME(this)))) 
     {
       theErrorStatus = 1;
       return false;
     }
   if(getNumberOfAdjustableParameters() != NUM_ADJUSTABLE_PARAMS)
     {
       initAdjustableParameters();
     }
   
   success = rspfSensorModel::loadState(kwl, prefix);
   if (!success) 
     {
       theErrorStatus++;
       return false;
     }
 
   keyword = PROJECTION_TYPE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theProjectionType = (ProjectionType) atoi(value);
 
   keyword = MAP_ZONE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theMapZone = atoi(value);
   if(theMapZone==0) {
   
  /* static const char*  MAP_SCALE_KW        = "theMapScale";
static const char*  MAP_CENTER_LONGITUDE_KW        = "theMapCenterLongitude";
static const char*  MAP_OFFSET_LONGITUDE_KW        = "theMapoffsetX";
static const char*  MAP_OFFSET_LATITUDE_KW        = "theMapoffsetY";
   
      double			m_scale;
   double			m_centerLongitude;
   double			m_theMapoffsetX;
   double		    m_theMapoffsetY;*/
   keyword = MAP_SCALE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   m_scale = atof(value);
   keyword = MAP_CENTER_LONGITUDE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   m_centerLongitude = atof(value);
      keyword = MAP_OFFSET_LONGITUDE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   m_theMapoffsetX = atof(value);
      keyword = MAP_OFFSET_LATITUDE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   m_theMapoffsetY = atof(value);
         keyword = MAP_SEMI_MAJOR_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   semi_major = atof(value);
         keyword = MAP_SEMI_MINOR_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   semi_minor= atof(value);
   
   }
 
   keyword = MAP_OFFSET_X_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theMapOffset.x = atof(value);
 
   keyword = MAP_OFFSET_Y_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theMapOffset.y = atof(value);
 
   keyword = WRS_PATH_NUMBER_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theWrsPathNumber = atoi(value);
   keyword = ROW_NUMBER_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theWrsRowNumber = atoi(value);
 
   keyword = ILLUM_AZIMUTH_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theIllumAzimuth = atof(value);
 
   keyword = ILLUM_ELEVATION_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theIllumElevation = atof(value);
 
   keyword = MERIDIANAL_ANGLE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theMeridianalAngle = atof(value);
 
   keyword = ORBIT_ALTITUDE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theOrbitAltitude = atof(value);
   
   keyword = ORBIT_INCLINATION_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theOrbitInclination = atof(value);
   
   keyword = MAP_AZIM_ANGLE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theMapAzimAngle = atof(value);
 
   keyword = MAP_2Ic_ROT_ANGLE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
     {
       theErrorStatus++;
       return false;
     }
   theMap2IcRotAngle = atof(value);
   theIntrackOffset = 0.0;
   theCrtrackOffset = 0.0;
   theLineGsdCorr   = 0.0;
   theSampGsdCorr   = 0.0;
   theRollOffset    = 0.0;
   theYawOffset     = 0.0;
   theYawRate       = 0.0;
   theMapRotation   = 0.0;
   
   
   
   
   initMapProjection();
   updateModel();
   
   if (traceExec())  rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::loadState: returning..." << std::endl;
   return true;
}
//*************************************************************************************************
//! Sets all the change flags to the boolean indicated to indicate parameters are changed (TRUE)
//! or not (FALSE).
//*************************************************************************************************
void ossimAdjustableParameterInterface::setAllChangeFlags(bool areChanged)
{
   ossim_uint32 num_params = getNumberOfAdjustableParameters();
   for (unsigned int i=0; i<num_params; ++i)
      theChangeFlags[i] = areChanged;
}
示例#17
0
//*****************************************************************************
//  METHOD: ossimRpcProjection::loadState()
//  
//  Restores the model's state from the KWL. This KWL also serves as a
//  geometry file.
//  
//*****************************************************************************
bool ossimRpcProjection::loadState(const ossimKeywordlist& kwl,
                              const char* prefix) 
{
   if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcProjection::loadState(): entering..." << std::endl;

   const char* value;
   const char* keyword;

   //***
   // Pass on to the base-class for parsing first:
   //***
   bool success = ossimProjection::loadState(kwl, prefix);
   if (!success)
   {
      theErrorStatus++;
      if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcProjection::loadState(): returning with error..." << std::endl;
      return false;
   }
      
   //***
   // Continue parsing for local members:
   //***
   keyword = POLY_TYPE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   thePolyType = (PolynomialType) value[0];
      
   keyword = LINE_SCALE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theLineScale = ossimString(value).toDouble();
   
   keyword = SAMP_SCALE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theSampScale = ossimString(value).toDouble();
   
   keyword = LAT_SCALE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theLatScale = ossimString(value).toDouble();
   
   keyword = LON_SCALE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theLonScale = ossimString(value).toDouble();
   
   keyword = HGT_SCALE_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theHgtScale = ossimString(value).toDouble();
   
   keyword = LINE_OFFSET_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theLineOffset = ossimString(value).toDouble();
   
   keyword = SAMP_OFFSET_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theSampOffset = ossimString(value).toDouble();
   
   keyword = LAT_OFFSET_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theLatOffset = ossimString(value).toDouble();
   
   keyword = LON_OFFSET_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theLonOffset = ossimString(value).toDouble();
   
   keyword = HGT_OFFSET_KW;
   value = kwl.find(prefix, keyword);
   if (!value)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                          << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                          << std::endl;
      return false;
   }
   theHgtOffset = ossimString(value).toDouble();

   for (int i=0; i<NUM_COEFFS; i++)
   {
      value = kwl.find(prefix, (LINE_NUM_COEF_KW+ossimString::toString(i)).c_str());
      if (!value)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                             << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                             << std::endl;
         return false;
      }
      theLineNumCoef[i] = ossimString(value).toDouble();
   
      value = kwl.find(prefix, (LINE_DEN_COEF_KW+ossimString::toString(i)).c_str());
      if (!value)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                             << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                             << std::endl;
         return false;
      }
      theLineDenCoef[i] = ossimString(value).toDouble();
   
      value = kwl.find(prefix, (SAMP_NUM_COEF_KW+ossimString::toString(i)).c_str());
      if (!value)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                             << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                             << std::endl;
         return false;
      }
      theSampNumCoef[i] = ossimString(value).toDouble();
      
      value = kwl.find(prefix, (SAMP_DEN_COEF_KW+ossimString::toString(i)).c_str());
      if (!value)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimRpcProjection::loadState(): Error encountered parsing the following required keyword: "
                                             << "<" << keyword << ">. Check the keywordlist for proper syntax."
                                             << std::endl;
         return false;
      }
      theSampDenCoef[i] = ossimString(value).toDouble();
   }

   loadAdjustments(kwl, prefix);

   if(getNumberOfAdjustableParameters() < 1)
   {
      initAdjustableParameters();
   }
      
   if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcProjection::loadState(): returning..." << std::endl;

   return true;
}
示例#18
0
bool rspfBuckeyeSensor::loadState(const rspfKeywordlist& kwl, const char* prefix)
{
   if(getNumberOfAdjustableParameters() < 1)
   {
      initAdjustableParameters();
   }
   theGSD.makeNan();
   theRefImgPt.makeNan();
   rspfSensorModel::loadState(kwl, prefix);
   if(theRefImgPt.hasNans())
   {
      theRefImgPt = theImageClipRect.midPoint();
   }
   rspfString framemeta_gsti = kwl.find(prefix, "framemeta_gsti");
   rspfString frame_number = kwl.find(prefix, "frame_number");
   rspfString pixel_size = kwl.find(prefix, "pixel_size");
   rspfString principal_point = kwl.find(prefix, "principal_point");
   rspfString focal_length = kwl.find(prefix, "focal_length");
   rspfString smac_radial = kwl.find(prefix, "smac_radial");
   rspfString smac_decent = kwl.find(prefix, "smac_decent");
   rspfString roll;
   rspfString pitch;
   rspfString yaw;
   rspfString platform_position;
   m_roll    = 0;
   m_pitch   = 0;
   m_yaw     = 0;
   if(!framemeta_gsti.empty()&&
      !frame_number.empty())
   {
      rspfCsvFile csv(" \t"); // we will use tab or spaces as seaparator
      if(csv.open(framemeta_gsti))
      {
         if(csv.readHeader())
         {
            rspfRefPtr<rspfCsvFile::Record> record;
            bool foundFrameNumber = false;
            while( ((record = csv.nextRecord()).valid()) && !foundFrameNumber)
            {
               if( (*record)["Frame#"] == frame_number)
               {
                  foundFrameNumber = true;
                  roll = (*record)["Roll(deg)"];
                  pitch = (*record)["Pitch(deg)"];
                  yaw = (*record)["Yaw(deg)"];
                  platform_position = "(" + (*record)["Lat(deg)"] + "," 
                                          + (*record)["Lon(deg)"]+ ","
                                          + (*record)["HAE(m)"] + ",WGE)";
               }
            }
         }
      }
   }
   else
   {
      roll = kwl.find(prefix, "roll"); 
      pitch = kwl.find(prefix, "pitch"); 
      yaw = kwl.find(prefix, "yaw"); 
      platform_position = kwl.find(prefix, "platform_position");
   }
   bool result = (!pixel_size.empty()&&
                  !principal_point.empty()&&
                  !focal_length.empty()&&
                  !platform_position.empty());
   
   if(!focal_length.empty())
   {
      m_focalLength = focal_length.toDouble();
   }
   if(!pixel_size.empty())
   {
      m_pixelSize.toPoint(pixel_size);
   }
   if(!roll.empty())
   {
      m_roll = roll.toDouble();
   }
   if(!pitch.empty())
   {
      m_pitch = pitch.toDouble();
   }
   if(!yaw.empty())
   {
      m_yaw   = yaw.toDouble();
   }
   if(!principal_point.empty())
   {
      m_principalPoint.toPoint(principal_point);
   }
   if(!platform_position.empty())
   {
      m_platformPosition.toPoint(platform_position);
   }
   m_lensDistortion = 0;
   if(!smac_radial.empty()&&
      !smac_decent.empty())
   {
      std::vector<rspfString> radial;
      std::vector<rspfString> decent;
      smac_radial.split(radial, " ");
      smac_decent.split(decent, " ");
      if((radial.size() == 5)&&
         (decent.size() == 4))
      {
         m_lensDistortion = new rspfSmacCallibrationSystem(radial[0].toDouble(),
                                                            radial[1].toDouble(),
                                                            radial[2].toDouble(),
                                                            radial[3].toDouble(),
                                                            radial[4].toDouble(),
                                                            decent[0].toDouble(),
                                                            decent[1].toDouble(),
                                                            decent[2].toDouble(),
                                                            decent[3].toDouble());
      }
   }
   theImageSize = rspfDpt(theImageClipRect.width(),
                           theImageClipRect.height());
   
   updateModel();
   
   if(theGSD.isNan())
   {
      try
      {
         computeGsd();
      }
      catch (const rspfException& e)
      {
         if (traceDebug())
         {
            rspfNotify(rspfNotifyLevel_DEBUG)
               << "rspfBuckeyeSensor::loadState Caught Exception:\n"
               << e.what() << std::endl;
         }
      }
   }
   
   return result;
}