virtual void run() { // let all threads start at the same time startBarrier->block(); ossim_uint32 idx = 0; for(idx = 0; idx < m_numberOfPointsToQuery; ++idx) { ossim_float32 t = static_cast<double>(rand())/static_cast<double>(RAND_MAX); ossim_float32 centerx = 10000.0*t; ossim_float32 centery = 10000.0*t; ossimPolyArea2d polyArea1(ossimDrect(centerx-1000,centery-1000,centerx+2000,centery+2000)); ossimPolyArea2d polyArea2(ossimDrect(centerx-500,centery-500,centerx+2000,centery+2000)); ossimPolyArea2d temp1 = polyArea1&polyArea2; ossimPolyArea2d temp2 = polyArea1+polyArea2; ossimPolyArea2d temp3(polyArea1); ossimPolyArea2d temp4(polyArea2); temp3+=temp1; temp4&=temp3; // ossimGpt gpt(m_minLat + yt*m_latDelta, m_minLon + xt*m_lonDelta); } // let all threads end at the same time endBarrier->block(); }
ossimDrect::ossimDrect(const ossimDpt& p1, const ossimDpt& p2, const ossimDpt& p3, const ossimDpt& p4, ossimCoordSysOrientMode mode) : theOrientMode(mode) { if(p1.hasNans()||p2.hasNans()||p3.hasNans()||p4.hasNans()) { makeNan(); } else { double minx, miny; double maxx, maxy; minx = std::min( p1.x, std::min(p2.x, std::min(p3.x, p4.x))); miny = std::min( p1.y, std::min(p2.y, std::min(p3.y, p4.y))); maxx = std::max( p1.x, std::max(p2.x, std::max(p3.x, p4.x))); maxy = std::max( p1.y, std::max(p2.y, std::max(p3.y, p4.y))); if(mode == OSSIM_LEFT_HANDED) { *this = ossimDrect(minx, miny, maxx, maxy, mode); } else { *this = ossimDrect(minx,maxy, maxx, miny, mode); } } }
bool ossimAlphaSensorHSI::initialize( const ossimAlphaSensorSupportData& supData ) { bool result = true; // Currently no error checking. ossimDpt imageSize = supData.getImageSize(); setImageSize(imageSize); setImageRect(ossimDrect(0,0,imageSize.x-1, imageSize.y-1)); setRefImgPt(ossimDpt(imageSize.x*.5, imageSize.y*.5)); setFov(supData.getFov()); setRollBias(supData.getRollBias()); setPitchBias(supData.getPitchBias()); setHeadingBias(supData.getHeadingBias()); setSlitRot(supData.getSlitRot()); setRollPoly(supData.getRollPoly()); setPitchPoly(supData.getPitchPoly()); setHeadingPoly(supData.getHeadingPoly()); setLonPoly(supData.getLonPoly()); setLatPoly(supData.getLatPoly()); setAltPoly(supData.getAltPoly()); setScanPoly(supData.getScanPoly()); updateModel(); return result; }
ossimDrect ossimFgdcXmlDoc::getBoundingBox() { if (isOpen()) { double ll_lat = 0.0; double ll_lon = 0.0; double lr_lat = 0.0; double lr_lon = 0.0; double ul_lat = 0.0; double ul_lon = 0.0; double ur_lat = 0.0; double ur_lon = 0.0; ossimString xpath = "/metadata/idinfo/spdom/lboundng/leftbc"; vector<ossimRefPtr<ossimXmlNode> > xml_nodes; m_xmlDocument->findNodes(xpath, xml_nodes); if (xml_nodes.size() > 0) { ul_lon = xml_nodes[0]->getText().toDouble(); ll_lon = ul_lon; } xpath = "/metadata/idinfo/spdom/lboundng/rightbc"; xml_nodes.clear(); m_xmlDocument->findNodes(xpath, xml_nodes); if (xml_nodes.size() > 0) { ur_lon = xml_nodes[0]->getText().toDouble(); lr_lon = ur_lon; } xpath = "/metadata/idinfo/spdom/lboundng/bottombc"; xml_nodes.clear(); m_xmlDocument->findNodes(xpath, xml_nodes); if (xml_nodes.size() > 0) { ll_lat = xml_nodes[0]->getText().toDouble(); lr_lat = ll_lat; } xpath = "/metadata/idinfo/spdom/lboundng/topbc"; xml_nodes.clear(); m_xmlDocument->findNodes(xpath, xml_nodes); if (xml_nodes.size() > 0) { ul_lat = xml_nodes[0]->getText().toDouble(); ur_lat = ul_lat; } ossimDrect rect(ossimDpt(ul_lon, ul_lat), ossimDpt(ur_lon, ur_lat), ossimDpt(lr_lon, lr_lat), ossimDpt(ll_lon, ll_lat), OSSIM_RIGHT_HANDED); return rect; } return ossimDrect(); }
void ossimGeoAnnotationBitmap::getBoundingRect(ossimDrect& rect)const { rect = ossimDrect(0,0,0,0); if(theImageData.valid()) { rect = theImageData->getImageRectangle(); } }
void ossimGeographicAnnotationGrid::computeBoundingRect() { static const char* MODULE = "ossimGeographicAnnotationGrid::computeBoundingRect"; if(theViewProjection.valid()) { vector<ossimDpt> points(4); theViewProjection->worldToLineSample(theGroundRect.ul(), points[0]); theViewProjection->worldToLineSample(theGroundRect.ll(), points[1]); theViewProjection->worldToLineSample(theGroundRect.lr(), points[2]); theViewProjection->worldToLineSample(theGroundRect.ur(), points[3]); // now solve the bounding rect in view space. theBoundingRect = ossimDrect(points); // for now we will add a border for the labelling // of lat lon readouts. We need a better border // computation that checks exactly what we need // based on font sizes. // ossimDpt ul = theBoundingRect.ul(); ossimDpt lr = theBoundingRect.lr(); ossimRefPtr<ossimAnnotationGdBitmapFont> font = new ossimAnnotationGdBitmapFont();; font->setCenterText(ossimDpt(0,0),"ddd@mm'ss.ssssC"); ossimDrect boundingRect; font->getBoundingRect(boundingRect); font = 0; theBoundingRect = ossimDrect(ul.x - boundingRect.width(), ul.y - boundingRect.height(), lr.x + boundingRect.width(), lr.y + boundingRect.height()); if(traceDebug()) { CLOG << " bounding rect: " << theBoundingRect << endl; } } }
//******************************************************************* //! Constructs an ossimDrect surrounding the specified point, and of specified size. //******************************************************************* ossimDrect::ossimDrect(const ossimDpt& center, const double& size_x, const double& size_y, ossimCoordSysOrientMode mode) : theOrientMode(mode) { double dx = fabs(size_x); double dy = fabs(size_y); double minx = center.x - dx/2.0; double maxx = minx + dx; double miny = center.y - dy/2.0; double maxy = miny + dy; if(mode == OSSIM_LEFT_HANDED) *this = ossimDrect(minx, miny, maxx, maxy, mode); else *this = ossimDrect(minx,maxy, maxx, miny, mode); }
//***************************************************************************** // CONSTRUCTOR: ossimDrect(const vector<ossimDpt>& points) // //***************************************************************************** ossimDrect::ossimDrect(const std::vector<ossimDpt>& points, ossimCoordSysOrientMode mode) : theOrientMode (mode) { if(points.size()) { unsigned long index; double minx, miny; double maxx, maxy; minx = points[0].x; miny = points[0].y; maxx = points[0].x; maxy = points[0].y; // find the bounds for(index = 1; index < points.size(); index++) { minx = std::min(minx, points[index].x); miny = std::min(miny, points[index].y); maxx = std::max(maxx, points[index].x); maxy = std::max(maxy, points[index].y); } if(theOrientMode == OSSIM_LEFT_HANDED) { *this = ossimDrect(minx, miny, maxx, maxy, mode); } else { *this = ossimDrect(minx,maxy, maxx, miny, mode); } } else { makeNan(); } }
void ossimNitfFileHeaderV2_0::initializeDisplayLevels(std::istream& in) { // we will need to temporarily save the get pointer since // initializeDisplayLevels changes it. std::streampos saveTheGetPointer = in.tellg(); std::vector<ossimNitfImageOffsetInformation>::iterator imageOffsetList = theImageOffsetList.begin(); // allocate temporary space to store image headers ossimNitfImageHeader* imageHeader = allocateImageHeader(); // clear the list theDisplayInformationList.clear(); theImageRect = ossimDrect(0,0,0,0); if(!imageHeader) { return; } ossim_uint32 idx = 0; while(imageOffsetList != theImageOffsetList.end()) { // position the get pointer in the input // stream to the start of the image header in.seekg((*imageOffsetList).theImageHeaderOffset, std::ios::beg); // get the data imageHeader->parseStream(in); // create a union of rects. The result should be the image rect. ossimDrect tempRect = imageHeader->getImageRect(); if((tempRect.width() > 1) && (tempRect.height() > 1)) { theImageRect = theImageRect.combine(tempRect); } insertIntoDisplayInfoList(ossimNitfDisplayInfo(ossimString("IM"), imageHeader->getDisplayLevel(), idx)); ++imageOffsetList; ++idx; } delete imageHeader; imageHeader = 0; // finally we reset the saved get state back // to its original position in.seekg(saveTheGetPointer, std::ios::beg); }
//******************************************************************* // Public Method: ossimDrect::clipToRect //******************************************************************* ossimDrect ossimDrect::clipToRect(const ossimDrect& rect)const { ossimDrect result; result.makeNan(); if(rect.hasNans() || hasNans()) { return result; } if (theOrientMode != rect.theOrientMode) return (*this); double x0 = ossim::max(rect.ul().x, ul().x); double x1 = ossim::min(rect.lr().x, lr().x); double y0, y1; if (theOrientMode == OSSIM_LEFT_HANDED) { y0 = ossim::max(rect.ll().y, ll().y); y1 = ossim::min(rect.ur().y, ur().y); if( (x1 < x0) || (y1 < y0) ) return result; else result = ossimDrect(x0, y0, x1, y1, theOrientMode); } else { y0 = ossim::max(rect.ll().y,ll().y); y1 = ossim::min(rect.ur().y,ur().y); if((x0 <= x1) && (y0 <= y1)) { result = ossimDrect(x0, y1, x1, y0, theOrientMode); } } return result; }
ossimDrect ossimImageViewTransform::getImageToViewBounds(const ossimDrect& imageRect)const { ossimDpt p1; ossimDpt p2; ossimDpt p3; ossimDpt p4; imageToView(imageRect.ul(), p1); imageToView(imageRect.ur(), p2); imageToView(imageRect.lr(), p3); imageToView(imageRect.ll(), p4); return ossimDrect(p1, p2, p3, p4); }
void ossimGui::ImageScrollWidget::setCacheRect() { /* ossimIpt ul(m_scrollOrigin); ossimIpt lr(m_scrollOrigin.x + size().width()-1, m_scrollOrigin.y + size().height()-1); ossimIrect rect(ul.x, ul.y, lr.x, lr.y); m_layers->setCacheRect(rect); */ QRectF rect = m_localToScroll.mapRect(QRectF(0,0,size().width(), size().height())); m_layers->setCacheRect(ossimDrect(rect.x(), rect.y(), rect.x() + rect.width()-1, rect.y() + rect.height()-1)); }
//************************************************************************************************** // Converts the local image space rect into bounding view-space rect //************************************************************************************************** ossimDrect ossimImageViewProjectionTransform::getImageToViewBounds(const ossimDrect& imageRect)const { // Let base class try: ossimDrect result = ossimImageViewTransform::getImageToViewBounds(imageRect); // If not successful, compute using input and output geometries: if (result.hasNans() && m_imageGeometry.valid() && m_viewGeometry.valid() && m_imageGeometry->hasProjection() && m_viewGeometry->hasProjection()) { ossimGeoPolygon viewClip; m_viewGeometry->getProjection()->getGroundClipPoints(viewClip); if(viewClip.size()) { std::vector<ossimGpt> imageGpts(4); m_imageGeometry->localToWorld(imageRect.ul(), imageGpts[0]); m_imageGeometry->localToWorld(imageRect.ur(), imageGpts[1]); m_imageGeometry->localToWorld(imageRect.lr(), imageGpts[2]); m_imageGeometry->localToWorld(imageRect.ll(), imageGpts[3]); const ossimDatum* viewDatum = m_viewGeometry->getProjection()->origin().datum(); imageGpts[0].changeDatum(viewDatum); imageGpts[1].changeDatum(viewDatum); imageGpts[2].changeDatum(viewDatum); imageGpts[3].changeDatum(viewDatum); ossimPolyArea2d viewPolyArea(viewClip.getVertexList()); ossimPolyArea2d imagePolyArea(imageGpts); viewPolyArea &= imagePolyArea; std::vector<ossimPolygon> visiblePolygons; viewPolyArea.getVisiblePolygons(visiblePolygons); if(visiblePolygons.size()) { std::vector<ossimDpt> vpts; ossim_uint32 idx = 0; for(idx=0; idx<visiblePolygons[0].getNumberOfVertices();++idx) { ossimDpt tempPt; ossimGpt gpt(visiblePolygons[0][idx].lat, visiblePolygons[0][idx].lon, 0.0, viewDatum); m_viewGeometry->worldToLocal(gpt, tempPt); vpts.push_back(tempPt); } result = ossimDrect(vpts); } } } return result; }
bool ossimQuadTreeWarpNode::loadState(const ossimKeywordlist& kwl, const char* prefix) { const char* ul_x = kwl.find(prefix, ossimKeywordNames::UL_X_KW); const char* ul_y = kwl.find(prefix, ossimKeywordNames::UL_Y_KW); const char* lr_x = kwl.find(prefix, ossimKeywordNames::LR_X_KW); const char* lr_y = kwl.find(prefix, ossimKeywordNames::LR_Y_KW); if(ul_x&&ul_y&&lr_x&&lr_y) { theBoundingRect = ossimDrect(ossimString(ul_x).toDouble(), ossimString(ul_y).toDouble(), ossimString(lr_x).toDouble(), ossimString(lr_y).toDouble()); return true; } return false; }
void ossimDrect::splitToQuad(ossimDrect& ulRect, ossimDrect& urRect, ossimDrect& lrRect, ossimDrect& llRect) { ossimDpt ulPt = this->ul(); ossimDpt urPt = this->ur(); ossimDpt lrPt = this->lr(); ossimDpt llPt = this->ll(); ossimIpt midPt = this->midPoint(); ulRect = ossimDrect(ulPt.x, ulPt.y, midPt.x, midPt.y, theOrientMode); urRect = ossimDrect(midPt.x, ulPt.y, urPt.x, midPt.y, theOrientMode); if(theOrientMode == OSSIM_LEFT_HANDED) { lrRect = ossimDrect(midPt.x, midPt.y, lrPt.x, theOrientMode); llRect = ossimDrect(ulPt.x, midPt.y, midPt.x, llPt.y, theOrientMode); } else { lrRect = ossimDrect(midPt.x, midPt.y, lrPt.x, theOrientMode); llRect = ossimDrect(ulPt.x, midPt.y, midPt.x, llPt.y, theOrientMode); } }
void ossimAnnotationMultiPolyObject::computeBoundingRect() { if(theMultiPolygon.size()) { ossimDrect rect(theMultiPolygon[0]); for(ossim_uint32 i = 1; i < theMultiPolygon.size(); ++i) { ossimDrect rect2(theMultiPolygon[i]); if(rect.hasNans()) { rect = rect2; } else { if(!rect2.hasNans()) { rect = rect.combine(rect2); } } } theBoundingRect = rect; } else { theBoundingRect.makeNan(); } if(!theBoundingRect.hasNans()) { ossimIpt origin = theBoundingRect.ul(); theBoundingRect = ossimDrect(origin.x - theThickness/2, origin.y - theThickness/2, origin.x + (theBoundingRect.width()-1) + theThickness/2, origin.y + (theBoundingRect.height()-1) + theThickness/2); } }
ossimDrect ossimGui::ImageScrollWidget::viewportBoundsInViewSpace()const { QSize size = viewport()->size(); QRectF out = m_localToView.mapRect(QRectF(0,0,size.width(), size.height())); return ossimDrect(out.x(), out.y(),out.x()+(out.width()-1), out.y() + (out.height()-1)); }
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; }
void oms::SingleImageChain::setViewCut(const ossimIrect& rect, bool imageSpaceFlag) { setViewCut(ossimDrect(rect), imageSpaceFlag); }
bool ossimGeneralRasterElevHandler::setFilename(const ossimFilename& file) { if(file.trim() == "") { return false; } theFilename = file; ossimFilename hdrFile = file; ossimFilename geomFile = file; theGeneralRasterInfo.theFilename = file; theGeneralRasterInfo.theWidth = 0; theGeneralRasterInfo.theHeight = 0; theNullHeightValue = ossim::nan(); hdrFile = hdrFile.setExtension("omd"); geomFile = geomFile.setExtension("geom"); if(!hdrFile.exists()|| !geomFile.exists()) { return false; } ossimKeywordlist kwl(hdrFile); if (kwl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { return false; } kwl.add(ossimKeywordNames::FILENAME_KW, file.c_str(), true); ossimGeneralRasterInfo generalInfo; if(!generalInfo.loadState(kwl)) { return false; } if(generalInfo.numberOfBands() != 1) { ossimNotify(ossimNotifyLevel_WARN) << "ossimGeneralRasterElevHandler::initializeInfo WARNING:The number of bands are not specified in the header file" << std::endl; return false; } kwl.clear(); if(kwl.addFile(geomFile)) { theGeneralRasterInfo.theNullHeightValue = generalInfo.getNullPixelValue(0); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theUl = theGeneralRasterInfo.theImageRect.ul(); theGeneralRasterInfo.theLr = theGeneralRasterInfo.theImageRect.lr(); theGeneralRasterInfo.theWidth = theGeneralRasterInfo.theImageRect.width(); theGeneralRasterInfo.theHeight = theGeneralRasterInfo.theImageRect.height(); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theByteOrder = generalInfo.getImageDataByteOrder(); theGeneralRasterInfo.theScalarType = generalInfo.getScalarType(); theGeneralRasterInfo.theBytesPerRawLine = generalInfo.bytesPerRawLine(); //add by simbla theGeneralRasterInfo.theGeometry = new ossimImageGeometry; if(!theGeneralRasterInfo.theGeometry->loadState(kwl)) { theGeneralRasterInfo.theGeometry = 0; } if(!theGeneralRasterInfo.theGeometry.valid()) { return false; } ossimGpt defaultDatum; ossimGpt ulGpt; ossimGpt urGpt; ossimGpt lrGpt; ossimGpt llGpt; theGeneralRasterInfo.theDatum = defaultDatum.datum(); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ul(), ulGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ur(), urGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.lr(), lrGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ll(), llGpt); ulGpt.changeDatum(theGeneralRasterInfo.theDatum); urGpt.changeDatum(theGeneralRasterInfo.theDatum); lrGpt.changeDatum(theGeneralRasterInfo.theDatum); llGpt.changeDatum(theGeneralRasterInfo.theDatum); theMeanSpacing = theGeneralRasterInfo.theGeometry->getMetersPerPixel().y; theGroundRect = ossimGrect(ulGpt, urGpt, lrGpt, llGpt); theGeneralRasterInfo.theWgs84GroundRect = ossimDrect(ulGpt, urGpt, lrGpt, llGpt, OSSIM_RIGHT_HANDED); theNullHeightValue = theGeneralRasterInfo.theNullHeightValue; } else { return false; } return true; }
ossimProjection* ossimSensorModelFactory::createProjection( const ossimFilename& filename, ossim_uint32 entryIdx) const { if(!filename.exists()) return 0; static const char MODULE[] = "ossimSensorModelFactory::createProjection"; ossimKeywordlist kwl; ossimRefPtr<ossimProjection> model = 0; ossimFilename geomFile = filename; geomFile = geomFile.setExtension("geom"); if(geomFile.exists()&& kwl.addFile(filename.c_str())) { ossimFilename coarseGrid; const char* type = kwl.find(ossimKeywordNames::TYPE_KW); if(type) { if(ossimString(type) == ossimString(STATIC_TYPE_NAME(ossimCoarseGridModel))) { findCoarseGrid(coarseGrid, filename); if(coarseGrid.exists() &&(coarseGrid != "")) { kwl.add("grid_file_name", coarseGrid.c_str(), true); model = new ossimCoarseGridModel(kwl); if(!model->getErrorStatus()) { return model.release(); } model = 0; } } } kwl.clear(); } // See if there is an external geomtry. ossimRefPtr<ossimProjection> proj = createProjectionFromGeometryFile(filename, entryIdx); if (proj.valid()) { return proj.release(); } if(model.valid()) { model = 0; } // first check for override // if(geomFile.exists()&&kwl.addFile(geomFile.c_str())) { model = createProjection(kwl); if(model.valid()) { return model.release(); } model = 0; } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: Testing ossimCoarsGridModel" << std::endl; } ifstream input(geomFile.c_str()); char ecgTest[4]; input.read((char*)ecgTest, 3); ecgTest[3] = '\0'; input.close(); if(ossimString(ecgTest) == "eCG") { ossimKeywordlist kwlTemp; kwlTemp.add("type", "ossimCoarseGridModel", true); kwlTemp.add("geom_file", geomFile.c_str(), true); return createProjection(kwlTemp); } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: testing ossimRpcModel" << std::endl; } //--- // Test for quick bird rpc. Could be either a tiff or nitf so not wrapped // around "isNitf()" anymore. //--- if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: testing ossimQuickbirdRpcModel" << std::endl; } ossimRefPtr<ossimQuickbirdRpcModel> qbModel = new ossimQuickbirdRpcModel; if(qbModel->parseFile(filename)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: returning ossimQuickbirdRpcModel" << std::endl; } model = qbModel.get(); qbModel = 0; return model.release(); } else { qbModel = 0; } //--- // Test for ikonos rpc. Could be tiff or nitf which is handled in // parseFile method. //--- ossimRefPtr<ossimIkonosRpcModel> ikModel = new ossimIkonosRpcModel; if(ikModel->parseFile(filename)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG returning ossimQuickbirdRpcModel" << std::endl; } model = ikModel.get(); ikModel = 0; return model.release(); } else { ikModel = 0; } if(isNitf(filename)) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: testing ossimNitfRpcModel" << std::endl; } ossimRefPtr<ossimNitfRpcModel> rpcModel = new ossimNitfRpcModel(); if ( rpcModel->parseFile(filename, entryIdx) ) // filename = NITF_file { model = rpcModel.get(); rpcModel = 0; return model.release(); } else { rpcModel = 0; } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: testing ossimIkinosRpcModel" << std::endl; } model = new ossimNitfMapModel(filename); // filename = NITF_file if(!model->getErrorStatus()) { return model.release(); } model = 0; } else if(isLandsat(filename)) { model = new ossimLandSatModel(filename); if(!model->getErrorStatus()) { return model.release(); } model = 0; } model = new ossimRS1SarModel(filename); if(model->getErrorStatus()!= ossimErrorCodes::OSSIM_OK) { return model.release(); } model = 0; // SPOT: ossimFilename spot5Test = geomFile; if(!spot5Test.exists()) { spot5Test = geomFile.path(); spot5Test = spot5Test.dirCat(ossimFilename("METADATA.DIM")); if (spot5Test.exists() == false) { spot5Test = geomFile.path(); spot5Test = spot5Test.dirCat(ossimFilename("metadata.dim")); } } if(spot5Test.exists()) { //--- // Check the basename of the input file. So we don't create a projection // for ancillary files, icon.jpg amd preview.jpg. //--- ossimFilename baseName = filename.file(); baseName.downcase(); if ( (baseName != "icon.jpg" ) && ( baseName != "preview.jpg" ) ) { ossimRefPtr<ossimSpotDimapSupportData> meta = new ossimSpotDimapSupportData; if(meta->loadXmlFile(spot5Test)) { model = new ossimSpot5Model(meta.get()); if(!model->getErrorStatus()) { return model.release(); } } } } model = 0; ossimFilename ppjFilename = filename; ppjFilename = ppjFilename.setExtension("ppj"); if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: testing ossimPpjFrameSensor" << std::endl; } if(ppjFilename.exists()) { ossimRefPtr<ossimPpjFrameSensorFile> ppjFile = new ossimPpjFrameSensorFile(); if(ppjFile->readFile(ppjFilename)) { ossimRefPtr<ossimPpjFrameSensor> sensor = new ossimPpjFrameSensor(); ossimDpt imageSize = ppjFile->getImageSize(); sensor->setFocalLength(ppjFile->getIntrinsic()[0][0], ppjFile->getIntrinsic()[1][1]); sensor->setPrincipalPoint(ppjFile->getPrincipalPoint()); sensor->setecef2CamMatrix(ppjFile->getExtrinsic().SymSubMatrix(1,3)); sensor->setCameraPosition(ppjFile->getPlatformPosition()); sensor->setImageSize(imageSize); sensor->setImageRect(ossimDrect(0,0,imageSize.x-1, imageSize.y-1)); sensor->setRefImgPt(ossimDpt(imageSize.x*.5, imageSize.y*.5)); sensor->setAveragePrjectedHeight(ppjFile->getAverageProjectedHeight()); sensor->updateModel(); return sensor.release(); } ppjFile = 0; } ossimFilename hdrFilename = filename; hdrFilename = hdrFilename.setExtension("hdr"); // image.hdr if ( !hdrFilename.exists() ) { hdrFilename = filename; hdrFilename.string() += ".hdr"; // image.ras.hdr } if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: testing ossimAlphaSensor\nheader file: " << hdrFilename << std::endl; } if(hdrFilename.exists()) { ossimRefPtr<ossimAlphaSensorSupportData> supData = new ossimAlphaSensorSupportData(); if(supData->readSupportFiles(hdrFilename)) { if (supData->isHSI()) { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: loading ossimAlphaSensorHSI" << std::endl; } ossimRefPtr<ossimAlphaSensorHSI> sensor = new ossimAlphaSensorHSI(); if ( sensor->initialize( *(supData.get()) ) ) { return (ossimProjection*)sensor.release(); } } else { if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: loading ossimAlphaSensorHRI" << std::endl; } ossimRefPtr<ossimAlphaSensorHRI> sensor = new ossimAlphaSensorHRI(); if ( sensor->initialize( *(supData.get()) ) ) { return (ossimProjection*)sensor.release(); } } } supData = 0; } model = new ossimCoarseGridModel(geomFile); if(model.valid()) { if(!model->getErrorStatus()) { return model.release(); } model = 0; } return model.release(); }
//******************************************************************* // Public Method: //******************************************************************* bool ossimKmlSuperOverlayReader::open() { // const char* MODULE = "ossimKmlSuperOverlayReader::open"; bool result = false; if(isOpen()) { close(); } if (theImageFile.ext().downcase() == "kmz") { result = getTopLevelKmlFileInfo(); if (result == false) { return result; } } else { m_xmlDocument = new ossimXmlDocument(theImageFile); } if ( m_xmlDocument.valid() ) { ossimRefPtr<ossimXmlNode> rootNode = m_xmlDocument->getRoot(); if (rootNode.valid()) { std::vector<ossimRefPtr<ossimXmlNode> > nodes = rootNode->getChildNodes(); result = isKmlSuperOverlayFile(nodes); if (result == false) //let gdal kml handle vector kml file { return result; } ossim_float64 north = 0.0; ossim_float64 south = 0.0; ossim_float64 east = 0.0; ossim_float64 west = 0.0; result = getCoordinate(nodes, north, south, east, west); if (result == false) { return result; } if (!theImageGeometry.valid()) { theImageGeometry = new ossimImageGeometry(0, createDefaultProj(north, south, east, west)); if (theImageGeometry.valid()) { result = true; theImageBound.makeNan(); //if the projection is default or geographic, uses the bounding of the OGR Layer vector<ossimGpt> points; points.push_back(ossimGpt(north, west)); points.push_back(ossimGpt(north, east)); points.push_back(ossimGpt(south, east)); points.push_back(ossimGpt(south, west)); std::vector<ossimDpt> rectTmp; rectTmp.resize(points.size()); for(std::vector<ossimGpt>::size_type index=0; index < points.size(); ++index) { theImageGeometry->worldToLocal(points[(int)index], rectTmp[(int)index]); } ossimDrect rect = ossimDrect(rectTmp[0], rectTmp[1], rectTmp[2], rectTmp[3]); theImageBound = rect; } else { result = false; } } } else { result = false; } } else { result = false; } return result; }
void ImageViewManipulator::fit() { ossimTypeNameVisitor visitor("ossimImageRenderer", true); m_scrollView->connectableObject()->accept(visitor); ossimConnectableObject* connectable = dynamic_cast<ossimConnectableObject*>(visitor.getObject()); ossim_float64 viewportWidth = m_scrollView->size().width()-16; ossim_float64 viewportHeight = m_scrollView->size().height()-16; ossimDpt saveCenter = m_centerPoint; if(connectable) { ossimImageSource* inputSource = dynamic_cast<ossimImageSource*>(connectable->getInput()); ossimImageRenderer* renderer = dynamic_cast<ossimImageRenderer*>(connectable); ossimImageViewAffineTransform* ivat = dynamic_cast<ossimImageViewAffineTransform*>(renderer->getImageViewTransform()); ossimImageViewProjectionTransform* ivpt = dynamic_cast<ossimImageViewProjectionTransform*>(renderer->getImageViewTransform()); if(ivpt) { ossimImageGeometry* iGeom = ivpt->getImageGeometry(); ossimImageGeometry* vGeom = asGeometry(); if(iGeom&&vGeom) { ossimMapProjection* mapProj = dynamic_cast<ossimMapProjection*>(vGeom->getProjection()); if(mapProj) { // ossimDpt savedMpp = mapProj->getMetersPerPixel(); ossimDpt mpp = m_fullResolutionScale; mapProj->setMetersPerPixel(m_fullResolutionScale); ossimDrect rect = inputSource->getBoundingRect(); std::vector<ossimGpt> gpoints(4); std::vector<ossimDpt> ipoints(4); iGeom->localToWorld(rect.ul(), gpoints[0]); iGeom->localToWorld(rect.ur(), gpoints[1]); iGeom->localToWorld(rect.lr(), gpoints[2]); iGeom->localToWorld(rect.ll(), gpoints[3]); vGeom->worldToLocal(gpoints[0], ipoints[0]); vGeom->worldToLocal(gpoints[1], ipoints[1]); vGeom->worldToLocal(gpoints[2], ipoints[2]); vGeom->worldToLocal(gpoints[3], ipoints[3]); ossimDrect fullBounds = ossimDrect(ipoints); double scaleX = static_cast<double>(fullBounds.width())/static_cast<double>(viewportWidth); double scaleY = static_cast<double>(fullBounds.height())/static_cast<double>(viewportHeight); double largestScale = ossim::max(scaleX, scaleY); mpp.x*=largestScale; mpp.y*=largestScale; mapProj->setMetersPerPixel(mpp); } } } else if(ivat) { ossimImageViewAffineTransform* ivat = getObjectAs<ossimImageViewAffineTransform>(); ossimDrect inputBounds = m_scrollView->getInputBounds(); double scaleX = static_cast<double>(inputBounds.width())/static_cast<double>(viewportWidth); double scaleY = static_cast<double>(inputBounds.height())/static_cast<double>(viewportHeight); double largestScale = ossim::max(scaleX, scaleY); if(ivat) { ossimDpt tempCenter; double x = 1.0/largestScale; double y = x; ivat->scale(x,y); } } } m_centerPoint = saveCenter; setViewToChains(); }
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; }
void ossimFgdcXmlDoc::getBoundingBox(ossimDrect& rect) const { rect.makeNan(); if (isOpen()) { double ll_lat = 0.0; double ll_lon = 0.0; double lr_lat = 0.0; double lr_lon = 0.0; double ul_lat = 0.0; double ul_lon = 0.0; double ur_lat = 0.0; double ur_lon = 0.0; ossimString xpath = "/metadata/idinfo/spdom/lboundng/leftbc"; bool result = getPath(xpath, ul_lon); if (!result) { xpath = "/metadata/idinfo/spdom/bounding/westbc"; result = getPath(xpath, ul_lon); m_boundInDegree = true; } if (result) { ll_lon = ul_lon; } xpath = "/metadata/idinfo/spdom/lboundng/rightbc"; result = getPath(xpath, ur_lon); if (!result) { xpath = "/metadata/idinfo/spdom/bounding/eastbc"; result = getPath(xpath, ur_lon); m_boundInDegree = true; } if (result) { lr_lon = ur_lon; } xpath = "/metadata/idinfo/spdom/lboundng/bottombc"; result = getPath(xpath, ll_lat); if (!result) { xpath = "/metadata/idinfo/spdom/bounding/southbc"; result = getPath(xpath, ll_lat); m_boundInDegree = true; } if (result) { lr_lat = ll_lat; } xpath = "/metadata/idinfo/spdom/lboundng/topbc"; result = getPath(xpath, ul_lat); if (!result) { xpath = "/metadata/idinfo/spdom/bounding/northbc"; result = getPath(xpath, ul_lat); m_boundInDegree = true; } if (result) { ur_lat = ul_lat; } rect = ossimDrect(ossimDpt(ul_lon, ul_lat), ossimDpt(ur_lon, ur_lat), ossimDpt(lr_lon, lr_lat), ossimDpt(ll_lon, ll_lat), OSSIM_RIGHT_HANDED); } }
void ossimPolygon::getMinimumBoundingRect(ossimPolygon& minRect) const { static const double MIN_STEP = (0.5)*M_PI/180.0; double angle_step = M_PI/8.0; // initial rotation step size for min area search = 22.5 deg double theta; double best_theta = M_PI/4.0; // Initial guess is 45 deg orientation double center_theta; double cos_theta, sin_theta; ossimPolygon rotatedPolygon(*this); ossimDpt xlatedVertex; ossimDpt rotatedVertex(0.0, 0.0); double min_x, min_y, max_x, max_y; double area; double min_area = 1.0/DBL_EPSILON; rotatedPolygon.theVertexList[0] = ossimDpt(0, 0); // first vertex always at origin bool first_time = true; ossimDrect best_rect; static const bool TESTING = false; //*** // Loop to converge on best orientation angle for bounding polygon: //*** while (angle_step > MIN_STEP) { //*** // Try four different rotations evenly centered about the current best guess: //*** center_theta = best_theta; for (int i=0; i<5; i++) { //*** // Check for i=2 (center angle) since already computed quantities for this in last iteration // unless this is first time through: //*** if ((i != 2) || (first_time)) { theta = center_theta + (i - 2.0)*angle_step; cos_theta = cos(theta); sin_theta = sin(theta); min_x = rotatedPolygon.theVertexList[0].x; min_y = rotatedPolygon.theVertexList[0].y; max_x = min_x; max_y = min_y; //*** // Translate polygon to origin and rotate all vertices by current theta: //*** for (unsigned int vertex=1; vertex < theVertexList.size(); vertex++) { xlatedVertex.x = theVertexList[vertex].x - theVertexList[0].x; xlatedVertex.y = theVertexList[vertex].y - theVertexList[0].y; rotatedVertex.x = cos_theta*xlatedVertex.x + sin_theta*xlatedVertex.y; rotatedVertex.y = cos_theta*xlatedVertex.y - sin_theta*xlatedVertex.x; rotatedPolygon.theVertexList[vertex] = rotatedVertex; //*** // Latch max and mins of bounding rect: //*** if (min_x > rotatedVertex.x) min_x = rotatedVertex.x; if (min_y > rotatedVertex.y) min_y = rotatedVertex.y; if (max_x < rotatedVertex.x) max_x = rotatedVertex.x; if (max_y < rotatedVertex.y) max_y = rotatedVertex.y; } if (TESTING) { ossimDpt v1 (cos_theta*min_x - sin_theta*max_y + theVertexList[0].x, cos_theta*max_y + sin_theta*min_x + theVertexList[0].y); ossimDpt v2 (cos_theta*max_x - sin_theta*max_y + theVertexList[0].x, cos_theta*max_y + sin_theta*max_x + theVertexList[0].y); ossimDpt v3 (cos_theta*max_x - sin_theta*min_y + theVertexList[0].x, cos_theta*min_y + sin_theta*max_x + theVertexList[0].y); ossimDpt v4 (cos_theta*min_x - sin_theta*min_y + theVertexList[0].x, cos_theta*min_y + sin_theta*min_x + theVertexList[0].y); cout << v1.x << "\t" << v1.y << endl; cout << v2.x << "\t" << v2.y << endl; cout << v3.x << "\t" << v3.y << endl; cout << v4.x << "\t" << v4.y << endl << endl; } //*** // Establish bounding rect and area about rotated polygon: //*** area = (max_x - min_x) * (max_y - min_y); if (area < min_area) { best_theta = theta; min_area = area; best_rect = ossimDrect(min_x, max_y, max_x, min_y, OSSIM_RIGHT_HANDED); } } // end if (i != 2 || first_time) } // end for-loop over surrounding rotations //*** // Adjust step size by half to repeat process: //*** angle_step /= 2.0; first_time = false; } // end while loop for convergence //*** // best_theta now contains optimum rotation of bounding rect. Need to apply reverse // rotation and translation of best_rect: //*** cos_theta = cos(best_theta); sin_theta = sin(best_theta); ossimDpt v1 (cos_theta*best_rect.ul().x - sin_theta*best_rect.ul().y + theVertexList[0].x, cos_theta*best_rect.ul().y + sin_theta*best_rect.ul().x + theVertexList[0].y); ossimDpt v2 (cos_theta*best_rect.ur().x - sin_theta*best_rect.ur().y + theVertexList[0].x, cos_theta*best_rect.ur().y + sin_theta*best_rect.ur().x + theVertexList[0].y); ossimDpt v3 (cos_theta*best_rect.lr().x - sin_theta*best_rect.lr().y + theVertexList[0].x, cos_theta*best_rect.lr().y + sin_theta*best_rect.lr().x + theVertexList[0].y); ossimDpt v4 (cos_theta*best_rect.ll().x - sin_theta*best_rect.ll().y + theVertexList[0].x, cos_theta*best_rect.ll().y + sin_theta*best_rect.ll().x + theVertexList[0].y); if (TESTING) { cout << v1.x << "\t" << v1.y << endl; cout << v2.x << "\t" << v2.y << endl; cout << v3.x << "\t" << v3.y << endl; cout << v4.x << "\t" << v4.y << endl << endl; } //*** // Assign return value rect: //*** minRect.clear(); minRect.addPoint(v1); minRect.addPoint(v2); minRect.addPoint(v3); minRect.addPoint(v4); return; }
bool ossimNitfRsmModel::parseImageHeader(const ossimNitfImageHeader* ih) { static const char MODULE[] = "ossimNitfRsmModel::getRsmData"; if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entering..." << std::endl; } bool status = false; if ( getRsmData(ih) ) { theImageID = m_iid.trim(); ossimIrect imageRect = ih->getImageRect(); // Fetch Image Size: theImageSize.line = static_cast<ossim_int32>(imageRect.height()); theImageSize.samp = static_cast<ossim_int32>(imageRect.width()); // Assign other data members: theRefImgPt.line = theImageSize.line/2.0; theRefImgPt.samp = theImageSize.samp/2.0; // Assign the bounding image space rectangle: theImageClipRect = ossimDrect(0.0, 0.0, theImageSize.samp-1, theImageSize.line-1); ossimGpt v0, v1, v2, v3; ossimDpt ip0 (0.0, 0.0); lineSampleHeightToWorld(ip0, m_znrmo, v0); ossimDpt ip1 (theImageSize.samp-1.0, 0.0); lineSampleHeightToWorld(ip1, m_znrmo, v1); ossimDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0); lineSampleHeightToWorld(ip2, m_znrmo, v2); ossimDpt ip3 (0.0, theImageSize.line-1.0); lineSampleHeightToWorld(ip3, m_znrmo, v3); theBoundGndPolygon = ossimPolygon (ossimDpt(v0), ossimDpt(v1), ossimDpt(v2), ossimDpt(v3)); updateModel(); // Set the ground reference point. lineSampleHeightToWorld(theRefImgPt, m_znrmo, theRefGndPt); // Height could have nan if elevation is not set so check lat, lon individually. if ( ( theRefGndPt.isLatNan() == false ) && ( theRefGndPt.isLonNan() == false ) ) { //--- // This will set theGSD and theMeanGSD. This model doesn't need these but // others do. //--- try { computeGsd(); // Set return status. status = true; } catch (const ossimException& e) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:\n" << e.what() << std::endl; } setErrorStatus(); } } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:" << "\nGround Reference Point not valid(has nans)." << " Aborting with error..." << std::endl; } setErrorStatus(); } } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::parseFile DEBUG:" << "\nError parsing rsm tags. Aborting with error." << std::endl; } setErrorStatus(); } if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status: " << ( status ? "true" : "false" ) << "\n"; } return status; } // End: ossimNitfRsmModel::parseImageHeader(const ossimNitfImageHeader* ih)
bool ossimErsSarModel::InitRefPoint(const ossimKeywordlist &kwl, const char *prefix) { const char* sc_lin_str = kwl.find(prefix, "sc_lin"); double sc_lin = atof(sc_lin_str); const char* sc_pix_str = kwl.find(prefix, "sc_pix"); double sc_pix = atof(sc_pix_str); const char* inp_sctim_str = kwl.find(prefix, "inp_sctim"); const char* rng_gate_str = kwl.find(prefix, "zero_dop_range_time_f_pixel"); double rng_gate = atof(rng_gate_str); if (_refPoint == NULL) { _refPoint = new RefPoint(); } _refPoint->set_pix_col(sc_pix); _refPoint->set_pix_line(sc_lin); char year_str[5]; for (int i = 0; i < 4; i++) { year_str[i] = inp_sctim_str[i]; } year_str[4] = '\0'; char month_str[3]; for (int i = 4; i < 6; i++) { month_str[i-4] = inp_sctim_str[i]; } month_str[2] = '\0'; char day_str[3]; for (int i = 6; i < 8; i++) { day_str[i-6] = inp_sctim_str[i]; } day_str[2] = '\0'; char hour_str[3]; for (int i = 8; i < 10; i++) { hour_str[i-8] = inp_sctim_str[i]; } hour_str[2] = '\0'; char min_str[3]; for (int i = 10; i < 12; i++) { min_str[i-10] = inp_sctim_str[i]; } min_str[2] = '\0'; char sec_str[3]; for (int i = 12; i < 14; i++) { sec_str[i-12] = inp_sctim_str[i]; } sec_str[2] = '\0'; char mili_str[4]; for (int i = 14; i < 17; i++) { mili_str[i-14] = inp_sctim_str[i]; } mili_str[3] = '\0'; int year = atoi(year_str); int month = atoi(month_str); int day = atoi(day_str); int hour = atoi(hour_str); int min = atoi(min_str); int sec = atoi(sec_str); double mili = atof(mili_str); CivilDateTime date(year, month, day, hour * 3600 + min * 60 + sec, mili / 1000.0); if (_platformPosition != NULL) { Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)date); if (ephemeris == NULL) return false ; _refPoint->set_ephemeris(ephemeris); delete ephemeris; } else { return false; } double c = 2.99792458e+8; double distance = (rng_gate * 1e-3 + ((double)sc_pix) * _sensor->get_nRangeLook() / _sensor->get_sf()) * (c / 2.0); _refPoint->set_distance(distance); // in order to use ossimSensorModel::lineSampleToWorld const char* nbCol_str = kwl.find(prefix, "num_pix"); const char* nbLin_str = kwl.find(prefix, "num_lines"); theImageSize.x = atoi(nbCol_str); theImageSize.y = atoi(nbLin_str); theImageClipRect = ossimDrect(0, 0, theImageSize.x - 1, theImageSize.y - 1); // Ground Control Points extracted from the model : corner points std::list<ossimGpt> groundGcpCoordinates ; std::list<ossimDpt> imageGcpCoordinates ; // first line first pix const char* lon_str = kwl.find("first_line_first_pixel_lon"); double lon = atof(lon_str); const char* lat_str = kwl.find("first_line_first_pixel_lat"); double lat = atof(lat_str); if (lon > 180.0) lon -= 360.0; ossimDpt imageGCP1(0, 0); ossimGpt groundGCP1(lat, lon, 0.0); groundGcpCoordinates.push_back(groundGCP1) ; imageGcpCoordinates.push_back(imageGCP1) ; // first line last pix lon_str = kwl.find("first_line_last_pixel_lon"); lon = atof(lon_str); lat_str = kwl.find("first_line_last_pixel_lat"); lat = atof(lat_str); if (lon > 180.0) lon -= 360.0; ossimDpt imageGCP2(theImageSize.x - 1, 0); ossimGpt groundGCP2(lat, lon, 0.0); groundGcpCoordinates.push_back(groundGCP2) ; imageGcpCoordinates.push_back(imageGCP2) ; // last line last pix lon_str = kwl.find("last_line_last_pixel_lon"); lon = atof(lon_str); lat_str = kwl.find("last_line_last_pixel_lat"); lat = atof(lat_str); if (lon > 180.0) lon -= 360.0; ossimDpt imageGCP3(theImageSize.x - 1, theImageSize.y - 1); ossimGpt groundGCP3(lat, lon, 0.0); groundGcpCoordinates.push_back(groundGCP3) ; imageGcpCoordinates.push_back(imageGCP3) ; // last line first pix lon_str = kwl.find("last_line_first_pixel_lon"); lon = atof(lon_str); lat_str = kwl.find("last_line_first_pixel_lat"); lat = atof(lat_str); if (lon > 180.0) lon -= 360.0; ossimDpt imageGCP4(0, theImageSize.y - 1); ossimGpt groundGCP4(lat, lon, 0.0); groundGcpCoordinates.push_back(groundGCP4) ; imageGcpCoordinates.push_back(imageGCP4) ; // Default optimization optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; return true; }
int main(int argc, char* argv[]) { ossimString tempString1; ossimString tempString2; ossimString tempString3; ossimString tempString4; ossimArgumentParser::ossimParameter tempParam1(tempString1); ossimArgumentParser::ossimParameter tempParam2(tempString2); ossimArgumentParser::ossimParameter tempParam3(tempString3); ossimArgumentParser::ossimParameter tempParam4(tempString4); ossimArgumentParser argumentParser(&argc, argv); ossimInit::instance()->addOptions(argumentParser); ossimInit::instance()->initialize(argumentParser); bool rpcFlag = false; bool cgFlag = false; bool enableElevFlag = true; bool enableAdjustmentFlag = true; ossimDrect imageRect; double error = .1; imageRect.makeNan(); argumentParser.getApplicationUsage()->setApplicationName(argumentParser.getApplicationName()); argumentParser.getApplicationUsage()->setDescription(argumentParser.getApplicationName() + " takes an input geometry (or image) and creates a converted output geometry"); argumentParser.getApplicationUsage()->setCommandLineUsage(argumentParser.getApplicationName() + " [options] <input file>"); argumentParser.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); argumentParser.getApplicationUsage()->addCommandLineOption("--rpc","Create an RPC projection"); argumentParser.getApplicationUsage()->addCommandLineOption("--rpc-gridsize","defines the grid size for the rpc estimate default is --rpc-gridsize=\"10 10\""); argumentParser.getApplicationUsage()->addCommandLineOption("--noelev","the projection but 0 out the elevation"); argumentParser.getApplicationUsage()->addCommandLineOption("--disable-adjustments","Current applies to coarse grid. It will try to make the grid adjustable if the input projection is adjustable"); argumentParser.getApplicationUsage()->addCommandLineOption("--cg","Create a coarse grid projection"); argumentParser.getApplicationUsage()->addCommandLineOption("--rect"," 4 values ulx uly width height"); argumentParser.getApplicationUsage()->addCommandLineOption("--tolerance","Used as an error tolerance. Currently on coarse grid uses it and is the pixel error for the estimate"); argumentParser.getApplicationUsage()->addCommandLineOption("--output","Override the default output name"); if (argumentParser.read("-h") || argumentParser.read("--help") || (argumentParser.argc() == 1)) { argumentParser.getApplicationUsage()->write(ossimNotify(ossimNotifyLevel_INFO)); ossimInit::instance()->finalize(); exit(0); } ossimFilename outputFile; ossimIpt rpcGridSize(10,10); if(argumentParser.read("--tolerance", tempParam1)) { error = tempString1.toDouble(); } if (argumentParser.read("--rpc")) { rpcFlag = true; } if (argumentParser.read("--rpc-gridsize",tempParam1, tempParam2)) { rpcGridSize.x = tempString1.toInt32(); rpcGridSize.y = tempString2.toInt32(); if(rpcGridSize.x < 1) { rpcGridSize.x = 8; } if(rpcGridSize.y < 1) { rpcGridSize.y = rpcGridSize.x; } } if (argumentParser.read("--cg")) { cgFlag = true; } if (argumentParser.read("--noelev")) { enableElevFlag = false; } if(argumentParser.read("--disable-adjustments")) { enableAdjustmentFlag = false; } if(argumentParser.read("--output", tempParam1)) { outputFile = ossimFilename(tempString1); } if(argumentParser.read("--rect", tempParam1,tempParam2,tempParam3,tempParam4 )) { double x,y,w,h; x = tempString1.toDouble(); y = tempString2.toDouble(); w = tempString3.toDouble(); h = tempString4.toDouble(); if(w < 1) w = 1; if(h < 1) h = 1; imageRect = ossimDrect(x,y,x+(w-1), y+(h-1)); } argumentParser.reportRemainingOptionsAsUnrecognized(); if (argumentParser.errors()) { argumentParser.writeErrorMessages(std::cout); exit(0); } ossimFilename file(argv[1]); ossimRefPtr<ossimImageHandler> h = ossimImageHandlerRegistry::instance()->open(file); ossimRefPtr<ossimProjection> inputProj = 0; ossimKeywordlist kwl; ossim_int32 minSpacing = 100; ossimRefPtr<ossimImageGeometry> geom; if(h.valid()) { geom = h->getImageGeometry(); imageRect = h->getBoundingRect(); } else if(!imageRect.hasNans()) { kwl.add(ossimKeywordNames::GEOM_FILE_KW, file.c_str()); inputProj = ossimProjectionFactoryRegistry::instance()->createProjection(kwl); } if(!geom.valid()||!geom->getProjection()) { ossimNotify(ossimNotifyLevel_WARN) << "Unable to obtain an input projection. Returning " << std::endl; argumentParser.getApplicationUsage()->write(ossimNotify(ossimNotifyLevel_INFO)); } else if(!imageRect.hasNans()) { if(outputFile.empty()) { outputFile = file.setExtension("geom"); } if(rpcFlag) { ossimRefPtr<ossimRpcSolver> solver = new ossimRpcSolver(enableElevFlag); solver->solveCoefficients(imageRect, geom.get(), rpcGridSize.x, rpcGridSize.y); ossimRefPtr<ossimImageGeometry> outputProj = solver->createRpcProjection(); kwl.clear(); outputProj->saveState(kwl); kwl.write(outputFile); } else if(cgFlag) { ossimCoarseGridModel::setInterpolationError(error); ossimCoarseGridModel::setMinGridSpacing(minSpacing); ossimCoarseGridModel cg; cg.buildGrid(imageRect, inputProj.get(), 500.0, enableElevFlag, enableAdjustmentFlag); kwl.clear(); cg.saveState(kwl); kwl.write(outputFile); cg.saveCoarseGrid(outputFile.setExtension("dat")); } } else { ossimNotify(ossimNotifyLevel_WARN) << "Unable to find an image rect" << std::endl; } return 0; }