/* ecrit le fichier ppm utilise la matrice tab2D_color pour le contenu du fichier */ void WriteFic::writeThePPMFic(Pixel** tableauPixels, unsigned int tailleTab)throw(string) { ofstream fic("result.ppm", ios::out | ios::trunc); if(fic) { //Debut du fichier fic << "P3 " << endl << this->nbrColFic << " " << this->nbrLigFic << endl; fic << "255" << endl; //Contenu du fichier for(int i = 0; i < this->nbrLigFic; i++) { for(int j = 0; j < this->nbrColFic; j++) { string color = "0 0 0"; if (!tableauPixels[i * this->nbrColFic + j]->pixelNoir){ //On verifie si le pixel est noir //On va chercher la couleur de lensemble color = getCouleurPixel(tableauPixels[i * this->nbrColFic + j]->getHead()); } fic << color << " "; // on ecrit la couleur } fic << endl; } fic.close(); } else { throw string("Fonction writeThePPMFic : Erreur lors de la creation du fichier"); } }
QStringList findResourceFiles(const QString& dirName, const QString& filter, QStringList additionalPreferredPaths) { QStringList searchFiles; QString dn = dirName; if (dn.endsWith('/')||dn.endsWith(QDir::separator())) dn=dn.left(dn.length()-1); //remove / at the end if (!dn.startsWith('/')&&!dn.startsWith(QDir::separator())) dn="/"+dn; //add / at beginning searchFiles<<":"+dn; //resource fall back searchFiles.append(additionalPreferredPaths); searchFiles<<QCoreApplication::applicationDirPath() + dn; //windows new // searchFiles<<QCoreApplication::applicationDirPath() + "/data/"+fileName; //windows new #if !defined(PREFIX) #define PREFIX "" #endif #if defined( Q_WS_X11 ) searchFiles<<PREFIX"/share/texstudio"+dn; //X_11 searchFiles<<PREFIX"/share/texmakerx"+dn; //X_11 #endif #ifdef Q_WS_MAC CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); searchFiles<<QString(pathPtr)+"/Contents/Resources"+dn; //Mac CFRelease(appUrlRef); CFRelease(macPath); #endif QStringList result; foreach(const QString& fn, searchFiles) { QDir fic(fn); if (fic.exists() && fic.isReadable()) result<< fic.entryList(QStringList(filter),QDir::Files,QDir::Name); }
Pt2dr Dimap::ptGeo2Carto(Pt2dr Pgeo, std::string targetSyst, std::string inputSyst)const { std::ofstream fic("processing/conv_ptGeo.txt"); fic << std::setprecision(15); fic << Pgeo.y <<" "<<Pgeo.x<<";"<<std::endl; // transformation in the ground coordinate system std::string command; command = g_externalToolHandler.get("cs2cs").callName() + " " + inputSyst + " +to " + targetSyst + " processing/conv_ptGeo.txt > processing/conv_ptCarto.txt"; int res = system(command.c_str()); if (res != 0) std::cout<<"error calling cs2cs in ptGeo2Carto"<<std::endl; // loading the coordinate of the converted point Pt2dr PointCarto; std::ifstream fic2("processing/conv_ptCarto.txt"); while(!fic2.eof()&&fic2.good()) { double X,Y,Z; fic2 >> Y >> X >> Z; if (fic2.good()) { PointCarto.x=X; PointCarto.y=Y; } } cout << PointCarto << endl; return PointCarto; }
Settings::Settings() { m_isDirty = false; m_isRunning = true; // Load settings std::ifstream in("../../usersettings.cfg"); if (!in.fail()) { std::string line; std::getline(in, line); std::string key; while (!in.eof()) { if (!key.empty()) { m_userSettings[key] = line; key.clear(); } else { key = line; } getline(in, line); } in.close(); } // Start saving thread m_savingThread = std::thread([this] { std::unique_lock<std::mutex> locker(m_mutex); while (m_isRunning) { m_conditionVariable.wait(locker); if (!m_isDirty) continue; m_isDirty = false; // Wait a little bit more, maybe the user is doing a bunch of transactions at once locker.unlock(); std::this_thread::sleep_for(std::chrono::milliseconds(200)); locker.lock(); // Copy the map so there is not conflics auto userSettings = m_userSettings; locker.unlock(); std::ofstream fic("../../usersettings.cfg"); if (!fic.fail()) { for (auto &kv : userSettings) { fic << kv.first << std::endl; fic << kv.second << std::endl; } fic.close(); } locker.lock(); } }); }
void WriteFic::generate (int n, int m) throw(string) { if(n <= 0 || m <= 0){ throw string("la taille donnee en parametre de generate est incorrect"); } ofstream fic("img_generate.pbm", ios::out | ios::trunc); if(fic) { //Debut du fichier fic << "P1 " << endl << m << " " << n << endl; //Contenu du fichier for(int i = 0; i < n; ++i) { for(int j=0; j < m; ++j){ int v = rand() %3; if (v == 1){ fic << 1 << " "; } else { fic << 0 << " "; } } fic << endl; } fic.close(); } else { throw string("Fonction generate : Erreur lors de la creation du fichier"); } }
void Konsole::sync() { if(!KileConfig::syncConsoleDirWithTabs()) { return; } KTextEditor::Document *doc = m_ki->activeTextDocument(); KTextEditor::View *view = Q_NULLPTR; if(doc) { view = doc->views().first(); } if(view) { QString finame; QUrl url = view->document()->url(); if(url.path().isEmpty()) { return; } QFileInfo fic(url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); if(fic.isReadable()) { setDirectory(url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).path()); } } }
void Dimap::createDirectGrid(double ulcSamp, double ulcLine, double stepPixel, int nbSamp, int nbLine, std::vector<double> const &vAltitude, std::vector<Pt2dr> &vPtCarto, std::string targetSyst, std::string inputSyst, std::vector<double> vRefineCoef,double rowCrop, double sampCrop)const { vPtCarto.clear(); // On cree un fichier de points geographiques pour les transformer avec proj4 { std::ofstream fic("processing/direct_ptGeo.txt"); fic << std::setprecision(15); for(size_t i=0;i<vAltitude.size();++i) { double altitude = vAltitude[i]; for(int l=0;l<nbLine;++l) { for(int c = 0;c<nbSamp;++c) { Pt2dr Pimg(ulcSamp + c * stepPixel, ulcLine + l * stepPixel); //pour affiner les coordonnees Pt2dr PimgRefined = ptRefined(Pimg, vRefineCoef, rowCrop, sampCrop); Pt2dr Pgeo = direct(PimgRefined,altitude); fic << Pgeo.y <<" "<<Pgeo.x<<";"<<std::endl; } } } } // transformation in the ground coordinate system std::string command; command = g_externalToolHandler.get("cs2cs").callName() + " " + inputSyst + " +to " + targetSyst + " -s processing/direct_ptGeo.txt > processing/direct_ptCarto.txt"; int res = system(command.c_str()); if (res != 0) std::cout<<"error calling cs2cs in createDirectGrid"<<std::endl; // loading points std::ifstream fic("processing/direct_ptCarto.txt"); while(!fic.eof()&&fic.good()) { double X,Y,Z; char c; fic >> Y >> X >> Z >> c; if (fic.good()) vPtCarto.push_back(Pt2dr(X,Y)); } std::cout << "createDirectGrid - Nombre de points lus : "<<vPtCarto.size()<<std::endl; }
void Dimap::createIndirectGrid(double ulcX, double ulcY, int nbrSamp, int nbrLine, double stepCarto, std::vector<double> const &vAltitude, std::vector<Pt2dr> &vPtImg, std::string targetSyst, std::string inputSyst, std::vector<double> vRefineCoef, double rowCrop, double sampCrop)const { vPtImg.clear(); // On cree un fichier de points cartographiques pour les transformer avec proj4 { std::ofstream fic("processing/indirect_ptCarto.txt"); fic << std::setprecision(15); for(int l=0;l<nbrLine;++l) { double Y = ulcY - l*stepCarto; for(int c = 0;c<nbrSamp;++c) { double X =ulcX + c*stepCarto; fic << X <<" "<<Y<<";"<<std::endl; } } } // transfo en Geo std::string command; command = g_externalToolHandler.get( "cs2cs" ).callName() + " " + targetSyst + " +to " + inputSyst + " -f %.12f -s processing/indirect_ptCarto.txt >processing/indirect_ptGeo.txt"; int res = system(command.c_str()); if (res != 0) std::cout<<"error calling cs2cs in createIndirectGrid"<<std::endl; for(size_t i=0;i<vAltitude.size();++i) { double altitude = vAltitude[i]; // chargement des points std::ifstream fic("processing/indirect_ptGeo.txt"); while(!fic.eof()&&fic.good()) { double lon ,lat ,Z; char c; fic >> lat >> lon >> Z >> c; if (fic.good()) { vPtImg.push_back(indirect(Pt2dr(lat,lon),altitude,vRefineCoef,rowCrop,sampCrop)); } } } std::cout << "createIndirectGrid - Nombre de points lus : "<<vPtImg.size()<<std::endl; }
void StarMgr::init() { QSettings* conf = StelApp::getInstance().getSettings(); Q_ASSERT(conf); starConfigFileFullPath = StelFileMgr::findFile("stars/default/starsConfig.json", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::File)); if (starConfigFileFullPath.isEmpty()) { qWarning() << "Could not find the starsConfig.json file: will copy the default one."; copyDefaultConfigFile(); } QFile fic(starConfigFileFullPath); if(fic.open(QIODevice::ReadOnly)) { starSettings = StelJsonParser::parse(&fic).toMap(); fic.close(); } // Increment the 1 each time any star catalog file change if (starSettings.value("version").toInt()!=StarCatalogFormatVersion) { qWarning() << "Found an old starsConfig.json file, upgrade.."; fic.remove(); copyDefaultConfigFile(); QFile fic2(starConfigFileFullPath); if(fic2.open(QIODevice::ReadOnly)) { starSettings = StelJsonParser::parse(&fic2).toMap(); fic2.close(); } } loadData(starSettings); starFont.setPixelSize(StelApp::getInstance().getBaseFontSize()); setFlagStars(conf->value("astro/flag_stars", true).toBool()); setFlagLabels(conf->value("astro/flag_star_name",true).toBool()); setLabelsAmount(conf->value("stars/labels_amount",3.f).toFloat()); objectMgr->registerStelObjectMgr(this); texPointer = StelApp::getInstance().getTextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png"); // Load pointer texture StelApp::getInstance().getCore()->getGeodesicGrid(maxGeodesicGridLevel)->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this); foreach(ZoneArray* z, gridLevels) z->scaleAxis(); StelApp *app = &StelApp::getInstance(); connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n())); connect(app, SIGNAL(skyCultureChanged(const QString&)), this, SLOT(updateSkyCulture(const QString&))); connect(app, SIGNAL(colorSchemeChanged(const QString&)), this, SLOT(setStelStyle(const QString&))); QString displayGroup = N_("Display Options"); addAction("actionShow_Stars", displayGroup, N_("Stars"), "flagStarsDisplayed", "S"); addAction("actionShow_Stars_Labels", displayGroup, N_("Stars labels"), "flagLabelsDisplayed", "Alt+S"); }
//----------------------------------------------------------------------------- // Renvoie true si le fichier existe avec sa taille //----------------------------------------------------------------------------- bool CSystemInfo::GetFileSize(const char* src, double &size) { size = 0; std::ifstream fic(src); if (!fic.good()) return false; fic.seekg(0, std::ios::end); size = fic.tellg(); return true; }
bool onut::PropertyManager::loadPropertiesFromFile(const std::string& filename) { std::ifstream fic(filename); if (fic.fail()) return false; Json::Value root; Json::Reader reader; if (!reader.parse(fic, root)) return false; fic.close(); return loadPropertiesFromJson(root); }
void HeapInspection::find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) { assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); assert(Heap_lock->is_locked(), "should have the Heap_lock"); // Ensure that the heap is parsable Universe::heap()->ensure_parsability(false); // no need to retire TALBs // Iterate over objects in the heap FindInstanceClosure fic(k, result); // If this operation encounters a bad object when using CMS, // consider using safe_object_iterate() which avoids metadata // objects that may contain bad references. Universe::heap()->object_iterate(&fic); }
bool RosCheckerboardDetection::detect(const sensor_msgs::ImageConstPtr& in_msg, vector<double>& out) { bool success; success = CheckerboardDetection::detect(in_msg, out); if (!success) { // no checkerboard found at all return success; } if (markerFrame == "") { // no marker frame given ROS_INFO( "No marker_frame parameter set! No automatic removal of outlier!"); return success; } // marker frame is given, check distance to predicted position string cameraFrame = in_msg->header.frame_id; ros::Time now = ros::Time::now(); tf::StampedTransform transform; cv::Point2d center; // get the transformation via TF if (!transformListener.waitForTransform(cameraFrame, markerFrame, now, ros::Duration(1.0))) { ROS_INFO("No transformation found from %s to %s!", markerFrame.c_str(), cameraFrame.c_str()); return success; } transformListener.lookupTransform(cameraFrame, markerFrame, now, transform); // get the projected center FrameImageConverter fic(cameraModel); fic.project(transform, center.x, center.y); ROS_INFO("Expecting the checkerboard near %f %f, found it at %f %f", center.x, center.y, out[idx_x], out[idx_y]); double deltaX = center.x - out[idx_x]; double deltaY = center.y - out[idx_y]; double dist = sqrt(deltaX * deltaX - deltaY * deltaY); if (dist > maxDist) { ROS_INFO("Too far away, probably an outlier."); return false; } return success; }
void Commande::initErrors() { ifstream fic("errors.don",ios::in); if (fic) { int errNum; while(fic >> errNum) { string err; getline(fic,err); errors[errNum] = err; } fic.close(); } else
//reads the txt file with lattice point in im coordinates (unit : pixels) vector<vector<Pt2dr> > ReadLatticeIm(string aTxtImage) { vector<vector<Pt2dr> > aMatIm; vector<double> Xs, Ys; //Reading the files std::ifstream fic(aTxtImage.c_str()); u_int X_count = 0; while (!fic.eof() && fic.good() && X_count<11) { double X; fic >> X; //std::cout << "X=" << X << endl; Xs.push_back(X); X_count++; } while (!fic.eof() && fic.good()) { double Y; fic >> Y; //std::cout << "Y=" << Y << endl; Ys.push_back(Y); } for (u_int i = 0; i < Ys.size(); i++) { vector<Pt2dr> aVectPts; for (u_int j = 0; j < Xs.size(); j++) { Pt2dr aPt(Xs[j], Ys[i]); aVectPts.push_back(aPt); } aMatIm.push_back(aVectPts); //std::cout << aMatIm[i] << endl; } std::cout << "Loaded " << aMatIm.size()*aMatIm[0].size() << " lattice points in image coordinates" << endl; return aMatIm; }
int newIDTest(void) { TestUtil testFramework("ObsID", "newID", __FILE__, __LINE__); std::string failMesg; failMesg = "[testing] ObsID::newID to redefine existing ID, [expected] exception gpstk::Exception, [actual] threw no exception"; try{gpstk::ObsID::newID("C6Z", "L6 Z range"); testFramework.assert(false, failMesg, __LINE__);} catch(gpstk::Exception e) {testFramework.assert(true, failMesg, __LINE__);} //create a fictional ID completely gpstk::ObsID fic(gpstk::ObsID::newID("T9W", "L9 W test")); failMesg = "Was the fictional type value stored in the map?"; testFramework.assert(gpstk::ObsID::char2ot.count('T'), failMesg, __LINE__); failMesg = "Was the fictional band value stored in the map?"; testFramework.assert(gpstk::ObsID::char2cb.count('9'), failMesg, __LINE__); failMesg = "Was the fictional code value stored in the map?"; testFramework.assert(gpstk::ObsID::char2tc.count('W'), failMesg, __LINE__); failMesg = "Was the fictional type value stored in an ObsID?"; testFramework.assert(fic.type == gpstk::ObsID::char2ot['T'], failMesg, __LINE__); failMesg = "Was the fictional band value stored in an ObsID?"; testFramework.assert(fic.band == gpstk::ObsID::char2cb['9'], failMesg, __LINE__); failMesg = "Was the fictional code value stored in an ObsID?"; testFramework.assert(fic.code == gpstk::ObsID::char2tc['W'], failMesg, __LINE__); failMesg = "[testing] ObsID::newID to redefine existing ID, [expected] exception gpstk::Exception, [actual] threw no exception"; try{gpstk::ObsID::newID("T9W", "L9 W test"); testFramework.assert(false, failMesg, __LINE__);} catch(gpstk::Exception e) {testFramework.assert(true, failMesg, __LINE__);} return testFramework.countFails(); }
bool Var::load() { //Chargement du fichier dans Var::var_names QFile fic(Config::programResourceDir()+"/vars.cfg"); if(!fic.exists() && fic.open(QIODevice::WriteOnly | QIODevice::Text)) { fic.write( QString("1|3|$AerisLovePoints\n").toLocal8Bit()+ QString("1|4|$TifaLovePoints\n").toLocal8Bit()+ QString("1|5|$YuffieLovePoints\n").toLocal8Bit()+ QString("1|6|$BarretLovePoints\n").toLocal8Bit()+ QString("1|20|$Hours\n").toLocal8Bit()+ QString("1|21|$Minutes\n").toLocal8Bit()+ QString("1|22|$Seconds\n").toLocal8Bit()+ QString("1|23|$Frames\n").toLocal8Bit()+ QString("1|64|$KeyItems\n").toLocal8Bit()+ QString("1|65|$KeyItems\n").toLocal8Bit()+ QString("1|66|$KeyItems\n").toLocal8Bit()+ QString("1|67|$KeyItems\n").toLocal8Bit()+ QString("1|68|$KeyItems\n").toLocal8Bit()+ QString("1|69|$KeyItems\n").toLocal8Bit()+ QString("1|70|$KeyItems\n").toLocal8Bit()+ QString("1|85|$ChocoboType1Catched\n").toLocal8Bit()+ QString("1|86|$ChocoboType2Catched\n").toLocal8Bit()+ QString("1|87|$ChocoboType3Catched\n").toLocal8Bit()+ QString("1|88|$ChocoboType4Catched\n").toLocal8Bit()+ QString("1|124|$ChocoboOnMap\n").toLocal8Bit()+ QString("1|167|$VictoryFortCondor\n").toLocal8Bit()+ QString("1|182|$DefeatFortCondor\n").toLocal8Bit()+ QString("2|0|$GameMoment\n").toLocal8Bit()+ QString("2|24|$BattleCount\n").toLocal8Bit()+ QString("2|26|$BattleEscaped\n").toLocal8Bit()+ QString("2|180|$GoldFortCondor\n").toLocal8Bit()+ QString("3|9|$PartyLeader\n").toLocal8Bit()+ QString("3|88|$NumStablesBought\n").toLocal8Bit()+ QString("3|89|$NumStablesFilled\n").toLocal8Bit()+ QString("13|31|$ErrorAddMateria\n").toLocal8Bit()+ QString("13|84|$LastCloud\n").toLocal8Bit()+ QString("13|85|$LastBarret\n").toLocal8Bit()+ QString("13|86|$LastTifa\n").toLocal8Bit()+ QString("13|87|$LastRedXIII\n").toLocal8Bit()+ QString("13|88|$LastCid\n").toLocal8Bit()+ QString("13|89|$LastYuffi\n").toLocal8Bit()+ QString("13|90|$LastCaitSith\n").toLocal8Bit()+ QString("13|92|$LastVincent\n").toLocal8Bit() ); fic.close(); } if(fic.open(QIODevice::ReadOnly | QIODevice::Text)) { QString line; QStringList liste; bool ok; int bank, adress; forever { line = QString(fic.readLine()); if(line.isEmpty()) break; liste = line.split(QChar('|')); if(liste.size() != 3) return false; bank = liste.at(0).toInt(&ok); if(!ok) return false; if(bank<1 || bank>15) continue; adress = liste.at(1).toInt(&ok); if(!ok) return false; if(adress<0 || adress>255) continue; line = liste.at(2); if(line.isEmpty()) return false; if(line.size()>50) line = line.left(50); set(bank, adress, line.simplified()); } fic.close(); return true; }
bool StarMgr::checkAndLoadCatalog(const QVariantMap& catDesc) { const bool checked = catDesc.value("checked").toBool(); QString catalogFileName = catDesc.value("fileName").toString(); // See if it is an absolute path, else prepend default path if (!(StelFileMgr::isAbsolute(catalogFileName))) catalogFileName = "stars/default/"+catalogFileName; QString catalogFilePath = StelFileMgr::findFile(catalogFileName); if (catalogFilePath.isEmpty()) { // The file is supposed to be checked, but we can't find it if (checked) { qWarning() << QString("Warning: could not find star catalog %1").arg(QDir::toNativeSeparators(catalogFileName)); setCheckFlag(catDesc.value("id").toString(), false); } return false; } // Possibly fixes crash on Vista if (!StelFileMgr::isReadable(catalogFilePath)) { qWarning() << QString("Warning: User does not have permissions to read catalog %1").arg(QDir::toNativeSeparators(catalogFilePath)); return false; } if (!checked) { // The file is not checked but we found it, maybe from a previous download/version qWarning() << "Found file " << QDir::toNativeSeparators(catalogFilePath) << ", checking md5sum.."; QFile fic(catalogFilePath); if(fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { // Compute the MD5 sum QCryptographicHash md5Hash(QCryptographicHash::Md5); const qint64 cat_sz = fic.size(); qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775807LL); uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd5) : NULL; if (!cat) { // The OS was not able to map the file, revert to slower not mmap based method static const qint64 maxStarBufMd5 = 1024*1024*8; char* mmd5buf = (char*)malloc(maxStarBufMd5); while (!fic.atEnd()) { qint64 sz = fic.read(mmd5buf, maxStarBufMd5); md5Hash.addData(mmd5buf, sz); } free(mmd5buf); } else { md5Hash.addData((const char*)cat, cat_sz); fic.unmap(cat); } fic.close(); if (md5Hash.result().toHex()!=catDesc.value("checksum").toByteArray()) { qWarning() << "Error: File " << QDir::toNativeSeparators(catalogFileName) << " is corrupt, MD5 mismatch! Found " << md5Hash.result().toHex() << " expected " << catDesc.value("checksum").toByteArray(); fic.remove(); return false; } qWarning() << "MD5 sum correct!"; setCheckFlag(catDesc.value("id").toString(), true); } } ZoneArray* z = ZoneArray::create(catalogFilePath, true); if (z) { if (z->level<gridLevels.size()) { qWarning() << QDir::toNativeSeparators(catalogFileName) << ", " << z->level << ": duplicate level"; delete z; return true; } Q_ASSERT(z->level==maxGeodesicGridLevel+1); Q_ASSERT(z->level==gridLevels.size()); ++maxGeodesicGridLevel; gridLevels.append(z); } return true; }
int Luc_main(int argc, char ** argv) { //GET PSEUDO-RPC2D FOR ASTER FROM LATTICE POINTS std::string aTxtImage, aTxtCarto; std::string aFileOut = "RPC2D-params.xml"; //Reading the arguments ElInitArgMain ( argc, argv, LArgMain() << EAMC(aTxtImage, "txt file contaning the lattice point in the image coordinates", eSAM_IsPatFile) << EAMC(aTxtCarto, "txt file contaning the lattice point in the carto coordinates", eSAM_IsPatFile), LArgMain() << EAM(aFileOut, "Out", true, "Output xml file with RPC2D coordinates") ); //Reading the files vector<Pt2dr> aPtsIm, aPtsCarto; { std::ifstream fic(aTxtImage.c_str()); while (!fic.eof() && fic.good()) { double X, Y; fic >> X >> Y; Pt2dr aPt(X, Y); if (fic.good()) { aPtsIm.push_back(aPt); } } cout << "Read " << aPtsIm.size() << " points in image coordinates" << endl; //cout << aPtsIm << endl; std::ifstream fic2(aTxtCarto.c_str()); while (!fic2.eof() && fic2.good()) { double X, Y, Z; fic2 >> X >> Y >> Z; Pt2dr aPt(X, Y); if (fic2.good()) { aPtsCarto.push_back(aPt); } } cout << "Read " << aPtsCarto.size() << " points in cartographic coordinates" << endl; //cout << aPtsCarto << endl; } //Finding normalization parameters //divide Pts into X and Y vector<double> aPtsCartoX, aPtsCartoY, aPtsImX, aPtsImY; for (u_int i = 0; i < aPtsCarto.size(); i++) { aPtsCartoX.push_back(aPtsCarto[i].x); aPtsCartoY.push_back(aPtsCarto[i].y); aPtsImX.push_back(aPtsIm[i].x); aPtsImY.push_back(aPtsIm[i].y); } Pt2dr aPtCartoMin(*std::min_element(aPtsCartoX.begin(), aPtsCartoX.end()), *std::min_element(aPtsCartoY.begin(), aPtsCartoY.end())); Pt2dr aPtCartoMax(*std::max_element(aPtsCartoX.begin(), aPtsCartoX.end()), *std::max_element(aPtsCartoY.begin(), aPtsCartoY.end())); Pt2dr aPtImMin(*std::min_element(aPtsImX.begin(), aPtsImX.end()), *std::min_element(aPtsImY.begin(), aPtsImY.end())); Pt2dr aPtImMax(*std::max_element(aPtsImX.begin(), aPtsImX.end()), *std::max_element(aPtsImY.begin(), aPtsImY.end())); Pt2dr aCartoScale((aPtCartoMax.x - aPtCartoMin.x) / 2, (aPtCartoMax.y - aPtCartoMin.y) / 2); Pt2dr aImScale((aPtImMax.x - aPtImMin.x) / 2, (aPtImMax.y - aPtImMin.y) / 2); Pt2dr aCartoOffset(aPtCartoMin.x + (aPtCartoMax.x - aPtCartoMin.x) / 2, aPtCartoMin.y + (aPtCartoMax.y - aPtCartoMin.y) / 2); Pt2dr aImOffset(aPtImMin.x + (aPtImMax.x - aPtImMin.x) / 2, aPtImMin.y + (aPtImMax.y - aPtImMin.y) / 2); //Parameters too get parameters of P1 and P2 in --- Column=P1(X,Y)/P2(X,Y) --- where (X,Y) are Carto coordinates (idem for Row) //Function is 0=Poly1(X,Y)-Column*Poly2(X,Y) ==> Column*k=a+bX+cY+dXY+eX^2+fY^2+gX^2Y+hXY^2+iX^3+jY^3-Column(lX+mY+nXY+oX^2+pY^2+qX^2Y+rXY^2+sX^3+tY^3) //k=1 to avoid sol=0 L2SysSurResol aSysCol(19), aSysRow(19); //For all lattice points for (u_int i = 0; i<aPtsCarto.size(); i++){ //NORMALIZATION double X = (aPtsCarto[i].x - aCartoOffset.x) / aCartoScale.x; double Y = (aPtsCarto[i].y - aCartoOffset.y) / aCartoScale.y; double COL = (aPtsIm[i].x - aImOffset.x) / aImScale.x; double ROW = (aPtsIm[i].y - aImOffset.y) / aImScale.y; double aEqCol[19] = { (1), (X), (Y), (X*Y), (pow(X, 2)), (pow(Y, 2)), (pow(X, 2)*Y), (X*pow(Y, 2)), (pow(X, 3)), (pow(Y, 3)), //(COL), (-COL*X), (-COL*Y), (-COL*X*Y), (-COL*pow(X, 2)), (-COL*pow(Y, 2)), (-COL*pow(X, 2)*Y), (-COL*X*pow(Y, 2)), (-COL*pow(X, 3)), (-COL*pow(Y, 3)), }; aSysCol.AddEquation(1, aEqCol, COL); double aEqRow[19] = { (1), (X), (Y), (X*Y), (pow(X, 2)), (pow(Y, 2)), (pow(X, 2)*Y), (X*pow(Y, 2)), (pow(X, 3)), (pow(Y, 3)), //(ROW), (-ROW*X), (-ROW*Y), (-ROW*X*Y), (-ROW*pow(X, 2)), (-ROW*pow(Y, 2)), (-ROW*pow(X, 2)*Y), (-ROW*X*pow(Y, 2)), (-ROW*pow(X, 3)), (-ROW*pow(Y, 3)), }; aSysRow.AddEquation(1, aEqRow, ROW); } //Computing the result bool Ok; Im1D_REAL8 aSolCol = aSysCol.GSSR_Solve(&Ok); Im1D_REAL8 aSolRow = aSysRow.GSSR_Solve(&Ok); double* aDataCol = aSolCol.data(); double* aDataRow = aSolRow.data(); //Outputting results { std::ofstream fic(aFileOut.c_str()); fic << std::setprecision(15); fic << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << endl; fic << "<RPC2D>" << endl; fic << "\t<RFM_Validity>" << endl; fic << "\t\t<Direct_Model_Validity_Domain>" << endl; fic << "\t\t\t<FIRST_ROW>" << aPtImMin.x << "</FIRST_ROW>" << endl; fic << "\t\t\t<FIRST_COL>" << aPtImMin.y << "</FIRST_COL>" << endl; fic << "\t\t\t<LAST_ROW>" << aPtImMax.x << "</LAST_ROW>" << endl; fic << "\t\t\t<LAST_COL>" << aPtImMax.y << "</LAST_COL>" << endl; fic << "\t\t</Direct_Model_Validity_Domain>" << endl; fic << "\t\t<Inverse_Model_Validity_Domain>" << endl; fic << "\t\t\t<FIRST_X>" << aPtCartoMin.x << "</FIRST_X>" << endl; fic << "\t\t\t<FIRST_Y>" << aPtCartoMin.y << "</FIRST_Y>" << endl; fic << "\t\t\t<LAST_X>" << aPtCartoMax.x << "</LAST_X>" << endl; fic << "\t\t\t<LAST_Y>" << aPtCartoMax.y << "</LAST_Y>" << endl; fic << "\t\t</Inverse_Model_Validity_Domain>" << endl; fic << "\t\t<X_SCALE>" << aCartoScale.x << "</X_SCALE>" << endl; fic << "\t\t<X_OFF>" << aCartoOffset.x << "</X_OFF>" << endl; fic << "\t\t<Y_SCALE>" << aCartoScale.y << "</Y_SCALE>" << endl; fic << "\t\t<Y_OFF>" << aCartoOffset.y << "</Y_OFF>" << endl; fic << "\t\t<SAMP_SCALE>" << aImScale.x << "</SAMP_SCALE>" << endl; fic << "\t\t<SAMP_OFF>" << aImOffset.x << "</SAMP_OFF>" << endl; fic << "\t\t<LINE_SCALE>" << aImScale.y << "</LINE_SCALE>" << endl; fic << "\t\t<LINE_OFF>" << aImOffset.y << "</LINE_OFF>" << endl; fic << "\t</RFM_Validity>" << endl; for (int i = 0; i<10; i++) { fic << "<COL_NUMERATOR_" << i + 1 << ">" << aDataCol[i] << "</COL_NUMERATOR_" << i + 1 << ">" << endl; } fic << "<COL_DENUMERATOR_1>1</COL_DENUMERATOR_1>" << endl; for (int i = 10; i<19; i++) { fic << "<COL_DENUMERATOR_" << i - 8 << ">" << aDataCol[i] << "</COL_DENUMERATOR_" << i -8 << ">" << endl; } for (int i = 0; i<10; i++) { fic << "<ROW_NUMERATOR_" << i + 1 << ">" << aDataRow[i] << "</ROW_NUMERATOR_" << i + 1 << ">" << endl; } fic << "<ROW_DENUMERATOR_1>1</ROW_DENUMERATOR_1>" << endl; for (int i = 10; i<19; i++) { fic << "<ROW_DENUMERATOR_" << i - 8 << ">" << aDataRow[i] << "</ROW_DENUMERATOR_" << i - 8 << ">" << endl; } fic << "</RPC2D>" << endl; } cout << "Written functions in file " << aFileOut << endl; return 0; }