Exemplo n.º 1
0
fs::path uniquify(const fs::path &dest)
{
    std::string ext = dest.extension();
    std::string fname = dest.stem();
    fs::path parent = dest.parent_path();

    unsigned number = 1;
    std::string newfname;
    fs::path newdest;

    boost::smatch match;
    if(boost::regex_search(fname, match, uregex)) {
        // Matches are indexes into fname, so don't change it while reading values
        newfname = match[1];
        number = boost::lexical_cast<short>(match[2]);
        fname = newfname;
    }

    do { 
        newfname = fname + "(" + boost::lexical_cast<std::string>(++number) + ")" + ext;
        newdest = parent / newfname;
    } while(fs::exists(newdest));

    return newdest;
}
/*******************************************************************
 * Function Name: GetFullImagePath
 * Return Type 	: const fs::path
 * Created On	: Mar 8, 2014
 * Created By 	: hrushi
 * Comments		: Returns the corresponding full image path for the given track image
 * Arguments	:
 *******************************************************************/
const fs::path TrackXML::GetFullImagePath( UINT FrameNum ) const
{
	const fs::path Parentfldr = GetFilePath().parent_path();
	const string FldrName = Parentfldr.stem().string();

	string ImgStemName = StringOp<UINT>::GetString(FrameNum, '0', 5);

	fs::path FullImgPath = Parentfldr.string() + "/full/" +  FldrName + "." + ImgStemName + ".jpeg";

	return FullImgPath;
}
Exemplo n.º 3
0
Save::Save(fs::path const& file, bool binary)
: file_name(file)
, tmp_name(unique_path(file.parent_path()/(file.stem().string() + "_tmp_%%%%" + file.extension().string())))
{
	LOG_D("agi/io/save/file") << file;

	fp = agi::make_unique<boost::filesystem::ofstream>(tmp_name, binary ? std::ios::binary : std::ios::out);
	if (!fp->good()) {
		acs::CheckDirWrite(file.parent_path());
		acs::CheckFileWrite(file);
		throw fs::WriteDenied(tmp_name);
	}
}
/*******************************************************************
 * Function Name: GetTrackFilePath
 * Return Type 	: const fs::path
 * Created On	: Mar 5, 2014
 * Created By 	: hrushi
 * Comments		: Get the TrackFile path from the given TrackImage path
 * Arguments	: const fs::path TrackChipPath
 *******************************************************************/
const fs::path TrackXML::GetTrackFilePath( const fs::path fsTrackChipPath)
{
	fs::path fsTrackFldrPath = fsTrackChipPath.parent_path().parent_path();
	string stemname = fsTrackChipPath.stem().string();

	UINT TrackNum, FrameNum;
	string VideoBaseName;

	GetTrkChipNameParts(stemname, TrackNum, FrameNum, VideoBaseName);
	fs::path fsTrackFilePath = fsTrackFldrPath.string() + "/" + VideoBaseName + "_track.xml";

	return fsTrackFilePath;
}
	Pano( const fs::path& path )
		: mDisplayMode{ ivec2(0,0) }, mName( path.filename().string() )
	{
		std::string stem = path.stem().string();
		std::transform( stem.begin(), stem.end(), stem.begin(), ::toupper );
		switch( stem.back() ) {
		case 'L': mDisplayMode = ivec2( 0, 0 ); break;
		case 'R': mDisplayMode = ivec2( 0, 1 ); break;
		case 'T': mDisplayMode = ivec2( 1, 0 ); break;
		case 'B': mDisplayMode = ivec2( 1, 1 ); break;
		default: break;
		}

		mLatLong = gl::Texture2d::create( loadImage( path ), gl::Texture2d::Format().wrap( GL_REPEAT ) );
	}
Exemplo n.º 6
0
// Tries to import a python module given the path to the .py file
// from http://wiki.python.org/moin/boost.python/EmbeddingPython
py::object Python_importFile(const fs::path &path) {
  try {
    py::dict locals;
    locals["modulename"] = path.stem().string(); // foo -> module name
    locals["path"] = path.string(); // /Users/whatever/blah/foo.py
    py::exec(
      "import imp; newmodule = imp.load_module(modulename,open(path),path,('py','U',imp.PY_SOURCE))",
      PyGlobals::main_namespace, locals
    );
    LOG_DEBUG("loaded python module " << path.string());
    return locals["newmodule"];
  } catch (const py::error_already_set &e) {
    PyErr_Print();
    throw e;
  }
}
/*******************************************************************
 * Function Name: GiveSegImgPath
 * Return Type 	: const fs::path
 * Created On	: Aug 21, 2013
 * Created By 	: hrushi
 * Comments		: For the given image path. It creates a segmentation folder and returns the path where the image could be stored
 * Arguments	: const fs::path& ImgPath
 *******************************************************************/
