OpenVolumeMesh
 All Classes Functions Variables Typedefs Pages
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() < vcolor_prop_.size());
70  return vcolor_prop_[_h.idx()];
71  }
72 
73  ColT& operator[](const VertexHandle& _h) {
74  assert((unsigned int)_h.idx() < kernel_.n_vertices());
75  return vcolor_prop_[_h.idx()];
76  }
77 
78  //==================
79  // Edges
80  //==================
81  const ColT& operator[](const EdgeHandle& _h) const {
82  assert((unsigned int)_h.idx() < ecolor_prop_.size());
83  return ecolor_prop_[_h.idx()];
84  }
85 
86  ColT& operator[](const EdgeHandle& _h) {
87  assert((unsigned int)_h.idx() < kernel_.n_edges());
88  return ecolor_prop_[_h.idx()];
89  }
90 
91  //==================
92  // Half-Edges
93  //==================
94  const ColT& operator[](const HalfEdgeHandle& _h) const {
95  assert((unsigned int)_h.idx() < hecolor_prop_.size());
96  return hecolor_prop_[_h.idx()];
97  }
98 
99  ColT& operator[](const HalfEdgeHandle& _h) {
100  assert((unsigned int)_h.idx() < kernel_.n_halfedges());
101  return hecolor_prop_[_h.idx()];
102  }
103 
104  //==================
105  // Faces
106  //==================
107  const ColT& operator[](const FaceHandle& _h) const {
108  assert((unsigned int)_h.idx() < fcolor_prop_.size());
109  return fcolor_prop_[_h.idx()];
110  }
111 
112  ColT& operator[](const FaceHandle& _h) {
113  assert((unsigned int)_h.idx() < kernel_.n_faces());
114  return fcolor_prop_[_h.idx()];
115  }
116 
117  //==================
118  // Half-Faces
119  //==================
120  const ColT& operator[](const HalfFaceHandle& _h) const {
121  assert((unsigned int)_h.idx() < hfcolor_prop_.size());
122  return hfcolor_prop_[_h.idx()];
123  }
124 
125  ColT& operator[](const HalfFaceHandle& _h) {
126  assert((unsigned int)_h.idx() < kernel_.n_halffaces());
127  return hfcolor_prop_[_h.idx()];
128  }
129 
130  //==================
131  // Cells
132  //==================
133  const ColT& operator[](const CellHandle& _h) const {
134  assert((unsigned int)_h.idx() < ccolor_prop_.size());
135  return ccolor_prop_[_h.idx()];
136  }
137 
138  ColT& operator[](const CellHandle& _h) {
139  assert((unsigned int)_h.idx() < kernel_.n_cells());
140  return ccolor_prop_[_h.idx()];
141  }
142 
143 private:
144 
145  VertexPropertyT<ColT> vcolor_prop_;
146  EdgePropertyT<ColT> ecolor_prop_;
147  HalfEdgePropertyT<ColT> hecolor_prop_;
148  FacePropertyT<ColT> fcolor_prop_;
149  HalfFacePropertyT<ColT> hfcolor_prop_;
150  CellPropertyT<ColT> ccolor_prop_;
151 
152  TopologyKernel& kernel_;
153 };
154 
155 } // Namespace OpenVolumeMesh
156 
157 #if defined(INCLUDE_TEMPLATES) && !defined(COLORATTRIBT_CC)
158 #include "ColorAttribT.cc"
159 #endif
160 
161 #endif /* COLORATTRIB_HH_ */