Example #1
0
int main()
{
    const int D = 5;   // we work in Euclidean 5-space
    const int N = 100; // we will insert 100 points
    // - - - - - - - - - - - - - - - - - - - - - - - - STEP 1
    CGAL::Random_points_in_cube_d<Triangulation::Point> rand_it(D, 1.0);
    std::vector<Triangulation::Point> points;
    CGAL::cpp11::copy_n(rand_it, N, std::back_inserter(points));

    Triangulation t(D);                      // create triangulation
    CGAL_assertion(t.empty());
    t.insert(points.begin(), points.end());  // compute triangulation
    CGAL_assertion( t.is_valid() );
    // - - - - - - - - - - - - - - - - - - - - - - - - STEP 2
    typedef Triangulation::Face Face;
    typedef std::vector<Face> Faces;
    Faces edges;
    std::back_insert_iterator<Faces> out(edges);
    t.tds().incident_faces(t.infinite_vertex(), 1, out);  
    // collect faces of dimension 1 (edges) incident to the infinite vertex
    std::cout << "There are " << edges.size() 
              << " vertices on the convex hull." << std::endl;

#include "triangulation1.cpp" // See below
#include "triangulation2.cpp"

    return 0;
}
Example #2
0
void MDAL::DriverFlo2D::createMesh( const std::vector<CellCenter> &cells, double half_cell_size )
{
  // Create all Faces from cell centers.
  // Vertexs must be also created, they are not stored in FLO-2D files
  // try to reuse Vertexs already created for other Faces by usage of unique_Vertexs set.
  Faces faces;
  Vertices vertices;
  std::map<Vertex, size_t, VertexCompare> unique_vertices; //vertex -> id
  size_t vertex_idx = 0;

  for ( size_t i = 0; i < cells.size(); ++i )
  {
    Face e( 4 );

    for ( size_t position = 0; position < 4; ++position )
    {
      Vertex n = createVertex( position, half_cell_size, cells[i] );
      const auto iter = unique_vertices.find( n );
      if ( iter == unique_vertices.end() )
      {
        unique_vertices[n] = vertex_idx;
        vertices.push_back( n );
        e[position] = vertex_idx;
        ++vertex_idx;
      }
      else
      {
        e[position] = iter->second;
      }
    }

    faces.push_back( e );
  }

  mMesh.reset(
    new MemoryMesh(
      name(),
      vertices.size(),
      faces.size(),
      4, //maximum quads
      computeExtent( vertices ),
      mDatFileName
    )
  );
  mMesh->faces = faces;
  mMesh->vertices = vertices;
}
Example #3
0
int incorrect_input(std::string error = "")
{
  std::cerr << "Incorrect input file.\n"
	    << "  " << error << "\n";
  std::cerr << "So far: " << vertices.size() << " vertices, "
	    << faces.size() << " faces\n";
  return EXIT_FAILURE;
}
Example #4
0
void generateTriangles(const unsigned xdiv,
					   const unsigned ydiv,
					   Faces& faces)
{
	const unsigned xpts(xdiv + 1); // number of points in x
	const unsigned NF(2 * xdiv * ydiv); // total number of faces

	faces.reserve(NF);

	for(unsigned y(0); y != ydiv; ++y)
		for(unsigned x(0); x != xdiv; ++x) {
			const unsigned a(y * xpts + x);
			const unsigned b(a + 1);
			const unsigned c(b + xdiv);
			const unsigned d(c + 1);

			faces.push_back(Trig(a, b, d));
			faces.push_back(Trig(a, d, c));
		}

	assert(faces.size() == NF);
}
Example #5
0
 void print()
 {
     std::cout << "MeshData:: " << std::endl << "Vertices : " << std::endl;
     for (int i = 0; i < m_Vertices.size(); i++)
     {
         std::cout << i << ": " << m_Vertices[i] << std::endl;
     }
     std::cout << "Indices & Normals : " << std::endl;
     for (int i = 0; i < m_Faces.size(); i++)
     {
         std::cout << i << ": " << m_Faces[i] << "\t n:" << m_Normals[i] << std::endl;
     }
 };
Example #6
0
void draw(const int tex,
		  const Mesh& mesh,
		  const Mesh& tc,
		  const Faces& faces)
{
	assert(tex != 0);
	assert(not mesh.empty());
	assert(mesh.size() == tc.size());
	assert(not faces.empty());

	const cgl::BindTexture2D bind(tex);

	glTexCoordPointer(2, GL_FLOAT, 0, &tc.front().x);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, &mesh.front().x);
	glEnableClientState(GL_VERTEX_ARRAY);

	glDrawElements(GL_TRIANGLES, faces.size() * 3,
				   GL_UNSIGNED_INT, &faces.front().a);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Example #7
