trimesh.h
来自「RBF平台」· C头文件 代码 · 共 175 行
H
175 行
#ifndef TRIMESH_H#define TRIMESH_H/*Szymon RusinkiewiczPrinceton UniversityTriMesh.hClass for triangle meshes.*/
// i+1 and i-1 modulo 3
// This way of computing it tends to be faster than using %
#define NEXT(i) ((i)<2 ? (i)+1 : (i)-2)
#define PREV(i) ((i)>0 ? (i)-1 : (i)+2)
#include "Vec.h"#include "Color.h"
#include <vector>using std::vector;
void diagonalize_curv(const vec &old_u, const vec &old_v,
float ku, float kuv, float kv,
const vec &new_norm,
vec &pdir1, vec &pdir2, float &k1, float &k2);
void proj_curv(const vec &old_u, const vec &old_v,
float old_ku, float old_kuv, float old_kv,
const vec &new_u, const vec &new_v,
float &new_ku, float &new_kuv, float &new_kv);
void proj_dcurv(const vec &old_u, const vec &old_v, const Vec<4> old_dcurv,
const vec &new_u, const vec &new_v,Vec<4> &new_dcurv);
class TriMesh {protected: //static bool read_helper(const char *filename, TriMesh *mesh);public:
TriMesh();
~TriMesh();
// Types struct Face { int v[3]; Face() {} Face(const int &v0, const int &v1, const int &v2) { v[0] = v0; v[1] = v1; v[2] = v2; } Face(const int *v_) { v[0] = v_[0]; v[1] = v_[1]; v[2] = v_[2]; } int &operator[] (int i) { return v[i]; } const int &operator[] (int i) const { return v[i]; } operator const int * () const { return &(v[0]); } operator const int * () { return &(v[0]); } operator int * () { return &(v[0]); } int indexof(int v_) const { return (v[0] == v_) ? 0 : (v[1] == v_) ? 1 : (v[2] == v_) ? 2 : -1; } }; struct BBox { point min, max; point center() const { return 0.5f * (min+max); } vec size() const { return max - min; } }; struct BSphere { point center; float r; bool valid; BSphere() : valid(false) { } }; // Enums enum tstrip_rep { TSTRIP_LENGTH, TSTRIP_TERM }; // The basics: vertices and faces vector<point> vertices; vector<Face> faces; // Triangle strips vector<int> tstrips; // Other per-vertex properties vector<Color> colors; vector<float> confidences; vector<unsigned> flags; unsigned flag_curr; //what's meaning? // Computed per-vertex properties vector<vec> normals; vector<vec> pdir1, pdir2; vector<float> curv1, curv2; vector< Vec<4,float> > dcurv; vector<vec> cornerareas; vector<float> pointareas; // Bounding structures BBox bbox; BSphere bsphere; // Connectivity structures: // For each vertex, all neighboring vertices vector< vector<int> > neighbors; // For each vertex, all neighboring faces vector< vector<int> > adjacentfaces; // For each face, the three faces attached to its edges // (for example, across_edge[3][2] is the number of the face // that's touching the edge opposite vertex 2 of face 3) vector<Face> across_edge;
public:
//---Compute all this stuff... void need_tstrips(); void convert_strips(tstrip_rep rep); void need_faces(); void need_normals(); void need_pointareas(); void need_curvatures(); void need_dcurv(); void need_bbox(); void need_bsphere(); void need_neighbors(); void need_adjacentfaces(); void need_across_edge();
//---remove operations
void remove_vertices(TriMesh *mesh, const vector<bool> &toremove);
void remove_unused_vertices(TriMesh *mesh);
void remove_faces(TriMesh *mesh, const vector<bool> &toremove);
void remove_sliver_faces(TriMesh *mesh);
//---mesh smoothing
void umbrella(TriMesh *mesh, float stepsize);
void lmsmooth(TriMesh *mesh, int niters);
//---other operations
void reorder_verts(TriMesh *mesh);
void inflate(TriMesh *mesh, float amount);
//---flip operation
void edgeflip(TriMesh *mesh);
void faceflip(TriMesh *mesh);
void vtxnormflip(TriMesh * mesh);
//---Input and output static TriMesh *read(const char *filename); void write(TriMesh * trimesh, const char *filename, bool istrips); // Statistics // XXX - Add stuff here float feature_size(); // Useful queries // XXX - Add stuff here bool is_bdy(int v) { if (neighbors.empty()) need_neighbors(); if (adjacentfaces.empty()) need_adjacentfaces(); return neighbors[v].size() != adjacentfaces[v].size(); } // Debugging printout, controllable by a "verbose"ness parameter static int verbose; static void set_verbose(int); static int dprintf(const char *format, ...);};#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?