Пример #1
0
int SimpleMesh::Genus() const {
  std::set<MyEdge> uniqueEdges;
  for(unsigned int i=0; i<mFaces.size(); i++){
    uniqueEdges.insert(MyEdge(mFaces[i].v1, mFaces[i].v2));
    uniqueEdges.insert(MyEdge(mFaces[i].v1, mFaces[i].v3));
    uniqueEdges.insert(MyEdge(mFaces[i].v2, mFaces[i].v3));
  }
  int E = uniqueEdges.size();
  int V = mVerts.size();
  int F = mFaces.size();

  std::cerr << "Number of edges: " << E << ", F: " << F << ", V: " << V << "\n";
  return -(V-E+F-2)/2;
}
int main(int , char **)
{
    //create a random mesh of edge
    MyEdgeMesh em;
    srand(1000);
    em.vert.reserve(VERT_NUMB);
    for (int i=0; i<VERT_NUMB; i=i+2)
    {
        float x0=((float)rand()/(float)RAND_MAX)*1000.f;
        float y0=((float)rand()/(float)RAND_MAX)*1000.f;
        float z0=((float)rand()/(float)RAND_MAX)*1000.f;
        float x1=((float)rand()/(float)RAND_MAX)*1000.f;
        float y1=((float)rand()/(float)RAND_MAX)*1000.f;
        float z1=((float)rand()/(float)RAND_MAX)*1000.f;
        em.vert.push_back(MyVertex());
        MyVertex *v0=&em.vert.back();
        em.vert.push_back(MyVertex());
        MyVertex *v1=&em.vert.back();
        v0->P().X()=x0;
        v0->P().Y()=y0;
        v0->P().Z()=z0;
        v1->P().X()=x1;
        v1->P().Y()=y1;
        v1->P().Z()=z1;
        em.edges.push_back(MyEdge());
        MyEdge *e=&em.edges.back();
        e->V(0)=v0;
        e->V(1)=v1;
    }
    vcg::edg::UpdateBounding<MyEdgeMesh>::Box(em);
    EdgeMeshGrid static_grid;
    static_grid.Set(em.edges.begin(), em.edges.end());
    float dist;
    vcg::Point3f p;
    MyEdge *e=vcg::edgemesh::GetClosestEdge<MyEdgeMesh,EdgeMeshGrid>(em,static_grid,vcg::Point3f(500,500,500),1000,dist,p);
    std::vector<MyEdge*> ret;
    int num=vcg::edgemesh::GetInBoxEdge<MyEdgeMesh,EdgeMeshGrid,std::vector<MyEdge*> >(em,static_grid,em.bbox,ret);
    return 0;
}