H3D API  2.4.1
X3DGeometryNode.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 __X3DGEOMETRYNODE_H__
30 #define __X3DGEOMETRYNODE_H__
31 
32 // H3Dapi includes
33 #include <H3D/X3DChildNode.h>
34 #include <H3D/H3DBoundedObject.h>
36 #include <H3D/MFBool.h>
37 #include <H3D/MFVec3f.h>
38 #include <H3D/H3DOptionNode.h>
39 #include <H3D/MFNode.h>
41 #include <H3D/OpenHapticsOptions.h>
42 
43 // HAPI includes
44 #include <HAPI/HAPIGLShape.h>
45 #include <HAPI/HapticTriangleSet.h>
46 
47 // H3DUtil includes
48 #include <H3DUtil/AutoPtrVector.h>
49 
50 namespace H3D {
51  // forward declaration
52  class H3DShadowObjectNode;
53 
57  class H3DAPI_API X3DGeometryNode :
58  public X3DChildNode,
59  public H3DBoundedObject,
60  public H3DDisplayListObject,
61  public HAPI::HAPIGLShape {
62  public:
64 
70  class H3DAPI_API BugWorkaroundDisplayList:
72  };
73 
76  class H3DAPI_API DisplayList: public BugWorkaroundDisplayList {
77  public:
79  virtual void callList( bool build_list = true );
82  virtual unsigned int cachingDelay();
84  virtual bool usingCaching();
85  };
86 
90  class H3DAPI_API SFBoundTree:
91  public RefCountSField< HAPI::Collision::BinaryBoundTree > {
92  virtual void update();
93  };
94 
96  X3DGeometryNode( Inst< SFNode > _metadata = 0,
97  Inst< SFBound > _bound = 0,
98  Inst< DisplayList > _displayList = 0,
99  Inst< MFBool > _isTouched = 0,
100  Inst< MFVec3f > _force = 0,
101  Inst< MFVec3f > _contactPoint = 0,
102  Inst< MFVec3f > _contactNormal = 0,
103  Inst< MFVec3f > _contactTexCoord = 0,
104  Inst< SFBoundTree > _boundTree = 0,
105  Inst< SFVec3f > _centerOfMass = 0);
106 
111  virtual void traverseSG( TraverseInfo &ti );
112 
119  virtual bool lineIntersect(
120  const Vec3f &from,
121  const Vec3f &to,
122  LineIntersectResult &result );
123 
129  virtual void closestPoint( const Vec3f &p,
130  NodeIntersectResult &result );
131 
139  virtual bool movingSphereIntersect( H3DFloat radius,
140  const Vec3f &from,
141  const Vec3f &to,
142  NodeIntersectResult &result );
143 
146  virtual void glRender() {
147  bool previous_allow = allowingCulling();
148  bool prev_draw = draw_debug_options;
149  allowCulling( false );
150  draw_debug_options = false;
151  displayList->callList( false );
152  draw_debug_options = prev_draw;
153  allowCulling( previous_allow );
154  }
155 
156 
160 
164  inline void useCulling( bool enabled ) {
165  use_culling = enabled;
166  }
167 
169  inline bool usingCulling() {
170  return use_culling;
171  }
172 
176  inline void allowCulling( bool allow ) {
177  allow_culling = allow;
178  }
179 
182  inline void useBackFaceCulling( bool enabled ) {
183  useCulling( enabled );
184  setCullFace( GL_BACK );
185  }
186 
188  inline bool allowingCulling() {
189  return allow_culling;
190  }
191 
194  inline void setCullFace( GLenum face ) {
195  cull_face = face;
196  }
197 
199  inline GLenum getCullFace() {
200  return cull_face;
201  }
202 
207  template< class OptionNodeType >
208  void getOptionNode( OptionNodeType * &option ) {
209  for( MFOptionsNode::const_iterator i = options->begin();
210  i != options->end(); ++i ) {
211  OptionNodeType *_options = dynamic_cast< OptionNodeType * >( *i );
212  if( _options ) {
213  option = _options;
214  return;
215  }
216  }
217  option = NULL;
218  }
219 
225  int getHapticShapeId( unsigned int index );
226 
228  virtual ~X3DGeometryNode();
229 
230 #ifdef HAVE_OPENHAPTICS
235  HAPI::HAPIHapticShape *getOpenGLHapticShape( unsigned int hd_index,
236  H3DSurfaceNode *_surface,
237  const Matrix4f &_transform,
238  int _nr_vertices = -1 );
239 #endif
243  virtual string defaultXMLContainerField() {
244  return "geometry";
245  }
246 
250  virtual bool supportsTangentAttributes() {
251  return false;
252  }
253 
258  virtual void getBound( HAPI::Vec3 &center, HAPI::Vec3& size ) {
259  BoxBound *b = dynamic_cast< BoxBound * >( bound->getValue() );
260  if( b ) {
261  center = b->center->getValue();
262  size = b->size->getValue();
263  } else {
264  HAPIGLShape::getBound( center, size );
265  }
266  }
267 
270  virtual void initialize();
271 
279  H3DUniquePtr< MFBool > isTouched;
280 
285  H3DUniquePtr< MFVec3f > force;
286 
294  H3DUniquePtr< MFVec3f > contactPoint;
295 
304  H3DUniquePtr< MFVec3f > contactTexCoord;
305 
313  H3DUniquePtr< MFVec3f > contactNormal;
314 
319  H3DUniquePtr< SFVec3f > centerOfMass;
320 
323  H3DUniquePtr< SFBoundTree > boundTree;
324 
328  H3DUniquePtr< MFOptionsNode > options;
329 
332 
333  protected:
339 
343  static void cleanUpFunction( void *userdata) {
344  static_cast< X3DGeometryNode * >(userdata)->unref();
345  }
346 
347  inline void renderTexCoordForActiveTexture( const Vec3f &tc ) {
349  }
350 
351  void createAndAddHapticShapes( TraverseInfo &ti,
352  H3DHapticsDevice *hd,
353  H3DInt32 hd_index,
354  OpenHapticsOptions *openhaptics_options );
355 
356  void addDynamicInfoToShape( TraverseInfo &ti,
357  const string &dynamic_mode,
358  HAPI::HAPIHapticShape *shape );
359 
361  vector< pair< int, pair< Matrix4f, H3DTime > > > haptic_shape_ids;
362 
363  bool use_culling, allow_culling;
364  bool draw_debug_options;
365  GLenum cull_face;
366  friend class H3DHapticsDevice;
367 
368  // Variable used to indicate if warning is printed.
369  bool print_negative_scaling_warning;
370 
371  };
372 }
373 
374 #endif
Header file for H3DBoundedObject.
Header file for H3DDisplayListObject.
Header file for H3DOptionNode.
Contains the MFBool field class.
Contains the MFNode class.
Contains the MFVec3f field class.
Header file for OpenHapticsOptions.
Header file for X3DChildNode, X3D scene-graph node.
Header file for X3DTextureCoordinateNode, X3D scene-graph node.
The BoxBound is a Bound class that specifies the bound using an axis-aligned bounding box.
Definition: Bound.h:144
H3DUniquePtr< SFVec3f > center
The center point of the bounding box.
Definition: Bound.h:285
H3DUniquePtr< SFVec3f > size
The size of the bounding box.
Definition: Bound.h:287
This abstract interface is the base class for all node types that include a bounding box.
Definition: H3DBoundedObject.h:42
We use the Field's lazy evaluation mechanisms to manage the GL display lists for rendering,...
Definition: H3DDisplayListObject.h:60
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
Base class for all haptic devices.
Definition: H3DHapticsDevice.h:68
The H3DShadowObjectNode is the base class for all shadow objects for use in the ShadowCaster node.
Definition: H3DShadowObjectNode.h:49
Base class for all surfaces.
Definition: H3DSurfaceNode.h:44
RefCountSField is almost like any SField but it encapsulates a pointer to a RefCountedClass.
Definition: RefCountSField.h:42
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
This is just a dummy class to get around a bug in Visual C++ 7.1 If the X3DGeometry::DisplayList inhe...
Definition: X3DGeometryNode.h:71
Display list is extended in order to set front sidedness of triangles outside the display list.
Definition: X3DGeometryNode.h:76
virtual void callList(bool build_list=true)
Perform front face code outside the display list.
The SFBoundTree constructs a BinaryBoundTree that can be used for collision detection as well as fast...
Definition: X3DGeometryNode.h:91
This is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
H3DUniquePtr< MFVec3f > contactTexCoord
The texture coordinate of last the contact points of the HapticDevices on the geometry.
Definition: X3DGeometryNode.h:304
H3DUniquePtr< SFVec3f > centerOfMass
The field contains center of mass for the object, based on its bounding box.
Definition: X3DGeometryNode.h:319
virtual bool supportsTangentAttributes()
Returns true if this geometry supports the automatic generation of tangents and binormals as FloatVer...
Definition: X3DGeometryNode.h:250
virtual ~X3DGeometryNode()
Destructor.
virtual void glRender()
Function overridden from HAPIGLShape.
Definition: X3DGeometryNode.h:146
H3DUniquePtr< MFVec3f > contactPoint
The last contact points of the HapticDevices on the geometry.
Definition: X3DGeometryNode.h:294
void allowCulling(bool allow)
Control if face culling is allowed or not.
Definition: X3DGeometryNode.h:176
static void cleanUpFunction(void *userdata)
Function sent to HAPIHapticsShape created to allow for deletion of X3DGeometryNode at the correct tim...
Definition: X3DGeometryNode.h:343
virtual string defaultXMLContainerField()
Returns the default xml containerField attribute value.
Definition: X3DGeometryNode.h:243
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DGeometryNode.h:331
AutoRef< Node > shadow_volume
The shadow volume used for this geometry when shadows enabled.
Definition: X3DGeometryNode.h:338
int getHapticShapeId(unsigned int index)
Get a shape id to be used for rendering of this geometry with HLAPI for the given haptics device.
virtual void getBound(HAPI::Vec3 &center, HAPI::Vec3 &size)
Overriden from HAPIGLShape to use the bound field in he X3DGeometryNode.
Definition: X3DGeometryNode.h:258
H3DUniquePtr< MFVec3f > force
The last force delivered by this geometry to the haptics device.
Definition: X3DGeometryNode.h:285
HAPI::HAPIHapticShape * getOpenGLHapticShape(unsigned int hd_index, H3DSurfaceNode *_surface, const Matrix4f &_transform, int _nr_vertices=-1)
Returns a either a HLFeedbackShape or a HLDepthBufferShape with the X3DGeometryNode.
virtual void initialize()
Changes behaviour of X3DGeometryNode to be a thread safe RefCountedClass.
GLenum getCullFace()
Get which face will be culled if culling is enabled.
Definition: X3DGeometryNode.h:199
bool usingCulling()
Returns if face culling is in use or not.
Definition: X3DGeometryNode.h:169
void setCullFace(GLenum face)
Set which side of a polygon to cull.
Definition: X3DGeometryNode.h:194
void getOptionNode(OptionNodeType *&option)
Get the first option node of the type of the pointer given as argument from the renderOptions fieeld ...
Definition: X3DGeometryNode.h:208
virtual bool movingSphereIntersect(H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result)
Detect collision between a moving sphere and the geometry.
virtual void closestPoint(const Vec3f &p, NodeIntersectResult &result)
Find closest point on this geometry to point p.
H3DUniquePtr< MFVec3f > contactNormal
The normal at the last contact points of the HapticDevices on the geometry.
Definition: X3DGeometryNode.h:313
virtual H3DShadowObjectNode * getShadowObject()
Get the H3DShadowObjectNode used to create a shadow volume for this geometry.
vector< pair< int, pair< Matrix4f, H3DTime > > > haptic_shape_ids
identifiers for the shapes geometry.
Definition: X3DGeometryNode.h:361
void useBackFaceCulling(bool enabled)
Enabling/disabling back face culling.
Definition: X3DGeometryNode.h:182
H3DUniquePtr< MFBool > isTouched
Tells if a HapticsDevice has been in contact with the geometry in the last scenegraph loop.
Definition: X3DGeometryNode.h:279
virtual bool lineIntersect(const Vec3f &from, const Vec3f &to, LineIntersectResult &result)
Detect intersection between a line segment and this geometry.
bool allowingCulling()
Returns true if back face culling is allowed, false otherwise.
Definition: X3DGeometryNode.h:188
H3DUniquePtr< MFOptionsNode > options
Contains nodes with options for haptics and graphics rendering.
Definition: X3DGeometryNode.h:328
X3DGeometryNode(Inst< SFNode > _metadata=0, Inst< SFBound > _bound=0, Inst< DisplayList > _displayList=0, Inst< MFBool > _isTouched=0, Inst< MFVec3f > _force=0, Inst< MFVec3f > _contactPoint=0, Inst< MFVec3f > _contactNormal=0, Inst< MFVec3f > _contactTexCoord=0, Inst< SFBoundTree > _boundTree=0, Inst< SFVec3f > _centerOfMass=0)
Constructor.
void useCulling(bool enabled)
This function should be used by the render() function to disable or enable face culling.
Definition: X3DGeometryNode.h:164
H3DUniquePtr< SFBoundTree > boundTree
Contains a tree of the HAPI::GeometryPrimitives that build up the X3DGeometryNode.
Definition: X3DGeometryNode.h:323
virtual void traverseSG(TraverseInfo &ti)
Traverse the scenegraph.
static void renderTexCoordForActiveTexture(const Vec3f &tc)
Render the texture coordinate for all texture units used by the texture in X3DTextureNode::getActiveT...
Definition: X3DTextureCoordinateNode.cpp:75
int H3DInt32
float H3DFloat
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
Used as input to lineIntersect functions.
Definition: Node.h:224
Used as input to intersection functions.
Definition: Node.h:114