18 static ossimTrace traceDebug(
"ossimBuckeyeSensor:debug");
22 ossimBuckeyeSensor::ossimBuckeyeSensor()
33 thePrincipalPoint =
ossimDpt(0.0, 0.0);
34 theEcefPlatformPosition =
ossimGpt(0.0, 0.0, 0.0);
35 theAdjEcefPlatformPosition =
ossimGpt(0.0, 0.0, 0.0);
39 initAdjustableParameters();
43 ossimBuckeyeSensor::ossimBuckeyeSensor(
const ossimDrect& imageRect,
52 if (traceDebug())
ossimNotify(
ossimNotifyLevel_DEBUG) <<
"DEBUG ossimBuckeyeSensor::ossimBuckeyeSensor(imageRect,platformPosition,roll,pitch,heading,ossimDpt,focalLength,pixelSize): entering..." << std::endl;
54 theImageClipRect = imageRect;
55 theRefImgPt = theImageClipRect.
midPoint();
61 theFocalLength = focalLength;
62 thePixelSize = pixelSize;
63 theEcefPlatformPosition = platformPosition;
64 theAdjEcefPlatformPosition = platformPosition;
68 initAdjustableParameters();
71 if (traceDebug())
ossimNotify(
ossimNotifyLevel_DEBUG) <<
"DEBUG ossimBuckeyeSensor::ossimBuckeyeSensor(imageRect,platformPosition,roll,pitch,heading,ossimDpt,focalLength,pixelSize): returning..." << std::endl;
74 ossimBuckeyeSensor::ossimBuckeyeSensor(
const ossimBuckeyeSensor& src)
79 initAdjustableParameters();
81 if(src.theLensDistortion.valid())
96 return new ossimBuckeyeSensor(*
this);
99 void ossimBuckeyeSensor::imagingRay(
const ossimDpt& image_point,
104 ossimDpt f1 ((image_point) - theRefImgPt);
105 f1.x *= thePixelSize.x;
106 f1.y *= -thePixelSize.y;
107 ossimDpt film (f1 - thePrincipalPoint);
116 if (theLensDistortion.valid())
119 theLensDistortion->undistort(film, filmOut);
127 ecf_ray_dir = ecf_ray_dir*(1.0/ecf_ray_dir.magnitude());
129 image_ray.
setOrigin(theAdjEcefPlatformPosition);
135 void ossimBuckeyeSensor::lineSampleToWorld(
const ossimDpt& image_point,
152 imagingRay(image_point, ray);
166 void ossimBuckeyeSensor::lineSampleHeightToWorld(
const ossimDpt& image_point,
167 const double& heightEllipsoid,
171 if (!insideImage(image_point))
181 imagingRay(image_point, ray);
188 void ossimBuckeyeSensor::worldToLineSample(
const ossimGpt& world_point,
192 if((theBoundGndPolygon.getNumberOfVertices() > 0)&&
193 (!theBoundGndPolygon.hasNans()))
195 if (!(theBoundGndPolygon.pointWithin(world_point)))
206 double scale = -theFocalLength/camRayDir[2];
207 ossimDpt film (scale*camRayDir[0], scale*camRayDir[1]);
209 if (theLensDistortion.valid())
212 theLensDistortion->distort(film, filmOut);
216 ossimDpt f1(film + thePrincipalPoint);
218 -f1.y/thePixelSize.y);
221 p1.y + theRefImgPt.y);
227 void ossimBuckeyeSensor::updateModel()
233 double degreePerMeter = 1.0/metersPerDegree;
234 double latShift = -computeParameterOffset(1)*degreePerMeter;
235 double lonShift = computeParameterOffset(0)*degreePerMeter;
237 gpt = theEcefPlatformPosition;
238 double height = gpt.
height();
239 gpt.
height(height + computeParameterOffset(5));
242 theAdjEcefPlatformPosition = gpt;
243 ossimLsrSpace lsrSpace(theAdjEcefPlatformPosition, theHeading+computeParameterOffset(4));
249 theCompositeMatrix = (lsrMatrix.getData()*orientation);
250 theCompositeMatrixInverse = theCompositeMatrix.
i();
252 theBoundGndPolygon.resize(4);
254 theExtrapolateImageFlag =
false;
255 theExtrapolateGroundFlag =
false;
265 <<
"ossimBuckeyeSensor Constructor caught Exception:\n" 266 << e.
what() << std::endl;
269 lineSampleToWorld(theImageClipRect.ul(),gpt);
270 theBoundGndPolygon[0] = gpt;
271 lineSampleToWorld(theImageClipRect.ur(),gpt);
272 theBoundGndPolygon[1] = gpt;
273 lineSampleToWorld(theImageClipRect.lr(),gpt);
274 theBoundGndPolygon[2] = gpt;
275 lineSampleToWorld(theImageClipRect.ll(),gpt);
276 theBoundGndPolygon[3] = gpt;
280 void ossimBuckeyeSensor::initAdjustableParameters()
283 resizeAdjustableParameterArray(6);
285 setAdjustableParameter(0, 0.0);
286 setParameterDescription(0,
"x_offset");
287 setParameterUnit(0,
"pixels");
289 setAdjustableParameter(1, 0.0);
290 setParameterDescription(1,
"y_offset");
291 setParameterUnit(1,
"pixels");
293 setAdjustableParameter(2, 0.0);
294 setParameterDescription(2,
"roll");
295 setParameterUnit(2,
"degrees");
297 setAdjustableParameter(3, 0.0);
298 setParameterDescription(3,
"pitch");
299 setParameterUnit(3,
"degrees");
301 setAdjustableParameter(4, 0.0);
302 setParameterDescription(4,
"heading");
303 setParameterUnit(4,
"degrees");
305 setAdjustableParameter(5, 0.0);
306 setParameterDescription(5,
"altitude");
307 setParameterUnit(5,
"meters");
310 setParameterSigma(0, 1.0);
311 setParameterSigma(1, 1.0);
312 setParameterSigma(2, 0);
313 setParameterSigma(3, 0);
314 setParameterSigma(4, 0);
315 setParameterSigma(5, 1000);
321 theLensDistortion = lensDistortion;
326 const char* prefix)
const 331 kwl.
add(prefix,
"type",
"ossimBuckeyeSensor",
true);
333 kwl.
add(prefix,
"roll", theRoll,
true);
334 kwl.
add(prefix,
"pitch", thePitch,
true);
335 kwl.
add(prefix,
"heading", theHeading,
true);
338 kwl.
add(prefix,
"focal_length", theFocalLength);
339 kwl.
add(prefix,
"ecef_platform_position",
344 if(theLensDistortion.valid())
347 theLensDistortion->saveState(kwl,
363 if ( theRefImgPt ==
ossimDpt(0, 0) )
365 theRefImgPt = theImageClipRect.midPoint();
368 if(getNumberOfAdjustableParameters() < 1)
370 initAdjustableParameters();
396 if (framemeta_gsti.
empty() && !framemeta.
empty() && !frame_number.
empty())
398 file_to_load.
setFile(framemeta);
399 YAW_STRING =
"Azimuth(deg)";
401 else if (!framemeta_gsti.
empty() && framemeta.
empty() && !frame_number.
empty())
403 file_to_load.
setFile(framemeta_gsti);
406 if (file_to_load.
exists() && !frame_number.
empty())
409 if(csv.open(file_to_load))
415 if (std::find(heads.begin(), heads.end(), FRAME_STRING) == heads.end())
417 FRAME_STRING = FRAME_STRING.
upcase();
418 ROLL_STRING = ROLL_STRING.
upcase();
419 PITCH_STRING = PITCH_STRING.
upcase();
420 YAW_STRING = YAW_STRING.
upcase();
421 LAT_STRING = LAT_STRING.
upcase();
422 LON_STRING = LON_STRING.
upcase();
423 HAE_STRING = HAE_STRING.
upcase();
427 bool foundFrameNumber =
false;
428 while( ((record = csv.nextRecord()).valid()) && !foundFrameNumber)
430 if( (*record)[FRAME_STRING] == frame_number)
432 foundFrameNumber =
true;
433 roll = (*record)[ROLL_STRING];
434 pitch = (*record)[PITCH_STRING];
435 yaw = (*record)[YAW_STRING];
436 platform_position = (*record)[LAT_STRING] +
" " 437 + (*record)[LON_STRING]+
" " 438 + (*record)[HAE_STRING] +
" WGE";
447 roll = kwl.
find(prefix,
"roll");
448 pitch = kwl.
find(prefix,
"pitch");
449 yaw = kwl.
find(prefix,
"heading");
450 platform_position = kwl.
find(prefix,
"ecef_platform_position");
453 bool result = (!pixel_size.
empty()&&
454 !principal_point.
empty()&&
455 !focal_length.
empty()&&
456 !platform_position.
empty());
458 if(!focal_length.
empty())
460 theFocalLength = focal_length.
toDouble();
462 if(!pixel_size.
empty())
464 thePixelSize.toPoint(pixel_size);
478 if(!principal_point.
empty())
480 thePrincipalPoint.toPoint(principal_point);
482 if(platform_position.
contains(
"WGE"))
484 std::vector<ossimString> splitString;
487 std::string datumString;
488 double lat=0.0, lon=0.0, h=0.0;
489 if(splitString.size() > 2)
491 lat = splitString[0].toDouble();
492 lon = splitString[1].toDouble();
493 h = splitString[2].toDouble();
496 theEcefPlatformPosition =
ossimGpt(lat,lon,h);
498 std::vector<ossimString> splitString;
501 std::string datumString;
502 double x=0.0,
y=0.0, z=0.0;
503 if(splitString.size() > 2)
505 x = splitString[0].toDouble();
506 y = splitString[1].toDouble();
507 z = splitString[2].toDouble();
511 theLensDistortion = 0;
512 if(!smac_radial.
empty()&&
513 !smac_decent.
empty())
515 std::vector<ossimString> radial;
516 std::vector<ossimString> decent;
517 smac_radial.
split(radial,
" ");
518 smac_decent.
split(decent,
" ");
519 if((radial.size() == 5)&&
520 (decent.size() == 4))
523 double k0 = radial[0].toDouble();
524 double k1 = radial[1].toDouble();
525 double k2 = radial[2].toDouble();
526 double k3 = radial[3].toDouble();
527 double k4 = radial[4].toDouble();
529 double p0 = decent[0].toDouble();
530 double p1 = decent[1].toDouble();
531 double p2 = decent[2].toDouble();
532 double p3 = decent[3].toDouble();
537 theImageSize =
ossimDpt(theImageClipRect.width(),
538 theImageClipRect.height());
546 bool ossimBuckeyeSensor::setupOptimizer(
const ossimString& init_file)
551 return loadState(kwl);
554 void ossimBuckeyeSensor::setPrincipalPoint(
ossimDpt principalPoint)
556 thePrincipalPoint = principalPoint;
559 void ossimBuckeyeSensor::setRollPitchHeading(
double roll,
565 theHeading = heading;
570 void ossimBuckeyeSensor::setPixelSize(
const ossimDpt& pixelSize)
572 thePixelSize = pixelSize;
575 void ossimBuckeyeSensor::setImageRect(
const ossimDrect& rect)
577 theImageClipRect = rect;
581 void ossimBuckeyeSensor::setFocalLength(
double focalLength)
583 theFocalLength = focalLength;
586 void ossimBuckeyeSensor::setPlatformPosition(
const ossimGpt& gpt)
589 theEcefPlatformPosition = gpt;
594 bool ossimBuckeyeSensor::getImageGeometry(
598 if ( ref ==
ossimString(
"parameters/fsmmgSensorImage/collectionTime" ) )
603 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/sensorType" ) )
608 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/focus/focalLength" ) )
613 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/pixelGridCharacteristics/numberOfRowsInImage" ) )
618 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/pixelGridCharacteristics/numberOfColumnsInImage" ) )
623 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/pixelGridCharacteristics/rowSpacing" ) )
627 if ( !pixel_size.
empty() )
635 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/pixelGridCharacteristics/columnSpacing" ) )
639 if ( !pixel_size.
empty() )
647 if ( ref ==
ossimString(
"parameters/fsmmgSensorImage/positionOrientationState/perspectiveCenter/geocentric-x-y-z" ) )
655 geomKwl.
add(
"ecef_platform_position", platformPositionStr );
658 if ( ref ==
ossimString(
"parameters/fsmmgSensorImage/velocity/components/geocentric-x-y-z" ) )
663 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/principalPointOffset/components/imagePlaneCRS-x0-y0" ) )
669 principal_point_offset.
x = offsetxStr.
toDouble();
670 principal_point_offset.
y = offsetyStr.
toDouble();
671 geomKwl.
add(
"principal_point", principal_point_offset.
toString().
c_str() );
674 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/radialDistortion/coefficients/k0-k1-k2-k3-k4" ) )
682 geomKwl.
add(
"smac_radial", radialDistortionStr );
685 if ( ref ==
ossimString(
"parameters/fsmmgSensorSession/decenteringDistortion/coefficients/p0-p1-p2-p3" ) )
693 geomKwl.
add(
"smac_decent", decenteringDistortionStr );
696 if ( ref ==
ossimString(
"parameters/fsmmgPlatformImage/positionOrientationState/externalOrientation/platformCS-roll-pitch-yaw" ) )
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
static ossimString upcase(const ossimString &aString)
static NEWMAT::Matrix createRotationYMatrix(double angle, ossimCoordSysOrientMode orientationMode=OSSIM_RIGHT_HANDED)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double lond() const
Will convert the radian measure to degrees.
ossimFilename & setFile(const ossimString &f)
ossimEcefPoint intersectAboveEarthEllipsoid(const double &heightAboveEllipsoid, const ossimDatum *aDatum=ossimDatumFactory::instance() ->wgs84()) const
Represents serializable keyword/value map.
bool addFile(const char *file)
bool intersectRay(const ossimEcefRay &ray, ossimGpt &gpt, double defaultElevValue=0.0)
METHOD: intersectRay()
const char * find(const char *key) const
ossimString afterPos(std::string::size_type pos) const
bool contains(char aChar) const
static ossimString toString(bool aValue)
Numeric to string methods.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
void setOrigin(const ossimEcefPoint &orig)
double latd() const
Will convert the radian measure to degrees.
std::string::size_type find_first_of(char c, std::string::size_type pos=0) const
Equivalent to find(c, pos).
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
RTTI_DEF1(ossimBuckeyeSensor, "ossimBuckeyeSensor", ossimSensorModel)
virtual const char * what() const
Returns the error message.
static NEWMAT::Matrix createRotationXMatrix(double angle, ossimCoordSysOrientMode orientationMode=OSSIM_RIGHT_HANDED)
void toPoint(const std::string &s)
Initializes this point from string.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Proecedure for compensation of aerial camera lens distortion as computed by the Simultaneous Multif...
ossimString toString(ossim_uint32 precision=15) const
static NEWMAT::Matrix createIdentity()
ossimDpt midPoint() const
ossimString beforePos(std::string::size_type pos) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
ossimDpt metersPerDegree() const
void setDirection(const ossimEcefVector &d)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::vector< ossimString > StringListType