本文整理汇总了C++中SurfaceMesh::vertices方法的典型用法代码示例。如果您正苦于以下问题:C++ SurfaceMesh::vertices方法的具体用法?C++ SurfaceMesh::vertices怎么用?C++ SurfaceMesh::vertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SurfaceMesh
的用法示例。
在下文中一共展示了SurfaceMesh::vertices方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int /*argc*/, char** argv) {
SurfaceMesh mesh;
mesh.read(argv[1]);
float mean_valence = 0.0f;
unsigned int vertex_valence;
// instantiate iterator and circulators
SurfaceMesh::Vertex_iterator vit;
SurfaceMesh::Vertex_around_vertex_circulator vc, vc_end;
// loop over all vertices
for (vit = mesh.vertices_begin(); vit != mesh.vertices_end(); ++vit) {
// initialize circulators
vc = mesh.vertices(*vit);
vc_end = vc;
// reset counter
vertex_valence = 0;
// loop over all incident vertices
do {
++vertex_valence;
} while (++vc != vc_end);
// sum up vertex valences
mean_valence += vertex_valence;
}
mean_valence /= mesh.n_vertices();
std::cout << "mean valence: " << mean_valence << std::endl;
}
示例2: main
int main(int argc, char** argv) {
std::string file = (argc>1) ? argv[1] : "bunny.obj";
SurfaceMesh mesh;
bool success = mesh.read(file);
CHECK(success);
auto points = mesh.get_vertex_property<Vec3>("v:point");
Vec3 p(0,0,0);
for (auto vit: mesh.vertices())
p += points[vit];
p /= mesh.n_vertices();
std::cout << "barycenter: " << p << std::endl;
}
示例3: init
/// OpenGL initialization
void init() {
///----------------------- DATA ----------------------------
auto vpoints = mesh.get_vertex_property<Vec3>("v:point");
auto vnormals = mesh.get_vertex_property<Vec3>("v:normal");
assert(vpoints);
assert(vnormals);
///---------------------- TRIANGLES ------------------------
triangles.clear();
for(auto f: mesh.faces())
for(auto v: mesh.vertices(f))
triangles.push_back(v.idx());
///---------------------- OPENGL GLOBALS--------------------
glClearColor(1.0f, 1.0f, 1.0f, 0.0f); ///< background
glEnable(GL_DEPTH_TEST); // Enable depth test
// glDisable(GL_CULL_FACE); // Cull back-facing
/// Compile the shaders
programID = load_shaders("vshader.glsl", "fshader.glsl");
if(!programID) exit(EXIT_FAILURE);
glUseProgram( programID );
///---------------------- CAMERA ----------------------------
{
typedef Eigen::Vector3f vec3;
typedef Eigen::Matrix4f mat4;
update_projection_matrix();
/// Define the view matrix (camera extrinsics)
vec3 cam_pos(0,0,5);
vec3 cam_look(0,0,-1); /// Remember: GL swaps viewdir
vec3 cam_up(0,1,0);
view = OpenGP::lookAt(cam_pos, cam_look, cam_up);
// cout << view << endl;
/// Define the modelview matrix
model = mat4::Identity();
// cout << model << endl;
/// Set initial matrices
set_uniform_matrix(programID,"M",model); ///< to get world coordinates
set_uniform_matrix(programID,"MV",view*model); ///< to get camera coordinates
set_uniform_matrix(programID,"MVP",projection*view*model); ///< to get clip coordinates
}
///---------------------- LIGHT -----------------------------
{
Vec3 light_dir(0,0,1);
set_uniform_vector(programID,"LDIR",light_dir); ///< to get camera coordinates
}
///---------------------- VARRAY ----------------------------
{
GLuint VertexArrayID;
glGenVertexArrays(1, &VertexArrayID);
glBindVertexArray(VertexArrayID);
}
///---------------------- BUFFERS ----------------------------
GLuint vertexbuffer, normalbuffer, trianglebuffer;
{
/// Load mesh vertices
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, mesh.n_vertices() * sizeof(Vec3), vpoints.data(), GL_STATIC_DRAW);
/// Load mesh normals
glGenBuffers(1, &normalbuffer);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glBufferData(GL_ARRAY_BUFFER, mesh.n_vertices() * sizeof(Vec3), vnormals.data(), GL_STATIC_DRAW);
/// Triangle indexes buffer
glGenBuffers(1, &trianglebuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, trianglebuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, triangles.size() * sizeof(unsigned int), &triangles[0], GL_STATIC_DRAW);
}
///---------------------- SHADER ATTRIBUTES ----------------------------
{
/// Vertex positions in shader variable "vposition"
GLuint vposition = glGetAttribLocation(programID, "vposition");
glEnableVertexAttribArray(vposition);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(vposition, 3, GL_FLOAT, DONT_NORMALIZE, ZERO_STRIDE, ZERO_BUFFER_OFFSET);
/// Vertex normals in in shader variable "vnormal"
GLuint vnormal = glGetAttribLocation(programID, "vnormal");
glEnableVertexAttribArray(vnormal);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glVertexAttribPointer(vnormal, 3, GL_FLOAT, DONT_NORMALIZE, ZERO_STRIDE, ZERO_BUFFER_OFFSET);
}
}