本文整理汇总了C++中TriangleArray::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleArray::push_back方法的具体用法?C++ TriangleArray::push_back怎么用?C++ TriangleArray::push_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriangleArray
的用法示例。
在下文中一共展示了TriangleArray::push_back方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Set
void TriangleMesh::Set(const Polyhedron &polyhedron)
{
TriangleArray tris = polyhedron.Triangulate();
if (!tris.empty())
{
int alignment = (simdCapability == SIMD_AVX) ? 8 : ((simdCapability == SIMD_SSE41 || simdCapability == SIMD_SSE2) ? 4 : 1);
vec degen = POINT_VEC_SCALAR(-FLOAT_INF);
Triangle degent(degen, degen, degen);
while(tris.size() % alignment != 0)
tris.push_back(degent);
Set((Triangle*)&tris[0], (int)tris.size());
}
}
示例2: Triangulate
int Sphere::Triangulate(vec *outPos, vec *outNormal, float2 *outUV, int numVertices, bool ccwIsFrontFacing) const
{
assume(outPos);
assume(numVertices >= 24 && "At minimum, sphere triangulation will contain at least 8 triangles, which is 24 vertices, but fewer were specified!");
assume(numVertices % 3 == 0 && "Warning:: The size of output should be divisible by 3 (each triangle takes up 3 vertices!)");
#ifndef MATH_ENABLE_INSECURE_OPTIMIZATIONS
if (!outPos)
return 0;
#endif
assume(this->r > 0.f);
if (numVertices < 24)
return 0;
#ifdef MATH_ENABLE_STL_SUPPORT
TriangleArray temp;
#else
Array<Triangle> temp;
#endif
// Start subdividing from a diamond shape.
vec xp = POINT_VEC(r,0,0);
vec xn = POINT_VEC(-r, 0, 0);
vec yp = POINT_VEC(0, r, 0);
vec yn = POINT_VEC(0, -r, 0);
vec zp = POINT_VEC(0, 0, r);
vec zn = POINT_VEC(0, 0, -r);
if (ccwIsFrontFacing)
{
temp.push_back(Triangle(yp,xp,zp));
temp.push_back(Triangle(xp,yp,zn));
temp.push_back(Triangle(yn,zp,xp));
temp.push_back(Triangle(yn,xp,zn));
temp.push_back(Triangle(zp,xn,yp));
temp.push_back(Triangle(yp,xn,zn));
temp.push_back(Triangle(yn,xn,zp));
temp.push_back(Triangle(xn,yn,zn));
}
else
{
temp.push_back(Triangle(yp,zp,xp));
temp.push_back(Triangle(xp,zn,yp));
temp.push_back(Triangle(yn,xp,zp));
temp.push_back(Triangle(yn,zn,xp));
temp.push_back(Triangle(zp,yp,xn));
temp.push_back(Triangle(yp,zn,xn));
temp.push_back(Triangle(yn,zp,xn));
temp.push_back(Triangle(xn,zn,yn));
}
int oldEnd = 0;
while(((int)temp.size()-oldEnd+3)*3 <= numVertices)
{
Triangle cur = temp[oldEnd];
vec a = ((cur.a + cur.b) * 0.5f).ScaledToLength(this->r);
vec b = ((cur.a + cur.c) * 0.5f).ScaledToLength(this->r);
vec c = ((cur.b + cur.c) * 0.5f).ScaledToLength(this->r);
temp.push_back(Triangle(cur.a, a, b));
temp.push_back(Triangle(cur.b, c, a));
temp.push_back(Triangle(cur.c, b, c));
temp.push_back(Triangle(a, c, b));
++oldEnd;
}
// Check that we really did tessellate as many new triangles as possible.
assert(((int)temp.size()-oldEnd)*3 <= numVertices && ((int)temp.size()-oldEnd)*3 + 9 > numVertices);
for(size_t i = oldEnd, j = 0; i < temp.size(); ++i, ++j)
{
outPos[3*j] = this->pos + TRIANGLE(temp[i]).a;
outPos[3*j+1] = this->pos + TRIANGLE(temp[i]).b;
outPos[3*j+2] = this->pos + TRIANGLE(temp[i]).c;
}
if (outNormal)
for(size_t i = oldEnd, j = 0; i < temp.size(); ++i, ++j)
{
outNormal[3*j] = TRIANGLE(temp[i]).a.Normalized();
outNormal[3*j+1] = TRIANGLE(temp[i]).b.Normalized();
outNormal[3*j+2] = TRIANGLE(temp[i]).c.Normalized();
}
if (outUV)
for(size_t i = oldEnd, j = 0; i < temp.size(); ++i, ++j)
{
outUV[3*j] = float2(atan2(TRIANGLE(temp[i]).a.y, TRIANGLE(temp[i]).a.x) / (2.f * 3.141592654f) + 0.5f, (TRIANGLE(temp[i]).a.z + r) / (2.f * r));
outUV[3*j+1] = float2(atan2(TRIANGLE(temp[i]).b.y, TRIANGLE(temp[i]).b.x) / (2.f * 3.141592654f) + 0.5f, (TRIANGLE(temp[i]).b.z + r) / (2.f * r));
outUV[3*j+2] = float2(atan2(TRIANGLE(temp[i]).c.y, TRIANGLE(temp[i]).c.x) / (2.f * 3.141592654f) + 0.5f, (TRIANGLE(temp[i]).c.z + r) / (2.f * r));
}
return ((int)temp.size() - oldEnd) * 3;
}
示例3: main
//.........这里部分代码省略.........
}
index.m_position = atoi(vertex)-1;
uint64_t hash0 = index.m_position;
uint64_t hash1 = uint64_t(index.m_texcoord)<<20;
uint64_t hash2 = uint64_t(index.m_normal)<<40;
uint64_t hash = hash0^hash1^hash2;
stl::pair<Index3Map::iterator, bool> result = indexMap.insert(stl::make_pair(hash, index) );
if (!result.second)
{
Index3& oldIndex = result.first->second;
BX_UNUSED(oldIndex);
BX_CHECK(oldIndex.m_position == index.m_position
&& oldIndex.m_texcoord == index.m_texcoord
&& oldIndex.m_normal == index.m_normal
, "Hash collision!"
);
}
switch (edge)
{
case 0:
case 1:
case 2:
triangle.m_index[edge] = hash;
if (2 == edge)
{
if (ccw)
{
std::swap(triangle.m_index[1], triangle.m_index[2]);
}
triangles.push_back(triangle);
}
break;
default:
if (ccw)
{
triangle.m_index[2] = triangle.m_index[1];
triangle.m_index[1] = hash;
}
else
{
triangle.m_index[1] = triangle.m_index[2];
triangle.m_index[2] = hash;
}
triangles.push_back(triangle);
break;
}
}
}
else if (0 == strcmp(argv[0], "g") )
{
EXPECT(1 < argc);
group.m_name = argv[1];
}
else if (*argv[0] == 'v')
{
group.m_numTriangles = (uint32_t)(triangles.size() ) - group.m_startTriangle;
if (0 < group.m_numTriangles)
{
groups.push_back(group);
group.m_startTriangle = (uint32_t)(triangles.size() );
group.m_numTriangles = 0;
示例4: Triangulate
/** The implementation of this function is based on the paper
"Kong, Everett, Toussant. The Graham Scan Triangulates Simple Polygons."
See also p. 772-775 of Geometric Tools for Computer Graphics.
The running time of this function is O(n^2). */
TriangleArray Polygon::Triangulate() const
{
assume1(IsPlanar(), this->SerializeToString());
TriangleArray t;
// Handle degenerate cases.
if (NumVertices() < 3)
return t;
if (NumVertices() == 3)
{
t.push_back(Triangle(Vertex(0), Vertex(1), Vertex(2)));
return t;
}
std::vector<float2> p2d;
std::vector<int> polyIndices;
for(int v = 0; v < NumVertices(); ++v)
{
p2d.push_back(MapTo2D(v));
polyIndices.push_back(v);
}
// Clip ears of the polygon until it has been reduced to a triangle.
int i = 0;
int j = 1;
int k = 2;
size_t numTries = 0; // Avoid creating an infinite loop.
while(p2d.size() > 3 && numTries < p2d.size())
{
if (float2::OrientedCCW(p2d[i], p2d[j], p2d[k]) && IsAnEar(p2d, i, k))
{
// The vertex j is an ear. Clip it off.
t.push_back(Triangle(p[polyIndices[i]], p[polyIndices[j]], p[polyIndices[k]]));
p2d.erase(p2d.begin() + j);
polyIndices.erase(polyIndices.begin() + j);
// The previous index might now have become an ear. Move back one index to see if so.
if (i > 0)
{
i = (i + (int)p2d.size() - 1) % p2d.size();
j = (j + (int)p2d.size() - 1) % p2d.size();
k = (k + (int)p2d.size() - 1) % p2d.size();
}
numTries = 0;
}
else
{
// The vertex at j is not an ear. Move to test next vertex.
i = j;
j = k;
k = (k+1) % p2d.size();
++numTries;
}
}
assume3(p2d.size() == 3, (int)p2d.size(), (int)polyIndices.size(), (int)NumVertices());
if (p2d.size() > 3) // If this occurs, then the polygon is NOT counter-clockwise oriented.
return t;
/*
{
// For conveniency, create a copy that has the winding order fixed, and triangulate that instead.
// (Causes a large performance hit!)
Polygon p2 = *this;
for(size_t i = 0; i < p2.p.size()/2; ++i)
std::swap(p2.p[i], p2.p[p2.p.size()-1-i]);
return p2.Triangulate();
}
*/
// Add the last poly.
t.push_back(Triangle(p[polyIndices[0]], p[polyIndices[1]], p[polyIndices[2]]));
return t;
}
示例5: objToBin
//.........这里部分代码省略.........
const int pos = atoi(vertex);
index.m_position = (pos < 0) ? pos+numPositions : pos-1;
uint64_t hash0 = index.m_position;
uint64_t hash1 = uint64_t(index.m_texcoord)<<20;
uint64_t hash2 = uint64_t(index.m_normal)<<40;
uint64_t hash = hash0^hash1^hash2;
CS_STL::pair<Index3Map::iterator, bool> result = indexMap.insert(CS_STL::make_pair(hash, index) );
if (!result.second)
{
Index3& oldIndex = result.first->second;
BX_UNUSED(oldIndex);
BX_CHECK(oldIndex.m_position == index.m_position
&& oldIndex.m_texcoord == index.m_texcoord
&& oldIndex.m_normal == index.m_normal
, "Hash collision!"
);
}
switch (edge)
{
case 0:
case 1:
case 2:
triangle.m_index[edge] = hash;
if (2 == edge)
{
if (_ccw)
{
std::swap(triangle.m_index[1], triangle.m_index[2]);
}
triangles.push_back(triangle);
}
break;
default:
if (_ccw)
{
triangle.m_index[2] = triangle.m_index[1];
triangle.m_index[1] = hash;
}
else
{
triangle.m_index[1] = triangle.m_index[2];
triangle.m_index[2] = hash;
}
triangles.push_back(triangle);
break;
}
}
}
else if (0 == strcmp(argv[0], "g") )
{
if (1 >= argc)
{
CS_PRINT("Error parsing *.obj file.\n");
return 0;
}
group.m_name = argv[1];
}
else if (*argv[0] == 'v')
{
group.m_numTriangles = (uint32_t)(triangles.size() ) - group.m_startTriangle;
if (0 < group.m_numTriangles)