void ossimLandSatModel::lineSampleHeightToWorld(const ossimDpt& image_point, const double& height, ossimGpt& gpt) const { if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimLandSatModel::lineSampleHeightToWorld: entering..." << std::endl; #if 0 if (!insideImage(image_point)) { gpt = extrapolate(image_point, height); if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimLandSatModel::lineSampleHeightToWorld: returning..." << std::endl; return; } #endif ossimEcefRay imaging_ray; imagingRay(image_point, imaging_ray); //ossimEcefPoint Pecf (imaging_ray.intersectAboveEarthEllipsoid(height)); //gpt = ossimGpt(Pecf); if (m_proj==NULL) { ossimEcefPoint Pecf (imaging_ray.intersectAboveEarthEllipsoid(height)); gpt = ossimGpt(Pecf); } else { ossimEcefPoint Pecf (imaging_ray.intersectAboveEarthEllipsoid(height,m_proj->getDatum())); gpt = ossimGpt(Pecf,m_proj->getDatum()); } }
ossimSpectraboticsRedEdgeModel::ossimSpectraboticsRedEdgeModel() { m_compositeMatrix = ossimMatrix4x4::createIdentity(); m_compositeMatrixInverse = ossimMatrix4x4::createIdentity(); m_roll = 0.0; m_pitch = 0.0; m_heading = 0.0; m_focalLength = 5.5; m_pixelSize = ossimDpt(0.003, 0.003); m_ecefPlatformPosition = ossimGpt(0.0,0.0, 1000.0); m_adjEcefPlatformPosition = ossimGpt(0.0,0.0, 1000.0); theGSD.x = 0.076; theGSD.y = 0.076; theMeanGSD = 0.076; m_fov = 48.8; // degrees m_lensDistortion = new ossimTangentialRadialLensDistortion(); initAdjustableParameters(); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimSpectraboticsRedEdgeModel::ossimSpectrabotics DEBUG:" << endl; #ifdef OSSIM_ID_ENABLED ossimNotify(ossimNotifyLevel_DEBUG)<< "OSSIM_ID: " << OSSIM_ID << endl; #endif } }
bool ossimPredatorKlvTable::getCornerPoints(ossimGpt& pt1, ossimGpt& pt2, ossimGpt& pt3, ossimGpt& pt4)const { klvMapType::const_iterator lat1i = theKlvParameters.find(KLV_KEY_CORNER_LATITUDE_POINT_1); klvMapType::const_iterator lat2i = theKlvParameters.find(KLV_KEY_CORNER_LATITUDE_POINT_2); klvMapType::const_iterator lat3i = theKlvParameters.find(KLV_KEY_CORNER_LATITUDE_POINT_3); klvMapType::const_iterator lat4i = theKlvParameters.find(KLV_KEY_CORNER_LATITUDE_POINT_4); klvMapType::const_iterator lon1i = theKlvParameters.find(KLV_KEY_CORNER_LONGITUDE_POINT_1); klvMapType::const_iterator lon2i = theKlvParameters.find(KLV_KEY_CORNER_LONGITUDE_POINT_2); klvMapType::const_iterator lon3i = theKlvParameters.find(KLV_KEY_CORNER_LONGITUDE_POINT_3); klvMapType::const_iterator lon4i = theKlvParameters.find(KLV_KEY_CORNER_LONGITUDE_POINT_4); if((lat1i!=theKlvParameters.end())&& (lat2i!=theKlvParameters.end())&& (lat3i!=theKlvParameters.end())&& (lat4i!=theKlvParameters.end())&& (lon1i!=theKlvParameters.end())&& (lon2i!=theKlvParameters.end())&& (lon3i!=theKlvParameters.end())&& (lon4i!=theKlvParameters.end())) { ossim_float64 lat1 = *reinterpret_cast<const ossim_float64*>(&(lat1i->second.theValue.front())); ossim_float64 lat2 = *reinterpret_cast<const ossim_float64*>(&(lat2i->second.theValue.front())); ossim_float64 lat3 = *reinterpret_cast<const ossim_float64*>(&(lat3i->second.theValue.front())); ossim_float64 lat4 = *reinterpret_cast<const ossim_float64*>(&(lat4i->second.theValue.front())); ossim_float64 lon1 = *reinterpret_cast<const ossim_float64*>(&(lon1i->second.theValue.front())); ossim_float64 lon2 = *reinterpret_cast<const ossim_float64*>(&(lon2i->second.theValue.front())); ossim_float64 lon3 = *reinterpret_cast<const ossim_float64*>(&(lon3i->second.theValue.front())); ossim_float64 lon4 = *reinterpret_cast<const ossim_float64*>(&(lon4i->second.theValue.front())); if(theNeedToSwapFlag) { theEndian.swap(lat1); theEndian.swap(lat2); theEndian.swap(lat3); theEndian.swap(lat4); theEndian.swap(lon1); theEndian.swap(lon2); theEndian.swap(lon3); theEndian.swap(lon4); } pt1 = ossimGpt(lat1, lon1); pt2 = ossimGpt(lat2, lon2); pt3 = ossimGpt(lat3, lon3); pt4 = ossimGpt(lat4, lon4); return true; } return false; }
ossimGpt ossimThreeParamDatum::shiftToWgs84(const ossimGpt &aPt)const { if(ossim::almostEqual(param1(), 0.0)&& ossim::almostEqual(param2(), 0.0)&& ossim::almostEqual(param3(), 0.0)) { return ossimGpt(aPt.latd(), aPt.lond(), aPt.latd(), ossimGpt().datum()); } ossimEcefPoint p1 = aPt; ossimEcefPoint p2; if(withinMolodenskyRange(aPt.latd())) { ossimWgs84Datum wgs84; double latin, lonin, hgtin; double latout, lonout, hgtout; double da = wgs84.ellipsoid()->getA() - ellipsoid()->getA(); double df = wgs84.ellipsoid()->getFlattening() - ellipsoid()->getFlattening(); latin = aPt.latr(); lonin = aPt.lonr(); hgtin = aPt.height(); if(aPt.isHgtNan()) { hgtin = 0.0; } molodenskyShift(ellipsoid()->getA(), da, ellipsoid()->getFlattening(), df, param1(), param2(), param3(), latin, lonin, hgtin, latout, lonout, hgtout); ossimGpt g; g.latr(latout); g.lonr(lonout); g.height(hgtout); g.datum(this); return g; } else { p2 = ossimEcefPoint(p1.x() + theParam1, p1.y() + theParam2, p1.z() + theParam3); } return ossimGpt(p2); // defaults to WGS84 }
ossimApplanixUtmModel::ossimApplanixUtmModel() :theOmega(0.0), thePhi(0.0), theKappa(0.0), theBoreSightTx(0.0), theBoreSightTy(0.0), theBoreSightTz(0.0) { theCompositeMatrix = ossimMatrix4x4::createIdentity(); theCompositeMatrixInverse = ossimMatrix4x4::createIdentity(); theFocalLength = 55.0; thePixelSize = ossimDpt(.009, .009); theEcefPlatformPosition = ossimGpt(0.0,0.0, 1000.0); theGSD.x = 0.1524; theGSD.y = 0.1524; theMeanGSD = 0.1524; theLensDistortion = new ossimMeanRadialLensDistortion; initAdjustableParameters(); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimApplanixUtmModel::ossimApplanixUtmModel DEBUG:" << endl; #ifdef OSSIM_ID_ENABLED ossimNotify(ossimNotifyLevel_DEBUG)<< "OSSIM_ID: " << OSSIM_ID << endl; #endif } }
void ossimPpjFrameSensor::updateModel() { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimPpjFrameSensor::updateModel DEBUG:" << std::endl; } double deltap = computeParameterOffset(PARAM_ADJ_LAT_OFFSET)/ m_cameraPositionEllipsoid.metersPerDegree().y; double deltal = computeParameterOffset(PARAM_ADJ_LON_OFFSET)/ m_cameraPositionEllipsoid.metersPerDegree().x; m_adjustedCameraPosition = ossimGpt(m_cameraPositionEllipsoid.latd() + deltap, m_cameraPositionEllipsoid.lond() + deltal, m_cameraPositionEllipsoid.height() + computeParameterOffset(PARAM_ADJ_ALTITUDE_OFFSET)); // TODO Need to add correction matrix to accommodate orientation offsets. It // shouldn't be done in ECF frame. // double r = ossim::degreesToRadians(m_roll + computeParameterOffset(PARAM_ADJ_ROLL_OFFSET)); // double p = ossim::degreesToRadians(m_pitch + computeParameterOffset(PARAM_ADJ_PITCH_OFFSET) ); // double y = ossim::degreesToRadians(m_yaw + computeParameterOffset(PARAM_ADJ_YAW_OFFSET)); // NEWMAT::Matrix rollM = ossimMatrix3x3::create(1, 0, 0, // 0, cos(r), sin(r), // 0, -sin(r), cos(r)); // NEWMAT::Matrix pitchM = ossimMatrix3x3::create(cos(p), 0, -sin(p), // 0, 1, 0, // sin(p), 0, cos(p)); // NEWMAT::Matrix yawM = ossimMatrix3x3::create(cos(y), sin(y), 0, // -sin(y), cos(y), 0, // 0,0,1); m_adjustedFocalLength = m_focalLength + computeParameterOffset(PARAM_ADJ_FOCAL_LENGTH_OFFSET); try { computeGsd(); } catch(...) { } if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimPpjFrameSensor::updateModel complete..." << std::endl; } /* ossimGpt gpt; lineSampleToWorld(theImageClipRect.ul(),gpt);//+ossimDpt(-w, -h), gpt); theBoundGndPolygon[0] = gpt; lineSampleToWorld(theImageClipRect.ur(),gpt);//+ossimDpt(w, -h), gpt); theBoundGndPolygon[1] = gpt; lineSampleToWorld(theImageClipRect.lr(),gpt);//+ossimDpt(w, h), gpt); theBoundGndPolygon[2] = gpt; lineSampleToWorld(theImageClipRect.ll(),gpt);//+ossimDpt(-w, h), gpt); theBoundGndPolygon[3] = gpt; */ }
ossimMapProjection* ossimKmlSuperOverlayReader::createDefaultProj(ossim_float64 north, ossim_float64 south, ossim_float64 east, ossim_float64 west) { ossimEquDistCylProjection* proj = new ossimEquDistCylProjection; ossim_float64 centerLat = (south + north) / 2.0; ossim_float64 centerLon = (west + east) / 2.0; ossim_float64 deltaLat = north - south; // Scale that gives 1024 pixel in the latitude direction. ossim_float64 scaleLat = deltaLat / 1024.0; ossim_float64 scaleLon = scaleLat*ossim::cosd(std::fabs(centerLat)); ossimGpt origin(centerLat, centerLon, 0.0); ossimDpt scale(scaleLon, scaleLat); // Set the origin. proj->setOrigin(origin); // Set the tie point. proj->setUlGpt( ossimGpt(north, west)); // Set the scale. Note this will handle computing meters per pixel. proj->setDecimalDegreesPerPixel(scale); return proj; }
void ImageViewManipulator::setViewToChains() { if(m_scrollView&&m_scrollView->connectableObject()) { ossimDpt center; ossimImageGeometry* geom = asGeometry(); if(geom) { geom->worldToLocal(ossimGpt(m_centerPoint.lat, m_centerPoint.lon), center); } else { ossimImageViewAffineTransform* ivat = getObjectAs<ossimImageViewAffineTransform>(); if(ivat) { if(!m_centerPoint.hasNans()) { ivat->imageToView(m_centerPoint,center); } } } SetViewVisitor viewVisitor(m_obj.get()); viewVisitor.setViewPoint(center); m_scrollView->connectableObject()->accept(viewVisitor); // just in case if an update causes a change in center let's keep our locked // center point for zooming in and out. ossimDpt saveCenter = m_centerPoint; viewVisitor.setView(); m_centerPoint = saveCenter; } }
void ossimNitfProjectionFactory::parseDecimalDegreesString(const ossimString& geographicLocation, std::vector<ossimGpt>& gpts) const { const char* bufPtr = geographicLocation.c_str(); ossimString ulLat(bufPtr, bufPtr + 7); bufPtr+=7; ossimString ulLon(bufPtr, bufPtr+8); bufPtr+=8; ossimString urLat(bufPtr, bufPtr + 7); bufPtr+=7; ossimString urLon(bufPtr, bufPtr+8); bufPtr+=8; ossimString lrLat(bufPtr, bufPtr + 7); bufPtr+=7; ossimString lrLon(bufPtr, bufPtr+8); bufPtr+=8; ossimString llLat(bufPtr, bufPtr + 7); bufPtr+=7; ossimString llLon(bufPtr, bufPtr+8); gpts.push_back(ossimGpt(ulLat.toDouble(), ulLon.toDouble())); gpts.push_back(ossimGpt(urLat.toDouble(), urLon.toDouble())); gpts.push_back(ossimGpt(lrLat.toDouble(), lrLon.toDouble())); gpts.push_back(ossimGpt(llLat.toDouble(), llLon.toDouble())); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfProjectionFactory::parseDecimalDegreesString DEBUG:" << "\nground point[" << 0 << "]: " << gpts[0] << "\nground point[" << 1 << "]: " << gpts[1] << "\nground point[" << 2 << "]: " << gpts[2] << "\nground point[" << 3 << "]: " << gpts[3] << std::endl; } }
//************************************************************************************************* //! When the CRS is specified with the "AUTO:<spec>" code format, this method is invoked to //! parse the <spec> and produce a projection (or NULL if spec invalid): //************************************************************************************************* ossimMapProjection* ossimEpsgProjectionFactory::createProjFromAutoCode(const std::vector<ossimString>& spec) const { if (spec.size() != 4) return 0; ossim_uint32 code = spec[0].toUInt32(); ossimGpt origin (spec[3].toDouble(), spec[2].toDouble()) ; // Only a few AUTO codes are considered: switch(code) { case 42001: { ossimUtmProjection* utm = new ossimUtmProjection; utm->setZone(origin); utm->setHemisphere(origin); utm->setOrigin(origin); utm->update(); utm->setPcsCode(42001); return utm; } case 42002: { ossimTransMercatorProjection* transMerc = new ossimTransMercatorProjection; transMerc->setFalseNorthing(origin.latd()>=0.0?0.0:10000000.0); transMerc->setOrigin(ossimGpt(0.0, origin.lond())); transMerc->setScaleFactor(.9996); transMerc->update(); transMerc->setPcsCode(42002); return transMerc; } case 42003: { ossimOrthoGraphicProjection* ortho = new ossimOrthoGraphicProjection; ortho->setOrigin(origin); ortho->update(); ortho->setPcsCode(42003); return ortho; } case 42004: { ossimEquDistCylProjection* geographic = new ossimEquDistCylProjection; geographic->setOrigin(origin); geographic->update(); geographic->setPcsCode(42004); return geographic; } } return 0; }
ossimGpt ossimVanDerGrintenProjection::inverse(const ossimDpt &eastingNorthing)const { double lat = 0.0; double lon = 0.0; Convert_Van_der_Grinten_To_Geodetic(eastingNorthing.x, eastingNorthing.y, &lat, &lon); return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0.0, theDatum); }
ossimGpt ossimGeoPolygon::computeCentroid()const { if(!size()) { return ossimGpt(); } ossimDpt average(0.0,0.0); double height=0.0; for(ossim_uint32 i = 0; i < size(); ++i) { average += ossimDpt(theVertexList[i]); height += theVertexList[i].height(); } average.x /= size(); average.y /= size(); height /= size(); return ossimGpt(average.y, average.x, height, theVertexList[0].datum()); }
ossimGpt ossimCassiniProjection::inverse(const ossimDpt &eastingNorthing)const { double lat = 0.0; double lon = 0.0; Convert_Cassini_To_Geodetic(eastingNorthing.x, eastingNorthing.y, &lat, &lon); return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0, theDatum); }
ossimGpt ossimTransCylEquAreaProjection::inverse(const ossimDpt &eastingNorthing)const { double lat = 0.0; double lon = 0.0; Convert_Trans_Cyl_Eq_Area_To_Geodetic(eastingNorthing.x, eastingNorthing.y, &lat, &lon); return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0.0, theDatum); }
ossimGpt ossimEquDistCylProjection::inverse(const ossimDpt &eastingNorthing)const { double lat = 0.0; double lon = 0.0; Convert_Equidistant_Cyl_To_Geodetic(eastingNorthing.x, eastingNorthing.y, &lat, &lon); return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0.0, theDatum); }
//************************************************************************************************** // This is the principal factory method. It accepts a string in format: // // <group>:<code>, for example "NGA:235" (Currently only code supported, used in GeoPackage) // // IMPORTANT NOTE: Image tie-points cannot be conveyed by a projection code. The projection // created here will not be fully initialized for use in rendering imagery. //************************************************************************************************** ossimProjection* ossimNgaProjectionFactory::createProjection(const ossimString& spec) const { ossimProjection* proj = 0; if ((!ossimString(spec).downcase().contains("nga")) && (spec.after(":").toInt() == 235)) { const ossimEllipsoid* e = ossimEllipsoidFactory::instance()->create("WE"); proj = new ossimMercatorProjection(*e, ossimGpt(0,0), 0, 0, 0.857385503731176); } return proj; }
ossimBuckeyeSensor::ossimBuckeyeSensor() { if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimBuckeyeSensor::ossimBuckeyeSensor(): entering..." << std::endl; theCompositeMatrix = ossimMatrix4x4::createIdentity(); theCompositeMatrixInverse = ossimMatrix4x4::createIdentity(); theRoll = 0.0; thePitch = 0.0; theHeading = 0.0; theFocalLength = 195.1000; thePixelSize = ossimDpt(.006, .006); thePrincipalPoint = ossimDpt(0, 0); theEcefPlatformPosition = ossimGpt(0.0,0.0, 1000.0); theAdjEcefPlatformPosition = ossimGpt(0.0,0.0, 1000.0); theLensDistortion = new ossimSmacCallibrationSystem(); theGSD.makeNan(); initAdjustableParameters(); if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimBuckeyeSensor::ossimBuckeyeSensor(): returning..." << std::endl; }
ossimGpt ossimLambertConformalConicProjection::inverse(const ossimDpt &eastingNorthing)const { double lat = 0.0; double lon = 0.0; Convert_Lambert_To_Geodetic(eastingNorthing.x, eastingNorthing.y, &lat, &lon); return ossimGpt(lat*DEG_PER_RAD, lon*DEG_PER_RAD, 0.0, theDatum); }
ossimGpt ossimNadconNarDatum::shift(const ossimGpt &aPt)const { const ossimDatum* datum = aPt.datum(); ossimString code = datum->code(); ossimString subCode(code.begin(), code.begin() + 3); if(subCode == "NAR") { return aPt; } else { if(subCode == "NAS") { checkGrid(aPt); if(!theLatGrid.getFileOkFlag()|| !theLonGrid.getFileOkFlag()) { return ossimThreeParamDatum::shift(aPt); } double shiftLat = theLatGrid.getShiftAtLatLon(aPt.latd(), aPt.lond()); double shiftLon = theLonGrid.getShiftAtLatLon(aPt.latd(), aPt.lond()); if( (ossim::isnan(shiftLat)) || (ossim::isnan(shiftLon)) ) { return ossimThreeParamDatum::shift(aPt); } else { // Note the shifts are stored in the file // as seconds. // // convert the seconds into decimal degrees. // shiftLat /= 3600.0; shiftLon /= 3600.0; return ossimGpt(aPt.latd() + shiftLat, aPt.lond() - shiftLon, aPt.height(), this); } } else { return ossimThreeParamDatum::shift(aPt); } } return ossimThreeParamDatum::shift(aPt); }
ossimGpt ossimThreeParamDatum::shift(const ossimGpt &aPt)const { const ossimDatum *aDatum = aPt.datum(); if( code() == aDatum->code()) { return ossimGpt(aPt.latd(), aPt.lond(), aPt.height(), this); } if(aDatum) { return shiftFromWgs84(aDatum->shiftToWgs84(aPt)); } return aPt; }
void ossimPpjFrameSensor::lineSampleHeightToWorld(const ossimDpt& imagePoint, const double& heightEllipsoid, ossimGpt& worldPt) const { ossimEcefRay ray; imagingRay(imagePoint, ray); double h = (ossim::isnan(heightEllipsoid)||ossim::almostEqual(heightEllipsoid, 0.0))?m_averageProjectedHeight:heightEllipsoid; ossimEcefPoint pecf(ray.intersectAboveEarthEllipsoid(h)); worldPt = ossimGpt(pecf); if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimPpjFrameSensor::lineSampleHeightToWorld DEBUG:" << std::endl; ossimNotify(ossimNotifyLevel_DEBUG) << " imagePoint = " << imagePoint << std::endl; ossimNotify(ossimNotifyLevel_DEBUG) << " heightEllipsoid = " << heightEllipsoid << std::endl; ossimNotify(ossimNotifyLevel_DEBUG) << " ray = " << ray << std::endl; ossimNotify(ossimNotifyLevel_DEBUG) << " worldPt = " << worldPt << std::endl; } }
void ossimSpectraboticsRedEdgeModel::lineSampleHeightToWorld(const ossimDpt& image_point, const double& heightEllipsoid, ossimGpt& worldPoint) const { // if (!insideImage(image_point)) // { // worldPoint.makeNan(); // worldPoint = extrapolate(image_point, heightEllipsoid); // } // else { //*** // First establish imaging ray from image point: //*** ossimEcefRay ray; imagingRay(image_point, ray); ossimEcefPoint Pecf (ray.intersectAboveEarthEllipsoid(heightEllipsoid)); worldPoint = ossimGpt(Pecf); } }
void ossimBuckeyeSensor::lineSampleHeightToWorld(const ossimDpt& image_point, const double& heightEllipsoid, ossimGpt& worldPoint) const { if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimBuckeyeSensor::lineSampleHeightToWorld: entering..." << std::endl; if (!insideImage(image_point)) { worldPoint.makeNan(); } else { //*** // First establish imaging ray from image point: //*** ossimEcefRay ray; imagingRay(image_point, ray); ossimEcefPoint Pecf (ray.intersectAboveEarthEllipsoid(heightEllipsoid)); worldPoint = ossimGpt(Pecf); } if (traceDebug()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimBuckeyeSensor::lineSampleHeightToWorld: returning..." << std::endl; }
bool ossimGeoPolygon::loadState(const ossimKeywordlist& kwl, const char* prefix) { const char* number_vertices = kwl.find(prefix, NUMBER_VERTICES_KW); ossimString datumStr = kwl.find(prefix, ossimKeywordNames::DATUM_KW); const ossimDatum* datum = ossimDatumFactoryRegistry::instance()->create(datumStr); theVertexList.clear(); int i = 0; int vertexCount = ossimString(number_vertices).toLong(); ossimString lat, lon, height; for(i = 0; i < vertexCount; ++i) { ossimString v = kwl.find(prefix, (ossimString("v")+ossimString::toString(i)).c_str()); ossimString latString, lonString, heightString; v = v.trim(); std::istringstream in(v); in>>lat>>lon>>height; theVertexList.push_back(ossimGpt(lat.toDouble(), lon.toDouble(), height.toDouble(), datum)); } return true; }
int main(int argc, char* argv[]) { ossimInit::instance()->initialize(argc, argv); ossimString tempString; ossimString tempString2; osg::ArgumentParser::Parameter stringParam(tempString); osg::ArgumentParser::Parameter stringParam2(tempString2); osg::ArgumentParser arguments(&argc,argv); arguments.getApplicationUsage()->addCommandLineOption("--video", "specify the input video to process"); arguments.getApplicationUsage()->addCommandLineOption("--animation-path-out", "specify the filename to output the animation path to"); arguments.getApplicationUsage()->addCommandLineOption("--test-sensor-projection", "Test sensor projection from KlvInfo"); unsigned int helpType = 0; if ((helpType = arguments.readHelpType())) { arguments.getApplicationUsage()->write(std::cout, helpType); return 1; } while(arguments.read("--video", stringParam)) { if(arguments.read("--test-sensor-projection")) { ossimRefPtr<ossimPredatorUavProjection> proj = new ossimPredatorUavProjection; ossimRefPtr<ossimPredatorVideo> predatorVideo = new ossimPredatorVideo(); if(predatorVideo->open(ossimFilename(tempString))) { ossim_uint32 imageWidth = predatorVideo->imageWidth(); ossim_uint32 imageHeight = predatorVideo->imageHeight(); ossimRefPtr<ossimPredatorVideo::KlvInfo> klvinfo; ossim_float64 prevTime = -1.0; while(( klvinfo = predatorVideo->nextKlv()).valid()) { ossim_float64 lat,lon,elev; ossim_float32 hfov; ossim_float32 vfov; ossim_float32 h,p,r; ossim_float32 obliquityAngle; ossim_float32 angleToNorth; ossim_float32 slantRange; ossim_float32 sensorRoll = 0.0; klvinfo->table()->print(std::cout) << std::endl; if(klvinfo->table()->getSensorPosition(lat, lon, elev)&& klvinfo->table()->getPlatformOrientation(h,p,r)) { if(!klvinfo->table()->getObliquityAngle(obliquityAngle)) { obliquityAngle = 0.0; } if(!klvinfo->table()->getSlantRange(slantRange)) { slantRange = 1.0; } bool gotHfov = true; if(!klvinfo->table()->getHorizontalFieldOfView(hfov)) { hfov = 1.0; gotHfov = false; } if(!klvinfo->table()->getVerticalFieldOfView(vfov)) { vfov = hfov; } else if(!gotHfov) { hfov = vfov; } klvinfo->table()->getSensorRollAngle(sensorRoll); if(!klvinfo->table()->getAngleToNorth(angleToNorth)) { angleToNorth = 0.0; } ossim_float64 value = ossimGeoidManager::instance()->offsetFromEllipsoid(ossimGpt(lat, lon, elev)); if(!ossim::isnan(value)) { elev += value; } proj->setParameters(imageWidth, imageHeight, ossimGpt(lat, lon, elev), ossimGpt(), h, p, sensorRoll, hfov, vfov, obliquityAngle, angleToNorth, 0.0, 0.0); ossimDpt ipt(imageWidth*.5, imageHeight*.5); ossimGpt centerProj; ossimGpt ul; ossimGpt ur; ossimGpt lr; ossimGpt ll; proj->lineSampleToWorld(ipt, centerProj); proj->lineSampleToWorld(ossimDpt(0,0), ul); proj->lineSampleToWorld(ossimDpt(imageWidth,0), ur); proj->lineSampleToWorld(ossimDpt(imageWidth,imageHeight), lr); proj->lineSampleToWorld(ossimDpt(imageHeight,0), ll); std::cout << std::setprecision(15); std::cout << "position = " << ossimGpt(lat, lon, elev) << std::endl; std::cout << "centerGpt = " << centerProj << std::endl; std::cout << "ul = " << ul << std::endl; std::cout << "ur = " << ur << std::endl; std::cout << "lr = " << lr << std::endl; std::cout << "ll = " << ll << std::endl; // std::cout << "angle to north = " << angleToNorth << std::endl; // std::cout << "ObliquityAngle = " << obliquityAngle << std::endl; // std::cout << "hpr = " << h << ", " << p << ", " << r << std::endl; // std::cout << "Platform = " << ossimGpt(lat, lon, elev) << std::endl; // std::cout << "World point = " << centerProj << std::endl; if(klvinfo->table()->getFrameCenter(lat, lon, elev)) { std::cout << "Center frame = " << ossimGpt(lat, lon, elev) << std::endl; } } } } } if(arguments.read("--animation-path-out", stringParam2)) { std::ofstream out(tempString2.c_str()); if(out.good()) { out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; out << "<AnimationPath>"; out << "<GeospatialPath timeUnit='seconds' positionType='latlonhgt' orientationType='lsrhpr'>"; out << "<description>Cool path</description>"; out << "<coordinates>"; ossimRefPtr<ossimPredatorVideo> predatorVideo = new ossimPredatorVideo(); if(predatorVideo->open(ossimFilename(tempString))) { ossim_float32 srange; ossimRefPtr<ossimPredatorVideo::KlvInfo> klvinfo; ossim_float64 prevTime = -1.0; while(( klvinfo = predatorVideo->nextKlv()).valid()) { klvinfo->table()->getSlantRange(srange); //std::cout << "range === " << srange << std::endl; if(!ossim::almostEqual(klvinfo->time(), prevTime, 1e-10)) { prevTime = klvinfo->time(); ossimString sensorLat, sensorLon, sensorAlt, h,p,r; if(klvinfo->table()->valueAsString(sensorLat, KLV_KEY_SENSOR_LATITUDE)&& klvinfo->table()->valueAsString(sensorLon, KLV_KEY_SENSOR_LONGITUDE)&& klvinfo->table()->valueAsString(sensorAlt, KLV_KEY_SENSOR_TRUE_ALTITUDE)) { klvinfo->table()->valueAsString(h,KLV_KEY_PLATFORM_HEADING_ANGLE); klvinfo->table()->valueAsString(p,KLV_KEY_PLATFORM_PITCH_ANGLE); klvinfo->table()->valueAsString(r,KLV_KEY_PLATFORM_ROLL_ANGLE); double headingAdjust = h.toDouble(); if(headingAdjust > 180.0) headingAdjust -= 360.0; out << klvinfo->time() << "," << sensorLat <<"," << sensorLon << "," <<sensorAlt.toDouble()*0.304801 << "," << headingAdjust << "," << p.toDouble() << "," << r.toDouble() <<std::endl; } } } } out << "</coordinates></GeospatialPath></AnimationPath>"; } } } }
ossimRefPtr<ossimProjection> ossimFgdcXmlDoc::getGridCoordSysProjection() { static const char M[] = "ossimFgdcXmlDoc::getGridCoordSysProjection"; if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << M << " entered...\n"; } if ( m_projection.valid() == false ) { ossimString s; if ( getGridCoordinateSystem(s) ) { ossimString gridsysn = s.downcase(); if ( getHorizontalDatum(s) ) { ossimString horizdn = s.downcase(); const ossimDatum* datum = createOssimDatum(s); // throws exception if ( gridsysn == "universal transverse mercator" ) { // Get the zone: if ( getUtmZone(s) ) { ossim_int32 zone = s.toInt32(); //--- // Note: Contruct with an origin with our datum. // "proj->setDatum" does not change the origin's datum. // This ensures theossimEpsgProjectionDatabase::findProjectionCode // sets the psc code correctly down the line. //--- ossimRefPtr<ossimUtmProjection> utmProj = new ossimUtmProjection( *(datum->ellipsoid()), ossimGpt(0.0,0.0,0.0,datum) ); utmProj->setDatum(datum); utmProj->setZone(zone); // Hemisphere( North false easting = 0.0, South = 10000000): bool tmpResult = getUtmFalseNorthing(s); if ( tmpResult && ( s != "0.0" ) ) { utmProj->setHemisphere('S'); } else { utmProj->setHemisphere('N'); } utmProj->setPcsCode(0); ossim_float64 xRes = 0.0; ossim_float64 yRes = 0.0; if (getXRes(xRes) && getYRes(yRes)) { ossimDrect rect; getBoundingBox(rect); ossimDpt gsd(std::fabs(xRes), std::fabs(yRes)); ossimUnitType unitType = getUnitType(); if (m_boundInDegree) { ossimGpt tieg(rect.ul().lat, rect.ul().lon); utmProj->setUlTiePoints(tieg); } else { ossimDpt tie(rect.ul().x, rect.ul().y); if ( unitType == OSSIM_US_SURVEY_FEET) { tie = tie * US_METERS_PER_FT; } else if ( unitType == OSSIM_FEET ) { tie = tie * MTRS_PER_FT; } utmProj->setUlTiePoints(tie); } if ( unitType == OSSIM_US_SURVEY_FEET) { gsd = gsd * US_METERS_PER_FT; } else if ( unitType == OSSIM_FEET ) { gsd = gsd * MTRS_PER_FT; } utmProj->setMetersPerPixel(gsd); } m_projection = utmProj.get(); // Capture projection. } else { std::string errMsg = M; errMsg += " ERROR: Could not determine utm zone!"; throw ossimException(errMsg); } } } } } if ( traceDebug() ) { if ( m_projection.valid() ) { m_projection->print(ossimNotify(ossimNotifyLevel_DEBUG)); } ossimNotify(ossimNotifyLevel_DEBUG) << M << " exiting...\n"; } return m_projection; }
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; }
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; }
//***************************************************************************** // METHOD: intersectRay() // // Service method for intersecting a ray with the elevation surface to // arrive at a ground point. The ray is expected to originate ABOVE the // surface and pointing down. // // NOTE: the gpt argument is expected to be initialized with the desired // datum, including ellipsoid, for the proper intersection point to be // computed. // // LIMITATION: This release supports only single valued solutions, i.e., it // is possible a ray passing through one side of a mountain and out the other // will return an intersection with the far side. Eventually, a more robust // algorithm will be employed. // //***************************************************************************** bool ossimElevSource::intersectRay(const ossimEcefRay& ray, ossimGpt& gpt, double defaultElevValue) { if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimElevSource::intersectRay: entering..." << std::endl; static const double CONVERGENCE_THRESHOLD = 0.001; // meters static const int MAX_NUM_ITERATIONS = 50; double h_ellips; // height above ellipsoid bool intersected; ossimEcefPoint prev_intersect_pt (ray.origin()); ossimEcefPoint new_intersect_pt; double distance; bool done = false; int iteration_count = 0; if(ray.hasNans()) { gpt.makeNan(); return false; } //*** // Set the initial guess for horizontal intersect position as the ray's // origin, and establish the datum and ellipsoid: //*** const ossimDatum* datum = gpt.datum(); const ossimEllipsoid* ellipsoid = datum->ellipsoid(); // double lat, lon, h; // ellipsoid->XYZToLatLonHeight(ray.origin().x(), // ray.origin().y(), // ray.origin().z(), // lat, lon, h); // ossimGpt nadirGpt(lat, lon, h); // std::cout << "nadir pt = " << nadirGpt << std::endl; gpt = ossimGpt(prev_intersect_pt, datum); // // Loop to iterate on ray intersection with variable elevation surface: // do { // // Intersect ray with ellipsoid inflated by h_ellips: // h_ellips = getHeightAboveEllipsoid(gpt); if ( ossim::isnan(h_ellips) ) h_ellips = defaultElevValue; intersected = ellipsoid->nearestIntersection(ray, h_ellips, new_intersect_pt); if (!intersected) { // // No intersection (looking over the horizon), so set ground point // to NaNs: // gpt.makeNan(); done = true; } else { // // Assign the ground point to the latest iteration's intersection // point: // gpt = ossimGpt(new_intersect_pt, datum); // // Determine if convergence achieved: // distance = (new_intersect_pt - prev_intersect_pt).magnitude(); if (distance < CONVERGENCE_THRESHOLD) done = true; else { prev_intersect_pt = new_intersect_pt; } } iteration_count++; } while ((!done) && (iteration_count < MAX_NUM_ITERATIONS)); if (iteration_count == MAX_NUM_ITERATIONS) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_WARN) << "WARNING ossimElevSource::intersectRay: Max number of iterations reached solving for ground " << "point. Result is probably inaccurate." << std::endl; } } if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimElevSource::intersectRay: returning..." << std::endl; return intersected; }
bool ossimAuxXmlSupportData::initializeProjection( const ossimXmlDocument xdoc, const std::string& wkt, ossimProjection* proj ) const { bool result = false; ossimRefPtr<ossimMapProjection> mapProj = dynamic_cast<ossimMapProjection*>( proj ); if ( mapProj.valid() ) { // Find the tie and scale. ossimString path = "/PAMDataset/Metadata/MDI"; std::vector<ossimRefPtr<ossimXmlNode> > xnodes; xdoc.findNodes(path, xnodes); if ( xnodes.size() ) { ossimDpt tie; ossimDpt scale; tie.makeNan(); scale.makeNan(); for ( ossim_uint32 i = 0; i < xnodes.size(); ++i ) { if ( xnodes[i].valid() ) { ossimString value; ossimString attrName = "key"; ossimRefPtr<ossimXmlAttribute> attr = xnodes[i]->findAttribute( attrName ); if ( attr.valid() ) { if (attr->getValue() == "IMAGE__XY_ORIGIN" ) { value = xnodes[i]->getText(); if ( value.size() ) { // Split it: std::vector<ossimString> list; value.split( list, ossimString(","), true ); if ( list.size() == 2 ) { if ( list[0].size() ) { tie.x = list[0].toFloat64(); } if ( list[1].size() ) { tie.y = list[1].toFloat64(); } } } } else if (attr->getValue() == "IMAGE__X_RESOLUTION" ) { value = xnodes[i]->getText(); if ( value.size() ) { scale.x = value.toFloat64(); } } else if (attr->getValue() == "IMAGE__Y_RESOLUTION" ) { value = xnodes[i]->getText(); if ( value.size() ) { scale.y = value.toFloat64(); } } } } // Matches: if ( xnodes[i].valid() ) } // Matches: for ( ossim_uint32 i = 0; i < xnodes.size(); ++i ) if ( !tie.hasNans() && !scale.hasNans() ) { if ( mapProj->isGeographic() ) { // Assuming tie and scale in decimal degrees: mapProj->setDecimalDegreesPerPixel( scale ); ossimGpt gpt(tie.y, tie.x, 0.0); mapProj->setUlTiePoints( ossimGpt( gpt ) ); result = true; } else { // Get the units: ossimUnitType units = getUnits( wkt ); // Convert to meters: result = true; if ( units != OSSIM_METERS ) { if ( units == OSSIM_FEET ) { tie.x = tie.x * MTRS_PER_FT; tie.y = tie.y * MTRS_PER_FT; scale.x = scale.x * MTRS_PER_FT; scale.y = scale.y * MTRS_PER_FT; } else if ( units == OSSIM_US_SURVEY_FEET) { tie.x = tie.x * US_METERS_PER_FT; tie.y = tie.y * US_METERS_PER_FT; scale.x = scale.x * OSSIM_US_SURVEY_FEET; scale.y = scale.y * OSSIM_US_SURVEY_FEET; } else { ossimNotify(ossimNotifyLevel_WARN) << "ossimAuxXmlSupportData::initializeProjection WARNING: " << "Unhandled unit type: " << units << std::endl; result = false; } } if ( result ) { mapProj->setMetersPerPixel( scale ); mapProj->setUlTiePoints( tie ); } } } } // Matches: if ( xnodes.size() ) } return result; } // ossimAuxXmlSupportData::initializeProjection