Exemple #1
0
std::pair<bool, typename graph_pack_t::clone_t> ProcessTwoBreakAndClone<graph_pack_t>::create_clone(graph_pack_t & graph_pack, 
    mularcs_t const & mularcs_mother, 
    vertex_t const & v, vertex_t const & father, mularcs_t const & mularcs_father, 
    set_arc_t const & mobile_mother, set_arc_t const & mobile_father) { 

  bool sligshot = (mularcs_mother.size() == 1) && (mularcs_father.size() != 1) 
      && graph_pack.multicolors.is_vec_T_consistent_color(mularcs_mother.cbegin()->second)
      && (mobile_mother.count(*mularcs_mother.cbegin()) != 0);
  size_t count_mobile_father = 0;
  for (auto arc = mularcs_father.cbegin(); arc != (mularcs_father.cend()) && sligshot; ++arc) {
    sligshot = (graph_pack.multicolors.is_vec_T_consistent_color(arc->second));// && (mobile_father.count(*arc) != 0));
    if (mobile_father.count(*arc) != 0) { 
      ++count_mobile_father;
    } 
  }
  assert(mularcs_mother.cbegin()->second == mularcs_father.union_multicolors());   
  
  clone_t clone;
  bool result = false;
  if (sligshot && count_mobile_father > 0) { 
    vertex_t const & mother = mularcs_mother.begin()->first;        
    if (mother == Infty) {
      vertex_t pseudo_vertex = graph_pack.request_pseudo_infinity_vertex();
      clone = clone_t(edge_t(father, v), mularcs_father, arc_t(pseudo_vertex, mularcs_mother.cbegin()->second), true);  
      result = true;
    } else {
      clone = clone_t(edge_t(father, v), mularcs_father, *(mularcs_mother.cbegin()), false);  
      result = true;
    }  
  }

  return std::make_pair(result, clone);
}
inline void ConstraintContainer1::push_on_edges(Constraint *p, const Machine::PTransition *t, Constraint *c){
  if(edge_count == int(edges.size())){
    edges.resize(edge_count*2);
  }
  edges[edge_count] = edge_t(p,t,c);
  edge_count++;
};
Exemple #3
0
void greedy_edge_add( solution & sol, 
                      const std::vector<vertex_t> & new_vertices,
                      const std::vector<std::vector<vertex_t> > & adjacency_list )

