OpendTect-6_4  6.4
visosg.h
Go to the documentation of this file.
1 #ifndef visosg_h
2 #define visosg_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kristofer Tingdahl
9  Date: Sep 2012
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 
14 -*/
15 
18 #include "refcount.h"
19 #include "visbasemod.h"
20 
21 class Coord3;
22 
23 namespace osg { class Vec3f; class Array; class Referenced; }
24 
25 
26 #define mGetOsgArrPtr(tp,ptr) ((tp) ptr->getDataPointer() )
27 #define mGetOsgVec2Arr(ptr) ((osg::Vec2Array*) ptr )
28 #define mGetOsgVec3Arr(ptr) ((osg::Vec3Array*) ptr )
29 #define mGetOsgVec4Arr(ptr) ((osg::Vec4Array*) ptr )
30 
31 #if defined(visBase_EXPORTS) || defined(VISBASE_EXPORTS) || \
32 defined(uiOSG_EXPORTS) || defined(UIOSG_EXPORTS)
33 //Only available in visBase
34 #include <osg/Vec3>
35 #include <osg/Vec3d>
36 #include <position.h>
37 #include <osg/Vec4>
38 #include <osg/Vec4d>
39 #include <osg/Node>
40 #include <color.h>
41 #include <convert.h>
42 
43 namespace visBase
44 {
45  void unRefOsgPtr(osg::Referenced*);
46  void refOsgPtr(const osg::Referenced*);
47  void unRefAndZeroOsgPtr(osg::Referenced*);
48 }
49 
50 
51 
52 namespace Conv
53 {
54  template <>
55  inline void set( Coord3& _to, const osg::Vec3f& v )
56  { _to.x = v[0]; _to.y=v[1]; _to.z=v[2]; }
57 
58  template <>
59  inline void set( osg::Vec3f& _to, const Coord3& v )
60  { _to.set( (float) v.x, (float) v.y, (float) v.z ); }
61 
62  template <>
63  inline void set( Coord& _to, const osg::Vec2f& v )
64  { _to.x = v[0]; _to.y=v[1]; }
65 
66  template <>
67  inline void set( osg::Vec2f& _to, const Coord& v )
68  { _to.set( (float) v.x, (float) v.y ); }
69 
70  template <>
71  inline void set( Coord3& _to, const osg::Vec3d& v )
72  { _to.x = v[0]; _to.y=v[1]; _to.z=v[2]; }
73 
74  template <>
75  inline void set( osg::Vec3d& _to, const Coord3& v )
76  { _to.set( v.x, v.y, v.z ); }
77 
78 #define mIsOsgVec3Def( pos ) \
79 ( pos[0]<mUdf(float) && pos[1]<mUdf(float) && pos[2]<mUdf(float) )
80 
81 #define mODColVal(val) ( val<=0.0 ? 0 : val>=1.0 ? 255 : mNINT32(255*val) )
82 #define mOsgColValF(val) ( val<=0 ? 0.0f : val>=255 ? 1.0f : float(val)/255 )
83 #define mOsgColValD(val) ( val<=0 ? 0.0 : val>=255 ? 1.0 : double(val)/255 )
84 
85  template <>
86  inline void set( Color& _to, const osg::Vec4f& col )
87  { _to.set( mODColVal(col[0]), mODColVal(col[1]),
88  mODColVal(col[2]), 255-mODColVal(col[3]) ); }
89 
90  template <>
91  inline void set( osg::Vec4f& _to, const Color& col )
92  { _to.set( mOsgColValF(col.r()), mOsgColValF(col.g()),
93  mOsgColValF(col.b()), 1.0f-mOsgColValF(col.t()) ); }
94 
95  template <>
96  inline void set( Color& _to, const osg::Vec4d& col )
97  { _to.set( mODColVal(col[0]), mODColVal(col[1]),
98  mODColVal(col[2]), 255-mODColVal(col[3]) ); }
99 
100  template <>
101  inline void set( osg::Vec4d& _to, const Color& col )
102  { _to.set( mOsgColValD(col.r()), mOsgColValD(col.g()),
103  mOsgColValD(col.b()), 1.0-mOsgColValD(col.t()) ); }
104 
105 } //Namespace conv
106 
107 namespace Values
108 {
109  template<>
110  class Undef<osg::Vec3f>
111  {
112  public:
113  static void setUdf( osg::Vec3f& i ) {}
114  };
115 
116  template<>
117  class Undef<osg::Vec3d>
118  {
119  public:
120  static void setUdf( osg::Vec3d& i ) {}
121  };
122 
123  template<>
124  class Undef<osg::Vec2f>
125  {
126  public:
127  static void setUdf( osg::Vec2f& i ) {}
128  };
129 
130  template<>
131  class Undef<osg::Vec2d>
132  {
133  public:
134  static void setUdf( osg::Vec2d& i ) {}
135  };
136 
137 
138  template<>
139  class Undef<osg::Vec4f>
140  {
141  public:
142  static void setUdf( osg::Vec4f& i ) {}
143  };
144 
145  template<>
146  class Undef<osg::Vec4d>
147  {
148  public:
149  static void setUdf( osg::Vec4d& i ) {}
150  };
151 
152 } //Namespace Values
153 
154 
162 mExpClass(visBase) OneFrameCullDisabler : public osg::NodeCallback
163 {
164 public:
165  OneFrameCullDisabler(osg::Node*);
166  virtual void operator()(osg::Node*,osg::NodeVisitor*);
167 };
168 
169 #define mAttachOneFrameCullDisabler( osgnode ) \
170  osg::ref_ptr<OneFrameCullDisabler> oneframeculldisablerof##osgnode = \
171  new OneFrameCullDisabler( osgnode );
172 
173 
174 #endif
175 
176 #endif
#define mExpClass(module)
Definition: commondefs.h:160
Templatized undefined and initialisation (i.e. null) values.
Definition: color.h:106
FixedString Undef()
Definition: keystrs.h:142
A cartesian coordinate in 2D space.
Definition: coord.h:25
A cartesian coordinate in 3D space.
Definition: coord.h:72
Definition: visannot.h:43
Open Scene Graph.
Definition: visannot.h:29
T & setUdf(T &u)
Definition: undefval.h:262
Color is an RGB color object, with a transparancy. The storage is in a 4-byte integer, similar to Qt.
Definition: color.h:26
Template based type conversion.
Definition: convert.h:24

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019