H3D API  2.4.1
DeformableShape.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 __DEFORMABLESHAPE_H__
30 #define __DEFORMABLESHAPE_H__
31 
32 #include <H3D/X3DShapeNode.h>
33 #include <H3D/Coordinate.h>
36 
37 namespace H3D {
38 
67  class H3DAPI_API DeformableShape : public X3DShapeNode {
68  public:
71 
75  public:
81  value = NULL;
82  }
83 
84  protected:
85  virtual void onAdd( Node *n ) {
87  dynamic_cast< X3DComposedGeometryNode * >( n );
88  if( !cg ) {
89  stringstream s;
90  s << "Expecting X3DComposedGeometryNode";
91  throw InvalidNodeType( n->getTypeName(),
92  s.str(),
94  }
95 
97  DeformableShape *dg =
98  static_cast< DeformableShape * >( getOwner() );
99  if( n ) {
100  Coordinate *cg_coord =
101  dynamic_cast< Coordinate * >( cg->coord->getValue() );
102  Coordinate *dg_orig_coord = dg->origCoord->getValue();
103  Coordinate *dg_deformed_coord = dg->deformedCoord->getValue();
104  Coordinate *dg_resting_coord = dg->restingCoord->getValue();
105  if( cg_coord ) {
106  if( dg_orig_coord ) {
107  dg_orig_coord->point->setValue( cg_coord->point->getValue() );
108  }
109  if( dg_deformed_coord ) {
110  dg_deformed_coord->point->setValue( cg_coord->point->getValue() );
111  }
112  if( dg_resting_coord ) {
113  dg_resting_coord->point->setValue( cg_coord->point->getValue() );
114  }
115  }
116  }
117  }
118  };
119 
121  DeformableShape( Inst< SFAppearanceNode > _appearance = 0,
122  Inst< SFGeometryNode > _geometry = 0,
123  Inst< SFHapticGeometry > _hapticGeometry = 0,
124  Inst< SFNode > _metadata = 0,
125  Inst< SFBound > _bound = 0,
126  Inst< SFVec3f > _bboxCenter = 0,
127  Inst< SFVec3f > _bboxSize = 0,
128  Inst< SFCoordinateNode > _origCoord = 0,
129  Inst< SFCoordinateNode > _restingCoord = 0,
130  Inst< SFCoordinateNode > _deformedCoor = 0,
131  Inst< SFCoordinateDeformer > _deformer = 0 );
132 
137  virtual void traverseSG( TraverseInfo &ti );
138 
145  H3DUniquePtr< SFCoordinateNode > origCoord;
146 
152  H3DUniquePtr< SFCoordinateNode > restingCoord;
153 
159  H3DUniquePtr< SFCoordinateNode > deformedCoord;
160 
166  H3DUniquePtr< SFCoordinateDeformer > deformer;
167 
170 
171  protected:
172  TraverseInfo *last_ti;
173 
174  };
175 }
176 
177 #endif
Header file for Coordinate, X3D scene-graph node.
#define H3D_FULL_LOCATION
Header file for H3DCoordinateDeformerNode.
Header file for X3DComposedGeometryNode, X3D scene-graph node.
Header file for X3DShapeNode, X3D scene-graph node.
std::string getTypeName() const
This node defines a set of 3D coordinates to be used in the coord field of vertex-based geometry node...
Definition: Coordinate.h:50
H3DUniquePtr< MFVec3f > point
A vector of Vec3f defining points in 3d-space.
Definition: Coordinate.h:99
The SFGeometryNode is extended to only accept X3DComposedGeometryNode nodes.
Definition: DeformableShape.h:74
~SFGeometryNode()
Destructor.
Definition: DeformableShape.h:80
virtual void onAdd(Node *n)
This function will be called when the value of RefCountField changes.
Definition: DeformableShape.h:85
The DeformableShape is an X3DShapeNode which makes it possible to deform the geometry of the shape wh...
Definition: DeformableShape.h:67
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: DeformableShape.h:169
H3DUniquePtr< SFCoordinateNode > deformedCoord
The deformedCoord field contains the coordinates after deformation of current contacts of haptics dev...
Definition: DeformableShape.h:159
H3DUniquePtr< SFCoordinateNode > restingCoord
The restingCoord fields contain the coordinates that the geometry will go back to when there are no c...
Definition: DeformableShape.h:152
H3DUniquePtr< SFCoordinateNode > origCoord
The origCoord field contains the coordinates that the X3DComposedGeometryNode had when it was added t...
Definition: DeformableShape.h:145
H3DUniquePtr< SFCoordinateDeformer > deformer
The deformer field specifies an H3DCoordinateDeformerNode that determines how the coordinates should ...
Definition: DeformableShape.h:166
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
This is the base node type for all composed 3D geometry in X3D.
Definition: X3DComposedGeometryNode.h:93
H3DUniquePtr< SFCoordinateNode > coord
An X3DCoordinate node with the coordinates to use.
Definition: X3DComposedGeometryNode.h:232
SFGeometryNode is dependent on the displayList field of its encapsulated X3DGeometryNode node,...
Definition: X3DShapeNode.h:76
virtual void onAdd(Node *n)
This function will be called when the value of RefCountField changes.
Definition: X3DShapeNode.h:99
This is the base node type for all Shape nodes.
Definition: X3DShapeNode.h:50
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