void Scene_combinatorial_map_item::direct_draw() const { typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> Volume_dart_range; typedef Combinatorial_map_3::One_dart_per_incident_cell_const_range<2,3> Facet_in_volume_drange; typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range; Volume_dart_range dart_per_volume_range = combinatorial_map().one_dart_per_cell<3>(); std::size_t index = 0; for (Volume_dart_range::const_iterator vit=dart_per_volume_range.begin();vit!=dart_per_volume_range.end();++vit) { if (++index!=volume_to_display && volume_to_display!=0) continue; Facet_in_volume_drange facet_range=combinatorial_map().one_dart_per_incident_cell<2,3>(vit); for(Facet_in_volume_drange::const_iterator fit=facet_range.begin();fit!=facet_range.end();++fit){ Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(fit); Kernel::Vector_3 normal = compute_face_normal(fit); ::glBegin(GL_POLYGON); ::glNormal3d(normal.x(),normal.y(),normal.z()); for (Dart_in_facet_range::const_iterator pit=vertices.begin();pit!=vertices.end();++pit ){ const Kernel::Point_3& p= pit->attribute<0>()->point(); ::glVertex3d(p.x(),p.y(),p.z()); } ::glEnd(); } } }
void Surface_mesh:: update_face_normals() { if (!fnormal_) fnormal_ = face_property<Normal>("f:normal"); Face_iterator fit, fend=faces_end(); for (fit=faces_begin(); fit!=fend; ++fit) { if (!is_deleted(fit)) fnormal_[fit] = compute_face_normal(fit); } }
void Scene_combinatorial_map_item::compute_elements(void) const{ positions_facets.resize(0); normals.resize(0); positions_lines.resize(0); positions_points.resize(0); //Facets { std::size_t index = 0; int voltreated = combinatorial_map().get_new_mark(); int facetreated = combinatorial_map().get_new_mark(); Combinatorial_map_3::Dart_const_range::const_iterator darts_it=combinatorial_map().darts().begin(), darts_end=combinatorial_map().darts().end(); for( ; darts_it!=darts_end; ++darts_it) { if ( !combinatorial_map().is_marked(darts_it,voltreated) ) { ++index; //iterate over all the darts of the volume Combinatorial_map_3::Dart_of_cell_const_range<3>::const_iterator vol_it=combinatorial_map().darts_of_cell<3>(darts_it).begin(), vol_end=combinatorial_map().darts_of_cell<3>(darts_it).end(); if ( volume_to_display!=0 && index!=volume_to_display ) { //only mark darts if the volume is not the one to display for ( ;vol_it!=vol_end; ++vol_it ) { combinatorial_map().mark(vol_it,facetreated); combinatorial_map().mark(vol_it, voltreated); } } else { for ( ;vol_it!=vol_end; ++vol_it ) { if ( !combinatorial_map().is_marked(vol_it,facetreated) ) { Kernel::Vector_3 normal = compute_face_normal(vol_it); for(int i=0; i<3; i++) { normals.push_back(normal.x()); normals.push_back(normal.y()); normals.push_back(normal.z()); } //iterate over all darts of facets for ( Combinatorial_map_3::Dart_of_orbit_const_range<1>::const_iterator face_it=combinatorial_map().darts_of_orbit<1>(vol_it).begin(), face_end=combinatorial_map().darts_of_orbit<1>(vol_it).end(); face_it!=face_end; ++face_it) { const Kernel::Point_3& p= face_it->attribute<0>()->point(); positions_facets.push_back(p.x()); positions_facets.push_back(p.y()); positions_facets.push_back(p.z()); combinatorial_map().mark(face_it,facetreated); combinatorial_map().mark(face_it, voltreated); } } } } if ( index==volume_to_display ) break; } } //mark remaining darts to have an O(1) free_mark for( ; darts_it!=darts_end; ++darts_it) { combinatorial_map().mark(darts_it, facetreated); combinatorial_map().mark(darts_it, voltreated); } combinatorial_map().free_mark(facetreated); combinatorial_map().free_mark(voltreated); } //edges { typedef Combinatorial_map_3::One_dart_per_cell_const_range<1> Edge_darts; Edge_darts darts=combinatorial_map().one_dart_per_cell<1>(); for (Edge_darts::const_iterator dit=darts.begin();dit!=darts.end();++dit){ CGAL_assertion(!dit->is_free(1)); const Kernel::Point_3& a = dit->attribute<0>()->point(); const Kernel::Point_3& b = dit->beta(1)->attribute<0>()->point(); positions_lines.push_back(a.x()); positions_lines.push_back(a.y()); positions_lines.push_back(a.z()); positions_lines.push_back(b.x()); positions_lines.push_back(b.y()); positions_lines.push_back(b.z()); } } //points { typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range; const Point_range& points=combinatorial_map().attributes<0>(); for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit){ const Kernel::Point_3& p=pit->point(); positions_points.push_back(p.x()); positions_points.push_back(p.y()); positions_points.push_back(p.z()); } } }
//---------------------------------------------------------------------------- void dmEnvironment::drawInit() { register int i, j; // GLfloat vertex[3][3], normal[3]; GLfloat vtex[4][3];//lyp // read in and allocate depth data m_terrain_model_index = glGenLists(1); if (m_terrain_model_index == 0) { cerr << "loadModel_grid: Error unable to allocate dlist index." << endl; } ////////////////////////////// // **** // Currently only flat ground can have textures. If you want to work with uneven terrain, comment out the // following line. That will switch back to the McMillan's old code. - yiping #define TEXTURED_FLAT_GROUND //NOTE: texture image has to be 16*16 or 64*64 or 128*128 or 256*256 #ifdef TEXTURED_FLAT_GROUND GLuint texture_ID_1; //glDisable(GL_BLEND); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGenTextures( 1, &texture_ID_1 ); //glBindTexture( GL_TEXTURE_2D, texture_ID_1 ); FILE* f = fopen("checker1.bmp","rb"); int tw; int th; unsigned char* data; //GLubyte **pixelArray; if (f != NULL) { unsigned char info[54]; fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header // extract texture image height and width from header tw = *(int*)&info[18]; th = *(int*)&info[22]; cout<< "texture file is "<< tw <<"x" <<th <<" ."<<endl; int size = 4 * tw * th; data = new unsigned char[size]; // allocate 4 bytes per pixel fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once! //Size in bytes of each element to be read. fclose(f); for(i = 0; i < size; i += 4) // swap the first and third pixal, possibly necessary. { unsigned char tmp = data[i]; data[i] = data[i+2]; data[i+2] = tmp; } //pixelArray = new GLubyte * [tw*th]; //for (int i=0; i<tw*th;i++) //{ // pixelArray[i]= new GLubyte [3]; // pixelArray[i][0]=(GLubyte) data[3*i]; // pixelArray[i][1]=(GLubyte) data[3*i+1]; // pixelArray[i][2]=(GLubyte) data[3*i+2]; //} } else { cout<<"Texture file not opened. "<<endl; } // cout<<int(textureArray[0][15][0])<<endl; glBindTexture (GL_TEXTURE_2D, texture_ID_1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, // level of detail 0-base level GL_RGBA, // number of color components in texture tw, // texture width th, // texture height, 0, // border GL_RGBA,// number of color components of image pixels GL_UNSIGNED_BYTE,// image data type data); glNewList(m_terrain_model_index, GL_COMPILE); { glEnable(GL_TEXTURE_2D); //glShadeModel(GL_SMOOTH); //glPolygonMode(GL_FRONT, GL_LINE); //glPolygonMode(GL_BACK, GL_LINE); // wire frame terrain glPolygonMode(GL_FRONT, GL_FILL); //GL_LINE); glPolygonMode(GL_BACK, GL_FILL); for (i=0; i<m_x_dim; i++)// { for (j=0; j<m_y_dim; j++)// { vtex[0][0] = ((GLfloat) i)*m_grid_resolution; vtex[0][1] = ((GLfloat) j)*m_grid_resolution; vtex[0][2] = 0.0; vtex[1][0] = ((GLfloat) i+ 1.0)*m_grid_resolution; vtex[1][1] = ((GLfloat) j )*m_grid_resolution; vtex[1][2] = 0.0; vtex[2][0] = ((GLfloat) i + 1.0)*m_grid_resolution; vtex[2][1] = ((GLfloat) j + 1.0)*m_grid_resolution; vtex[2][2] = 0.0; vtex[3][0] = ((GLfloat) i )*m_grid_resolution; vtex[3][1] = ((GLfloat) j+ 1.0 )*m_grid_resolution; vtex[3][2] = 0.0; glBegin (GL_QUADS); glNormal3d(0, 0, 1); glTexCoord2f (0.0, 0.0); glVertex3fv (vtex[0]); glTexCoord2f (1.0, 0.0); glVertex3fv (vtex[1]); glTexCoord2f (1.0, 1.0); glVertex3fv (vtex[2]); glTexCoord2f (0.0, 1.0); glVertex3fv (vtex[3]); glEnd (); } } glDisable(GL_TEXTURE_2D); } glEndList(); #else ///////////////////////////////////////////////// glNewList(m_terrain_model_index, GL_COMPILE); { glPolygonMode(GL_FRONT, GL_FILL); //GL_LINE); glPolygonMode(GL_BACK, GL_FILL); GLfloat color[4] = {0.5,0.5,0.5,1.0}; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); char buffer[200]; // // for (j=0; j<m_y_dim-1; j++) { glBegin(GL_TRIANGLE_STRIP); { for (i=0; i<m_x_dim; i++) { vertex[0][0] = ((GLfloat) i)*m_grid_resolution; vertex[0][1] = ((GLfloat) j + 1.0)*m_grid_resolution; vertex[0][2] = m_depth[i][j+1]; if (i > 0) { vertex[1][0] = ((GLfloat) i - 1.0)*m_grid_resolution; vertex[1][1] = ((GLfloat) j + 1.0)*m_grid_resolution; vertex[1][2] = m_depth[i-1][j+1]; vertex[2][0] = ((GLfloat) i - 1.0)*m_grid_resolution; vertex[2][1] = ((GLfloat) j)*m_grid_resolution; vertex[2][2] = m_depth[i-1][j]; compute_face_normal(vertex[1], vertex[2], vertex[0], normal); glNormal3fv(normal); } glVertex3fv(vertex[0]); vertex[1][0] = ((GLfloat) i)*m_grid_resolution; vertex[1][1] = ((GLfloat) j)*m_grid_resolution; vertex[1][2] = m_depth[i][j]; if (i > 0) { compute_face_normal(vertex[1], vertex[0], vertex[2], normal); glNormal3fv(normal); } glVertex3fv(vertex[1]); } } glEnd(); } } glEndList(); #endif }
double MxBlockModel::compute_face_area(MxFaceID f) { Vec3 n = compute_face_normal(f, false); return 0.5 * n.Length(); }