本文整理汇总了C++中svector::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ svector::clear方法的具体用法?C++ svector::clear怎么用?C++ svector::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类svector
的用法示例。
在下文中一共展示了svector::clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ComputeExtremities
int ComputeExtremities(TopologicalGraph &G,svector<int> &x,
svector<int> &x1,svector<int> &x2,int morg)
{tvertex v;
tedge e;
int n=G.nv();
int m=G.ne();
int maxxval=0;
for(e=1;e <=m;e++)
if(x[e] > maxxval)maxxval = x[e];
x2.clear();
for (v=1; v <= n;v++)
x1[v] = maxxval + 1;
int xe;
for (e=1;e<=morg;e++)
{xe=x[e];
v=G.vin[e.firsttbrin()];
if (x1[v]>xe) x1[v]=xe;
if (x2[v]<xe) x2[v]=xe;
v=G.vin[e.secondtbrin()];
if (x1[v]>xe) x1[v]=xe;
if (x2[v]<xe) x2[v]=xe;
}
// For isolated vertices
for (v=1; v <= n;v++)
if(x1[v] == maxxval + 1)
{xe = x[G.FirstBrin(v).GetEdge()];
x1[v] = x2[v] = xe;
}
return maxxval;
}
示例2: BFS
int TopologicalGraph::BFS(svector<int> &comp)
{comp.clear();
if(!nv()) return -1;
tvertex v,w;
tbrin b,b0;
int ncc = 0;
svector<tvertex> stack(1,nv()); stack.SetName("TG:BFS:stack");
int rank =0;
int max_rank = 0;
tvertex v0 = 1;
while (max_rank < nv())
{while (comp[v0]) v0++;
comp[v0] = ++ncc;
++max_rank;
stack[rank + 1] = v0;
while(rank < max_rank)
{v = stack[++rank];
b = b0 = pbrin[v];
if (b0!=0)
do {w = vin[-b];
if(!comp[w])
{comp[w] = ncc;
stack[++max_rank] = w;
}
}while((b = cir[b])!= b0);
}
}
return ncc;
}
示例3: WORD
BOOL CreateNode(Fvector& vAt, vertex& N)
{
// *** Query and cache polygons for ray-casting
Fvector PointUp; PointUp.set(vAt); PointUp.y += RCAST_Depth; SnapXZ (PointUp);
Fvector PointDown; PointDown.set(vAt); PointDown.y -= RCAST_Depth; SnapXZ (PointDown);
Fbox BB; BB.set (PointUp,PointUp); BB.grow(g_params.fPatchSize/2); // box 1
Fbox B2; B2.set (PointDown,PointDown); B2.grow(g_params.fPatchSize/2); // box 2
BB.merge(B2 );
BoxQuery(BB,false );
u32 dwCount = XRC.r_count();
if (dwCount==0) {
// Log("chasm1");
return FALSE; // chasm?
}
// *** Transfer triangles and compute sector
R_ASSERT(dwCount<RCAST_MaxTris);
static svector<tri,RCAST_MaxTris> tris; tris.clear();
for (u32 i=0; i<dwCount; i++)
{
tri& D = tris.last();
CDB::RESULT &rp = XRC.r_begin()[i];
CDB::TRI& T = *(Level.get_tris()+rp.id);
D.v[0].set (rp.verts[0]);
D.v[1].set (rp.verts[1]);
D.v[2].set (rp.verts[2]);
D.sector = T.sector;
D.N.mknormal(D.v[0],D.v[1],D.v[2]);
if (D.N.y<=0) continue;
tris.inc ();
}
if (tris.size()==0) {
// Log("chasm2");
return FALSE; // chasm?
}
// *** Perform ray-casts and calculate sector
WORD Sector = 0xfffe; // mark as first time
static svector<Fvector,RCAST_Total> points; points.clear();
static svector<Fvector,RCAST_Total> normals; normals.clear();
Fvector P,D; D.set(0,-1,0);
float coeff = 0.5f*g_params.fPatchSize/float(RCAST_Count);
for (int x=-RCAST_Count; x<=RCAST_Count; x++)
{
P.x = vAt.x + coeff*float(x);
for (int z=-RCAST_Count; z<=RCAST_Count; z++) {
P.z = vAt.z + coeff*float(z);
P.y = vAt.y + 10.f;
float tri_min_range = flt_max;
int tri_selected = -1;
float range,u,v;
for (i=0; i<u32(tris.size()); i++)
{
if (CDB::TestRayTri(P,D,tris[i].v,u,v,range,false))
{
if (range<tri_min_range) {
tri_min_range = range;
tri_selected = i;
}
}
}
if (tri_selected>=0) {
P.y -= tri_min_range;
points.push_back(P);
normals.push_back(tris[tri_selected].N);
WORD TS = WORD(tris[tri_selected].sector);
if (Sector==0xfffe) Sector = TS;
else if (Sector!=TS) Sector=InvalidSector;
}
}
}
if (points.size()<3) {
// Msg ("Failed to create node at [%f,%f,%f].",vAt.x,vAt.y,vAt.z);
return FALSE;
}
if (float(points.size())/float(RCAST_Total) < 0.7f) {
// Msg ("Partial chasm at [%f,%f,%f].",vAt.x,vAt.y,vAt.z);
return FALSE;
}
// *** Calc normal
Fvector vNorm;
vNorm.set(0,0,0);
for (u32 n=0; n<normals.size(); n++)
vNorm.add(normals[n]);
vNorm.div(float(normals.size()));
vNorm.normalize();
/*
{
// second algorithm (Magic)
Fvector N,O;
N.set(vNorm);
O.set(points[0]);
//.........这里部分代码省略.........
示例4:
BOOL ValidNode(vertex& N)
{
// *** Query and cache polygons for ray-casting
Fvector PointUp; PointUp.set(N.Pos); PointUp.y += RCAST_Depth/2;
Fvector PointDown; PointDown.set(N.Pos); PointDown.y -= RCAST_Depth/2;
Fbox BB; BB.set (PointUp,PointUp); BB.grow(g_params.fPatchSize/2); // box 1
Fbox B2; B2.set (PointDown,PointDown); B2.grow(g_params.fPatchSize/2); // box 2
BB.merge(B2 );
BoxQuery(BB,false );
u32 dwCount = XRC.r_count();
if (dwCount==0) {
Log("chasm1");
return FALSE; // chasm?
}
// *** Transfer triangles and compute sector
R_ASSERT(dwCount<RCAST_MaxTris);
static svector<tri,RCAST_MaxTris> tris; tris.clear();
for (u32 i=0; i<dwCount; i++)
{
tri& D = tris.last();
CDB::RESULT&rp = XRC.r_begin()[i];
*(Level.get_tris()+XRC.r_begin()[i].id);
D.v[0].set (rp.verts[0]);
D.v[1].set (rp.verts[1]);
D.v[2].set (rp.verts[2]);
Fvector N;
N.mknormal (D.v[0],D.v[1],D.v[2]);
if (N.y<=0) continue;
tris.inc ();
}
if (tris.size()==0) {
Log("chasm2");
return FALSE; // chasm?
}
// *** Perform ray-casts and calculate sector
Fvector P,D,PLP; D.set(0,-1,0);
float coeff = 0.5f*g_params.fPatchSize/float(RCAST_Count);
int num_successed_rays = 0;
for (int x=-RCAST_Count; x<=RCAST_Count; x++)
{
P.x = N.Pos.x + coeff*float(x);
for (int z=-RCAST_Count; z<=RCAST_Count; z++) {
P.z = N.Pos.z + coeff*float(z);
P.y = N.Pos.y;
N.Plane.intersectRayPoint(P,D,PLP); // "project" position
P.y = PLP.y+RCAST_DepthValid/2;
float tri_min_range = flt_max;
int tri_selected = -1;
float range = 0.f,u,v;
for (i=0; i<u32(tris.size()); i++)
{
if (CDB::TestRayTri(P,D,tris[i].v,u,v,range,false))
{
if (range<tri_min_range) {
tri_min_range = range;
tri_selected = i;
}
}
}
if (tri_selected>=0) {
if (range<RCAST_DepthValid) num_successed_rays++;
}
}
}
if (float(num_successed_rays)/float(RCAST_Total) < 0.5f) {
Msg ("Floating node.");
return FALSE;
}
return TRUE;
}