本文整理匯總了C++中Edge函數的典型用法代碼示例。如果您正苦於以下問題:C++ Edge函數的具體用法?C++ Edge怎麽用?C++ Edge使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Edge函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Edge
Edge(1, 5), Edge(5, 5), Edge(1, 7), Edge(7, 1)});
this->checkAddEdge(6, Edge(1, 7), {Edge(0, 5), Edge(5, 0), Edge(1, 7)},
{Edge(0, 1), Edge(0, 0), Edge(0, 4), Edge(0, 6),
Edge(1, 5), Edge(5, 5), Edge(7, 1)});
this->checkAddEdge(6, Edge(5, 5),
{Edge(0, 5), Edge(5, 0), Edge(1, 7), Edge(5, 5)},
{Edge(0, 1), Edge(0, 0), Edge(0, 4), Edge(0, 6), Edge(1, 5), Edge(7, 1)});
this->checkAddEdge(7, Edge(5, 6),
{Edge(0, 5), Edge(5, 0), Edge(1, 7), Edge(5, 5), Edge(5, 6)}, {});
this->checkAddEdge(8, Edge(6, 5),
{Edge(0, 5), Edge(5, 0), Edge(1, 7), Edge(5, 5), Edge(5, 6), Edge(6, 5)}, {});
}
TYPED_TEST_P(BipartiteGraphTest, addEdge_tooBigIndex)
{
ASSERT_THROW(this->g.addEdge(Edge(TypeParam::INDEX_LIMIT, 0)), typename TypeParam::exception_t);
ASSERT_THROW(this->g.addEdge(Edge(TypeParam::INDEX_LIMIT + 1, 0)), typename TypeParam::exception_t);
ASSERT_THROW(this->g.addEdge(Edge(0, TypeParam::INDEX_LIMIT)), typename TypeParam::exception_t);
ASSERT_THROW(this->g.addEdge(Edge(0, TypeParam::INDEX_LIMIT + 1)), typename TypeParam::exception_t);
ASSERT_THROW(
this->g.addEdge(Edge(TypeParam::INDEX_LIMIT, TypeParam::INDEX_LIMIT)),
typename TypeParam::exception_t);
ASSERT_THROW(
this->g.addEdge(Edge(TypeParam::INDEX_LIMIT + 1, TypeParam::INDEX_LIMIT + 1)),
typename TypeParam::exception_t);
}
TYPED_TEST_P(BipartiteGraphTest, simpleMaximumMatching)
{
this->checkMatching(3, {Edge(0, 0), Edge(1, 1), Edge(2, 2)});
}
示例2: addEdge
inline void addEdge(int u,int v,Type cost){
e[cnt] = Edge(v,cost);
int tmp = head[u];
head[u] = cnt;
nxt[cnt++] = tmp;
}
示例3: find_non_manifold_verts
// edges are given as (edges[i], edges[i+1])
void find_non_manifold_verts(const cvcraw_geometry::cvcgeom_t& geom,
std::vector<int>& non_manifold_vertices) {
static log4cplus::Logger logger =
log4cplus::Logger::getInstance("find_non_manifold_verts");
const vector<Point_3> vertices = sm_vertices(geom);
const vector<Triangle> triangles = sm_triangles(geom);
const vector<vector<Triangle> > v2t = build_v2t(triangles.begin(), triangles.end());
// set<Edge> non_manifold_edges;
// vector<int> non_manifold_vertices;
for (int vi = 0; vi < v2t.size(); ++vi) {
set<Edge> edges;
bool manifold = true;
const vector<Triangle>& tris = v2t[vi];
if (!tris.empty()){
set<Triangle> tri_set(tris.begin(), tris.end());
Triangle start_t = *tri_set.begin();
Triangle t = *tri_set.begin();
bool done = false;
const int li = t.g2l(vi);
const Edge er(t[(li+1)%3], vi);
const Edge el(t[(li+2)%3], vi);
Edge e = er;
//walk right when count = 0 and left when count =1
int count = 0;
while (count < 2){
while (!done && manifold && !tri_set.empty() && tri_set.find(t) != tri_set.end()) {
tri_set.erase(t);
// Local triangle index [012] of vi in triangle t
const vector<Triangle> adjs = adj_triangles(e, v2t);
if (adjs.size() < 2) {
// boundary
done = true;
} else if (adjs.size() > 2) {
// non_manifold edge
done = true;
manifold = false;
} else {
Triangle adj = adjs[0];
if (adj == t) {
adj = adjs[1];
}
t = adj;
e = Edge(adj.opposite(e), vi);
}
}
t = start_t;
if (count == 0 && !tri_set.empty()){
tri_set.insert(t); //just so it can be removed again
}
done = false;
e = el;
count++;
}
if (!tri_set.empty() || !manifold) {
LOG4CPLUS_TRACE(logger, "Non Manifold vert is: " << vi);
non_manifold_vertices.push_back(vi);
}
}
}
}
示例4: Edge
TriMesh<FloatType> TriMesh<FloatType>::flatLoopSubdivision(float minEdgeLength) const
{
struct Edge
{
Edge(UINT32 _v0, UINT32 _v1)
{
v0 = std::min(_v0, _v1);
v1 = std::max(_v0, _v1);
}
union
{
struct {
UINT32 v0, v1;
};
UINT64 val;
};
};
struct edgeCompare
{
bool operator() (const Edge &a, const Edge &b)
{
return a.val < b.val;
}
};
map<Edge, UINT, edgeCompare> edgeToNewVertexMap;
TriMesh<FloatType> result;
result.m_Vertices = m_Vertices;
result.m_Indices.reserve(m_Indices.size() * 4);
for (const vec3ui &tri : m_Indices)
{
/*bool subdivide = true;
for (UINT eIndex = 0; eIndex < 3; eIndex++)
{
const vec3f &v0 = m_Vertices[tri[eIndex]].position;
const vec3f &v1 = m_Vertices[tri[(eIndex + 1) % 3]].position;
float edgeLength = vec3f::dist(v0, v1);
if (edgeLength < minEdgeLength)
subdivide = false;
}*/
bool subdivide = math::triangleArea(m_Vertices[tri[0]].position, m_Vertices[tri[1]].position, m_Vertices[tri[2]].position) >= (minEdgeLength * minEdgeLength);
if (subdivide)
{
UINT edgeMidpoints[3];
for (UINT eIndex = 0; eIndex < 3; eIndex++)
{
const UINT v0 = tri[eIndex];
const UINT v1 = tri[(eIndex + 1) % 3];
Edge e = Edge(v0, v1);
if (edgeToNewVertexMap.count(e) == 0)
{
edgeToNewVertexMap[e] = (UINT)result.m_Vertices.size();
result.m_Vertices.push_back((m_Vertices[v0] + m_Vertices[v1]) * (FloatType)0.5);
}
edgeMidpoints[eIndex] = edgeToNewVertexMap[e];
}
result.m_Indices.push_back(vec3ui(tri[0], edgeMidpoints[0], edgeMidpoints[2]));
result.m_Indices.push_back(vec3ui(edgeMidpoints[0], tri[1], edgeMidpoints[1]));
result.m_Indices.push_back(vec3ui(edgeMidpoints[2], edgeMidpoints[1], tri[2]));
result.m_Indices.push_back(vec3ui(edgeMidpoints[2], edgeMidpoints[0], edgeMidpoints[1]));
}
else
{
result.m_Indices.push_back(tri);
}
}
return result;
}
示例5: while
bool ConvexHull2<Real>::Update (Edge*& rpkHull, int i)
{
// Locate an edge visible to the input point (if possible).
Edge* pkVisible = 0;
Edge* pkCurrent = rpkHull;
do
{
if (pkCurrent->GetSign(i,m_pkQuery) > 0)
{
pkVisible = pkCurrent;
break;
}
pkCurrent = pkCurrent->A[1];
}
while (pkCurrent != rpkHull);
if (!pkVisible)
{
// The point is inside the current hull; nothing to do.
return true;
}
// Remove the visible edges.
Edge* pkAdj0 = pkVisible->A[0];
assert(pkAdj0);
if (!pkAdj0)
{
return false;
}
Edge* pkAdj1 = pkVisible->A[1];
assert(pkAdj1);
if (!pkAdj1)
{
return false;
}
pkVisible->DeleteSelf();
while (pkAdj0->GetSign(i,m_pkQuery) > 0)
{
rpkHull = pkAdj0;
pkAdj0 = pkAdj0->A[0];
assert(pkAdj0);
if (!pkAdj0)
{
return false;
}
pkAdj0->A[1]->DeleteSelf();
}
while (pkAdj1->GetSign(i,m_pkQuery) > 0)
{
rpkHull = pkAdj1;
pkAdj1 = pkAdj1->A[1];
assert(pkAdj1);
if (!pkAdj1)
{
return false;
}
pkAdj1->A[0]->DeleteSelf();
}
// Insert the new edges formed by the input point and the end points of
// the polyline of invisible edges.
Edge* pkEdge0 = WM4_NEW Edge(pkAdj0->V[1],i);
Edge* pkEdge1 = WM4_NEW Edge(i,pkAdj1->V[0]);
pkEdge0->Insert(pkAdj0,pkEdge1);
pkEdge1->Insert(pkEdge0,pkAdj1);
rpkHull = pkEdge0;
return true;
}
示例6: addEdge
void addEdge(int from, int to, FLOW cost) {
edges[from].push_back(Edge(to, cost, size_of(edges[to])));
edges[to].push_back(Edge(from, FLOW(), size_of(edges[from]) - 1));
}
示例7: add_edge
int add_edge(int from, int to, T cost) {
adj_[from].push_back(Edge(edgeIndex_++, from, to, cost));
return edgeIndex_;
}
示例8: choiceBestSplitEdge
Tree::Node* Tree::contructTree_R( IndexVec& idxEdges )
{
if ( idxEdges.empty() )
return nullptr;
int idx = choiceBestSplitEdge( idxEdges );
Node* node = new Node;
node->idxEdge = idx;
if ( idx < 0 ) // leaf
{
node->tag = ~uint32( mLeaves.size() );
node->front = nullptr;
node->back = nullptr;
mLeaves.push_back( Leaf() );
Leaf& data = mLeaves.back();
data.node = node;
data.edges.swap( idxEdges );
return node;
}
else
{
node->tag = uint32( mNodes.size() );
mNodes.push_back( node );
}
//triList.erase( cIter );
IndexVec idxFronts;
IndexVec idxBacks;
Plane& plane = mEdges[ idx ].plane;
for( IndexVec::iterator iter( idxEdges.begin() ) , itEnd( idxEdges.end() ) ;
iter != itEnd ; ++iter )
{
int idxTest = *iter;
Edge& edgeTest = mEdges[ idxTest ];
Vec2f vSplit[2];
switch ( plane.splice( edgeTest.v , vSplit ) )
{
case SIDE_FRONT:
case SIDE_IN:
idxFronts.push_back( idxTest );
break;
case SIDE_BACK:
idxBacks.push_back( idxTest );
break;
case SIDE_SPLIT:
{
idxFronts.push_back( idxTest );
idxBacks.push_back( (int)mEdges.size() );
mEdges.push_back( Edge() );
Edge& edge = mEdges.back();
edge.v[0] = vSplit[0];
edge.v[1] = vSplit[1];
edge.plane = edgeTest.plane;
edge.idx = edgeTest.idx;
}
break;
}
}
node->front = contructTree_R( idxFronts );
if ( node->front )
node->front->parent = node;
node->back = contructTree_R( idxBacks );
if ( node->back )
node->back->parent = node;
node->tag = 0;
return node;
}
示例9: ERR_FAIL_COND
void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int>& p_connections) {
ERR_FAIL_COND(p_connections.size()&1);
points.clear();
edges.clear();
//insert points
int point_count=p_points.size();
points.resize(point_count+2);
bounds=Rect2();
for(int i=0;i<p_points.size();i++) {
points[i].pos=p_points[i];
points[i].penalty=0;
outside_point.x = i==0?p_points[0].x:(MAX( p_points[i].x, outside_point.x ));
outside_point.y = i==0?p_points[0].y:(MAX( p_points[i].y, outside_point.y ));
if (i==0) {
bounds.pos=points[i].pos;
} else {
bounds.expand_to(points[i].pos);
}
}
outside_point.x+=20.451+Math::randf()*10.2039;
outside_point.y+=21.193+Math::randf()*12.5412;
//insert edges (which are also connetions)
for(int i=0;i<p_connections.size();i+=2) {
Edge e(p_connections[i],p_connections[i+1]);
ERR_FAIL_INDEX(e.points[0],point_count);
ERR_FAIL_INDEX(e.points[1],point_count);
points[p_connections[i]].connections.insert(p_connections[i+1]);
points[p_connections[i+1]].connections.insert(p_connections[i]);
edges.insert(e);
}
//fill the remaining connections based on visibility
for(int i=0;i<point_count;i++) {
for(int j=i+1;j<point_count;j++) {
if (edges.has(Edge(i,j)))
continue; //if in edge ignore
Vector2 from=points[i].pos;
Vector2 to=points[j].pos;
if (!_is_point_inside(from*0.5+to*0.5)) //connection between points in inside space
continue;
bool valid=true;
for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
const Edge& e=E->get();
if (e.points[0]==i || e.points[1]==i || e.points[0]==j || e.points[1]==j )
continue;
Vector2 a = points[e.points[0]].pos;
Vector2 b = points[e.points[1]].pos;
if (Geometry::segment_intersects_segment_2d(a,b,from,to,NULL)) {
valid=false;
break;
}
}
if (valid) {
points[i].connections.insert(j);
points[j].connections.insert(i);
}
}
}
}
示例10: Link
void Link(int x, int y, int z){
E[++ tot] = Edge(y, Last[x], z), Last[x] = tot;
}
示例11: main
int main() {
Vertex v1, v2, v3;
std::vector<Edge> v {Edge(v1, v2, 1.0), Edge(v2, v3, 2.0), Edge(v3, v1, 5.0)};
return 0;
}
示例12: Edge
Edge Edge::reversed() const {
return Edge(toVertex, fromVertex);
}
示例13: H
R2 H(int i) const { ASSERTION(i>=0 && i <3);
R2 E=Edge(i);return E.perp()/(2.*this->mesure());} // heigth
示例14: TYPED_TEST_P
TYPED_TEST_P(BipartiteGraphTest, addEdge)
{
this->checkAddEdge(2, Edge(0, 5), {Edge(0, 5)},
{Edge(5, 0), Edge(0, 1), Edge(0, 0), Edge(0, 4), Edge(0, 6),
Edge(1, 5), Edge(5, 5), Edge(1, 7), Edge(7, 1)});
this->checkAddEdge(4, Edge(5, 0), {Edge(0, 5), Edge(5, 0)},
{Edge(0, 1), Edge(0, 0), Edge(0, 4), Edge(0, 6),
Edge(1, 5), Edge(5, 5), Edge(1, 7), Edge(7, 1)});
this->checkAddEdge(6, Edge(1, 7), {Edge(0, 5), Edge(5, 0), Edge(1, 7)},
{Edge(0, 1), Edge(0, 0), Edge(0, 4), Edge(0, 6),
Edge(1, 5), Edge(5, 5), Edge(7, 1)});
this->checkAddEdge(6, Edge(5, 5),
{Edge(0, 5), Edge(5, 0), Edge(1, 7), Edge(5, 5)},
{Edge(0, 1), Edge(0, 0), Edge(0, 4), Edge(0, 6), Edge(1, 5), Edge(7, 1)});
this->checkAddEdge(7, Edge(5, 6),
{Edge(0, 5), Edge(5, 0), Edge(1, 7), Edge(5, 5), Edge(5, 6)}, {});
this->checkAddEdge(8, Edge(6, 5),
{Edge(0, 5), Edge(5, 0), Edge(1, 7), Edge(5, 5), Edge(5, 6), Edge(6, 5)}, {});
}
示例15: tmp
//simplified version of divideEdges that accepts only one index => one edge
//it is a common case that one edge still goes deeper e.g. an edge between a high leaf in the tree
//and a node that goes deeper and deepper. Therefore a lot of effort can be saved by providing
//a method that works with just one edge
void EdgeHierarchy::divideEdges(TravelIndex t1, TravelIndex t2, int index) {
QuadTreeMetaNode* m1 = _quadTree->getMeta(t1.level, t1.index);
QuadTreeMetaNode* m2 = _quadTree->getMeta(t2.level, t2.index);
if (_quadTree->isLeaf(m1) && _quadTree->isLeaf(m2)) {
//both nodes are leafs add the edge as leaf edge and return
int depth = t2.level;
if (t1.level > t2.level) {
depth = t1.level;
}
Edge tmp(_edges->at(index));
tmp.depth = depth; //leaf edge positive depth
addEdge(tmp, depth);
} else {
int nodeIndexI;
int nodeIndexJ;
if (t1.level == t2.level && t1.index == t2.index) {
//edge start and end point to the same meta node
//can't be a leaf (-> if above)
Edge e = _edges->at(index);
//test where the edge belongs to
nodeIndexI = _quadTree->travelSelect(e.x1, e.y1, &t1) - 1;
nodeIndexJ = _quadTree->travelSelect(e.x2, e.y2, &t2) - 1; //t1=t2
} else {
//different nodes => insert edges
Node* n1 = _quadTree->getNode(t1.level, t1.index);
Node* n2 = _quadTree->getNode(t2.level, t2.index);
int depth = t2.level;
if (t1.level > t2.level) {
depth = t1.level;
}
depth = 0 - depth; //inner edge indicated by negative depth
float weight = _edges->at(index).weight;
addEdge(Edge(n1, n2, depth, weight), abs(depth));
Edge e = _edges->at(index);
if (!_quadTree->isLeaf(m1)) {
nodeIndexI = _quadTree->travelSelect(e.x1, e.y1, &t1) - 1;
}
if (!_quadTree->isLeaf(m2)) {
nodeIndexJ = _quadTree->travelSelect(e.x2, e.y2, &t2) - 1;
}
}
//recursive calls
TravelIndex newT1(t1);
TravelIndex newT2(t2);
//go on with t1
if (!_quadTree->isLeaf(m1)) {
_quadTree->travelDown((nodeIndexI+1), &newT1);
}
//and with t2
if (!_quadTree->isLeaf(m2)) {
_quadTree->travelDown((nodeIndexJ+1), &newT2);
}
divideEdges(newT1, newT2, index);
}
}