00001 #include <stdio.h>
00002 #include <vcg/space/color4.h>
00003 #include <vcg/space/index/grid_static_ptr.h>
00004 #include <vcg/simplex/vertex/base.h>
00005 #include <vcg/simplex/vertex/component.h>
00006 #include <vcg/simplex/edge/base.h>
00007 #include <vcg/simplex/edge/component.h>
00008 #include <vcg/complex/edgemesh/base.h>
00009 #include <vcg/complex/edgemesh/allocate.h>
00010 #include <vcg/complex/edgemesh/update/bounding.h>
00011 #include <vcg/complex/edgemesh/closest.h>
00012 #include <vcg/complex/trimesh/closest.h>
00013 #include <vcg/complex/used_types.h>
00014
00015
00016
00017
00018 class MyFace;
00019 class MyEdge;
00020 class MyVertex;
00021 struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
00022 vcg::Use<MyEdge> ::AsEdgeType,
00023 vcg::Use<MyFace> ::AsFaceType>{};
00024
00025 class MyVertex : public vcg::Vertex<MyUsedTypes,vcg::vertex::BitFlags,vcg::vertex::Coord3f> {};
00026 class MyEdge : public vcg::Edge<MyUsedTypes,vcg::edge::Mark,vcg::edge::VertexRef,vcg::edge::BitFlags> {};
00027 class MyEdgeMesh: public vcg::edg::EdgeMesh< std::vector<MyVertex>, std::vector<MyEdge> > {};
00028
00029 typedef vcg::GridStaticPtr<MyEdge, MyEdge::ScalarType> EdgeMeshGrid;
00030
00031 #define VERT_NUMB 100
00032
00033 int main(int , char **)
00034 {
00035
00036 MyEdgeMesh em;
00037 srand(1000);
00038 em.vert.reserve(VERT_NUMB);
00039 for (int i=0;i<VERT_NUMB;i=i+2)
00040 {
00041 float x0=((float)rand()/(float)RAND_MAX)*1000.f;
00042 float y0=((float)rand()/(float)RAND_MAX)*1000.f;
00043 float z0=((float)rand()/(float)RAND_MAX)*1000.f;
00044 float x1=((float)rand()/(float)RAND_MAX)*1000.f;
00045 float y1=((float)rand()/(float)RAND_MAX)*1000.f;
00046 float z1=((float)rand()/(float)RAND_MAX)*1000.f;
00047 em.vert.push_back(MyVertex());
00048 MyVertex *v0=&em.vert.back();
00049 em.vert.push_back(MyVertex());
00050 MyVertex *v1=&em.vert.back();
00051 v0->P().X()=x0;
00052 v0->P().Y()=y0;
00053 v0->P().Z()=z0;
00054 v1->P().X()=x1;
00055 v1->P().Y()=y1;
00056 v1->P().Z()=z1;
00057 em.edges.push_back(MyEdge());
00058 MyEdge *e=&em.edges.back();
00059 e->V(0)=v0;
00060 e->V(1)=v1;
00061 }
00062 vcg::edg::UpdateBounding<MyEdgeMesh>::Box(em);
00063 EdgeMeshGrid static_grid;
00064 static_grid.Set(em.edges.begin(), em.edges.end());
00065 float dist;
00066 vcg::Point3f p;
00067 MyEdge *e=vcg::edgemesh::GetClosestEdge<MyEdgeMesh,EdgeMeshGrid>(em,static_grid,vcg::Point3f(500,500,500),1000,dist,p);
00068 std::vector<MyEdge*> ret;
00069 int num=vcg::edgemesh::GetInBoxEdge<MyEdgeMesh,EdgeMeshGrid,std::vector<MyEdge*> >(em,static_grid,em.bbox,ret);
00070 return 0;
00071 }