Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenInventorSceneHandler.cc,v 1.53 2007/04/03 13:35:48 allison Exp $ >> 28 // GEANT4 tag $Name: geant4-09-00 $ 27 // 29 // 28 // 30 // 29 // Jeff Kallenbach 01 Aug 1996 31 // Jeff Kallenbach 01 Aug 1996 30 // OpenInventor stored scene - creates OpenInv 32 // OpenInventor stored scene - creates OpenInventor display lists. >> 33 #ifdef G4VIS_BUILD_OI_DRIVER 31 34 32 // this : 35 // this : 33 #include "G4OpenInventorSceneHandler.hh" 36 #include "G4OpenInventorSceneHandler.hh" 34 37 35 #include <Inventor/SoPath.h> 38 #include <Inventor/SoPath.h> 36 #include <Inventor/SoNodeKitPath.h> 39 #include <Inventor/SoNodeKitPath.h> 37 #include <Inventor/nodes/SoCoordinate3.h> 40 #include <Inventor/nodes/SoCoordinate3.h> 38 #include <Inventor/nodes/SoCoordinate4.h> 41 #include <Inventor/nodes/SoCoordinate4.h> 39 #include <Inventor/nodes/SoSeparator.h> 42 #include <Inventor/nodes/SoSeparator.h> 40 #include <Inventor/nodes/SoDrawStyle.h> 43 #include <Inventor/nodes/SoDrawStyle.h> 41 #include <Inventor/nodes/SoLightModel.h> 44 #include <Inventor/nodes/SoLightModel.h> 42 #include <Inventor/nodes/SoMaterial.h> 45 #include <Inventor/nodes/SoMaterial.h> 43 #include <Inventor/nodes/SoLineSet.h> 46 #include <Inventor/nodes/SoLineSet.h> 44 #include <Inventor/nodes/SoCube.h> 47 #include <Inventor/nodes/SoCube.h> >> 48 #include <Inventor/nodes/SoSphere.h> 45 #include <Inventor/nodes/SoFont.h> 49 #include <Inventor/nodes/SoFont.h> 46 #include <Inventor/nodes/SoText2.h> 50 #include <Inventor/nodes/SoText2.h> 47 #include <Inventor/nodes/SoFaceSet.h> 51 #include <Inventor/nodes/SoFaceSet.h> 48 #include <Inventor/nodes/SoNormal.h> 52 #include <Inventor/nodes/SoNormal.h> 49 #include <Inventor/nodes/SoNormalBinding.h> 53 #include <Inventor/nodes/SoNormalBinding.h> 50 #include <Inventor/nodes/SoComplexity.h> 54 #include <Inventor/nodes/SoComplexity.h> >> 55 #include <Inventor/nodes/SoNurbsSurface.h> 51 #include <Inventor/nodes/SoTranslation.h> 56 #include <Inventor/nodes/SoTranslation.h> 52 #include <Inventor/nodes/SoTransform.h> 57 #include <Inventor/nodes/SoTransform.h> 53 #include <Inventor/nodes/SoResetTransform.h> 58 #include <Inventor/nodes/SoResetTransform.h> 54 #include <Inventor/nodes/SoMatrixTransform.h> 59 #include <Inventor/nodes/SoMatrixTransform.h> 55 60 56 #define USE_SOPOLYHEDRON 61 #define USE_SOPOLYHEDRON 57 62 58 #ifndef USE_SOPOLYHEDRON 63 #ifndef USE_SOPOLYHEDRON 59 #include "HEPVis/nodes/SoBox.h" 64 #include "HEPVis/nodes/SoBox.h" 60 #include "HEPVis/nodes/SoTubs.h" 65 #include "HEPVis/nodes/SoTubs.h" 61 #include "HEPVis/nodes/SoCons.h" 66 #include "HEPVis/nodes/SoCons.h" 62 #include "HEPVis/nodes/SoTrd.h" 67 #include "HEPVis/nodes/SoTrd.h" 63 #include "HEPVis/nodes/SoTrap.h" 68 #include "HEPVis/nodes/SoTrap.h" 64 #endif 69 #endif 65 #include "HEPVis/nodes/SoMarkerSet.h" 70 #include "HEPVis/nodes/SoMarkerSet.h" 66 << 71 typedef HEPVis_SoMarkerSet SoMarkerSet; 67 using SoMarkerSet = HEPVis_SoMarkerSet; << 68 << 69 #include "HEPVis/nodekits/SoDetectorTreeKit.h" 72 #include "HEPVis/nodekits/SoDetectorTreeKit.h" 70 #include "HEPVis/misc/SoStyleCache.h" 73 #include "HEPVis/misc/SoStyleCache.h" 71 74 72 #include "SoG4Polyhedron.h" 75 #include "SoG4Polyhedron.h" 73 #include "SoG4LineSet.h" 76 #include "SoG4LineSet.h" 74 #include "SoG4MarkerSet.h" 77 #include "SoG4MarkerSet.h" 75 78 76 #include "G4Scene.hh" 79 #include "G4Scene.hh" >> 80 #include "G4NURBS.hh" 77 #include "G4OpenInventor.hh" 81 #include "G4OpenInventor.hh" 78 #include "G4OpenInventorTransform3D.hh" 82 #include "G4OpenInventorTransform3D.hh" 79 #include "G4ThreeVector.hh" 83 #include "G4ThreeVector.hh" 80 #include "G4Point3D.hh" 84 #include "G4Point3D.hh" 81 #include "G4Normal3D.hh" 85 #include "G4Normal3D.hh" 82 #include "G4Transform3D.hh" 86 #include "G4Transform3D.hh" 83 #include "G4Polyline.hh" 87 #include "G4Polyline.hh" 84 #include "G4Text.hh" 88 #include "G4Text.hh" 85 #include "G4Circle.hh" 89 #include "G4Circle.hh" 86 #include "G4Square.hh" 90 #include "G4Square.hh" 87 #include "G4Polymarker.hh" 91 #include "G4Polymarker.hh" 88 #include "G4Polyhedron.hh" 92 #include "G4Polyhedron.hh" 89 #include "G4Box.hh" 93 #include "G4Box.hh" 90 #include "G4Tubs.hh" 94 #include "G4Tubs.hh" 91 #include "G4Cons.hh" 95 #include "G4Cons.hh" 92 #include "G4Trap.hh" 96 #include "G4Trap.hh" 93 #include "G4Trd.hh" 97 #include "G4Trd.hh" 94 #include "G4ModelingParameters.hh" 98 #include "G4ModelingParameters.hh" 95 #include "G4VPhysicalVolume.hh" 99 #include "G4VPhysicalVolume.hh" 96 #include "G4LogicalVolume.hh" 100 #include "G4LogicalVolume.hh" 97 #include "G4Material.hh" 101 #include "G4Material.hh" 98 #include "G4VisAttributes.hh" 102 #include "G4VisAttributes.hh" 99 103 100 #define G4warn G4cout << 101 << 102 G4int G4OpenInventorSceneHandler::fSceneIdCoun 104 G4int G4OpenInventorSceneHandler::fSceneIdCount = 0; 103 105 104 G4OpenInventorSceneHandler::G4OpenInventorScen 106 G4OpenInventorSceneHandler::G4OpenInventorSceneHandler (G4OpenInventor& system, 105 cons 107 const G4String& name) 106 :G4VSceneHandler (system, fSceneIdCount++, nam 108 :G4VSceneHandler (system, fSceneIdCount++, name) 107 ,fRoot(0) 109 ,fRoot(0) 108 ,fDetectorRoot(0) 110 ,fDetectorRoot(0) 109 ,fTransientRoot(0) 111 ,fTransientRoot(0) 110 ,fCurrentSeparator(0) 112 ,fCurrentSeparator(0) 111 ,fModelingSolid(false) 113 ,fModelingSolid(false) 112 ,fReducedWireFrame(true) 114 ,fReducedWireFrame(true) 113 ,fStyleCache(0) 115 ,fStyleCache(0) 114 ,fPreviewAndFull(true) << 116 ,fPreviewAndFull(false) 115 { 117 { 116 fStyleCache = new SoStyleCache; 118 fStyleCache = new SoStyleCache; 117 fStyleCache->ref(); 119 fStyleCache->ref(); 118 120 119 fRoot = new SoSeparator; 121 fRoot = new SoSeparator; 120 fRoot->ref(); 122 fRoot->ref(); 121 fRoot->setName("Root"); 123 fRoot->setName("Root"); 122 124 123 fDetectorRoot = new SoSeparator; 125 fDetectorRoot = new SoSeparator; 124 fDetectorRoot->setName("StaticRoot"); 126 fDetectorRoot->setName("StaticRoot"); 125 fRoot->addChild(fDetectorRoot); 127 fRoot->addChild(fDetectorRoot); 126 128 127 fTransientRoot = new SoSeparator; 129 fTransientRoot = new SoSeparator; 128 fTransientRoot->setName("TransientRoot"); 130 fTransientRoot->setName("TransientRoot"); 129 fRoot->addChild(fTransientRoot); 131 fRoot->addChild(fTransientRoot); 130 132 131 fCurrentSeparator = fTransientRoot; 133 fCurrentSeparator = fTransientRoot; 132 } 134 } 133 135 134 G4OpenInventorSceneHandler::~G4OpenInventorSce 136 G4OpenInventorSceneHandler::~G4OpenInventorSceneHandler () 135 { 137 { 136 fRoot->unref(); 138 fRoot->unref(); 137 fStyleCache->unref(); 139 fStyleCache->unref(); 138 } 140 } 139 141 140 void G4OpenInventorSceneHandler::ClearStore () << 142 void G4OpenInventorSceneHandler::ClearStore () { 141 { << 143 G4VSceneHandler::ClearStore(); >> 144 142 fDetectorRoot->removeAllChildren(); 145 fDetectorRoot->removeAllChildren(); 143 fSeparatorMap.clear(); 146 fSeparatorMap.clear(); 144 147 145 fTransientRoot->removeAllChildren(); 148 fTransientRoot->removeAllChildren(); 146 } 149 } 147 150 148 void G4OpenInventorSceneHandler::ClearTransien << 151 void G4OpenInventorSceneHandler::ClearTransientStore () { 149 { << 152 G4VSceneHandler::ClearTransientStore (); >> 153 150 fTransientRoot->removeAllChildren(); 154 fTransientRoot->removeAllChildren(); 151 } 155 } 152 156 153 // 157 // 154 // Generates prerequisites for solids 158 // Generates prerequisites for solids 155 // 159 // 156 void G4OpenInventorSceneHandler::PreAddSolid 160 void G4OpenInventorSceneHandler::PreAddSolid 157 (const G4Transform3D& objectTransformation, 161 (const G4Transform3D& objectTransformation, 158 const G4VisAttributes& visAttribs) 162 const G4VisAttributes& visAttribs) 159 { 163 { 160 G4VSceneHandler::PreAddSolid (objectTransfor 164 G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs); 161 // Stores arguments away for future use, e.g 165 // Stores arguments away for future use, e.g., AddPrimitives. 162 166 163 GeneratePrerequisites(); 167 GeneratePrerequisites(); 164 } 168 } 165 169 166 // 170 // 167 // Generates prerequisites for primitives 171 // Generates prerequisites for primitives 168 // 172 // 169 void G4OpenInventorSceneHandler::BeginPrimitiv 173 void G4OpenInventorSceneHandler::BeginPrimitives 170 (const G4Transform3D& objectTransformation) { 174 (const G4Transform3D& objectTransformation) { 171 175 172 G4VSceneHandler::BeginPrimitives (objectTran 176 G4VSceneHandler::BeginPrimitives (objectTransformation); 173 177 174 // If thread of control has already passed t 178 // If thread of control has already passed through PreAddSolid, 175 // avoid opening a graphical data base compo 179 // avoid opening a graphical data base component again. 176 if (!fProcessingSolid) { 180 if (!fProcessingSolid) { 177 GeneratePrerequisites(); 181 GeneratePrerequisites(); 178 } 182 } 179 } 183 } 180 184 181 // 185 // 182 // Method for handling G4Polyline objects (fro 186 // Method for handling G4Polyline objects (from tracking). 183 // 187 // 184 void G4OpenInventorSceneHandler::AddPrimitive 188 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline& line) 185 { 189 { 186 if (fProcessing2D) { << 190 AddProperties(line.GetVisAttributes()); // Transformation, colour, etc. 187 static G4bool warned = false; << 188 if (!warned) { << 189 warned = true; << 190 G4Exception << 191 ("G4OpenInventorSceneHandler::AddPrimitive ( << 192 "OpenInventor-0001", JustWarning, << 193 "2D polylines not implemented. Ignored."); << 194 } << 195 return; << 196 } << 197 << 198 // Get vis attributes - pick up defaults if << 199 const G4VisAttributes* pVA = << 200 fpViewer -> GetApplicableVisAttributes (line << 201 << 202 AddProperties(pVA); // Colour, etc. << 203 AddTransform(); // Transformation << 204 191 205 G4int nPoints = (G4int)line.size(); << 192 G4int nPoints = line.size(); 206 SbVec3f* pCoords = new SbVec3f[nPoints]; 193 SbVec3f* pCoords = new SbVec3f[nPoints]; 207 194 208 for (G4int iPoint = 0; iPoint < nPoints ; ++ << 195 for (G4int iPoint = 0; iPoint < nPoints ; iPoint++) { 209 pCoords[iPoint].setValue((G4float)line[iPo << 196 pCoords[iPoint].setValue((float)line[iPoint].x(), 210 (G4float)line[iPo << 197 (float)line[iPoint].y(), 211 (G4float)line[iPo << 198 (float)line[iPoint].z()); 212 } 199 } 213 200 214 // 201 // 215 // Point Set 202 // Point Set 216 // 203 // 217 SoCoordinate3 *polyCoords = new SoCoordinate 204 SoCoordinate3 *polyCoords = new SoCoordinate3; 218 polyCoords->point.setValues(0,nPoints,pCoord 205 polyCoords->point.setValues(0,nPoints,pCoords); 219 fCurrentSeparator->addChild(polyCoords); 206 fCurrentSeparator->addChild(polyCoords); 220 207 221 // 208 // 222 // Wireframe 209 // Wireframe 223 // 210 // 224 SoDrawStyle* drawStyle = fStyleCache->getLin 211 SoDrawStyle* drawStyle = fStyleCache->getLineStyle(); 225 fCurrentSeparator->addChild(drawStyle); 212 fCurrentSeparator->addChild(drawStyle); 226 213 227 SoG4LineSet *pLine = new SoG4LineSet; 214 SoG4LineSet *pLine = new SoG4LineSet; 228 215 229 // Loads G4Atts for picking... 216 // Loads G4Atts for picking... 230 if (fpViewer->GetViewParameters().IsPicking( 217 if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(line, pLine); 231 218 232 #ifdef INVENTOR2_0 219 #ifdef INVENTOR2_0 233 pLine->numVertices.setValues(0,1,(const G4lo << 220 pLine->numVertices.setValues(0,1,(const long *)&nPoints); 234 #else 221 #else 235 pLine->numVertices.setValues(0,1,&nPoints); 222 pLine->numVertices.setValues(0,1,&nPoints); 236 #endif 223 #endif 237 224 238 fCurrentSeparator->addChild(pLine); 225 fCurrentSeparator->addChild(pLine); 239 226 240 delete [] pCoords; 227 delete [] pCoords; 241 } 228 } 242 229 243 void G4OpenInventorSceneHandler::AddPrimitive 230 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 244 { 231 { 245 if (fProcessing2D) { << 232 AddProperties(polymarker.GetVisAttributes()); // Transformation, colour, etc. 246 static G4bool warned = false; << 247 if (!warned) { << 248 warned = true; << 249 G4Exception << 250 ("G4OpenInventorSceneHandler::AddPrimitive ( << 251 "OpenInventor-0002", JustWarning, << 252 "2D polymarkers not implemented. Ignored." << 253 } << 254 return; << 255 } << 256 233 257 // Get vis attributes - pick up defaults if << 234 G4int pointn = polymarker.size(); 258 const G4VisAttributes* pVA = << 259 fpViewer -> GetApplicableVisAttributes (poly << 260 << 261 AddProperties(pVA); // Colour, etc. << 262 AddTransform(); // Transformation << 263 << 264 G4int pointn = (G4int)polymarker.size(); << 265 if(pointn<=0) return; 235 if(pointn<=0) return; 266 236 267 SbVec3f* points = new SbVec3f[pointn]; 237 SbVec3f* points = new SbVec3f[pointn]; 268 for (G4int iPoint = 0; iPoint < pointn ; ++i << 238 for (G4int iPoint = 0; iPoint < pointn ; iPoint++) { 269 points[iPoint].setValue((G4float)polymarke << 239 points[iPoint].setValue((float)polymarker[iPoint].x(), 270 (G4float)polymarke << 240 (float)polymarker[iPoint].y(), 271 (G4float)polymarke << 241 (float)polymarker[iPoint].z()); 272 } 242 } 273 243 274 SoCoordinate3* coordinate3 = new SoCoordinat 244 SoCoordinate3* coordinate3 = new SoCoordinate3; 275 coordinate3->point.setValues(0,pointn,points 245 coordinate3->point.setValues(0,pointn,points); 276 fCurrentSeparator->addChild(coordinate3); 246 fCurrentSeparator->addChild(coordinate3); 277 247 278 MarkerSizeType sizeType; 248 MarkerSizeType sizeType; 279 G4double screenSize = GetMarkerSize (polymar 249 G4double screenSize = GetMarkerSize (polymarker, sizeType); 280 switch (sizeType) { 250 switch (sizeType) { 281 default: 251 default: 282 case screen: 252 case screen: 283 // Draw in screen coordinates. OK. 253 // Draw in screen coordinates. OK. 284 break; 254 break; 285 case world: 255 case world: 286 // Draw in world coordinates. Not implem 256 // Draw in world coordinates. Not implemented. Use screenSize = 10. 287 screenSize = 10.; 257 screenSize = 10.; 288 break; 258 break; 289 } 259 } 290 260 291 SoG4MarkerSet* markerSet = new SoG4MarkerSet 261 SoG4MarkerSet* markerSet = new SoG4MarkerSet; 292 markerSet->numPoints = pointn; 262 markerSet->numPoints = pointn; 293 263 294 // Loads G4Atts for picking... 264 // Loads G4Atts for picking... 295 if (fpViewer->GetViewParameters().IsPicking( 265 if (fpViewer->GetViewParameters().IsPicking()) 296 LoadAtts(polymarker, markerSet); 266 LoadAtts(polymarker, markerSet); 297 267 298 G4VMarker::FillStyle style = polymarker.GetF 268 G4VMarker::FillStyle style = polymarker.GetFillStyle(); 299 switch (polymarker.GetMarkerType()) { 269 switch (polymarker.GetMarkerType()) { 300 default: 270 default: 301 // Are available 5_5, 7_7 and 9_9 271 // Are available 5_5, 7_7 and 9_9 302 case G4Polymarker::dots: 272 case G4Polymarker::dots: 303 if (screenSize <= 5.) { 273 if (screenSize <= 5.) { 304 markerSet->markerIndex = SoMarkerSet::CI 274 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5; 305 } else if (screenSize <= 7.) { 275 } else if (screenSize <= 7.) { 306 markerSet->markerIndex = SoMarkerSet::CI 276 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7; 307 } else { 277 } else { 308 markerSet->markerIndex = SoMarkerSet::CI 278 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9; 309 } 279 } 310 break; 280 break; 311 case G4Polymarker::circles: 281 case G4Polymarker::circles: 312 if (screenSize <= 5.) { 282 if (screenSize <= 5.) { 313 if (style == G4VMarker::filled) { 283 if (style == G4VMarker::filled) { 314 markerSet->markerIndex = SoMarkerSet::CIRCLE 284 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5; 315 } else { 285 } else { 316 markerSet->markerIndex = SoMarkerSet::CIRCLE 286 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_5_5; 317 } 287 } 318 } else if (screenSize <= 7.) { 288 } else if (screenSize <= 7.) { 319 if (style == G4VMarker::filled) { 289 if (style == G4VMarker::filled) { 320 markerSet->markerIndex = SoMarkerSet::CIRCLE 290 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7; 321 } else { 291 } else { 322 markerSet->markerIndex = SoMarkerSet::CIRCLE 292 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_7_7; 323 } 293 } 324 } else { 294 } else { 325 if (style == G4VMarker::filled) { 295 if (style == G4VMarker::filled) { 326 markerSet->markerIndex = SoMarkerSet::CIRCLE 296 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9; 327 } else { 297 } else { 328 markerSet->markerIndex = SoMarkerSet::CIRCLE 298 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_9_9; 329 } 299 } 330 } 300 } 331 break; 301 break; 332 case G4Polymarker::squares: 302 case G4Polymarker::squares: 333 if (screenSize <= 5.) { 303 if (screenSize <= 5.) { 334 if (style == G4VMarker::filled) { 304 if (style == G4VMarker::filled) { 335 markerSet->markerIndex = SoMarkerSet::SQUARE 305 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_5_5; 336 } else { 306 } else { 337 markerSet->markerIndex = SoMarkerSet::SQUARE 307 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_5_5; 338 } 308 } 339 } else if (screenSize <= 7.) { 309 } else if (screenSize <= 7.) { 340 if (style == G4VMarker::filled) { 310 if (style == G4VMarker::filled) { 341 markerSet->markerIndex = SoMarkerSet::SQUARE 311 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_7_7; 342 } else { 312 } else { 343 markerSet->markerIndex = SoMarkerSet::SQUARE 313 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_7_7; 344 } 314 } 345 } else { 315 } else { 346 if (style == G4VMarker::filled) { 316 if (style == G4VMarker::filled) { 347 markerSet->markerIndex = SoMarkerSet::SQUARE 317 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_9_9; 348 } else { 318 } else { 349 markerSet->markerIndex = SoMarkerSet::SQUARE 319 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_9_9; 350 } 320 } 351 } 321 } 352 } 322 } 353 fCurrentSeparator->addChild(markerSet); 323 fCurrentSeparator->addChild(markerSet); 354 324 355 delete [] points; 325 delete [] points; 356 } 326 } 357 327 >> 328 // ********* NOTE ********* NOTE ********* NOTE ********* NOTE ********* >> 329 // >> 330 // This method (Text) has not been tested, as it is >> 331 // innaccessible from the menu in the current configuration >> 332 // >> 333 // Currently draws at the origin! How do I get it to draw at >> 334 // text.GetPosition()? JA >> 335 // >> 336 // ********* NOTE ********* NOTE ********* NOTE ********* NOTE ********* >> 337 // 358 // Method for handling G4Text objects 338 // Method for handling G4Text objects 359 // 339 // 360 void G4OpenInventorSceneHandler::AddPrimitive 340 void G4OpenInventorSceneHandler::AddPrimitive (const G4Text& text) 361 { 341 { 362 if (fProcessing2D) { << 342 AddProperties(text.GetVisAttributes()); // Transformation, colour, etc. 363 static G4bool warned = false; << 364 if (!warned) { << 365 warned = true; << 366 G4Exception << 367 ("G4OpenInventorSceneHandler::AddPrimitive ( << 368 "OpenInventor-0003", JustWarning, << 369 "2D text not implemented. Ignored."); << 370 } << 371 return; << 372 } << 373 << 374 AddProperties(text.GetVisAttributes()); // << 375 AddTransform(text.GetPosition()); // << 376 343 377 // 344 // 378 // Color. Note: text colour is worked out d 345 // Color. Note: text colour is worked out differently. This 379 // over-rides the colour added in AddPropert 346 // over-rides the colour added in AddProperties... 380 // 347 // 381 const G4Colour& c = GetTextColour (text); 348 const G4Colour& c = GetTextColour (text); 382 SoMaterial* material = 349 SoMaterial* material = 383 fStyleCache->getMaterial((G4float)c.GetRed << 350 fStyleCache->getMaterial((float)c.GetRed(), 384 (G4float)c.GetGre << 351 (float)c.GetGreen(), 385 (G4float)c.GetBlu << 352 (float)c.GetBlue(), 386 (G4float)(1-c.Get << 353 (float)(1-c.GetAlpha())); 387 fCurrentSeparator->addChild(material); 354 fCurrentSeparator->addChild(material); 388 355 389 MarkerSizeType sizeType; 356 MarkerSizeType sizeType; 390 G4double size = GetMarkerSize (text, sizeTyp 357 G4double size = GetMarkerSize (text, sizeType); 391 switch (sizeType) { 358 switch (sizeType) { 392 default: 359 default: 393 case screen: 360 case screen: 394 // Draw in screen coordinates. OK. 361 // Draw in screen coordinates. OK. 395 break; 362 break; 396 case world: 363 case world: 397 // Draw in world coordinates. Not implem 364 // Draw in world coordinates. Not implemented. Use size = 20. 398 size = 20.; 365 size = 20.; 399 break; 366 break; 400 } 367 } 401 368 402 // 369 // 403 // Font 370 // Font 404 // 371 // 405 SoFont *g4Font = new SoFont(); 372 SoFont *g4Font = new SoFont(); 406 g4Font->size = size; 373 g4Font->size = size; 407 fCurrentSeparator->addChild(g4Font); 374 fCurrentSeparator->addChild(g4Font); 408 375 409 // 376 // 410 // Text 377 // Text 411 // 378 // 412 SoText2 *g4String = new SoText2(); 379 SoText2 *g4String = new SoText2(); 413 g4String->string.setValue(text.GetText()); 380 g4String->string.setValue(text.GetText()); 414 g4String->spacing = 2.0; 381 g4String->spacing = 2.0; 415 switch (text.GetLayout()) { 382 switch (text.GetLayout()) { 416 default: 383 default: 417 case G4Text::left: 384 case G4Text::left: 418 g4String->justification = SoText2::LEFT; b 385 g4String->justification = SoText2::LEFT; break; 419 case G4Text::centre: 386 case G4Text::centre: 420 g4String->justification = SoText2::CENTER; 387 g4String->justification = SoText2::CENTER; break; 421 case G4Text::right: 388 case G4Text::right: 422 g4String->justification = SoText2::RIGHT; 389 g4String->justification = SoText2::RIGHT; break; 423 } 390 } 424 fCurrentSeparator->addChild(g4String); 391 fCurrentSeparator->addChild(g4String); 425 } 392 } 426 393 427 // 394 // 428 // Method for handling G4Circle objects 395 // Method for handling G4Circle objects 429 // 396 // 430 void G4OpenInventorSceneHandler::AddPrimitive 397 void G4OpenInventorSceneHandler::AddPrimitive (const G4Circle& circle) { 431 AddCircleSquare(G4OICircle, circle); 398 AddCircleSquare(G4OICircle, circle); 432 } 399 } 433 400 434 // 401 // 435 // Method for handling G4Square objects - defa 402 // Method for handling G4Square objects - defaults to wireframe 436 // 403 // 437 void G4OpenInventorSceneHandler::AddPrimitive 404 void G4OpenInventorSceneHandler::AddPrimitive (const G4Square& square) { 438 AddCircleSquare(G4OISquare, square); 405 AddCircleSquare(G4OISquare, square); 439 } 406 } 440 407 441 void G4OpenInventorSceneHandler::AddCircleSqua 408 void G4OpenInventorSceneHandler::AddCircleSquare 442 (G4OIMarker markerType, const G4VMarker& marke 409 (G4OIMarker markerType, const G4VMarker& marker) 443 { 410 { 444 if (fProcessing2D) { << 411 AddProperties(marker.GetVisAttributes()); // Transformation, colour, etc. 445 static G4bool warned = false; << 446 if (!warned) { << 447 warned = true; << 448 G4Exception << 449 ("G4OpenInventorSceneHandler::AddCircleSquar << 450 "OpenInventor-0004", JustWarning, << 451 "2D circles and squares not implemented. I << 452 } << 453 return; << 454 } << 455 << 456 // Get vis attributes - pick up defaults if << 457 const G4VisAttributes* pVA = << 458 fpViewer -> GetApplicableVisAttributes (mark << 459 << 460 AddProperties(pVA); // Colour, etc. << 461 AddTransform(); // Transformation << 462 412 463 MarkerSizeType sizeType; 413 MarkerSizeType sizeType; 464 G4double screenSize = GetMarkerSize (marker, 414 G4double screenSize = GetMarkerSize (marker, sizeType); 465 switch (sizeType) { 415 switch (sizeType) { 466 default: 416 default: 467 case screen: 417 case screen: 468 // Draw in screen coordinates. OK. 418 // Draw in screen coordinates. OK. 469 break; 419 break; 470 case world: 420 case world: 471 // Draw in world coordinates. Not implem 421 // Draw in world coordinates. Not implemented. Use size = 10. 472 screenSize = 10.; 422 screenSize = 10.; 473 break; 423 break; 474 } 424 } 475 425 476 G4Point3D centre = marker.GetPosition(); 426 G4Point3D centre = marker.GetPosition(); 477 427 478 // Borrowed from AddPrimitive(G4Polymarker) 428 // Borrowed from AddPrimitive(G4Polymarker) - inefficient? JA 479 SbVec3f* points = new SbVec3f[1]; 429 SbVec3f* points = new SbVec3f[1]; 480 points[0].setValue((G4float)centre.x(), << 430 points[0].setValue((float)centre.x(), 481 (G4float)centre.y(), << 431 (float)centre.y(), 482 (G4float)centre.z()); << 432 (float)centre.z()); 483 SoCoordinate3* coordinate3 = new SoCoordinat 433 SoCoordinate3* coordinate3 = new SoCoordinate3; 484 coordinate3->point.setValues(0,1,points); 434 coordinate3->point.setValues(0,1,points); 485 fCurrentSeparator->addChild(coordinate3); 435 fCurrentSeparator->addChild(coordinate3); 486 436 487 SoG4MarkerSet* markerSet = new SoG4MarkerSet 437 SoG4MarkerSet* markerSet = new SoG4MarkerSet; 488 markerSet->numPoints = 1; 438 markerSet->numPoints = 1; 489 439 490 // Loads G4Atts for picking... 440 // Loads G4Atts for picking... 491 if (fpViewer->GetViewParameters().IsPicking( 441 if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(marker, markerSet); 492 442 493 G4VMarker::FillStyle style = marker.GetFillS 443 G4VMarker::FillStyle style = marker.GetFillStyle(); 494 switch (markerType) { 444 switch (markerType) { 495 case G4OICircle: 445 case G4OICircle: 496 if (screenSize <= 5.) { 446 if (screenSize <= 5.) { 497 if (style == G4VMarker::filled) { 447 if (style == G4VMarker::filled) { 498 markerSet->markerIndex = SoMarkerSet::CIRCLE 448 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_5_5; 499 } else { 449 } else { 500 markerSet->markerIndex = SoMarkerSet::CIRCLE 450 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_5_5; 501 } 451 } 502 } else if (screenSize <= 7.) { 452 } else if (screenSize <= 7.) { 503 if (style == G4VMarker::filled) { 453 if (style == G4VMarker::filled) { 504 markerSet->markerIndex = SoMarkerSet::CIRCLE 454 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7; 505 } else { 455 } else { 506 markerSet->markerIndex = SoMarkerSet::CIRCLE 456 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_7_7; 507 } 457 } 508 } else { 458 } else { 509 if (style == G4VMarker::filled) { 459 if (style == G4VMarker::filled) { 510 markerSet->markerIndex = SoMarkerSet::CIRCLE 460 markerSet->markerIndex = SoMarkerSet::CIRCLE_FILLED_9_9; 511 } else { 461 } else { 512 markerSet->markerIndex = SoMarkerSet::CIRCLE 462 markerSet->markerIndex = SoMarkerSet::CIRCLE_LINE_9_9; 513 } 463 } 514 } 464 } 515 break; 465 break; 516 case G4OISquare: 466 case G4OISquare: 517 if (screenSize <= 5.) { 467 if (screenSize <= 5.) { 518 if (style == G4VMarker::filled) { 468 if (style == G4VMarker::filled) { 519 markerSet->markerIndex = SoMarkerSet::SQUARE 469 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_5_5; 520 } else { 470 } else { 521 markerSet->markerIndex = SoMarkerSet::SQUARE 471 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_5_5; 522 } 472 } 523 } else if (screenSize <= 7.) { 473 } else if (screenSize <= 7.) { 524 if (style == G4VMarker::filled) { 474 if (style == G4VMarker::filled) { 525 markerSet->markerIndex = SoMarkerSet::SQUARE 475 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_7_7; 526 } else { 476 } else { 527 markerSet->markerIndex = SoMarkerSet::SQUARE 477 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_7_7; 528 } 478 } 529 } else { 479 } else { 530 if (style == G4VMarker::filled) { 480 if (style == G4VMarker::filled) { 531 markerSet->markerIndex = SoMarkerSet::SQUARE 481 markerSet->markerIndex = SoMarkerSet::SQUARE_FILLED_9_9; 532 } else { 482 } else { 533 markerSet->markerIndex = SoMarkerSet::SQUARE 483 markerSet->markerIndex = SoMarkerSet::SQUARE_LINE_9_9; 534 } 484 } 535 } 485 } 536 break; 486 break; 537 } 487 } 538 fCurrentSeparator->addChild(markerSet); 488 fCurrentSeparator->addChild(markerSet); 539 489 540 delete [] points; 490 delete [] points; 541 } 491 } 542 492 543 // 493 // 544 // Method for handling G4Polyhedron objects fo 494 // Method for handling G4Polyhedron objects for drawing solids. 545 // 495 // 546 void G4OpenInventorSceneHandler::AddPrimitive 496 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) 547 { 497 { 548 if (polyhedron.GetNoFacets() == 0) return; 498 if (polyhedron.GetNoFacets() == 0) return; 549 499 550 if (fProcessing2D) { << 500 AddProperties(polyhedron.GetVisAttributes()); // Transformation, colour, etc. 551 static G4bool warned = false; << 552 if (!warned) { << 553 warned = true; << 554 G4Exception << 555 ("G4OpenInventorSceneHandler::AddPrimitive ( << 556 "OpenInventor-0005", JustWarning, << 557 "2D polyhedra not implemented. Ignored."); << 558 } << 559 return; << 560 } << 561 << 562 // Get vis attributes - pick up defaults if << 563 const G4VisAttributes* pVA = << 564 fpViewer -> GetApplicableVisAttributes (poly << 565 << 566 AddProperties(pVA); // Colour, etc. << 567 AddTransform(); // Transformation << 568 501 569 SoG4Polyhedron* soPolyhedron = new SoG4Polyh 502 SoG4Polyhedron* soPolyhedron = new SoG4Polyhedron(polyhedron); 570 503 571 // Loads G4Atts for picking... 504 // Loads G4Atts for picking... 572 if (fpViewer->GetViewParameters().IsPicking( 505 if (fpViewer->GetViewParameters().IsPicking()) 573 LoadAtts(polyhedron, soPolyhedron); 506 LoadAtts(polyhedron, soPolyhedron); 574 507 575 SbString name = "Non-geometry"; 508 SbString name = "Non-geometry"; 576 G4PhysicalVolumeModel* pPVModel = 509 G4PhysicalVolumeModel* pPVModel = 577 dynamic_cast<G4PhysicalVolumeModel*>(fpMod 510 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 578 if (pPVModel) { 511 if (pPVModel) { 579 name = pPVModel->GetCurrentLV()->GetName() 512 name = pPVModel->GetCurrentLV()->GetName().c_str(); 580 } 513 } 581 SbName sbName(name); 514 SbName sbName(name); 582 soPolyhedron->setName(sbName); 515 soPolyhedron->setName(sbName); 583 soPolyhedron->solid.setValue(fModelingSolid) 516 soPolyhedron->solid.setValue(fModelingSolid); 584 soPolyhedron->reducedWireFrame.setValue(fRed 517 soPolyhedron->reducedWireFrame.setValue(fReducedWireFrame?TRUE:FALSE); 585 fCurrentSeparator->addChild(soPolyhedron); 518 fCurrentSeparator->addChild(soPolyhedron); 586 } 519 } 587 520 588 void G4OpenInventorSceneHandler::AddCompound(c << 521 // 589 StandardSpecialMeshRendering(mesh); << 522 // Method for handling G4NURBS objects for drawing solids. >> 523 // Knots and Ctrl Pnts MUST be arrays of GLfloats. >> 524 // >> 525 void G4OpenInventorSceneHandler::AddPrimitive (const G4NURBS& nurb) { >> 526 >> 527 AddProperties(nurb.GetVisAttributes()); // Transformation, colour, etc. >> 528 >> 529 G4float *u_knot_array, *u_knot_array_ptr; >> 530 u_knot_array = u_knot_array_ptr = new G4float [nurb.GetnbrKnots(G4NURBS::U)]; >> 531 G4NURBS::KnotsIterator u_iterator (nurb, G4NURBS::U); >> 532 while (u_iterator.pick (u_knot_array_ptr++)); >> 533 >> 534 G4float *v_knot_array, *v_knot_array_ptr; >> 535 v_knot_array = v_knot_array_ptr = new G4float [nurb.GetnbrKnots(G4NURBS::V)]; >> 536 G4NURBS::KnotsIterator v_iterator (nurb, G4NURBS::V); >> 537 while (v_iterator.pick (v_knot_array_ptr++)); >> 538 >> 539 G4float *ctrl_pnt_array, *ctrl_pnt_array_ptr; >> 540 ctrl_pnt_array = ctrl_pnt_array_ptr = >> 541 new G4float [nurb.GettotalnbrCtrlPts () * G4NURBS::NofC*sizeof(G4float)]; >> 542 G4NURBS::CtrlPtsCoordsIterator c_p_iterator (nurb); >> 543 while (c_p_iterator.pick (ctrl_pnt_array_ptr++)); >> 544 >> 545 SoSeparator *surfSep = new SoSeparator(); >> 546 >> 547 // >> 548 // Set up NURBS >> 549 // >> 550 SoComplexity *complexity = new SoComplexity; >> 551 SoCoordinate4 *ctlPts = new SoCoordinate4; >> 552 SoNurbsSurface *oi_nurb = new SoNurbsSurface; >> 553 >> 554 complexity->value = (float)0.6; >> 555 G4int nPoints = nurb.GettotalnbrCtrlPts (); >> 556 SbVec4f* points = new SbVec4f[nPoints]; >> 557 for (G4int iPoint = 0; iPoint < nPoints ; iPoint++) { >> 558 points[iPoint].setValue( >> 559 ctrl_pnt_array[iPoint*4 + 0], >> 560 ctrl_pnt_array[iPoint*4 + 1], >> 561 ctrl_pnt_array[iPoint*4 + 2], >> 562 ctrl_pnt_array[iPoint*4 + 3]); >> 563 } >> 564 ctlPts->point.setValues (0,nPoints,points); >> 565 oi_nurb->numUControlPoints = nurb.GetnbrCtrlPts(G4NURBS::U); >> 566 oi_nurb->numVControlPoints = nurb.GetnbrCtrlPts(G4NURBS::V); >> 567 oi_nurb->uKnotVector.setValues(0,nurb.GetnbrKnots(G4NURBS::U),u_knot_array); >> 568 oi_nurb->vKnotVector.setValues(0,nurb.GetnbrKnots(G4NURBS::V),v_knot_array); >> 569 >> 570 surfSep->addChild(complexity); >> 571 surfSep->addChild(ctlPts); >> 572 surfSep->addChild(oi_nurb); >> 573 >> 574 fCurrentSeparator->addChild(surfSep); >> 575 >> 576 // >> 577 // Clean-up >> 578 // >> 579 delete [] u_knot_array; >> 580 delete [] v_knot_array; >> 581 delete [] ctrl_pnt_array; >> 582 delete [] points; 590 } 583 } 591 584 592 void G4OpenInventorSceneHandler::GeneratePrere 585 void G4OpenInventorSceneHandler::GeneratePrerequisites() 593 { 586 { 594 // Utility for PreAddSolid and BeginPrimitiv 587 // Utility for PreAddSolid and BeginPrimitives. 595 588 596 // This routines prepares for adding items t 589 // This routines prepares for adding items to the scene database. We 597 // are expecting two kinds of solids: leaf p 590 // are expecting two kinds of solids: leaf parts and non-leaf parts. 598 // For non-leaf parts, we create a detector 591 // For non-leaf parts, we create a detector tree kit. This has two 599 // separators. The solid itself goes in the 592 // separators. The solid itself goes in the preview separator, the 600 // full separator is forseen for daughters. 593 // full separator is forseen for daughters. This separator is not 601 // only created--it is also put in a diction 594 // only created--it is also put in a dictionary for future use by 602 // the leaf part. 595 // the leaf part. 603 596 604 // For leaf parts, we first locate the mothe 597 // For leaf parts, we first locate the mother volume and find its 605 // separator through the dictionary. 598 // separator through the dictionary. 606 599 607 // The private member fCurrentSeparator is s 600 // The private member fCurrentSeparator is set to the proper 608 // location on in the scene database so that 601 // location on in the scene database so that when the solid is 609 // actually added (in addthis), it is put in 602 // actually added (in addthis), it is put in the right place. 610 603 611 G4PhysicalVolumeModel* pPVModel = 604 G4PhysicalVolumeModel* pPVModel = 612 dynamic_cast<G4PhysicalVolumeModel*>(fpMod 605 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 613 606 614 if (pPVModel) { 607 if (pPVModel) { 615 608 616 // This call comes from a G4PhysicalVolume 609 // This call comes from a G4PhysicalVolumeModel. drawnPVPath is 617 // the path of the current drawn (non-cull 610 // the path of the current drawn (non-culled) volume in terms of 618 // drawn (non-culled) ancestors. Each nod << 611 // drawn (non-culled) ancesters. Each node is identified by a 619 // PVNodeID object, which is a physical vo 612 // PVNodeID object, which is a physical volume and copy number. It 620 // is a vector of PVNodeIDs corresponding 613 // is a vector of PVNodeIDs corresponding to the geometry hierarchy 621 // actually selected, i.e., not culled. 614 // actually selected, i.e., not culled. 622 using PVNodeID = G4PhysicalVolumeModel::G4 << 615 typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID; 623 using PVPath = std::vector<PVNodeID>; << 616 typedef std::vector<PVNodeID> PVPath; 624 const PVPath& drawnPVPath = pPVModel->GetD 617 const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath(); 625 //G4int currentDepth = pPVModel->GetCurren 618 //G4int currentDepth = pPVModel->GetCurrentDepth(); 626 G4VPhysicalVolume* pCurrentPV = pPVModel-> 619 G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV(); 627 G4LogicalVolume* pCurrentLV = pPVModel->Ge 620 G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV(); 628 //G4Material* pCurrentMaterial = pPVModel- 621 //G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial(); 629 // Note: pCurrentMaterial may be zero (par 622 // Note: pCurrentMaterial may be zero (parallel world). 630 623 631 // The simplest algorithm, used by the Ope 624 // The simplest algorithm, used by the Open Inventor Driver 632 // developers, is to rely on the fact the 625 // developers, is to rely on the fact the G4PhysicalVolumeModel 633 // traverses the geometry hierarchy in an 626 // traverses the geometry hierarchy in an orderly manner. The last 634 // mother, if any, will be the node to whi 627 // mother, if any, will be the node to which the volume should be 635 // added. So it is enough to keep a map o 628 // added. So it is enough to keep a map of scene graph nodes keyed 636 // on the volume path ID. Actually, it is 629 // on the volume path ID. Actually, it is enough to use the logical 637 // volume as the key. (An alternative wou 630 // volume as the key. (An alternative would be to keep the PVNodeID 638 // in the tree and match the PVPath from t 631 // in the tree and match the PVPath from the root down.) 639 632 640 // Find mother. ri points to mother, if a 633 // Find mother. ri points to mother, if any... 641 PVPath::const_reverse_iterator ri; 634 PVPath::const_reverse_iterator ri; 642 G4LogicalVolume* MotherVolume = 0; 635 G4LogicalVolume* MotherVolume = 0; 643 ri = ++drawnPVPath.rbegin(); 636 ri = ++drawnPVPath.rbegin(); 644 if (ri != drawnPVPath.rend()) { 637 if (ri != drawnPVPath.rend()) { 645 // This volume has a mother. 638 // This volume has a mother. 646 MotherVolume = ri->GetPhysicalVolume()-> 639 MotherVolume = ri->GetPhysicalVolume()->GetLogicalVolume(); 647 } 640 } 648 641 649 if (pCurrentLV->GetNoDaughters()!=0 || 642 if (pCurrentLV->GetNoDaughters()!=0 || 650 pCurrentPV->IsReplicated()) { //????Don't u 643 pCurrentPV->IsReplicated()) { //????Don't understand this???? JA 651 // This block of code is executed for no 644 // This block of code is executed for non-leaf parts: 652 645 653 // Make the detector tree kit: 646 // Make the detector tree kit: 654 SoDetectorTreeKit* detectorTreeKit = new 647 SoDetectorTreeKit* detectorTreeKit = new SoDetectorTreeKit(); 655 648 656 SoSeparator* previewSeparator = 649 SoSeparator* previewSeparator = 657 (SoSeparator*) detectorTreeKit->getPart("pre 650 (SoSeparator*) detectorTreeKit->getPart("previewSeparator",TRUE); 658 previewSeparator->renderCaching = SoSepa 651 previewSeparator->renderCaching = SoSeparator::OFF; 659 652 660 SoSeparator* fullSeparator = 653 SoSeparator* fullSeparator = 661 (SoSeparator*) detectorTreeKit->getPart("ful 654 (SoSeparator*) detectorTreeKit->getPart("fullSeparator", TRUE); 662 fullSeparator->renderCaching = SoSeparat 655 fullSeparator->renderCaching = SoSeparator::OFF; 663 656 664 if(fPreviewAndFull) detectorTreeKit->set 657 if(fPreviewAndFull) detectorTreeKit->setPreviewAndFull(); 665 else detectorTreeKit->setPreview(TRUE); 658 else detectorTreeKit->setPreview(TRUE); 666 659 667 // Colour, etc., for SoDetectorTreeKit. 660 // Colour, etc., for SoDetectorTreeKit. Treated differently to 668 // othere SoNodes(?). Use fpVisAttribs 661 // othere SoNodes(?). Use fpVisAttribs stored away in 669 // PreAddSolid... 662 // PreAddSolid... 670 const G4VisAttributes* pApplicableVisAtt 663 const G4VisAttributes* pApplicableVisAttribs = 671 fpViewer->GetApplicableVisAttributes (fpVisA 664 fpViewer->GetApplicableVisAttributes (fpVisAttribs); 672 665 673 // First find the color attributes... 666 // First find the color attributes... 674 const G4Colour& g4Col = pApplicableVisA 667 const G4Colour& g4Col = pApplicableVisAttribs->GetColour (); 675 const G4double red = g4Col.GetRed (); << 668 const double red = g4Col.GetRed (); 676 const G4double green = g4Col.GetGreen () << 669 const double green = g4Col.GetGreen (); 677 const G4double blue = g4Col.GetBlue (); << 670 const double blue = g4Col.GetBlue (); 678 G4double transparency = 1 - g4Col.GetAlp << 671 double transparency = 1 - g4Col.GetAlpha(); 679 672 680 // Drawing style... 673 // Drawing style... 681 G4ViewParameters::DrawingStyle drawing_s 674 G4ViewParameters::DrawingStyle drawing_style = 682 GetDrawingStyle(pApplicableVisAttribs); 675 GetDrawingStyle(pApplicableVisAttribs); 683 switch (drawing_style) { 676 switch (drawing_style) { 684 case (G4ViewParameters::wireframe): 677 case (G4ViewParameters::wireframe): 685 fModelingSolid = false; 678 fModelingSolid = false; 686 break; 679 break; 687 case (G4ViewParameters::hlr): 680 case (G4ViewParameters::hlr): 688 case (G4ViewParameters::hsr): 681 case (G4ViewParameters::hsr): 689 case (G4ViewParameters::hlhsr): 682 case (G4ViewParameters::hlhsr): 690 fModelingSolid = true; 683 fModelingSolid = true; 691 break; 684 break; 692 case (G4ViewParameters::cloud): << 693 fModelingSolid = false; << 694 break; << 695 } 685 } 696 686 697 SoMaterial* material = 687 SoMaterial* material = 698 fStyleCache->getMaterial((G4float)red, << 688 fStyleCache->getMaterial((float)red, 699 (G4float)green, << 689 (float)green, 700 (G4float)blue, << 690 (float)blue, 701 (G4float)transparency); << 691 (float)transparency); 702 detectorTreeKit->setPart("appearance.mat 692 detectorTreeKit->setPart("appearance.material",material); 703 693 704 SoLightModel* lightModel = 694 SoLightModel* lightModel = 705 fModelingSolid ? fStyleCache->getLightModelP 695 fModelingSolid ? fStyleCache->getLightModelPhong() : 706 fStyleCache->getLightModelBaseColor(); 696 fStyleCache->getLightModelBaseColor(); 707 detectorTreeKit->setPart("appearance.lig 697 detectorTreeKit->setPart("appearance.lightModel",lightModel); 708 698 709 // Add the full separator to the diction 699 // Add the full separator to the dictionary; it is indexed by the 710 // address of the logical volume! 700 // address of the logical volume! 711 fSeparatorMap[pCurrentLV] = fullSeparato 701 fSeparatorMap[pCurrentLV] = fullSeparator; 712 702 713 // Find out where to add this volume. 703 // Find out where to add this volume. 714 // If no mother can be found, it goes un 704 // If no mother can be found, it goes under root. 715 if (MotherVolume) { 705 if (MotherVolume) { 716 if (fSeparatorMap.find(MotherVolume) != fSep 706 if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) { 717 //printf("debug : PreAddSolid : mother %s 707 //printf("debug : PreAddSolid : mother %s found in map\n", 718 // MotherVolume->GetName().c_str()); 708 // MotherVolume->GetName().c_str()); 719 fSeparatorMap[MotherVolume]->addChild(dete 709 fSeparatorMap[MotherVolume]->addChild(detectorTreeKit); 720 } else { 710 } else { 721 // Mother not previously encountered. Sho 711 // Mother not previously encountered. Shouldn't happen, since 722 // G4PhysicalVolumeModel sends volumes as 712 // G4PhysicalVolumeModel sends volumes as it encounters them, 723 // i.e., mothers before daughters, in its 713 // i.e., mothers before daughters, in its descent of the 724 // geometry tree. Error! 714 // geometry tree. Error! 725 G4warn << << 715 G4cout << 726 "ERROR: G4OpenInventorSceneHandler::Gene 716 "ERROR: G4OpenInventorSceneHandler::GeneratePrerequisites: Mother " 727 << ri->GetPhysicalVolume()->GetName() 717 << ri->GetPhysicalVolume()->GetName() 728 << ':' << ri->GetCopyNo() 718 << ':' << ri->GetCopyNo() 729 << " not previously encountered." 719 << " not previously encountered." 730 "\nShouldn't happen! Please report to v 720 "\nShouldn't happen! Please report to visualization coordinator." 731 << G4endl; 721 << G4endl; 732 // Continue anyway. Add to root of scene 722 // Continue anyway. Add to root of scene graph tree... 733 //printf("debug : PreAddSolid : mother %s 723 //printf("debug : PreAddSolid : mother %s not found in map !!!\n", 734 // MotherVolume->GetName().c_str()); 724 // MotherVolume->GetName().c_str()); 735 fDetectorRoot->addChild(detectorTreeKit); 725 fDetectorRoot->addChild(detectorTreeKit); 736 } 726 } 737 } else { 727 } else { 738 //printf("debug : PreAddSolid : has no mothe 728 //printf("debug : PreAddSolid : has no mother\n"); 739 fDetectorRoot->addChild(detectorTreeKit); 729 fDetectorRoot->addChild(detectorTreeKit); 740 } 730 } 741 731 742 fCurrentSeparator = previewSeparator; 732 fCurrentSeparator = previewSeparator; 743 733 744 } else { 734 } else { 745 // This block of code is executed for le 735 // This block of code is executed for leaf parts. 746 736 747 if (MotherVolume) { 737 if (MotherVolume) { 748 if (fSeparatorMap.find(MotherVolume) != fSep 738 if (fSeparatorMap.find(MotherVolume) != fSeparatorMap.end()) { 749 fCurrentSeparator = fSeparatorMap[MotherVo 739 fCurrentSeparator = fSeparatorMap[MotherVolume]; 750 } else { 740 } else { 751 // Mother not previously encountered. Sho 741 // Mother not previously encountered. Shouldn't happen, since 752 // G4PhysicalVolumeModel sends volumes as 742 // G4PhysicalVolumeModel sends volumes as it encounters them, 753 // i.e., mothers before daughters, in its 743 // i.e., mothers before daughters, in its descent of the 754 // geometry tree. Error! 744 // geometry tree. Error! 755 G4warn << "ERROR: G4OpenInventorSceneHandl << 745 G4cout << "ERROR: G4OpenInventorSceneHandler::PreAddSolid: Mother " 756 << ri->GetPhysicalVolume()->GetName() 746 << ri->GetPhysicalVolume()->GetName() 757 << ':' << ri->GetCopyNo() 747 << ':' << ri->GetCopyNo() 758 << " not previously encountered." 748 << " not previously encountered." 759 "\nShouldn't happen! Please report to v 749 "\nShouldn't happen! Please report to visualization coordinator." 760 << G4endl; 750 << G4endl; 761 // Continue anyway. Add to root of scene 751 // Continue anyway. Add to root of scene graph tree... 762 fCurrentSeparator = fDetectorRoot; 752 fCurrentSeparator = fDetectorRoot; 763 } 753 } 764 } else { 754 } else { 765 fCurrentSeparator = fDetectorRoot; 755 fCurrentSeparator = fDetectorRoot; 766 } 756 } 767 } 757 } 768 758 769 } else { 759 } else { 770 // Not from G4PhysicalVolumeModel, so add 760 // Not from G4PhysicalVolumeModel, so add to root as leaf part... 771 761 772 if (fReadyForTransients) { 762 if (fReadyForTransients) { 773 fCurrentSeparator = fTransientRoot; 763 fCurrentSeparator = fTransientRoot; 774 } else { 764 } else { 775 fCurrentSeparator = fDetectorRoot; 765 fCurrentSeparator = fDetectorRoot; 776 } 766 } 777 } 767 } 778 } 768 } 779 769 780 void G4OpenInventorSceneHandler::AddProperties 770 void G4OpenInventorSceneHandler::AddProperties(const G4VisAttributes* visAtts) 781 { 771 { 782 // Use the applicable vis attributes... 772 // Use the applicable vis attributes... 783 const G4VisAttributes* pApplicableVisAttribs 773 const G4VisAttributes* pApplicableVisAttribs = 784 fpViewer->GetApplicableVisAttributes (visA 774 fpViewer->GetApplicableVisAttributes (visAtts); 785 775 786 // First find the color attributes... 776 // First find the color attributes... 787 const G4Colour& g4Col = pApplicableVisAttri 777 const G4Colour& g4Col = pApplicableVisAttribs->GetColour (); 788 const G4double red = g4Col.GetRed (); << 778 const double red = g4Col.GetRed (); 789 const G4double green = g4Col.GetGreen (); << 779 const double green = g4Col.GetGreen (); 790 const G4double blue = g4Col.GetBlue (); << 780 const double blue = g4Col.GetBlue (); 791 G4double transparency = 1 - g4Col.GetAlpha() << 781 double transparency = 1 - g4Col.GetAlpha(); 792 782 793 // Drawing style... 783 // Drawing style... 794 G4ViewParameters::DrawingStyle drawing_style 784 G4ViewParameters::DrawingStyle drawing_style = 795 GetDrawingStyle(pApplicableVisAttribs); 785 GetDrawingStyle(pApplicableVisAttribs); 796 switch (drawing_style) { 786 switch (drawing_style) { 797 case (G4ViewParameters::wireframe): 787 case (G4ViewParameters::wireframe): 798 fModelingSolid = false; 788 fModelingSolid = false; 799 break; 789 break; 800 case (G4ViewParameters::hlr): 790 case (G4ViewParameters::hlr): 801 case (G4ViewParameters::hsr): 791 case (G4ViewParameters::hsr): 802 case (G4ViewParameters::hlhsr): 792 case (G4ViewParameters::hlhsr): 803 fModelingSolid = true; 793 fModelingSolid = true; 804 break; 794 break; 805 case (G4ViewParameters::cloud): << 806 fModelingSolid = false; << 807 break; << 808 } 795 } 809 796 810 // Edge visibility... 797 // Edge visibility... 811 G4bool isAuxEdgeVisible = GetAuxEdgeVisible 798 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs); 812 fReducedWireFrame = !isAuxEdgeVisible; 799 fReducedWireFrame = !isAuxEdgeVisible; 813 800 814 SoMaterial* material = 801 SoMaterial* material = 815 fStyleCache->getMaterial((G4float)red, << 802 fStyleCache->getMaterial((float)red, 816 (G4float)green, << 803 (float)green, 817 (G4float)blue, << 804 (float)blue, 818 (G4float)transparency); << 805 (float)transparency); 819 fCurrentSeparator->addChild(material); 806 fCurrentSeparator->addChild(material); 820 807 821 SoLightModel* lightModel = 808 SoLightModel* lightModel = 822 fModelingSolid ? fStyleCache->getLightMode 809 fModelingSolid ? fStyleCache->getLightModelPhong() : 823 fStyleCache->getLightModelBaseColor(); 810 fStyleCache->getLightModelBaseColor(); 824 fCurrentSeparator->addChild(lightModel); 811 fCurrentSeparator->addChild(lightModel); 825 } << 826 812 827 void G4OpenInventorSceneHandler::AddTransform( << 813 // Set up the geometrical transformation for the coming 828 { << 829 // AddTransform takes fObjectTransformation << 830 // Set up the geometrical transformation for << 831 fCurrentSeparator->addChild(fStyleCache->get 814 fCurrentSeparator->addChild(fStyleCache->getResetTransform()); 832 815 833 SoMatrixTransform* matrixTransform = new SoM 816 SoMatrixTransform* matrixTransform = new SoMatrixTransform; 834 G4OpenInventorTransform3D oiTran << 817 G4OpenInventorTransform3D oiTran(*fpObjectTransformation); 835 (fObjectTransformation * G4Translate3D(trans << 836 SbMatrix* sbMatrix = oiTran.GetSbMatrix(); 818 SbMatrix* sbMatrix = oiTran.GetSbMatrix(); 837 819 838 const G4Vector3D scale = fpViewer->GetViewPa 820 const G4Vector3D scale = fpViewer->GetViewParameters().GetScaleFactor(); 839 SbMatrix sbScale; 821 SbMatrix sbScale; 840 sbScale.setScale 822 sbScale.setScale 841 (SbVec3f((G4float)scale.x(),(G4float)scale << 823 (SbVec3f((float)scale.x(),(float)scale.y(),(float)scale.z())); 842 sbMatrix->multRight(sbScale); 824 sbMatrix->multRight(sbScale); 843 825 844 matrixTransform->matrix.setValue(*sbMatrix); 826 matrixTransform->matrix.setValue(*sbMatrix); 845 delete sbMatrix; 827 delete sbMatrix; 846 fCurrentSeparator->addChild(matrixTransform) 828 fCurrentSeparator->addChild(matrixTransform); 847 } 829 } >> 830 #endif 848 831