Exemplo n.º 1
0
int main(int argc, char** argv)
{
  typedef boost::property_map< 
    Polyhedron,
    CGAL::face_index_t 
    >::const_type Face_index_map;

  std::ifstream in((argc>1)?argv[1]:"cube.off");
  Polyhedron P;
  in >> P ;
  
  // initialize facet indices
  std::size_t i = 0;
  for(Polyhedron::Facet_iterator it = P.facets_begin(); it != P.facets_end(); ++it, ++i) 
  {
    it->id() = i;
  }

  // Ad hoc property_map to store normals. Face_index_map is used to
  // map face_descriptors to a contiguous range of indices. See
  // http://www.boost.org/libs/property_map/doc/vector_property_map.html
  // for details.
  boost::vector_property_map<Vector, Face_index_map> 
    normals(get(CGAL::face_index, P));

  calculate_face_normals(
    P // Graph
    , get(CGAL::vertex_point, P) // map from vertex_descriptor to point
    , normals // map from face_descriptor to Vector_3
    );

  std::cout << "Normals" << std::endl;
  for(Polyhedron::Facet_iterator it = P.facets_begin(); it != P.facets_end(); ++it) { 
    // Facet_iterator is a face_descriptor, so we can use it as the
    // key here
    std::cout << normals[it] << std::endl;
  }

  return 0;
}
Exemplo n.º 2
0
void CL_Collada_Triangles_Impl::create_vertices_texcoords(CL_Vec2f *destination, int stride, const CL_String &semantic)
{
	CL_Collada_Input_Shared &input = get_input(semantic);

	CL_Collada_Source &source = input.get_source();
	if (source.is_null())
	{
		throw CL_Exception("unsupported situation. fixme");
	}

	std::vector<CL_Vec3f> &pos_array = source.get_vec3f_array();

	unsigned int primitive_offset = input.get_offset();
	std::vector<CL_Vec3f> face_normals;
	calculate_face_normals(face_normals, pos_array, primitive_offset);

	std::vector<int> face_offsets;
	std::vector<int> faces;

	generate_point_facelist(face_offsets, faces, pos_array.size(), primitive_offset);

	calculate_texcoords(face_offsets, faces, pos_array, face_normals, destination, stride, primitive_offset );
}