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