Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenInventor/src/SoPolyhedron.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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/SoPolyhedron.cc (Version 11.3.0) and /visualization/OpenInventor/src/SoPolyhedron.cc (Version 9.1.p3)


  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 #ifdef G4VIS_BUILD_OI_DRIVER
                                                   >>  27 
 26 /*----------------------------HEPVis----------     28 /*----------------------------HEPVis----------------------------------------*/
 27 /*                                                 29 /*                                                                          */
 28 /* Node:             SoPolyhedron                  30 /* Node:             SoPolyhedron                                           */
 29 /* Description:      SoNode to represent HepPo     31 /* Description:      SoNode to represent HepPolyhedron                      */
 30 /* Author:           Guy Barrand                   32 /* Author:           Guy Barrand                                            */
 31 /*                                                 33 /*                                                                          */
 32 /*--------------------------------------------     34 /*--------------------------------------------------------------------------*/
 33                                                    35 
 34 // this :                                          36 // this :
 35 #include "Geant4_SoPolyhedron.h"                   37 #include "Geant4_SoPolyhedron.h"
 36                                                    38 
 37 #include <Inventor/SbBox.h>                        39 #include <Inventor/SbBox.h>
 38 #include <Inventor/actions/SoAction.h>             40 #include <Inventor/actions/SoAction.h>
 39 #include <Inventor/SoPrimitiveVertex.h>            41 #include <Inventor/SoPrimitiveVertex.h>
 40 #include <Inventor/elements/SoTextureCoordinat     42 #include <Inventor/elements/SoTextureCoordinateElement.h>
 41 #include <Inventor/nodes/SoSeparator.h>            43 #include <Inventor/nodes/SoSeparator.h>
 42                                                    44 
 43 //#include <HEPVis/SbMath.h>                       45 //#include <HEPVis/SbMath.h>
 44 #define SbMinimum(a,b) ((a)<(b)?a:b)               46 #define SbMinimum(a,b) ((a)<(b)?a:b)
 45 #define SbMaximum(a,b) ((a)>(b)?a:b)               47 #define SbMaximum(a,b) ((a)>(b)?a:b)
 46                                                    48 
 47 #include <HEPVis/actions/SoAlternateRepAction.     49 #include <HEPVis/actions/SoAlternateRepAction.h>
 48                                                    50 
 49 #include "G4Polyhedron.hh"                         51 #include "G4Polyhedron.hh"
 50                                                    52 
 51 //typedef SbVec3f HVPoint3D;                       53 //typedef SbVec3f HVPoint3D;
 52 //typedef SbVec3f HVNormal3D;                      54 //typedef SbVec3f HVNormal3D;
 53                                                    55 
 54 typedef HepGeom::Point3D<double> HVPoint3D;        56 typedef HepGeom::Point3D<double> HVPoint3D;
 55 typedef HepGeom::Normal3D<double> HVNormal3D;      57 typedef HepGeom::Normal3D<double> HVNormal3D;
 56                                                    58 
 57 SO_NODE_SOURCE(Geant4_SoPolyhedron)                59 SO_NODE_SOURCE(Geant4_SoPolyhedron) 
 58 //////////////////////////////////////////////     60 //////////////////////////////////////////////////////////////////////////////
 59 void Geant4_SoPolyhedron::initClass(               61 void Geant4_SoPolyhedron::initClass(
 60 )                                                  62 )
 61 //////////////////////////////////////////////     63 //////////////////////////////////////////////////////////////////////////////
 62 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     64 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 63 {                                                  65 {
 64   static bool first = true;                    <<  66   SO_NODE_INIT_CLASS(Geant4_SoPolyhedron,SoShape,"Shape");
 65   if (first) {                                 << 
 66     first = false;                             << 
 67     SO_NODE_INIT_CLASS(Geant4_SoPolyhedron,SoS << 
 68   }                                            << 
 69 }                                                  67 }
 70 //////////////////////////////////////////////     68 //////////////////////////////////////////////////////////////////////////////
 71 Geant4_SoPolyhedron::Geant4_SoPolyhedron(          69 Geant4_SoPolyhedron::Geant4_SoPolyhedron(
 72 )                                                  70 )
 73 :fPolyhedron(0)                                    71 :fPolyhedron(0)
 74 //////////////////////////////////////////////     72 //////////////////////////////////////////////////////////////////////////////
 75 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     73 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 76 {                                                  74 {
 77   SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);        75   SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);
 78   SO_NODE_ADD_FIELD(solid,(TRUE));                 76   SO_NODE_ADD_FIELD(solid,(TRUE));
 79   SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));      77   SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));
 80   SO_NODE_ADD_FIELD(alternateRep,(NULL));          78   SO_NODE_ADD_FIELD(alternateRep,(NULL));
 81 }                                                  79 }
 82 //////////////////////////////////////////////     80 //////////////////////////////////////////////////////////////////////////////
 83 Geant4_SoPolyhedron::Geant4_SoPolyhedron(          81 Geant4_SoPolyhedron::Geant4_SoPolyhedron(
 84  const G4Polyhedron& aPolyhedron                   82  const G4Polyhedron& aPolyhedron
 85 )                                                  83 )
 86 :fPolyhedron(0)                                    84 :fPolyhedron(0)
 87 //////////////////////////////////////////////     85 //////////////////////////////////////////////////////////////////////////////
 88 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     86 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 89 {                                                  87 {
 90   SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);        88   SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);
 91   SO_NODE_ADD_FIELD(solid,(TRUE));                 89   SO_NODE_ADD_FIELD(solid,(TRUE));
 92   SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));      90   SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));
 93   SO_NODE_ADD_FIELD(alternateRep,(NULL));          91   SO_NODE_ADD_FIELD(alternateRep,(NULL));
 94                                                    92 
 95   fPolyhedron = new G4Polyhedron(aPolyhedron);     93   fPolyhedron = new G4Polyhedron(aPolyhedron);
 96 }                                                  94 }
 97 //////////////////////////////////////////////     95 //////////////////////////////////////////////////////////////////////////////
 98 Geant4_SoPolyhedron::Geant4_SoPolyhedron(          96 Geant4_SoPolyhedron::Geant4_SoPolyhedron(
 99  G4Polyhedron* aPolyhedron                         97  G4Polyhedron* aPolyhedron
100 )                                                  98 )
101 :fPolyhedron(aPolyhedron)                          99 :fPolyhedron(aPolyhedron)
102 //////////////////////////////////////////////    100 //////////////////////////////////////////////////////////////////////////////
103 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    101 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
104 {                                                 102 {
105   SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);       103   SO_NODE_CONSTRUCTOR(Geant4_SoPolyhedron);
106   SO_NODE_ADD_FIELD(solid,(TRUE));                104   SO_NODE_ADD_FIELD(solid,(TRUE));
107   SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));     105   SO_NODE_ADD_FIELD(reducedWireFrame,(TRUE));
108   SO_NODE_ADD_FIELD(alternateRep,(NULL));         106   SO_NODE_ADD_FIELD(alternateRep,(NULL));
109 }                                                 107 }
110 //////////////////////////////////////////////    108 //////////////////////////////////////////////////////////////////////////////
111 Geant4_SoPolyhedron::~Geant4_SoPolyhedron(        109 Geant4_SoPolyhedron::~Geant4_SoPolyhedron(
112 )                                                 110 )
113 //////////////////////////////////////////////    111 //////////////////////////////////////////////////////////////////////////////
114 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    112 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
115 {                                                 113 {
116   delete fPolyhedron;                             114   delete fPolyhedron;
117 }                                                 115 }
118 //////////////////////////////////////////////    116 //////////////////////////////////////////////////////////////////////////////
119 void Geant4_SoPolyhedron::generatePrimitives(     117 void Geant4_SoPolyhedron::generatePrimitives(
120  SoAction* aAction                                118  SoAction* aAction
121 )                                                 119 ) 
122 //////////////////////////////////////////////    120 //////////////////////////////////////////////////////////////////////////////
123 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    121 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
124 {                                                 122 {
125   if(!fPolyhedron) return;                        123   if(!fPolyhedron) return;
126   if(fPolyhedron->GetNoFacets()<=0) return; //    124   if(fPolyhedron->GetNoFacets()<=0) return; // Abnormal polyhedron.
127                                                   125 
128   SoState *state = aAction->getState();           126   SoState *state = aAction->getState();
129   SbBool useTexFunction =                         127   SbBool useTexFunction =
130     (SoTextureCoordinateElement::getType(state    128     (SoTextureCoordinateElement::getType(state) == 
131      SoTextureCoordinateElement::FUNCTION);       129      SoTextureCoordinateElement::FUNCTION);
132   const SoTextureCoordinateElement *tce = NULL    130   const SoTextureCoordinateElement *tce = NULL;
133   SbVec4f texCoord(0.,0.,0.,0.);                  131   SbVec4f texCoord(0.,0.,0.,0.);
134   if (useTexFunction) {                           132   if (useTexFunction) {
135     tce = SoTextureCoordinateElement::getInsta    133     tce = SoTextureCoordinateElement::getInstance(state);
136   } else {                                        134   } else {
137     texCoord[2] = 0.0;                            135     texCoord[2] = 0.0;
138     texCoord[3] = 1.0;                            136     texCoord[3] = 1.0;
139   }                                               137   }
140                                                   138 
141   if(solid.getValue()==TRUE) {                    139   if(solid.getValue()==TRUE) {
142     SoPrimitiveVertex pv;                         140     SoPrimitiveVertex pv;
143     SbVec3f point, normal;                        141     SbVec3f point, normal;
144     //////////////////////////////////////////    142     //////////////////////////////////////////
145     //----------------------------------------    143     //----------------------------------------
146 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \      144 #define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz)  \
147   point.setValue(x,y,z);                   \      145   point.setValue(x,y,z);                   \
148   normal.setValue(nx,ny,nz);               \      146   normal.setValue(nx,ny,nz);               \
149   if (useTexFunction) {                    \      147   if (useTexFunction) {                    \
150     texCoord=tce->get(point,normal);       \      148     texCoord=tce->get(point,normal);       \
151   } else {                                 \      149   } else {                                 \
152     texCoord[0]=s;                         \      150     texCoord[0]=s;                         \
153     texCoord[1]=t;                         \      151     texCoord[1]=t;                         \
154   }                                        \      152   }                                        \
155   pv.setPoint(point);                      \      153   pv.setPoint(point);                      \
156   pv.setNormal(normal);                    \      154   pv.setNormal(normal);                    \
157   pv.setTextureCoords(texCoord);           \      155   pv.setTextureCoords(texCoord);           \
158   shapeVertex(&pv);                               156   shapeVertex(&pv);
159   //----------------------------------------      157   //----------------------------------------
160   //////////////////////////////////////////      158   //////////////////////////////////////////
161                                                   159 
162     // Assume all facets are convex quadrilate    160     // Assume all facets are convex quadrilaterals :
163     bool notLastFace;                             161     bool notLastFace;
164     do {                                          162     do {
165       HVNormal3D unitNormal;                      163       HVNormal3D unitNormal;
166       notLastFace = fPolyhedron->GetNextUnitNo    164       notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
167                                                   165 
168       beginShape(aAction,POLYGON);                166       beginShape(aAction,POLYGON);
169       bool notLastEdge;                           167       bool notLastEdge;
170       int edgeFlag = 1;                           168       int edgeFlag = 1;
171       do {                                        169       do {
172         HVPoint3D vertex;                         170         HVPoint3D vertex;
173         notLastEdge = fPolyhedron->GetNextVert    171         notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
174         GEN_VERTEX(pv,                            172         GEN_VERTEX(pv,
175                    vertex[0],                     173                    vertex[0],
176                    vertex[1],                     174                    vertex[1],
177                    vertex[2],                     175                    vertex[2],
178                    0.0,0.0,                       176                    0.0,0.0,
179                    unitNormal[0],                 177                    unitNormal[0],
180                    unitNormal[1],                 178                    unitNormal[1],
181                    unitNormal[2]);                179                    unitNormal[2]);
182       } while (notLastEdge);                      180       } while (notLastEdge);
183       endShape();                                 181       endShape();
184     } while (notLastFace);                        182     } while (notLastFace);
185   } else {                                        183   } else {
186     SoPrimitiveVertex pvb,pve;                    184     SoPrimitiveVertex pvb,pve;
187     pve.setTextureCoords(texCoord);               185     pve.setTextureCoords(texCoord);
188     pvb.setTextureCoords(texCoord);               186     pvb.setTextureCoords(texCoord);
189                                                   187 
190 #ifdef __COIN__ // To bypass a bug in invokeLi    188 #ifdef __COIN__ // To bypass a bug in invokeLineSegment when picking.
191     beginShape(aAction,POLYGON);                  189     beginShape(aAction,POLYGON);
192     endShape();                                   190     endShape();
193 #endif                                            191 #endif
194                                                   192 
195     SbVec3f point;                                193     SbVec3f point;
196     bool notLastFace;                             194     bool notLastFace;
197     do {                                          195     do {
198       HVNormal3D unitNormal;                      196       HVNormal3D unitNormal;
199       notLastFace = fPolyhedron->GetNextUnitNo    197       notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
200                                                   198 
201       SbVec3f normal;                             199       SbVec3f normal;
202       normal.setValue(unitNormal[0],unitNormal    200       normal.setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
203                                                   201 
204       // Treat edges :                            202       // Treat edges :
205       int edgeFlag = 1;                           203       int edgeFlag = 1;
206       int prevEdgeFlag = edgeFlag;                204       int prevEdgeFlag = edgeFlag;
207       bool notLastEdge;                           205       bool notLastEdge;
208       SbBool firstEdge = TRUE;                    206       SbBool firstEdge = TRUE;
209       do {                                        207       do {
210         HVPoint3D vertex;                         208         HVPoint3D vertex;
211         notLastEdge = fPolyhedron->GetNextVert    209         notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
212         if(reducedWireFrame.getValue()==FALSE)    210         if(reducedWireFrame.getValue()==FALSE) edgeFlag = 1;        
213         if(firstEdge) {                           211         if(firstEdge) {
214           if(edgeFlag > 0) {                      212           if(edgeFlag > 0) {
215             pvb.setNormal(normal);                213             pvb.setNormal(normal);
216             point.setValue(vertex[0],vertex[1]    214             point.setValue(vertex[0],vertex[1],vertex[2]);
217             pvb.setPoint(point);                  215             pvb.setPoint(point);
218           } else {                                216           } else {
219           }                                       217           }
220           firstEdge = FALSE;                      218           firstEdge = FALSE;
221           prevEdgeFlag = edgeFlag;                219           prevEdgeFlag = edgeFlag;
222         } else {                                  220         } else {
223           if(edgeFlag!=prevEdgeFlag) {            221           if(edgeFlag!=prevEdgeFlag) { 
224             if(edgeFlag > 0) { // Pass to a vi    222             if(edgeFlag > 0) { // Pass to a visible edge :
225               pvb.setNormal(normal);              223               pvb.setNormal(normal);
226               point.setValue(vertex[0],vertex[    224               point.setValue(vertex[0],vertex[1],vertex[2]);
227               pvb.setPoint(point);                225               pvb.setPoint(point);
228             } else { // Pass to an invisible e    226             } else { // Pass to an invisible edge :
229               pve.setNormal(normal);              227               pve.setNormal(normal);
230               point.setValue(vertex[0],vertex[    228               point.setValue(vertex[0],vertex[1],vertex[2]);
231               pve.setPoint(point);                229               pve.setPoint(point);
232               invokeLineSegmentCallbacks(aActi    230               invokeLineSegmentCallbacks(aAction,&pvb,&pve);
233             }                                     231             }
234             prevEdgeFlag = edgeFlag;              232             prevEdgeFlag = edgeFlag;
235           } else {                                233           } else {
236             if(edgeFlag > 0) {                    234             if(edgeFlag > 0) {
237               pve.setNormal(normal);              235               pve.setNormal(normal);
238               point.setValue(vertex[0],vertex[    236               point.setValue(vertex[0],vertex[1],vertex[2]);
239               pve.setPoint(point);                237               pve.setPoint(point);
240               invokeLineSegmentCallbacks(aActi    238               invokeLineSegmentCallbacks(aAction,&pvb,&pve);
241               pvb = pve;                          239               pvb = pve;
242             } else {                              240             } else {
243             }                                     241             }
244           }                                       242           }
245         }                                         243         }
246       } while (notLastEdge);                      244       } while (notLastEdge);
247     } while (notLastFace);                        245     } while (notLastFace);
248   }                                               246   }
249                                                   247 
250 }                                                 248 }
251 //////////////////////////////////////////////    249 //////////////////////////////////////////////////////////////////////////////
252 void Geant4_SoPolyhedron::computeBBox(            250 void Geant4_SoPolyhedron::computeBBox(
253  SoAction*                                        251  SoAction*
254 ,SbBox3f& aBox                                    252 ,SbBox3f& aBox
255 ,SbVec3f& aCenter                                 253 ,SbVec3f& aCenter
256 )                                                 254 )
257 //////////////////////////////////////////////    255 //////////////////////////////////////////////////////////////////////////////
258 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    256 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
259 {                                                 257 {
260   if(!fPolyhedron) return;                        258   if(!fPolyhedron) return;
261   if(fPolyhedron->GetNoFacets()<=0) { // Abnor    259   if(fPolyhedron->GetNoFacets()<=0) { // Abnormal polyhedron.
262     SbVec3f vmin(-1,-1,-1);                       260     SbVec3f vmin(-1,-1,-1);
263     SbVec3f vmax( 1, 1, 1);                       261     SbVec3f vmax( 1, 1, 1);
264     aBox.setBounds(vmin,vmax);                    262     aBox.setBounds(vmin,vmax);
265     aCenter.setValue(0,0,0);                      263     aCenter.setValue(0,0,0);
266   } else {                                        264   } else {
267     SbBool first = TRUE;                          265     SbBool first = TRUE;
268     float xmn = 0,ymn = 0,zmn = 0;                266     float xmn = 0,ymn = 0,zmn = 0;
269     float xmx = 0,ymx = 0,zmx = 0;                267     float xmx = 0,ymx = 0,zmx = 0;
270     float xct = 0,yct = 0,zct = 0;                268     float xct = 0,yct = 0,zct = 0;
271     SbVec3f point;                                269     SbVec3f point;
272     int count = 0;                                270     int count = 0;
273     // Assume all facets are convex quadrilate    271     // Assume all facets are convex quadrilaterals :
274     bool notLastFace;                             272     bool notLastFace;
275     do {                                          273     do {
276       HVNormal3D unitNormal;                      274       HVNormal3D unitNormal;
277       notLastFace = fPolyhedron->GetNextUnitNo    275       notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
278       bool notLastEdge;                           276       bool notLastEdge;
279       do {                                        277       do {
280         HVPoint3D vertex;                         278         HVPoint3D vertex;
281         int edgeFlag = 1;                         279         int edgeFlag = 1;
282         notLastEdge = fPolyhedron->GetNextVert    280         notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
283         point.setValue(vertex[0],vertex[1],ver    281         point.setValue(vertex[0],vertex[1],vertex[2]);
284         if(first==TRUE) {                         282         if(first==TRUE) {
285           xct = xmx = xmn = point[0];             283           xct = xmx = xmn = point[0];
286           yct = ymx = ymn = point[1];             284           yct = ymx = ymn = point[1];
287           zct = zmx = zmn = point[2];             285           zct = zmx = zmn = point[2];
288           count++;                                286           count++;
289           first = FALSE;                          287           first = FALSE;
290         } else {                                  288         } else {
291           xmn = SbMinimum(xmn,point[0]);          289           xmn = SbMinimum(xmn,point[0]);
292           ymn = SbMinimum(ymn,point[1]);          290           ymn = SbMinimum(ymn,point[1]);
293           zmn = SbMinimum(zmn,point[2]);          291           zmn = SbMinimum(zmn,point[2]);
294           //                                      292           //
295           xmx = SbMaximum(xmx,point[0]);          293           xmx = SbMaximum(xmx,point[0]);
296           ymx = SbMaximum(ymx,point[1]);          294           ymx = SbMaximum(ymx,point[1]);
297           zmx = SbMaximum(zmx,point[2]);          295           zmx = SbMaximum(zmx,point[2]);
298           //                                      296           //
299           xct += point[0];                        297           xct += point[0];
300           yct += point[1];                        298           yct += point[1];
301           zct += point[2];                        299           zct += point[2];
302           count++;                                300           count++;
303         }                                         301         }
304         //                                        302         //
305       } while (notLastEdge);                      303       } while (notLastEdge);
306     } while (notLastFace);                        304     } while (notLastFace);
307     SbVec3f vmin(xmn,ymn,zmn);                    305     SbVec3f vmin(xmn,ymn,zmn);
308     SbVec3f vmax(xmx,ymx,zmx);                    306     SbVec3f vmax(xmx,ymx,zmx);
309     aBox.setBounds(vmin,vmax);                    307     aBox.setBounds(vmin,vmax);
310     if(count==0)                                  308     if(count==0)
311       aCenter.setValue(0,0,0);                    309       aCenter.setValue(0,0,0);
312     else                                          310     else
313       aCenter.setValue(xct/count,yct/count,zct    311       aCenter.setValue(xct/count,yct/count,zct/count);
314   }                                               312   }
315 }                                                 313 }
316                                                   314 
317 #include <Inventor/nodes/SoNormalBinding.h>       315 #include <Inventor/nodes/SoNormalBinding.h>
318 #include <Inventor/nodes/SoNormal.h>              316 #include <Inventor/nodes/SoNormal.h>
319 #include <Inventor/nodes/SoCoordinate3.h>         317 #include <Inventor/nodes/SoCoordinate3.h>
320 #include <Inventor/nodes/SoIndexedFaceSet.h>      318 #include <Inventor/nodes/SoIndexedFaceSet.h>
321 #include <Inventor/nodes/SoIndexedLineSet.h>      319 #include <Inventor/nodes/SoIndexedLineSet.h>
322 //////////////////////////////////////////////    320 //////////////////////////////////////////////////////////////////////////////
323 void Geant4_SoPolyhedron::generateAlternateRep    321 void Geant4_SoPolyhedron::generateAlternateRep(
324 )                                                 322 ) 
325 //////////////////////////////////////////////    323 //////////////////////////////////////////////////////////////////////////////
326 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    324 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
327 {                                                 325 {
328   if(!fPolyhedron) return;                        326   if(!fPolyhedron) return;
329   if(fPolyhedron->GetNoFacets()<=0) return; //    327   if(fPolyhedron->GetNoFacets()<=0) return; // Abnormal polyhedron.
330   if(fPolyhedron->GetNoVertices()<=0) return;     328   if(fPolyhedron->GetNoVertices()<=0) return; // Abnormal polyhedron.
331                                                   329 
332   if(solid.getValue()==TRUE) {                    330   if(solid.getValue()==TRUE) {
333                                                   331 
334     SoSeparator* separator = new SoSeparator;     332     SoSeparator* separator = new SoSeparator;
335                                                   333 
336     SoNormalBinding* normalBinding = new SoNor    334     SoNormalBinding* normalBinding = new SoNormalBinding;
337     normalBinding->value = SoNormalBinding::PE    335     normalBinding->value = SoNormalBinding::PER_FACE;
338     separator->addChild(normalBinding);           336     separator->addChild(normalBinding);
339                                                   337 
340     SoCoordinate3* coordinate3 = new SoCoordin    338     SoCoordinate3* coordinate3 = new SoCoordinate3;
341     separator->addChild(coordinate3);             339     separator->addChild(coordinate3);
342     SoNormal* normal = new SoNormal;              340     SoNormal* normal = new SoNormal;
343     separator->addChild(normal);                  341     separator->addChild(normal);
344     SoIndexedFaceSet* indexedFaceSet = new SoI    342     SoIndexedFaceSet* indexedFaceSet = new SoIndexedFaceSet;
345     separator->addChild(indexedFaceSet);          343     separator->addChild(indexedFaceSet);
346                                                   344 
                                                   >> 345     SbBool empty = TRUE;
                                                   >> 346 
347     int nvert = fPolyhedron->GetNoVertices();     347     int nvert = fPolyhedron->GetNoVertices();
348     int nface = fPolyhedron->GetNoFacets();       348     int nface = fPolyhedron->GetNoFacets();
349                                                   349 
350     SbVec3f* normals = new SbVec3f[nface];        350     SbVec3f* normals = new SbVec3f[nface];
351     //FIXME : have the exact booking.             351     //FIXME : have the exact booking.
352     SbVec3f* points = new SbVec3f[nvert];         352     SbVec3f* points = new SbVec3f[nvert];
353     int32_t* coords = new int32_t[nvert+1];       353     int32_t* coords = new int32_t[nvert+1];
354                                                   354 
355     int inormal = 0;                              355     int inormal = 0;
356     int icoord = 0;                               356     int icoord = 0;
357     int iindex = 0;                               357     int iindex = 0;
358                                                   358 
359     // Assume all facets are convex quadrilate    359     // Assume all facets are convex quadrilaterals :
360     bool notLastFace;                             360     bool notLastFace;
361     do {                                          361     do {
362       HVNormal3D unitNormal;                      362       HVNormal3D unitNormal;
363       notLastFace = fPolyhedron->GetNextUnitNo    363       notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
364                                                   364 
365       // begin face POLYGON                       365       // begin face POLYGON
366       int ipoint = 0;                             366       int ipoint = 0;
367                                                   367 
368       bool notLastEdge;                           368       bool notLastEdge;
369       int edgeFlag = 1;                           369       int edgeFlag = 1;
370       do {                                        370       do {
371         HVPoint3D vertex;                         371         HVPoint3D vertex;
372         notLastEdge = fPolyhedron->GetNextVert    372         notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
373         points[ipoint].setValue(vertex[0],vert    373         points[ipoint].setValue(vertex[0],vertex[1],vertex[2]);
374         coords[ipoint] = icoord + ipoint;         374         coords[ipoint] = icoord + ipoint;
375         ipoint++;                                 375         ipoint++;
                                                   >> 376         empty = FALSE;
                                                   >> 377 
376       } while (notLastEdge);                      378       } while (notLastEdge);
377                                                   379 
378       // end face.                                380       // end face.
379       coords[ipoint] = SO_END_FACE_INDEX;         381       coords[ipoint] = SO_END_FACE_INDEX;
380       coordinate3->point.setValues(icoord,ipoi    382       coordinate3->point.setValues(icoord,ipoint,points);
381       icoord += ipoint;                           383       icoord += ipoint;
382                                                   384 
383       normals[inormal].setValue(unitNormal[0],    385       normals[inormal].setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
384       inormal++;                                  386       inormal++;  
385                                                   387 
386       indexedFaceSet->coordIndex.setValues(iin    388       indexedFaceSet->coordIndex.setValues(iindex,(ipoint+1),coords);
387       iindex += ipoint+1;                         389       iindex += ipoint+1;
388                                                   390 
389     } while (notLastFace);                        391     } while (notLastFace);
390                                                   392 
391     normal->vector.setValues(0,inormal,normals    393     normal->vector.setValues(0,inormal,normals);
392                                                   394 
393     delete [] normals;                            395     delete [] normals;
394     delete [] coords;                             396     delete [] coords;
395     delete [] points;                             397     delete [] points;
396                                                   398 
397     alternateRep.setValue(separator);          << 399     if(empty==TRUE) {
                                                   >> 400       separator->unref();
                                                   >> 401     } else {
                                                   >> 402       alternateRep.setValue(separator);
                                                   >> 403     }
398                                                   404 
399   } else {                                        405   } else {
400                                                   406 
401     SoSeparator* separator = new SoSeparator;     407     SoSeparator* separator = new SoSeparator;
402                                                   408 
403     int nvert = fPolyhedron->GetNoVertices();     409     int nvert = fPolyhedron->GetNoVertices();
404                                                   410 
405     //FIXME : have the exact booking.             411     //FIXME : have the exact booking.
406     int nedge = nvert * 3;                        412     int nedge = nvert * 3;
407     int npoint = nedge*2;                         413     int npoint = nedge*2;
408     SbVec3f* points = new SbVec3f[npoint];        414     SbVec3f* points = new SbVec3f[npoint];
409     int ncoord = nedge*3;                         415     int ncoord = nedge*3;
410     int32_t* coords = new int32_t[ncoord];        416     int32_t* coords = new int32_t[ncoord];
411                                                   417 
412     SbVec3f pvb(0.,0.,0.), pve(0.,0.,0.);         418     SbVec3f pvb(0.,0.,0.), pve(0.,0.,0.);
413                                                   419 
414     SbBool empty = TRUE;                          420     SbBool empty = TRUE;
415     int ipoint = 0;                               421     int ipoint = 0;
416     int icoord = 0;                               422     int icoord = 0;
417                                                   423 
418     bool notLastFace;                             424     bool notLastFace;
419     do {                                          425     do {
420       HVNormal3D unitNormal;                      426       HVNormal3D unitNormal;
421       notLastFace = fPolyhedron->GetNextUnitNo    427       notLastFace = fPolyhedron->GetNextUnitNormal(unitNormal);
422                                                   428 
423       //SbVec3f normal;                           429       //SbVec3f normal;
424       //if( (fProjection==SbProjectionRZ) || (    430       //if( (fProjection==SbProjectionRZ) || (fProjection==SbProjectionZR) ) {
425         //normal.setValue(0,0,1);                 431         //normal.setValue(0,0,1);
426       //} else {                                  432       //} else {
427         //normal.setValue(unitNormal[0],unitNo    433         //normal.setValue(unitNormal[0],unitNormal[1],unitNormal[2]);
428       //}                                         434       //}
429                                                   435 
430       // Treat edges :                            436       // Treat edges :
431       int edgeFlag = 1;                           437       int edgeFlag = 1;
432       int prevEdgeFlag = edgeFlag;                438       int prevEdgeFlag = edgeFlag;
433       bool notLastEdge;                           439       bool notLastEdge;
434       SbBool firstEdge = TRUE;                    440       SbBool firstEdge = TRUE;
435       do {                                        441       do {
436         HVPoint3D vertex;                         442         HVPoint3D vertex;
437         notLastEdge = fPolyhedron->GetNextVert    443         notLastEdge = fPolyhedron->GetNextVertex(vertex,edgeFlag);
438         if(reducedWireFrame.getValue()==FALSE)    444         if(reducedWireFrame.getValue()==FALSE) edgeFlag = 1;        
439         if(firstEdge) {                           445         if(firstEdge) {
440           if(edgeFlag > 0) {                      446           if(edgeFlag > 0) {
441             pvb.setValue(vertex[0],vertex[1],v    447             pvb.setValue(vertex[0],vertex[1],vertex[2]);
442           } else {                                448           } else {
443           }                                       449           }
444           firstEdge = FALSE;                      450           firstEdge = FALSE;
445           prevEdgeFlag = edgeFlag;                451           prevEdgeFlag = edgeFlag;
446         } else {                                  452         } else {
447           if(edgeFlag!=prevEdgeFlag) {            453           if(edgeFlag!=prevEdgeFlag) { 
448             if(edgeFlag > 0) { // Pass to a vi    454             if(edgeFlag > 0) { // Pass to a visible edge :
449               pvb.setValue(vertex[0],vertex[1]    455               pvb.setValue(vertex[0],vertex[1],vertex[2]);
450             } else { // Pass to an invisible e    456             } else { // Pass to an invisible edge :
451               pve.setValue(vertex[0],vertex[1]    457               pve.setValue(vertex[0],vertex[1],vertex[2]);
452                                                   458 
453               if((ipoint+1)>=npoint) {            459               if((ipoint+1)>=npoint) {
454                 int new_npoint = 2 * npoint;      460                 int new_npoint = 2 * npoint;
455                 SbVec3f* new_points = new SbVe    461                 SbVec3f* new_points = new SbVec3f[new_npoint];
456                 for(int i=0;i<npoint;i++) new_    462                 for(int i=0;i<npoint;i++) new_points[i] = points[i];
457                 delete [] points;                 463                 delete [] points;
458                 npoint = new_npoint;              464                 npoint = new_npoint;
459                 points = new_points;              465                 points = new_points;
460               }                                   466               }
461                                                   467 
462               if((icoord+2)>=ncoord) {            468               if((icoord+2)>=ncoord) {
463                 int new_ncoord = 2 * ncoord;      469                 int new_ncoord = 2 * ncoord;
464                 int32_t* new_coords = new int3    470                 int32_t* new_coords = new int32_t[new_ncoord];
465                 for(int i=0;i<ncoord;i++) new_    471                 for(int i=0;i<ncoord;i++) new_coords[i] = coords[i];
466                 delete [] coords;                 472                 delete [] coords;
467                 ncoord = new_ncoord;              473                 ncoord = new_ncoord;
468                 coords = new_coords;              474                 coords = new_coords;
469               }                                   475               }
470                                                   476 
471               points[ipoint+0] = pvb;             477               points[ipoint+0] = pvb;
472               points[ipoint+1] = pve;             478               points[ipoint+1] = pve;
473               coords[icoord+0] = ipoint + 0;      479               coords[icoord+0] = ipoint + 0;
474               coords[icoord+1] = ipoint + 1;      480               coords[icoord+1] = ipoint + 1;
475               coords[icoord+2] = SO_END_LINE_I    481               coords[icoord+2] = SO_END_LINE_INDEX;
476               ipoint += 2;                        482               ipoint += 2;
477               icoord += 3;                        483               icoord += 3;
478               empty = FALSE;                      484               empty = FALSE;
479             }                                     485             }
480             prevEdgeFlag = edgeFlag;              486             prevEdgeFlag = edgeFlag;
481           } else {                                487           } else {
482             if(edgeFlag > 0) {                    488             if(edgeFlag > 0) {
483               pve.setValue(vertex[0],vertex[1]    489               pve.setValue(vertex[0],vertex[1],vertex[2]);
484                                                   490 
485               if((ipoint+1)>=npoint) {            491               if((ipoint+1)>=npoint) {
486                 int new_npoint = 2 * npoint;      492                 int new_npoint = 2 * npoint;
487                 SbVec3f* new_points = new SbVe    493                 SbVec3f* new_points = new SbVec3f[new_npoint];
488                 for(int i=0;i<npoint;i++) new_    494                 for(int i=0;i<npoint;i++) new_points[i] = points[i];
489                 delete [] points;                 495                 delete [] points;
490                 npoint = new_npoint;              496                 npoint = new_npoint;
491                 points = new_points;              497                 points = new_points;
492               }                                   498               }
493                                                   499 
494               if((icoord+2)>=ncoord) {            500               if((icoord+2)>=ncoord) {
495                 int new_ncoord = 2 * ncoord;      501                 int new_ncoord = 2 * ncoord;
496                 int32_t* new_coords = new int3    502                 int32_t* new_coords = new int32_t[new_ncoord];
497                 for(int i=0;i<ncoord;i++) new_    503                 for(int i=0;i<ncoord;i++) new_coords[i] = coords[i];
498                 delete [] coords;                 504                 delete [] coords;
499                 ncoord = new_ncoord;              505                 ncoord = new_ncoord;
500                 coords = new_coords;              506                 coords = new_coords;
501               }                                   507               }
502                                                   508 
503               points[ipoint+0] = pvb;             509               points[ipoint+0] = pvb;
504               points[ipoint+1] = pve;             510               points[ipoint+1] = pve;
505               coords[icoord+0] = ipoint + 0;      511               coords[icoord+0] = ipoint + 0;
506               coords[icoord+1] = ipoint + 1;      512               coords[icoord+1] = ipoint + 1;
507               coords[icoord+2] = SO_END_LINE_I    513               coords[icoord+2] = SO_END_LINE_INDEX;
508               ipoint += 2;                        514               ipoint += 2;
509               icoord += 3;                        515               icoord += 3;
510               empty = FALSE;                      516               empty = FALSE;
511                                                   517 
512               pvb = pve;                          518               pvb = pve;
513             } else {                              519             } else {
514             }                                     520             }
515           }                                       521           }
516         }                                         522         }
517       } while (notLastEdge);                      523       } while (notLastEdge);
518     } while (notLastFace);                        524     } while (notLastFace);
519                                                   525 
520     SoCoordinate3* coordinate3 = new SoCoordin    526     SoCoordinate3* coordinate3 = new SoCoordinate3;
521     coordinate3->point.setValues(0,ipoint,poin    527     coordinate3->point.setValues(0,ipoint,points);
522     separator->addChild(coordinate3);             528     separator->addChild(coordinate3);
523                                                   529 
524     SoIndexedLineSet* indexedLineSet = new SoI    530     SoIndexedLineSet* indexedLineSet = new SoIndexedLineSet;
525     indexedLineSet->coordIndex.setValues(0,ico    531     indexedLineSet->coordIndex.setValues(0,icoord,coords);
526     separator->addChild(indexedLineSet);          532     separator->addChild(indexedLineSet);
527                                                   533 
528     delete [] coords;                             534     delete [] coords;
529     delete [] points;                             535     delete [] points;
530                                                   536 
531     if(empty==TRUE) {                             537     if(empty==TRUE) {
532       separator->unref();                         538       separator->unref();
533     } else {                                      539     } else {
534       alternateRep.setValue(separator);           540       alternateRep.setValue(separator);
535     }                                             541     }
536   }                                               542   }
537 }                                                 543 }
538 //////////////////////////////////////////////    544 //////////////////////////////////////////////////////////////////////////////
539 void Geant4_SoPolyhedron::clearAlternateRep(      545 void Geant4_SoPolyhedron::clearAlternateRep(
540 )                                                 546 ) 
541 //////////////////////////////////////////////    547 //////////////////////////////////////////////////////////////////////////////
542 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    548 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
543 {                                                 549 {
544   alternateRep.setValue(NULL);                    550   alternateRep.setValue(NULL);
545 }                                                 551 }
546 //////////////////////////////////////////////    552 //////////////////////////////////////////////////////////////////////////////
547 void Geant4_SoPolyhedron::doAction(               553 void Geant4_SoPolyhedron::doAction(
548  SoAction* aAction                                554  SoAction* aAction
549 )                                                 555 )
550 //////////////////////////////////////////////    556 //////////////////////////////////////////////////////////////////////////////
551 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    557 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
552 {                                                 558 {
553   SO_ALTERNATEREP_DO_ACTION(aAction)              559   SO_ALTERNATEREP_DO_ACTION(aAction)
554   SoShape::doAction(aAction);                     560   SoShape::doAction(aAction);
555 }                                                 561 }
                                                   >> 562 
                                                   >> 563 #endif
556                                                   564