// class declaration /// Cache implementation. input_t must implement "void update(bool)" and "facevertices_t& face_vertices()" template class catmull_clark_cache_implementation { public: catmull_clark_cache_implementation(input_t& Input, int Levels); ~catmull_clark_cache_implementation(); /// update point positions void update(bool all = false); /// Get the number of levels const unsigned long levels() const { return m_levels; } /// draw the result using opengl void draw(); private: input_t& m_input; int m_levels; typedef std::map inner_bordermap_t; typedef std::map bordermap_t; typedef std::map cornermap_t; bordermap_t m_borders; std::vector m_patch_parents; std::vector m_border_parents; cornermap_t m_patch_corners; // get or create the border line with given start and end points border_root_t* get_border(valid_point* Start, valid_point* End); // only retrieve the border from the map border_root_t* retrieve_border(valid_point* Start, valid_point* End, bool recurse = true); // generate cache up to level void generate(int level); // get the patch_corner associated with the Point patch_corner* get_patch_corner(valid_point* Point); }; // definition template void libk3dmesh::detail::catmull_clark_cache_implementation::draw( ) { k3d::gl::store_attributes attributes; glEnable(GL_LIGHTING); glColor3d(0.8, 0.8, 1); glFrontFace(GL_CW); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_CULL_FACE); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0, 1.0); for (facevertices_t::iterator face = m_input.face_vertices().begin(); face != m_input.face_vertices().end(); ++face) (*face)->draw(m_levels-1); }