00001
00002
00003 #include "Iguana/Inventor/interface/IgSoG4Torus.h"
00004 #include <Inventor/nodes/SoNurbsSurface.h>
00005 #include <Inventor/nodes/SoSeparator.h>
00006 #include <Inventor/nodes/SoCoordinate4.h>
00007 #include <Inventor/actions/SoGetBoundingBoxAction.h>
00008
00009
00010
00011 #define SO_TORUS_U_DIM 7
00012 #define SO_TORUS_V_DIM 7
00013 #define SO_TORUS_U_ORDER 3
00014 #define SO_TORUS_V_ORDER 3
00015
00016
00017
00018 const int NPTS = SO_TORUS_U_DIM * SO_TORUS_V_DIM;
00019 const float u_knot_vals [] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
00020 const float v_knot_vals [] = {0, 0, 0, 1, 1, 2, 2, 3, 3, 3};
00021
00022
00023
00024
00025
00026
00027 SO_KIT_SOURCE (IgSoG4Torus);
00028
00029
00030
00031
00032
00033 void
00034 IgSoG4Torus::initClass (void)
00035 { SO_KIT_INIT_CLASS (IgSoG4Torus, IgSoShapeKit, "IgSoShapeKit"); }
00036
00037 IgSoG4Torus::IgSoG4Torus (void)
00038 {
00039 SO_KIT_CONSTRUCTOR (IgSoG4Torus);
00040 SO_KIT_ADD_FIELD (minRadius, (0.f));
00041 SO_KIT_ADD_FIELD (maxRadius, (1.f));
00042 SO_KIT_ADD_FIELD (phiStart, (0.0));
00043 SO_KIT_ADD_FIELD (phiDelta, (2 * M_PI));
00044 SO_KIT_ADD_CATALOG_ENTRY (torus, SoSeparator, FALSE, separator,\x0, TRUE);
00045 SO_KIT_INIT_INSTANCE ();
00046 setUpConnections (true, true);
00047 }
00048
00049 void
00050 IgSoG4Torus::refresh (void)
00051 {
00052 SoSeparator *torSeparator = new SoSeparator;
00053 SoCoordinate4 *torCoordinate4 = new SoCoordinate4;
00054 torCoordinate4->point.setNum (NPTS);
00055 torSeparator->addChild (torCoordinate4);
00056
00057
00058 SoNurbsSurface *torSurface = new SoNurbsSurface;
00059 torSurface->numUControlPoints.setValue (SO_TORUS_U_DIM);
00060 torSurface->numVControlPoints.setValue (SO_TORUS_V_DIM);
00061 torSurface->uKnotVector.setValues (0, SO_TORUS_U_DIM + SO_TORUS_U_ORDER, u_knot_vals);
00062 torSurface->vKnotVector.setValues (0, SO_TORUS_V_DIM + SO_TORUS_V_ORDER, v_knot_vals);
00063 torSeparator->addChild (torSurface);
00064
00065 int iu, iv, i;
00066 double angleU, angleV;
00067
00068
00069 double weight, weightU, weightV;
00070 SbVec3f cpt;
00071 SbRotation rotator;
00072
00073
00074 for (iv = 0, angleV = 0; iv < SO_TORUS_V_DIM; ++iv, angleV += M_PI/3)
00075 {
00076 rotator.setValue (SbVec3f (0, 0, 1), (float) angleV);
00077 if (iv % 2 == 1)
00078 {
00079 weightV = 0.5;
00080 }
00081 else
00082 {
00083 weightV = 1;
00084 }
00085 for (iu = 0, angleU = 0; iu < SO_TORUS_U_DIM; ++iu, angleU -= M_PI/3)
00086 {
00087
00088 i = iu + iv * SO_TORUS_U_DIM;
00089 if (iu % 2 == 1)
00090 {
00091 weightU = 0.5;
00092 }
00093 else
00094 {
00095 weightU = 1;
00096 }
00097
00098 weight = weightU * weightV;
00099 cpt = SbVec3f (maxRadius.getValue (), 0, 0) / (float) weightV +
00100 SbVec3f ((float)(minRadius.getValue () * cos (angleU) / weight),
00101 0,
00102 (float)(minRadius.getValue () * sin (angleU) / weightU));
00103 rotator.multVec (cpt, cpt);
00104 cpt *= (float) weight;
00105 torCoordinate4->point.set1Value (i, cpt [0], cpt [1], cpt [2], (float) weight);
00106 }
00107 }
00108
00109 setPart ("torus", torSeparator);
00110 }