{                     
    //TODO: ensure to prevent duplicates
    //      could happen using an adjacency
    std::vector<int> vertex_added( adjacency_list.size(), 0);



    // TODO: this sort order is very important for beeing better than solutuin 1.1 ;)
    //       so we have to work on edge allocation as well
    auto new_vertices_sorted= new_vertices;
    std::sort( new_vertices_sorted.begin(), new_vertices_sorted.end() );


    //for( auto new_vert= new_vertices.begin(); new_vert!=new_vertices.end(); ++new_vert )
    for( auto new_vert= new_vertices_sorted.begin(); new_vert!=new_vertices_sorted.end(); ++new_vert )
    {
        auto neighbours= adjacency_list[*new_vert];

        for( auto neighbour= neighbours.begin(); neighbour!=neighbours.end(); ++neighbour )
        {
            // only add edges to vertices which are already in the spine
            if( sol.vertex_in_spine(*neighbour) && 
                !vertex_added[*neighbour] )
            {
                insert_on_next_crossfree_page(sol, edge_t(*new_vert,*neighbour) );
            }
        }
        vertex_added[*new_vert] = 1;
    }
}
Exemple #4
0
//--------------------------------------------------------------------------
inline void callgraph_t::create_edge(int id1, int id2)
{
  edges.push_back(edge_t(id1, id2));
}
vector< vector < set < vector< vector<int> > > > > myGraph::findPathforTwoNodes(int pid1, int type1, int id1, int pid2, int type2, int id2)
{
	vector<vector<int>> pathVector;
	vector< vector < set < vector< vector<int> > > > > linkededge;

	//vertexInfo
	//...
	//Graph
	//find node set

	vector<int> node1(3,-1), node2(3,-1), edge_t(2,-1);
	vector<vector<int>> AEdge;
	AEdge.push_back(node1), AEdge.push_back(node2);
		
	
	int start, end;
	
	node1[0] = pid1, node1[1] = type1, node1[2] = id1;
	node2[0] = pid2, node2[1] = type2, node2[2] = id2;
	
	start = findNodeID(node1, nodeVector);
	end = findNodeID(node2, nodeVector);

	if(start<0 || end<0)
		return linkededge;

	findAllPathesBetweenTwoNodes(start, end, totalNode, totalEdge, _Graph, pathVector);	

	/*findAllPathes(18, 20, totalnode, totaledge, GRAPH, pathVector);	
	findAllPathes(1, 10, totalnode, totaledge, GRAPH, pathVector);	
	findAllPathes(15, 20, totalnode, totaledge, GRAPH, pathVector);	
	findAllPathes(25, 20, totalnode, totaledge, GRAPH, pathVector);	*/

	//if(pid1 >= linkededge.size())	   linkededge.resize(pid1+1);
	//if(pid2 >= linkededge.size())	   linkededge.resize(pid2+1);

	/*if(m_pathwayID>=linkedProtein.size())	   linkedProtein.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedSmallMolecule.size())        linkedSmallMolecule.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedComplex.size()) 	   linkedComplex.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedDna.size()) 	   linkedDna.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedReaction.size()) 	   linkedReaction.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedANode.size()) 	   linkedANode.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedCompartment.size())    linkedCompartment.resize(m_pathwayID+1);
	if(m_pathwayID>=linkedPathway.size())    linkedPathway.resize(m_pathwayID+1);*/
	
	for(int i=0; i<pathVector.size(); ++i)
    {
		set < vector < vector<int> > > path;
		set <int> pids;
		for(int j=0; j<pathVector[i].size()-1; ++j)
		{
			int id1=pathVector[i][j], id2=pathVector[i][j+1];
			AEdge[0] = nodeVector[id1];  AEdge[1]= nodeVector[id2];
            path.insert(AEdge);	
			pids.insert(AEdge[0][0]);
			pids.insert(AEdge[1][0]);
		}	
		for(set<int>::iterator it=pids.begin(); it!=pids.end(); it++)
        {
			int ptid = *it;
			if(ptid>=linkededge.size())
				linkededge.resize(ptid+1);

			linkededge[ptid].push_back(path);			
		}		
	}
	//getGraphToBePaint();	
	return linkededge;
}
Exemple #6
0
void extract_command_t::add_candidate_edge( const edge_t& e, node_t *src, std::vector<edge_t>& edges)
{
	if( e.src->selected() && !e.dst->selected())
		edges.push_back( edge_t( src, e.dst, e.port));
}
void BasicMesh::Subdivide() {
  // Loop subdivision
  // NOTE The indices of the original set of vertices do not change after
  // subdivision. The new vertices are simply added to the set of vertices.
  // However, the faces change their indices after subdivision. See how new
  // faces are added to the face set for details.
  // In short, the new mesh is created as follows:
  //   [old vertices]
  //   [new vertices]
  //   [faces]

  // For each edge, compute its center point
  struct edge_t {
    edge_t() {}
    edge_t(int s, int t) : s(s), t(t) {}
    edge_t(const edge_t& e) : s(e.s), t(e.t) {}
    bool operator<(const edge_t& other) const {
      if(s < other.s) return true;
      else if( s > other.s ) return false;
      else return t < other.t;
    }
    int s, t;
  };

  struct face_edge_t {
    face_edge_t() {}
    face_edge_t(int fidx, edge_t e) : fidx(fidx), e(e) {}
    bool operator<(const face_edge_t& other) const {
      if(fidx < other.fidx) return true;
      else if(fidx > other.fidx) return false;
      return e < other.e;
    }
    int fidx;
    edge_t e;
  };

  const int num_faces = NumFaces();

  map<edge_t, Vector3d> midpoints;

  // iterate over all edges
  for (HalfEdgeMesh::EdgeIter e=hemesh.edges_begin(); e!=hemesh.edges_end(); ++e) {
    auto heh = hemesh.halfedge_handle(e, 0);
    auto hefh = hemesh.halfedge_handle(e, 1);

    auto v0h = hemesh.to_vertex_handle(heh);
    auto v1h = hemesh.to_vertex_handle(hefh);

    int v0idx = vhandles_map[v0h];
    int v1idx = vhandles_map[v1h];

    auto v0 = verts.row(v0idx);
    auto v1 = verts.row(v1idx);

    if(hemesh.is_boundary(*e)) {
      // simply compute the mid point
      midpoints.insert(make_pair(edge_t(v0idx, v1idx),
                                 0.5 * (v0 + v1)));
    } else {
      // use [1/8, 3/8, 3/8, 1/8] weights
      auto v2h = hemesh.to_vertex_handle(hemesh.next_halfedge_handle(heh));
      auto v3h = hemesh.to_vertex_handle(hemesh.next_halfedge_handle(hefh));

      int v2idx = vhandles_map[v2h];
      int v3idx = vhandles_map[v3h];

      auto v2 = verts.row(v2idx);
      auto v3 = verts.row(v3idx);

      midpoints.insert(make_pair(edge_t(v0idx, v1idx), (v0 * 3 + v1 * 3 + v2 + v3) / 8.0));
    }
  }

  // Now create a new set of vertices and faces
  const int num_verts = NumVertices() + midpoints.size();
  MatrixX3d new_verts(num_verts, 3);

  // Smooth these points
  for(int i=0;i<NumVertices();++i) {
    auto vh = vhandles[i];
    if(hemesh.is_boundary(vh)) {
      // use [1/8, 6/8, 1/8] weights
      auto heh = hemesh.halfedge_handle(vh);
      if(heh.is_valid()) {
        assert(hemesh.is_boundary(hemesh.edge_handle(heh)));

        auto prev_heh = hemesh.prev_halfedge_handle(heh);

        auto to_vh = hemesh.to_vertex_handle(heh);
        auto from_vh = hemesh.from_vertex_handle(prev_heh);

        Vector3d p = 6 * verts.row(i);
        p += verts.row(vhandles_map[to_vh]);
        p += verts.row(vhandles_map[from_vh]);
        p /= 8.0;
        new_verts.row(i) = p;
      }
    } else {
      // loop through the neighbors and count them
      int valence = 0;
      Vector3d p(0, 0, 0);
      for(auto vvit = hemesh.vv_iter(vh); vvit.is_valid(); ++vvit) {
        ++valence;
        p += verts.row(vhandles_map[*vvit]);
      }
      const double PI = 3.1415926535897;
      const double wa = (0.375 + 0.25 * cos(2.0 * PI / valence));
      const double w = (0.625 - wa * wa);
      p *= (w / valence);
      p += verts.row(i) * (1 - w);
      new_verts.row(i) = p;
    }
  }

  // Add the midpoints
  map<edge_t, int> midpoints_indices;
  int new_idx = NumVertices();
  for(auto p : midpoints) {
    midpoints_indices.insert(make_pair(p.first, new_idx));
    midpoints_indices.insert(make_pair(edge_t(p.first.t, p.first.s), new_idx));

    new_verts.row(new_idx) = p.second;
    ++new_idx;
  }

  // Process the texture coordinates
  map<face_edge_t, Vector2d> midpoints_texcoords;

  for(int fidx=0;fidx<NumFaces();++fidx){
    int j[] = {1, 2, 0};
    for(int i=0;i<3;++i) {
      int v0idx = faces(fidx, i);
      int v1idx = faces(fidx, j[i]);

      // if v0 = f[index_of(v0)], the tv0 = tf[index_of(v0)]
      int tv0idx = face_tex_index(fidx, i);
      // if v1 = f[index_of(v1)], the tv1 = tf[index_of(v1)]
      int tv1idx = face_tex_index(fidx, j[i]);

      auto t0 = texcoords.row(tv0idx);
      auto t1 = texcoords.row(tv1idx);

      // the texture coordinates is always the mid point
      midpoints_texcoords.insert(make_pair(face_edge_t(fidx, edge_t(v0idx, v1idx)),
                                           0.5 * (t0 + t1)));
    }
  }

  const int num_texcoords = texcoords.rows() + midpoints_texcoords.size();
  MatrixX2d new_texcoords(num_texcoords, 2);

  // Just copy the existing texture coordinates
  new_texcoords.topRows(texcoords.rows()) = texcoords;

  // Tex-coords for the mid points
  map<face_edge_t, int> midpoints_texcoords_indices;
  int new_texcoords_idx = texcoords.rows();
  for(auto p : midpoints_texcoords) {
    //cout << p.first.fidx << ": " << p.first.e.s << "->" << p.first.e.t << endl;
    //getchar();
    midpoints_texcoords_indices.insert(make_pair(p.first,
                                                 new_texcoords_idx));
    midpoints_texcoords_indices.insert(make_pair(face_edge_t(p.first.fidx, edge_t(p.first.e.t, p.first.e.s)),
                                                 new_texcoords_idx));

    new_texcoords.row(new_texcoords_idx) = p.second;
    ++new_texcoords_idx;
  }

  MatrixX3i new_faces(num_faces*4, 3);
  MatrixX3i new_face_tex_index(num_faces*4, 3);
  for(int i=0;i<num_faces;++i) {
    // vertex indices of the original triangle
    auto vidx0 = faces(i, 0);
    auto vidx1 = faces(i, 1);
    auto vidx2 = faces(i, 2);

    // texture coordinates indices of the original triangle
    auto tvidx0 = face_tex_index(i, 0);
    auto tvidx1 = face_tex_index(i, 1);
    auto tvidx2 = face_tex_index(i, 2);

    // indices of the mid points
    int nvidx01 = midpoints_indices[edge_t(vidx0, vidx1)];
    int nvidx12 = midpoints_indices[edge_t(vidx1, vidx2)];
    int nvidx20 = midpoints_indices[edge_t(vidx2, vidx0)];

    // indices of the texture coordinates of the mid points
    int tnvidx01 = midpoints_texcoords_indices.at(face_edge_t(i, edge_t(vidx0, vidx1)));
    int tnvidx12 = midpoints_texcoords_indices.at(face_edge_t(i, edge_t(vidx1, vidx2)));
    int tnvidx20 = midpoints_texcoords_indices.at(face_edge_t(i, edge_t(vidx2, vidx0)));

    // add the 4 new faces
    new_faces.row(i*4+0) = Vector3i(vidx0, nvidx01, nvidx20);
    new_faces.row(i*4+1) = Vector3i(nvidx20, nvidx01, nvidx12);
    new_faces.row(i*4+2) = Vector3i(nvidx20, nvidx12, vidx2);
    new_faces.row(i*4+3) = Vector3i(nvidx01, vidx1, nvidx12);

    new_face_tex_index.row(i*4+0) = Vector3i(tvidx0, tnvidx01, tnvidx20);
    new_face_tex_index.row(i*4+1) = Vector3i(tnvidx20, tnvidx01, tnvidx12);
    new_face_tex_index.row(i*4+2) = Vector3i(tnvidx20, tnvidx12, tvidx2);
    new_face_tex_index.row(i*4+3) = Vector3i(tnvidx01, tvidx1, tnvidx12);
  }

  verts = new_verts;
  faces = new_faces;
  texcoords = new_texcoords;
  face_tex_index = new_face_tex_index;

  // Update the normals after subdivision
  ComputeNormals();
}