Commit f81019db authored by Max Lyon's avatar Max Lyon

color and normal attributes for OpenVolumeMesh can now be checked

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@237 66977474-1d4b-4f09-8fe9-267525286df2
parent c27a90a5
......@@ -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<ColT> vcolor_prop_;
......@@ -150,6 +172,16 @@ private:
CellPropertyT<ColT> 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
......
......@@ -54,7 +54,15 @@ ColorAttrib<ColT>::ColorAttrib(TopologyKernel& _kernel, const ColT _def) :
fcolor_prop_(_kernel.request_face_property<ColT>("face_color", _def)),
hfcolor_prop_(_kernel.request_halfface_property<ColT>("halfface_color", _def)),
ccolor_prop_(_kernel.request_cell_property<ColT>("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<ColT>::~ColorAttrib() {
}
template <class ColT>
void ColorAttrib<ColT>::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 <class ColT>
void ColorAttrib<ColT>::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 <class ColT>
void ColorAttrib<ColT>::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 <class ColT>
void ColorAttrib<ColT>::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 <class ColT>
void ColorAttrib<ColT>::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 <class ColT>
void ColorAttrib<ColT>::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
......@@ -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<typename GeomKernelT::PointT> v_normals_;
FacePropertyT<typename GeomKernelT::PointT> f_normals_;
bool vertex_normals_available_;
bool face_normals_available_;
};
} // Namespace OpenVolumeMesh
......
......@@ -54,7 +54,10 @@ template <class GeomKernelT>
NormalAttrib<GeomKernelT>::NormalAttrib(GeomKernelT& _kernel) :
kernel_(_kernel),
v_normals_(_kernel.template request_vertex_property<typename GeomKernelT::PointT>("vertex_normals")),
f_normals_(_kernel.template request_face_property<typename GeomKernelT::PointT>("face_normals")) {
f_normals_(_kernel.template request_face_property<typename GeomKernelT::PointT>("face_normals")),
vertex_normals_available_(false),
face_normals_available_(false)
{
}
......@@ -77,6 +80,8 @@ void NormalAttrib<GeomKernelT>::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 <class GeomKernelT>
......@@ -92,26 +97,27 @@ void NormalAttrib<GeomKernelT>::update_face_normals() {
// first two edges
compute_face_normal(*f_it);
}
face_normals_available_ = true;
}
template <class GeomKernelT>
void NormalAttrib<GeomKernelT>::compute_vertex_normal(const VertexHandle& _vh) {
std::set<FaceHandle> faces;
std::set<HalfFaceHandle> 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<FaceHandle>::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<HalfFaceHandle>::const_iterator hf_it = halffaces.begin();
hf_it != halffaces.end(); ++hf_it) {
normal += (*this)[*hf_it];
}
normal.normalize();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment