Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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]]));
        }
    };
Ejemplo n.º 3
0
/**
 * List up all the vertices that have to be tested for the conflict graph.
 */
void listUpdateVertices(Arrangement &arr, Vertex *v, Edges &horizon, Vertices &vertices)
{
	map<Vertex*, bool> hashtable;

	for (int i = 0; i < horizon.size(); ++i) {
		Face* f1 = horizon[i]->face;
		Face* f2 = horizon[i]->twin->face;

		for (int j = 0; j < f1->visibleVertices.size(); ++j) {
			if (f1->visibleVertices[j] != v) {
				hashtable[f1->visibleVertices[j]] = true;
			}
		}
		for (int j = 0; j < f2->visibleVertices.size(); ++j) {
			if (f2->visibleVertices[j] != v) {
				hashtable[f2->visibleVertices[j]] = true;
			}
		}
	}

	for (map<Vertex*, bool>::iterator it = hashtable.begin(); it != hashtable.end(); ++it) {
		vertices.push_back((*it).first);
	}
}
Ejemplo n.º 4
0
int main() {

    /*
    #Graph

        The following class hierarchy exists:

            BidirectionalGraph -------- Incience ---------+
                                                          |
                                        Adjacency --------+
                                                          |
            VertexAndEdgeList ----+---- VertexList -------+---- Graph
                                  |                       |
                                  +---- EdgeList ---------+
                                                          |
                                        AdjacenyMatrix ---+
    */
    {
        /*
        #properties

            Properties are values associated to edges and vertices.
        */
        {
            /*
            There are a few predefined properties which you should use whenever possible
            as they are already used in many algorithms, but you can also define your own properties.

            Predefined properties include:

            - `edge_weight_t`. Used for most algorithms that have a single value associated to each
                edge such as Dijikstra.

            - `vertex_name_t`
            */
            {
                typedef boost::property<boost::vertex_name_t, std::string> VertexProperties;
                typedef boost::property<boost::edge_weight_t, int> EdgeProperties;
            }

            /*
            Multiple properties can be specified either by:

            - using a custom class as the property type. TODO is there any limitation to this?
            - chaining multile properties
            */
            {
            }

            /*
            The absense of a property is speficied by boost::no_property.
            */
            {
                typedef boost::no_property VertexProperties;
            }

        }

        typedef boost::property<boost::vertex_name_t, std::string> VertexProperties;
        typedef boost::property<boost::edge_weight_t, int> EdgeProperties;
        typedef boost::adjacency_list<
            // Data structure to represent the out edges for each vertex.
            // Possibilities:
            //
            // #vecS selects std::vector.
            // #listS selects std::list.
            // #slistS selects std::slist.
            // #setS selects std::set.
            // #multisetS selects std::multiset.
            // #hash_setS selects std::hash_set.
            //
            // `S` standas for Selector.
            boost::vecS,

            // Data structure to represent the vertex set.
            boost::vecS,

            // Directed type.
            // #bidirectionalS: directed graph with access to in and out edges
            // #directedS:      directed graph with access only to out-edges
            // #undirectedS:    undirected graph
            boost::bidirectionalS,

            // Optional.
            VertexProperties,

            // Optional.
            EdgeProperties
        > Graph;
        //typedef boost::graph_traits<Graph>::vertex_iterator VertexIter;
        //typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
        //typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;

        // Fix number of vertices, and add one edge at a time.
        int num_vertices = 3;
        Graph g(num_vertices);
        boost::add_edge(0, 1, g);
        boost::add_edge(1, 2, g);

        // Fix number of vertices, and add one edge array.
        {
            int num_vertices = 3;
            typedef std::pair<int, int> Edge;
            std::vector<Edge> edges{
                {0, 1},
                {1, 2},
            };
            Graph g(edges.data(), edges.data() + edges.size(), num_vertices);
        }

        // It is also possible to add vertices with #add_vertex.

        //#vertices
        {
            // Number of vertices.
            boost::graph_traits<Graph>::vertices_size_type num_vertices = boost::num_vertices(g);
            assert(num_vertices == 3u);

            //#vertices() Returns a begin() end() vertex iterator pair so we know where to stop.
            {
                typedef std::vector<boost::graph_traits<Graph>::vertex_descriptor> Vertices;
                Vertices vertices;
                vertices.reserve(num_vertices);
                //IndexMap
                auto index = boost::get(boost::vertex_index, g);
                //std::pair<vertex_iter, vertex_iter> vp
                for (auto vp = boost::vertices(g); vp.first != vp.second; ++vp.first) {
                    // Vertex
                    auto v = *vp.first;
                    vertices.push_back(index[v]);
                }
                assert((vertices == Vertices{0, 1, 2}));
            }

            // The iterator is a ranom access iterator.
            {
                auto index = boost::get(boost::vertex_index, g);
                auto it = boost::vertices(g).first;
                assert(index[it[2]] == 2);
                assert(index[it[1]] == 1);
            }
        }

        //#edges
        {
            // It seems that only AdjencyMatrix has a method to get an edge given two vertices:
            //edge(u, v, g)
        }
    }

    //#source is also a global function: <http://stackoverflow.com/questions/16114616/why-is-boost-graph-librarys-source-a-global-function>

    //#dijikstra
    std::cout << "#dijkstra" << std::endl;
    {
        typedef boost::adjacency_list<
            boost::listS,
            boost::vecS,
            boost::directedS,
            boost::no_property,
            boost::property<boost::edge_weight_t, int>
        > Graph;
        typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
        typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
        typedef std::pair<int, int> Edge;

        // Model inputs.
        const int num_nodes = 5;
        const int sorce = 0;
        std::vector<Edge> edges{
            {0, 2}, {1, 1}, {1, 3}, {1, 4}, {2, 1},
            {2, 3}, {3, 4}, {4, 0}, {4, 1}
        };
        std::vector<int> weights{
            1, 2, 1, 2, 7,
            3, 1, 1, 1
        };

        // Solve.
        Graph g(edges.data(), edges.data() + edges.size(), weights.data(), num_nodes);
        std::vector<vertex_descriptor> p(num_vertices(g));
        std::vector<int> d(num_vertices(g));
        vertex_descriptor s = vertex(sorce, g);
        dijkstra_shortest_paths(g, s,
            predecessor_map(boost::make_iterator_property_map(
                p.begin(),
                boost::get(boost::vertex_index, g)
            )).distance_map(boost::make_iterator_property_map(
                d.begin(),
                boost::get(boost::vertex_index, g)
            ))
        );

        // Print solution to stdout.
        std::cout << "node | distance from source | parent" << std::endl;
        boost::graph_traits<Graph>::vertex_iterator vi, vend;
        for (boost::tie(vi, vend) = vertices(g); vi != vend; ++vi)
            std::cout << *vi << " " << d[*vi] << " " << p[*vi] << std::endl;
        std::cout <<std::endl;

        // Generate a .dot graph file with shortest path highlighted.
        // To PNG with: dot -Tpng -o outfile.png input.dot
        boost::property_map<Graph, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, g);
        std::ofstream dot_file("dijkstra.dot");
        dot_file << "digraph D {\n"      << "  rankdir=LR\n"           << "  size=\"4,3\"\n"
                 << "  ratio=\"fill\"\n" << "  edge[style=\"bold\"]\n" << "  node[shape=\"circle\"]\n";
        boost::graph_traits <Graph>::edge_iterator ei, ei_end;
        for (std::tie(ei, ei_end) = boost::edges(g); ei != ei_end; ++ei) {
            edge_descriptor e = *ei;
            boost::graph_traits<Graph>::vertex_descriptor
                u = boost::source(e, g), v = boost::target(e, g);
            dot_file << u << " -> " << v << "[label=\"" << boost::get(weightmap, e) << "\"";
            if (p[v] == u)
                dot_file << ", color=\"black\"";
            else
                dot_file << ", color=\"grey\"";
            dot_file << "]";
        }
        dot_file << "}";

        // Construct forward path to a destination.
        int dest = 4;
        int cur = dest;
        std::vector<int> path;
        path.push_back(cur);
        while(cur != sorce) {
            cur = p[cur];
            path.push_back(cur);
        }
        std::reverse(path.begin(), path.end());
        // Print.
        std::cout << "Path to node " << std::to_string(dest) << ":" << std::endl;
        for(auto& node : path) {
            std::cout << node << std::endl;
        }
    }
}
Ejemplo n.º 5
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() );
}
Ejemplo n.º 6
0
pcl::simulation::TriangleMeshModel::TriangleMeshModel (pcl::PolygonMesh::Ptr plg)
{
  Vertices vertices;
  Indices indices;

  bool found_rgb = false;
  for (size_t i=0; i < plg->cloud.fields.size () ; ++i)
    if (plg->cloud.fields[i].name.compare ("rgb") == 0)
      found_rgb = true;

  if (found_rgb)
  {
    pcl::PointCloud<pcl::PointXYZRGB> newcloud;
    pcl::fromROSMsg (plg->cloud, newcloud);

    PCL_DEBUG("RGB Triangle mesh: ");
    PCL_DEBUG("Mesh polygons: %ld", plg->polygons.size ());
    PCL_DEBUG("Mesh points: %ld", newcloud.points.size ());

    Eigen::Vector4f tmp;
    for(size_t i=0; i< plg->polygons.size (); ++i)
    { // each triangle/polygon
      pcl::Vertices apoly_in = plg->polygons[i];
      for(size_t j = 0; j < apoly_in.vertices.size (); ++j)
      { // each point
        uint32_t pt = apoly_in.vertices[j];
        tmp = newcloud.points[pt].getVector4fMap();
        vertices.push_back (Vertex (Eigen::Vector3f (tmp (0), tmp (1), tmp (2)),
                                    Eigen::Vector3f (newcloud.points[pt].r/255.0f,
                                                     newcloud.points[pt].g/255.0f,
                                                     newcloud.points[pt].b/255.0f)));
        indices.push_back (indices.size ());
      }
    }
  }
  else
  {
    pcl::PointCloud<pcl::PointXYZ> newcloud;
    pcl::fromROSMsg (plg->cloud, newcloud);
    Eigen::Vector4f tmp;
    for(size_t i=0; i< plg->polygons.size (); i++)
    { // each triangle/polygon
      pcl::Vertices apoly_in = plg->polygons[i];
      for(size_t j=0; j< apoly_in.vertices.size (); j++)
      { // each point
        uint32_t pt = apoly_in.vertices[j];
        tmp = newcloud.points[pt].getVector4fMap();
        vertices.push_back (Vertex (Eigen::Vector3f (tmp (0), tmp (1), tmp (2)),
                                    Eigen::Vector3f (1.0, 1.0, 1.0)));
        indices.push_back (indices.size ());
      }
    }
  }

  PCL_DEBUG("Vertices: %ld", vertices.size ());
  PCL_DEBUG("Indices: %ld", indices.size ());

  glGenBuffers (1, &vbo_);
  glBindBuffer (GL_ARRAY_BUFFER, vbo_);
  glBufferData (GL_ARRAY_BUFFER, vertices.size () * sizeof (vertices[0]), &(vertices[0]), GL_STATIC_DRAW);
  glBindBuffer (GL_ARRAY_BUFFER, 0);

  glGenBuffers (1, &ibo_);
  glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, ibo_);
  glBufferData (GL_ELEMENT_ARRAY_BUFFER, indices.size () * sizeof (indices[0]), &(indices[0]), GL_STATIC_DRAW);
  glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);

  if (indices.size () > std::numeric_limits<GLuint>::max ())
    PCL_THROW_EXCEPTION(PCLException, "Too many vertices");

  size_ = static_cast<GLuint>(indices.size ());
}
	Maxclique(const BB* conn, const int sz, const float tt = 0.025) \
	 : pk(0), level(1), Tlimit(tt){
		for(int i = 0; i < sz; i++) V.push_back(Vertex(i));
		e = conn, C.resize(sz + 1), S.resize(sz + 1);
	}
	void cut2(const Vertices &A, Vertices &B){
		for(int i = 0; i < (int)A.size() - 1; i++)
			if(e[A.back().i][A[i].i])
				B.push_back(A[i].i);
	}
