H3D API  2.4.1
SuperShape.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 __SUPERSHAPE_H__
30 #define __SUPERSHAPE_H__
31 
32 #include <H3D/X3DGeometryNode.h>
33 #include <H3D/SFFloat.h>
34 #include <H3D/SFInt32.h>
36 #include <H3D/X3DCoordinateNode.h>
37 #include <H3D/CoordBoundField.h>
38 #include <H3D/X3DNormalNode.h>
39 
40 namespace H3D {
41 
62  class H3DAPI_API SuperShape : public X3DGeometryNode {
63  public:
64 
69  Field,
72 
91  class SFCoordinateNode: public TypedField< DependentSFNode< X3DCoordinateNode,
92  FieldRef< X3DGeometricPropertyNode,
93  Field,
94  &X3DCoordinateNode::propertyChanged > >, Types< SFFloat, SFFloat,
95  SFFloat, SFFloat,
96  SFFloat, SFFloat,
97  SFFloat, SFFloat,
98  SFFloat, SFFloat,
99  SFFloat, SFFloat,
100  SFInt32 > > {
102  virtual void update();
103 
104  // Function used internally to define supershape.
105  H3DFloat R( H3DFloat phi, H3DFloat m, H3DFloat a, H3DFloat b,
106  H3DFloat n1, H3DFloat n2, H3DFloat n3 ) {
107  H3DFloat t2 = m*phi/4.0f;
108  H3DFloat t3 = cosf(t2);
109  H3DFloat t6 = H3DAbs(t3/a);
110  H3DFloat t7 = powf(t6,n2);
111  H3DFloat t8 = sinf(t2);
112  H3DFloat t11 = H3DAbs(t8/b);
113  H3DFloat t12 = powf(t11,n3);
114  H3DFloat t14 = powf(t7+t12,-1/n1);
115  return t14;
116  //return powf(powf(fabsf(cosf((alpha*m)/4.)/a), n2)
117  // + powf(fabsf(sinf((alpha*m)/4.)/b),n3), -1/n1);
118  }
119 
120  // Function used internally to define supershape.
121  Vec3f SS( H3DFloat theta, H3DFloat phi, H3DFloat sm, H3DFloat sa,
122  H3DFloat sb, H3DFloat sn1, H3DFloat sn2, H3DFloat sn3,
123  H3DFloat tm, H3DFloat ta, H3DFloat tb, H3DFloat tn1,
124  H3DFloat tn2, H3DFloat tn3 ) {
125  H3DFloat r1theta = R( theta, sm, sa, sb, sn1, sn2, sn3 );
126  H3DFloat r2phi = R( phi, tm, ta, tb, tn1, tn2, tn3 );
127 
128  H3DFloat x = r1theta * cosf(theta) * r2phi * cosf(phi);
129  H3DFloat y = r1theta * sin(theta) * r2phi * cosf(phi);
130  H3DFloat z = r2phi * sin(phi);
131 
132  return Vec3f( x, y, z);
133  }
134  };
135 
138 
139  SuperShape( Inst< SFNode > _metadata = 0,
140  Inst< SFBound > _bound = 0,
141  Inst< SFFloat > _ss1_m = 0,
142  Inst< SFFloat > _ss1_a = 0,
143  Inst< SFFloat > _ss1_b = 0,
144  Inst< SFFloat > _ss1_n1 = 0,
145  Inst< SFFloat > _ss1_n2 = 0,
146  Inst< SFFloat > _ss1_n3 = 0,
147  Inst< SFFloat > _ss2_m = 0,
148  Inst< SFFloat > _ss2_a = 0,
149  Inst< SFFloat > _ss2_b = 0,
150  Inst< SFFloat > _ss2_n1 = 0,
151  Inst< SFFloat > _ss2_n2 = 0,
152  Inst< SFFloat > _ss2_n3 = 0,
153  Inst< SFInt32 > _resolution = 0 );
154 
155  virtual void render();
156 
158  virtual int nrTriangles() {
159  H3DInt32 res = resolution->getValue();
160  if( res < 0 ) return 0;
161  else return res * res * 2;
162  }
163 
164  // Traverse the scenegraph. See X3DGeometryNode::traverseSG
165  // for more info.
166  virtual void traverseSG( TraverseInfo &ti );
167 
168  // Fields
175  H3DUniquePtr< SFFloat > ss1_m;
176 
183  H3DUniquePtr< SFFloat > ss1_a;
184 
191  H3DUniquePtr< SFFloat > ss1_b;
192 
199  H3DUniquePtr< SFFloat > ss1_n1;
200 
207  H3DUniquePtr< SFFloat > ss1_n2;
208 
215  H3DUniquePtr< SFFloat > ss1_n3;
216 
223  H3DUniquePtr< SFFloat > ss2_m;
224 
231  H3DUniquePtr< SFFloat > ss2_a;
232 
239  H3DUniquePtr< SFFloat > ss2_b;
240 
247  H3DUniquePtr< SFFloat > ss2_n1;
248 
255  H3DUniquePtr< SFFloat > ss2_n2;
256 
263  H3DUniquePtr< SFFloat > ss2_n3;
264 
273  H3DUniquePtr< SFInt32 > resolution;
274 
275  static H3DNodeDatabase database;
276  protected:
277 
282  void startTexGen();
283 
285  void stopTexGen();
286 
290  H3DUniquePtr< SFCoordinateNode > coord;
291 
295  H3DUniquePtr< SFNormalNode > normal;
296 
297  };
298 }
299 
300 #endif
Header file for CoordBoundField, specialiced field class.
Contains the DependentSFNode and DependentMFNode template classes.
Contains the SFFloat field class.
Contains the SFInt32 field class.
Header file for X3DCoordinateNode, X3D scene-graph node.
Header file for X3DGeometryNode, X3D scene-graph node.
Header file for X3DNormalNode, X3D scene-graph node.
The CoordBoundField is specialized update itself from a X3DCoordinateNode.
Definition: CoordBoundField.h:43
DependentSFNode are modified TypedSFNode fields where the field dirty status is dependent on fields i...
Definition: DependentNodeFields.h:294
Class used for specifying a field member of a node in a DependentSFNode or DependentMFNode specificat...
Definition: DependentNodeFields.h:48
The Field class.
Definition: Field.h:46
The SFCoordinateNode is a class that contain a X3DCoordinateNode.
Definition: SuperShape.h:100
The SuperShape node implements a SuperShape!
Definition: SuperShape.h:62
H3DUniquePtr< SFFloat > ss2_n2
Parameter to define supershape.
Definition: SuperShape.h:255
H3DUniquePtr< SFFloat > ss2_b
Parameter to define supershape.
Definition: SuperShape.h:239
H3DUniquePtr< SFFloat > ss1_a
Parameter to define supershape.
Definition: SuperShape.h:183
H3DUniquePtr< SFFloat > ss1_n3
Parameter to define supershape.
Definition: SuperShape.h:215
H3DUniquePtr< SFFloat > ss2_a
Parameter to define supershape.
Definition: SuperShape.h:231
DependentSFNode< X3DNormalNode, FieldRef< X3DGeometricPropertyNode, Field, &X3DNormalNode::propertyChanged > > SFNormalNode
The SFNormalNode is dependent on the propertyChanged field of the contained X3DNormalNode.
Definition: SuperShape.h:71
H3DUniquePtr< SFCoordinateNode > coord
Field that contains a Coordinate node with the coordinates generated by SuperShape.
Definition: SuperShape.h:290
H3DUniquePtr< SFFloat > ss1_n1
Parameter to define supershape.
Definition: SuperShape.h:199
H3DUniquePtr< SFFloat > ss1_n2
Parameter to define supershape.
Definition: SuperShape.h:207
H3DUniquePtr< SFNormalNode > normal
Field that contains a Normal node with the normals generated by SuperShape.
Definition: SuperShape.h:295
virtual int nrTriangles()
The number of triangles renderered in this geometry.
Definition: SuperShape.h:158
CoordBoundField SFBound
The bound field for SuperShape is a CoordBoundField.
Definition: SuperShape.h:137
H3DUniquePtr< SFFloat > ss2_n3
Parameter to define supershape.
Definition: SuperShape.h:263
H3DUniquePtr< SFFloat > ss2_m
Parameter to define supershape.
Definition: SuperShape.h:223
H3DUniquePtr< SFFloat > ss2_n1
Parameter to define supershape.
Definition: SuperShape.h:247
H3DUniquePtr< SFInt32 > resolution
Parameter to define the resolution of the supershape.
Definition: SuperShape.h:273
H3DUniquePtr< SFFloat > ss1_m
Parameter to define supershape.
Definition: SuperShape.h:175
H3DUniquePtr< SFFloat > ss1_b
Parameter to define supershape.
Definition: SuperShape.h:191
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
This is the base node type for all geometric property node types defined in X3D.
Definition: X3DGeometricPropertyNode.h:43
H3DUniquePtr< Field > propertyChanged
Field that indicated whether the properties have changed.
Definition: X3DGeometricPropertyNode.h:53
This is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
This is the base node type for all normal node types in X3D.
Definition: X3DNormalNode.h:45
F H3DAbs(F f)
H3DDouble x
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