H3D API  2.4.1
VisibilitySensor.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __VISIBILITYSENSOR_H__
30 #define __VISIBILITYSENSOR_H__
31 
33 #include <H3D/SFVec3f.h>
34 #include <GL/glew.h>
35 
36 namespace H3D {
37 
92  class H3DAPI_API VisibilitySensor : public X3DEnvironmentalSensorNode {
93  public:
94 
97  Inst< SFNode > _metadata = 0,
98  Inst< SFVec3f > _center = 0,
99  Inst< SFVec3f > _size = 0,
100  Inst< SFTime > _enterTime = 0,
101  Inst< SFTime > _exitTime = 0,
102  Inst< SFBool > _enabled = 0,
103  Inst< SFBool > _isActive = 0,
104  Inst< SFBool > _viewFrustumMode = 0 );
105 
106  ~VisibilitySensor(){
107  if ( prev_travinfoadr && glIsQuery( queryId ) )
108  glDeleteQueriesARB(1, &queryId );
109  }
113  class H3DAPI_API SetTime: public AutoUpdate< SFBool > {
114  public:
117  virtual void setValue( const bool &b, int _id = 0 ) {
118  SFBool::setValue( b , _id );
119  VisibilitySensor *vs =
120  static_cast< VisibilitySensor * >( getOwner() );
121  if( value )
122  vs->enterTime->setValue( TimeStamp() , vs->id );
123  else
124  vs->exitTime->setValue( TimeStamp() , vs->id );
125  }
126  protected:
129  virtual void update() {
130  SFBool::update();
131  VisibilitySensor *vs =
132  static_cast< VisibilitySensor * >( getOwner() );
133  if( value )
134  vs->enterTime->setValue( TimeStamp() , vs->id );
135  else
136  vs->exitTime->setValue( TimeStamp(), vs->id );
137  }
138  };
139 
140 
141  // traverse func.
142  virtual void traverseSG( TraverseInfo &ti );
143 
148  H3DUniquePtr< SetTime > set_time;
149 
156  H3DUniquePtr< SFBool > viewFrustumMode;
157 
161 
162  // The variable keeping the instance no in a traverseSG
163  int no_instance;
164 
165  // List of NoInstances of visible instances
166  vector < int > list;
167  // The threshold : an object is considered as visible if the no of
168  // visible pixels exceeds the threshold value
169  int visib_pix_no_threshold;
170 
171  // Internal Vectors for previous position, orientation and
172  // center of rotation of viewpoint
173  Vec3f prev_vp_pos;
174  Vec3f can_prev_vp_pos;
175 
178 
179  protected:
180  GLuint queryId;
181 
182  bool queryNoViewFrustum( std::vector<Vec3f> &global_points );
183 
184  bool queryViewFrustum( std::vector<Vec3f> &global_points );
185 
186  };
187 }
188 
189 #endif
Contains the SFVec3f field class.
Header file for X3DEnvironmentalSensorNode, X3D scene-graph node.
virtual void setValue(const bool &v, int id=0)
Set the value of the field.
Definition: SField.h:215
virtual void update()
Make the field up to date given that an event has occured.
Definition: SField.h:181
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
The SetTime class is specialize to set the value of either the inputTrue or inputFalse field in the B...
Definition: VisibilitySensor.h:113
virtual void update()
Sets either the inputTrue or inputFalse field depending on the new value.
Definition: VisibilitySensor.h:129
virtual void setValue(const bool &b, int _id=0)
Sets either the inputTrue or inputFalse field depending on the new value.
Definition: VisibilitySensor.h:117
The VisibilitySensor node detects visibility changes of a rectangular box as the user navigates the w...
Definition: VisibilitySensor.h:92
H3DUniquePtr< SFBool > viewFrustumMode
If true, isActive field will be true as long as the sensor stays within the view frustum without bein...
Definition: VisibilitySensor.h:156
H3DUniquePtr< SetTime > set_time
Sets enterTime if the set_boolean value is set to TRUE.
Definition: VisibilitySensor.h:148
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: VisibilitySensor.h:177
TraverseInfo * prev_travinfoadr
Adress of traverseInfo only interested in adress, what it points to will be invalid.
Definition: VisibilitySensor.h:160
This abstract node type is the base type for all sensors.
Definition: X3DEnvironmentalSensorNode.h:43
H3DUniquePtr< SFTime > enterTime
enterTime
Definition: X3DEnvironmentalSensorNode.h:74
H3DUniquePtr< SFTime > exitTime
exitTime
Definition: X3DEnvironmentalSensorNode.h:80
H3D API namespace.
Definition: Anchor.h:38
The AutoUpdate field is a template to force the BaseField to update itself as soon as an event is rec...
Definition: FieldTemplates.h:130
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194