H3D API  2.4.1
HAnimDisplacer.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 __HANIMDISPLACER_H__
30 #define __HANIMDISPLACER_H__
31 
33 #include <H3D/MFVec3f.h>
34 #include <H3D/MFInt32.h>
35 #include <H3D/SFString.h>
36 #include <H3D/SFFloat.h>
37 
38 
39 namespace H3D {
40 
66  class H3DAPI_API HAnimDisplacer : public X3DGeometricPropertyNode {
67  public:
69  HAnimDisplacer( Inst< SFNode > _metadata = 0,
70  Inst< MFInt32 > _coordIndex = 0,
71  Inst< MFVec3f > _displacements = 0,
72  Inst< SFString > _name = 0,
73  Inst< SFFloat > _weight = 0 );
74 
80  template< class VectorType >
81  inline void displaceCoordinates( VectorType &points,
82  const Matrix4f &displace_transform );
83 
90  H3DUniquePtr< MFInt32 > coordIndex;
91 
103  H3DUniquePtr< MFVec3f > displacements;
104 
112  H3DUniquePtr< SFString > name;
113 
120  H3DUniquePtr< SFFloat > weight;
121 
124  };
125 
126  template< class VectorClass >
127  void HAnimDisplacer::displaceCoordinates( VectorClass &points,
128  const Matrix4f &displace_transform) {
129  const vector< Vec3f > &displace = displacements->getValue();
130  const vector< int > &indices = coordIndex->getValue();
131  H3DFloat w = weight->getValue();
132 
133  // if weight is 0 this displacer adds nothing.
134  if( w == 0 ) return;
135 
136  size_t p_size = points.size();
137  size_t d_size = displace.size();
138 
139  for( size_t i = 0; i < indices.size(); ++i ) {
140  int index = indices[i];
141  if( (unsigned int) index < p_size && i < d_size) {
142  Vec4f point_displacement = displace_transform * Vec4f( displace[i].x, displace[i].y, displace[i].z, 0 ) ;
143  points[index] = w * (Vec3f(point_displacement.x,
144  point_displacement.y,
145  point_displacement.z ) ) + points[index];
146  }
147  }
148  }
149 
150 }
151 
152 #endif
Contains the MFInt32 field class.
Contains the MFVec3f field class.
Contains the SFFloat field class.
Contains the SFString field class.
Header file for X3DGeometricPropertyNode, X3D scene-graph node.
Applications may need to alter the shape of individual segments.
Definition: HAnimDisplacer.h:66
H3DUniquePtr< SFFloat > weight
The displacements shall be uniformly scaled by the value of the weight field.
Definition: HAnimDisplacer.h:120
H3DUniquePtr< SFString > name
The name field contains a name that is used for identifying the object.
Definition: HAnimDisplacer.h:112
H3DUniquePtr< MFVec3f > displacements
The displacements field, if present, provides a set of 3D values that are added to the neutral or res...
Definition: HAnimDisplacer.h:103
void displaceCoordinates(VectorType &points, const Matrix4f &displace_transform)
Displaces the coordinates in points according to the HAnimDisplacer fields.
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HAnimDisplacer.h:123
H3DUniquePtr< MFInt32 > coordIndex
The coordIndex field contains the indices into the coordinate array for the mesh of the vertices that...
Definition: HAnimDisplacer.h:90
This is the base node type for all geometric property node types defined in X3D.
Definition: X3DGeometricPropertyNode.h:43
H3DDouble x
Vec4f()
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