cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osaOSGImage.h
Go to the documentation of this file.
1 /*
2 
3  Author(s): Simon Leonard
4  Created on: Nov 11 2009
5 
6  (C) Copyright 2008 Johns Hopkins University (JHU), All Rights
7  Reserved.
8 
9 --- begin cisst license - do not edit ---
10 
11 This software is provided "as is" under an open source license, with
12 no warranty. The complete license can be found in license.txt and
13 http://www.cisst.org/cisst/license.txt.
14 
15 --- end cisst license ---
16 */
17 
18 #ifndef _osaOSGImage_h
19 #define _osaOSGImage_h
20 
21 #include <osg/Image>
22 #include <osg/Texture2D>
23 #include <osg/Group>
24 #include <osg/Switch>
25 #include <osg/MatrixTransform>
26 #include <osg/TriangleFunctor>
27 #include <osg/PositionAttitudeTransform>
28 #include <osgUtil/TransformAttributeFunctor>
29 
31 
35 
36 class CISST_EXPORT osaOSGImage : public osg::Group {
37 
38  public:
39 
40  enum Switch{ SWITCH_OFF, SWITCH_ON };
41 
42  protected:
43 
44  // Callback stuff
45 
46  // This is to store a pointer to the image
47  class UserData : public osg::Referenced {
48  private:
49  osg::ref_ptr<osaOSGImage> imagesequence;
50  public:
51  UserData( osaOSGImage* imgseq ) : imagesequence( imgseq ){}
52  osaOSGImage* GetImage() { return imagesequence; }
53  };
54  osg::ref_ptr<osg::Referenced> userdata;
55 
56  // This is used to update the position of the image
57  class TransformCallback : public osg::NodeCallback {
58  public:
60  void operator()( osg::Node* node, osg::NodeVisitor* nv );
61  };
62  // The transform callback
63  osg::ref_ptr<TransformCallback> transformcallback;
64 
66  virtual void UpdateTransform();
67 
68  // The vct transform
70 
71  // The osg transform
72  osg::ref_ptr<osg::MatrixTransform> osgtransform;
73 
74 
75 
76  // This is used to update the position of the image
77  class SwitchCallback : public osg::NodeCallback {
78  public:
80  void operator()( osg::Node* node, osg::NodeVisitor* nv );
81  };
82  // The switch callback
83  osg::ref_ptr<SwitchCallback> switchcallback;
84 
86  virtual void UpdateSwitch();
87 
88  // The switch
90 
91  // The switch
92  osg::ref_ptr< osg::Switch> osgswitch;
93 
94  protected:
95 
96  // in order for the image to update itself at each traversal we need to
97  // a new class and overloads the following methods
98  class Image : public osg::Image {
99 
100  bool requiresUpdateCall() const { return true; }
101 
102  void update( osg::NodeVisitor* ){
103  osg::Referenced* data = getUserData();
104  osaOSGImage::UserData* userdata;
105  userdata = dynamic_cast<osaOSGImage::UserData*>( data );
106 
107  // update the image
108  if( userdata != NULL )
109  { userdata->GetImage()->UpdateImage(); }
110  }
111 
112  };
113 
114 
115  float x, y;
116  float width, height;
117  unsigned char* data;
118  osg::ref_ptr<osg::Image> osgimage;
119  osg::ref_ptr<osg::Texture2D> osgtexture;
120  osg::ref_ptr<osg::StateSet> osgstateset;
121  osg::ref_ptr<osg::Geode> osggeode;
122  osg::ref_ptr<osg::Geometry> osggeom;
123 
124  void Initialize();
125 
126  virtual void UpdateImage(){}
127 
128  public:
129 
131 
140  osaOSGImage( float x,
141  float y,
142  float width,
143  float height,
144  osaOSGWorld* world,
146 
148 
157  osaOSGImage( float x,
158  float y,
159  float width,
160  float height,
161  osaOSGHUD* hud,
163 
165 
174  osaOSGImage( float x,
175  float y,
176  float width,
177  float height,
178  osaOSGWorld* world,
179  const vctFrm3& Rt );
180 
181  ~osaOSGImage();
182 
184  virtual void SetTransform( const vctFrame4x4<double>& Rt );
185  virtual void SetTransform( const vctFrm3& Rt );
186  virtual vctFrm3 GetTransform() const;
187 
188  void SetImage( const osg::Image* image );
189  void SetImage( const std::string& filename );
190 
192  void SwitchOn();
193  void SwitchOff();
194 
195 };
196 
197 #endif
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Definition: osaOSGImage.h:57
osg::ref_ptr< osg::Switch > osgswitch
Definition: osaOSGImage.h:92
osaOSGImage * GetImage()
Definition: osaOSGImage.h:52
UserData(osaOSGImage *imgseq)
Definition: osaOSGImage.h:51
Definition: osaOSGImage.h:47
osg::ref_ptr< osg::StateSet > osgstateset
Definition: osaOSGImage.h:120
osg::ref_ptr< TransformCallback > transformcallback
Definition: osaOSGImage.h:63
osg::ref_ptr< SwitchCallback > switchcallback
Definition: osaOSGImage.h:83
Definition: osaOSGImage.h:98
osg::ref_ptr< osg::Geometry > osggeom
Definition: osaOSGImage.h:122
osg::ref_ptr< osg::Texture2D > osgtexture
Definition: osaOSGImage.h:119
float y
Definition: osaOSGImage.h:115
Typedef for different transformations.
Switch
Definition: osaOSGImage.h:40
unsigned char * data
Definition: osaOSGImage.h:117
Definition: osaOSGImage.h:36
Definition: osaOSGWorld.h:24
Definition: osaOSGHUD.h:15
Switch onoff
Definition: osaOSGImage.h:89
SwitchCallback()
Definition: osaOSGImage.h:79
TransformCallback()
Definition: osaOSGImage.h:59
Definition: osaOSGImage.h:77
osg::ref_ptr< osg::MatrixTransform > osgtransform
Definition: osaOSGImage.h:72
osg::ref_ptr< osg::Geode > osggeode
Definition: osaOSGImage.h:121
osg::ref_ptr< osg::Referenced > userdata
Definition: osaOSGImage.h:54
virtual void UpdateImage()
Definition: osaOSGImage.h:126
osg::ref_ptr< osg::Image > osgimage
Definition: osaOSGImage.h:118
float width
Definition: osaOSGImage.h:116
vctFrame4x4< double > transform
Definition: osaOSGImage.h:69