00001
00002
00003 #include "Iguana/Inventor/interface/IgSoG4Trap.h"
00004 #include <Inventor/nodes/SoIndexedFaceSet.h>
00005 #include <Inventor/nodes/SoVertexProperty.h>
00006
00007
00008
00009
00010
00011
00012
00013
00014 SO_KIT_SOURCE (IgSoG4Trap);
00015
00016
00017
00018
00019
00020 void
00021 IgSoG4Trap::initClass (void)
00022 { SO_KIT_INIT_CLASS (IgSoG4Trap, IgSoShapeKit, "IgSoShapeKit"); }
00023
00024 IgSoG4Trap::IgSoG4Trap (void)
00025 {
00026 SO_KIT_CONSTRUCTOR (IgSoG4Trap);
00027 SO_KIT_ADD_FIELD (dz, (1.0));
00028 SO_KIT_ADD_FIELD (theta, (0.0));
00029 SO_KIT_ADD_FIELD (phi, (0.0));
00030 SO_KIT_ADD_FIELD (dy1, (1.0));
00031 SO_KIT_ADD_FIELD (dx1, (1.0));
00032 SO_KIT_ADD_FIELD (dx2, (1.0));
00033 SO_KIT_ADD_FIELD (dy2, (1.0));
00034 SO_KIT_ADD_FIELD (dx3, (1.0));
00035 SO_KIT_ADD_FIELD (dx4, (1.0));
00036 SO_KIT_ADD_FIELD (alp1, (0.0));
00037 SO_KIT_ADD_FIELD (alp2, (0.0));
00038 SO_KIT_ADD_CATALOG_ENTRY (faces, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00039 SO_KIT_INIT_INSTANCE ();
00040 setUpConnections (true, true);
00041 }
00042
00043 void
00044 IgSoG4Trap::refresh (void)
00045 {
00046
00047 static const int NPOINTS = 8;
00048 static const int NFACES = 6;
00049 static const int NINDICES = NFACES*5;
00050
00051 SoIndexedFaceSet *faces = new SoIndexedFaceSet;
00052 SoVertexProperty *vtx = new SoVertexProperty;
00053 float dy1TAlp1 = dy1.getValue () * tan (alp1.getValue ());
00054 float dy2TAlp2 = dy2.getValue () * tan (alp2.getValue ());
00055 float dzTThetaCPhi = dz.getValue ()
00056 * tan (theta.getValue ())
00057 * cos (phi.getValue ());
00058 float dzTThetaSPhi = dz.getValue ()
00059 * tan (theta.getValue ())
00060 * sin (phi.getValue ());
00061 static const int indices [NINDICES] = { 3,2,1,0, SO_END_FACE_INDEX,
00062 4,5,6,7, SO_END_FACE_INDEX,
00063 0,1,5,4, SO_END_FACE_INDEX,
00064 1,2,6,5, SO_END_FACE_INDEX,
00065 2,3,7,6, SO_END_FACE_INDEX,
00066 3,0,4,7, SO_END_FACE_INDEX };
00067 float points [NPOINTS][3] = {
00068 { dx2.getValue ()+dy1TAlp1 - dzTThetaCPhi, dy1.getValue () - dzTThetaSPhi, -dz.getValue () },
00069 { -dx2.getValue ()+dy1TAlp1 - dzTThetaCPhi, dy1.getValue () - dzTThetaSPhi, -dz.getValue () },
00070 { -dx1.getValue ()-dy1TAlp1 - dzTThetaCPhi, -dy1.getValue () - dzTThetaSPhi, -dz.getValue () },
00071 { dx1.getValue ()-dy1TAlp1 - dzTThetaCPhi, -dy1.getValue () - dzTThetaSPhi, -dz.getValue () },
00072 { dx4.getValue ()+dy2TAlp2 + dzTThetaCPhi, dy2.getValue () + dzTThetaSPhi, dz.getValue () },
00073 { -dx4.getValue ()+dy2TAlp2 + dzTThetaCPhi, dy2.getValue () + dzTThetaSPhi, dz.getValue () },
00074 { -dx3.getValue ()-dy2TAlp2 + dzTThetaCPhi, -dy2.getValue () + dzTThetaSPhi, dz.getValue () },
00075 { dx3.getValue ()-dy2TAlp2 + dzTThetaCPhi, -dy2.getValue () + dzTThetaSPhi, dz.getValue () }
00076 };
00077
00078 for (int i = 0; i < NPOINTS; ++i)
00079 vtx->vertex.set1Value (i, points[i][0], points[i][1], points[i][2]);
00080
00081 for (int i = 0; i < 6; ++i)
00082 {
00083 SbVec3f p0 = vtx->vertex [indices [5*i + 0]];
00084 SbVec3f p1 = vtx->vertex [indices [5*i + 1]];
00085 SbVec3f p2 = vtx->vertex [indices [5*i + 2]];
00086 SbVec3f normal = (p1-p0).cross (p2-p0);
00087 normal.normalize ();
00088 vtx->normal.set1Value (i, normal);
00089 }
00090
00091 vtx->normalBinding = SoVertexProperty::PER_FACE;
00092 faces->coordIndex.setValues (0, NINDICES, indices);
00093 faces->vertexProperty = vtx;
00094
00095
00096 setPart ("faces", faces);
00097 }