本文整理汇总了C++中SurfaceMesh类的典型用法代码示例。如果您正苦于以下问题:C++ SurfaceMesh类的具体用法?C++ SurfaceMesh怎么用?C++ SurfaceMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SurfaceMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTangent
tensor<double, 3, 2> getTangent(const SurfaceMesh &mesh, SurfaceMesh::SimplexID<3> faceID)
{
auto cover = mesh.get_name(faceID);
auto vertexID = mesh.get_simplex_up({cover[0]});
std::set<SurfaceMesh::KeyType> next(std::begin(cover)+1, std::end(cover));
return surfacemesh_detail::getTangentF(mesh, (*vertexID).position, vertexID, next);
}
示例2: getNormal
Vector getNormal(const SurfaceMesh &mesh, SurfaceMesh::SimplexID<3> faceID)
{
Vector norm;
auto name = mesh.get_name(faceID);
// Get the three vertices
auto a = *mesh.get_simplex_up({name[0]});
auto b = *mesh.get_simplex_up({name[1]});
auto c = *mesh.get_simplex_up({name[2]});
if ((*faceID).orientation == 1)
{
norm = cross(c-b, a-b);
}
else if ((*faceID).orientation == -1)
{
norm = cross(a-b, c-b);
}
else
{
// std::cerr << "ERROR(getNormal): Orientation undefined, cannot compute "
// << "normal. Did you call compute_orientation()?" << std::endl;
throw std::runtime_error("ERROR(getNormal): Orientation undefined, cannot compute normal. Did you call compute_orientation()?");
}
return norm;
}
示例3: main
int main(int argc, char** argv) {
QApplication application(argc,argv);
if(argc!=2){
cout << "One argument necessary, given: " << (argc-1) << endl;
return EXIT_FAILURE;
}
SurfaceMesh mesh;
bool ok = mesh.read(argv[1]);
if(!ok){
cout << "could not open file: " << argv[1] << endl;
return EXIT_FAILURE;
}
///--- Preprocess
mesh.triangulate();
mesh.update_vertex_normals();
///--- Shutdown on close GUI
QObject::connect(&application, &QApplication::lastWindowClosed, &application, &QApplication::quit);
Viewer viewer(mesh);
viewer.setWindowTitle("OpenGP/apps/qglviewer");
viewer.show();
return application.exec();
}
示例4: getArea
double getArea(const SurfaceMesh &mesh, SurfaceMesh::SimplexID<3> faceID)
{
auto name = mesh.get_name(faceID);
auto a = *mesh.get_simplex_up({name[0]});
auto b = *mesh.get_simplex_up({name[1]});
auto c = *mesh.get_simplex_up({name[2]});
return getArea(a, b, c);
}
示例5: coarse
void coarse(SurfaceMesh &mesh, double coarseRate, double flatRate, double denseWeight){
// TODO: Check if all polygons are closed (0)
std::cout << "Before coarsening: " << mesh.size<1>() << " " << mesh.size<2>() << " " << mesh.size<3>() << std::endl;
// Compute the average edge length
double avgLen = 0;
if (denseWeight > 0){
avgLen = surfacemesh_detail::getMeanEdgeLength(mesh);
}
double sparsenessRatio = 1;
double flatnessRatio = 1;
// Construct list of vertices to decimate
std::vector<SurfaceMesh::SimplexID<1> > toRemove;
for(auto vertexID : mesh.get_level_id<1>()){
// Sparseness as coarsening criteria
if(denseWeight > 0){
// Get max length of edges.
auto edges = mesh.up(vertexID);
double maxLen = 0;
for(auto edgeID : edges){
auto name = mesh.get_name(edgeID);
auto v = *mesh.get_simplex_down(edgeID, name[0])
- *mesh.get_simplex_down(edgeID, name[1]);
double tmpLen = std::sqrt(v|v);
if(tmpLen > maxLen) maxLen = tmpLen;
}
sparsenessRatio = std::pow(maxLen/avgLen, denseWeight);
}
// Curvature as coarsening criteria
if(flatRate > 0){
auto lst = surfacemesh_detail::computeLocalStructureTensor(mesh, vertexID, RINGS);
auto eigenvalues = surfacemesh_detail::getEigenvalues(lst).eigenvalues();
// The closer this ratio is to 0 the flatter the local region.
flatnessRatio = std::pow(eigenvalues[1]/eigenvalues[2], flatRate);
}
// Add vertex to delete list
if(sparsenessRatio * flatnessRatio < coarseRate){
toRemove.push_back(vertexID);
}
}
std::cout << toRemove.size() << " vertices are marked to be removed." << std::endl;
for(auto vertexID : toRemove){
surfacemesh_detail::decimateVertex(mesh, vertexID);
}
std::cout << "After coarsening: " << mesh.size<1>() << " " << mesh.size<2>() << " " << mesh.size<3>() << std::endl;
}
示例6: refineMesh
/**
* @brief Refine the mesh by quadrisection.
*
* Note that this function will delete all stored data on edges and faces. But
* this can be easily fixed.
*
* @param mesh The mesh
*/
std::unique_ptr<SurfaceMesh> refineMesh(const SurfaceMesh &mesh){
std::unique_ptr<SurfaceMesh> refinedMesh(new SurfaceMesh);
// Copy over vertices to refinedMesh
for (auto vertex : mesh.get_level_id<1>()){
auto key = mesh.get_name(vertex);
refinedMesh->insert(key, *vertex);
}
// Split edges and generate a map of names before to after
std::map<std::array<int,2>, int> edgeMap;
for(auto edge : mesh.get_level_id<2>()){
auto edgeName = mesh.get_name(edge);
auto v1 = *mesh.get_simplex_up({edgeName[0]});
auto v2 = *mesh.get_simplex_up({edgeName[1]});
auto newVertex = refinedMesh->add_vertex(Vertex(0.5*(v1+v2)));
edgeMap.emplace(std::make_pair(edgeName, newVertex));
}
// Connect edges and face and copy data
for(auto face : mesh.get_level_id<3>()){
auto name = mesh.get_name(face);
int a, b, c;
// Skip checking if found
auto it = edgeMap.find({name[0],name[1]});
a = it->second;
it = edgeMap.find({name[1],name[2]});
b = it->second;
it = edgeMap.find({name[0],name[2]});
c = it->second;
refinedMesh->insert({name[0], a});
refinedMesh->insert({a, name[1]});
refinedMesh->insert({name[1], b});
refinedMesh->insert({b, name[2]});
refinedMesh->insert({name[0], c});
refinedMesh->insert({c, name[2]});
refinedMesh->insert({a,b,c});
refinedMesh->insert({name[0],a,c}, *face);
refinedMesh->insert({name[1],a,b}, *face);
refinedMesh->insert({name[2],b,c}, *face);
}
return refinedMesh;
}
示例7: getVolume
/**
* http://research.microsoft.com/en-us/um/people/chazhang/publications/icip01_ChaZhang.pdf
* http://chenlab.ece.cornell.edu/Publication/Cha/icip01_Cha.pdf
*/
double getVolume(const SurfaceMesh &mesh)
{
bool orientError = false;
double volume = 0;
for (auto faceID : mesh.get_level_id<3>())
{
auto name = mesh.get_name(faceID);
auto a = (*mesh.get_simplex_up({name[0]})).position;
auto b = (*mesh.get_simplex_up({name[1]})).position;
auto c = (*mesh.get_simplex_up({name[2]})).position;
Vector norm;
double tmp;
if ((*faceID).orientation == 1)
{
// a->b->c
norm = cross(b, c);
tmp = dot(a, norm);
}
else if ((*faceID).orientation == -1)
{
// c->b->a
norm = cross(b, a);
tmp = dot(c, norm);
}
else
{
orientError = true;
}
// * Probably less efficient way #1
// tmp = dot(a, getNormal(mesh, faceID));
// * Less efficient way #2
// norm = getNormalFromTangent(getTangent(mesh, faceID));
// auto wedge = a^b^c;
// tmp = std::sqrt(wedge|wedge);
// auto sgn = dot((a+b+c)/3, norm);
// if(sgn <= 0) {
// tmp = -1*tmp;
// }
volume += tmp;
}
if(orientError){
std::cerr << "ERROR getVolume(): Orientation undefined for one or more "
<< "simplices. Did you call compute_orientation()?" << std::endl;
}
return volume/6;
}
示例8: main
int main(void)
{
// instantiate a SurfaceMesh object
SurfaceMesh mesh;
// instantiate 4 vertex handles
SurfaceMesh::Vertex v0,v1,v2,v3;
// add 4 vertices
v0 = mesh.add_vertex(Vec3(0,0,0));
v1 = mesh.add_vertex(Vec3(1,0,0));
v2 = mesh.add_vertex(Vec3(0,1,0));
v3 = mesh.add_vertex(Vec3(0,0,1));
// add 4 triangular faces
mesh.add_triangle(v0,v1,v3);
mesh.add_triangle(v1,v2,v3);
mesh.add_triangle(v2,v0,v3);
mesh.add_triangle(v0,v2,v1);
std::cout << "vertices: " << mesh.n_vertices() << std::endl;
std::cout << "edges: " << mesh.n_edges() << std::endl;
std::cout << "faces: " << mesh.n_faces() << std::endl;
return 0;
}
示例9: 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;
}
示例10: coarseIT
void coarseIT(SurfaceMesh &mesh, double coarseRate, double flatRate, double denseWeight){
std::cout << "Before coarsening: " << mesh.size<1>() << " " << mesh.size<2>() << " " << mesh.size<3>() << std::endl;
// Compute the average edge length
double avgLen = 0;
if (denseWeight > 0){
avgLen = surfacemesh_detail::getMeanEdgeLength(mesh);
}
double sparsenessRatio = 1;
double flatnessRatio = 1;
// Backup vertices so we can modify in place
auto range = mesh.get_level_id<1>();
const std::vector<SurfaceMesh::SimplexID<1> > Vertices(range.begin(), range.end());
for(auto vertexID : Vertices) {
// Sparseness as coarsening criteria
if(denseWeight > 0){
// Get max length of edges.
auto edges = mesh.up(vertexID);
double maxLen = 0;
for(auto edgeID : edges){
auto name = mesh.get_name(edgeID);
auto v = *mesh.get_simplex_down(edgeID, name[0])
- *mesh.get_simplex_down(edgeID, name[1]);
double tmpLen = std::sqrt(v|v);
if(tmpLen > maxLen) maxLen = tmpLen;
}
sparsenessRatio = std::pow(maxLen/avgLen, denseWeight);
}
// Curvature as coarsening criteria
if(flatRate > 0){
auto lst = surfacemesh_detail::computeLocalStructureTensor(mesh, vertexID, RINGS);
auto eigenvalues = surfacemesh_detail::getEigenvalues(lst).eigenvalues();
// The closer this ratio is to 0 the flatter the local region.
flatnessRatio = std::pow(eigenvalues[1]/eigenvalues[2], flatRate);
}
// Check if we should delete
if(sparsenessRatio * flatnessRatio < coarseRate){
surfacemesh_detail::decimateVertex(mesh, vertexID);
}
}
std::cout << "After coarsening: " << mesh.size<1>() << " " << mesh.size<2>() << " " << mesh.size<3>() << std::endl;
}
示例11: simulation_load_render_mesh
bool simulation_load_render_mesh(const char* filename)
{
SurfaceMesh* mesh = new SurfaceMesh;
if (!read_mesh_obj(filename, mesh->positions, mesh->triangles, (render_meshes.empty() ? &mesh->texcoords : NULL))) // we use the texture only for the first OBJ
{
delete mesh;
return false;
}
mesh->filename = filename;
mesh->updateNormals();
if (render_meshes.size()&1)
mesh->color = TColor(0.15f, 0.15f, 0.15f, 1.0f);
else
mesh->color = TColor(0.8f, 0.8f, 0.8f, 1.0f);
render_meshes.push_back(mesh);
return true;
}
示例12: hasHole
bool hasHole(const SurfaceMesh &mesh){
for(auto eID : mesh.get_level_id<2>()){
auto cover = mesh.get_cover(eID);
if(cover.size() != 2){
return true;
}
}
return false;
}
示例13: getMinMaxAngles
std::tuple<double, double, int, int> getMinMaxAngles(
const SurfaceMesh &mesh,
int maxMinAngle,
int minMaxAngle)
{
double minAngle = 360;
double maxAngle = 0;
int small = 0;
int large = 0;
// for each triangle
for(auto nid : mesh.get_level_id<3>()){
auto name = mesh.get_name(nid);
auto a = *mesh.get_simplex_up({name[0]});
auto b = *mesh.get_simplex_up({name[1]});
auto c = *mesh.get_simplex_up({name[2]});
std::array<double, 3> angles;
try{
angles[0] = angle(a,b,c);
angles[1] = angle(b,a,c);
angles[2] = angle(a,c,b);
}
catch (std::runtime_error& e){
throw std::runtime_error("ERROR(getMinMaxAngles): Cannot compute angles of face with zero area.");
}
for(double angle : angles){
if (angle < minAngle){
minAngle = angle;
}
if (angle > maxAngle){
maxAngle = angle;
}
if (angle < maxMinAngle){
++small;
}
if (angle > minMaxAngle){
++large;
}
}
}
return std::make_tuple(minAngle, maxAngle, small, large);
}
示例14: print
void print(const SurfaceMesh &mesh)
{
std::cout << "Level: 1" << std::endl;
for (auto node : mesh.get_level_id<1>())
{
std::cout << " " << *node << std::endl;
}
std::cout << "Level: 2" << std::endl;
for (auto node : mesh.get_level_id<2>())
{
auto name = mesh.get_name(node);
std::cout << " " << casc::to_string(name) << std::endl;
}
std::cout << "Level: 3" << std::endl;
for (auto node : mesh.get_level_id<3>())
{
auto name = mesh.get_name(node);
std::cout << " " << casc::to_string(name) << std::endl;
}
}
示例15: loadScalars
void VertexScalar::loadScalars()
{
if (!mi) return;
SurfaceMesh *mesh = mi->getMesh();
if (!mesh) return;
unsigned int i = 0;
for (SurfaceMesh::VertexIter v_it = mesh->vertices_begin(); v_it!=mesh->vertices_end(); ++v_it) {
if (i >= ps->size()) {
ps->addParticle();
}
SurfaceMesh::TexCoord2D tc = mesh->texcoord2D(v_it);
setScalar(i,tc[0]);
i++;
}
for (unsigned int j = ps->size() - 1; j >= i; j--)
ps->removeParticle(j);
}