diff --git a/src/OpenVolumeMesh/Attribs/ColorAttrib.hh b/src/OpenVolumeMesh/Attribs/ColorAttrib.hh index a8d6e14c2669e9940ed4f9e57612445d1a6b4094..018c3fdac997193e30e2b8d65bdeee38511c348b 100644 --- a/src/OpenVolumeMesh/Attribs/ColorAttrib.hh +++ b/src/OpenVolumeMesh/Attribs/ColorAttrib.hh @@ -72,6 +72,7 @@ public: ColT& operator[](const VertexHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_vertices()); + vertex_colors_available_ = true; return vcolor_prop_[_h.idx()]; } @@ -85,6 +86,7 @@ public: ColT& operator[](const EdgeHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_edges()); + edge_colors_available_ = true; return ecolor_prop_[_h.idx()]; } @@ -98,6 +100,7 @@ public: ColT& operator[](const HalfEdgeHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_halfedges()); + halfedge_colors_available_ = true; return hecolor_prop_[_h.idx()]; } @@ -111,6 +114,7 @@ public: ColT& operator[](const FaceHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_faces()); + face_colors_available_ = true; return fcolor_prop_[_h.idx()]; } @@ -124,6 +128,7 @@ public: ColT& operator[](const HalfFaceHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_halffaces()); + halfface_colors_available_ = true; return hfcolor_prop_[_h.idx()]; } @@ -137,9 +142,26 @@ public: ColT& operator[](const CellHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_cells()); + cell_colors_available_ = true; return ccolor_prop_[_h.idx()]; } + + bool vertex_colors_available() { return vertex_colors_available_; } + bool halfedge_colors_available() { return halfedge_colors_available_; } + bool edge_colors_available() { return edge_colors_available_; } + bool halfface_colors_available() { return halfface_colors_available_; } + bool face_colors_available() { return face_colors_available_; } + bool cell_colors_available() { return cell_colors_available_; } + + void clear_vertex_colors(); + void clear_halfedge_colors(); + void clear_edge_colors(); + void clear_halfface_colors(); + void clear_face_colors(); + void clear_cell_colors(); + + private: VertexPropertyT vcolor_prop_; @@ -150,6 +172,16 @@ private: CellPropertyT ccolor_prop_; TopologyKernel& kernel_; + + bool vertex_colors_available_; + bool halfedge_colors_available_; + bool edge_colors_available_; + bool halfface_colors_available_; + bool face_colors_available_; + bool cell_colors_available_; + + ColT default_color_; + }; } // Namespace OpenVolumeMesh diff --git a/src/OpenVolumeMesh/Attribs/ColorAttribT.cc b/src/OpenVolumeMesh/Attribs/ColorAttribT.cc index f01427633535c432780d9657f0ae5f93057338be..7893385dec69985e94901ae1bb22a6e412e49d3d 100644 --- a/src/OpenVolumeMesh/Attribs/ColorAttribT.cc +++ b/src/OpenVolumeMesh/Attribs/ColorAttribT.cc @@ -54,7 +54,15 @@ ColorAttrib::ColorAttrib(TopologyKernel& _kernel, const ColT _def) : fcolor_prop_(_kernel.request_face_property("face_color", _def)), hfcolor_prop_(_kernel.request_halfface_property("halfface_color", _def)), ccolor_prop_(_kernel.request_cell_property("cell_color", _def)), - kernel_(_kernel) { + kernel_(_kernel), + vertex_colors_available_(false), + halfedge_colors_available_(false), + edge_colors_available_(false), + halfface_colors_available_(false), + face_colors_available_(false), + cell_colors_available_(false), + default_color_ (_def) +{ } @@ -63,4 +71,52 @@ ColorAttrib::~ColorAttrib() { } +template +void ColorAttrib::clear_vertex_colors() +{ + for (VertexIter v_it = kernel_.vertices_begin(); v_it != kernel_.vertices_end(); ++v_it) + vcolor_prop_[v_it->idx()] = default_color_; + vertex_colors_available_ = false; +} + +template +void ColorAttrib::clear_halfedge_colors() +{ + for (HalfEdgeIter he_it = kernel_.halfedges_begin(); he_it != kernel_.halfedges_end(); ++he_it) + hecolor_prop_[he_it->idx()] = default_color_; + halfedge_colors_available_ = false; +} + +template +void ColorAttrib::clear_edge_colors() +{ + for (EdgeIter e_it = kernel_.edges_begin(); e_it != kernel_.edges_end(); ++e_it) + ecolor_prop_[e_it->idx()] = default_color_; + edge_colors_available_ = false; +} + +template +void ColorAttrib::clear_halfface_colors() +{ + for (HalfFaceIter hf_it = kernel_.halffaces_begin(); hf_it != kernel_.halffaces_end(); ++hf_it) + hfcolor_prop_[hf_it->idx()] = default_color_; + halfface_colors_available_ = false; +} + +template +void ColorAttrib::clear_face_colors() +{ + for (FaceIter f_it = kernel_.faces_begin(); f_it != kernel_.faces_end(); ++f_it) + fcolor_prop_[f_it->idx()] = default_color_; + face_colors_available_ = false; +} + +template +void ColorAttrib::clear_cell_colors() +{ + for (CellIter c_it = kernel_.cells_begin(); c_it != kernel_.cells_end(); ++c_it) + ccolor_prop_[c_it->idx()] = default_color_; + cell_colors_available_ = false; +} + } // Namespace OpenVolumeMesh diff --git a/src/OpenVolumeMesh/Attribs/NormalAttrib.hh b/src/OpenVolumeMesh/Attribs/NormalAttrib.hh index 146742be5247771f8d451b109713d815d12ec7f6..616273b04a09360154c67b6cb40e7e60ab869e79 100644 --- a/src/OpenVolumeMesh/Attribs/NormalAttrib.hh +++ b/src/OpenVolumeMesh/Attribs/NormalAttrib.hh @@ -94,21 +94,27 @@ public: typename GeomKernelT::PointT& operator[](const VertexHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_vertices()); + vertex_normals_available_ = true; return v_normals_[_h.idx()]; } typename GeomKernelT::PointT& operator[](const FaceHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_faces()); + face_normals_available_ = true; return f_normals_[_h.idx()]; } typename GeomKernelT::PointT operator[](const HalfFaceHandle& _h) { assert((unsigned int)_h.idx() < kernel_.n_halffaces()); + face_normals_available_ = true; double mult = 1.0; if(_h.idx() % 2 == 1) mult = -1.0; return f_normals_[kernel_.face_handle(_h).idx()] * mult; } + bool vertex_normals_available() { return vertex_normals_available_; } + bool face_normals_available() { return face_normals_available_; } + private: void compute_vertex_normal(const VertexHandle& _vh); @@ -119,6 +125,10 @@ private: VertexPropertyT v_normals_; FacePropertyT f_normals_; + + + bool vertex_normals_available_; + bool face_normals_available_; }; } // Namespace OpenVolumeMesh diff --git a/src/OpenVolumeMesh/Attribs/NormalAttribT.cc b/src/OpenVolumeMesh/Attribs/NormalAttribT.cc index 0921d72e420db304df0dfc0673db3cc3e3559c6f..0f9a62f812cd7c4d29026a538a8a178bf424b9ca 100644 --- a/src/OpenVolumeMesh/Attribs/NormalAttribT.cc +++ b/src/OpenVolumeMesh/Attribs/NormalAttribT.cc @@ -54,7 +54,10 @@ template NormalAttrib::NormalAttrib(GeomKernelT& _kernel) : kernel_(_kernel), v_normals_(_kernel.template request_vertex_property("vertex_normals")), -f_normals_(_kernel.template request_face_property("face_normals")) { +f_normals_(_kernel.template request_face_property("face_normals")), +vertex_normals_available_(false), +face_normals_available_(false) +{ } @@ -77,6 +80,8 @@ void NormalAttrib::update_vertex_normals() { for(VertexIter v_it = kernel_.v_iter(); v_it.valid(); ++v_it) { compute_vertex_normal(*v_it); } + + vertex_normals_available_ = true; } template @@ -92,26 +97,27 @@ void NormalAttrib::update_face_normals() { // first two edges compute_face_normal(*f_it); } + face_normals_available_ = true; } template void NormalAttrib::compute_vertex_normal(const VertexHandle& _vh) { - std::set faces; + std::set halffaces; for(VertexOHalfEdgeIter voh_it = kernel_.voh_iter(_vh); voh_it.valid(); ++voh_it) { for(HalfEdgeHalfFaceIter hehf_it = kernel_.hehf_iter(*voh_it); hehf_it.valid(); ++hehf_it) { if(kernel_.is_boundary(*hehf_it)) { - faces.insert(kernel_.face_handle(*hehf_it)); + halffaces.insert(*hehf_it); } } } - typename GeomKernelT::PointT normal; - for(std::set::const_iterator f_it = faces.begin(); - f_it != faces.end(); ++f_it) { - normal += f_normals_[f_it->idx()]; + typename GeomKernelT::PointT normal = typename GeomKernelT::PointT(0.0); + for(std::set::const_iterator hf_it = halffaces.begin(); + hf_it != halffaces.end(); ++hf_it) { + normal += (*this)[*hf_it]; } normal.normalize();