Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/SoTubs.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/SoTubs.cc (Version 11.3.0) and /visualization/OpenInventor/src/SoTubs.cc (Version 6.2.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: SoTubs.cc,v 1.2 2004/06/14 09:27:41 gcosmo Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-06-02 $
 27 //                                                 26 //
 28 //                                             <<  27 /*-----------------------------Hepvis---------------------------------------*/
 29 /*-----------------------------HEPVis--------- << 
 30 /*                                                 28 /*                                                                          */
 31 /* Node:             SoTubs                        29 /* Node:             SoTubs                                                 */
 32 /* Description:      Represents the G4Tubs Gea     30 /* Description:      Represents the G4Tubs Geant Geometry entity            */
 33 /* Author:           Joe Boudreau Nov 11 1996      31 /* Author:           Joe Boudreau Nov 11 1996                               */
 34 /*                                                 32 /*                                                                          */
 35 /*--------------------------------------------     33 /*--------------------------------------------------------------------------*/
 36                                                << 
 37 // this :                                      << 
 38 #include "HEPVis/nodes/SoTubs.h"               << 
 39                                                << 
 40 #include <assert.h>                                34 #include <assert.h>
 41 #include <cmath>                               <<  35 #include <math.h>
 42                                                << 
 43 #include <Inventor/SbBox.h>                        36 #include <Inventor/SbBox.h>
 44 #include <Inventor/actions/SoGLRenderAction.h>     37 #include <Inventor/actions/SoGLRenderAction.h>
 45 #include <Inventor/fields/SoSFFloat.h>             38 #include <Inventor/fields/SoSFFloat.h>
 46 #include <Inventor/misc/SoChildList.h>             39 #include <Inventor/misc/SoChildList.h>
 47 #include <Inventor/nodes/SoSeparator.h>            40 #include <Inventor/nodes/SoSeparator.h>
 48 #include <Inventor/nodes/SoIndexedFaceSet.h>       41 #include <Inventor/nodes/SoIndexedFaceSet.h>
 49 #include <Inventor/nodes/SoNormal.h>               42 #include <Inventor/nodes/SoNormal.h>
 50 #include <Inventor/nodes/SoCoordinate3.h>          43 #include <Inventor/nodes/SoCoordinate3.h>
 51 #include <Inventor/nodes/SoNormalBinding.h>        44 #include <Inventor/nodes/SoNormalBinding.h>
 52 #include <Inventor/SoPrimitiveVertex.h>            45 #include <Inventor/SoPrimitiveVertex.h>
 53 #include <Inventor/elements/SoTextureCoordinat     46 #include <Inventor/elements/SoTextureCoordinateElement.h>
 54                                                    47 
 55 #include "HEPVis/SbMath.h"                         48 #include "HEPVis/SbMath.h"
                                                   >>  49 #include "HEPVis/nodes/SoTubs.h"
 56                                                    50 
 57 // This statement is required                      51 // This statement is required
 58 SO_NODE_SOURCE(SoTubs)                             52 SO_NODE_SOURCE(SoTubs)
 59                                                    53 
 60 // Constructor                                     54 // Constructor
 61 SoTubs::SoTubs() {                                 55 SoTubs::SoTubs() {
 62                                                    56 
 63                                                    57 
 64   // This statement is required                    58   // This statement is required
 65   SO_NODE_CONSTRUCTOR(SoTubs);                     59   SO_NODE_CONSTRUCTOR(SoTubs);
 66                                                    60 
 67   // Data fields are initialized like this:        61   // Data fields are initialized like this:
 68   SO_NODE_ADD_FIELD(pRMin,               (0));     62   SO_NODE_ADD_FIELD(pRMin,               (0));
 69   SO_NODE_ADD_FIELD(pRMax,               (1));     63   SO_NODE_ADD_FIELD(pRMax,               (1));
 70   SO_NODE_ADD_FIELD(pDz,                 (10))     64   SO_NODE_ADD_FIELD(pDz,                 (10));
 71   SO_NODE_ADD_FIELD(pSPhi,               (0));     65   SO_NODE_ADD_FIELD(pSPhi,               (0));
 72   SO_NODE_ADD_FIELD(pDPhi,               ((flo     66   SO_NODE_ADD_FIELD(pDPhi,               ((float)(2*M_PI)));
 73   SO_NODE_ADD_FIELD(alternateRep,        (NULL     67   SO_NODE_ADD_FIELD(alternateRep,        (NULL));
 74   children = new SoChildList(this);                68   children = new SoChildList(this);
 75 }                                                  69 }
 76                                                    70 
 77 // Destructor                                      71 // Destructor
 78 SoTubs::~SoTubs() {                                72 SoTubs::~SoTubs() {
 79   delete children;                                 73   delete children;
 80 }                                                  74 }
 81                                                    75 
 82                                                    76 
 83 // initClass                                       77 // initClass
 84 void SoTubs::initClass(){                          78 void SoTubs::initClass(){
 85   // This statement is required.                   79   // This statement is required.
 86   static bool first = true;                    <<  80   SO_NODE_INIT_CLASS(SoTubs,SoShape,"Shape");
 87   if (first) {                                 << 
 88     first = false;                             << 
 89     SO_NODE_INIT_CLASS(SoTubs,SoShape,"Shape") << 
 90   }                                            << 
 91 }                                                  81 }
 92                                                    82 
 93 // generatePrimitives                              83 // generatePrimitives
 94 void SoTubs::generatePrimitives(SoAction *acti     84 void SoTubs::generatePrimitives(SoAction *action) {
 95   // This variable is used to store each verte     85   // This variable is used to store each vertex
 96   SoPrimitiveVertex pv;                            86   SoPrimitiveVertex pv;
 97                                                    87 
 98   // Access the stat from the action               88   // Access the stat from the action
 99   SoState *state = action->getState();             89   SoState *state = action->getState();
100                                                    90 
101   // See if we have to use a texture coordinat     91   // See if we have to use a texture coordinate function,
102   // rather than generating explicit texture c     92   // rather than generating explicit texture coordinates.
103   SbBool useTexFunction=                           93   SbBool useTexFunction=
104     (SoTextureCoordinateElement::getType(state     94     (SoTextureCoordinateElement::getType(state) == 
105      SoTextureCoordinateElement::FUNCTION);        95      SoTextureCoordinateElement::FUNCTION);
106                                                    96 
107   // If we need to generate texture coordinate     97   // If we need to generate texture coordinates with a function,
108   // we'll need an SoGLTextureCoordinateElemen     98   // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
109   // set up the coordinates directly.              99   // set up the coordinates directly.
110   const SoTextureCoordinateElement* tce = NULL    100   const SoTextureCoordinateElement* tce = NULL;
111   SbVec4f texCoord;                               101   SbVec4f texCoord;
112   if (useTexFunction) {                           102   if (useTexFunction) {
113     tce = SoTextureCoordinateElement::getInsta    103     tce = SoTextureCoordinateElement::getInstance(state);
114   }                                               104   }
115   else {                                          105   else {
116     texCoord[2] = 0.0;                            106     texCoord[2] = 0.0;
117     texCoord[3] = 1.0;                            107     texCoord[3] = 1.0;
118   }                                               108   }
119   SbVec3f point, normal;                          109   SbVec3f point, normal;
120                                                   110 
121                                                   111 
122   ////////////////////////////////////////////    112   ///////////////////////////////////////////////////////
123   //------------------------------------------    113   //-----------------------------------------------------
124 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)         114 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)               \
125   point.setValue((float)(x),(float)(y),(float)    115   point.setValue((float)(x),(float)(y),(float)(z));     \
126   normal.setValue((float)(nx),(float)(ny),(flo    116   normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
127   if (useTexFunction) {                           117   if (useTexFunction) {                                 \
128     texCoord=tce->get(point,normal);              118     texCoord=tce->get(point,normal);                    \
129   } else {                                        119   } else {                                              \
130     texCoord[0]=(float)(s);                       120     texCoord[0]=(float)(s);                             \
131     texCoord[1]=(float)(t);                       121     texCoord[1]=(float)(t);                             \
132   }                                               122   }                                                     \
133   pv.setPoint(point);                             123   pv.setPoint(point);                                   \
134   pv.setNormal(normal);                           124   pv.setNormal(normal);                                 \
135   pv.setTextureCoords(texCoord);                  125   pv.setTextureCoords(texCoord);                        \
136   shapeVertex(&pv);                               126   shapeVertex(&pv);
137   //------------------------------------------    127   //-----------------------------------------------------
138   ////////////////////////////////////////////    128   ///////////////////////////////////////////////////////
139                                                   129 
140   int NPHI = (int)(2+22*std::fabs(pDPhi.getVal << 130   int NPHI = (int)(2+22*fabs(pDPhi.getValue()/(2.0*M_PI)));
141   double deltaPhi = pDPhi.getValue()/NPHI, phi    131   double deltaPhi = pDPhi.getValue()/NPHI, phi0 = pSPhi.getValue(),phi1=phi0+pDPhi.getValue();
142   double rMax=pRMax.getValue(),rMin=pRMin.getV    132   double rMax=pRMax.getValue(),rMin=pRMin.getValue();
143   double zMax=pDz.getValue(),zMin=-zMax;          133   double zMax=pDz.getValue(),zMin=-zMax;
144   double cosPhi0=std::cos(phi0), sinPhi0=std:: << 134   double cosPhi0=cos(phi0), sinPhi0=sin(phi0);
145   double cosPhi1=std::cos(phi1), sinPhi1=std:: << 135   double cosPhi1=cos(phi1), sinPhi1=sin(phi1);
146   double cosDeltaPhi=std::cos(deltaPhi),sinDel << 136   double cosDeltaPhi=cos(deltaPhi),sinDeltaPhi=sin(deltaPhi);
147   //                                              137   //
148   // The outer surface!                           138   // The outer surface!
149   //                                              139   //
150   int i;                                          140   int i;
151   double sinPhi,cosPhi;                           141   double sinPhi,cosPhi;
152   beginShape(action,TRIANGLE_STRIP);              142   beginShape(action,TRIANGLE_STRIP);
153   sinPhi=sinPhi0;                                 143   sinPhi=sinPhi0;
154   cosPhi=cosPhi0;                                 144   cosPhi=cosPhi0;
155   for (i = 0; i<=NPHI; i++) {                     145   for (i = 0; i<=NPHI; i++) {
156     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax    146     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,cosPhi,sinPhi,0);   
157     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin    147     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,cosPhi,sinPhi,0);   
158     inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaP    148     inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
159   }                                               149   }
160   endShape();                                     150   endShape();
161   //                                              151   //
162   // The inner surface!                           152   // The inner surface!
163   //                                              153   //
164   if(rMin!=0.F) {                                 154   if(rMin!=0.F) {
165     beginShape(action,TRIANGLE_STRIP);            155     beginShape(action,TRIANGLE_STRIP);
166     sinPhi=sinPhi0;                               156     sinPhi=sinPhi0;
167     cosPhi=cosPhi0;                               157     cosPhi=cosPhi0;
168     for (i = 0; i<=NPHI; i++) {                   158     for (i = 0; i<=NPHI; i++) {
169       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zM    159       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,-cosPhi,-sinPhi,0);   
170       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zM    160       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,1.0,1.0,-cosPhi,-sinPhi,0);   
171       inc(sinPhi, cosPhi, sinDeltaPhi, cosDelt    161       inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
172     }                                             162     } 
173     endShape();                                   163     endShape();
174   }                                               164   }
175   if (std::fabs(deltaPhi)<2.0*M_PI) {          << 165   if (fabs(deltaPhi)<2.0*M_PI) { 
176     //                                            166     //
177     // The end                                    167     // The end 
178     //                                            168     //
179     beginShape(action,TRIANGLE_STRIP);            169     beginShape(action,TRIANGLE_STRIP);
180     sinPhi=sinPhi0;                               170     sinPhi=sinPhi0;
181     cosPhi=cosPhi0;                               171     cosPhi=cosPhi0;
182     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax    172     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);   
183     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin    173     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);   
184     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax    174     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);   
185     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin    175     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);   
186     endShape();                                   176     endShape();
187     //                                            177     //
188     // The other end                              178     // The other end 
189     //                                            179     //
190     beginShape(action,TRIANGLE_STRIP);            180     beginShape(action,TRIANGLE_STRIP);
191     sinPhi=sinPhi1;                               181     sinPhi=sinPhi1;
192     cosPhi=cosPhi1;                               182     cosPhi=cosPhi1;
193     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMa    183     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);   
194     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMi    184     GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);   
195     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMa    185     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);   
196     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMi    186     GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);   
197     endShape();                                   187     endShape();
198   }                                               188   }
199   //                                              189   //
200   // The outer surface at z=+PDZ                  190   // The outer surface at z=+PDZ
201   //                                              191   //
202   if(rMin==0.F) {                                 192   if(rMin==0.F) {
203     beginShape(action,TRIANGLE_FAN);              193     beginShape(action,TRIANGLE_FAN);
204     sinPhi=sinPhi0;                               194     sinPhi=sinPhi0;
205     cosPhi=cosPhi0;                               195     cosPhi=cosPhi0;
206     GEN_VERTEX(pv,0,0,zMax,0.0,0.0,0,0,1);        196     GEN_VERTEX(pv,0,0,zMax,0.0,0.0,0,0,1);   
207     for (i = 0; i<=NPHI; i++) {                   197     for (i = 0; i<=NPHI; i++) {
208       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zM    198       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);   
209       inc(sinPhi, cosPhi, sinDeltaPhi, cosDelt    199       inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
210     }                                             200     }
211     endShape();                                   201     endShape();
212     //                                            202     //
213     // The outer surface at z=-PDZ                203     // The outer surface at z=-PDZ
214     //                                            204     //
215     beginShape(action,TRIANGLE_FAN);              205     beginShape(action,TRIANGLE_FAN);
216     sinPhi=sinPhi0;                               206     sinPhi=sinPhi0;
217     cosPhi=cosPhi0;                               207     cosPhi=cosPhi0;
218     GEN_VERTEX(pv,0,0,zMin,0.0,0.0,0,0,-1);       208     GEN_VERTEX(pv,0,0,zMin,0.0,0.0,0,0,-1);   
219     for (i = 0; i<=NPHI; i++) {                   209     for (i = 0; i<=NPHI; i++) {
220       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zM    210       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);   
221       inc(sinPhi, cosPhi, sinDeltaPhi, cosDelt    211       inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
222     }                                             212     }
223     endShape();                                   213     endShape();
224   } else {                                        214   } else {
225     beginShape(action,TRIANGLE_STRIP);            215     beginShape(action,TRIANGLE_STRIP);
226     sinPhi=sinPhi0;                               216     sinPhi=sinPhi0;
227     cosPhi=cosPhi0;                               217     cosPhi=cosPhi0;
228     for (i = 0; i<=NPHI; i++) {                   218     for (i = 0; i<=NPHI; i++) {
229       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zM    219       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,0,0,1);   
230       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zM    220       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);   
231       inc(sinPhi, cosPhi, sinDeltaPhi, cosDelt    221       inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
232     }                                             222     }
233     endShape();                                   223     endShape();
234     //                                            224     //
235     // The outer surface at z=-PDZ                225     // The outer surface at z=-PDZ
236     //                                            226     //
237     beginShape(action,TRIANGLE_STRIP);            227     beginShape(action,TRIANGLE_STRIP);
238     sinPhi=sinPhi0;                               228     sinPhi=sinPhi0;
239     cosPhi=cosPhi0;                               229     cosPhi=cosPhi0;
240     for (i = 0; i<=NPHI; i++) {                   230     for (i = 0; i<=NPHI; i++) {
241       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zM    231       GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,0.0,0,0,-1);   
242       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zM    232       GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);   
243       inc(sinPhi, cosPhi, sinDeltaPhi, cosDelt    233       inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);    
244     }                                             234     }
245     endShape();                                   235     endShape();
246   }                                               236   }
247 }                                                 237 }
248                                                   238 
249 // getChildren                                    239 // getChildren
250 SoChildList *SoTubs::getChildren() const {        240 SoChildList *SoTubs::getChildren() const {
251   return children;                                241   return children;
252 }                                                 242 }
253                                                   243 
254                                                   244 
255 // computeBBox                                    245 // computeBBox
256 void SoTubs::computeBBox(SoAction *, SbBox3f &    246 void SoTubs::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
257   SbVec3f vmin(-pRMax.getValue(),-pRMax.getVal    247   SbVec3f vmin(-pRMax.getValue(),-pRMax.getValue(),-pDz.getValue()), 
258           vmax( pRMax.getValue(), pRMax.getVal    248           vmax( pRMax.getValue(), pRMax.getValue(), pDz.getValue());
259   center.setValue(0,0,0);                         249   center.setValue(0,0,0);
260   box.setBounds(vmin,vmax);                       250   box.setBounds(vmin,vmax);
261 }                                                 251 }
262                                                   252 
263                                                   253 
264 // updateChildren                                 254 // updateChildren
265 void SoTubs::updateChildren() {                   255 void SoTubs::updateChildren() {
266                                                   256 
267   // Redraw the G4Tubs....                        257   // Redraw the G4Tubs....
268                                                   258 
269   assert(children->getLength()==1);               259   assert(children->getLength()==1);
270   SoSeparator       *sep                = (SoS    260   SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
271   SoCoordinate3     *theCoordinates     = (SoC    261   SoCoordinate3     *theCoordinates     = (SoCoordinate3 *)      ( sep->getChild(0));
272   SoNormal          *theNormals         = (SoN    262   SoNormal          *theNormals         = (SoNormal *)           ( sep->getChild(1)); 
273   SoNormalBinding   *theNormalBinding   = (SoN    263   SoNormalBinding   *theNormalBinding   = (SoNormalBinding *)    ( sep->getChild(2));
274   SoIndexedFaceSet  *theFaceSet         = (SoI    264   SoIndexedFaceSet  *theFaceSet         = (SoIndexedFaceSet *)   ( sep->getChild(3));
275                                                   265   
276                                                   266   
277   const int NPHI=24, NPOINTS=2*(2*NPHI+2), NFA    267   const int NPHI=24, NPOINTS=2*(2*NPHI+2), NFACES=4*NPHI+2, NINDICES = NFACES*5;
278   float points[NPOINTS][3],normals[NFACES][3];    268   float points[NPOINTS][3],normals[NFACES][3];
279 #ifdef INVENTOR2_0                                269 #ifdef INVENTOR2_0
280   static long     indices[NINDICES];              270   static long     indices[NINDICES];
281 #else                                             271 #else
282   static int32_t  indices[NINDICES];              272   static int32_t  indices[NINDICES];
283 #endif                                            273 #endif
284                                                   274     
285   static int init=0;                              275   static int init=0;
286   double phi, pp, DeltaPhi;                       276   double phi, pp, DeltaPhi;
287                                                   277     
288   // Indices need to be generated once! This i    278   // Indices need to be generated once! This is here to keep it close to the point
289   // generation, since otherwise it will be co    279   // generation, since otherwise it will be confusing.
290                                                   280     
291   int i;                                          281   int i;
292   if (!init) {                                    282   if (!init) {
293     init = 1;                                     283     init = 1;
294     // Outer face                                 284     // Outer face
295     for (i = 0; i< NPHI; i++) {                   285     for (i = 0; i< NPHI; i++) {
296       // 0 1 3 2;                                 286       // 0 1 3 2;
297       indices[5*i+0] =  2*i+0;                    287       indices[5*i+0] =  2*i+0;
298       indices[5*i+1] =  2*i+1;                    288       indices[5*i+1] =  2*i+1;
299       indices[5*i+2] =  2*i+3;                    289       indices[5*i+2] =  2*i+3;
300       indices[5*i+3] =  2*i+2;                    290       indices[5*i+3] =  2*i+2;
301       indices[5*i+4] = SO_END_FACE_INDEX;         291       indices[5*i+4] = SO_END_FACE_INDEX;
302     }                                             292     }
303     // the inner face                             293     // the inner face
304     for (i=0;i<NPHI;i++) {                        294     for (i=0;i<NPHI;i++) {
305       indices[5*1*NPHI + 5*i+0] = 2*NPHI+2 + 2    295       indices[5*1*NPHI + 5*i+0] = 2*NPHI+2 + 2*i+0;  
306       indices[5*1*NPHI + 5*i+1] = 2*NPHI+2 + 2    296       indices[5*1*NPHI + 5*i+1] = 2*NPHI+2 + 2*i+1;
307       indices[5*1*NPHI + 5*i+2] = 2*NPHI+2 + 2    297       indices[5*1*NPHI + 5*i+2] = 2*NPHI+2 + 2*i+3;
308       indices[5*1*NPHI + 5*i+3] = 2*NPHI+2 + 2    298       indices[5*1*NPHI + 5*i+3] = 2*NPHI+2 + 2*i+2;
309       indices[5*1*NPHI + 5*i+4] = SO_END_FACE_    299       indices[5*1*NPHI + 5*i+4] = SO_END_FACE_INDEX;
310     }                                             300     }
311     // the top side                               301     // the top side
312     for (i=0;i<NPHI;i++) {                        302     for (i=0;i<NPHI;i++) {
313       indices[5*2*NPHI + 5*i+0] = 2*i+0;          303       indices[5*2*NPHI + 5*i+0] = 2*i+0;
314       indices[5*2*NPHI + 5*i+1] = 2*i+2;          304       indices[5*2*NPHI + 5*i+1] = 2*i+2;
315       indices[5*2*NPHI + 5*i+2] = NPOINTS - (2    305       indices[5*2*NPHI + 5*i+2] = NPOINTS - (2*i+4);
316       indices[5*2*NPHI + 5*i+3] = NPOINTS - (2    306       indices[5*2*NPHI + 5*i+3] = NPOINTS - (2*i+2);
317       indices[5*2*NPHI + 5*i+4] = SO_END_FACE_    307       indices[5*2*NPHI + 5*i+4] = SO_END_FACE_INDEX;
318     }                                             308     }
319     // the bottom side                            309     // the bottom side
320     for (i=0;i<NPHI;i++) {                        310     for (i=0;i<NPHI;i++) {
321       indices[5*3*NPHI + 5*i+0] = 2*i+1;          311       indices[5*3*NPHI + 5*i+0] = 2*i+1;
322       indices[5*3*NPHI + 5*i+1] = NPOINTS - (2    312       indices[5*3*NPHI + 5*i+1] = NPOINTS - (2*i+1);
323       indices[5*3*NPHI + 5*i+2] = NPOINTS - (2    313       indices[5*3*NPHI + 5*i+2] = NPOINTS - (2*i+3);
324       indices[5*3*NPHI + 5*i+3] = 2*i+3;          314       indices[5*3*NPHI + 5*i+3] = 2*i+3;
325       indices[5*3*NPHI + 5*i+4] = SO_END_FACE_    315       indices[5*3*NPHI + 5*i+4] = SO_END_FACE_INDEX;
326     }                                             316     }
327     // the odd side                               317     // the odd side
328     indices[5*4*NPHI +0] = 2*NPHI;                318     indices[5*4*NPHI +0] = 2*NPHI;
329     indices[5*4*NPHI +1] = 2*NPHI+1;              319     indices[5*4*NPHI +1] = 2*NPHI+1;
330     indices[5*4*NPHI +2] = 2*NPHI+3;              320     indices[5*4*NPHI +2] = 2*NPHI+3;
331     indices[5*4*NPHI +3] = 2*NPHI+2;              321     indices[5*4*NPHI +3] = 2*NPHI+2;
332     indices[5*4*NPHI +4] = SO_END_FACE_INDEX;     322     indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
333     // aother odd side                            323     // aother odd side
334     indices[5*4*NPHI +5 +0] = 0;                  324     indices[5*4*NPHI +5 +0] = 0;
335     indices[5*4*NPHI +5 +1] = NPOINTS-2;          325     indices[5*4*NPHI +5 +1] = NPOINTS-2;
336     indices[5*4*NPHI +5 +2] = NPOINTS-1;          326     indices[5*4*NPHI +5 +2] = NPOINTS-1;
337     indices[5*4*NPHI +5 +3] = 1;                  327     indices[5*4*NPHI +5 +3] = 1;
338     indices[5*4*NPHI +5 +4] = SO_END_FACE_INDE    328     indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
339   }                                               329   }
340   // Points need to be generated each time:       330   // Points need to be generated each time:
341   if (pDPhi.getValue()<2*M_PI) {                  331   if (pDPhi.getValue()<2*M_PI) {
342     // the odd side                               332     // the odd side
343     indices[5*4*NPHI +0] = 2*NPHI;                333     indices[5*4*NPHI +0] = 2*NPHI;
344     indices[5*4*NPHI +1] = 2*NPHI+1;              334     indices[5*4*NPHI +1] = 2*NPHI+1;
345     indices[5*4*NPHI +2] = 2*NPHI+3;              335     indices[5*4*NPHI +2] = 2*NPHI+3;
346     indices[5*4*NPHI +3] = 2*NPHI+2;              336     indices[5*4*NPHI +3] = 2*NPHI+2;
347     indices[5*4*NPHI +4] = SO_END_FACE_INDEX;     337     indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
348     // aother odd side                            338     // aother odd side
349     indices[5*4*NPHI +5 +0] = 0;                  339     indices[5*4*NPHI +5 +0] = 0;
350     indices[5*4*NPHI +5 +1] = NPOINTS-2;          340     indices[5*4*NPHI +5 +1] = NPOINTS-2;
351     indices[5*4*NPHI +5 +2] = NPOINTS-1;          341     indices[5*4*NPHI +5 +2] = NPOINTS-1;
352     indices[5*4*NPHI +5 +3] = 1;                  342     indices[5*4*NPHI +5 +3] = 1;
353     indices[5*4*NPHI +5 +4] = SO_END_FACE_INDE    343     indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
354   }                                               344   } 
355   else {                                          345   else {
356     // the odd side                               346     // the odd side
357     indices[5*4*NPHI +0] = SO_END_FACE_INDEX;     347     indices[5*4*NPHI +0] = SO_END_FACE_INDEX;
358     indices[5*4*NPHI +1] = SO_END_FACE_INDEX;     348     indices[5*4*NPHI +1] = SO_END_FACE_INDEX;
359     indices[5*4*NPHI +2] = SO_END_FACE_INDEX;     349     indices[5*4*NPHI +2] = SO_END_FACE_INDEX;
360     indices[5*4*NPHI +3] = SO_END_FACE_INDEX;     350     indices[5*4*NPHI +3] = SO_END_FACE_INDEX;
361     indices[5*4*NPHI +4] = SO_END_FACE_INDEX;     351     indices[5*4*NPHI +4] = SO_END_FACE_INDEX;
362     // aother odd side                            352     // aother odd side
363     indices[5*4*NPHI +5 +0] = SO_END_FACE_INDE    353     indices[5*4*NPHI +5 +0] = SO_END_FACE_INDEX;
364     indices[5*4*NPHI +5 +1] = SO_END_FACE_INDE    354     indices[5*4*NPHI +5 +1] = SO_END_FACE_INDEX;
365     indices[5*4*NPHI +5 +2] = SO_END_FACE_INDE    355     indices[5*4*NPHI +5 +2] = SO_END_FACE_INDEX;
366     indices[5*4*NPHI +5 +3] = SO_END_FACE_INDE    356     indices[5*4*NPHI +5 +3] = SO_END_FACE_INDEX;
367     indices[5*4*NPHI +5 +4] = SO_END_FACE_INDE    357     indices[5*4*NPHI +5 +4] = SO_END_FACE_INDEX;
368   }                                               358   }
369   // The outer surface                            359   // The outer surface
370   DeltaPhi = pDPhi.getValue()/NPHI, phi = pSPh    360   DeltaPhi = pDPhi.getValue()/NPHI, phi = pSPhi.getValue();
371   for (i = 0; i<=NPHI; i++) {                     361   for (i = 0; i<=NPHI; i++) {
372     points[2*i+0][0] = pRMax.getValue()*FCOS(p    362     points[2*i+0][0] = pRMax.getValue()*FCOS(phi); 
373     points[2*i+0][1]= pRMax.getValue()*FSIN(ph    363     points[2*i+0][1]= pRMax.getValue()*FSIN(phi); 
374     points[2*i+0][2] = +pDz.getValue();           364     points[2*i+0][2] = +pDz.getValue();
375                                                   365 
376     points[2*i+1][0] = pRMax.getValue()*FCOS(p    366     points[2*i+1][0] = pRMax.getValue()*FCOS(phi); 
377     points[2*i+1][1]= pRMax.getValue()*FSIN(ph    367     points[2*i+1][1]= pRMax.getValue()*FSIN(phi); 
378     points[2*i+1][2] = -pDz.getValue();           368     points[2*i+1][2] = -pDz.getValue();
379                                                   369 
380     pp = phi+DeltaPhi/2.0;                        370     pp = phi+DeltaPhi/2.0;
381     if (i!=NPHI) {                                371     if (i!=NPHI) {
382       normals[i][0] = FCOS(pp);                   372       normals[i][0] = FCOS(pp); 
383       normals[i][1] = FSIN(pp);                   373       normals[i][1] = FSIN(pp); 
384       normals[i][2] = 0;                          374       normals[i][2] = 0;
385     }                                             375     }
386     phi+=DeltaPhi;                                376     phi+=DeltaPhi;
387   }                                               377   }
388   // The inner surface                            378   // The inner surface
389   phi = pSPhi.getValue() + pDPhi.getValue();      379   phi = pSPhi.getValue() + pDPhi.getValue();
390   for (i = 0; i<=NPHI; i++) {                     380   for (i = 0; i<=NPHI; i++) {
391     points[2*NPHI+2+2*i+0][0] = pRMin.getValue    381     points[2*NPHI+2+2*i+0][0] = pRMin.getValue()*FCOS(phi); 
392     points[2*NPHI+2+2*i+0][1] = pRMin.getValue    382     points[2*NPHI+2+2*i+0][1] = pRMin.getValue()*FSIN(phi); 
393     points[2*NPHI+2+2*i+0][2] = +pDz.getValue(    383     points[2*NPHI+2+2*i+0][2] = +pDz.getValue();
394     points[2*NPHI+2+2*i+1][0] = pRMin.getValue    384     points[2*NPHI+2+2*i+1][0] = pRMin.getValue()*FCOS(phi); 
395     points[2*NPHI+2+2*i+1][1] = pRMin.getValue    385     points[2*NPHI+2+2*i+1][1] = pRMin.getValue()*FSIN(phi); 
396     points[2*NPHI+2+2*i+1][2] = -pDz.getValue(    386     points[2*NPHI+2+2*i+1][2] = -pDz.getValue();
397     pp = phi-DeltaPhi/2.0;                        387     pp = phi-DeltaPhi/2.0;
398     if (i!=NPHI) {                                388     if (i!=NPHI) {
399       normals[NPHI+i][0] = -FCOS(pp);             389       normals[NPHI+i][0] = -FCOS(pp); 
400       normals[NPHI+i][1] = -FSIN(pp);             390       normals[NPHI+i][1] = -FSIN(pp); 
401       normals[NPHI+i][2] = 0;                     391       normals[NPHI+i][2] = 0;
402     }                                             392     }
403     phi-=DeltaPhi;                                393     phi-=DeltaPhi;
404   }                                               394   }
405   // The top side                                 395   // The top side
406   for (i=0;i<NPHI;i++) {                          396   for (i=0;i<NPHI;i++) {
407     normals[2*NPHI+i][0]=normals[2*NPHI+i][1]=    397     normals[2*NPHI+i][0]=normals[2*NPHI+i][1]=0; 
408     normals[2*NPHI+i][2]=  1.0;                   398     normals[2*NPHI+i][2]=  1.0;
409   }                                               399   } 
410   // The bottom side                              400   // The bottom side
411   for (i=0;i<NPHI;i++) {                          401   for (i=0;i<NPHI;i++) {
412     normals[3*NPHI+i][0]=normals[3*NPHI+i][1]=    402     normals[3*NPHI+i][0]=normals[3*NPHI+i][1]=0; 
413     normals[3*NPHI+i][2]= -1.0;                   403     normals[3*NPHI+i][2]= -1.0;
414   }                                               404   } 
415   // The odd side                                 405   // The odd side
416   phi = pSPhi.getValue();                         406   phi = pSPhi.getValue(); 
417   normals[4*NPHI+0][0]=  FSIN(phi);               407   normals[4*NPHI+0][0]=  FSIN(phi); 
418   normals[4*NPHI+0][1]= -FCOS(phi);               408   normals[4*NPHI+0][1]= -FCOS(phi); 
419   normals[4*NPHI+0][2]=0;                         409   normals[4*NPHI+0][2]=0;
420                                                   410     
421     // Another odd side                           411     // Another odd side
422   phi = pSPhi.getValue()+pDPhi.getValue();        412   phi = pSPhi.getValue()+pDPhi.getValue(); 
423   normals[4*NPHI+1][0]= -FSIN(phi);               413   normals[4*NPHI+1][0]= -FSIN(phi); 
424   normals[4*NPHI+1][1]= +FCOS(phi);               414   normals[4*NPHI+1][1]= +FCOS(phi); 
425   normals[4*NPHI+1][2]=0;                         415   normals[4*NPHI+1][2]=0;
426                                                   416     
427   for (int np=0;np<NPOINTS; np++) theCoordinat    417   for (int np=0;np<NPOINTS; np++) theCoordinates->point.set1Value(np,points[np][0],points[np][1],points[np][2]);
428   for (int ni=0;ni<NINDICES;ni++) theFaceSet->    418   for (int ni=0;ni<NINDICES;ni++) theFaceSet->coordIndex.set1Value(ni,indices[ni]);
429   for (int nf=0;nf<NFACES;nf++) theNormals->ve    419   for (int nf=0;nf<NFACES;nf++) theNormals->vector.set1Value(nf,normals[nf][0],normals[nf][1],normals[nf][2]);
430   theNormalBinding->value=SoNormalBinding::PER    420   theNormalBinding->value=SoNormalBinding::PER_FACE;
431 }                                                 421 }
432                                                   422 
433 // generateChildren                               423 // generateChildren
434 void SoTubs::generateChildren() {                 424 void SoTubs::generateChildren() {
435                                                   425 
436   // This routines creates one SoSeparator, on    426   // This routines creates one SoSeparator, one SoCoordinate3, and
437   // one SoLineSet, and puts it in the child l    427   // one SoLineSet, and puts it in the child list.  This is done only
438   // once, whereas redrawing the position of t    428   // once, whereas redrawing the position of the coordinates occurs each
439   // time an update is necessary, in the updat    429   // time an update is necessary, in the updateChildren routine. 
440                                                   430 
441   assert(children->getLength() ==0);              431   assert(children->getLength() ==0);
442   SoSeparator      *sep              = new SoS    432   SoSeparator      *sep              = new SoSeparator(); 
443   SoCoordinate3    *theCoordinates   = new SoC    433   SoCoordinate3    *theCoordinates   = new SoCoordinate3();
444   SoNormal         *theNormals       = new SoN    434   SoNormal         *theNormals       = new SoNormal(); 
445   SoNormalBinding  *theNormalBinding = new SoN    435   SoNormalBinding  *theNormalBinding = new SoNormalBinding();
446   SoIndexedFaceSet *theFaceSet       = new SoI    436   SoIndexedFaceSet *theFaceSet       = new SoIndexedFaceSet();
447   //                                              437   // 
448   // This line costs some in render quality! b    438   // This line costs some in render quality! but gives speed.
449   //                                              439   // 
450   sep->addChild(theCoordinates);                  440   sep->addChild(theCoordinates);
451   sep->addChild(theNormals);                      441   sep->addChild(theNormals);
452   sep->addChild(theNormalBinding);                442   sep->addChild(theNormalBinding);
453   sep->addChild(theFaceSet);                      443   sep->addChild(theFaceSet);
454   children->append(sep);                          444   children->append(sep);
455 }                                                 445 }
456                                                   446 
457 // generateAlternateRep                           447 // generateAlternateRep
458 void SoTubs::generateAlternateRep() {             448 void SoTubs::generateAlternateRep() {
459                                                   449 
460   // This routine sets the alternate represent    450   // This routine sets the alternate representation to the child
461   // list of this mode.                           451   // list of this mode.  
462                                                   452 
463   if (children->getLength() == 0) generateChil    453   if (children->getLength() == 0) generateChildren();
464   updateChildren();                               454   updateChildren();
465   alternateRep.setValue((SoSeparator *)  ( *ch    455   alternateRep.setValue((SoSeparator *)  ( *children)[0]);
466 }                                                 456 }
467                                                   457 
468 // clearAlternateRep                              458 // clearAlternateRep
469 void SoTubs::clearAlternateRep() {                459 void SoTubs::clearAlternateRep() {
470   alternateRep.setValue(NULL);                    460   alternateRep.setValue(NULL);
471 }                                                 461 }
                                                   >> 462 
472                                                   463