示例#1
0
bool FileHelper::load_file_house_back(const string pcap_file, list< uint64_t>& stamps){
    string file_path = pcap_file + "_houseback.txt";
    fstream in_file(file_path);
    if (!in_file.good()) {
        cout << "file house back empty :" << file_path << endl;
        return false;
    }
    int pointcount = 0;
    double tempTime = 0.0;
    string str_line;
    vector< string> arr_strs;
    uint64_t stamp = 0;
    int frame = 0;
    while (!in_file.eof()) {
        getline(in_file, str_line, '\n');
		if(in_file.fail())  
        {  
			in_file.clear(in_file.rdstate() & ~(ifstream::failbit));  
        }  
        stringstream stream;
        stream << str_line;
        stream >> stamp;
        if (stamp != 0) {
            stamps.push_back(stamp);
        }
    }
    in_file.close();

    return true;
}
示例#2
0
bool FileHelper::load_file_glass(const string pcap_file, 
    map< uint64_t, uint64_t>& intensity){
    string file_path = pcap_file + "_glass.txt";
    fstream in_file(file_path);
    if (!in_file.good()) {
        cout << "file house back empty :" << file_path << endl;
        return false;
    }
    int pointcount = 0;
    double tempTime = 0.0;
    string str_line;
    vector< string> arr_strs;
    uint64_t stamp = 0;
    int frame = 0;
    while (!in_file.eof()) {
        getline(in_file, str_line, '\n');
		if(in_file.fail())  
        {  
			in_file.clear(in_file.rdstate() & ~(ifstream::failbit));  
        }  
        arr_strs = StringHelper::split(std::string(str_line), " ");
        if (arr_strs.size() == 2) {
            stringstream stream;
            stream << arr_strs[0];
            stream >> stamp;
            if (stamp != 0) {
                stream.clear();
                stream << arr_strs[1];
                stream >> intensity[stamp];
            }
        }
示例#3
0
void 
Printer::initUserSections(const char* name) 
{
	user_sections_.clear();
	std::ifstream in_file(name);
	if(!in_file) {
		return;
	}

	std::string section;
	std::string section_name;
	std::string line;
	while(std::getline(in_file, line)) {
		if(!line.compare( 0, 29, "// BEGIN USER INSERT SECTION " ))	{
			section_name = line.substr( 29 );
		
			while(std::getline( in_file, line )) {
				if(!line.compare( 0, 27, "// END USER INSERT SECTION " )) {
					user_sections_[section_name] = section;
					section = "";
					break;
				}
				section.append(line);
				section.append("\n");
			}
		}
	}

	in_file.close();
}
示例#4
0
文件: utility.cpp 项目: salilab/imp
void read_files(Model *m, const std::vector<std::string>& files,
                std::vector<std::string>& pdb_file_names,
                std::vector<std::string>& dat_files,
                std::vector<IMP::Particles>& particles_vec,
                Profiles& exp_profiles, bool residue_level,
                bool heavy_atoms_only, int multi_model_pdb,
                bool explicit_water, float max_q, int units) {

  for (unsigned int i = 0; i < files.size(); i++) {
    // check if file exists
    std::ifstream in_file(files[i].c_str());
    if (!in_file) {
      IMP_WARN("Can't open file " << files[i] << std::endl);
      return;
    }
    // 1. try as pdb
    try {
      read_pdb(m, files[i], pdb_file_names, particles_vec, residue_level,
               heavy_atoms_only, multi_model_pdb, explicit_water);
    }
    catch (const IMP::ValueException &e) {  // not a pdb file
      // 2. try as a dat profile file
      IMP_NEW(Profile, profile, (files[i], false, max_q, units));
      if (profile->size() == 0) {
        IMP_WARN("can't parse input file " << files[i] << std::endl);
        return;
      } else {
        dat_files.push_back(files[i]);
        exp_profiles.push_back(profile);
        IMP_LOG_TERSE("Profile read from file " << files[i]
                      << " size = " << profile->size() << std::endl);
      }
    }
  }
}
示例#5
0
int main(int argc, char** argv) {
  if( argc < 2) {
    std::cerr << std::endl << "\tUsage is: " << argv[0] << " <text_file_with_values>" << std::endl;
  } else {
    std::string input_file = argv[1];
    std::cout << std::endl << "Processing file: " << input_file << std::endl;
    std::ifstream in_file(input_file.c_str());
    std::string line = "";
    std::vector<gpr_fit_values> data;
    if(in_file) {
      std::cout << "Checking Data string: " << std::endl;
      while(getline(in_file,line)) {
        if(line[0] == '#') continue;
        gpr_fit_values data_temp;
        std::stringstream ss;
        ss.str(line.c_str());
        ss >> data_temp.index >> data_temp.arm >> data_temp.charge
            >> data_temp.dw23_bin_center >> data_temp.wness_bin_center
            >> data_temp.value >> data_temp.uncertainty;
        std::cout << "\t" << data_temp.GetDataString() << std::endl;
        data.push_back(data_temp);
      }
      std::cout << " Lines successfully extracted: " << data.size() << std::endl;
      std::cout << " Done." << std::endl;
    } else {
      std::cerr << std::endl << "Badly formatted input file string, or problem opening file." << std::endl;
    }
  }
void SegmentationDataLayer<Dtype>::DataLayerSetUp(const vector<Blob<Dtype>*>& bottom,
      const vector<Blob<Dtype>*>& top) {

  SegmentationDataParameter data_param = this->layer_param_.segmentation_data_param();
  const string source = data_param.source();
  const bool shuffle = data_param.shuffle();
  const int batch_size = data_param.batch_size();
  const bool has_manipulation_data = data_param.has_manipulation_data();

  for(int i = 0; i < data_param.mean_value_size(); ++i){
    mean_values_.push_back(data_param.mean_value(i));
  }

  string image_path;
  string gt_image_path;
  float mp_x;
  float mp_y;

  LOG(INFO) << "Opening file " << source;
  std::ifstream in_file(source.c_str());
  if(has_manipulation_data){
    while(in_file >> image_path >> gt_image_path >> mp_x >> mp_y){
      ImagePair pair;
      pair.image = image_path;
      pair.gt_image = gt_image_path;
      pair.mp_x = mp_x;
      pair.mp_y = mp_y;
      image_pairs_.push_back(pair);
    }
  }else{
示例#7
0
void fillUnmatchedChunkData(vector<bool> indexes, vector<Chunk> chunkHead, string path, queue<chunkdat> *unmatchedChunks){
    ifstream in_file(path.c_str(),std::ifstream::binary);
    DeltaHandler deltahandler;
    int beforeEncode=0,afterencode=0;
    for(int y=0;y<indexes.size();y++){
        chunkdat ch_data;
        if(!indexes[y]){

            Bytef sourceblock[1024*65]={0};
            int value = y;

            in_file.seekg(chunkHead[value].getOffset(),in_file.beg);
            in_file.read((char *)sourceblock,chunkHead[value].getLength());

            Bytef* deltachunk;
            unsigned long int deltasize=0;
            deltahandler.getDeltaBlock(sourceblock,chunkHead[value].getLength(),&deltachunk,&deltasize);            
            beforeEncode+=chunkHead[value].getLength();
            afterencode+=deltasize;
            ch_data.chunk_size=deltasize;
            memcpy(ch_data.data,reinterpret_cast<char *>(deltachunk),deltasize);           
            unmatchedChunks->push(ch_data);            
            deltachunk=NULL;
        }
    }
    in_file.close();
    cout<<"Total size before delta encode:"<<beforeEncode<<endl;
    cout<<"Total size after delta encode:"<<afterencode<<endl;
}
示例#8
0
std::string Message::message_string (int n) const
{
  // Output string stream where we will put the text of the message
  std::ostringstream oss;
  std::ifstream in_file(_file_path.c_str());
  std::string line;

  if ( in_file.is_open() )
    {
      // Counter to keep track of how many lines we already got
      int counter(0);
      /* Put each line of the file in the output stream
       * until counter = n or we are at the end of the file */
      while ( (!(counter == n)) && (!in_file.eof()) )
        {
          getline(in_file, line);
          oss << line << std::endl;
          counter++;
        }
      in_file.close();
      // Return the actual string of the oss
      return oss.str(); // Return the actual string of the oss
    }
  else
    throw std::runtime_error("unable to open message: " + _file_path);
}
void convert_matrices(const std::string &in, const std::string &out) {
    std::ifstream in_file(in);
    // TODO check if in file exists
    std::ofstream out_file(out, std::ofstream::trunc);

    std::string line;
    int line_num = 0;

    while (std::getline(in_file, line)) {
        std::istringstream line_stream(line);
        std::stringstream output_stream;

        out_file << line_num << ' ';
        ++line_num;

        bool c;
        int c_num = 0;
        int matches = 0;
        while (line_stream >> c) {
            if (c) {
                ++matches;
                output_stream << ' ' << c_num;
            }
            ++c_num;
        }

        // construct line
        out_file << matches << output_stream.str() << std::endl;
    }

    in_file.close();
    out_file.close();
}
示例#10
0
				base::OptionalError read_file( boost::string_ref path, base::data_t & buffer, bool append_buffer ) {
					std::ifstream in_file( path.to_string( ), std::ifstream::ate | std::ifstream::binary );
					if( !in_file ) {
						auto result = base::create_optional_error( "Could not open file" );
						result->add( "where", "read_file#open" );
						return result;
					}

					auto fsize = in_file.tellg( );
					if( fsize < 0 ) {
						auto result = base::create_optional_error( "Error reading file length" );
						result->add( "where", "read_file#tellg" );
						return result;
					}
					if( !in_file.seekg( 0 ) ) {
						auto result = base::create_optional_error( "Error reseting file position to beginning" );
						result->add( "where", "read_file#seekg" );
						return result;
					}

					size_t first_pos = append_buffer ? buffer.size( ) : 0;
					buffer.resize( first_pos + static_cast<size_t>(fsize) );

					if( !in_file.read( buffer.data( ) + first_pos, fsize ) ) {
						auto result = base::create_optional_error( "Error reading file" );
						result->add( "where", "read_file#read" );
						return result;
					}
					return base::create_optional_error( );
				}
示例#11
0
void
Formula::InitFromFile( const char *filename )
{
   
   assert( filename != nullptr );
   /** open file **/
   std::ifstream in_file( filename, std::ifstream::in );
   if( in_file.is_open() )
   {
 /*
      std::stringstream ss;
      std::string line;
      while( in_file.good() )
      {
         std::getline( in_file, line );
         ss << line;
      }
      in_file.close();
*/
      load( in_file );
      
      in_file.close();
   }
   else
   {
      /* couldn't open file!! */
      std::cerr << "Failed to open file \"" << filename << "\", exiting!!\n";
      exit( EXIT_FAILURE );
   }
}
示例#12
0
IMPINTEGRATIVEDOCKING_BEGIN_INTERNAL_NAMESPACE

void ResidueContent::read_content_file(const std::string& file_name) {
  std::ifstream in_file(file_name.c_str());
  if (!in_file) {
    IMP_THROW("Can't open file " << file_name, IMP::IOException);
  }

  std::string line;
  while (!in_file.eof()) {
    getline(in_file, line);
    boost::trim(line);  // remove all spaces
    // skip comments
    if (line[0] == '#' || line[0] == '\0') continue;
    std::vector<std::string> split_results;
    boost::split(split_results, line, boost::is_any_of("\t "),
                 boost::token_compress_on);
    if (split_results.size() != 2) continue;
    int counter = atoi(split_results[1].c_str());
    IMP::atom::ResidueType residue_type =
        IMP::atom::ResidueType(split_results[0]);
    residue_content_[residue_type] = counter;
  }
  in_file.close();
}
示例#13
0
int main(int argc, char* argv[])
{
  // Open the input file and read a polygon.
  const char* filename = (argc > 1) ? argv[1] : "tight.dat";
  std::ifstream in_file(filename);

  if (! in_file.is_open()) {
    std::cerr << "Failed to open the input file." << std::endl;
    return -1;
  }

  // Read the input polygon.
  Linear_polygon P;
  in_file >> P;
  in_file.close();

  std::cout << "Read an input polygon with " << P.size() << " vertices."
            << std::endl;

  // Approximate the offset polygon.
  std::list<Polygon_2> inset_polygons;
  boost::timer timer;
  approximated_inset_2(P, 1, 0.00001, std::back_inserter(inset_polygons));
  double secs = timer.elapsed();

  std::list<Polygon_2>::iterator it;
  std::cout << "The inset comprises " << inset_polygons.size()
            << " polygon(s)." << std::endl;
  for (it = inset_polygons.begin(); it != inset_polygons.end(); ++it)
    std::cout << "    Polygon with " << it->size() << " vertices." << std::endl;
  std::cout << "Inset computation took " << secs << " seconds." << std::endl;
  return 0;
}
示例#14
0
void PSLang::Driver::compile(const std::string& filename,
		const std::string& outputFile) {
	if (_isVerbose) {
		std::cout << "Compilation started!" << std::endl << "Input file: "
				<< filename << std::endl << "Output file: " << outputFile
				<< std::endl;
	}
	std::ifstream in_file(filename);
	if (!in_file.good())
		exit(EXIT_FAILURE);
	scanner = std::unique_ptr<PSLang::Scanner>(new PSLang::Scanner(&in_file));
	parser = std::unique_ptr<PSLang::Parser>(
			new PSLang::Parser((*scanner) /* scanner */, (*this) /* driver */));

	if (parser->parse() == FAIL) {
		std::cerr << "Parse failed!!\n";
	}

	CodeGenBase* codeGenerator;
	if(llvmMode)
	{
		codeGenerator = new CodeGenLLVM(outputFile);
	}
	else
	{
		codeGenerator = new CodeGen(outputFile);
	}

	codeGenerator->generateCode(*programBlock);

	if (_isVerbose) {
		std::cout << "Compilation ended successfully!" << std::endl;
	}

}
示例#15
0
int main(int argc, char ** argv) {
try {
  using float_t = double;
  using size_type = std::uint32_t;
  if (4 != argc)
    throw std::invalid_argument("usage: simplify <<t> | -p> <in_file> <out_file>");
  // read the flow complex from file
  auto fc = FC::flow_complex<float_t, size_type>(42, 42);  // dummy
  {
    auto in_filename = argv[2];
    std::ifstream in_file(in_filename);
    in_file >> fc;
  }
  char const* action = argv[1];
  if (std::string(action) == "-p") {
    char const* out_filename = argv[3];
    std::ofstream out_file(out_filename);
    print_histogram(out_file, std::move(fc));
  } else {
    // simplify
    float_t const t = std::atof(argv[1]);
    if (t < 1)
      throw std::invalid_argument("prerequisite: t >= 1");
    fc = simplify(std::move(fc), t);
    // write result flow complex to file
    char const* out_filename = argv[3];
    std::ofstream out_file(out_filename);
    out_file << fc;
  }
} catch (std::exception & e) {
  std::cerr << e.what() << std::endl;
  std::exit(EXIT_FAILURE);
}
  std::exit(EXIT_SUCCESS);
}
示例#16
0
PBM_Image::PBM_Image(const std::string &file_name)
{
    std::ifstream in_file(file_name.c_str());
    std::string line;
    // get P1
    std::getline( in_file, line );
    // get comment (temp, works only for one comment, e.g. generated with GIMP)
    std::getline( in_file, line );
    // get size of the image
    in_file >> _w >> _h;

    // initialize matrix
    _inner_matrix = new unsigned int*[_h];
    for (unsigned int i=0; i<_h; ++i)
    {
        _inner_matrix[i] = new unsigned int[_w];
    }

    unsigned int count = 0;
    while (in_file.good())
    {
        char c = in_file.get();
        if (c == '1' || c == '0')
        {
            _inner_matrix[count/_w][count%_w] = c - '0';
            ++count;
        }
    }
}
 void ObjectWriter::CopyFile(std::string in, std::string out){
     std::ifstream in_file(in.c_str(), std::fstream::binary);
     std::ofstream out_file(out.c_str(), std::fstream::trunc|std::fstream::binary);
     out_file << in_file.rdbuf();
     in_file.close();
     out_file.close();
 }
示例#18
0
void writeSourceFile(std::ofstream & out_file, std::string & filename, const char * dirname, const char * alignment)
{
    std::string fullpath(dirname);
    fullpath += "/";
    fullpath += alignment;
    fullpath += "/";
    fullpath += filename;
    std::ifstream in_file(fullpath.c_str());
    std::string tmp;

    if (in_file.is_open())
    {
        //write variable declaration:
        out_file << "const char * const " << dirname << "_" << alignment << "_" << filename.substr(0, filename.size()-3) << " = " << std::endl;

        //write source string:
        while (getline(in_file, tmp, '\n'))
        {
            if (tmp.size() > 0)
            {
                //out_file << "\"" << tmp.replace(tmp.end()-1, tmp.end(), "\\n\"") << std::endl;
                if ( *(tmp.end()-1) == '\r')  //Windows line delimiter, \r\n
                    out_file << "\"" << tmp.replace(tmp.end()-1, tmp.end(), "\\n\"") << std::endl;
                else //Unix line delimiter \n
                    out_file << "\"" << tmp.append("\\n\"") << std::endl;
            }
        }
        out_file << "; //" << dirname << "_" << alignment << "_" << filename.substr(0, filename.size()-3)  << std::endl << std::endl;

    }
    else
        std::cerr << "Failed to open file " << filename << std::endl;
}
示例#19
0
vector<chunkdat> unmatchedChunkData(vector<bool> indexes,vector<Chunk> chunkdetails,string path){
    vector<chunkdat> chunkData;
    DeltaHandler deltahandler;
    ifstream in_file(path.c_str(),std::ifstream::binary);
    int beforeEncode=0,afterencode=0;
    for(int y=0;y<indexes.size();y++){
        chunkdat ch_data;
        if(!indexes[y]){
            Bytef *sourceblock=(Bytef*) malloc(1024*1024*sizeof(Byte));
            int value = y;
            in_file.seekg(chunkdetails[value].getOffset(),in_file.beg);
            in_file.read((char *)sourceblock,chunkdetails[value].getLength());
            Bytef* deltachunk=(Bytef*) malloc(1024*1024*sizeof(Byte));
            unsigned long int deltasize;
            deltahandler.getDeltaBlock(sourceblock,chunkdetails[value].getLength(),&deltachunk,&deltasize);
            cout<<"Size before delta encode: "<<chunkdetails[value].getLength()<<" and size after: "<<deltasize<<endl;
            beforeEncode+=chunkdetails[value].getLength();
            afterencode+=deltasize;
            ch_data.chunk_size=deltasize;
            memcpy(ch_data.data,reinterpret_cast<char *>(deltachunk),deltasize);
            cout<<"Reading chunk No: "<<value+1<<endl;
            chunkData.push_back(ch_data);
            free(sourceblock);
            free(deltachunk);
        }
    }
    cout<<"Total chunk size before encode:"<<beforeEncode<<endl;
    cout<<"Total chunk size after encode:"<<afterencode<<endl;
    in_file.close();
    return chunkData;
}
示例#20
0
unsigned long Message::size () const
{
  unsigned long begin, end;
  std::ifstream in_file(_file_path.c_str());

  if ( in_file.is_open() )
    {
      // Get position of the get pointer
      begin = in_file.tellg();
      // Set the postion of the  get pointer to the end of the file
      in_file.seekg(0, std::ios::end);
      // Get the position of the get pointer
      end = in_file.tellg();
      in_file.close();

      unsigned long bits(end - begin);

      if ( bits == 0 )
        return bits;
      else
        // We get the size size of the file by substracting end from begin
        return ceil(bits / 8);
    }
  else
    throw std::runtime_error("unable to open message: " + _file_path);
}
示例#21
0
	// 从硬盘读取文件到内存,再进行ini解析
	// 处理好文件句柄打开而未关闭
	bool INIParser::Parse(const std::string& ini_file_path)
	{
		ifstream in_file(ini_file_path.c_str());
		if(NULL == in_file)
		{
			fprintf(stderr, "INIParser::Parse read_filepath_error=[%s] error!!", ini_file_path.c_str());
            in_file.close();
			return false;
		}

		in_file.seekg(0, ios::end);
		size_t len_of_file = in_file.tellg();
		if(len_of_file < 0)
		{
			fprintf(stderr, "INIParser::Parse read_filelen error!!");
            in_file.close();
			return false;
		}

		char* buffer = new char [len_of_file + 1];

		in_file.seekg(0, ios::beg);
		in_file.read(buffer, len_of_file);
		buffer[len_of_file] = '\0';

		in_file.close();
		return Parse(buffer, len_of_file);
	}
示例#22
0
void WAS::WAS_Driver::parse(const char *const filename, int debug_level, int trace_level_) {
  assert(filename != nullptr);
  std::ifstream in_file(filename);
  if (!in_file.good())
    exit(EXIT_FAILURE);
  delete (scanner);
  try {
    scanner = new WAS::WAS_Scanner(&in_file);
  } catch (std::bad_alloc &ba) {
    std::cerr << "Failed to allocate scanner: (" << ba.what()
              << "), exiting!!\n";
    exit(EXIT_FAILURE);
  }
  delete parser;
  try {
    parser = new WAS::WAS_Parser(*scanner, *this);
    parser->set_debug_level(debug_level);
    trace_level = trace_level_;
  } catch (std::bad_alloc &ba) {
    std::cerr << "Failed to allocate parser: (" << ba.what()
              << "), exiting!!\n";
    exit(EXIT_FAILURE);
  }
  const int accept(0);
  if (parser->parse() != accept) {
    std::cerr << "Parse failed!!\n";
    exit(EXIT_FAILURE);
  }
}
示例#23
0
int main(int argc, char** argv) {
	std::ifstream in_file(argv[1]);
	std::string input((std::istreambuf_iterator<char_type>(in_file)), std::istreambuf_iterator<char_type>());
	std::transform(input.begin(), input.end(), input.begin(), caesar_cipher(std::atoi(argv[2])));
	std::ofstream out_file("caesar_cipher.txt");
	std::cout << input << std::endl;
	out_file << input;
}
示例#24
0
void MakeHistogram(const std::string& file) {
  std::ifstream in_file(file.c_str());
  TH1F* h = new TH1F("h","title",100,-300,300);
  float zvtx = 0;
  while(in_file >> zvtx){
    h->Fill(zvtx);
  }
  h->Draw();
}
示例#25
0
			void handle_reg(std::string& task)
			{
				if(in_file(task.c_str()))
				{
					//std::cout<<dirname(task.c_str())<<std::endl;
					std::cout<<basename(task.c_str())<<std::endl;
				}
				mod_unfinished();
			}
示例#26
0
文件: Generator.cpp 项目: kurff/Fonts
void Generator::load_all_fonts(char* file){
	ifstream in_file(file);
	string files;
	fonts_name.clear();
	while (in_file >> files){
		fonts_name.push_back(files);
	}
	in_file.close();
}
示例#27
0
bool
StyleFile::load (const char *filename)
{
    clear ();
    setup_default_entries ();
    m_filename = filename;

    std::ifstream in_file (filename);
    if (!in_file)
        return false;

    clear ();

    m_sections.push_back (StyleLines ());
    StyleLines *section = &m_sections[0];
    unsigned int section_id = 0;

    char buf[MAX_LINE_LENGTH];
    do {
        in_file.getline (buf, MAX_LINE_LENGTH);
        if (in_file.eof ())
            break;

        std::string dest = buf;
        StyleLine line (this, dest);
        StyleLineType type = line.get_type ();

        if (type == FCITX_ANTHY_STYLE_LINE_SECTION) {
            m_sections.push_back (StyleLines ());
            section = &m_sections.back();
            section_id++;
        }

        section->push_back (line);

        if (section_id == 0) {
            std::string key;
            line.get_key (key);
            if (key == "FormatVersion") {
                line.get_value (m_format_version);

            } else if (key == "Title") {
                line.get_value (m_title);

            } else if (key == "Version") {
                line.get_value (m_version);
            }
        }
    } while (!in_file.eof ());

    in_file.close ();

    m_filename = filename;

    return true;
}
示例#28
0
void MyWindow::open_linear_polygon_file()
{

  QString s = QFileDialog::getOpenFileName(file_name,
					   QString::null,
					   this,
					   "open file dialog",
					   "Choose a file" );
  if (s==QString::null)
    return;
  file_name=s;

  std::ifstream in_file(s.ascii());
  if (!in_file.is_open())
    {
      QMessageBox::warning( widget,"Open","Can't open file");
      return ;
    }

  CGAL::Bbox_2 box = CGAL::Bbox_2 (widget->x_min(), widget->y_min(),
				   widget->x_max(), widget->y_max());
  QCursor old = widget->cursor();
  widget->setCursor(Qt::WaitCursor);
  widget->lock();
  widget->clear_history();

  Linear_polygon_2 pgn;
  in_file >> pgn;
  if (pgn.is_empty())
    {
      widget->unlock();
      widget->setCursor(old);
      return;
    }
  if (pgn.orientation() != CGAL::COUNTERCLOCKWISE)
    pgn.reverse_orientation();

  const Polygon_2& circ_pgn = linear_2_circ(pgn);


  if (red_active)
    red_set.join(circ_pgn);
  else
    blue_set.join(circ_pgn);


  box = box + circ_pgn.bbox();
  widget->set_window(box.xmin(),
		     box.xmax(),
		     box.ymin(),
		     box.ymax());
  widget->unlock();
  newtoolbar->reset();
  something_changed();
  widget->setCursor(old);
}
示例#29
0
int main (int argc, char *argv[])
{
  // Get the name of the input file from the command line, or use the default
  // fan_grids.dat file if no command-line parameters are given.
  const char * filename = (argc > 1) ? argv[1] : "fan_grids.dat";

  // Open the input file.
  std::ifstream     in_file (filename);

  if (! in_file.is_open()) {
    std::cerr << "Failed to open " << filename << " ..." << std::endl;
    return (1);
  }

  // Read the segments from the file.
  // The input file format should be (all coordinate values are integers):
  // <n>                                 // number of segments.
  // <sx_1> <sy_1>  <tx_1> <ty_1>        // source and target of segment #1.
  // <sx_2> <sy_2>  <tx_2> <ty_2>        // source and target of segment #2.
  //   :      :       :      :
  // <sx_n> <sy_n>  <tx_n> <ty_n>        // source and target of segment #n.
  
  std::list<Segment_2>  segments;

  unsigned int n;
  in_file >> n;
  unsigned int i;
  for (i = 0; i < n; ++i) {
    int sx, sy, tx, ty;
    in_file >> sx >> sy >> tx >> ty;
    segments.push_back (Segment_2 (Point_2 (Number_type(sx), Number_type(sy)),
                                   Point_2 (Number_type(tx), Number_type(ty))));
  }
  in_file.close();

  // Construct the arrangement by aggregately inserting all segments.
  Arrangement_2                  arr;
  CGAL::Timer                    timer;

  std::cout << "Performing aggregated insertion of " 
            << n << " segments." << std::endl;

  timer.start();
  insert (arr, segments.begin(), segments.end());
  timer.stop();

  // Print the arrangement dimensions.
  std::cout << "V = " << arr.number_of_vertices()
	    << ",  E = " << arr.number_of_edges() 
	    << ",  F = " << arr.number_of_faces() << std::endl;

  std::cout << "Construction took " << timer.time() 
	    << " seconds." << std::endl;
  
  return 0;
}
示例#30
0
int Parser::Driver::parse(const char *filename, Parser::CompilationUnit*& module) {
   std::ifstream in_file(filename);

   scanner = new Parser::FlexScanner(&in_file);

   parser = new Parser::BisonParser(*scanner, *this, module);

   /* Returns 1 if parsing went OK. */
   return !parser->parse();
}