void	PathTest::testPath() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testPath() begin");
	Path	path1("/usr/local/bin/test");
	CPPUNIT_ASSERT(path1.size() == 5);
	CPPUNIT_ASSERT(path1[0] == "");
	CPPUNIT_ASSERT(path1[1] == "usr");
	CPPUNIT_ASSERT(path1[2] == "local");
	CPPUNIT_ASSERT(path1[3] == "bin");
	CPPUNIT_ASSERT(path1[4] == "test");
	CPPUNIT_ASSERT(path1.basename() == "test");
	CPPUNIT_ASSERT(path1.dirname() == "/usr/local/bin");
	Path	path2("/usr/local/bin/");
	CPPUNIT_ASSERT(path2.size() == 4);
	CPPUNIT_ASSERT(path2[0] == "");
	CPPUNIT_ASSERT(path2[1] == "usr");
	CPPUNIT_ASSERT(path2[2] == "local");
	CPPUNIT_ASSERT(path2[3] == "bin");
	CPPUNIT_ASSERT(path2.basename() == "bin");
	CPPUNIT_ASSERT(path2.dirname() == "/usr/local");
	Path	path3("blubb/bla/foo");
	CPPUNIT_ASSERT(path3.size() == 3);
	CPPUNIT_ASSERT(path3[0] == "blubb");
	CPPUNIT_ASSERT(path3[1] == "bla");
	CPPUNIT_ASSERT(path3[2] == "foo");
	CPPUNIT_ASSERT(path3.basename() == "foo");
	CPPUNIT_ASSERT(path3.dirname() == "blubb/bla");
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testPath() end");
}
示例#2
0
TEST(Path, pwd)
{
    cxx::sys::Path path1(cxx::sys::Path::curpath());
    printf("current path is: %s\n", path1.name());

    cxx::sys::Path path2(cxx::sys::Path::curpath());
    path2.append("abc");
    printf("path2 is: %s\n", path2.name());

    cxx::sys::Path path3("abc/");
    printf("path3 is: %s\n", path3.name());

    cxx::sys::Path path6("../");
    printf("path6 is: %s\n", path6.name());
}
示例#3
0
int main(int argc, char *argv[]) {
    Log::open("log.txt");
    if(argc < 3){
        Log::i("main", QString("usage: ")+argv[0]+" paper_path.txt outputpath.json test.json...");
        exit(1);
    }

    PaperParser parser;
    ExamPaper paper = parser.parse(argv[1]);
    QString paperStr = paper.listAllQuestions();
    printf("\n\n ----------------------------------\n\n");
    printf("%s\n", paperStr.toUtf8().constData());

    QString path(argv[2]);
    paper.save2JsonFile(path);

    paper.clear();
    paper.loadFromJsonFile(path);
    QString path3(argv[3]);
    paper.save2JsonFile(path3);

    return false;
}
示例#4
0
文件: main.cpp 项目: Exadios/Cumulus
int main(int argc, char *argv[])
{
  // Workaround to start browser from QTextView
  qputenv( "BROWSER", "browser --url" );

  // @AP: Reset the locale that is used for number formatting to "C" locale.
  setlocale(LC_NUMERIC, "C");

#ifdef ANDROID

  // Gets the additional data directory from our app. That is normally the
  // storage path to the SD-Card as /sdcard/Cumulus.
  QString addDir = jniGetAddDataDir();

  while( addDir.isEmpty() )
    {
      qDebug() << " Waiting for Cumulus addDir ...";
      usleep(250000);
      addDir = jniGetAddDataDir();
    }

  // Assign the original path name
  addDir = QDir(addDir).canonicalPath();

  // Nice trick to overwrite the HOME directory under Android by us ;-)
  // That must be done before the QApplication constructor is called.
  // Otherwise another HOME is used by QApplication.
  qputenv ( "HOME", addDir.toLatin1().data() );

#endif

#ifndef ANDROID
#if QT_VERSION < 0x050000
  // Note this must be called before QApplication constructor
  QApplication::setGraphicsSystem( "raster" );
#endif
#endif

  QApplication app(argc, argv, true);

  QCoreApplication::setApplicationName( "Cumulus" );
  QCoreApplication::setApplicationVersion( CU_VERSION );
  QCoreApplication::setOrganizationName( "KFLog" );
  QCoreApplication::setOrganizationDomain( "www.kflog.org" );

  // Make sure the application uses utf8 encoding for translated widgets
#if QT_VERSION < 0x050000
  QTextCodec::setCodecForTr( QTextCodec::codecForName ("UTF-8") );
#endif

  // Note, that first $HOME must be overwritten under Android otherwise the
  // setting file is created/searched in the internal data area under:
  // /data/data/org.kflog.cumulus/files. That is the $HOME, set by Necessitas.
  GeneralConfig *conf = GeneralConfig::instance();

#ifdef ANDROID

  // Set the add data directory in our configuration
  conf->setDataRoot( addDir );

  // Set data directory after every startup because different Android APIs
  // uses different locations. Otherwise that can cause problems during Andoid
  // updates to a newer release.
  conf->setUserDataDirectory( addDir );

  // As next we must wait, that the add data are installed. That is done
  // at the Java side.
  while( jniAddDataInstalled() == false )
    {
      qDebug() << " Waiting for Cumulus addData installed ...";
      usleep(250000);
    }

  // Gets the internal data directory from our App
  QString appDir = jniGetAppDataDir();

  while (appDir.isEmpty())
    {
      qDebug() << " Waiting for Cumulus appDir ...";
      usleep(250000);
      appDir = jniGetAppDataDir();
    }

  conf->setAppRoot( appDir );

#endif /* ANDROID */

  // @AP: we installing our own message handler
#if QT_VERSION < 0x050000
  qInstallMsgHandler(messageHandler);
#else
  qInstallMessageHandler(messageHandler);
#endif

  // @AP: to make trace output available, if process is started via
  // QT/X11, we can redirect all output into a file, if configuration option
  // Log2File is set to true.

#ifndef ANDROID
  // @AP: make install root of Cumulus available for other modules via
  // GeneralConfig. The assumption is that Cumulus is installed at
  // <root>/bin/cumulus. The <root> path will be passed to GeneralConfig.
  QDir rootDir( QFileInfo(argv[0]).canonicalPath() );

  if( rootDir.cdUp() == false )
    {
      qWarning() << "main: Cumulus App has no parent directory! InstallDir is" << rootDir;
    }

  QString rootPath = rootDir.canonicalPath();

  conf->setAppRoot( rootPath );
#endif

#ifdef MAEMO
  bool isLog2File = true;
#else
  bool isLog2File = conf->getLog2FileMode();
#endif

  QString logDir = "/tmp";

#ifdef ANDROID

  // always log on Android for now
  isLog2File = true;
  logDir = QDir::homePath();

#endif

  if( isLog2File )
    {

#ifdef MAEMO
      // check for alternate paths under Maemo
      QDir path1("/media/mmc1"); // N8x0
      QDir path2("/media/mmc2"); // N8x0
      QDir path3("/home/user/MyDocs");

      if( path1.exists() && HwInfo::isMounted(path1.absolutePath()) )
        {
          logDir = path1.absolutePath();
        }
      else if( path2.exists() && HwInfo::isMounted(path2.absolutePath()) )
        {
          logDir = path2.absolutePath();
        }
      else if( path3.exists() )
         {
           logDir = path3.absolutePath();
         }

#endif

      logDir += "/cumulus.log";

      // Save one old log file version.
      rename( logDir.toLatin1().data(), (logDir + ".old").toLatin1().data() );

      int i = open( logDir.toLatin1().data(), O_RDWR|O_CREAT|O_TRUNC,
                    S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH );

      // Duplicate file descriptors 1, 2 that the output goes into a logfile

      // dup2( i, fileno(stdin) );
      dup2( i, fileno(stdout) );
      dup2( i, fileno(stderr) );
      close(i);
    }

#ifdef ANDROID

  qDebug() << "Cumulus addDir and QtHome:" << addDir;
  qDebug() << "Cumulus appDir:" << appDir;
  qDebug() << "Cumulus LogDir:" << logDir;

#endif

  /*
    @AP: check, if environment variable LD_BIND_NOW is set. In this case reset
    it to avoid a gps client crash during fork under Opie.

    If the process environment [see exec(base operating system)] contains a
    variable named LD_BIND_NOW with a non-null value, the dynamic linker processes
    all relocations before transferring control to the program. For example, all
    the following environment entries would specify this behavior.

    * LD_BIND_NOW=1
    * LD_BIND_NOW=on
    * LD_BIND_NOW=off

    Otherwise, LD_BIND_NOW either does not occur in the environment or has a null
    value. The dynamic linker is permitted to evaluate procedure linkage table
    entries lazily, thus avoiding symbol resolution and relocation overhead for
    functions that are not called. See the Procedure Linkage Table in this chapter
    of the processor supplement for more information.
  */

  char *env = getenv("LD_BIND_NOW");
  qDebug( "LD_BIND_NOW=%s", env ? env : "NULL" );

//  if( env != 0 )
//    {
//      unsetenv("LD_BIND_NOW");
//    }

  // Load language translation file for Cumulus.

#ifndef ANDROID

  conf->setLanguage( conf->getLanguage() );

#else

  // Gets the default language from the Android device.
   QString language = jniGetLanguage();

   // Put Android's default language into the program environment.
   qputenv( "LANG",  language.toLatin1().data() );

   qDebug() << "Android sets language to" << language;

   if( language.startsWith( "de" ) )
     {
       // In case of German there is a translation available.
       conf->setLanguage( "de" );
     }
   else
     {
       conf->setLanguage( conf->getLanguage() );
     }

  QFontDatabase database;

  foreach (const QString &family, database.families())
    {
      foreach (const QString &style, database.styles(family))
        {
          QString sizes;

          foreach (int points, database.smoothSizes(family, style))
            sizes += QString::number(points) + " ";

          qDebug() << "Installed Font:" << family << style << sizes.trimmed();
        }
    }

  QHash <QString, float> dmh = jniGetDisplayMetrics();

  QHashIterator<QString, float> i(dmh);

  qDebug() << "Android display metrics as key value list";

  while( i.hasNext() )
    {
      i.next();
      qDebug() << i.key() << "=" << i.value();
    }

  QHash <QString, QString> bdh = jniGetBuildData();

  QHashIterator<QString, QString> j(bdh);

  qDebug() << "Android build data as key value list";

  while( j.hasNext() )
    {
      j.next();
      qDebug() << j.key() << "=" << j.value();
    }

#endif

  // save done configuration settings
  conf->save();

  // create the Cumulus application window
  MainWindow *cumulus = new MainWindow( Qt::WindowContextHelpButtonHint );

  // start window manager event processing loop
  int result = QApplication::exec();

  // remove as first MainWindow because class objects inside can call GeneralConfig
  delete cumulus;

  // remove GeneralConfig, it is created during first call to it
  delete GeneralConfig::instance();

  return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//                                       place ring
//
// Place autonomous ring while sensing the IR beacon
//
/////////////////////////////////////////////////////////////////////////////////////////////////
void placering (string iSide, int iPos, int iColumn, int iHeight)
{
	if (iColumn == 2)
	{
		moveLift (0, 0, UP);
	}
	else
	{
		if (iHeight == 1)
		{
			moveLift(40, 571, UP);
		}
		else if (iHeight == 2)
		{
			moveLift(40, 3095, UP);
		}
		else if (iHeight == 3)
		{
			moveLift(40, 5233, UP);
		}
	}

	if (iPos == 1)
	{
		if (iColumn == 1)
		{
			path1 (iSide,33, 15);
		}
		else if (iColumn == 2)
		{
			move(50, 16, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 45, LEFT);
			}
			else
			{
				GyroTurn (50, 45, RIGHT);
			}

			move(50, 21, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 45, LEFT);
			}
			else
			{
				GyroTurn (50, 45, RIGHT);
			}

			move(50, 13, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 30, RIGHT);
			}
			else
			{
				GyroTurn (50, 30, LEFT);
			}

			move(50, 1, BACKWARD);

			moveLift(40, 500, UP);

			move(50, 3, FORWARD);
		}
		else if (iColumn == 3)
		{
			path2 (iSide, 20, 31);
		}
	}
	else if (iPos == 2)
	{
		if (iColumn == 1)
		{
			path1 (iSide, 15, 12);
		}
		else if (iColumn == 2)
		{
			move(50, 33, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 90, LEFT);
			}
			else
			{
				GyroTurn (50, 90, RIGHT);
			}

			move(50, 19, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 30, RIGHT);
			}
			else
			{
				GyroTurn (50, 30, LEFT);
			}

			move(50, 2, BACKWARD);

			moveLift(40, 500, UP);

			move(50, 3, FORWARD);
		}
		else if (iColumn == 3)
		{
			path2 (iSide, 35, 13);
		}
	}
	else if (iPos == 3)
	{
		if (iColumn == 1)
		{
			path1 (iSide, 12, 14);
		}
		else if (iColumn == 2)
		{
			move(50, 12, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 90, LEFT);
			}
			else
			{
				GyroTurn (50, 90, RIGHT);
			}

			move(50, 13, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 90, RIGHT);
			}
			else
			{
				GyroTurn (50, 90, LEFT);
			}

			move(50, 18, FORWARD);

			if (strcmp(iSide, "left")== 0)
			{
				GyroTurn (50, 35, LEFT);
			}
			else
			{
				GyroTurn (50, 35, RIGHT);
			}

			move(50, 1, BACKWARD);

			moveLift(40, 500, UP);

			move(50, 4, FORWARD);
		}
		else if (iColumn == 3)
		{
			path3 (iSide, 15);
		}
	}

	servo[pivotLeft]  = 0;
	servo[pivotRight] = 255;

	if (iHeight == 1)
	{
		moveLift(40, 571, DOWN);
	}
	else if (iHeight == 2)
	{
		moveLift(40, 3095, DOWN);
	}
	else if (iHeight == 3)
	{
		moveLift(40, 5233,DOWN);
	}
}
bool SparseRec2View::save()
{
	if(!_onlymatch) {
		//save reconstructed points
		string path1(dir+imgname1+string("-")+imgname2+string(".X"));
		std::ofstream o1(path1.c_str());
		o1 << "VERTEX " << (int)results.size() << endl;
		for(int i=0; i<(int)results.size(); ++i) {
			o1<<results[i].x<<" "<<results[i].y<<" "<<results[i].z<<endl;
		}
		o1.close();
		TagI("save reconstructed points to\n  %s\n",path1.c_str());

		//save cam par
		string path7(imgpath1+string(".par"));
		std::ofstream o7(path7.c_str());
		o7.setf(std::ios::scientific);
		o7 << "K(alphaX alphaY u0 v0)=" <<endl;
		o7 << K[0] << " " << K[4] << " " << K[2] << " " << K[5] << endl;
		o7 << "R=" << endl;
		o7 << "1 0 0\n0 1 0\n0 0 1" <<endl;
		o7 << "T=" << endl;
		o7 << "0 0 0" << endl;
		o7.close();
		TagI("save camera 1's parameters to\n  %s\n",path7.c_str());

		string path8(imgpath2+string(".par"));
		std::ofstream o8(path8.c_str());
		o8.setf(std::ios::scientific);
		o8 << "K(alphaX alphaY u0 v0)=" <<endl;
		o8 << K[0] <<" "<< K[4] <<" "<< K[2] <<" "<< K[5] << endl;
		o8 << "R=" << endl;
		for(int i=0; i<3; ++i) {
			for(int j=0; j<3; ++j) {
				o8 << R[i*3+j] << " ";
			}
			o8 << endl;
		}
		o8 << "T=" << endl;
		o8 << t[0] <<" "<< t[1] <<" "<< t[2] << endl;
		o8.close();
		TagI("save camera 2's parameters to\n  %s\n",path8.c_str());
	}

	double fontScale=0.5;
	CvPoint text_origin;
	//save matched point pairs
	string path2(dir+imgname1+string("-")+imgname2+string(".p1p2"));
	std::ofstream o2(path2.c_str());
	//out.setf(std::ios::scientific);
	int cnt = 0;
	for(int i=0; i<(int)p1.size(); ++i) {
		if(!inliers[i]) continue;

		o2 << p1[i].x <<" "<< p1[i].y <<" "<< p2[i].x <<" "<< p2[i].y <<endl;

		char tmp[256];
		sprintf(tmp, "%d", cnt++);
		text_origin.x = (int)p1[i].x+5;
		text_origin.y = (int)p1[i].y-5;
		putText(img1, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK);
		text_origin.x = (int)p2[i].x+5;
		text_origin.y = (int)p2[i].y-5;
		putText(img2, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK);
	}
	o2.close();
	TagI("save matched point pairs to\n  %s\n",path2.c_str());

	//save images
	string path3(imgpath1+string("-detect.jpg"));
	string path4(imgpath2+string("-detect.jpg"));
	string path5(dir+imgname1+string("-")+imgname2+string(".jpg"));
	if(!img1.empty()) cv::imwrite(path3, img1);
	else {
		TagE("no valid image to save!\n");
		return false;
	}
	if(!img2.empty()) cv::imwrite(path4, img2);
	if(!combined.empty()) cv::imwrite(path5, combined);
	TagI("save surfed image 1 to\n  %s\n",path3.c_str());
	TagI("save surfed image 2 to\n  %s\n",path4.c_str());
	TagI("save combined image to\n  %s\n",path5.c_str());

	//save F
	string path6(dir+imgname1+string("-")+imgname2+string(".fmatrix"));
	std::ofstream o6(path6.c_str());
	o6 << helper::PrintMat<>(3,3,F);
	o6.close();
	TagI("save fundamental matrix to\n  %s\n",path6.c_str());

	return true;
}
示例#7
0
int CmdPull::execute (std::string& output)
{
  context.footnote ("The 'pull' command is deprecated, and will be removed in a subsequent release.");

  std::vector <std::string> words = context.a3.extract_words ();
  std::string file;
  if (words.size ())
    file = words[0];

  Uri uri (file, "pull");
  uri.parse ();

  if (uri._data.length ())
  {
		Directory location (context.config.get ("data.location"));

    if (! uri.append ("{pending,undo,completed}.data"))
      throw format (STRING_CMD_PULL_NOT_DIR, uri._path);

		Transport* transport;
		if ((transport = Transport::getTransport (uri)) != NULL)
		{
			transport->recv (location._data + "/");
			delete transport;
		}
		else
		{
      // Verify that files are not being copied from rc.data.location to the
      // same place.
      if (Directory (uri._path) == Directory (context.config.get ("data.location")))
        throw std::string (STRING_CMD_PULL_SAME);

      // copy files locally

      // remove {pending,undo,completed}.data
      uri._path = uri.parent();

      Path path1 (uri._path + "undo.data");
      Path path2 (uri._path + "pending.data");
      Path path3 (uri._path + "completed.data");

      if (path1.exists() && path2.exists() && path3.exists())
      {
//        if (confirm ("xxxxxxxxxxxxx"))
//        {
          std::ofstream ofile1 ((location._data + "/undo.data").c_str(), std::ios_base::binary);
          std::ifstream ifile1 (path1._data.c_str()                    , std::ios_base::binary);
          ofile1 << ifile1.rdbuf();

          std::ofstream ofile2 ((location._data + "/pending.data").c_str(), std::ios_base::binary);
          std::ifstream ifile2 (path2._data.c_str()                    , std::ios_base::binary);
          ofile2 << ifile2.rdbuf();

          std::ofstream ofile3 ((location._data + "/completed.data").c_str(), std::ios_base::binary);
          std::ifstream ifile3 (path3._data.c_str()                    , std::ios_base::binary);
          ofile3 << ifile3.rdbuf();
//        }
      }
      else
      {
        throw format (STRING_CMD_PULL_MISSING, uri._path);
      }
		}

    output += format (STRING_CMD_PULL_TRANSFERRED, uri.ToString ()) + "\n";
  }
  else
    throw std::string (STRING_CMD_PULL_NO_URI);

  return 0;
}