Esempio n. 1
0
bool OBJFileReader::load(const char *filename, int n) {
  // Open OBJ file
  std::ifstream OBJFile(filename);
  std::cout << "trying to load obj" << std::endl;
  // Original load
  if(n==1) {
    if (!OBJFile.is_open()) {
      std::cerr << "Could not open " << filename << std::endl;
      return false;
    }
        
    // Extract vertices and indices
    std::string line;
    glm::vec3 vertex;
    uint32_t vertexIndex0, vertexIndex1, vertexIndex2;
    while (!OBJFile.eof()) {
      std::getline(OBJFile, line);
      if (line.substr(0, 2) == VERTEX_LINE) {
	std::istringstream vertexLine(line.substr(2));
	vertexLine >> vertex.x;
	vertexLine >> vertex.y;
	vertexLine >> vertex.z;
	mVertices.push_back(vertex);
      }
      else if (line.substr(0, 2) == FACE_LINE) {
	std::istringstream faceLine(line.substr(2));
	faceLine >> vertexIndex0;
	faceLine >> vertexIndex1;
	faceLine >> vertexIndex2;
	mIndices.push_back(vertexIndex0 - 1);
	mIndices.push_back(vertexIndex1 - 1);
	mIndices.push_back(vertexIndex2 - 1);
      }
Esempio n. 2
0
bool PolyRegions::readFepBoundaries(const std::string& filename) {
	SEISCOMP_DEBUG("reading boundary polygons from file: %s", filename.c_str());

	std::ifstream infile(filename.c_str());

	if (infile.bad())
		return false;

	boost::regex vertexLine("^\\s*([-+]?[0-9]*\\.?[0-9]+)\\s+([-+]?[0-9]*\\.?[0-9]+)(?:\\s+([^\\d\\s].*)$|\\s*$)");
	boost::regex LLine("^\\s*L\\s+(.*)$");
	boost::smatch what;

	std::string line;
	bool newPolygon = true;
	GeoFeature *pr = NULL;
	OPT(Vertex) last;

	while(std::getline(infile, line)) {

		if (newPolygon){
			pr = new GeoFeature();
			newPolygon = false;
		}

		if ( boost::regex_match(line, what, vertexLine) ) {
			if ( last ) pr->addVertex(*last);
			last = Vertex(atof(what.str(2).c_str()), atof(what.str(1).c_str()));
		}
		else if (boost::regex_match(line, what, LLine)) {
			if ( last && pr->vertices().size() > 0 ) {
				if ( *last != pr->vertices().back() )
					pr->addVertex(*last);
			}

			if ( pr->vertices().size() < 3 )
				delete pr;
			else {
				pr->setName(what.str(1));
				pr->setClosedPolygon(true);
				addRegion(pr);

				if ( pr->area() < 0 )
					SEISCOMP_WARNING("Polygon %s is defined clockwise", pr->name().c_str());
			}

			last = Core::None;
			newPolygon = true;
		}
		else {
			//std::cout << "Warning: line ignored: " << line << std::endl;
		}
		
	}

	return true;

}
Esempio n. 3
0
/** BN vertex file: see SINGLE format.
 *  BN distribution file: see above.
 */
void BayesGraphLoad::operator()( std::shared_ptr<Graph> graph,
                                 const std::string labPosFileName,
                                 const std::string vertexFileName,
                                 const std::string distributionFileName,
                                 const std::string cndDataFileName,
                                 const std::string dataFileName
                                ) const {

  BOOST_LOG_TRIVIAL(trace) << "begin loading label..." << std::endl;
  LabPosMap labPosMap = readLabPos(labPosFileName);
  BOOST_LOG_TRIVIAL(trace) << "end loading label..." << std::endl;
  std::ifstream vertexFile(vertexFileName.c_str()), distributionFile(distributionFileName.c_str()), dataFile(dataFileName.c_str());
  CSVIterator<std::string> vertexLine(vertexFile); ++vertexLine; // skips header.
  BOOST_LOG_TRIVIAL(trace) << "begin loading vertices\n";

  for( ; vertexLine != CSVIterator<std::string>(); ++vertexLine ) {
    size_t id = boost::lexical_cast<size_t>( (*vertexLine)[0] );
    int level =  boost::lexical_cast<int>( (*vertexLine)[2] );
    int cardinality = boost::lexical_cast<int>( (*vertexLine)[3] );
    // printf("id: %lu, level: %d, card: %d, label: %s, pos: %d", id, level, cardinality, label.c_str(), position);
    std::string label = labPosMap[id].first;
    int position = labPosMap[id].second;
    create_graph_node( graph, cardinality, label, position, level );
  }

  Graph& graphRef = *graph;
  BOOST_LOG_TRIVIAL(trace)  << "end loading vertices: " << boost::num_vertices(graphRef) <<  "\n\n";
  BOOST_LOG_TRIVIAL(trace)  << "begin loading dist\n";

  CSVIterator<std::string> distributionLine(distributionFile);
  while ( distributionLine != CSVIterator<std::string>() ) {
    plVariablesConjunction variables; // holds child variables
    plComputableObjectList jointDistri;
    size_t latentId =  boost::lexical_cast<size_t>( (*distributionLine)[BN_LATENT_ID] );
    size_t nbrChildren = boost::lexical_cast<size_t>( (*distributionLine)[NBR_CHILDREN] );
    Node& latentNode = graphRef[ latentId ]; ++distributionLine; // reads next line.

    std::vector< plProbValue > probValuesZ;
    for ( size_t latentVal = 0; latentVal < latentNode.variable.cardinality(); ++latentVal) { // loads probability table for the latent var
      probValuesZ.push_back( boost::lexical_cast<plProbValue>( (*distributionLine)[latentVal] ) );
    }
    const plProbTable probTabZ(latentNode.variable, probValuesZ); ++distributionLine;
    for ( size_t child = 0; child < nbrChildren; ++child ) {
      size_t childId = boost::lexical_cast<size_t>( (*distributionLine)[BN_LATENT_ID] ); ++distributionLine;
      Node& childNode = graphRef[ childId ]; variables ^= childNode.variable;
      plDistributionTable distTab_Xi_Z ( childNode.variable, latentNode.variable );

      for ( size_t latentVal = 0; latentVal < latentNode.variable.cardinality(); ++latentVal ) {
        std::vector< plProbValue > probValuesXiZ_vals;
        for ( size_t childVal = 0; childVal < childNode.variable.cardinality(); ++childVal ) {
          probValuesXiZ_vals.push_back( boost::lexical_cast<plProbValue>( (*distributionLine)[childVal] ) );
        }
        distTab_Xi_Z.push( plProbTable( childNode.variable, probValuesXiZ_vals), (int)latentVal );
        ++distributionLine;
      }
      jointDistri *= distTab_Xi_Z; // adds the conditional table to result
      boost::add_edge( latentId, childId, graphRef );
    }

    auto jd = ( probTabZ * jointDistri );

    ++distributionLine;
    latentNode.set_joint_distribution(
        plJointDistribution(latentNode.variable ^ variables, probTabZ * jointDistri) );
  }
  distributionFile.close();
  vertexFile.close();

  set_data(*graph, cndDataFileName, dataFileName);
}