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