0
    void writeToLog(Logging::Log* plog)
    {
        std::stringstream logmessage;

        using std::endl;
        using std::cout;

        logmessage << "MeshData:: " << std::endl << "Vertices : " << std::endl;
        for (int i = 0; i < m_Vertices.size(); i++)
        {
            logmessage << i << ": " << m_Vertices[i] << endl;
        }
        logmessage << "Indices & Normals : " << endl;
        for (int i = 0; i < m_Faces.size(); i++)
        {
            logmessage << i << ": " << m_Faces[i] << "\t n:" << m_Normals[i] << std::endl;
        }
        plog->logMessage(logmessage.str());
    };
Example #8
0
    void setup(size_t& vertex_count, Ogre::Vector3* vertices, size_t& index_count, unsigned long* indices, double scale)
    {
        // If we add more Objects we need an Offset for the Indices
        std::size_t indices_offset = m_Vertices.size();

        Vector3 temp;
        for (int i = 0; i < vertex_count; i++)
        {
            temp << vertices[i].x / (Ogre::Real)scale, vertices[i].y / (Ogre::Real)scale,
                vertices[i].z / (Ogre::Real)scale;
            m_Vertices.push_back(temp);
        }

        for (int i = 0; i < index_count; i += 3)
        {
            Eigen::Matrix<unsigned long, 3, 1> temp;
            temp << (unsigned long)(indices[i] + indices_offset), (unsigned long)(indices[i + 1] + indices_offset),
                (unsigned long)(indices[i + 2] + indices_offset);
            m_Faces.push_back(temp);
            // Calculate the normal to each triangle:
            // m_Normals.push_back(Ogre::Math::calculateBasicFaceNormal(m_Vertices[indices[i]],m_Vertices[indices[i+1]],m_Vertices[indices[i+2]]));
        }
    };
Example #9
0
void MDAL::Driver3Di::populateFacesAndVertices( Vertices &vertices, Faces &faces )
{
  assert( vertices.empty() );
  size_t faceCount = mDimensions.size( CFDimensions::Face2D );
  faces.resize( faceCount );
  size_t verticesInFace = mDimensions.size( CFDimensions::MaxVerticesInFace );
  size_t arrsize = faceCount * verticesInFace;
  std::map<std::string, size_t> xyToVertex2DId;

  // X coordinate
  int ncidX = mNcFile.getVarId( "Mesh2DContour_x" );
  double fillX = mNcFile.getFillValue( ncidX );
  std::vector<double> faceVerticesX( arrsize );
  if ( nc_get_var_double( mNcFile.handle(), ncidX, faceVerticesX.data() ) ) throw MDAL_Status::Err_UnknownFormat;

  // Y coordinate
  int ncidY = mNcFile.getVarId( "Mesh2DContour_y" );
  double fillY = mNcFile.getFillValue( ncidY );
  std::vector<double> faceVerticesY( arrsize );
  if ( nc_get_var_double( mNcFile.handle(), ncidY, faceVerticesY.data() ) ) throw MDAL_Status::Err_UnknownFormat;

  // now populate create faces and backtrack which vertices
  // are used in multiple faces
  for ( size_t faceId = 0; faceId < faceCount; ++faceId )
  {
    Face face;

    for ( size_t faceVertexId = 0; faceVertexId < verticesInFace; ++faceVertexId )
    {
      size_t arrId = faceId * verticesInFace + faceVertexId;
      Vertex vertex;
      vertex.x = faceVerticesX[arrId];
      vertex.y = faceVerticesY[arrId];
      vertex.z = 0;

      if ( MDAL::equals( vertex.x, fillX ) || MDAL::equals( vertex.y, fillY ) )
        break;


      size_t vertexId;

      std::string key = std::to_string( vertex.x ) + "," + std::to_string( vertex.y );
      const auto it = xyToVertex2DId.find( key );
      if ( it == xyToVertex2DId.end() )
      {
        // new vertex
        vertexId = vertices.size();
        xyToVertex2DId[key] = vertexId;
        vertices.push_back( vertex );
      }
      else
      {
        // existing vertex
        vertexId = it->second;
      }

      face.push_back( vertexId );

    }

    faces[faceId] = face;
  }

  // Only now we have number of vertices, since we identified vertices that
  // are used in multiple faces
  mDimensions.setDimension( CFDimensions::Vertex2D, vertices.size() );
}
Example #10
0
 boost_foreach(Faces& entities, find_components_recursively<Faces>( *comp ) )
 {
   entities.create_space(space_lib_name+"."+entities.element_type().shape_name(),*dict);
 }