Ejemplo n.º 9
0
/// Read an event and fill a vector of MCParticles.
Geant4EventReader::EventReaderStatus
Geant4EventReaderGuineaPig::readParticles(int /* event_number */, 
                                          Vertices& vertices,
                                          vector<Particle*>& particles)   {


  // if no number of particles per event set, we will read the whole file
  if ( m_part_num < 0 )
    m_part_num = std::numeric_limits<int>::max() ; 



  // First check the input file status
  if ( m_input.eof() )   {
    return EVENT_READER_EOF;
  }
  else if ( !m_input.good() )   {
    return EVENT_READER_IO_ERROR;
  }

  double Energy;
  double betaX;
  double betaY;
  double betaZ;
  double posX;
  double posY;
  double posZ;

  //  Loop over particles
  for( int counter = 0; counter < m_part_num ; ++counter ){      

    // need to check for NAN as not all ifstream implementations can handle this directly
    std::string lineStr ;
    std::getline( m_input, lineStr ) ;

    if( m_input.eof() ) {
      if( counter==0 ) { 
        return EVENT_READER_IO_ERROR ;  // reading first particle of event failed 
      } else{
        ++m_currEvent;
        return EVENT_READER_OK ; // simply EOF
      }
    }

    std::transform(lineStr.begin(), lineStr.end(), lineStr.begin(), ::tolower);
    if( lineStr.find("nan") != std::string::npos){

      printout(WARNING,"EventReader","### Read line with 'nan' entries - particle will be ignored  ! " ) ;
      continue ;
    }
    std::stringstream m_input_str( lineStr ) ;

    m_input_str  >> Energy
		 >> betaX   >> betaY >> betaZ
		 >> posX    >> posY  >> posZ ;

    
    //    printf(" ------- %e  %e  %e  %e  %e  %e  %e \n", Energy,betaX, betaY,betaZ,posX,posY,posZ ) ;

    //
    //  Create a MCParticle and fill it from stdhep info
    Particle* p = new Particle(counter);
    PropertyMask status(p->status);

    //  PDGID: If Energy positive (negative) particle is electron (positron)
    p->pdgID  = 11;
    p->charge = -1;
    if(Energy < 0.0) {
      p->pdgID = -11;
      p->charge = +1;
    }

    //  Momentum vector
    p->pex = p->psx = betaX*TMath::Abs(Energy)*GeV;
    p->pey = p->psy = betaY*TMath::Abs(Energy)*GeV;
    p->pez = p->psz = betaZ*TMath::Abs(Energy)*GeV;

    //  Mass
    p->mass = 0.0005109989461*GeV;
    //


    //  Creation time (note the units [1/c_light])
    // ( not information in GuineaPig files )
    p->time       = 0.0;
    p->properTime = 0.0;


    //  Vertex
    p->vsx = posX*nm;
    p->vsy = posY*nm;
    p->vsz = posZ*nm;

    Vertex* vtx = new Vertex ;
    vtx->x = p->vsx ;
    vtx->y = p->vsy ;
    vtx->z = p->vsz ;
    vtx->time = p->time ;

    vtx->out.insert( p->id ); 

    //
    //  Generator status
    //  Simulator status 0 until simulator acts on it
    p->status = 0;
    status.set(G4PARTICLE_GEN_STABLE);


    //  Add the particle to the collection vector
    particles.push_back(p);

    // create a new vertex for this particle
    vertices.push_back( vtx) ;


  } // End loop over particles

  ++m_currEvent;

  return EVENT_READER_OK;

}
Ejemplo n.º 10
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;
};
Ejemplo n.º 11
0
void InitVertices(	unsigned recursionDepth, float edgeSize,
					Vertices &pyramidVertices,
					Indices &pyramidIndices)
{
	assert( 0 == pyramidIndices.size() );
	assert( 0 == pyramidVertices.size() );

	std::vector<Node> nodes;

	const float alpha = atanf( sqrtf(2.0f) );
	const float cosAlpha = cosf(alpha);
	const float sinAlpha = sinf(alpha);

	//top right triangle
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
										sinAlpha,  cosAlpha,  0.0f ) );

	//top back triangle
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f,  cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f,  cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f,  cosAlpha,  sinAlpha ) );

	//top left triangle
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
									   -sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
									   -sinAlpha,  cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
									   -sinAlpha,  cosAlpha,  0.0f ) );

	//top fron triangle
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f,  cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f,  cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex(  0.0f,  edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f,  cosAlpha, -sinAlpha ) );



	//bottom right triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
										sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										sinAlpha, -cosAlpha,  0.0f ) );

	//bottom back triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f, -cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f, -cosAlpha,  sinAlpha ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
										0.0f, -cosAlpha,  sinAlpha ) );

	//bottom left triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
									   -sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f,  edgeSize/ 2,
									   -sinAlpha, -cosAlpha,  0.0f ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
									   -sinAlpha, -cosAlpha,  0.0f ) );

	//bottom fron triangle
	pyramidVertices.push_back( Vertex(  0.0f, -edgeSize*sqrtf(2.0f)/2, 0.0f,
										0.0f, -cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex( -edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f, -cosAlpha, -sinAlpha ) );
	pyramidVertices.push_back( Vertex(  edgeSize/2, 0.0f, -edgeSize/ 2,
										0.0f, -cosAlpha, -sinAlpha ) );


	for( Index index=0; index<pyramidVertices.size(); ++index )
	{
		nodes.push_back( Node(NULL, NULL, index) );
	}

	for( unsigned i=0; i<nodes.size(); i+=3 )
	{
		Tessellation( nodes[i], nodes[i+1], nodes[i+2], pyramidVertices, pyramidIndices, 0, recursionDepth );
	}		
}
Ejemplo n.º 12
0
void Atoms::ComputeAtoms() {
    // Get minimal triangulation
    EliminationOrder* eo = new EliminationOrder(G_);
    FillEdges* F = new FillEdges(G_);
    VertexList* minsep_generators = new VertexList();
    MCSmPlus::Run(*G_, eo, F, minsep_generators);

    std::list< VertexSet* > vertices_of_atoms;
    SeparatorComponents cc(G_);
    Vertices deleted_vertices;  // in paper, this is V(G_) - V(G_')
    std::vector< bool > is_deleted(G_->order(), false);

    // Examine minsep_generators, eo-earliest first
    for (int i : *minsep_generators) {
        // Check to see if minimal separator is a clique
        Vertex v = eo->VertexAt(i);
        Vertices S;
        for (Vertex u : G_->N(v)) {
            if (eo->Before(v, u) && !is_deleted[u]) {
                S.push_back(u);
            }
        }
        for (Vertex u : (*F)[v]) {
            if (eo->Before(v, u) && !is_deleted[u]) {
                S.push_back(u);
            }
        }
        if (G_->IsClique(S)) {
            clique_minimal_separators_.Insert(S);
            for (Vertex u : deleted_vertices) {
                S.push_back(u);
            }
            cc.Separate(S);
            Vertices C = cc.ConnectedComponent(v);
            VertexSet* atom = new VertexSet();
            for (Vertex u : C) {
                if (!is_deleted[u]) {
                    deleted_vertices.push_back(u);
                    is_deleted[u] = true;
                    atom->insert(u);
                }
            }
            for (Vertex u : S) {
                if (!is_deleted[u]) {
                    atom->insert(u);
                }
            }
            vertices_of_atoms.push_back(atom);
        }
    }
    // Remaining vertices form an atom
    Vertices C;
    for (Vertex v : *G_) {
        if (!is_deleted[v]) {
            C.push_back(v);
        }
    }
    if (!C.empty()) {
        VertexSet* atom = new VertexSet();
        for (Vertex v : C) {
            atom->insert(v);
        }
        vertices_of_atoms.push_back(atom);
    }
    for (VertexSet* U : vertices_of_atoms) {
        atom_subgraphs_.push_back(new InducedSubgraph(G_, *U));
        delete U;
    }
    delete eo;
    delete F;
    delete minsep_generators;
    return;
}