コード例 #1
0
void create_directories(const boost::filesystem::path & cur, 
						      boost::filesystem::path & work,
							  boost::filesystem::path & out)
{
	auto parent = cur.parent_path();
	auto start  = parent.begin();

	for(auto p = config::tests.begin(); p != config::tests.end() && *p == *start; ++p, ++start) ;

	work = config::cache;
	out  = config::data;

	for(; start != parent.end(); ++start)
	{
		work /= *start;
		out  /= *start;
		boost::filesystem::create_directory(work);
		boost::filesystem::create_directory(out);
	}

	work /= cur.stem();
	out  /= (cur.stem().native() + ".out");

	boost::filesystem::create_directory(work);
}
コード例 #2
0
ファイル: client.cpp プロジェクト: tribal-tec/Equalizer
bool Client::initLocal( const int argc, char** argv )
{
    if( _impl->name.empty() && argc > 0 && argv )
    {
        const boost::filesystem::path prog = argv[0];
        setName( prog.stem().string( ));
    }

    const auto options = _getProgramOptions();
    arg::variables_map vm;
    try
    {
        Strings args;
        for( int i = 0; i < argc; ++i )
            if( strcmp( argv[i], "--" ) != 0 )
                args.push_back( argv[i] );

        arg::store( arg::command_line_parser( args )
                        .options( options ).allow_unregistered().run(), vm );
        arg::notify( vm );
    }
    catch( const std::exception& e )
    {
        LBERROR << "Error in argument parsing: " << e.what() << std::endl;
        return false;
    }

    const bool isClient = vm.count( "eq-client" );
    std::string clientOpts;

    if( vm.count( "eq-layout" ))
        _impl->activeLayouts.push_back( vm["eq-layout"].as< std::string >( ));
    if( vm.count( "eq-gpufilter" ))
        _impl->gpuFilter = vm["eq-gpufilter"].as< std::string >();
    if( vm.count( "eq-modelunit" ))
        _impl->modelUnit = vm["eq-modelunit"].as< float >();

    LBVERB << "Launching " << getNodeID() << std::endl;
    if( !Super::initLocal( argc, argv ))
        return false;

    if( isClient )
    {
        LBVERB << "Client node started from command line with option "
               << clientOpts << std::endl;

        if( !_setupClient( clientOpts ))
        {
            exitLocal();
            return false;
        }

        _impl->running = true;
        clientLoop();
        exitClient();
    }

    _impl->initQt( argc, argv );
    return true;
}
コード例 #3
0
ファイル: client.cpp プロジェクト: weetgo/Equalizer
bool Client::initLocal( const int argc, char** argv )
{
    bool isClient = false;
    std::string clientOpts;

    if( _impl->name.empty() && argc > 0 && argv )
    {
        const boost::filesystem::path prog = argv[0];
        setName( prog.stem().string( ));
    }

    for( int i=1; i<argc; ++i )
    {
        if( std::string( "--eq-client" ) == argv[i] )
            isClient = true;
        else if( _isParameterOption( "--eq-layout", argc, argv, i ))
            _impl->activeLayouts.push_back( argv[++i] );
        else if( _isParameterOption( "--eq-gpufilter" , argc, argv, i ))
            _impl->gpuFilter = argv[ ++i ];
        else if( _isParameterOption( "--eq-modelunit", argc, argv, i ))
        {
            std::istringstream unitString( argv[++i] );
            unitString >> _impl->modelUnit;
        }
    }
コード例 #4
0
void try_run_file(const boost::filesystem::path & cur)
{
	if(cur.extension().native().compare(".py"))
	{
		return;
	}

	script_file_parser script_file(cur.native());

	if(script_file.is_valid())
	{
		boost::filesystem::path work, out;
		create_directories(cur, work, out);

		auto parent = cur.parent_path();
		auto start  = parent.begin();

		for(auto p = config::tests.begin(); p != config::tests.end() && *p == *start; ++p, ++start) ;

		for(; start != parent.end(); ++start)
		{
			script_file.add_keyword((*start).native());
		}

		script_file.add_title(cur.stem().native());

		if(config::query->evaluate(script_file))
		{
			script_scheduler()->schedule_file(cur, work, out);
		}
	}
}
コード例 #5
0
static std::string
loadFile (boost::property_tree::ptree &config,
          const boost::filesystem::path &file)
{
  boost::filesystem::path extension = file.extension();
  boost::filesystem::path extension2 = file.stem().extension();
  std::string fileName = file.filename().string();
  boost::property_tree::ptree readConfig;

  if (extension2.string() == ".conf") {
    if (extension.string() == ".json") {
      boost::property_tree::read_json (file.string(), readConfig);
    } else if (extension.string() == ".info") {
      boost::property_tree::read_info (file.string(), readConfig);
    } else if (extension.string() == ".ini") {
      boost::property_tree::read_ini (file.string(), readConfig);
    } else if (extension.string() == ".xml") {
      boost::property_tree::read_xml (file.string(), readConfig);
    } else {
      throw ParseException ("Unknonw file format");
    }
  } else {
    throw ParseException ("Unknonw file format");
  }

  mergePropertyTrees (config, readConfig);

  config.put ("configPath", file.parent_path().string() );

  fileName = fileName.substr (0, fileName.size() - extension.string().size() );
  fileName = fileName.substr (0, fileName.size() - extension2.string().size() );

  return fileName;
}
コード例 #6
0
ファイル: driver.hpp プロジェクト: purpleKarrot/Lemonade
	driver(boost::filesystem::path const& path)
		: name_{path.stem().string()}
		, library_{path.string()}
	{
		new_fn_t new_fn;
		library_.require("k_driver_new", new_fn);
		library_.require("k_driver_free", free_fn);
		impl_ = new_fn();
	}
コード例 #7
0
ファイル: main.cpp プロジェクト: WebAssembly/wasmint
    WastConverter(const std::string& outDir, const boost::filesystem::path& path) : outDir_(outDir) {
        baseName_ = path.stem().string();

        SExpr fileExpr = SExprParser::parseFile(path.string());
        for (const SExpr& child : fileExpr.children()) {
            const std::string& firstValue = child[0].value();
            if (firstValue == "module") {
                setCurrentModule(child);
            } else if (firstValue == "assert_invalid") {
                std::ofstream outStream(generateOutFile("invalid"));
                outStream << child[1].toString();
                outStream.close();
            } else if (firstValue == "assert_return_nan") {
                SExpr functionCall = convertInvoke(child[1]);
                SExpr newTest = SExprParser::parseString("if (i32.eq (i32.and () " + functionCall.toString() + ") (nop) (unreachable)");
                mainFunction_.addChild(newTest);
            } else if (firstValue == "assert_return") {
                if (child.children().size() == 2) {
                    SExpr functionCall = convertInvoke(child[1]);

                    mainFunction_.addChild(functionCall);
                } else {
                    std::string compareType = child[2][0].value().substr(0, 3);

                    SExpr functionCall = convertInvoke(child[1]);

                    SExpr newTest = SExprParser::parseString("if (" + compareType + ".eq " + functionCall.toString() + " " + child[2].toString() +") (nop) (unreachable)");
                    mainFunction_.addChild(newTest);
                }
            } else if (firstValue == "assert_trap") {
                SExpr functionCall = convertInvoke(child[1]);

                SExpr mainFunctionWithTrap = mainFunction_;
                mainFunctionWithTrap.addChild(functionCall);

                SExpr result = currentModuleExpr_;
                result.addChild(mainFunctionWithTrap);

                std::ofstream outStream(generateOutFile("trap"));
                outStream << result.toString();
                outStream.close();
            } else if (firstValue == "invoke") {
                SExpr functionCall = convertInvoke(child[1]);

                mainFunction_.addChild(functionCall);
            } else {
                std::cerr << "Can't handle assert " << child.toString() << std::endl;
            }
        }
        SExpr positiveModule = currentModuleExpr_;
        positiveModule.addChild(mainFunction_);

        std::ofstream outStream(generatePositiveOutFile("positive"));
        outStream << positiveModule.toString();
        outStream.close();
    }
コード例 #8
0
ファイル: stem.cpp プロジェクト: vinzenz/fcppt
fcppt::string
fcppt::filesystem::stem(
	boost::filesystem::path const &_path
)
{
	return
		fcppt::filesystem::path_to_string(
			_path.stem()
		);
}
コード例 #9
0
ファイル: commands.cpp プロジェクト: SiLeader/slbuild
void Compile(bool isRebuild, const slbuild::config::build_conf& bc, fs::path p, std::time_t bin_time)
{
	if(!isRebuild){
		auto src_time=fs::last_write_time(p);
		
		if(bin_time>src_time)return;
	}
	std::string ext=p.extension().string();
	slbuild::utility::replace(ext, ".", "");
	
	auto cc_itr=bc.compilers.find(ext);
	if(cc_itr==bc.compilers.end())return;
	
	std::system((bc.compilers.at(ext)+" -o obj/"+p.stem().string()+"_"+ext+".obj "+inc_and_lib()+" -c "+p.filename().string()).c_str());
}
コード例 #10
0
py::api::object InterpreterContext::import_file(boost::filesystem::path filename) {
    std::string name = filename.stem().string();

    py::list paths;
    paths.append(filename.parent_path().string());

    auto imp_module = py::import("imp");
    auto module_data = imp_module.attr("find_module")(name, paths);
    return imp_module.attr("load_module")(
               name,
               py::api::object(module_data[0]), // file
               py::api::object(module_data[1]), // pathname
               py::api::object(module_data[2])  // description
           );
}
コード例 #11
0
void SystemProcessPath::outputFileInfo( const boost::filesystem::path& rPath )
{
	std::string br = "";
	if(rPath.extension() == ".exe" || rPath.extension() == ".EXE" || rPath.extension() == ".eXE" || rPath.extension() == ".exE" || rPath.extension() == ".eXe" || rPath.extension() == ".Exe")
	{		
		br = rPath.parent_path().string();
		br += "\\";
		br += rPath.stem().string();
		br += rPath.extension().string();	

		char bh[64];
		sprintf_s(bh,"%d",iflag);
		stpath = bh;
		SystemProcessPath::mmmap.insert(std:: make_pair( SystemProcessPath::stpath,std::string(br)));
	}
}
コード例 #12
0
ScriptProperties::ScriptProperties(const boost::filesystem::path &file) {
	if (file.extension() != ".sql") {
		THROW(boost::format("Invalid file extension (should be .sql): %1%") % file.string());
	}

	const std::string stem = file.stem().string();

	const std::string targetDbVersionNum = stem.substr(0, versionLength);

	try {
		targetDbVersion = ::stringToNumber(targetDbVersionNum);
	} HANDLE_RETHROW(boost::format("Script file name should begin with a number (%1% digits): %2%") % size_t(versionLength) % file.string());

	if (stem.size() < (versionLength + 1) || (stem[versionLength] != '_')) {
		THROW(boost::format("Number in a script file name has to begin with an underscore (_): %1%") % file.string());
	}

	name = stem.substr(versionLength + 1);
}
コード例 #13
0
ファイル: hashselection.cpp プロジェクト: glocalsaint/thesis
  std::vector<string> getallfilenames(boost::filesystem::path p)
 {
     std::vector<string> filepaths;
     boost::filesystem::directory_iterator end_ptr;      
     boost::filesystem::directory_iterator dir(p);   
     for (;dir != end_ptr; dir++) {
         p = boost::filesystem::path(*dir);
         if(is_directory(p))
         {
             getallfilenames(p);
         }
         else
         {
                 string dirpath(dir->path().parent_path().string() );
                 string filename(p.stem().string());
                 filepaths.push_back(dir->path().string());
         }
     }
     return filepaths;
 }
コード例 #14
0
ファイル: hydrator.cpp プロジェクト: UHBiocomputation/neurite
model hydrator::hydrate(const boost::filesystem::path& p) const {
    const auto gs(p.generic_string());
    BOOST_LOG_SEV(lg, debug) << "Parsing file: " << gs;
    boost::filesystem::ifstream s(p);

    if (s.fail()) {
        BOOST_LOG_SEV(lg, error) << failed_to_open_file << ": " << gs;
        BOOST_THROW_EXCEPTION(hydration_error(failed_to_open_file + gs));
    }

    try {
        auto r(hydrate(s));
        r.name(p.stem().generic_string());
        BOOST_LOG_SEV(lg, debug) << "Parsed file successfully.";
        return r;
    } catch(boost::exception& e) {
        const auto s(p.generic_string());
        BOOST_LOG_SEV(lg, error) << "Failed to parse file: " << s;
        e << error_in_file(s);
        throw;
    }
}
コード例 #15
0
ファイル: client.cpp プロジェクト: RubenGarcia/Equalizer
bool Client::initLocal( const int argc, char** argv )
{
    bool isClient = false;
    std::string clientOpts;

    if( _impl->name.empty() && argc > 0 && argv )
    {
        const boost::filesystem::path prog = argv[0];
        setName( prog.stem().string( ));
    }

    for( int i=1; i<argc; ++i )
    {
        if( std::string( "--eq-client" ) == argv[i] )
        {
            isClient = true;
            if( i < argc-1 && argv[i+1][0] != '-' ) // server-started client
            {
                clientOpts = argv[++i];

                if( !deserialize( clientOpts ))
                    LBWARN << "Failed to parse client listen port parameters"
                           << std::endl;
                LBASSERT( !clientOpts.empty( ));
            }
        }
        else if( _isParameterOption( "--eq-layout", argc, argv, i ))
            _impl->activeLayouts.push_back( argv[++i] );
        else if( _isParameterOption( "--eq-gpufilter" , argc, argv, i ))
            _impl->gpuFilter = argv[ ++i ];
        else if( _isParameterOption( "--eq-modelunit", argc, argv, i ))
        {
            std::istringstream unitString( argv[++i] );
            unitString >> _impl->modelUnit;
        }
    }
コード例 #16
0
ファイル: ste_shader_factory.cpp プロジェクト: ssteinberg/ste
std::string ste_shader_factory::compile_shader(const boost::filesystem::path &path,
											   const boost::filesystem::path &source_path,
											   shader_blob_header &out) {
	out = {};
	out.magic = shader_blob_header().magic;

	const auto shader_name = path.stem();
	const auto src = compile_from_path(path, source_path, out);
	std::string temp_extension;

	switch (out.type) {
	case ste_shader_type::compute_program:
		temp_extension = ".comp";
		break;
	case ste_shader_type::fragment_program:
		temp_extension = ".frag";
		break;
	case ste_shader_type::geometry_program:
		temp_extension = ".geom";
		break;
	case ste_shader_type::vertex_program:
		temp_extension = ".vert";
		break;
	case ste_shader_type::tesselation_control_program:
		temp_extension = ".tesc";
		break;
	case ste_shader_type::tesselation_evaluation_program:
		temp_extension = ".tese";
		break;
	default:
		std::cerr << "Unknown shader type" << std::endl;
		throw std::exception((std::string("Unknown shader type ")).c_str());
	}

	return src;
}
コード例 #17
0
ファイル: main.cpp プロジェクト: HavenDV/Detector
auto	detect_file_or_url( const fs::path & file, const fs::path & saveTo, double k ) {
	auto isExists = fs::exists( file );
	auto isUrl = is_url( file );
	if ( !isExists && !isUrl ) {
		std::cout << "File or directory " << file << " not is exists" << std::endl;
		return -1;
	}

	auto outDir = saveTo.empty() ? ( file.has_parent_path() ? file.parent_path() : "./" ) : saveTo;
	if ( !isUrl ) {
		outDir /= file.stem();
	}

	if ( !fs::exists( outDir ) && !fs::create_directories( outDir ) ) {
		std::cout << "Unable to create directory " << outDir << std::endl;
		return -1;
	}

	std::cout << "Begin. k = " << k << "." << std::endl;
	std::cout << "Input " << ( isUrl ? "url" : "file" ) << " is " << file << std::endl;
	std::cout << "Files save to " << outDir << std::endl;
	
	return detect( file.string(), outDir.string(), k );
}
コード例 #18
0
ファイル: FileUtil.cpp プロジェクト: kayusawa/choreonoid
std::string getBasename(const boost::filesystem::path& path)
{
    return path.stem().string();
}
コード例 #19
0
ファイル: Source.cpp プロジェクト: Jelly-Bee/waifu2x-caffe
int main(int argc, char** argv)
{
	// definition of command line arguments
	TCLAP::CmdLine cmd("waifu2x reimplementation using Caffe", ' ', "1.0.0");

	TCLAP::ValueArg<std::string> cmdInputFile("i", "input_path",
		"path to input image file", true, "",
		"string", cmd);

	TCLAP::ValueArg<std::string> cmdOutputFile("o", "output_path",
		"path to output image file (when input_path is folder, output_path must be folder)", false,
		"(auto)", "string", cmd);

	TCLAP::ValueArg<std::string> cmdInputFileExt("l", "input_extention_list",
		"extention to input image file when input_path is folder", false, "png:jpg:jpeg:tif:tiff:bmp",
		"string", cmd);

	TCLAP::ValueArg<std::string> cmdOutputFileExt("e", "output_extention",
		"extention to output image file when output_path is (auto) or input_path is folder", false,
		"png", "string", cmd);

	std::vector<std::string> cmdModeConstraintV;
	cmdModeConstraintV.push_back("noise");
	cmdModeConstraintV.push_back("scale");
	cmdModeConstraintV.push_back("noise_scale");
	cmdModeConstraintV.push_back("auto_scale");
	TCLAP::ValuesConstraint<std::string> cmdModeConstraint(cmdModeConstraintV);
	TCLAP::ValueArg<std::string> cmdMode("m", "mode", "image processing mode",
		false, "noise_scale", &cmdModeConstraint, cmd);

	std::vector<int> cmdNRLConstraintV;
	cmdNRLConstraintV.push_back(1);
	cmdNRLConstraintV.push_back(2);
	TCLAP::ValuesConstraint<int> cmdNRLConstraint(cmdNRLConstraintV);
	TCLAP::ValueArg<int> cmdNRLevel("n", "noise_level", "noise reduction level",
		false, 1, &cmdNRLConstraint, cmd);

	TCLAP::ValueArg<double> cmdScaleRatio("s", "scale_ratio",
		"custom scale ratio", false, 2.0, "double", cmd);

	TCLAP::ValueArg<std::string> cmdModelPath("", "model_dir",
		"path to custom model directory (don't append last / )", false,
		"models", "string", cmd);

	std::vector<std::string> cmdProcessConstraintV;
	cmdProcessConstraintV.push_back("cpu");
	cmdProcessConstraintV.push_back("gpu");
	cmdProcessConstraintV.push_back("cudnn");
	TCLAP::ValuesConstraint<std::string> cmdProcessConstraint(cmdProcessConstraintV);
	TCLAP::ValueArg<std::string> cmdProcess("p", "process", "process mode",
		false, "gpu", &cmdProcessConstraint, cmd);

	TCLAP::ValueArg<int> cmdCropSizeFile("c", "crop_size",
		"input image split size", false,
		128, "int", cmd);

	TCLAP::ValueArg<int> cmdBatchSizeFile("b", "batch_size",
		"input batch size", false,
		1, "int", cmd);

	// definition of command line argument : end

	TCLAP::Arg::enableIgnoreMismatched();

	// parse command line arguments
	try
	{
		cmd.parse(argc, argv);
	}
	catch (std::exception &e)
	{
		printf("エラー: %s\n", e.what());
		return 1;
	}

	const boost::filesystem::path input_path(boost::filesystem::absolute((cmdInputFile.getValue())));

	std::string outputExt = cmdOutputFileExt.getValue();
	if (outputExt.length() > 0 && outputExt[0] != '.')
		outputExt = "." + outputExt;

	std::vector<std::pair<std::string, std::string>> file_paths;
	if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
	{
		boost::filesystem::path output_path;

		if (cmdOutputFile.getValue() == "(auto)")
		{
			// 「test」なら「test_noise_scale(Level1)(x2.000000)」みたいな感じにする

			std::string addstr("_" + cmdMode.getValue());

			const std::string &mode = cmdMode.getValue();
			if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos)
				addstr += "(Level" + std::to_string(cmdNRLevel.getValue()) + ")";
			if (mode.find("scale") != mode.npos)
				addstr += "(x" + std::to_string(cmdScaleRatio.getValue()) + ")";

			output_path = input_path.branch_path() / (input_path.stem().string() + addstr);
		}
		else
			output_path = cmdOutputFile.getValue();

		output_path = boost::filesystem::absolute(output_path);

		if (!boost::filesystem::exists(output_path))
		{
			if (!boost::filesystem::create_directory(output_path))
			{
				printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", output_path.string().c_str());
				return 1;
			}
		}

		std::vector<std::string> extList;
		{
			// input_extention_listを文字列の配列にする

			typedef boost::char_separator<char> char_separator;
			typedef boost::tokenizer<char_separator> tokenizer;

			char_separator sep(":", "", boost::drop_empty_tokens);
			tokenizer tokens(cmdInputFileExt.getValue(), sep);

			for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
				extList.push_back("." + *tok_iter);
		}

		// 変換する画像の入力、出力パスを取得
		const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const boost::filesystem::path &path)
		{
			BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path),
				boost::filesystem::recursive_directory_iterator()))
			{
				if (boost::filesystem::is_directory(p))
				{
					const auto out_relative = relativePath(p, input_path);
					const auto out_absolute = output_path / out_relative;

					if (!boost::filesystem::exists(out_absolute))
					{
						if (!boost::filesystem::create_directory(out_absolute))
						{
							printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", out_absolute.string().c_str());
							return false;
						}
					}
				}
				else if (std::find(extList.begin(), extList.end(), p.extension().string()) != extList.end())
				{
					const auto out_relative = relativePath(p, input_path);
					const auto out_absolute = output_path / out_relative;

					const auto out = (out_absolute.branch_path() / out_absolute.stem()).string() + outputExt;

					file_paths.emplace_back(p.string(), out);
				}
			}

			return true;
		};

		if (!func(input_path))
			return 1;
	}
	else
	{
コード例 #20
0
boost::filesystem::path get_relative_without_extension(const boost::filesystem::path& file,
                                                       const boost::filesystem::path& relative_to)
{
    return get_relative(file.parent_path() / file.stem(), relative_to);
}
コード例 #21
0
void workflow::
initialise_template_name(const dogen::options::stitching_options& o) {
    const boost::filesystem::path p(o.target());
    template_name_ = p.stem().filename().string();
}
コード例 #22
0
ファイル: Source.cpp プロジェクト: OasisHyde/waifu2x-caffe
int main(int argc, char** argv)
{
	Waifu2x::init_liblary(argc, argv);

	// Caffeのエラーでないログを保存しないようにする
	google::SetLogDestination(google::INFO, "");
	google::SetLogDestination(google::WARNING, "");

	// Caffeのエラーログを「error_log_〜」に出力
	google::SetLogDestination(google::ERROR, "error_log_");
	google::SetLogDestination(google::FATAL, "error_log_");

	// definition of command line arguments
	TCLAP::CmdLine cmd("waifu2x reimplementation using Caffe", ' ', "1.0.0");

	TCLAP::ValueArg<std::string> cmdInputFile("i", "input_path",
		"path to input image file", true, "",
		"string", cmd);

	TCLAP::ValueArg<std::string> cmdOutputFile("o", "output_path",
		"path to output image file (when input_path is folder, output_path must be folder)", false,
		"(auto)", "string", cmd);

	TCLAP::ValueArg<std::string> cmdInputFileExt("l", "input_extention_list",
		"extention to input image file when input_path is folder", false, "png:jpg:jpeg:tif:tiff:bmp:tga",
		"string", cmd);

	TCLAP::ValueArg<std::string> cmdOutputFileExt("e", "output_extention",
		"extention to output image file when output_path is (auto) or input_path is folder", false,
		"png", "string", cmd);

	std::vector<std::string> cmdModeConstraintV;
	cmdModeConstraintV.push_back("noise");
	cmdModeConstraintV.push_back("scale");
	cmdModeConstraintV.push_back("noise_scale");
	cmdModeConstraintV.push_back("auto_scale");
	TCLAP::ValuesConstraint<std::string> cmdModeConstraint(cmdModeConstraintV);
	TCLAP::ValueArg<std::string> cmdMode("m", "mode", "image processing mode",
		false, "noise_scale", &cmdModeConstraint, cmd);

	std::vector<int> cmdNRLConstraintV;
	cmdNRLConstraintV.push_back(1);
	cmdNRLConstraintV.push_back(2);
	cmdNRLConstraintV.push_back(3);
	TCLAP::ValuesConstraint<int> cmdNRLConstraint(cmdNRLConstraintV);
	TCLAP::ValueArg<int> cmdNRLevel("n", "noise_level", "noise reduction level",
		false, 1, &cmdNRLConstraint, cmd);

	TCLAP::ValueArg<double> cmdScaleRatio("s", "scale_ratio",
		"custom scale ratio", false, 2.0, "double", cmd);

	TCLAP::ValueArg<double> cmdScaleWidth("w", "scale_width",
		"custom scale width", false, 0, "double", cmd);

	TCLAP::ValueArg<double> cmdScaleHeight("h", "scale_height",
		"custom scale height", false, 0, "double", cmd);

	TCLAP::ValueArg<std::string> cmdModelPath("", "model_dir",
		"path to custom model directory (don't append last / )", false,
		"models/anime_style_art_rgb", "string", cmd);

	std::vector<std::string> cmdProcessConstraintV;
	cmdProcessConstraintV.push_back("cpu");
	cmdProcessConstraintV.push_back("gpu");
	cmdProcessConstraintV.push_back("cudnn");
	TCLAP::ValuesConstraint<std::string> cmdProcessConstraint(cmdProcessConstraintV);
	TCLAP::ValueArg<std::string> cmdProcess("p", "process", "process mode",
		false, "gpu", &cmdProcessConstraint, cmd);

	TCLAP::ValueArg<int> cmdOutputQuality("q", "output_quality",
		"output image quality", false,
		-1, "int", cmd);

	TCLAP::ValueArg<int> cmdOutputDepth("d", "output_depth",
		"output image chaneel depth bit", false,
		8, "int", cmd);

	TCLAP::ValueArg<int> cmdCropSizeFile("c", "crop_size",
		"input image split size", false,
		128, "int", cmd);

	TCLAP::ValueArg<int> cmdCropWidth("", "crop_w",
		"input image split size(width)", false,
		128, "int", cmd);

	TCLAP::ValueArg<int> cmdCropHeight("", "crop_h",
		"input image split size(height)", false,
		128, "int", cmd);

	TCLAP::ValueArg<int> cmdBatchSizeFile("b", "batch_size",
		"input batch size", false,
		1, "int", cmd);

	TCLAP::ValueArg<int> cmdGPUNoFile("", "gpu",
		"gpu device no", false,
		0, "int", cmd);

	std::vector<int> cmdTTAConstraintV;
	cmdTTAConstraintV.push_back(0);
	cmdTTAConstraintV.push_back(1);
	TCLAP::ValuesConstraint<int> cmdTTAConstraint(cmdTTAConstraintV);
	TCLAP::ValueArg<int> cmdTTALevel("t", "tta", "8x slower and slightly high quality",
		false, 0, &cmdTTAConstraint, cmd);

	// definition of command line argument : end

	TCLAP::Arg::enableIgnoreMismatched();

	// parse command line arguments
	try
	{
		cmd.parse(argc, argv);
	}
	catch (std::exception &e)
	{
		printf("エラー: %s\n", e.what());
		return 1;
	}

	boost::optional<double> ScaleRatio;
	boost::optional<int> ScaleWidth;
	boost::optional<int> ScaleHeight;

	int valid_num = 0;
	if (cmdScaleWidth.getValue() > 0)
		valid_num++;
	if (cmdScaleHeight.getValue() > 0)
		valid_num++;

	if (valid_num > 1)
	{
		printf("エラー: scale_widthとscale_heightは同時に指定できません\n");
		return 1;
	}

	int crop_w = cmdCropSizeFile.getValue();
	int crop_h = cmdCropSizeFile.getValue();

	if (cmdCropWidth.isSet())
		crop_w = cmdCropWidth.getValue();

	if (cmdCropHeight.isSet())
		crop_h = cmdCropHeight.getValue();

	if (cmdScaleWidth.getValue() > 0)
		ScaleWidth = cmdScaleWidth.getValue();
	else if (cmdScaleHeight.getValue() > 0)
		ScaleHeight = cmdScaleHeight.getValue();
	else
		ScaleRatio = cmdScaleRatio.getValue();

	const boost::filesystem::path input_path(boost::filesystem::absolute((cmdInputFile.getValue())));

	std::string outputExt = cmdOutputFileExt.getValue();
	if (outputExt.length() > 0 && outputExt[0] != '.')
		outputExt = "." + outputExt;

	const std::string ModelName = Waifu2x::GetModelName(cmdModelPath.getValue());

	const bool use_tta = cmdTTALevel.getValue() == 1;

	std::vector<std::pair<std::string, std::string>> file_paths;
	if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換
	{
		boost::filesystem::path output_path;

		if (cmdOutputFile.getValue() == "(auto)")
		{
			// 「test」なら「test_noise_scale(Level1)(x2.000000)」みたいな感じにする

			std::string addstr("(");
			addstr += ModelName;
			addstr += ")";

			const std::string &mode = cmdMode.getValue();

			addstr += "(" + mode + ")";

			if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos)
				addstr += "(Level" + std::to_string(cmdNRLevel.getValue()) + ")";

			if (use_tta)
				addstr += "(tta)";
			if (mode.find("scale") != mode.npos)
			{
				if(ScaleRatio)
					addstr += "(x" + std::to_string(*ScaleRatio) + ")";
				else if (ScaleWidth)
					addstr += "(width " + std::to_string(*ScaleWidth) + ")";
				else
					addstr += "(height " + std::to_string(*ScaleHeight) + ")";
			}

			if (cmdOutputDepth.getValue() != 8)
				addstr += "(" + std::to_string(cmdOutputDepth.getValue()) + "bit)";

			output_path = input_path.branch_path() / (input_path.stem().string() + addstr);
		}
		else
			output_path = cmdOutputFile.getValue();

		output_path = boost::filesystem::absolute(output_path);

		if (!boost::filesystem::exists(output_path))
		{
			if (!boost::filesystem::create_directory(output_path))
			{
				printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", output_path.string().c_str());
				return 1;
			}
		}

		std::vector<std::string> extList;
		{
			// input_extention_listを文字列の配列にする

			typedef boost::char_separator<char> char_separator;
			typedef boost::tokenizer<char_separator> tokenizer;

			char_separator sep(":", "", boost::drop_empty_tokens);
			tokenizer tokens(cmdInputFileExt.getValue(), sep);

			for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
			{
				std::string ext(*tok_iter);
				std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
				extList.push_back("." + ext);
			}
		}

		// 変換する画像の入力、出力パスを取得
		const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const boost::filesystem::path &path)
		{
			BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path),
				boost::filesystem::recursive_directory_iterator()))
			{
				if (boost::filesystem::is_directory(p))
				{
					const auto out_relative = relativePath(p, input_path);
					const auto out_absolute = output_path / out_relative;

					if (!boost::filesystem::exists(out_absolute))
					{
						if (!boost::filesystem::create_directory(out_absolute))
						{
							printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", out_absolute.string().c_str());
							return false;
						}
					}
				}
				else
				{
					std::string ext(p.extension().string());
					std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
					if (std::find(extList.begin(), extList.end(), ext) != extList.end())
					{
						const auto out_relative = relativePath(p, input_path);
						const auto out_absolute = output_path / out_relative;

						const auto out = (out_absolute.branch_path() / out_absolute.stem()).string() + outputExt;

						file_paths.emplace_back(p.string(), out);
					}
				}
			}

			return true;
		};

		if (!func(input_path))
			return 1;
	}
	else
	{
コード例 #23
0
ファイル: Information.cpp プロジェクト: Yadoms/yadoms
   CInformation::CInformation(const boost::filesystem::path& pluginPath)
      :m_path(pluginPath),
       m_isSupportedOnThisPlatform(true)
   {
      try
      {
         boost::filesystem::path packageFile;
         packageFile = m_path / "package.json";
         m_package.deserializeFromFile(packageFile.string());
      }
      catch (shared::exception::CException& e)
      {
         throw shared::exception::CInvalidParameter(pluginPath.stem().string() + std::string(" : Error reading package.json : ") + e.what());
      }

      try
      {
         // Get and check data

         m_type = m_package.get<std::string>("type");
         if (m_type.empty())
            throw shared::exception::CInvalidParameter("Error reading package.json : plugin type can not be empty");

         m_version = m_package.get<std::string>("version");
         if (m_version.empty() || !regex_match(m_version, boost::regex("\\d+.\\d+.\\d+")))
            throw shared::exception::CInvalidParameter("Error reading package.json : plugin version doesn't match expected format (x.x.x)");

         m_releaseType = m_package.get<shared::versioning::EReleaseType>("releaseType");

         m_author = m_package.get<std::string>("author");
         if (m_author.empty())
            throw shared::exception::CInvalidParameter("Error reading package.json : plugin author can not be empty");

         if (m_package.containsValue("url"))
            m_url = m_package.get<std::string>("url");   // No check on URL
         else
            m_url = shared::CStringExtension::EmptyString;

         if (m_package.containsValue("supportedPlatforms") || m_package.containsChild("supportedPlatforms"))
            m_isSupportedOnThisPlatform = tools::CSupportedPlatformsChecker::isSupported(m_package.get<shared::CDataContainer>("supportedPlatforms"));
         else
            m_isSupportedOnThisPlatform = true;


         if (m_package.containsValue("supportManuallyDeviceCreation"))
            m_supportManuallyCreatedDevice = m_package.get<bool>("supportManuallyDeviceCreation");
         else
            m_supportManuallyCreatedDevice = false;
      }
      catch (shared::exception::CException & e)
      {
         // Set plugin as not supported
         m_isSupportedOnThisPlatform = false;
         throw shared::exception::CInvalidParameter(pluginPath.stem().string() + std::string(" : Error reading package.json : data not found : ") + e.what());
      }

      auto pluginFolder = m_path.filename().string();
      if (!boost::equal(pluginFolder, m_type))
      {
         // Set plugin as not supported
         m_isSupportedOnThisPlatform = false;
         throw CInvalidPluginException(m_type, (boost::format("The plugin folder '%1%' does not match plugin type '%2%'") % pluginFolder % m_type).str());
      }
   }
コード例 #24
-1
ファイル: vrFileSystem.cpp プロジェクト: YangchenVR/libTools
		void parser_filepath(const vrString& filePath, vrString& strParentPath, vrString& strFileName, vrString& strStem, vrString& strExtension)
		{
			const fs::path p1 = filePath;
			strParentPath = p1.parent_path().string();
			strFileName = p1.filename().string();
			strExtension = p1.extension().string();
			strStem = p1.stem().string();
		}