const fs::path Detect::GiveSegImgPath( const fs::path& iPath, const string Suffix)
{
	fs::path SegImgPath;


	fs::path SegFldr = iPath.parent_path().string() + "/Seg";
	fs::create_directory(SegFldr);

	string OutputPath;
	OutputPath = SegFldr.parent_path().string() + "/Seg/";
	OutputPath +=  iPath.stem().string() + Suffix;
	OutputPath +=  iPath.extension().string();

	SegImgPath = OutputPath;

	return SegImgPath;
}
Exemplo n.º 8
0
void SpriteSheetGeneratorApp::addFile(const fs::path &file)
{
  set<string> extensions = { ".png", ".jpg", ".gif", ".tiff", ".tif", ".tga" };
  if( fs::exists( file ) )
  {
    cout << "Checking file: " << file << ", extension: " << file.extension().string() << endl;
    if( fs::is_regular_file( file ) && extensions.count(file.extension().string()) )
    {
      cout << "Adding file: " << file << endl;
      Surface img = loadImage( file );
      string id = file.stem().string();
      mWidestImage = max( img.getWidth(), mWidestImage );
      auto sprite = mImagePacker.addImage( id, img );
      sprite->setRegistrationPoint( Vec2i( sprite->getWidth() / 2, sprite->getHeight() ) );
    }
    else if( fs::is_directory( file ) )
    {
      for( auto iter = fs::directory_iterator( file ); iter != fs::directory_iterator(); ++iter )
      {
        addFile( *iter );
      }
    }
  }
}
Exemplo n.º 9
0
void writeToFile(fs::path _path)
{
	stringstream ss;

	if (fileCount < 0){
		fileCount = 0;
		ss << fileCount;
		outFile.open(fs::path(string(BASE_MODEL_PATH)+"/Data"+ss.str()+".bin"), ios::binary);
		ss.flush();
	}
	else if (byteCount > BYTE_LIMIT){
		outFile.flush();
		outFile.close();
		fileCount++;
		ss << fileCount;
		outFile.open(fs::path(string(BASE_DEST_PATH)+"/Data"+ss.str()+".bin"), ios::binary);
		ss.flush();
		byteCount = 0;
		// close file and open new
	}

	Header head;
	head.id = strToUint64(_path.stem());


	idxFile.open(_path, ios::binary);
	dataFile.open(_path.parent_path() / (_path.stem()+".data"), ios::binary);

	idxFile.seekg(0, ios::beg);
	idxFile.read((char*)&head.indexCount, sizeof(unsigned));
	idxFile.seekg(4, ios::beg);
	dataFile.seekg(0, ios::beg);
	dataFile.read((char*)&head.vertexCount, sizeof(unsigned));
	dataFile.seekg(4, ios::beg);

	indexData = new unsigned[head.indexCount];
	vertexData = new ooctools::V4N4[head.vertexCount];

	idxFile.read((char*)indexData, sizeof(unsigned)*head.indexCount);
	idxFile.close();

	dataFile.read((char*)vertexData, sizeof(V4N4)*head.vertexCount);
	dataFile.close();

	// ------------------------------------
	//write to file

	outFile.seekp(byteCount, ios::beg);
	//writing header-info
	outFile.write((char*)&head, sizeof(Header));
	outFile.seekp(byteCount+sizeof(Header), ios::beg);
	//writing the indices
	outFile.write((char*)indexData, head.indexCount*sizeof(unsigned));
	outFile.seekp(byteCount + sizeof(Header) + head.indexCount*sizeof(unsigned), ios::beg);
	//writing the vertices
	outFile.write((char*)vertexData, head.vertexCount*sizeof(V4N4));
	byteCount += head.sizeOf();
	outFile.flush();

	delete[] vertexData;
	vertexData = 0;
	delete[] indexData;
	indexData = 0;
}
Exemplo n.º 10
0
void trim(fs::ofstream & out, fs::path & file, std::vector<std::pair<int, int>> & contents, fs::path ffmpeg_path, std::string ffmpeg_options)
{
	if (contents.size() != 0)
	{
		int i = 0;

		int gap = 3;

		// trim command
		for (auto & elem : contents)
		{
			out << ffmpeg_path << " -y -ss " << (((elem.first - gap) < 0) ? 0 : elem.first - gap) << " -i \"" << file.string() << "\" -t " << elem.second - elem.first + gap << "  -vcodec copy -acodec copy tmp_" + std::to_string(i++) + ".m2ts\n";
		}

		// concastrate command

		// ffmpeg path
		out << ffmpeg_path;

		for (auto j = 0; j < i; ++j)
		{
			out << " -i tmp_" << std::to_string(j) << ".m2ts";
		}

		// ffmpeg commands
		out << " -filter_complex \"yadif=0:-1,concat=n=" << std::to_string(i) << ":v=1:a=1\" " << ffmpeg_options << " \"done\\" << file.stem().string() << ".mp4\"\n";
	}
	else
	{
		out << ffmpeg_path << " ";
		out << " -i \"" << file.string() << "\" -filter_complex \"yadif=0:-1\" " << ffmpeg_options << " \"done\\" << file.stem().string() << ".mp4\"\n";
	}
}