Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/SoTrd.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenInventor/src/SoTrd.cc (Version 11.3.0) and /visualization/OpenInventor/src/SoTrd.cc (Version 10.3.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
                                                   >>  28 // $Id: SoTrd.cc 66373 2012-12-18 09:41:34Z gcosmo $
 28 //                                                 29 //
 29 /*-----------------------------HEPVis---------     30 /*-----------------------------HEPVis---------------------------------------*/
 30 /*                                                 31 /*                                                                          */
 31 /* Node:             SoTrd                         32 /* Node:             SoTrd                                                  */
 32 /* Description:      Represents the G4Trd Gean     33 /* Description:      Represents the G4Trd Geant Geometry entity             */
 33 /* Author:           Joe Boudreau Nov 11 1996      34 /* Author:           Joe Boudreau Nov 11 1996                               */
 34 /*                                                 35 /*                                                                          */
 35 /*--------------------------------------------     36 /*--------------------------------------------------------------------------*/
 36                                                    37 
                                                   >>  38 #ifdef G4VIS_BUILD_OI_DRIVER
                                                   >>  39 
 37 #include <assert.h>                                40 #include <assert.h>
 38 #include <cmath>                                   41 #include <cmath>
 39                                                    42 
 40 #include <Inventor/SbBox.h>                        43 #include <Inventor/SbBox.h>
 41 #include <Inventor/actions/SoAction.h>             44 #include <Inventor/actions/SoAction.h>
 42 #include <Inventor/fields/SoSFFloat.h>             45 #include <Inventor/fields/SoSFFloat.h>
 43 #include <Inventor/misc/SoChildList.h>             46 #include <Inventor/misc/SoChildList.h>
 44 #include <Inventor/nodes/SoSeparator.h>            47 #include <Inventor/nodes/SoSeparator.h>
 45 #include <Inventor/nodes/SoIndexedFaceSet.h>       48 #include <Inventor/nodes/SoIndexedFaceSet.h>
 46 #include <Inventor/nodes/SoNormal.h>               49 #include <Inventor/nodes/SoNormal.h>
 47 #include <Inventor/nodes/SoCoordinate3.h>          50 #include <Inventor/nodes/SoCoordinate3.h>
 48 #include <Inventor/nodes/SoNormalBinding.h>        51 #include <Inventor/nodes/SoNormalBinding.h>
 49 #include <Inventor/SoPrimitiveVertex.h>            52 #include <Inventor/SoPrimitiveVertex.h>
 50 #include <Inventor/elements/SoTextureCoordinat     53 #include <Inventor/elements/SoTextureCoordinateElement.h>
 51                                                    54 
 52 #include "HEPVis/SbMath.h"                         55 #include "HEPVis/SbMath.h"
 53 #include "HEPVis/nodes/SoTrd.h"                    56 #include "HEPVis/nodes/SoTrd.h"
 54                                                    57 
 55 // This statement is required                      58 // This statement is required
 56 SO_NODE_SOURCE(SoTrd)                              59 SO_NODE_SOURCE(SoTrd)
 57                                                    60 
 58 // initClass                                       61 // initClass
 59 void SoTrd::initClass(){                           62 void SoTrd::initClass(){
 60   static bool first = true;                    <<  63   SO_NODE_INIT_CLASS(SoTrd,SoShape,"Shape");
 61   if (first) {                                 << 
 62     first = false;                             << 
 63     SO_NODE_INIT_CLASS(SoTrd,SoShape,"Shape"); << 
 64   }                                            << 
 65 }                                                  64 }
 66 // Constructor                                     65 // Constructor
 67 SoTrd::SoTrd() {                                   66 SoTrd::SoTrd() {
 68   // This statement is required                    67   // This statement is required
 69   SO_NODE_CONSTRUCTOR(SoTrd);                      68   SO_NODE_CONSTRUCTOR(SoTrd);
 70   // Data fields are initialized like this:        69   // Data fields are initialized like this:
 71   SO_NODE_ADD_FIELD(fDx1,(1.0));                   70   SO_NODE_ADD_FIELD(fDx1,(1.0));
 72   SO_NODE_ADD_FIELD(fDx2,(1.0));                   71   SO_NODE_ADD_FIELD(fDx2,(1.0));
 73   SO_NODE_ADD_FIELD(fDy1,(1.0));                   72   SO_NODE_ADD_FIELD(fDy1,(1.0));
 74   SO_NODE_ADD_FIELD(fDy2,(1.0));                   73   SO_NODE_ADD_FIELD(fDy2,(1.0));
 75   SO_NODE_ADD_FIELD(fDz,(1.0));                    74   SO_NODE_ADD_FIELD(fDz,(1.0));
 76   SO_NODE_ADD_FIELD(alternateRep,(NULL));          75   SO_NODE_ADD_FIELD(alternateRep,(NULL));
 77   children = new SoChildList(this);                76   children = new SoChildList(this);
 78 }                                                  77 }
 79 // Destructor                                      78 // Destructor
 80 SoTrd::~SoTrd() {                                  79 SoTrd::~SoTrd() {
 81   delete children;                                 80   delete children;
 82 }                                                  81 }
 83 // generatePrimitives                              82 // generatePrimitives
 84 void SoTrd::generatePrimitives(SoAction *actio     83 void SoTrd::generatePrimitives(SoAction *action) {
 85   // This variable is used to store each verte     84   // This variable is used to store each vertex
 86   SoPrimitiveVertex pv;                            85   SoPrimitiveVertex pv;
 87                                                    86 
 88   // Access the stat from the action               87   // Access the stat from the action
 89   SoState *state = action->getState();             88   SoState *state = action->getState();
 90                                                    89 
 91   // See if we have to use a texture coordinat     90   // See if we have to use a texture coordinate function,
 92   // rather than generating explicit texture c     91   // rather than generating explicit texture coordinates.
 93   SbBool useTexFunction=                           92   SbBool useTexFunction=
 94     (SoTextureCoordinateElement::getType(state     93     (SoTextureCoordinateElement::getType(state) == 
 95      SoTextureCoordinateElement::FUNCTION);        94      SoTextureCoordinateElement::FUNCTION);
 96                                                    95 
 97   // If we need to generate texture coordinate     96   // If we need to generate texture coordinates with a function,
 98   // we'll need an SoGLTextureCoordinateElemen     97   // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
 99   // set up the coordinates directly.              98   // set up the coordinates directly.
100   const SoTextureCoordinateElement *tce = NULL     99   const SoTextureCoordinateElement *tce = NULL;
101   SbVec4f texCoord;                               100   SbVec4f texCoord;
102   if (useTexFunction) {                           101   if (useTexFunction) {
103     tce = SoTextureCoordinateElement::getInsta    102     tce = SoTextureCoordinateElement::getInstance(state);
104   }                                               103   }
105   else {                                          104   else {
106     texCoord[2] = 0.0;                            105     texCoord[2] = 0.0;
107     texCoord[3] = 1.0;                            106     texCoord[3] = 1.0;
108   }                                               107   }
109   SbVec3f point, normal;                          108   SbVec3f point, normal;
110                                                   109 
111                                                   110 
112   //////////////////////////////////////////      111   //////////////////////////////////////////
113   //----------------------------------------      112   //----------------------------------------
114 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \      113 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
115   point.setValue(x,y,z);                   \      114   point.setValue(x,y,z);                   \
116   normal.setValue(nx,ny,nz);               \      115   normal.setValue(nx,ny,nz);               \
117   if (useTexFunction) {                    \      116   if (useTexFunction) {                    \
118     texCoord=tce->get(point,normal);       \      117     texCoord=tce->get(point,normal);       \
119   }                                        \      118   }                                        \
120   else {                                   \      119   else {                                   \
121     texCoord[0]=s;                         \      120     texCoord[0]=s;                         \
122     texCoord[1]=t;                         \      121     texCoord[1]=t;                         \
123   }                                        \      122   }                                        \
124   pv.setPoint(point);                      \      123   pv.setPoint(point);                      \
125   pv.setNormal(normal);                    \      124   pv.setNormal(normal);                    \
126   pv.setTextureCoords(texCoord);           \      125   pv.setTextureCoords(texCoord);           \
127   shapeVertex(&pv);                               126   shapeVertex(&pv);
128   //----------------------------------------      127   //----------------------------------------
129   //////////////////////////////////////////      128   //////////////////////////////////////////
130                                                   129 
131   const int NPOINTS=8, NFACES=6, NINDICES = NF    130   const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
132   int indices[NINDICES] = {3,2,1,0, SO_END_FAC    131   int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,  //z back.
133          4,5,6,7, SO_END_FACE_INDEX,  //z fron    132          4,5,6,7, SO_END_FACE_INDEX,  //z front.
134          0,1,5,4, SO_END_FACE_INDEX,  //y up.     133          0,1,5,4, SO_END_FACE_INDEX,  //y up.
135          1,2,6,5, SO_END_FACE_INDEX,  //x left    134          1,2,6,5, SO_END_FACE_INDEX,  //x left.
136          2,3,7,6, SO_END_FACE_INDEX,  //y down    135          2,3,7,6, SO_END_FACE_INDEX,  //y down.
137          3,0,4,7, SO_END_FACE_INDEX}; //x righ    136          3,0,4,7, SO_END_FACE_INDEX}; //x right.
138                                                   137 
139                                                   138   
140   // points for the eight vertices                139   // points for the eight vertices
141   float points[NPOINTS][3];                       140   float points[NPOINTS][3];
142   points[0][0] =  fDx1.getValue();                141   points[0][0] =  fDx1.getValue(); 
143   points[0][1] =  fDy1.getValue();                142   points[0][1] =  fDy1.getValue(); 
144   points[0][2] = -fDz.getValue();                 143   points[0][2] = -fDz.getValue();
145                                                   144 
146   points[1][0] = -fDx1.getValue();                145   points[1][0] = -fDx1.getValue();
147   points[1][1] =  fDy1.getValue();                146   points[1][1] =  fDy1.getValue();
148   points[1][2] = -fDz.getValue();                 147   points[1][2] = -fDz.getValue();
149                                                   148 
150   points[2][0] = -fDx1.getValue();                149   points[2][0] = -fDx1.getValue(); 
151   points[2][1] = -fDy1.getValue();                150   points[2][1] = -fDy1.getValue(); 
152   points[2][2] = -fDz.getValue();                 151   points[2][2] = -fDz.getValue();
153                                                   152 
154   points[3][0] =  fDx1.getValue();                153   points[3][0] =  fDx1.getValue(); 
155   points[3][1] = -fDy1.getValue();                154   points[3][1] = -fDy1.getValue(); 
156   points[3][2] = -fDz.getValue();                 155   points[3][2] = -fDz.getValue();
157                                                   156 
158   points[4][0] =  fDx2.getValue();                157   points[4][0] =  fDx2.getValue(); 
159   points[4][1] =  fDy2.getValue();                158   points[4][1] =  fDy2.getValue(); 
160   points[4][2] =  fDz.getValue();                 159   points[4][2] =  fDz.getValue();
161                                                   160 
162   points[5][0] = -fDx2.getValue();                161   points[5][0] = -fDx2.getValue(); 
163   points[5][1] =  fDy2.getValue();                162   points[5][1] =  fDy2.getValue(); 
164   points[5][2] =  fDz.getValue();                 163   points[5][2] =  fDz.getValue();
165                                                   164 
166   points[6][0] = -fDx2.getValue();                165   points[6][0] = -fDx2.getValue(); 
167   points[6][1] = -fDy2.getValue();                166   points[6][1] = -fDy2.getValue(); 
168   points[6][2] =  fDz.getValue();                 167   points[6][2] =  fDz.getValue();
169                                                   168 
170   points[7][0] =  fDx2.getValue();                169   points[7][0] =  fDx2.getValue(); 
171   points[7][1] = -fDy2.getValue();                170   points[7][1] = -fDy2.getValue(); 
172   points[7][2] =  fDz.getValue();                 171   points[7][2] =  fDz.getValue();
173                                                   172 
174   float t1  = FATAN((fDx2.getValue()-fDx1.getV    173   float t1  = FATAN((fDx2.getValue()-fDx1.getValue())/(2*fDz.getValue()));
175   float t2  = FATAN((fDy2.getValue()-fDy1.getV    174   float t2  = FATAN((fDy2.getValue()-fDy1.getValue())/(2*fDz.getValue()));
176   float st1 = FSIN(t1);                           175   float st1 = FSIN(t1);
177   float st2 = FSIN(t2);                           176   float st2 = FSIN(t2);
178   float ct1 = FCOS(t1);                           177   float ct1 = FCOS(t1);
179   float ct2 = FCOS(t2);                           178   float ct2 = FCOS(t2);
180                                                   179 
181   float normals[NFACES][3];                       180   float normals[NFACES][3];
182   //z back.                                       181   //z back.
183   normals[0][0] = 0   ; normals[0][1] =    0;     182   normals[0][0] = 0   ; normals[0][1] =    0; normals [0][2] =  -1;    
184   //z front.                                      183   //z front.
185   normals[1][0] = 0   ; normals[1][1] =    0;     184   normals[1][0] = 0   ; normals[1][1] =    0; normals [1][2] =   1;    
186   //y up.                                         185   //y up.
187   normals[2][0] = 0   ; normals[2][1] =  ct2;     186   normals[2][0] = 0   ; normals[2][1] =  ct2; normals [2][2] = -st2;    
188   //x left.                                       187   //x left.
189   normals[3][0] = -ct1; normals[3][1] =    0;     188   normals[3][0] = -ct1; normals[3][1] =    0; normals [3][2] = -st1;    
190   //y down.                                       189   //y down.
191   normals[4][0] = 0   ; normals[4][1] = -ct2;     190   normals[4][0] = 0   ; normals[4][1] = -ct2; normals [4][2] = -st2;    
192   //x right.                                      191   //x right.
193   normals[5][0] =  ct1; normals[5][1] =    0;     192   normals[5][0] =  ct1; normals[5][1] =    0; normals [5][2] = -st1;    
194                                                   193 
195   float x,y,z;                                    194   float x,y,z;
196   int   index;                                    195   int   index;
197   for (int nf=0;nf<NFACES;nf++) {                 196   for (int nf=0;nf<NFACES;nf++) {
198     beginShape(action,TRIANGLE_FAN);              197     beginShape(action,TRIANGLE_FAN);
199     index = indices[nf * 5];                      198     index = indices[nf * 5];   
200     x = points[index][0];                         199     x = points[index][0];
201     y = points[index][1];                         200     y = points[index][1];
202     z = points[index][2];                         201     z = points[index][2];
203     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    202     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
204     index = indices[nf * 5 + 1];                  203     index = indices[nf * 5 + 1];   
205     x = points[index][0];                         204     x = points[index][0];
206     y = points[index][1];                         205     y = points[index][1];
207     z = points[index][2];                         206     z = points[index][2];
208     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    207     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
209     index = indices[nf * 5 + 2];                  208     index = indices[nf * 5 + 2];   
210     x = points[index][0];                         209     x = points[index][0];
211     y = points[index][1];                         210     y = points[index][1];
212     z = points[index][2];                         211     z = points[index][2];
213     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    212     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
214     index = indices[nf * 5 + 3];                  213     index = indices[nf * 5 + 3];   
215     x = points[index][0];                         214     x = points[index][0];
216     y = points[index][1];                         215     y = points[index][1];
217     z = points[index][2];                         216     z = points[index][2];
218     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    217     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
219     endShape();                                   218     endShape();
220   }                                               219   }
221 }                                                 220 }
222                                                   221 
223 // getChildren                                    222 // getChildren
224 SoChildList *SoTrd::getChildren() const {         223 SoChildList *SoTrd::getChildren() const {
225   return children;                                224   return children;
226 }                                                 225 }
227                                                   226 
228                                                   227 
229 // computeBBox                                    228 // computeBBox
230 void SoTrd::computeBBox(SoAction *, SbBox3f &b    229 void SoTrd::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
231   float fDx= fDx1.getValue(),fDy=fDy1.getValue    230   float fDx= fDx1.getValue(),fDy=fDy1.getValue();
232                                                   231   
233   if (fDx2.getValue() > fDx) fDx = fDx2.getVal    232   if (fDx2.getValue() > fDx) fDx = fDx2.getValue(); 
234   if (fDy2.getValue() > fDy) fDy = fDy2.getVal    233   if (fDy2.getValue() > fDy) fDy = fDy2.getValue(); 
235                                                   234 
236   SbVec3f vmin(-fDx,-fDy,-fDz.getValue()),        235   SbVec3f vmin(-fDx,-fDy,-fDz.getValue()), 
237           vmax( fDx, fDy, fDz.getValue());        236           vmax( fDx, fDy, fDz.getValue());
238                                                   237 
239   center.setValue(0,0,0);                         238   center.setValue(0,0,0);
240   box.setBounds(vmin,vmax);                       239   box.setBounds(vmin,vmax);
241 }                                                 240 }
242                                                   241 
243                                                   242 
244                                                   243 
245                                                   244 
246 // updateChildren                                 245 // updateChildren
247 void SoTrd::updateChildren() {                    246 void SoTrd::updateChildren() {
248                                                   247 
249                                                   248 
250   // Redraw the G4Trd....                         249   // Redraw the G4Trd....
251                                                   250 
252   assert(children->getLength()==1);               251   assert(children->getLength()==1);
253   SoSeparator       *sep                = (SoS    252   SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
254   SoCoordinate3     *theCoordinates     = (SoC    253   SoCoordinate3     *theCoordinates     = (SoCoordinate3 *)      ( sep->getChild(0));
255   SoNormal          *theNormals         = (SoN    254   SoNormal          *theNormals         = (SoNormal *)           ( sep->getChild(1)); 
256   SoNormalBinding   *theNormalBinding   = (SoN    255   SoNormalBinding   *theNormalBinding   = (SoNormalBinding *)    ( sep->getChild(2));
257   SoIndexedFaceSet  *theFaceSet         = (SoI    256   SoIndexedFaceSet  *theFaceSet         = (SoIndexedFaceSet *)   ( sep->getChild(3));
258                                                   257 
259   const int NPOINTS=8, NFACES=6, NINDICES = NF    258   const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
260   float points[NPOINTS][3];                       259   float points[NPOINTS][3];
261   float normals[NFACES][3]= {{0,0,-1}, {0,0,1}    260   float normals[NFACES][3]= {{0,0,-1}, {0,0,1}, {0,1,0}, {-1, 0, 0}, {0, -1, 0}, {1,0,0}};
262                                                   261 
263   // Indices for the eight faces                  262   // Indices for the eight faces
264 #ifdef INVENTOR2_0                                263 #ifdef INVENTOR2_0
265   static long                                     264   static long  
266 #else                                             265 #else 
267   static int32_t                                  266   static int32_t
268 #endif                                            267 #endif
269   indices[NINDICES] = {3,2,1,0, SO_END_FACE_IN    268   indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX, // bottom
270                                        4,5,6,7    269                                        4,5,6,7, SO_END_FACE_INDEX, // top
271                                        0,1,5,4    270                                        0,1,5,4, SO_END_FACE_INDEX, 
272                                        1,2,6,5    271                                        1,2,6,5, SO_END_FACE_INDEX,
273                                        2,3,7,6    272                                        2,3,7,6, SO_END_FACE_INDEX,
274                                        3,0,4,7    273                                        3,0,4,7, SO_END_FACE_INDEX};
275                                                   274 
276                                                   275   
277   // points for the eight vertices                276   // points for the eight vertices
278   points[0][0] =  fDx1.getValue(); points[0][1    277   points[0][0] =  fDx1.getValue(); points[0][1] =  fDy1.getValue(); points[0][2] = -fDz.getValue();
279   points[1][0] = -fDx1.getValue(); points[1][1    278   points[1][0] = -fDx1.getValue(); points[1][1] =  fDy1.getValue(); points[1][2] = -fDz.getValue();
280   points[2][0] = -fDx1.getValue(); points[2][1    279   points[2][0] = -fDx1.getValue(); points[2][1] = -fDy1.getValue(); points[2][2] = -fDz.getValue();
281   points[3][0] =  fDx1.getValue(); points[3][1    280   points[3][0] =  fDx1.getValue(); points[3][1] = -fDy1.getValue(); points[3][2] = -fDz.getValue();
282   points[4][0] =  fDx2.getValue(); points[4][1    281   points[4][0] =  fDx2.getValue(); points[4][1] =  fDy2.getValue(); points[4][2] =  fDz.getValue();
283   points[5][0] = -fDx2.getValue(); points[5][1    282   points[5][0] = -fDx2.getValue(); points[5][1] =  fDy2.getValue(); points[5][2] =  fDz.getValue();
284   points[6][0] = -fDx2.getValue(); points[6][1    283   points[6][0] = -fDx2.getValue(); points[6][1] = -fDy2.getValue(); points[6][2] =  fDz.getValue();
285   points[7][0] =  fDx2.getValue(); points[7][1    284   points[7][0] =  fDx2.getValue(); points[7][1] = -fDy2.getValue(); points[7][2] =  fDz.getValue();
286                                                   285 
287   float t1 = FATAN((fDx2.getValue()-fDx1.getVa    286   float t1 = FATAN((fDx2.getValue()-fDx1.getValue())/(2*fDz.getValue()));
288   float t2 = FATAN((fDy2.getValue()-fDy1.getVa    287   float t2 = FATAN((fDy2.getValue()-fDy1.getValue())/(2*fDz.getValue()));
289   float st1 = FSIN(t1);                           288   float st1 = FSIN(t1);
290   float st2 = FSIN(t2);                           289   float st2 = FSIN(t2);
291   float ct1 = FCOS(t1);                           290   float ct1 = FCOS(t1);
292   float ct2 = FCOS(t2);                           291   float ct2 = FCOS(t2);
293                                                   292 
294   normals[0][0] = 0   ; normals[0][1] =    0;     293   normals[0][0] = 0   ; normals[0][1] =    0; normals [0][2] =  -1;    
295   normals[1][0] = 0   ; normals[1][1] =    0;     294   normals[1][0] = 0   ; normals[1][1] =    0; normals [1][2] =   1;    
296   normals[2][0] = 0   ; normals[2][1] =  ct2;     295   normals[2][0] = 0   ; normals[2][1] =  ct2; normals [2][2] = -st2;    
297   normals[3][0] = -ct1; normals[3][1] =    0;     296   normals[3][0] = -ct1; normals[3][1] =    0; normals [3][2] = -st1;    
298   normals[4][0] = 0   ; normals[4][1] = -ct2;     297   normals[4][0] = 0   ; normals[4][1] = -ct2; normals [4][2] = -st2;    
299   normals[5][0] =  ct1; normals[5][1] =    0;     298   normals[5][0] =  ct1; normals[5][1] =    0; normals [5][2] = -st1;    
300                                                   299 
301   for (int np=0;np<NPOINTS;np++) theCoordinate    300   for (int np=0;np<NPOINTS;np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
302   theFaceSet->coordIndex.setValues(0,NINDICES,    301   theFaceSet->coordIndex.setValues(0,NINDICES,indices);
303   for (int nf=0;nf<NFACES;nf++) theNormals->ve    302   for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
304   theNormalBinding->value=SoNormalBinding::PER    303   theNormalBinding->value=SoNormalBinding::PER_FACE;
305 }                                                 304 }
306                                                   305 
307 // generateChildren                               306 // generateChildren
308 void SoTrd::generateChildren() {                  307 void SoTrd::generateChildren() {
309                                                   308 
310   // This routines creates one SoSeparator, on    309   // This routines creates one SoSeparator, one SoCoordinate3, and
311   // one SoLineSet, and puts it in the child l    310   // one SoLineSet, and puts it in the child list.  This is done only
312   // once, whereas redrawing the position of t    311   // once, whereas redrawing the position of the coordinates occurs each
313   // time an update is necessary, in the updat    312   // time an update is necessary, in the updateChildren routine. 
314                                                   313 
315   assert(children->getLength() ==0);              314   assert(children->getLength() ==0);
316   SoSeparator      *sep              = new SoS    315   SoSeparator      *sep              = new SoSeparator(); 
317   SoCoordinate3    *theCoordinates   = new SoC    316   SoCoordinate3    *theCoordinates   = new SoCoordinate3();
318   SoNormal         *theNormals       = new SoN    317   SoNormal         *theNormals       = new SoNormal(); 
319   SoNormalBinding  *theNormalBinding = new SoN    318   SoNormalBinding  *theNormalBinding = new SoNormalBinding();
320   SoIndexedFaceSet *theFaceSet       = new SoI    319   SoIndexedFaceSet *theFaceSet       = new SoIndexedFaceSet();
321   //                                              320   // 
322   // This line costs some in render quality! b    321   // This line costs some in render quality! but gives speed.
323   //                                              322   // 
324   sep->addChild(theCoordinates);                  323   sep->addChild(theCoordinates);
325   sep->addChild(theNormals);                      324   sep->addChild(theNormals);
326   sep->addChild(theNormalBinding);                325   sep->addChild(theNormalBinding);
327   sep->addChild(theFaceSet);                      326   sep->addChild(theFaceSet);
328   children->append(sep);                          327   children->append(sep);
329 }                                                 328 }
330                                                   329 
331 // generateAlternateRep                           330 // generateAlternateRep
332 void SoTrd::generateAlternateRep() {              331 void SoTrd::generateAlternateRep() {
333                                                   332 
334   // This routine sets the alternate represent    333   // This routine sets the alternate representation to the child
335   // list of this mode.                           334   // list of this mode.  
336                                                   335 
337   if (children->getLength() == 0) generateChil    336   if (children->getLength() == 0) generateChildren();
338   updateChildren();                               337   updateChildren();
339   alternateRep.setValue((SoSeparator *)  ( *ch    338   alternateRep.setValue((SoSeparator *)  ( *children)[0]);
340 }                                                 339 }
341                                                   340 
342 // clearAlternateRep                              341 // clearAlternateRep
343 void SoTrd::clearAlternateRep() {                 342 void SoTrd::clearAlternateRep() {
344   alternateRep.setValue(NULL);                    343   alternateRep.setValue(NULL);
345 }                                                 344 }
                                                   >> 345 
                                                   >> 346 #endif
346                                                   347