Esempio n. 1
0
File: Grid.cpp Progetto: Danvil/dasp
std::vector<Eigen::Vector2f> RectGrid(const Eigen::MatrixXf& density)
{
	const float width = static_cast<float>(density.rows());
	const float height = static_cast<float>(density.cols());
	const float numf = density.sum();
	const float d = std::sqrt(float(width*height) / numf);
	const unsigned int Nx = static_cast<unsigned int>(std::ceil(width / d));
	const unsigned int Ny = static_cast<unsigned int>(std::ceil(height / d));
	const float Dx = width / static_cast<float>(Nx);
	const float Dy = height / static_cast<float>(Ny);
	const float Hx = Dx/2.0f;
	const float Hy = Dy/2.0f;

	std::vector<Eigen::Vector2f> seeds;
	seeds.reserve(Nx*Ny);
	for(unsigned int iy=0; iy<Ny; iy++) {
		float y = Hy + Dy * static_cast<float>(iy);
		for(unsigned int ix=0; ix<Nx; ix++) {
			float x = Hx + Dx * static_cast<float>(ix);
			seeds.push_back(Eigen::Vector2f(x, y));
		}
	}

	return seeds;
}
Esempio n. 2
0
File: main.cpp Progetto: Danvil/dasp
int main(int argc, char** argv)
{
	std::string p_density = "";
	std::string p_mode = "spds";
	std::string p_out = "pnts.tsv";
	unsigned p_size = 128;
	unsigned p_num = 250;

	namespace po = boost::program_options;
	po::options_description desc;
	desc.add_options()
		("help", "produce help message")
		("density", po::value(&p_density), "density function image (leave empty for test function)")
		("mode", po::value(&p_mode), "sampling method")
		("out", po::value(&p_out), "filename of result file with samples points")
		("size", po::value(&p_size), "size of image in pixel")
		("num", po::value(&p_num), "number of points to sample")
	;

	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
	if(vm.count("help")) {
		std::cerr << desc << std::endl;
		return 1;
	}

	Eigen::MatrixXf rho;
	if(p_density.empty()) {
		rho = TestDensity(p_size, p_num);
		std::cout << "Created density dim=" << rho.rows() << "x" << rho.cols() << ", sum=" << rho.sum() << "." << std::endl;
	}
	else {
		rho = density::LoadDensity(p_density);
		std::cout << "Loaded density dim=" << rho.rows() << "x" << rho.cols() << ", sum=" << rho.sum() << "." << std::endl;
	}

	// scale density
	float scl = static_cast<float>(p_num) / rho.sum();
	rho *= scl;

	std::vector<Eigen::Vector2f> pnts;
	{
		boost::timer::auto_cpu_timer t;
		pnts = pds::PoissonDiscSampling(p_mode, rho);
	}
	std::cout << "Generated " << pnts.size() << " points." << std::endl;

	std::ofstream ofs(p_out);
	for(const Eigen::Vector2f& x : pnts) {
		ofs << x[0] << "\t" << x[1] << std::endl;
	}
	std::cout << "Wrote points to file '" << p_out << "'." << std::endl;

	return 1;
}
Esempio n. 3
0
File: main.cpp Progetto: sh0/dasp
int main(int argc, char** argv)
{
	std::string p_feature_img = "";
	std::string p_density = "";
	std::string p_fn_points = "";
	std::string p_out = "";
	unsigned p_num = 250;
	bool p_verbose = false;
	unsigned p_repetitions = 1;
	bool p_error = false;
	bool p_save_density = true;

	// parameters
	asp::Parameters params = asp::parameters_default();

	namespace po = boost::program_options;
	po::options_description desc;
	desc.add_options()
		("help", "produce help message")
		("features", po::value(&p_feature_img), "feature image (leave empty for uniform image)")
		("density", po::value(&p_density), "density function image (leave empty for test function)")
		("points", po::value(&p_fn_points), "file with points to use as seeds (for DDS)")
		("out", po::value(&p_out), "filename of result file with samples points")
		("num", po::value(&p_num), "number of points to sample")
		("p_num_iterations", po::value(&params.num_iterations), "number of DALIC iterations")
		("p_pds_mode", po::value(&params.pds_mode), "Poisson Disk Sampling method")
		("p_seed_mean_radius_factor", po::value(&params.seed_mean_radius_factor), "size factor for initial cluster mean feature")
		("p_coverage", po::value(&params.coverage), "DALIC cluster search factor")
		("p_weight_compact", po::value(&params.weight_compact), "weight for compactness term")
		("verbose", po::value(&p_verbose), "verbose")
		("repetitions", po::value(&p_repetitions), "repetitions")
		("error", po::value(&p_error), "error")
		("save_density", po::value(&p_save_density), "save_density")
	;

	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
	if(vm.count("help")) {
		std::cerr << desc << std::endl;
		return 1;
	}


	// load

	bool is_features_null = p_feature_img.empty();
	bool is_density_null = p_density.empty();

	Eigen::MatrixXf rho;
	std::vector<Eigen::Vector3f> features;
	int width = -1, height = -1;

	if(is_density_null && is_features_null) {
		std::cerr << "ERROR feature or density must not be both empty!" << std::endl;
		return 1;
	}
	if(!is_features_null) {
		features = LoadFeatures(p_feature_img, width, height);
		if(p_verbose) std::cout << "Loaded features dim=" << width << "x" << height << "." << std::endl;
	}
	if(!is_density_null) {
		rho = density::LoadDensity(p_density);
		if(p_verbose) std::cout << "Loaded density dim=" << rho.rows() << "x" << rho.cols() << ", sum=" << rho.sum() << "." << std::endl;
	}
	if(is_features_null) {
		width = rho.rows();
		height = rho.cols();
		features.resize(width*height, Eigen::Vector3f{1,1,1});
		if(p_verbose) std::cout << "Created uniform features dim=" << rho.rows() << "x" << rho.cols() << "." << std::endl;
	}
	if(is_density_null) {
		//rho = CreateDensity(p_size, p_size, [](float x, float y) { return TestDensityFunction(x,y); } );
		rho = CreateDensity(width, height, [](float x, float y) { return 1.0f; } );
		if(p_verbose) std::cout << "Created density dim=" << rho.rows() << "x" << rho.cols() << ", sum=" << rho.sum() << "." << std::endl;
	}
	assert(width == rho.rows());
	assert(height == rho.cols());

	std::vector<Eigen::Vector2f> seed_points;
	if(!p_fn_points.empty()) {
		std::ifstream ifs(p_fn_points);
		if(!ifs.is_open()) {
			std::cerr << "Error opening file '" << p_fn_points << "'" << std::endl;
		}
		std::string line;
		while(getline(ifs, line)) {
			std::istringstream ss(line);
			std::vector<float> q;
			while(!ss.eof()) {
				float v;
				ss >> v;
				q.push_back(v);
			}
			seed_points.push_back({q[0], q[1]});
		}
	}
Esempio n. 4
0
File: main.cpp Progetto: Danvil/dasp
int main(int argc, char** argv)
{
	std::string p_in = "";
	std::string p_out = "out.tsv";

	namespace po = boost::program_options;
	po::options_description desc;
	desc.add_options()
		("help", "produce help message")
		("density", po::value(&p_in), "filename for input density")
		("out", po::value(&p_out), "filename for smoothed output density")
	;

	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);
	if(vm.count("help")) {
		std::cerr << desc << std::endl;
		return 1;
	}

	Eigen::MatrixXf rho = density::LoadDensity(p_in);
	std::cout << "Loaded density dim=" << rho.rows() << "x" << rho.cols() << ", sum=" << rho.sum() << "." << std::endl;

	Eigen::MatrixXf result;
	{
		boost::timer::auto_cpu_timer t;
		result = density::DensityAdaptiveSmooth(rho);
	}

	density::SaveDensity(p_out, result);
	std::cout << "Wrote result to file '" << p_out << "'." << std::endl;

	return 1;
}