Cube::Cube(){ geoType = CUBE_GEO; p = new Poly(); Point pt1(0,0,0); Point pt2(0,0,10); Point pt3(10,0,10); Point pt4(10,0,0); Point pt5(10,10,0); Point pt6(10,10,10); Point pt7(0,10,10); Point pt8(0,10,0); p->addFace(pt1, pt2, pt7, pt8); // bottom p->addFace(pt3, pt4, pt5, pt6); // right p->addFace(pt1, pt2, pt3, pt4); // front p->addFace(pt5, pt6, pt7, pt8); // top p->addFace(pt1, pt4, pt5, pt8); // left p->addFace(pt2, pt3, pt6, pt7); // back p->computeNormals(); this->addPoly(p); // this adds it to scene p->bound(); this->bound(); }
static gboolean expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data) { GdkGLContext *glcontext = gtk_widget_get_gl_context (da); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (da); // g_print (" :: expose\n"); if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) { g_assert_not_reached (); } /* draw in here */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glDepthFunc(GL_GREATER); // The Type Of Depth Testing (Less Or Equal) glEnable(GL_DEPTH_TEST); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse); glPushMatrix(); glRotatef (ang, 1, 0, 1); // glRotatef (ang, 0, 1, 0); // glRotatef (ang, 0, 0, 1); glShadeModel(GL_SMOOTH); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); /* glBegin (GL_LINES); glColor3f (1., 0., 0.); glVertex3f (0., 0., 0.); glVertex3f (1., 0., 0.); glEnd (); glBegin (GL_LINES); glColor3f (0., 1., 0.); glVertex3f (0., 0., 0.); glVertex3f (0., 1., 0.); glEnd (); glBegin (GL_LINES); glColor3f (0., 0., 1.); glVertex3f (0., 0., 0.); glVertex3f (0., 0., 1.); glEnd (); */ FreeREP::Init(); Geom_Vec3 pt1(0,0,0); Geom_Vec3 pt2(0,1,0); Geom_Vec3 pt3(1,1,0); Geom_Vec3 pt4(1,0,0); Geom_Vec3 pt5(0.5,0.5,0); Geom_Vec3 pt6(0.5,.75,0); Geom_Vec3 pt7(.75,.75,0); Topo_Line *l1 = new Topo_Line(pt1,pt2); Topo_Line *l2 = new Topo_Line(pt2,pt3); Topo_Line *l3 = new Topo_Line(pt3,pt4); Topo_Arc *a1 = new Topo_Arc(Geom_Ax2(pt4,Geom_Vec3(0,0,-1),Geom_Vec3(-1,0,0)),1,M_PI/2,0); Topo_Line *l4 = new Topo_Line(pt5,pt6); Topo_Line *l5 = new Topo_Line(pt6,pt7); Topo_Line *l6 = new Topo_Line(pt7,pt5); /* Topo_Edge *e1 = new Topo_Edge(); e1->Add(l1); e1->Add(l2); //e1->Add(l3); e1->Add(a1); e1->Reverse(); Topo_Edge *e2 = new Topo_Edge(); e2->Add(l4); e2->Add(l5); e2->Add(l6); */ /* glBegin(GL_LINE_STRIP); e1->GetVertices(.01,vCall); glEnd(); glBegin(GL_LINE_STRIP); e2->GetVertices(.01,vCall); glEnd(); */ /* Topo_Face *face = new Topo_Face_Planar(Geom_Plane(Geom_Vec3(0,0,0),Geom_Vec3(0,0,-1))); face->Add(e1); face->Add(e2);*/ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_AUTO_NORMAL); //Draw a coordinate axis on the screen glBegin(GL_LINES); glVertex3d(0,0,0); glVertex3d(0,0,.5); glVertex3d(0,0,0); glVertex3d(0,.5,0); glVertex3d(0,0,0); glVertex3d(.5,0,0); glEnd(); glPushMatrix(); glScaled(.25,.25,.25); glPushMatrix(); glTranslated(-.5,.5,0); t3dDraw3D("Y", 0, 0, 0.05f); glPopMatrix(); glPushMatrix(); glTranslated(.5,-.5,0); glRotated(90,0,0,1); t3dDraw3D("X", 0, 0, 0.05f); glPopMatrix(); glTranslated(-.5,0,0.5); glRotated(90,1,0,0); t3dDraw3D("Z", 0, 0, 0.05f); glPopMatrix(); glBegin(GL_TRIANGLES); //face->Triangulate(.01,vCall); glEnd(); Topo_Face_Spheric *sphere = new Topo_Face_Spheric(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),1); glBegin(GL_TRIANGLES); //sphere->Triangulate(.01,vCall); glEnd(); Topo_Face_Toroidal *toroid = new Topo_Face_Toroidal(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),.5,.125); glBegin(GL_TRIANGLES); //toroid->Triangulate(.01,vCall); glEnd(); //Topo_Solid *solid = BrepAlgoExtrude(face,Geom_Vec3(0,0,.5)); glBegin(GL_TRIANGLES); //solid->Triangulate(.001,vCall); glEnd(); std::vector<Topo_Shape*> shapes = ReadIGES("Tests/Pawn.igs");// = ReadFREP("Tests/SimpleFaces.FREP"); // shapes.push_back(MakeSphere(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),1)); // shapes.push_back(MakeSphere(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),0.25)); // shapes.push_back(MakeCone(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),.5,1,1)); for(int i=0; i < shapes.size(); i++) { ICanTriangulate *obj = dynamic_cast<ICanTriangulate*>(shapes[i]); if(obj) { #ifdef DRAWFACES glBegin(GL_TRIANGLES); obj->Triangulate(.01,vCall); glEnd(); #endif #ifdef DRAWEDGES Topo_Face *face = dynamic_cast<Topo_Face*>(shapes[i]); if(face) { Topo_Edge* edge = face->GetFirstEdge(); while(edge) { glBegin(GL_LINE_STRIP); edge->GetVertices(.01,dvCall); glEnd(); edge = face->GetNextEdge(); } } Topo_Solid *solid = dynamic_cast<Topo_Solid*>(shapes[i]); if(solid) { face = solid->GetFirstFace(); while(face) { Topo_Edge* edge = face->GetFirstEdge(); while(edge) { glBegin(GL_LINE_STRIP); edge->GetVertices(.01,dvCall); glEnd(); edge = face->GetNextEdge(); } face = solid->GetNextFace(); } } #endif } else { Topo_Edge *edge = dynamic_cast<Topo_Edge*>(shapes[i]); if(edge) { glBegin(GL_LINE_STRIP); edge->GetVertices(.01,dvCall); glEnd(); } Topo_Wire *wire = dynamic_cast<Topo_Wire*>(shapes[i]); if(wire) { glBegin(GL_LINE_STRIP); wire->GetVertices(.01,dvCall); glEnd(); } } } /* Topo_Face *tface = solid->GetFirstFace(); while(tface) { Topo_Edge *tedge = tface->GetFirstEdge(); while(tedge) { glBegin(GL_LINE_STRIP); tedge->GetVertices(.01,vCall); glEnd(); tedge = tface->GetNextEdge(); } tface = solid->GetNextFace(); }*/ glPopMatrix (); if (gdk_gl_drawable_is_double_buffered (gldrawable)) gdk_gl_drawable_swap_buffers (gldrawable); else glFlush (); gdk_gl_drawable_gl_end (gldrawable); return TRUE; }
void test_RT() { typedef RT Cls; // _test_cls_regular_3( Cls() ); typedef traits::Bare_point Point; typedef traits::Weighted_point Weighted_point; typedef typename Cls::Vertex_handle Vertex_handle; typedef typename Cls::Cell_handle Cell_handle; typedef typename Cls::Facet Facet; typedef typename Cls::Edge Edge; typedef std::list<Weighted_point> list_point; typedef typename Cls::Finite_cells_iterator Finite_cells_iterator; // temporary version int n, m; int count = 0; // For dimension 0, we need to check that the point of highest weight is the // one that finally ends up in the vertex. std::cout << " test dimension 0 " << std::endl; Cls T0; T0.insert(Weighted_point( Point (0,0,0), 0) ); T0.insert(Weighted_point( Point (0,0,0), 1) ); T0.insert(Weighted_point( Point (0,0,0), -1) ); assert(T0.dimension() == 0); assert(T0.number_of_vertices() == 1); assert(T0.finite_vertices_begin()->point().weight() == 1); std::cout << " test dimension 1 " << std::endl; Cls T1; std::cout << " number of inserted points : " ; Weighted_point p[5]; for ( m=0; m<5; m++) { if ( (m%2)== 0 ) p[m] = Weighted_point( Point( 2*m,0,0 ), 2 ); else p[m] = Weighted_point( Point( -2*m+1,0,0 ), 2 ); T1.insert( p[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; std::cout << " number of inserted points : " ; Weighted_point q[5]; for ( m=0; m<5; m++) { if ( (m%2)== 0 ) q[m] = Weighted_point( Point( 2*m+1,0,0 ), 5 ); else q[m] = Weighted_point( Point( -2*m+1,0,0 ), 5 ); T1.insert( q[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; std::cout << " number of inserted points : " ; Weighted_point r[10]; for ( m=0; m<10; m++) { if ( (m%2)== 0 ) r[m] = Weighted_point( Point( m,0,0 ), 1 ); else r[m] = Weighted_point( Point( -m,0,0 ), 1 ); T1.insert( r[m] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } assert( T1.is_valid() ); std::cout << std::endl << " number of vertices : " << T1.number_of_vertices() << std::endl; assert( T1.dimension()==1 ); // The following is distilled from a bug report by Wulue Zhao // ([email protected]), a student of Tamal Dey. Point pt0(0,0,0); Point pt1( 1,0,0), pt2(2,0,0), pt3(3,0,0); Point pt4(-1,0,0), pt5(-2,0,0), pt6(-3,0,0); Weighted_point wp0(pt0,10.0); Weighted_point wp1(pt1,0.0), wp2(pt2,0.0), wp3(pt3,0.0); Weighted_point wp4(pt4,0.0), wp5(pt5,0.0), wp6(pt6,0.0); Cls T11; T11.insert(wp0); T11.insert(wp1); T11.insert(wp2); T11.insert(wp3); T11.insert(wp4); T11.insert(wp5); T11.insert(wp6); assert(T11.is_valid()); // And another distilled bug report from the same guy. { Point p1(-0.07, 0.04, 0.04); Point p2(0.09, 0.04, 0.04); Point p3(0.09, -0.05, 0.04); Point p4(0.05, -0.05, 0.04); Point p5(0.05, 0.0, 0.04); Point p6(-0.07, 0.0, 0.04); Point p7(-0.07, 0.04, -0.04); Point p8(0.09, 0.04, -0.04); Point p9(0.09, -0.05, -0.04); Point p10(0.05, -0.05, -0.04); Point p11(0.05, 0.0, -0.04); Point p12(-0.07, 0.0, -0.04); Weighted_point wp1(p1,0); Weighted_point wp2(p2,0); Weighted_point wp3(p3,0); Weighted_point wp4(p4,0); Weighted_point wp5(p5,0); Weighted_point wp6(p6,0); Weighted_point wp7(p7,0); Weighted_point wp8(p8,0); Weighted_point wp9(p9,0); Weighted_point wp10(p10,0); Weighted_point wp11(p11,0); Weighted_point wp12(p12,0); Weighted_point wp13(p3,0.3); // wp13 has the same coordinates with wp3 Cls T111; T111.insert(wp1); T111.insert(wp2); T111.insert(wp3); T111.insert(wp13); // it doesnot work inserting wp13 here T111.insert(wp4); T111.insert(wp5); T111.insert(wp6); T111.insert(wp7); T111.insert(wp8); T111.insert(wp9); T111.insert(wp10); T111.insert(wp11); T111.insert(wp12); assert(T111.is_valid()); } std::cout << " test dimension 2 " << std::endl; std::cout << " number of inserted points : " ; Cls T2; count = 0 ; int px=1, py=1; int qx=-1, qy=2; Weighted_point s[400]; for (m=0; m<10; m++) for (n=0; n<10; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 1 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=10; m<20; m++) for (n=0; n<10; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -1 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=0; m<10; m++) for (n=10; n<20; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), -2 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } for (m=10; m<20; m++) for (n=10; n<20; n++) { s[m+20*n] = Weighted_point( Point(m*px+n*qx, m*py+n*qy, 0), 5 ); T2.insert( s[m+20*n] ); count++; if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else std::cout << count << '\b' << '\b' << '\b' ; std::cout.flush(); } std::cout << std::endl << " number of vertices : " << T2.number_of_vertices() << std::endl; assert( T2.dimension()==2 ); assert( T2.is_valid() ); // dimension 3 std::cout << " test dimension 3" << std::endl; Cls T; list_point lp; int a, b, d; for (a=0;a!=10;a++) // for (b=0;b!=10;b++) for (b=0;b!=5;b++) // for (d=0;d!=10;d++) for (d=0;d!=5;d++) lp.push_back(Weighted_point( Point(a*b-d*a + (a-b)*10 +a , a-b+d +5*b, a*a-d*d+b), a*b-a*d) ); list_point::iterator it; count = 0 ; std::cout << " number of inserted points : " ; for (it=lp.begin(); it!=lp.end(); ++it){ count++; T.insert(*it); if (count <10) std::cout << count << '\b' ; else if (count < 100) std::cout << count << '\b' << '\b' ; else if (count < 1000) std::cout << count << '\b' << '\b' << '\b' ; else std::cout << count << std::endl; std::cout.flush(); } std::cout << std::endl; std::cout << " number of vertices : " << T.number_of_vertices() << std::endl; assert(T.is_valid()); assert(T.dimension()==3); T.clear(); std::cout << " test iterator range insert" << std::endl; T.insert (lp.begin(), lp.end()); std::cout << " number of vertices : " << T.number_of_vertices() << std::endl; assert(T.is_valid()); assert(T.dimension()==3); //test nearest_power_vertex std::cout << " test nearest_power_vertex " << std::endl; Point pp1(0.0, 0.0, 0.0); Point pp2(1.0, 0.0, 0.0); Point pp3(0.0, 1.0, 0.0); Point pp4(0.0, 0.0, 1.0); Point pp5(1.0, 1.0, 0.0); Point pp6(0.0, 1.0, 1.0); Point pp7(1.0, 0.0, 1.0); Point pp8(1.0, 1.0, 1.0); Weighted_point wpp1(pp1, 1.0); Weighted_point wpp2(pp2, 2.0); Weighted_point wpp3(pp3, 1.0); Weighted_point wpp4(pp4, 4.0); Weighted_point wpp5(pp5, 1.0); Weighted_point wpp6(pp6, 1.0); Weighted_point wpp7(pp7, 1.0); Weighted_point wpp8(pp8, 8.0); Cls T3; T3.insert(wpp1); Vertex_handle v2 = T3.insert(wpp2); assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v2); T3.insert(wpp3); Vertex_handle v4 = T3.insert(wpp4); assert( T3.nearest_power_vertex(Point(0.5,0.5,0.5)) == v4); T3.insert(wpp5); T3.insert(wpp6); T3.insert(wpp7); // Avoid inserting the same point twice, now that hidden points are handled, // insert (existing_point) returns Vertex_handle(). // T3.insert(wpp8); Vertex_handle v8 = T3.insert(wpp8); Point query(0.5,0.5,0.5); assert(T3.nearest_power_vertex(query) == v8); assert(T3.nearest_power_vertex(Weighted_point(query,1.0)) == v8 ); assert(T3.nearest_power_vertex_in_cell(query ,v8->cell()) == v8); // test dual std::cout << " test dual member functions" << std::endl; Finite_cells_iterator fcit = T3.finite_cells_begin(); for( ; fcit != T3.finite_cells_end(); ++fcit) { Point cc = T3.dual(fcit); Vertex_handle ncc = T3.nearest_power_vertex(cc); assert(fcit->has_vertex(ncc)); } // test Gabriel std::cout << " test is_Gabriel " << std::endl; Point q0(0.,0.,0.); Point q1(2.,0.,0.); Point q2(0.,2.,0.); Point q3(0.,0.,2.); Weighted_point wq0(q0,0.); Weighted_point wq1(q1,0.); Weighted_point wq2(q2,0.); Weighted_point wq3(q3,0.); Weighted_point wq01(q0,2.); Cls T4; Vertex_handle v0 = T4.insert(wq0); Vertex_handle v1 = T4.insert(wq1); v2 = T4.insert(wq2); Vertex_handle v3 = T4.insert(wq3); Cell_handle c; int i,j,k,l; assert(T4.is_facet(v0,v1,v2,c,j,k,l)); i = 6 - (j+k+l); Facet f = std::make_pair(c,i); assert(T4.is_Gabriel(c,i)); assert(T4.is_Gabriel(f)); assert(T4.is_facet(v1,v2,v3,c,j,k,l)); i = 6 - (j+k+l); assert(!T4.is_Gabriel(c,i)); assert(T4.is_edge(v0,v1,c,i,j)); assert(T4.is_Gabriel(c,i,j)); Edge e = make_triple(c,i,j); assert(T4.is_Gabriel(e)); assert(T4.is_edge(v2,v3,c,i,j)); assert(T4.is_Gabriel(c,i,j)); Vertex_handle v01 = T4.insert(wq01); (void) v01; // kill warning assert(T4.is_edge(v2,v3,c,i,j)); assert(!T4.is_Gabriel(c,i,j)); Weighted_point wwq0(q0,0.); Weighted_point wwq1(q1,0.); Weighted_point wwq2(q2,0.); Weighted_point wwq3(q3,5.); Cls T5; v0 = T5.insert(wwq0); v1 = T5.insert(wwq1); v2 = T5.insert(wwq2); v3 = T5.insert(wwq3); assert(T5.nearest_power_vertex(v3->point().point()) == v3); assert(T5.nearest_power_vertex(v0->point().point()) == v3); assert(T5.is_Gabriel(v3)); assert(!T5.is_Gabriel(v0)); }