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