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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 6.2)


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