Exemplo n.º 1
0
    result test(std::string const & name, mapnik::Map const & map, double scale_factor) const
    {
        typename Renderer::image_type image(ren.render(map, scale_factor));
        boost::filesystem::path reference = reference_dir / image_file_name(name, map.width(), map.height(), scale_factor, true, Renderer::ext);
        bool reference_exists = boost::filesystem::exists(reference);
        result res;

        res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
        res.name = name;
        res.renderer_name = Renderer::name;
        res.scale_factor = scale_factor;
        res.size = map_size(map.width(), map.height());
        res.reference_image_path = reference;
        res.diff = reference_exists ? ren.compare(image, reference) : 0;

        if (res.diff)
        {
            boost::filesystem::create_directories(output_dir);
            boost::filesystem::path path = output_dir / image_file_name(name, map.width(), map.height(), scale_factor, false, Renderer::ext);
            res.actual_image_path = path;
            res.state = STATE_FAIL;
            ren.save(image, path);
        }

        if ((res.diff && overwrite) || !reference_exists)
        {
            ren.save(image, reference);
            res.state = STATE_OVERWRITE;
        }

        return res;
    }
Exemplo n.º 2
0
    result report(image_type const & image,
                  std::string const & name,
                  map_size const & size,
                  map_size const & tiles,
                  double scale_factor) const
    {
        boost::filesystem::path reference = reference_dir / image_file_name(name, size, tiles, scale_factor, true);
        bool reference_exists = boost::filesystem::exists(reference);
        result res;

        res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
        res.name = name;
        res.renderer_name = Renderer::name;
        res.scale_factor = scale_factor;
        res.size = size;
        res.tiles = tiles;
        res.reference_image_path = reference;
        res.diff = reference_exists ? ren.compare(image, reference) : 0;

        if (res.diff)
        {
            boost::filesystem::create_directories(output_dir);
            boost::filesystem::path path = output_dir / image_file_name(name, size, tiles, scale_factor, false);
            res.actual_image_path = path;
            res.state = STATE_FAIL;
            ren.save(image, path);
        }

        if ((res.diff && overwrite) || !reference_exists)
        {
            ren.save(image, reference);
            res.state = STATE_OVERWRITE;
        }

        return res;
    }
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	Globals globales;
	clock_t render_ticks;
            //tInitDataTicks,
            //tCleanDataTicks;
    std::string scene_desc_file,
                output_file,
                output_file_dir,
                output_file_path;

    // Redirigimos std::clog a un archivo de texto.
    CLog_Redir  clogredir("log.txt");

    // Y configuramos el logger.
    LOGCFG.headers  = true;
    LOGCFG.level    = DEBUG;

    bool end_status;

    LOG() << "main - Comprobando argumentos.";

	if(argc > 1) {
		for(int i = 1; i < argc; ++i) {
			if(argv[i][0] == '-') { // Procesamos las opciones.
				if(std::string(argv[i]) == "-h" || std::string(argv[i]) == "--help") {
					muestra_ayuda(argv[0]);
					return 0;
				}
				else if(std::string(argv[i]) == "-t" || std::string(argv[i]) == "--test") {
					globales.options |= Global_opts::kglb_do_test;
				}
				else if(std::string(argv[i]) == "-s" || std::string(argv[i]) == "--showaabb") {
					globales.options |= Global_opts::kglb_show_aabb;
				}
				else if(std::string(argv[i]) == "-c" || std::string(argv[i]) == "--contrib") {
					globales.options |= Global_opts::kglb_do_contrib;
				}
			}
			else {
				// Se proporciona fichero, anulamos el test.
				globales.options &= ~Global_opts::kglb_do_test;

				if(scene_desc_file.empty())
					// Fichero de escena a renderizar
					scene_desc_file.assign(argv[i]);
				else
					// Fichero donde guardar la imagen
					output_file.assign(argv[i]);
			}
		}
	}

	LOG() << "main -    ... hecho.";

	if((scene_desc_file.empty() || (argc < 2)) && !(globales.options & Global_opts::kglb_do_test)) {
		muestra_ayuda(argv[0]);
		return 0;
	}
	else {

        if(globales.options & Global_opts::kglb_do_test) {
            Test test;
            end_status = test.launch_test();
        }
        else {
            LOG() << "main - Leyendo archivo...";
            end_status = parse_file(&globales, scene_desc_file);
            LOG() << "main -     ... hecho.";
            if(end_status) {
                render_ticks = clock();

                // Start render loop
                if(globales.options & Global_opts::kglb_do_contrib)
                    end_status = start_render_v2(&globales);
                else
                    end_status = start_render(&globales);

                render_ticks = clock() - render_ticks;

                print_time("\n\nRender Time: ", static_cast<float>(render_ticks)/CLOCKS_PER_SEC);
                print_statistics();

                if(output_file.empty()) {
                    std::string	temp;

                    // Averiguamos el nombre del fichero.
                    image_file_name(scene_desc_file, temp);

                    // Añadimos la extension.
                    output_file         = temp + ".ppm";
                    output_file_dir     = temp + "_dir.ppm";
                    output_file_path    = temp + "_path.ppm";
                }

                if(globales.options & Global_opts::kglb_do_contrib)
                    globales.image->create_final_img();

                globales.image->gamma_correct(2.2f);

                save_file(&globales, output_file, 0);

                if(globales.options & Global_opts::kglb_do_contrib) {
                    save_file(&globales, output_file_dir, 1);
                    save_file(&globales, output_file_path, 2);
                }
            }
        }
    }

	if(end_status)
		return 0;
	else
		return -1;
}