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