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

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