void ObjectToFile::readObjects(const char* address){
	//FILE * file = fopen(address.c_str(), "rb");
	FILE * file = fopen(address, "rb");
	char c;
	float values_x = 0, values_y = 0, values_z = 0;
	long int v_index[3]={0}, vt_index[3]={0}, vn_index[3]={0}, without_texture;
	int regular_expression_type = 0;
	char type;
	without_texture = -100;
	string number;
	Points *point_v, *point_vt, *point_vn; //vertex, texture vertex, normal vertex
	IntegerPoints *left_index, *middle_index, *right_index; //every IntegerPoint have 3 long it
	Faces *faces;
	vector<Points*> vector_v, vector_vt, vector_vn; //Arraylist of Points
	//VertexBuffer *vertexBuffer;
	
	faces = new Faces();

	printf("\nLoading object in file...");
	if(file == NULL)
	{
		printf("Impossible to open the file! Are you in the right path ?\n");
		printf("Exit...\n");
	}
	else
	{
		printf("\n");
		while(!feof(file)){ //Read until end file
			c = fgetc(file); //get first character
			//Verify if the line starts with v
			if(c == 'v')
			{
				//get this line in file
				fscanf(file, "%c %f %f %f", &type, &values_x, &values_y, &values_z);
				switch(type)
				{//Verify if type is vertex, vertex texture, vertex normal or face.

					case 't': //Get the Vertex Texture
						point_vt = new Points(values_x, values_y, values_z);
						vector_vt.push_back(point_vt);
						break;//End vertex texture

					case 'n': //get the Vertex Normal
						point_vn = new Points(values_x, values_y, values_z);
						vector_vn.push_back(point_vn);
						break;

					default: //get the Vertex
						if(type == ' '){//Verifica se o proximo espaço é vazio para não pegar valores errados no arquivo
							point_v = new Points(values_x, values_y, values_z);
							vector_v.push_back(point_v);
						}
						break;

				}//end switch
			}//end get v

			//check if the head of line is by Face.
			else if(c == 'f')
			{
				c = fgetc(file);
				if(c == ' '){ //check first line
					number = selectNumberInLine(file);
					v_index[0] = atol(number.c_str()); //number.c_str() convert string to const char*
					number = "";
					c = fgetc(file);
					if(c == '/')
					{
						regular_expression_type = 2;
						fscanf(file, "%ld %ld//%ld %ld//%ld", &vn_index[0], &v_index[1], &vn_index[1], &v_index[2], &vn_index[2]);
						left_index = new IntegerPoints(v_index[0], without_texture, vn_index[0], regular_expression_type);
						middle_index = new IntegerPoints(v_index[1], without_texture, vn_index[1], regular_expression_type);
						right_index = new IntegerPoints(v_index[2], without_texture, vn_index[2], regular_expression_type);
						faces->addAllGroupsInteger(left_index, middle_index, right_index);
					}

					else
					{
						number += c;
						number += selectNumberInLine(file);
						vt_index[0] = atol(number.c_str());
						number = "";
						regular_expression_type = 3;
						fscanf(file, "%ld %ld/%ld/%ld %ld/%ld/%ld", &vn_index[0], &v_index[1], &vt_index[1], &vn_index[1], &v_index[2], &vt_index[2], &vn_index[2]);
						left_index = new IntegerPoints(v_index[0], vt_index[0], vn_index[0], regular_expression_type);
						middle_index = new IntegerPoints(v_index[1],vt_index[1], vn_index[1], regular_expression_type);
						right_index = new IntegerPoints(v_index[2], vt_index[2], vn_index[2], regular_expression_type);
						faces->addAllGroupsInteger(left_index, middle_index, right_index);
					}//End else to integers with 3 numbers
				}//End if to verify the next step is empty space
			}//End if to "faces" objects
		}//End to while
		

		//Organizing the vertex by Faces
		setVertex(vector_v);
		setTextureVertex(vector_vt);
		setNormalVertex(vector_vn);
		faces->organizeVertexByFaces(faces, vector_v, vector_vt, vector_vn);
		setFaces(faces);



	}//End if read Object
}
Example #12
0
void test(const int d, const string & type, const int N)
{
    // we must write 'typename' below, because we are in a template-function,
    // so the parser has no way to know that DC contains sub-types, before
    // instanciating the function.
    typedef typename DC::Full_cell_handle Full_cell_handle;
    typedef typename DC::Face Face;
    typedef typename DC::Point Point;
    typedef typename DC::Finite_full_cell_const_iterator Finite_full_cell_const_iterator;
    typedef typename DC::Finite_vertex_iterator Finite_vertex_iterator;

    typedef CGAL::Random_points_in_cube_d<Point> Random_points_iterator;

    DC pc(d);
    cerr << "\nBuilding Delaunay triangulation of (" << type << d << ") dimension with " << N << " points";
    assert(pc.empty());

    vector<Point> points;
    CGAL::Random rng;
    Random_points_iterator rand_it(d, 2.0, rng);
    //CGAL::cpp11::copy_n(rand_it, N, back_inserter(points));
    
    vector<int> coords(d);
    for( int i = 0; i < N; ++i )
    {
        for( int j = 0; j < d; ++j )
            coords[j] = rand() % 100000;
        points.push_back(Point(d, coords.begin(), coords.end()));
    }
    pc.insert(points.begin(),  points.end());
    cerr << "\nChecking topology and geometry...";
    assert( pc.is_valid() );

    cerr << "\nTraversing finite full_cells... ";
    size_t nbfs(0), nbis(0);
    Finite_full_cell_const_iterator fsit = pc.finite_full_cells_begin();
    while( fsit != pc.finite_full_cells_end() )
        ++fsit, ++nbfs;
    cerr << nbfs << " + ";
    vector<Full_cell_handle> infinite_full_cells;
    pc.tds().incident_full_cells(pc.infinite_vertex(), back_inserter(infinite_full_cells));
    nbis = infinite_full_cells.size();
    cerr << nbis << " = " << (nbis+nbfs)
    << " = " << pc.number_of_full_cells();
    cerr << "\nThe triangulation has current dimension " << pc.current_dimension();
    CGAL_assertion( pc.number_of_full_cells() == nbis+nbfs);

    cerr << "\nTraversing finite vertices... ";
    size_t nbfv(0);
    Finite_vertex_iterator fvit = pc.finite_vertices_begin();
    while( fvit != pc.finite_vertices_end() )
        ++fvit, ++nbfv;
    cerr << nbfv <<endl;

    // Count convex hull vertices:
    if( pc.maximal_dimension() > 1 )
    {
        typedef vector<Face> Faces;
        Faces edges;
        back_insert_iterator<Faces> out(edges);
        pc.tds().incident_faces(pc.infinite_vertex(), 1, out);
        cout << "\nThere are " << edges.size() << " vertices on the convex hull.";
        edges.clear();
    }
    else // pc.maximal_dimension() == 1
    {
        typedef vector<Full_cell_handle> Cells;
        Cells cells;
        back_insert_iterator<Cells> out(cells);
        pc.tds().incident_full_cells(pc.infinite_vertex(), out);
        cout << "\nThere are " << cells.size() << " vertices on the convex hull.";
        cells.clear();
    }

    // Remove all !
    cerr << "\nBefore removal: " << pc.number_of_vertices() << " vertices. After: ";
    random_shuffle(points.begin(),  points.end());
    pc.remove(points.begin(),  points.end());
    assert( pc.is_valid() );
    cerr << pc.number_of_vertices() << " vertices.";
    // assert( pc.empty() ); NOT YET !
    // CLEAR
    pc.clear();
    assert( -1 == pc.current_dimension() );
    assert( pc.empty() );
    assert( pc.is_valid() );
}
Example #13
0
int main(int argc,char *argv[]){
        if(argc<2){
                std::cerr<<
                        "usage: "<<argv[0]<<" input_file"<<std::endl;
                exit(-1);
        }
        std::fstream infile;
        Point p;
        size_t index=0;
        std::vector<Point> points;
#ifdef USE_HASHED_DETERMINANTS
        HD Pdets;
#endif
        infile.open(argv[1],std::fstream::in);
        int dim=0;
        while(infile>>p){
                dim=p.dimension();
#ifdef USE_HASHED_DETERMINANTS
                p.set_index(index++);
                p.set_hash(&Pdets);
#endif
                points.push_back(p);
#ifdef USE_HASHED_DETERMINANTS
                // now we have to add the point to the hash table
                std::vector<CGAL::Gmpq> column;
                for(size_t i=0;i<dim;++i)
                        column.push_back(p[i]);
                Pdets.add_column(column);
#endif
        }
        infile.close();
        clock_t elapsed_offline,elapsed_online;
        Triangulation triang_offline(dim),triang_online(dim);

        clock_t start=clock();
        //for(size_t i=0;i<points.size();++i)
        //        triang_offline.insert(points[i]);
        elapsed_offline=clock()-start;

        start=clock();
        triang_online.insert(points.begin(),points.end());
        elapsed_online=clock()-start;

        typedef Triangulation::Face Face;
        typedef std::vector<Face> Faces;
        Faces edges;
        std::back_insert_iterator<Faces> out(edges);
        triang_online.incident_faces(triang_online.infinite_vertex(),1,out);

        std::cerr<<dim<<'\t'<<
                points.size()<<'\t'<<
                //(double)elapsed_offline/CLOCKS_PER_SEC<<'\t'<<
                .0<<'\t'<<
                (double)elapsed_online/CLOCKS_PER_SEC<<'\t'<<
                edges.size()<<'\t'<<
#ifdef USE_HASHED_DETERMINANTS
                points[0].hash()->algorithm()<<
#else
                "no_hash"<<
#endif
                std::endl;
        //edges.clear();
        return 0;
}
Example #14
0
void test(const int d, const string & type)
{
    // we must write 'typename' below, because we are in a template-function,
    // so the parser has no way to know that TDS contains sub-types, before
    // instanciating the function.
    typedef typename TDS::Vertex_handle Vertex_handle;
    typedef typename TDS::Vertex_iterator Vertex_iterator;
    typedef typename TDS::Full_cell_handle Full_cell_handle;
    typedef typename TDS::Face Face;
    typedef typename TDS::Facet Facet;
    typedef typename TDS::Facet_iterator Facet_iterator;

    TDS tds(d);
    cout << "\nChecking Tds of (" << type << ") dimension "
        << tds.maximal_dimension();
    assert(tds.empty());
    vector<Vertex_handle> vhs;
    vhs.push_back(tds.insert_increase_dimension());
    assert( tds.is_valid() );
    size_t nb_verts = 1;
    for( int i = 0; i <= d; ++i )
    {
        vhs.push_back(tds.insert_increase_dimension(vhs[0]));
        ++nb_verts;
        
        assert(i == tds.current_dimension());
        assert(!tds.is_vertex(Vertex_handle()));
        assert(!tds.is_full_cell(Full_cell_handle()));
        assert(tds.is_vertex(vhs[i]));
        assert(tds.is_full_cell(vhs[i]->full_cell()));

        if( tds.current_dimension() > 0 )
        {
            //int nbs = tds.number_of_full_cells();
            tds.insert_in_full_cell(tds.full_cell(vhs[i+1]));
            ++nb_verts;
            //assert((size_t)(nbs+tds.current_dimension())==tds.number_of_full_cells());
        }
        assert( tds.is_valid() );
    }
    assert((nb_verts == tds.number_of_vertices()));

    if( d > 1 )
    {
        // insert in hole
        std::vector<Full_cell_handle> simps;
        simps.push_back(tds.full_cells_begin());
        simps.push_back(tds.neighbor(simps[0],0));
        tds.insert_in_hole(simps.begin(), simps.end(), Facet(simps[0],1));
    }

   // TEST Faces enumeration
    typedef std::vector<Face> Faces;
    Faces faces;
    for( Vertex_iterator vit = tds.vertices_begin(); vit != tds.vertices_end(); ++vit )
    {
        for( int d = 1; d < tds.current_dimension() - 1; ++d )
        {
            //cout << '\n' << d << "-dimensional faces adjacent to " << &(*vit)
            //      << " ( current dimension is " << tds.current_dimension() << " )";
            faces.clear();
            std::back_insert_iterator<Faces> out(faces);
            tds.incident_faces(vit, d, out);
            typename Faces::iterator fit = faces.begin();
            while( fit != faces.end() )
            {
                //cout << '\n';
                //for( int i = 0; i <= d; ++i )
                //    cout << ' ' << &(*fit->vertex(i));
                ++fit;
            }
        }
    }

    // TEST Finite iterators
    if( tds.current_dimension() > 0 )
    {
        Facet_iterator fit = tds.facets_begin();
        size_t nbfft(0);
        while( fit != tds.facets_end() )
            ++fit, ++nbfft;
        cout << '\n' << tds.number_of_full_cells() << " full cells, ";
        cout << ' ' << nbfft << " facets.";
    }
 
    // TEST File I/O
    std::ofstream fo((string("output-tds-")+type).c_str());
    if( d % 2 )
        CGAL::set_binary_mode(fo);
    fo << tds;
    fo.close();

    std::ifstream fi((string("output-tds-")+type).c_str());
    if( d % 2 )
        CGAL::set_binary_mode(fi);
    TDS input_tds(d);
    fi >> input_tds;
    fi.close();

    // TEST Copy Constructor
    TDS tds2(tds);
    assert( tds2.is_valid() );
    assert( tds.current_dimension() == tds2.current_dimension() );
    assert( tds.maximal_dimension() == tds2.maximal_dimension() );
    assert( tds.number_of_vertices() == tds2.number_of_vertices() );
    assert( tds.number_of_full_cells() == tds2.number_of_full_cells() );

    // CLEAR
    tds.clear();
    assert(-2==tds.current_dimension());
    assert(tds.empty());
    assert( tds.is_valid() );
}
Example #15
0
int main(int argc, char** argv)
{
  if(argc != 3)
    return usage(argv[0]);
  mark_tag vertex_index(1), vertex_x(2), vertex_y(3), vertex_z(4);

  sregex tface_re = bos >> *space >> "TFACE" >> *space >> eos;

  sregex vertex_re = bos >> *space >> "VRTX" 
			 >> +space >> (vertex_index=+_d)
			 >> +space >> (vertex_x=+(digit|'-'|'+'|'.'))
			 >> +space >> (vertex_y=+(digit|'-'|'+'|'.'))
			 >> +space >> (vertex_z=+(digit|'-'|'+'|'.'))
			 >> eos;

  sregex triangle_re = bos >> *space >> "TRGL"
			   >> +space >> (s1=+digit)
			   >> +space >> (s2=+digit)
			   >> +space >> (s3=+digit)
			   >> eos;
  sregex end_re = bos >> *space >> "END" >> *space >> eos;

  std::ifstream input(argv[1]);
  std::ofstream output(argv[2]);

  if(!input) {
    std::cerr << "Cannot read \"" << argv[1] << "\"!\n";
    return EXIT_FAILURE;
  }
  if(!output) {
    std::cerr << "Cannot write to \"" << argv[2] << "\"!\n";
    return EXIT_FAILURE;
  }

  std::string line;
  std::getline(input, line);
  smatch results;
  while(input && ! regex_match(line, tface_re)) // search line "TFACE"
  {
    std::getline(input, line);
  }
  std::getline(input, line);
  while(input && regex_match(line, results, vertex_re)) {
    vertices.push_back(boost::make_tuple(results[vertex_x],
					 results[vertex_y],
					 results[vertex_z]));
    std::getline(input, line);
  }
  while(input && regex_match(line, results, triangle_re)) {
    std::stringstream s;
    int i, j, k;
    s << results[1] << " " << results[2] << " " << results[3];
    s >> i >> j >> k;
    faces.push_back(boost::make_tuple(i, j, k));
    std::getline(input, line);
  }
  if(!input || !regex_match(line, end_re))
    return incorrect_input("premature end of file!");

  output << "OFF " << vertices.size() << " " << faces.size() << " " << "0\n";
  for(Vertices::const_iterator vit = vertices.begin(), vend = vertices.end();
      vit != vend; ++vit)
    output << boost::get<0>(*vit) << " "
	   << boost::get<1>(*vit) << " "
	   << boost::get<2>(*vit) << "\n";
  for(Faces::const_iterator fit = faces.begin(), fend = faces.end();
      fit != fend; ++fit)
    output << "3 " << boost::get<0>(*fit)
	   << " " << boost::get<1>(*fit)
	   << " " << boost::get<2>(*fit) << "\n";
  if(output)
    return EXIT_SUCCESS;
  else
    return EXIT_FAILURE;
};
Example #16
0
static void validateModel(Faces & facesToBeValidated )
{
  
  std::vector<AbsFace*> faces      = facesToBeValidated.faces();
  std::vector<gml::Point3D> points = facesToBeValidated.points();
  
  bool find=false;
  
  std::vector< std::vector<gml::Point3D> > edges; 

  // Edges' construction
  for (int i=0 ; i<(int) faces.size() ; i++)
    { 
      std::vector <int> & indexes =  *( faces[i]->getIndexes() );
      
      for (int j=0 ; j< (int) indexes.size(); j++)
	{
	  std::vector <gml::Point3D> temp;
	  
	  temp.push_back( points[ indexes[j] ] );
	  
	  if (j+1 == (int) (indexes.size()) )
	    {
	      temp.push_back( points[indexes[0]] );
	    }
	  else
	    {
	      temp.push_back( points[indexes[j+1]] );
	    }

	  // Test if the found edge is not already in the vector edges
	  int k=0;
	  while (k<(int)edges.size() && !find) 
	    {
	      // Exact comparaison
	      if ((edges[k][0][0] == temp[0][0] && 
		   edges[k][0][1] == temp[0][1] &&
		   edges[k][0][2] == temp[0][2] &&
		   edges[k][1][0] == temp[1][0] &&
		   edges[k][1][1] == temp[1][1] &&
		   edges[k][1][2] == temp[1][2]) ||
		  (edges[k][0][0] == temp[1][0] && 
		   edges[k][0][1] == temp[1][1] &&
		   edges[k][0][2] == temp[1][2] &&
		   edges[k][1][0] == temp[0][0] &&
		   edges[k][1][1] == temp[0][1] &&
		   edges[k][1][2] == temp[0][2])) {
		   
		find = true;
		
	      }
	      else 
		{
		
		  k++;
		}
	    }
	  k=0;
	  if (!find) {
	    edges.push_back(temp);
	  }
	  else {
	    find = false;
	  }
	}
    }

  edgesIntersections(edges);
  facesOnSamePlan(faces, points);
  edgesCutFaces(faces, edges, points);


}  
Example #17
0
// greebo: TODO: Make this a member method of the Brush class
bool Brush_merge(Brush& brush, const BrushPtrVector& in, bool onlyshape) {
	// gather potential outer faces
	typedef std::vector<const Face*> Faces;
	Faces faces;

	for (BrushPtrVector::const_iterator i(in.begin()); i != in.end(); ++i) {
		(*i)->getBrush().evaluateBRep();

		for (Brush::const_iterator j((*i)->getBrush().begin()); j != (*i)->getBrush().end(); ++j) {
			if (!(*j)->contributes()) {
				continue;
			}

			const Face& face1 = *(*j);

			bool skip = false;

			// test faces of all input brushes
			//!\todo SPEEDUP: Flag already-skip faces and only test brushes from i+1 upwards.
			for (BrushPtrVector::const_iterator k(in.begin()); !skip && k != in.end(); ++k) {
				if (k != i) { // don't test a brush against itself
					for (Brush::const_iterator l((*k)->getBrush().begin()); !skip && l != (*k)->getBrush().end(); ++l) {
						const Face& face2 = *(*l);

						// face opposes another face
						if (face1.plane3() == -face2.plane3()) {
							// skip opposing planes
							skip  = true;
							break;
						}
					}
				}
			}

			// check faces already stored
			for (Faces::const_iterator m = faces.begin(); !skip && m != faces.end(); ++m) {
				const Face& face2 = *(*m);

				// face equals another face
				if (face1.plane3() == face2.plane3()) {
					// if the texture/shader references should be the same but are not
					if (!onlyshape && !shader_equal(
                            face1.getFaceShader().getMaterialName(),
                            face2.getFaceShader().getMaterialName()
                        ))
                    {
						return false;
					}

					// skip duplicate planes
					skip = true;
					break;
				}

				// face1 plane intersects face2 winding or vice versa
				if (Winding::planesConcave(face1.getWinding(), face2.getWinding(), face1.plane3(), face2.plane3())) {
					// result would not be convex
					return false;
				}
			}

			if (!skip) {
				faces.push_back(&face1);
			}
		}
	}

	for (Faces::const_iterator i = faces.begin(); i != faces.end(); ++i) {
		if (!brush.addFace(*(*i))) {
			// result would have too many sides
			return false;
		}
	}

	brush.removeEmptyFaces();
	return true;
}
void SleepDetector::operator()( cv::Mat & src )
{
	cv::Mat gray;
	cv::cvtColor(src, gray, CV_BGR2GRAY);
	cv::equalizeHist(gray, gray);

	typedef std::vector<cv::Rect> Faces;

	Faces faces;
	m_faceCascade.detectMultiScale(gray, faces, 1.1, 3, CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT, cv::Size(30, 30));

	unsigned int subjectiveAlertness = 0; // start out with the lowest alertness.
#if defined(NDEBUG)
	if (!faces.empty())
	{
		subjectiveAlertness += 1;

		const cv::Mat && faceROI = gray(faces[0]);

		typedef std::vector<cv::Rect> Eyes;
		Eyes eyes;
		m_eyesCascade.detectMultiScale(faceROI, eyes, 1.1, 3, CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));

		subjectiveAlertness += eyes.size() > 1 ? 1 : 0;
	}
