Debian Codegraph @

vcg/wrap/opensg/vertex_component.h

raw symbols SCIP
1
2
3
4 #ifndef __VCG_OSG_VERTEX_PLUS_COMPONENT
5 #define __VCG_OSG_VERTEX_PLUS_COMPONENT
6
7
8 #include <vector>
9 #include <vcg/space/point3.h>
10 #include <vcg/space/texcoord2.h>
11 #include <vcg/space/color4.h>
12
13 #include <opensg/osggeometry.h>
14
15
16 namespace vcg {
17
18 namespace vert {
19
20 /// Some Naming Rules : All the Components that can be added to a vertex should be defined in the namespace vert:
21
22 /// ------------------------- OPENSGINFO -----------------------------------------
23
24 template< class T > class EmptyOSGInfo : public T { public : OSG::GeometryPtr Geo() { assert(0); return NULL; } };
25
26 template< class T > class OSGInfo : public T
27 {
28 public :
29 OSG::GeometryPtr & Geo() { return _geop; }
30 int & Index() { return _vertexi; }
31 private :
32 OSG::GeometryPtr _geop; /// Maybe we can use pointers to buffers directly but now we really don't now if these pointers change in time ... !!!
33 int _vertexi; /// OSG vertex index
34 };
35
36 /// ------------------------- COORD -----------------------------------------
37
38 /// Core for the coordinate component templated with the coordinate type of the component
39 template< class T > class OSGCoordCore
40 {
41 public :
42 typedef T CoordType;
43 typedef typename CoordType::ValueType ScalarType;
44 OSGCoordCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
45 ~OSGCoordCore() { _vertexindex = -1; }
46 CoordType & operator=( CoordType & p2 )
47 {
48 /// Set coordinates
49 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
50 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
51 pos->setValue( p2, _vertexindex );
52 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
53 return p2; /// Warning : instead of returning the left side operand we return the right one !!!
54 }
55 ScalarType X()
56 {
57 /// Get coordinates
58 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
59 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
60 OSG::Pnt3f p; pos->getValue( p, _vertexindex );
61 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
62 return p.x();
63 }
64 ScalarType Y()
65 {
66 /// Get coordinates
67 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
68 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
69 OSG::Pnt3f p; pos->getValue( p, _vertexindex );
70 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
71 return p.y();
72 }
73 ScalarType Z()
74 {
75 /// Get coordinates
76 OSG::GeoPositions3fPtr pos = OSG::GeoPositions3fPtr::dcast( _geopointer->getPositions() );
77 OSG::beginEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
78 OSG::Pnt3f p; pos->getValue( p, _vertexindex );
79 OSG::endEditCP( pos, OSG::GeoPositions3f::GeoPropDataFieldMask );
80 return p.z();
81 }
82 private :
83 OSG::GeometryPtr _geopointer;
84 int _vertexindex;
85 };
86
87 template< class T > class EmptyOSGCoord : public T
88 {
89 public :
90 typedef OSG::Pnt3f CoordType;
91 typedef OSG::Real32 ScalarType;
92 CoordType & P() { assert(0); return CoordType(); }
93 const CoordType & P() const { assert(0); return CoordType(); }
94 const CoordType & cP() const { assert(0); return CoordType(); }
95 CoordType & UberP() { assert(0); return CoordType(); }
96 static bool HasCoord() { return false; }
97 static void Name( std::vector< std::string > & name ) { T::Name(name); }
98 };
99
100 template< class A, class T > class OSGCoord : public T
101 {
102 public :
103 typedef A CoordType; /// Must be a OSG::Pnt3 type as : OSG::Pnt3s, OSG:Pnt3f, OSG::Pnt3d etc...
104 typedef typename CoordType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc...
105 typedef typename OSGCoordCore< CoordType > CoreType;
106 OSGCoord() { _corep = NULL; }
107 ~OSGCoord() { if( _corep != NULL ) delete _corep; }
108 CoreType & P()
109 {
110 CoreType * tmpcorep = _corep;
111 _corep = new CoreType( Geo(), Index() );
112 if( tmpcorep != NULL ) delete tmpcorep;
113 return *_corep;
114 }
115 static bool HasCoord() { return true; }
116 static void Name( std::vector< std::string > & name ) { name.push_back( std::string("OSGCoord") ); T::Name(name); }
117 private :
118 CoreType * _corep;
119 };
120
121 class OSGCoordCore3f : public OSGCoordCore< OSG::Pnt3f > {};
122
123 template< class T > class OSGCoord3f : public OSGCoord< OSG::Pnt3f, T >
124 { public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGCoord3f" ) ); T::Name(name); } };
125
126
127 /// -------------------------- NORMAL ----------------------------------------
128
129 template< class T > class OSGNormalCore
130 {
131 public :
132 typedef T NormalType;
133 typedef typename NormalType::ValueType ScalarType;
134 OSGNormalCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
135 ~OSGNormalCore() { _vertexindex = -1; }
136 NormalType & operator=( NormalType & n2 )
137 {
138 /// Set coordinates
139 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
140 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
141 norm->setValue( n2, _vertexindex );
142 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
143 return n2; /// Warning : instead of returning the left side operand we return the right one !!!
144 }
145 ScalarType X()
146 {
147 /// Get coordinates
148 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
149 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
150 OSG::Vec3f n; norm->getValue( n, _vertexindex );
151 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
152 return n.x();
153 }
154 ScalarType Y()
155 {
156 /// Get coordinates
157 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
158 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
159 OSG::Vec3f n; norm->getValue( n, _vertexindex );
160 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
161 return n.y();
162 }
163 ScalarType Z()
164 {
165 /// Get coordinates
166 OSG::GeoNormals3fPtr norm = OSG::GeoNormals3fPtr::dcast( _geopointer->getNormals() );
167 OSG::beginEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
168 OSG::Vec3f n; norm->getValue( n, _vertexindex );
169 OSG::endEditCP( norm, OSG::GeoNormals3f::GeoPropDataFieldMask );
170 return n.z();
171 }
172 private :
173 OSG::GeometryPtr _geopointer;
174 int _vertexindex;
175 };
176
177 template< class T > class EmptyOSGNormal : public T
178 {
179 public :
180 typedef OSG::Vec3f NormalType;
181 typedef OSG::Real32 ScalarType;
182 NormalType & N() { assert(0); return NormalType(); }
183 const NormalType cN()const { assert(0); return NormalType(); }
184 static bool HasNormal() { return false; }
185 static bool HasNormalOcc() { return false; }
186 static void Name( std::vector< std::string > & name ) { T::Name(name); }
187 };
188
189 template< class A, class T > class OSGNormal : public T
190 {
191 public :
192 typedef A NormalType; /// Must be a OSG::Vec3 type as : OSG::Vec3s, OSG:Vec3f, OSG::Vec3d etc...
193 typedef typename NormalType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::Int16, OSG::Real32, OSG::Real64 etc...
194 typedef typename OSGNormalCore< NormalType > CoreType;
195 OSGNormal() { _corep = NULL; }
196 ~OSGNormal() { if( _corep == NULL ) delete _corep; }
197 CoreType & N()
198 {
199 CoreType * tmpcorep = _corep;
200 _corep = new CoreType( Geo(), Index() );
201 if( tmpcorep == NULL ) delete tmpcorep;
202 return *_corep;
203 }
204 static bool HasNormal() { return true; }
205 static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal" ) );T::Name(name); }
206 private :
207 CoreType * _corep;
208 };
209
210 class OSGNormalCore3f : public OSGNormalCore< OSG::Vec3f > {};
211
212 template< class T > class OSGNormal3f : public OSGNormal< OSG::Vec3f, T >
213 { public : static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGNormal3f" ) ); T::Name(name); } };
214
215
216 /// -------------------------- COLOR ----------------------------------
217
218 template< class T > class OSGColorCore
219 {
220 public :
221 typedef T ColorType;
222 typedef typename ColorType::ValueType ScalarType;
223 OSGColorCore( OSG::GeometryPtr p, int i ) { _geopointer = p; _vertexindex = i; }
224 ~OSGColorCore() { _vertexindex = -1; }
225 ColorType & operator=( ColorType & c2 )
226 {
227 /// Set color
228 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
229 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
230 colp->setValue( c2, _vertexindex );
231 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
232 return c2; /// Warning : instead of returning the left side operand we return the right one !!!
233 }
234 ScalarType R()
235 {
236 /// Get coordinates
237 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
238 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
239 OSG::Color3f c; colp->getValue( c, _vertexindex );
240 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
241 return c.red();
242 }
243 ScalarType G()
244 {
245 /// Get coordinates
246 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
247 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
248 OSG::Color3f c; colp->getValue( c, _vertexindex );
249 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
250 return c.green();
251 }
252 ScalarType B()
253 {
254 /// Get coordinates
255 OSG::GeoColors3fPtr colp = OSG::GeoColors3fPtr::dcast( _geopointer->getColors() );
256 OSG::beginEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
257 OSG::Color3f c; colp->getValue( c, _vertexindex );
258 OSG::endEditCP( colp, OSG::GeoColors3f::GeoPropDataFieldMask );
259 return c.blue();
260 }
261 private :
262 OSG::GeometryPtr _geopointer;
263 int _vertexindex;
264 };
265
266 template< class T > class EmptyOSGColor : public T
267 {
268 public :
269 typedef OSG::Color3f ColorType;
270 typedef OSG::Real32 ScalarType;
271 ColorType & C() { assert(0); return ColorType(); }
272 static bool HasColor() { return false; }
273 static void Name( std::vector< std::string > & name ) { T::Name(name); }
274 };
275
276 template< class A, class T > class OSGColor : public T
277 {
278 public :
279 typedef A ColorType; /// Must be a OSG::Color3 type as : OSG::Color3ub, OSG:Color3f etc...
280 typedef typename ColorType::ValueType ScalarType; /// Can be a OSG basic type as : OSG::UInt8, OSG::Real32 etc...
281 typedef typename OSGColorCore< ColorType > CoreType;
282 OSGColor() { _corep = NULL; }
283 ~OSGColor() { if( _corep != NULL ) delete _corep; }
284 CoreType & C()
285 {
286 CoreType * tmpcorep = _corep;
287 _corep = new CoreType( Geo(), Index() );
288 if( tmpcorep != NULL ) delete tmpcorep;
289 return *_corep;
290 }
291 static bool HasColor() { return true; }
292 static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor" ) ); T::Name(name); }
293 private :
294 CoreType * _corep;
295 };
296
297 class OSGColorCore3f : public OSGColorCore< OSG::Color3f > {};
298
299 template< class T > class OSGColor3f : public OSGColor< OSG::Color3f, T >
300 { static void Name( std::vector< std::string > & name ) { name.push_back( std::string( "OSGColor3f" ) ); T::Name(name); } };
301
302
303 } /// end namespace vert
304
305 } /// end namespace vcg
306
307
308 #endif
309
310