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

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