Esempio n. 1
0
/**
 * @brief Process the difference between 2 readers and return status.
 */
EImageStatus diffImageStatus(Graph::Node& read1, Graph::Node& read2, Graph::Node& stat, Graph& graph, const bfs::path& filename1, const bfs::path& filename2)
{
	if (bfs::exists(filename1) == 0 || bfs::exists(filename2) == 0)
		return eImageStatusNoFile;

	if (bfs::file_size(filename1) == 0 || bfs::file_size(filename2) == 0)
		return eImageStatusFileSizeError;

	try
	{
		// Setup parameters
		read1.getParam("filename").setValue(filename1.string());
		read2.getParam("filename").setValue(filename2.string());
		
		if( !verbose )
			std::cout.rdbuf(0);
		graph.compute(stat);
		std::cout.rdbuf(_stdCout);
		if( verbose )
		{
			std::cout << "diff = ";
			for (unsigned int i = 0; i < 3; ++i)
			{
				std::cout << stat.getParam("quality").getDoubleValueAtIndex(i) << "  ";
			}
			std::cout << std::endl;
		}

		for (unsigned int i = 0; i < 3; ++i)
		{
			if (stat.getParam("quality").getDoubleValueAtIndex(i) != 0.0 )
				return eImageStatusDiffNotNull;
		}
		//std::cout << stat << std::endl;

		return eImageStatusDiffNull;
	}
	catch (...)
	{
		std::cerr << boost::current_exception() << std::endl;
		std::cerr << boost::current_exception_diagnostic_information() << std::endl;
		return eImageStatusImageError;
	}
}
Esempio n. 2
0
/**
 * @brief Process difference between a reader and a generator.
 */
EImageStatus diffImageStatus(Graph::Node& read1, Graph::Node& read2, Graph::Node& stat, Graph& graph, const bfs::path& filename, const std::vector<std::string>& generatorOptions )
{
	if ( ! bfs::exists(filename))
		return eImageStatusNoFile;

	if ( bfs::file_size(filename) == 0 )
		return eImageStatusFileSizeError;

	try
	{
		// Setup parameters
		read1.getParam("filename").setValue(filename.string());
		for( size_t i=0; i<generatorOptions.size(); i++ )
		{
			std::vector<std::string> opt;
			boost::split(opt, generatorOptions.at(i), boost::is_any_of("="));
			int optvalue = atoi ( opt.at(1).c_str() );
			if( optvalue == 0 )
			{
				std::vector<std::string> optList;
				boost::split(optList, opt.at(1), boost::is_any_of(","));
				switch( optList.size() )
				{
					case 1 :
					{ // not a number, set a string parameter
						read2.getParam(opt.at(0)).setValue( opt.at(1) );
						break;
					}
					case 2 :
					{
						float opt0 = atof ( optList.at(0).c_str() );
						float opt1 = atof ( optList.at(1).c_str() );
						read2.getParam(opt.at(0)).setValue( opt0, opt1 );
						break;
					}
					case 3 :
					{
						float opt0 = atof ( optList.at(0).c_str() );
						float opt1 = atof ( optList.at(1).c_str() );
						float opt2 = atof ( optList.at(2).c_str() );
						read2.getParam(opt.at(0)).setValue( opt0, opt1, opt2 );
						break;
					}/*
					case 4 :
					{
						double opt0 = atof ( optList.at(0).c_str() );
						double opt1 = atof ( optList.at(1).c_str() );
						double opt2 = atof ( optList.at(2).c_str() );
						//double opt3 = atof ( optList.at(3).c_str() );
						read2.getParam(opt.at(0)).setValue( opt0, opt1, opt2 );
					}*/
					default :
					{
						for(size_t i=0; i<opt.size(); i++)
								TUTTLE_COUT_VAR(opt.at(i));
						TUTTLE_COUT("ERROR: unable to process " << optList.size() << " arguments");
						break;
					}
				}

				
			}
			else
			{
				read2.getParam(opt.at(0)).setValue( optvalue );
			}
		}

		if( !verbose )
			std::cout.rdbuf(0);
		graph.compute(stat);
		std::cout.rdbuf(_stdCout);

		if( verbose )
		{
			std::cout << "diff = ";
			for (unsigned int i = 0; i < 3; ++i)
			{
				std::cout << stat.getParam("quality").getDoubleValueAtIndex(i) << "  ";
			}
			std::cout << std::endl;
		}

		for (unsigned int i = 0; i < 3; ++i)
		{
			if (stat.getParam("quality").getDoubleValueAtIndex(i) != 0.0 )
				return eImageStatusDiffNotNull;
		}
		//std::cout << stat << std::endl;

		return eImageStatusDiffNull;
    }
	catch (...)
	{
		std::cerr << boost::current_exception() << std::endl;
		std::cerr << boost::current_exception_diagnostic_information() << std::endl;
		return eImageStatusImageError;
	}
}