Developer Documentation
ColorAttrib.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenVolumeMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 36 $ *
38  * $Date: 2012-01-10 18:00:06 +0100 (Di, 10 Jan 2012) $ *
39  * $LastChangedBy: kremer $ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef COLORATTRIB_HH_
44 #define COLORATTRIB_HH_
45 
46 #include <cassert>
47 
48 #include "../Core/OpenVolumeMeshHandle.hh"
49 #include "OpenVolumeMeshStatus.hh"
50 #include "../Core/PropertyDefines.hh"
51 #include "../Core/TopologyKernel.hh"
52 
53 namespace OpenVolumeMesh {
54 
55 //== CLASS DEF ================================================================
56 
57 template <class ColT>
58 class ColorAttrib {
59 public:
60 
61  ColorAttrib(TopologyKernel& _kernel, const ColT _def = ColT());
62 
63  virtual ~ColorAttrib();
64 
65  //==================
66  // Vertices
67  //==================
68  const ColT& operator[](const VertexHandle& _h) const {
69  assert((unsigned int)_h.idx() < kernel_.n_vertices());
70  return vcolor_prop_[_h];
71  }
72 
73  ColT& operator[](const VertexHandle& _h) {
74  assert((unsigned int)_h.idx() < kernel_.n_vertices());
75  vertex_colors_available_ = true;
76  return vcolor_prop_[_h];
77  }
78 
79  //==================
80  // Edges
81  //==================
82  const ColT& operator[](const EdgeHandle& _h) const {
83  assert((unsigned int)_h.idx() < kernel_.n_edges());
84  return ecolor_prop_[_h];
85  }
86 
87  ColT& operator[](const EdgeHandle& _h) {
88  assert((unsigned int)_h.idx() < kernel_.n_edges());
89  edge_colors_available_ = true;
90  return ecolor_prop_[_h];
91  }
92 
93  //==================
94  // Half-Edges
95  //==================
96  const ColT& operator[](const HalfEdgeHandle& _h) const {
97  assert((unsigned int)_h.idx() < kernel_.n_halfedges());
98  return hecolor_prop_[_h];
99  }
100 
101  ColT& operator[](const HalfEdgeHandle& _h) {
102  assert((unsigned int)_h.idx() < kernel_.n_halfedges());
103  halfedge_colors_available_ = true;
104  return hecolor_prop_[_h];
105  }
106 
107  //==================
108  // Faces
109  //==================
110  const ColT& operator[](const FaceHandle& _h) const {
111  assert((unsigned int)_h.idx() < kernel_.n_faces());
112  return fcolor_prop_[_h];
113  }
114 
115  ColT& operator[](const FaceHandle& _h) {
116  assert((unsigned int)_h.idx() < kernel_.n_faces());
117  face_colors_available_ = true;
118  return fcolor_prop_[_h];
119  }
120 
121  //==================
122  // Half-Faces
123  //==================
124  const ColT& operator[](const HalfFaceHandle& _h) const {
125  assert((unsigned int)_h.idx() < kernel_.n_halffaces());
126  return hfcolor_prop_[_h];
127  }
128 
129  ColT& operator[](const HalfFaceHandle& _h) {
130  assert((unsigned int)_h.idx() < kernel_.n_halffaces());
131  halfface_colors_available_ = true;
132  return hfcolor_prop_[_h];
133  }
134 
135  //==================
136  // Cells
137  //==================
138  const ColT& operator[](const CellHandle& _h) const {
139  assert((unsigned int)_h.idx() < kernel_.n_cells());
140  return ccolor_prop_[_h];
141  }
142 
143  ColT& operator[](const CellHandle& _h) {
144  assert((unsigned int)_h.idx() < kernel_.n_cells());
145  cell_colors_available_ = true;
146  return ccolor_prop_[_h];
147  }
148 
149 
150  bool vertex_colors_available() { return vertex_colors_available_; }
151  bool halfedge_colors_available() { return halfedge_colors_available_; }
152  bool edge_colors_available() { return edge_colors_available_; }
153  bool halfface_colors_available() { return halfface_colors_available_; }
154  bool face_colors_available() { return face_colors_available_; }
155  bool cell_colors_available() { return cell_colors_available_; }
156 
157  void clear_vertex_colors();
158  void clear_halfedge_colors();
159  void clear_edge_colors();
160  void clear_halfface_colors();
161  void clear_face_colors();
162  void clear_cell_colors();
163 
164 
165 private:
166 
167  VertexPropertyT<ColT> vcolor_prop_;
168  EdgePropertyT<ColT> ecolor_prop_;
169  HalfEdgePropertyT<ColT> hecolor_prop_;
170  FacePropertyT<ColT> fcolor_prop_;
171  HalfFacePropertyT<ColT> hfcolor_prop_;
172  CellPropertyT<ColT> ccolor_prop_;
173 
174  TopologyKernel& kernel_;
175 
176  bool vertex_colors_available_;
177  bool halfedge_colors_available_;
178  bool edge_colors_available_;
179  bool halfface_colors_available_;
180  bool face_colors_available_;
181  bool cell_colors_available_;
182 
183  ColT default_color_;
184 
185 };
186 
187 } // Namespace OpenVolumeMesh
188 
189 #if defined(INCLUDE_TEMPLATES) && !defined(COLORATTRIBT_CC)
190 #include "ColorAttribT_impl.hh"
191 #endif
192 
193 #endif /* COLORATTRIB_HH_ */
virtual size_t n_halfedges() const
Get number of halfedges in mesh.
virtual size_t n_halffaces() const
Get number of halffaces in mesh.
virtual size_t n_faces() const
Get number of faces in mesh.
virtual size_t n_cells() const
Get number of cells in mesh.
virtual size_t n_edges() const
Get number of edges in mesh.
virtual size_t n_vertices() const
Get number of vertices in mesh.