本文整理汇总了C++中Mesh::AddTriangle方法的典型用法代码示例。如果您正苦于以下问题:C++ Mesh::AddTriangle方法的具体用法?C++ Mesh::AddTriangle怎么用?C++ Mesh::AddTriangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh::AddTriangle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Mesh
Mesh *StockMeshes::NewBoxMesh(float width, float height, float depth, const Color &color,
const Texture *texture) {
float x = width/2, y = height/2, z = depth/2;
Mesh *result = new Mesh(24, 12, true, true, true);
// Top face
result->AddPoint(Point3(-x, y, -z), Point3(0, 1, 0), color, 0, 1);
result->AddPoint(Point3(-x, y, z), Point3(0, 1, 0), color, 0, 0);
result->AddPoint(Point3( x, y, z), Point3(0, 1, 0), color, 1, 0);
result->AddPoint(Point3( x, y, -z), Point3(0, 1, 0), color, 1, 1);
result->AddTriangle(0, 1, 2, texture);
result->AddTriangle(0, 2, 3, texture);
// Front face
result->AddPoint(Point3(-x, -y, -z), Point3(0, 0, -1), color, 0, 1);
result->AddPoint(Point3(-x, y, -z), Point3(0, 0, -1), color, 0, 0);
result->AddPoint(Point3( x, y, -z), Point3(0, 0, -1), color, 1, 0);
result->AddPoint(Point3( x, -y, -z), Point3(0, 0, -1), color, 1, 1);
result->AddTriangle(4, 5, 6, texture);
result->AddTriangle(4, 6, 7, texture);
// Left face
result->AddPoint(Point3(-x, -y, z), Point3(-1, 0, 0), color, 0, 1);
result->AddPoint(Point3(-x, y, z), Point3(-1, 0, 0), color, 0, 0);
result->AddPoint(Point3(-x, y, -z), Point3(-1, 0, 0), color, 1, 0);
result->AddPoint(Point3(-x, -y, -z), Point3(-1, 0, 0), color, 1, 1);
result->AddTriangle(8, 9, 10, texture);
result->AddTriangle(8, 10, 11, texture);
// Back face
result->AddPoint(Point3( x, -y, z), Point3(0, 0, 1), color, 0, 1);
result->AddPoint(Point3( x, y, z), Point3(0, 0, 1), color, 0, 0);
result->AddPoint(Point3(-x, y, z), Point3(0, 0, 1), color, 1, 0);
result->AddPoint(Point3(-x, -y, z), Point3(0, 0, 1), color, 1, 1);
result->AddTriangle(12, 13, 14, texture);
result->AddTriangle(12, 14, 15, texture);
// Right face
result->AddPoint(Point3( x, -y, -z), Point3(1, 0, 0), color, 0, 1);
result->AddPoint(Point3( x, y, -z), Point3(1, 0, 0), color, 0, 0);
result->AddPoint(Point3( x, y, z), Point3(1, 0, 0), color, 1, 0);
result->AddPoint(Point3( x, -y, z), Point3(1, 0, 0), color, 1, 1);
result->AddTriangle(16, 17, 18, texture);
result->AddTriangle(16, 18, 19, texture);
// Bottom face
result->AddPoint(Point3(-x, -y, z), Point3(0, -1, 0), color, 0, 1);
result->AddPoint(Point3(-x, -y, -z), Point3(0, -1, 0), color, 0, 0);
result->AddPoint(Point3( x, -y, -z), Point3(0, -1, 0), color, 1, 0);
result->AddPoint(Point3( x, -y, z), Point3(0, -1, 0), color, 1, 1);
result->AddTriangle(20, 21, 22, texture);
result->AddTriangle(20, 22, 23, texture);
return result;
}
示例2: p
Mesh *StockMeshes::NewSphereMesh(float width, float height, float depth, const Color &color,
int precision, const Texture *texture) {
Mesh *result = new Mesh(precision*precision+2, 2*precision*precision, true, true, true);
float w = width/2, h = height/2, d = depth/2;
// Create points
result->AddPoint(Point3(0, h, 0), Point3(0, h, 0), color, 0.5f, 0);
for (int i = 0; i < precision; i++)
for (int j = 0; j < precision; j++) {
float v = float(i+1) / (precision+1);
float u = float(j) / precision;
float r = sin(v*kPi);
Point3 p(-cos(2*u*kPi)*w*r, cos(v*kPi)*h, sin(2*u*kPi)*w*d*r);
result->AddPoint(p, p, color, u, v);
}
result->AddPoint(Point3(0, -h, 0), Point3(0, -h, 0), color, 0.5f, 0);
// Create triangles
for (int j = 0; j < precision; j++) {
int j2 = (j+1) % precision;
result->AddTriangle(0, 1 + j, 1 + j2, texture);
}
for (int i = 0; i < precision-1; i++)
for (int j = 0; j < precision; j++) {
int j2 = (j+1) % precision;
result->AddTriangle(1 + i*precision + j, 1 + (i+1)*precision + j, 1 + (i+1)*precision + j2,
texture);
result->AddTriangle(1 + i*precision + j, 1 + (i+1)*precision + j2, 1 + i*precision + j2,
texture);
}
for (int j = 0; j < precision; j++) {
int j2 = (j+1) % precision;
result->AddTriangle(precision*(precision-1) + j + 1, 1 + precision*precision,
precision*(precision-1) + j2 + 1, texture);
}
return result;
}
示例3: main
int main(int argc, char *argv[])
{
// 1. Initialize MPI.
int num_procs, myid;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
// 2. Parse command-line options.
int elem_type = 1;
int ref_levels = 2;
int amr = 0;
int order = 2;
bool always_snap = false;
bool visualization = 1;
OptionsParser args(argc, argv);
args.AddOption(&elem_type, "-e", "--elem",
"Type of elements to use: 0 - triangles, 1 - quads.");
args.AddOption(&order, "-o", "--order",
"Finite element order (polynomial degree).");
args.AddOption(&ref_levels, "-r", "--refine",
"Number of times to refine the mesh uniformly.");
args.AddOption(&amr, "-amr", "--refine-locally",
"Additional local (non-conforming) refinement:"
" 1 = refine around north pole, 2 = refine randomly.");
args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
"--no-visualization",
"Enable or disable GLVis visualization.");
args.AddOption(&always_snap, "-snap", "--always-snap", "-no-snap",
"--snap-at-the-end",
"If true, snap nodes to the sphere initially and after each refinement "
"otherwise, snap only after the last refinement");
args.Parse();
if (!args.Good())
{
if (myid == 0)
{
args.PrintUsage(cout);
}
MPI_Finalize();
return 1;
}
if (myid == 0)
{
args.PrintOptions(cout);
}
// 3. Generate an initial high-order (surface) mesh on the unit sphere. The
// Mesh object represents a 2D mesh in 3 spatial dimensions. We first add
// the elements and the vertices of the mesh, and then make it high-order
// by specifying a finite element space for its nodes.
int Nvert = 8, Nelem = 6;
if (elem_type == 0)
{
Nvert = 6;
Nelem = 8;
}
Mesh *mesh = new Mesh(2, Nvert, Nelem, 0, 3);
if (elem_type == 0) // inscribed octahedron
{
const double tri_v[6][3] =
{
{ 1, 0, 0}, { 0, 1, 0}, {-1, 0, 0},
{ 0, -1, 0}, { 0, 0, 1}, { 0, 0, -1}
};
const int tri_e[8][3] =
{
{0, 1, 4}, {1, 2, 4}, {2, 3, 4}, {3, 0, 4},
{1, 0, 5}, {2, 1, 5}, {3, 2, 5}, {0, 3, 5}
};
for (int j = 0; j < Nvert; j++)
{
mesh->AddVertex(tri_v[j]);
}
for (int j = 0; j < Nelem; j++)
{
int attribute = j + 1;
mesh->AddTriangle(tri_e[j], attribute);
}
mesh->FinalizeTriMesh(1, 1, true);
}
else // inscribed cube
{
const double quad_v[8][3] =
{
{-1, -1, -1}, {+1, -1, -1}, {+1, +1, -1}, {-1, +1, -1},
{-1, -1, +1}, {+1, -1, +1}, {+1, +1, +1}, {-1, +1, +1}
};
const int quad_e[6][4] =
{
{3, 2, 1, 0}, {0, 1, 5, 4}, {1, 2, 6, 5},
{2, 3, 7, 6}, {3, 0, 4, 7}, {4, 5, 6, 7}
};
for (int j = 0; j < Nvert; j++)
{
mesh->AddVertex(quad_v[j]);
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[])
{
// 1. Parse command-line options.
int elem_type = 1;
int ref_levels = 2;
int amr = 0;
int order = 2;
bool always_snap = false;
bool visualization = 1;
OptionsParser args(argc, argv);
args.AddOption(&elem_type, "-e", "--elem",
"Type of elements to use: 0 - triangles, 1 - quads.");
args.AddOption(&order, "-o", "--order",
"Finite element order (polynomial degree).");
args.AddOption(&ref_levels, "-r", "--refine",
"Number of times to refine the mesh uniformly.");
args.AddOption(&amr, "-amr", "--refine-locally",
"Additional local (non-conforming) refinement:"
" 1 = refine around north pole, 2 = refine randomly.");
args.AddOption(&visualization, "-vis", "--visualization", "-no-vis",
"--no-visualization",
"Enable or disable GLVis visualization.");
args.AddOption(&always_snap, "-snap", "--always-snap", "-no-snap",
"--snap-at-the-end",
"If true, snap nodes to the sphere initially and after each refinement "
"otherwise, snap only after the last refinement");
args.Parse();
if (!args.Good())
{
args.PrintUsage(cout);
return 1;
}
args.PrintOptions(cout);
// 2. Generate an initial high-order (surface) mesh on the unit sphere. The
// Mesh object represents a 2D mesh in 3 spatial dimensions. We first add
// the elements and the vertices of the mesh, and then make it high-order
// by specifying a finite element space for its nodes.
int Nvert = 8, Nelem = 6;
if (elem_type == 0)
{
Nvert = 6;
Nelem = 8;
}
Mesh *mesh = new Mesh(2, Nvert, Nelem, 0, 3);
if (elem_type == 0) // inscribed octahedron
{
const double tri_v[6][3] =
{
{ 1, 0, 0}, { 0, 1, 0}, {-1, 0, 0},
{ 0, -1, 0}, { 0, 0, 1}, { 0, 0, -1}
};
const int tri_e[8][3] =
{
{0, 1, 4}, {1, 2, 4}, {2, 3, 4}, {3, 0, 4},
{1, 0, 5}, {2, 1, 5}, {3, 2, 5}, {0, 3, 5}
};
for (int j = 0; j < Nvert; j++)
{
mesh->AddVertex(tri_v[j]);
}
for (int j = 0; j < Nelem; j++)
{
int attribute = j + 1;
mesh->AddTriangle(tri_e[j], attribute);
}
mesh->FinalizeTriMesh(1, 1, true);
}
else // inscribed cube
{
const double quad_v[8][3] =
{
{-1, -1, -1}, {+1, -1, -1}, {+1, +1, -1}, {-1, +1, -1},
{-1, -1, +1}, {+1, -1, +1}, {+1, +1, +1}, {-1, +1, +1}
};
const int quad_e[6][4] =
{
{3, 2, 1, 0}, {0, 1, 5, 4}, {1, 2, 6, 5},
{2, 3, 7, 6}, {3, 0, 4, 7}, {4, 5, 6, 7}
};
for (int j = 0; j < Nvert; j++)
{
mesh->AddVertex(quad_v[j]);
}
for (int j = 0; j < Nelem; j++)
{
int attribute = j + 1;
mesh->AddQuad(quad_e[j], attribute);
}
mesh->FinalizeQuadMesh(1, 1, true);
}
// Set the space for the high-order mesh nodes.
H1_FECollection fec(order, mesh->Dimension());
FiniteElementSpace nodal_fes(mesh, &fec, mesh->SpaceDimension());
mesh->SetNodalFESpace(&nodal_fes);
//.........这里部分代码省略.........