コード例 #1
0
void PlainSurfaceRender::draw_surface() {

	if (use_color_attribute_)
		facet_color_.bind_if_defined(target(), "color") ;
	if (use_color_attribute_ && (!facet_color_.is_bound()))
		vertex_color_.bind_if_defined(target(), "color") ;

	glEnable(GL_LIGHTING);
	glColor4fv(surface_style_.color.data());

	if (vertex_color_.is_bound()) {
		glShadeModel(GL_SMOOTH);
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		if (smooth_shading_) {
			if (!MapVertexNormal::is_defined(target()))
				target()->compute_vertex_normals();
			MapVertexNormal normal(target()) ;

			FOR_EACH_FACET_CONST(Map, target(), it) {
				glBegin(GL_POLYGON);
				Map::Halfedge* jt = it->halfedge() ;
				do {
					Map::Vertex* v = jt->vertex();
					glColor4fv(vertex_color_[v].data());

					const vec3& n = normal[v];
					glNormal3dv(n.data());

					const vec3& p = v->point();
					glVertex3dv(p.data());
					jt = jt->next() ;
				} while(jt != it->halfedge()) ;
				glEnd();
			}	
		} 
コード例 #2
0
 // Step 4: create facets
 FOR_EACH_FACET(MapComponent, component, it) {
     Map::Halfedge* h = it->halfedge() ;
     builder.begin_facet() ;
     do {
         builder.add_vertex_to_facet(vertex_id[h->vertex()]) ;
         builder.set_corner_tex_vertex(tex_vertex_id[h->tex_vertex()]) ;
         h = h->next() ;
     } while(h != it->halfedge()) ;
     builder.end_facet() ;
     copy_facet_attributes(builder.current_facet(), it) ;
 }
コード例 #3
0
	bool save(const std::string& filename) {
		if(map_ == nil) {
			Logger::err("PlyMeshSave") << "mesh is null" << std::endl ;
			return false ;
		}

		p_ply ply = ply_create(filename.c_str(), PLY_LITTLE_ENDIAN, nil, 0, nil) ;

		if(ply == nil) {
			Logger::err("PlyMeshSave") << filename << ": could not open" << std::endl ;
			return false ;
		}

		//////////////////////////////////////////////////////////////////////////

		if (!ply_add_comment(ply, "saved by [email protected]")) {
			Logger::err("PlyMeshSave") << "unable to add comment" << std::endl ;
			ply_close(ply) ;
			return false ;
		}

		int num_v = map_->size_of_vertices();
		if (!ply_add_element(ply, "vertex", num_v)) {
			Logger::err("PlyMeshSave") << "unable to add element \'vertex\'" << std::endl ;
			ply_close(ply) ;
			return false ;
		}
		
		e_ply_type length_type, value_type;
		length_type = value_type = static_cast<e_ply_type>(-1);
		std::string pos[3] = { "x", "y", "z" };
		for (unsigned int i=0; i<3; ++i) {
			if (!ply_add_property(ply, pos[i].c_str(), PLY_FLOAT, length_type, value_type)) {
				Logger::err("PlyMeshSave") << "unable to add property \'" << pos[i] << "\'" << std::endl ;
				ply_close(ply) ;
				return false ;
			}
		}

		MapVertexAttribute<Color> vertex_color;
		vertex_color.bind_if_defined(const_cast<Map*>(map_), "color") ;
		if (vertex_color.is_bound()) {
			std::string color[4] = { "red", "green", "blue", "alpha" };
			for (unsigned int i=0; i<4; ++i) {
				if (!ply_add_property(ply, color[i].c_str(), PLY_UCHAR, length_type, value_type)) {
					Logger::err("PlyMeshSave") << "unable to add property \'" << color[i] << "\'" << std::endl ;
					ply_close(ply) ;
					return false ;
				}
			}
		}
		
		int num_f = map_->size_of_facets();
		if (!ply_add_element(ply, "face", num_f)) {
			Logger::err("PlyMeshSave") << "unable to add element \'face\'" << std::endl ;
			ply_close(ply) ;
			return false ;
		}
		if (!ply_add_property(ply, "vertex_indices", PLY_LIST, PLY_UCHAR, PLY_INT)) {
			Logger::err("PlyMeshSave") << "unable to add property \'vertex_indices\'" << std::endl ;
			ply_close(ply) ;
			return false ;
		}

		if(!ply_write_header(ply)) {
			Logger::err("PlyMeshSave") << filename << ": invalid PLY file" << std::endl ;
			ply_close(ply) ;
			return false ;
		}

		//////////////////////////////////////////////////////////////////////////
		
		FOR_EACH_VERTEX_CONST(Map, map_, it) {
			const vec3& p = it->point();
			ply_write(ply, p.x);
			ply_write(ply, p.y);
			ply_write(ply, p.z);
			if (vertex_color.is_bound()) {
				const Color& c = vertex_color[it];
				double r = c.r() * color_mult_;	ogf_clamp(r, 0.0, 255.0);
				double g = c.g() * color_mult_;	ogf_clamp(g, 0.0, 255.0);
				double b = c.b() * color_mult_;	ogf_clamp(b, 0.0, 255.0);
				double a = c.a() * color_mult_; ogf_clamp(a, 0.0, 255.0);
				ply_write(ply, r);
				ply_write(ply, g);
				ply_write(ply, b);
				ply_write(ply, a);
			}
		}

		// ply files numbering starts with 0
		Attribute<Map::Vertex, int> vertex_id(map_->vertex_attribute_manager());
		MapEnumerator::enumerate_vertices(const_cast<Map*>(map_), vertex_id, 0);
		FOR_EACH_FACET_CONST(Map, map_, it) {
			ply_write(ply, it->nb_vertices());
			Map::Halfedge* h = it->halfedge();
			do 
			{
				int id = vertex_id[h->vertex()];
				ply_write(ply, id);
				h = h->next();
			} while (h != it->halfedge());
		}