void
mux_dialog::on_abort(wxCommandEvent &) {
#if defined(SYS_WINDOWS)
  if (m_abort_button_changed) {
    wxFileName output_file_name(static_cast<mmg_dialog *>(GetParent())->tc_output->GetValue());
    wxExecute(wxString::Format(wxT("explorer \"%s\""), output_file_name.GetPath().c_str()));
    return;
  }

  change_abort_button();
#else
  if (m_abort_button_changed)
    return;

  m_abort_button_changed = true;

  b_abort->Enable(false);
#endif

  b_ok->Enable(true);
  b_ok->SetFocus();

#if defined(SYS_WINDOWS)
  wxKill(m_pid, wxSIGKILL);
#else
  wxKill(m_pid, wxSIGTERM);
#endif
}
Beispiel #2
0
int main()
{
	string input_file_name("seed.txt");
	string output_file_name("crawled_links.txt");
	CCrawl crawl(input_file_name.c_str(),output_file_name.c_str());
	
	crawl.DoCrawl();
}
Beispiel #3
0
static FILE *
open_output_file		(vbi_pgno		pgno,
				 vbi_subno		subno)
{
	char *name;
	FILE *fp;

	if (NULL == out_file_name_prefix)
		return stdout;

	name = output_file_name (pgno, subno);

	fp = fopen (name, "w");
	if (NULL == fp) {
		error_exit (_("Could not open "
			      "output file '%s': %s."),
			    name, strerror (errno));
	}

	free (name);

	return fp;
}
Beispiel #4
0
static void
do_export			(vbi_pgno		pgno,
				 vbi_subno		subno,
				 double			timestamp)
{
	vbi_page *pg;
	vbi_bool success;

	if (option_delay > 1) {
		--option_delay;
		return;
	}

	if (pgno >= 0x100) {
		if (0 != option_override_cs) {
			pg = vbi_decoder_get_page
				(vbi, NULL /* current network */,
				 pgno, subno,
				 VBI_HEADER_ONLY, option_header_only, 
				 VBI_PADDING, option_padding,
				 VBI_PANELS, option_panels,
				 VBI_NAVIGATION, option_navigation,
				 VBI_HYPERLINKS, option_hyperlinks,
				 VBI_PDC_LINKS, option_pdc_links,
				 VBI_WST_LEVEL, VBI_WST_LEVEL_3p5,
				 VBI_OVERRIDE_CHARSET_0, option_override_cs,
				 VBI_END);
		} else {
			pg = vbi_decoder_get_page
				(vbi, NULL /* current network */,
				 pgno, subno,
				 VBI_HEADER_ONLY, option_header_only, 
				 VBI_PADDING, option_padding,
				 VBI_PANELS, option_panels,
				 VBI_NAVIGATION, option_navigation,
				 VBI_HYPERLINKS, option_hyperlinks,
				 VBI_PDC_LINKS, option_pdc_links,
				 VBI_WST_LEVEL, VBI_WST_LEVEL_3p5,
				 VBI_DEFAULT_CHARSET_0, option_default_cs,
				 VBI_END);
		}
	} else {
		pg = vbi_decoder_get_page
			(vbi, NULL /* current network */,
			 pgno, subno,
			 VBI_PADDING, option_padding,
			 VBI_DEFAULT_FOREGROUND, option_default_fg,
			 VBI_DEFAULT_BACKGROUND, option_default_bg,
			 VBI_ROW_CHANGE, option_row_update,
			 VBI_END);
	}

	assert (NULL != pg);

	if (option_dump_pg) {
		page_dump (pg);
	}

	switch (option_target) {
		char *file_name;
		void *buffer;
		void *buffer2;
		FILE *fp;
		size_t size;
		ssize_t ssize;

	case 1:
		buffer = malloc (1 << 20);
		if (NULL == buffer)
			no_mem_exit ();
		ssize = vbi_export_mem (ex, buffer, 1 << 20, pg);
		success = (ssize >= 0);
		if (success) {
			ssize_t ssize2;

			fp = open_output_file (pgno, subno);
			if (1 != fwrite (buffer, ssize, 1, fp))
				write_error_exit (/* msg: errno */ NULL);
			close_output_file (fp);

			/* Test. */
			ssize2 = vbi_export_mem (ex, buffer, 0, pg);
			assert (ssize == ssize2);
			assert (ssize > 0);
			ssize2 = vbi_export_mem (ex, buffer, ssize - 1, pg);
			assert (ssize == ssize2);
		}
		free (buffer);
		break;

	case 2:
		buffer = NULL;
		buffer2 = vbi_export_alloc (ex, &buffer, &size, pg);
		/* Test. */
		assert (buffer == buffer2);
		success = (NULL != buffer);
		if (success) {
			fp = open_output_file (pgno, subno);
			if (1 != fwrite (buffer, size, 1, fp))
				write_error_exit (/* msg: errno */ NULL);
			close_output_file (fp);
			free (buffer);
		}
		break;

	case 3:
		/* This is the default target. The other cases are only
		   implemented for tests and will be removed when I
		   wrote proper unit tests. */

	fp = open_output_file (pgno, subno);

	/* For proper timing of subtitles. */
	vbi_export_set_timestamp (ex, timestamp);

		success = vbi_export_stdio (ex, fp, pg);

		close_output_file (fp);

		break;

	case 5:
		file_name = output_file_name (pgno, subno);
		success = vbi_export_file (ex, file_name, pg);
		free (file_name);
		break;

	default:
		error_exit ("Invalid target %u.", option_target);
		break;
	}

	if (!success) {
		error_exit (_("Export of page %x failed: %s"),
			    pgno,
			    vbi_export_errstr (ex));
	}

	if (option_pdc_enum) {
		pdc_dump (pg);
	}

	vbi_page_delete (pg);
	pg = NULL;
}
Beispiel #5
0
static void
do_export			(vbi_pgno		pgno,
				 vbi_subno		subno)
{
	vbi_page page;
	vbi_bool success;

	if (option_delay > 1) {
		--option_delay;
		return;
	}

	success = vbi_fetch_vt_page (vbi, &page,
				     pgno, subno,
				     VBI_WST_LEVEL_3p5,
				     /* n_rows */ 25,
				     /* navigation */ TRUE);
	if (!success) {
		/* Shouldn't happen. */
		error_exit (_("Unknown error."));
	}

	if (option_dump_pg) {
		page_dump (&page);
	}

	switch (option_target) {
		char *file_name;
		void *buffer;
		void *buffer2;
		FILE *fp;
		size_t size;
		ssize_t ssize;

	case 1:
		buffer = malloc (1 << 20);
		if (NULL == buffer)
			no_mem_exit ();
		ssize = vbi_export_mem (ex, buffer, 1 << 20, &page);
		success = (ssize >= 0);
		if (success) {
			ssize_t ssize2;

			fp = open_output_file (pgno, subno);
			if (1 != fwrite (buffer, ssize, 1, fp))
				write_error_exit (/* msg: errno */ NULL);
			close_output_file (fp);

			/* Test. */
			ssize2 = vbi_export_mem (ex, buffer, 0, &page);
			assert (ssize == ssize2);
			assert (ssize > 0);
			ssize2 = vbi_export_mem (ex, buffer, ssize - 1, &page);
			assert (ssize == ssize2);
		}
		free (buffer);
		break;

	case 2:
		buffer = NULL;
		buffer2 = vbi_export_alloc (ex, &buffer, &size, &page);
		/* Test. */
		assert (buffer == buffer2);
		success = (NULL != buffer);
		if (success) {
			fp = open_output_file (pgno, subno);
			if (1 != fwrite (buffer, size, 1, fp))
				write_error_exit (/* msg: errno */ NULL);
			close_output_file (fp);
			free (buffer);
		}
		break;

	case 3:
		/* This is the default target. The other cases are only
		   implemented for tests and will be removed when I
		   wrote proper unit tests. */

		fp = open_output_file (pgno, subno);
		success = vbi_export_stdio (ex, fp, &page);
		close_output_file (fp);
		break;

	case 5:
		file_name = output_file_name (pgno, subno);
		success = vbi_export_file (ex, file_name, &page);
		free (file_name);
		break;

	default:
		error_exit ("Invalid target %u.", option_target);
		break;
	}

	if (!success) {
		error_exit (_("Export of page %x failed: %s"),
			    pgno,
			    vbi_export_errstr (ex));
	}

	vbi_unref_page (&page);
}
Beispiel #6
0
int main (int argc, char *argv[]) {
    try {
        LogPolicy::GetInstance().Unmute();
        double startup_time = get_timestamp();

        boost::filesystem::path config_file_path, input_path, profile_path;
        int requested_num_threads;

        // declare a group of options that will be allowed only on command line
        boost::program_options::options_description generic_options("Options");
        generic_options.add_options()
            ("version,v", "Show version")
            ("help,h", "Show this help message")
            ("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("extractor.ini"),
                  "Path to a configuration file.");

        // declare a group of options that will be allowed both on command line and in config file
        boost::program_options::options_description config_options("Configuration");
        config_options.add_options()
            ("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
                "Path to LUA routing profile")
            ("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
                "Number of threads to use");

        // hidden options, will be allowed both on command line and in config file, but will not be shown to the user
        boost::program_options::options_description hidden_options("Hidden options");
        hidden_options.add_options()
            ("input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
                "Input file in .osm, .osm.bz2 or .osm.pbf format");

        // positional option
        boost::program_options::positional_options_description positional_options;
        positional_options.add("input", 1);

        // combine above options for parsing
        boost::program_options::options_description cmdline_options;
        cmdline_options.add(generic_options).add(config_options).add(hidden_options);

        boost::program_options::options_description config_file_options;
        config_file_options.add(config_options).add(hidden_options);

        boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
        visible_options.add(generic_options).add(config_options);

        // parse command line options
        boost::program_options::variables_map option_variables;
        boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
            options(cmdline_options).positional(positional_options).run(), option_variables);

        if(option_variables.count("version")) {
            SimpleLogger().Write() << g_GIT_DESCRIPTION;
            return 0;
        }

        if(option_variables.count("help")) {
            SimpleLogger().Write() << visible_options;
            return 0;
        }

        boost::program_options::notify(option_variables);

        // parse config file
        if(boost::filesystem::is_regular_file(config_file_path)) {
            SimpleLogger().Write() << "Reading options from: " << config_file_path.c_str();
            std::string config_str;
            PrepareConfigFile( config_file_path.c_str(), config_str );
            std::stringstream config_stream( config_str );
            boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables);
            boost::program_options::notify(option_variables);
        }

        if(!option_variables.count("input")) {
            SimpleLogger().Write(logWARNING) << "No input file specified";
            SimpleLogger().Write() << visible_options;
            return -1;
        }

        if(1 > requested_num_threads) {
            SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
            return -1;
        }

        SimpleLogger().Write() << "Input file: " << input_path.filename().string();
        SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
        SimpleLogger().Write() << "Threads: " << requested_num_threads;

        /*** Setup Scripting Environment ***/
        ScriptingEnvironment scriptingEnvironment(profile_path.c_str());

        omp_set_num_threads( std::min( omp_get_num_procs(), requested_num_threads) );

        bool file_has_pbf_format(false);
        std::string output_file_name(input_path.c_str());
        std::string restrictionsFileName(input_path.c_str());
        std::string::size_type pos = output_file_name.find(".osm.bz2");
        if(pos==std::string::npos) {
            pos = output_file_name.find(".osm.pbf");
            if(pos!=std::string::npos) {
                file_has_pbf_format = true;
            }
        }
        if(pos==std::string::npos) {
            pos = output_file_name.find(".pbf");
            if(pos!=std::string::npos) {
                file_has_pbf_format = true;
            }
        }
        if(pos!=std::string::npos) {
            output_file_name.replace(pos, 8, ".osrm");
            restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
        } else {
            pos=output_file_name.find(".osm");
            if(pos!=std::string::npos) {
                output_file_name.replace(pos, 5, ".osrm");
                restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
            } else {
                output_file_name.append(".osrm");
                restrictionsFileName.append(".osrm.restrictions");
            }
        }

        StringMap stringMap;
        ExtractionContainers externalMemory;

        stringMap[""] = 0;
        extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
        BaseParser* parser;
        if(file_has_pbf_format) {
            parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
        } else {
            parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
        }

        if(!parser->ReadHeader()) {
            throw OSRMException("Parser not initialized!");
        }
        SimpleLogger().Write() << "Parsing in progress..";
        double parsing_start_time = get_timestamp();
        parser->Parse();
        SimpleLogger().Write() << "Parsing finished after " <<
            (get_timestamp() - parsing_start_time) <<
            " seconds";

        if( externalMemory.all_edges_list.empty() ) {
            SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
            return -1;
        }

        externalMemory.PrepareData(output_file_name, restrictionsFileName);

        delete parser;
        delete extractCallBacks;

        SimpleLogger().Write() <<
            "extraction finished after " << get_timestamp() - startup_time <<
            "s";

         SimpleLogger().Write() << "To prepare the data for routing, run: "
            << "./osrm-prepare " << output_file_name << std::endl;

    } catch(boost::program_options::too_many_positional_options_error& e) {
        SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
        return -1;
    } catch(boost::program_options::error& e) {
        SimpleLogger().Write(logWARNING) << e.what();
        return -1;
    } catch(std::exception & e) {
        SimpleLogger().Write(logWARNING) << "Unhandled exception: " << e.what();
        return -1;
    }
    return 0;
}
Beispiel #7
0
int main(int argc, char** argv)
{
  if(argc != 5)
  {
    printUsage(argv[0]);
    return(0);
  }
  
  srand ( time(NULL) );
  
  std::string image_name(argv[1]);
  std::string saliency_map_name(argv[2]);
  std::string output_file_name(argv[3]);
  std::string output_png_name(argv[4]);
    
  cv::Mat image = cv::imread(image_name,-1);
  cv::Mat map = cv::imread(saliency_map_name,-1);
  map.convertTo(map,CV_32F,1.0f/255);
    
  std::vector<v4r::ConnectedComponent> connectedComponents;
    
  float th = 0.1;
  v4r::extractConnectedComponents(map,connectedComponents,th);
  v4r::drawConnectedComponents(connectedComponents,image,cv::Scalar(255,0,0));
  //std::cerr << "Number of connected components: " << connectedComponents.size() << std::endl;
    
  std::vector<v4r::SaliencyLine> saliencyLine;
  cv::Mat points_image = cv::Mat_<uchar>::zeros(image.rows,image.cols);
  std::vector<v4r::PointSaliency> saliencyPoints;
    
  for(unsigned int i = 0; i < connectedComponents.size(); ++ i)
  {
    //std::cerr << i << " " << connectedComponents.size() << std::endl;
    cv::Mat mask = cv::Mat_<uchar>::zeros(image.rows,image.cols);
    v4r::drawConnectedComponent(connectedComponents.at(i),mask,cv::Scalar(1));
    //cv::imshow("mask",255*mask);
    //cv::waitKey();
      
    v4r::SaliencyLine saliencyLineCurent;
    v4r::PointSaliency pointSaliencyCurrent;
    //std::cerr << "here 0" << std::endl;
    if(v4r::extractSaliencyLine(mask,map,saliencyLineCurent))
    {
      //std::vector<cv::Point> saliencyLineCurent_points;
      //v4r::createSimpleLine(saliencyLineCurent,saliencyLineCurent_points);
      //std::cerr << saliencyLineCurent_points.size() << std::endl;
      //v4r::drawAttentionPoints(image,saliencyLineCurent_points);
      //cv::imshow("skeleton",image);
      //cv::waitKey();
      
      saliencyLine.push_back(saliencyLineCurent);
      //std::cerr << "here 1" << std::endl;
      v4r::selectSaliencyCenterPoint(saliencyLineCurent,pointSaliencyCurrent);
      //std::cerr << "here 2" << std::endl;
      saliencyPoints.push_back(pointSaliencyCurrent);
      
    }
    //std::cerr << "here 3" << std::endl;
  }
    
  std::sort(saliencyPoints.begin(),saliencyPoints.end(),v4r::saliencyPointsSort);
    
  std::vector<cv::Point> attentionPoints;
  v4r::createAttentionPoints(saliencyPoints,attentionPoints);
  
  v4r::writeAttentionPoints(attentionPoints,output_file_name);
  
  v4r::drawAttentionPoints(image,attentionPoints,10);
  
  cv::imwrite(output_png_name,image);
  
  //cv::imshow("attention points", image);
  //cv::imshow("saliency map", map);
  //cv::waitKey();
}