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