#else
	std::for_each(
		faces.cbegin(),
		faces.cend(),
		[&](const Faces::value_type & face)
	{
		++subjectiveAlertness;

		cv::ellipse(
			src,
			cv::Point(face.x + face.width*0.5, face.y + face.height*0.5),
			cv::Size(face.width*0.5, face.height*0.5),
			0,
			0,
			360,
			cv::Scalar(0, 255, 127),
			4,
			8,
			0);

		const cv::Mat && faceROI = gray(face);

		typedef std::vector<cv::Rect> Eyes;

		Eyes eyes;
		m_eyesCascade.detectMultiScale(faceROI, eyes, 1.1, 3, CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));

		subjectiveAlertness += eyes.size() > 1 ? 1 : 0;

		std::for_each(
			eyes.cbegin(),
			eyes.cend(),
			[&](const Eyes::value_type & eye)
		{
			cv::circle(
				src,
				cv::Point((face.x + eye.x + eye.width*0.5), (face.y + eye.y + eye.height*0.5)),
				cvRound((eye.width + eye.height) * 0.25),
				cv::Scalar(127, 0, 127),
				4,
				8,
				0);
		});
	});
#endif

	switch (subjectiveAlertness)
	{
	case 2:
		m_awareness->onStaring(src);
		break;

	case 1:
		m_awareness->onBlink(src);
		break;

	default:
		m_awareness->onNotLooking(src);
		break;
	}
}
Example #19
0
void Field::writeCellDataToVTK( std::ostream& fs,  const Faces& faces ) const
{
	fs << "CELL_DATA " << faces.nActive() << std::endl;
	fs << "SCALARS " << _name << " double " << _nDim << std::endl;
	if ( _nDim == 1 )
	{
		for (int i = 0; i < faces.N(); ++i )
		{
			if ( faces.isActive(i) )
			{
				std::vector<int> faceVerts = faces.vertices(i);
				for ( int j = 0; j < faces.nVerts(i); ++j)
				{
					double subTriAvg = scalar[ faces.centerParticle(i) ];
					subTriAvg += scalar[ faceVerts[j] ] + scalar[ faceVerts[(j+1)%faces.nVerts(i)] ];
					subTriAvg /= 3.0;
					
					fs << subTriAvg << std::endl;
				}
			}
		}
	}
	else if ( _nDim == 2 )
	{
		for (int i = 0; i < faces.N(); ++i )
		{
			if ( faces.isActive(i) )
			{
				std::vector<int> faceVerts = faces.vertices(i);
				for ( int j = 0; j < faces.nVerts(i); ++j)
				{
					double subTriAvgX = xComp[ faces.centerParticle(i) ];
					double subTriAvgY = yComp[ faces.centerParticle(i) ];
					subTriAvgX += xComp[ faceVerts[j] ] + xComp[ faceVerts[(j+1)%faces.nVerts(i)] ];
					subTriAvgY += yComp[ faceVerts[j] ] + yComp[ faceVerts[(j+1)%faces.nVerts(i)] ];
					subTriAvgX /= 3.0;
					subTriAvgY /= 3.0;
					
					fs << subTriAvgX << "     " << subTriAvgY << std::endl;
				}
			}
		}
	}
	else
	{
		for (int i = 0; i < faces.N(); ++i )
		{
			if ( faces.isActive(i) )
			{
				std::vector<int> faceVerts = faces.vertices(i);
				for ( int j = 0; j < faces.nVerts(i); ++j)
				{
					double subTriAvgX = xComp[ faces.centerParticle(i) ];
					double subTriAvgY = yComp[ faces.centerParticle(i) ];
					double subTriAvgZ = zComp[ faces.centerParticle(i) ];
					subTriAvgX += xComp[ faceVerts[j] ] + xComp[ faceVerts[(j+1)%faces.nVerts(i)] ];
					subTriAvgY += yComp[ faceVerts[j] ] + yComp[ faceVerts[(j+1)%faces.nVerts(i)] ];
					subTriAvgZ += zComp[ faceVerts[j] ] + zComp[ faceVerts[(j+1)%faces.nVerts(i)] ];
					subTriAvgX /= 3.0;
					subTriAvgY /= 3.0;
					subTriAvgZ /= 3.0;
					
					fs << subTriAvgX << "     "<< subTriAvgY << "     "<< subTriAvgZ << std::endl;
				}
			}
		}
	}
};