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[ 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/SoBox.cc (Version 11.3.0) and /visualization/OpenInventor/src/SoBox.cc (Version 9.6.p2)


  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$
 28 //                                                 29 //
 29 /*----------------------------HEPVis----------     30 /*----------------------------HEPVis----------------------------------------*/
 30 /*                                                 31 /*                                                                          */
 31 /* Node:             SoBox                         32 /* Node:             SoBox                                                  */
 32 /* Description:      Represents the G4Box Gean     33 /* Description:      Represents the G4Box Geant Geometry entity             */
 33 /* Author:           Joe Boudreau Nov 11 1996      34 /* Author:           Joe Boudreau Nov 11 1996                               */
 34 /*                                                 35 /*                                                                          */
 35 /*--------------------------------------------     36 /*--------------------------------------------------------------------------*/
 36                                                    37 
                                                   >>  38 #ifdef G4VIS_BUILD_OI_DRIVER
                                                   >>  39 
 37 // this :                                          40 // this :
 38 #include "HEPVis/nodes/SoBox.h"                    41 #include "HEPVis/nodes/SoBox.h"
 39                                                    42 
 40 #include <assert.h>                                43 #include <assert.h>
 41 #include <cmath>                                   44 #include <cmath>
 42                                                    45 
 43 #include <Inventor/SbBox.h>                        46 #include <Inventor/SbBox.h>
 44 #include <Inventor/fields/SoSFFloat.h>             47 #include <Inventor/fields/SoSFFloat.h>
 45 #include <Inventor/misc/SoChildList.h>             48 #include <Inventor/misc/SoChildList.h>
 46 #include <Inventor/nodes/SoSeparator.h>            49 #include <Inventor/nodes/SoSeparator.h>
 47 #include <Inventor/nodes/SoCube.h>                 50 #include <Inventor/nodes/SoCube.h>
 48 #include <Inventor/nodes/SoScale.h>                51 #include <Inventor/nodes/SoScale.h>
 49 #include <Inventor/actions/SoAction.h>             52 #include <Inventor/actions/SoAction.h>
 50 #include <Inventor/nodes/SoIndexedFaceSet.h>       53 #include <Inventor/nodes/SoIndexedFaceSet.h>
 51 #include <Inventor/SoPrimitiveVertex.h>            54 #include <Inventor/SoPrimitiveVertex.h>
 52 #include <Inventor/elements/SoTextureCoordinat     55 #include <Inventor/elements/SoTextureCoordinateElement.h>
 53                                                    56 
 54 // This statement is required                      57 // This statement is required
 55 SO_NODE_SOURCE(SoBox)                              58 SO_NODE_SOURCE(SoBox)
 56                                                    59 
 57 // Constructor                                     60 // Constructor
 58 SoBox::SoBox() {                                   61 SoBox::SoBox() {
 59   // This statement is required                    62   // This statement is required
 60   SO_NODE_CONSTRUCTOR(SoBox);                      63   SO_NODE_CONSTRUCTOR(SoBox);
 61                                                    64 
 62   // Data fields are initialized like this:        65   // Data fields are initialized like this:
 63   SO_NODE_ADD_FIELD(fDx,                (1.0))     66   SO_NODE_ADD_FIELD(fDx,                (1.0));
 64   SO_NODE_ADD_FIELD(fDy,                (1.0))     67   SO_NODE_ADD_FIELD(fDy,                (1.0));
 65   SO_NODE_ADD_FIELD(fDz,                (1.0))     68   SO_NODE_ADD_FIELD(fDz,                (1.0));
 66   SO_NODE_ADD_FIELD(alternateRep,       (NULL)     69   SO_NODE_ADD_FIELD(alternateRep,       (NULL));
 67   children = new SoChildList(this);                70   children = new SoChildList(this);
 68 }                                                  71 }
 69                                                    72 
 70 // Destructor                                      73 // Destructor
 71 SoBox::~SoBox() {                                  74 SoBox::~SoBox() {
 72  delete children;                                  75  delete children;
 73 }                                                  76 }
 74                                                    77 
 75                                                    78 
 76 // initClass                                       79 // initClass
 77 void SoBox::initClass(){                           80 void SoBox::initClass(){
 78   // This statement is required.                   81   // This statement is required.
 79   static bool first = true;                    <<  82   SO_NODE_INIT_CLASS(SoBox,SoShape,"Shape");
 80   if (first) {                                 << 
 81     first = false;                             << 
 82     SO_NODE_INIT_CLASS(SoBox,SoShape,"Shape"); << 
 83   }                                            << 
 84 }                                                  83 }
 85                                                    84 
 86                                                    85 
 87 // generatePrimitives                              86 // generatePrimitives
 88 void SoBox::generatePrimitives(SoAction *actio     87 void SoBox::generatePrimitives(SoAction *action) {
 89   // This variable is used to store each verte     88   // This variable is used to store each vertex
 90   SoPrimitiveVertex pv;                            89   SoPrimitiveVertex pv;
 91                                                    90 
 92   // Access the stat from the action               91   // Access the stat from the action
 93   SoState *state = action->getState();             92   SoState *state = action->getState();
 94                                                    93 
 95   // See if we have to use a texture coordinat     94   // See if we have to use a texture coordinate function,
 96   // rather than generating explicit texture c     95   // rather than generating explicit texture coordinates.
 97   SbBool useTexFunction=                           96   SbBool useTexFunction=
 98     (SoTextureCoordinateElement::getType(state     97     (SoTextureCoordinateElement::getType(state) == 
 99      SoTextureCoordinateElement::FUNCTION);        98      SoTextureCoordinateElement::FUNCTION);
100                                                    99 
101   // If we need to generate texture coordinate    100   // If we need to generate texture coordinates with a function,
102   // we'll need an SoGLTextureCoordinateElemen    101   // we'll need an SoGLTextureCoordinateElement.  Otherwise, we'll
103   // set up the coordinates directly.             102   // set up the coordinates directly.
104   const SoTextureCoordinateElement *tce = NULL    103   const SoTextureCoordinateElement *tce = NULL;
105   SbVec4f texCoord;                               104   SbVec4f texCoord;
106   if (useTexFunction) {                           105   if (useTexFunction) {
107     tce = SoTextureCoordinateElement::getInsta    106     tce = SoTextureCoordinateElement::getInstance(state);
108   }                                               107   }
109   else {                                          108   else {
110     texCoord[2] = 0.0;                            109     texCoord[2] = 0.0;
111     texCoord[3] = 1.0;                            110     texCoord[3] = 1.0;
112   }                                               111   }
113   SbVec3f point, normal;                          112   SbVec3f point, normal;
114                                                   113 
115                                                   114 
116   //////////////////////////////////////////      115   //////////////////////////////////////////
117   //----------------------------------------      116   //----------------------------------------
118 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \      117 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
119   point.setValue(x,y,z);                   \      118   point.setValue(x,y,z);                   \
120   normal.setValue(nx,ny,nz);               \      119   normal.setValue(nx,ny,nz);               \
121   if (useTexFunction) {                    \      120   if (useTexFunction) {                    \
122     texCoord=tce->get(point,normal);       \      121     texCoord=tce->get(point,normal);       \
123   }                                        \      122   }                                        \
124   else {                                   \      123   else {                                   \
125     texCoord[0]=s;                         \      124     texCoord[0]=s;                         \
126     texCoord[1]=t;                         \      125     texCoord[1]=t;                         \
127   }                                        \      126   }                                        \
128   pv.setPoint(point);                      \      127   pv.setPoint(point);                      \
129   pv.setNormal(normal);                    \      128   pv.setNormal(normal);                    \
130   pv.setTextureCoords(texCoord);           \      129   pv.setTextureCoords(texCoord);           \
131   shapeVertex(&pv);                               130   shapeVertex(&pv);
132   //----------------------------------------      131   //----------------------------------------
133   //////////////////////////////////////////      132   //////////////////////////////////////////
134                                                   133 
135   const int NPOINTS=8, NFACES=6, NINDICES = NF    134   const int NPOINTS=8, NFACES=6, NINDICES = NFACES*5;
136   int indices[NINDICES] = {3,2,1,0, SO_END_FAC    135   int indices[NINDICES] = {3,2,1,0, SO_END_FACE_INDEX,  //z back.
137          4,5,6,7, SO_END_FACE_INDEX,  //z fron    136          4,5,6,7, SO_END_FACE_INDEX,  //z front.
138          0,1,5,4, SO_END_FACE_INDEX,  //y up.     137          0,1,5,4, SO_END_FACE_INDEX,  //y up.
139          1,2,6,5, SO_END_FACE_INDEX,  //x left    138          1,2,6,5, SO_END_FACE_INDEX,  //x left.
140          2,3,7,6, SO_END_FACE_INDEX,  //y down    139          2,3,7,6, SO_END_FACE_INDEX,  //y down.
141          3,0,4,7, SO_END_FACE_INDEX}; //x righ    140          3,0,4,7, SO_END_FACE_INDEX}; //x right.
142                                                   141 
143                                                   142   
144   // points for the eight vertices                143   // points for the eight vertices
145   float points[NPOINTS][3];                       144   float points[NPOINTS][3];
146   points[0][0] =  fDx.getValue();                 145   points[0][0] =  fDx.getValue(); 
147   points[0][1] =  fDy.getValue();                 146   points[0][1] =  fDy.getValue(); 
148   points[0][2] = -fDz.getValue();                 147   points[0][2] = -fDz.getValue();
149                                                   148 
150   points[1][0] = -fDx.getValue();                 149   points[1][0] = -fDx.getValue();
151   points[1][1] =  fDy.getValue();                 150   points[1][1] =  fDy.getValue();
152   points[1][2] = -fDz.getValue();                 151   points[1][2] = -fDz.getValue();
153                                                   152 
154   points[2][0] = -fDx.getValue();                 153   points[2][0] = -fDx.getValue(); 
155   points[2][1] = -fDy.getValue();                 154   points[2][1] = -fDy.getValue(); 
156   points[2][2] = -fDz.getValue();                 155   points[2][2] = -fDz.getValue();
157                                                   156 
158   points[3][0] =  fDx.getValue();                 157   points[3][0] =  fDx.getValue(); 
159   points[3][1] = -fDy.getValue();                 158   points[3][1] = -fDy.getValue(); 
160   points[3][2] = -fDz.getValue();                 159   points[3][2] = -fDz.getValue();
161                                                   160 
162   points[4][0] =  fDx.getValue();                 161   points[4][0] =  fDx.getValue(); 
163   points[4][1] =  fDy.getValue();                 162   points[4][1] =  fDy.getValue(); 
164   points[4][2] =  fDz.getValue();                 163   points[4][2] =  fDz.getValue();
165                                                   164 
166   points[5][0] = -fDx.getValue();                 165   points[5][0] = -fDx.getValue(); 
167   points[5][1] =  fDy.getValue();                 166   points[5][1] =  fDy.getValue(); 
168   points[5][2] =  fDz.getValue();                 167   points[5][2] =  fDz.getValue();
169                                                   168 
170   points[6][0] = -fDx.getValue();                 169   points[6][0] = -fDx.getValue(); 
171   points[6][1] = -fDy.getValue();                 170   points[6][1] = -fDy.getValue(); 
172   points[6][2] =  fDz.getValue();                 171   points[6][2] =  fDz.getValue();
173                                                   172 
174   points[7][0] =  fDx.getValue();                 173   points[7][0] =  fDx.getValue(); 
175   points[7][1] = -fDy.getValue();                 174   points[7][1] = -fDy.getValue(); 
176   points[7][2] =  fDz.getValue();                 175   points[7][2] =  fDz.getValue();
177                                                   176 
178   float normals[NFACES][3];                       177   float normals[NFACES][3];
179   //z back.                                       178   //z back.
180   normals[0][0] =  0  ; normals[0][1] =    0;     179   normals[0][0] =  0  ; normals[0][1] =    0; normals [0][2] =  -1;    
181   //z front.                                      180   //z front.
182   normals[1][0] =  0  ; normals[1][1] =    0;     181   normals[1][0] =  0  ; normals[1][1] =    0; normals [1][2] =   1;    
183   //y up.                                         182   //y up.
184   normals[2][0] =  0  ; normals[2][1] =    1;     183   normals[2][0] =  0  ; normals[2][1] =    1; normals [2][2] =   0;    
185   //x left.                                       184   //x left.
186   normals[3][0] = -1  ; normals[3][1] =    0;     185   normals[3][0] = -1  ; normals[3][1] =    0; normals [3][2] =   0;    
187   //y down.                                       186   //y down.
188   normals[4][0] =  0  ; normals[4][1] =   -1;     187   normals[4][0] =  0  ; normals[4][1] =   -1; normals [4][2] =   0;    
189   //x right.                                      188   //x right.
190   normals[5][0] =  1  ; normals[5][1] =    0;     189   normals[5][0] =  1  ; normals[5][1] =    0; normals [5][2] =   0;    
191                                                   190 
192   float x,y,z;                                    191   float x,y,z;
193   int   index;                                    192   int   index;
194   for (int nf=0;nf<NFACES;nf++) {                 193   for (int nf=0;nf<NFACES;nf++) {
195     beginShape(action,TRIANGLE_FAN);              194     beginShape(action,TRIANGLE_FAN);
196     index = indices[nf * 5];                      195     index = indices[nf * 5];   
197     x = points[index][0];                         196     x = points[index][0];
198     y = points[index][1];                         197     y = points[index][1];
199     z = points[index][2];                         198     z = points[index][2];
200     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    199     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
201     index = indices[nf * 5 + 1];                  200     index = indices[nf * 5 + 1];   
202     x = points[index][0];                         201     x = points[index][0];
203     y = points[index][1];                         202     y = points[index][1];
204     z = points[index][2];                         203     z = points[index][2];
205     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    204     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
206     index = indices[nf * 5 + 2];                  205     index = indices[nf * 5 + 2];   
207     x = points[index][0];                         206     x = points[index][0];
208     y = points[index][1];                         207     y = points[index][1];
209     z = points[index][2];                         208     z = points[index][2];
210     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    209     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
211     index = indices[nf * 5 + 3];                  210     index = indices[nf * 5 + 3];   
212     x = points[index][0];                         211     x = points[index][0];
213     y = points[index][1];                         212     y = points[index][1];
214     z = points[index][2];                         213     z = points[index][2];
215     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0]    214     GEN_VERTEX(pv,x,y,z,0.0,0.0,normals[nf][0],normals[nf][1],normals[nf][2]);   
216     endShape();                                   215     endShape();
217   }                                               216   }
218 }                                                 217 }
219                                                   218 
220 // getChildren                                    219 // getChildren
221 SoChildList *SoBox::getChildren() const {         220 SoChildList *SoBox::getChildren() const {
222   return children;                                221   return children;
223 }                                                 222 }
224                                                   223 
225                                                   224 
226 // computeBBox                                    225 // computeBBox
227 void SoBox::computeBBox(SoAction *, SbBox3f &b    226 void SoBox::computeBBox(SoAction *, SbBox3f &box, SbVec3f &center ){
228   SbVec3f vmin(-fDx.getValue(),-fDy.getValue()    227   SbVec3f vmin(-fDx.getValue(),-fDy.getValue(),-fDz.getValue()), 
229           vmax( fDx.getValue(), fDy.getValue()    228           vmax( fDx.getValue(), fDy.getValue(), fDz.getValue());
230   center.setValue(0,0,0);                         229   center.setValue(0,0,0);
231   box.setBounds(vmin,vmax);                       230   box.setBounds(vmin,vmax);
232 }                                                 231 }
233                                                   232 
234                                                   233 
235                                                   234 
236                                                   235 
237 // updateChildren                                 236 // updateChildren
238 void SoBox::updateChildren() {                    237 void SoBox::updateChildren() {
239                                                   238 
240                                                   239 
241   // Redraw the G4Box....                         240   // Redraw the G4Box....
242                                                   241 
243   assert(children->getLength()==1);               242   assert(children->getLength()==1);
244   SoSeparator       *sep                = (SoS    243   SoSeparator       *sep                = (SoSeparator *)  ( *children)[0];
245   SoScale           *scale              = (SoS    244   SoScale           *scale              = (SoScale *)( sep->getChild(0));
246   //SoCube            *cube               = (S    245   //SoCube            *cube               = (SoCube  *)( sep->getChild(1));
247   scale->scaleFactor.setValue(fDx.getValue(),     246   scale->scaleFactor.setValue(fDx.getValue(), fDy.getValue(), fDz.getValue());
248 }                                                 247 }
249                                                   248 
250 // generateChildren                               249 // generateChildren
251 void SoBox::generateChildren() {                  250 void SoBox::generateChildren() {
252                                                   251 
253   // A box consists of a set of scale factors     252   // A box consists of a set of scale factors and a 
254   // cube.                                        253   // cube.
255                                                   254 
256   assert(children->getLength() ==0);              255   assert(children->getLength() ==0);
257   SoSeparator      *sep              = new SoS    256   SoSeparator      *sep              = new SoSeparator(); 
258   SoScale          *scale            = new SoS    257   SoScale          *scale            = new SoScale();
259   SoCube           *cube             = new SoC    258   SoCube           *cube             = new SoCube();
260                                                   259 
261   sep->addChild(scale);                           260   sep->addChild(scale);
262   sep->addChild(cube);                            261   sep->addChild(cube);
263   children->append(sep);                          262   children->append(sep);
264 }                                                 263 }
265                                                   264 
266 // generateAlternateRep                           265 // generateAlternateRep
267 void SoBox::generateAlternateRep() {              266 void SoBox::generateAlternateRep() {
268                                                   267 
269   // This routine sets the alternate represent    268   // This routine sets the alternate representation to the child
270   // list of this mode.                           269   // list of this mode.  
271                                                   270 
272   if (children->getLength() == 0) generateChil    271   if (children->getLength() == 0) generateChildren();
273   updateChildren();                               272   updateChildren();
274   alternateRep.setValue((SoSeparator *)  ( *ch    273   alternateRep.setValue((SoSeparator *)  ( *children)[0]);
275 }                                                 274 }
276                                                   275 
277 // clearAlternateRep                              276 // clearAlternateRep
278 void SoBox::clearAlternateRep() {                 277 void SoBox::clearAlternateRep() {
279   alternateRep.setValue(NULL);                    278   alternateRep.setValue(NULL);
280 }                                                 279 }
                                                   >> 280 
                                                   >> 281 #endif
281                                                   282