- Timestamp:
- Nov 9, 2007, 3:32:25 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenInventor/src/G4OpenInventorSceneHandler.cc
r529 r593 25 25 // 26 26 // 27 // $Id: G4OpenInventorSceneHandler.cc,v 1.5 0 2006/11/05 20:48:57allison Exp $28 // GEANT4 tag $Name: geant4-0 8-02-patch-01 $27 // $Id: G4OpenInventorSceneHandler.cc,v 1.53 2007/04/03 13:35:48 allison Exp $ 28 // GEANT4 tag $Name: geant4-09-00-ref-01 $ 29 29 // 30 30 // … … 96 96 #include "G4Trap.hh" 97 97 #include "G4Trd.hh" 98 #include "G4PhysicalVolumeModel.hh"99 #include "G4TrajectoriesModel.hh"100 #include "G4VTrajectory.hh"101 #include "G4VTrajectoryPoint.hh"102 #include "G4HitsModel.hh"103 #include "G4VHit.hh"104 98 #include "G4ModelingParameters.hh" 105 99 #include "G4VPhysicalVolume.hh" … … 189 183 } 190 184 191 void G4OpenInventorSceneHandler::LoadAtts192 (const G4Visible& visible,193 G4AttHolder* holder)194 {195 // Load G4Atts from G4VisAttributes, if any...196 const std::map<G4String,G4AttDef>* vaDefs =197 visible.GetVisAttributes()->GetAttDefs();198 if (vaDefs) {199 holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);200 }201 202 G4PhysicalVolumeModel* pPVModel =203 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);204 if (pPVModel) {205 // Load G4Atts from G4PhysicalVolumeModel...206 const std::map<G4String,G4AttDef>* defs = pPVModel->GetAttDefs();207 if (defs) {208 holder->AddAtts(pPVModel->CreateCurrentAttValues(), defs);209 }210 }211 212 G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);213 if (trajModel) {214 // Load G4Atts from trajectory...215 const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();216 const std::map<G4String,G4AttDef>* defs = traj->GetAttDefs();217 if (defs) {218 holder->AddAtts(traj->CreateAttValues(), defs);219 }220 G4int nPoints = traj->GetPointEntries();221 for (G4int i = 0; i < nPoints; ++i) {222 G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);223 const std::map<G4String,G4AttDef>* defs = trajPoint->GetAttDefs();224 if (defs) {225 holder->AddAtts(trajPoint->CreateAttValues(), defs);226 }227 }228 }229 230 G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);231 if (hitsModel) {232 // Load G4Atts from hit...233 const G4VHit* hit = hitsModel->GetCurrentHit();234 const std::map<G4String,G4AttDef>* defs = hit->GetAttDefs();235 if (defs) {236 holder->AddAtts(hit->CreateAttValues(), defs);237 }238 }239 }240 241 185 // 242 186 // Method for handling G4Polyline objects (from tracking). 243 187 // 244 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline& line) { 188 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyline& line) 189 { 190 AddProperties(line.GetVisAttributes()); // Transformation, colour, etc. 191 245 192 G4int nPoints = line.size(); 246 193 SbVec3f* pCoords = new SbVec3f[nPoints]; … … 252 199 } 253 200 254 // Don't understand why I have to do this again (done in255 // GeneratePrerequisites) - JA.256 //257 // Color258 //259 const G4Colour& c = GetColour (line);260 SoMaterial* material =261 fStyleCache->getMaterial((float)c.GetRed(),262 (float)c.GetGreen(),263 (float)c.GetBlue(),264 (float)(1-c.GetAlpha()));265 fCurrentSeparator->addChild(material);266 267 201 // 268 202 // Point Set … … 281 215 282 216 // Loads G4Atts for picking... 283 LoadAtts(line, pLine);217 if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(line, pLine); 284 218 285 219 #ifdef INVENTOR2_0 … … 294 228 } 295 229 296 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker& polymarker) { 230 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 231 { 232 AddProperties(polymarker.GetVisAttributes()); // Transformation, colour, etc. 233 297 234 G4int pointn = polymarker.size(); 298 235 if(pointn<=0) return; … … 305 242 } 306 243 307 // Don't understand why I have to do this again (done in308 // GeneratePrerequisites) - JA.309 const G4Colour& c = GetColour (polymarker);310 SoMaterial* material =311 fStyleCache->getMaterial((float)c.GetRed(),312 (float)c.GetGreen(),313 (float)c.GetBlue(),314 (float)(1-c.GetAlpha()));315 fCurrentSeparator->addChild(material);316 317 244 SoCoordinate3* coordinate3 = new SoCoordinate3; 318 245 coordinate3->point.setValues(0,pointn,points); … … 336 263 337 264 // Loads G4Atts for picking... 338 LoadAtts(polymarker, markerSet); 265 if (fpViewer->GetViewParameters().IsPicking()) 266 LoadAtts(polymarker, markerSet); 339 267 340 268 G4VMarker::FillStyle style = polymarker.GetFillStyle(); … … 410 338 // Method for handling G4Text objects 411 339 // 412 void G4OpenInventorSceneHandler::AddPrimitive (const G4Text& text) { 340 void G4OpenInventorSceneHandler::AddPrimitive (const G4Text& text) 341 { 342 AddProperties(text.GetVisAttributes()); // Transformation, colour, etc. 343 413 344 // 414 345 // Color. Note: text colour is worked out differently. This 415 // over-rides the colour added in GeneratePrerequisites...346 // over-rides the colour added in AddProperties... 416 347 // 417 348 const G4Colour& c = GetTextColour (text); … … 476 407 477 408 void G4OpenInventorSceneHandler::AddCircleSquare 478 (G4OIMarker markerType, const G4VMarker& marker) { 479 480 // Don't understand why I have to do this again (done in 481 // GeneratePrerequisites) - JA. 482 // 483 // Color 484 // 485 const G4Colour& c = GetColour (marker); 486 SoMaterial* material = 487 fStyleCache->getMaterial((float)c.GetRed(), 488 (float)c.GetGreen(), 489 (float)c.GetBlue(), 490 (float)(1-c.GetAlpha())); 491 fCurrentSeparator->addChild(material); 409 (G4OIMarker markerType, const G4VMarker& marker) 410 { 411 AddProperties(marker.GetVisAttributes()); // Transformation, colour, etc. 492 412 493 413 MarkerSizeType sizeType; … … 519 439 520 440 // Loads G4Atts for picking... 521 LoadAtts(marker, markerSet);441 if (fpViewer->GetViewParameters().IsPicking()) LoadAtts(marker, markerSet); 522 442 523 443 G4VMarker::FillStyle style = marker.GetFillStyle(); … … 574 494 // Method for handling G4Polyhedron objects for drawing solids. 575 495 // 576 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) { 496 void G4OpenInventorSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) 497 { 577 498 if (polyhedron.GetNoFacets() == 0) return; 578 499 500 AddProperties(polyhedron.GetVisAttributes()); // Transformation, colour, etc. 501 579 502 SoG4Polyhedron* soPolyhedron = new SoG4Polyhedron(polyhedron); 580 503 581 504 // Loads G4Atts for picking... 582 LoadAtts(polyhedron, soPolyhedron); 505 if (fpViewer->GetViewParameters().IsPicking()) 506 LoadAtts(polyhedron, soPolyhedron); 583 507 584 508 SbString name = "Non-geometry"; … … 600 524 // 601 525 void G4OpenInventorSceneHandler::AddPrimitive (const G4NURBS& nurb) { 526 527 AddProperties(nurb.GetVisAttributes()); // Transformation, colour, etc. 602 528 603 529 G4float *u_knot_array, *u_knot_array_ptr; … … 618 544 619 545 SoSeparator *surfSep = new SoSeparator(); 620 621 //622 // Color623 //624 const G4Colour& c = GetColour (nurb);625 SoMaterial* material =626 fStyleCache->getMaterial((float)c.GetRed(),627 (float)c.GetGreen(),628 (float)c.GetBlue(),629 (float)(1-c.GetAlpha()));630 surfSep->addChild(material);631 546 632 547 // … … 686 601 // location on in the scene database so that when the solid is 687 602 // actually added (in addthis), it is put in the right place. 688 689 // Use the applicable vis attributes...690 const G4VisAttributes* pApplicableVisAttribs =691 fpViewer->GetApplicableVisAttributes (fpVisAttribs);692 693 // First find the color attributes...694 const G4Colour& g4Col = pApplicableVisAttribs->GetColour ();695 const double red = g4Col.GetRed ();696 const double green = g4Col.GetGreen ();697 const double blue = g4Col.GetBlue ();698 double transparency = 1 - g4Col.GetAlpha();699 700 // Drawing style...701 G4ViewParameters::DrawingStyle drawing_style =702 GetDrawingStyle(pApplicableVisAttribs);703 switch (drawing_style) {704 case (G4ViewParameters::wireframe):705 fModelingSolid = false;706 break;707 case (G4ViewParameters::hlr):708 case (G4ViewParameters::hsr):709 case (G4ViewParameters::hlhsr):710 fModelingSolid = true;711 break;712 }713 714 // Edge visibility...715 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs);716 fReducedWireFrame = !isAuxEdgeVisible;717 603 718 604 G4PhysicalVolumeModel* pPVModel = … … 771 657 if(fPreviewAndFull) detectorTreeKit->setPreviewAndFull(); 772 658 else detectorTreeKit->setPreview(TRUE); 659 660 // Colour, etc., for SoDetectorTreeKit. Treated differently to 661 // othere SoNodes(?). Use fpVisAttribs stored away in 662 // PreAddSolid... 663 const G4VisAttributes* pApplicableVisAttribs = 664 fpViewer->GetApplicableVisAttributes (fpVisAttribs); 665 666 // First find the color attributes... 667 const G4Colour& g4Col = pApplicableVisAttribs->GetColour (); 668 const double red = g4Col.GetRed (); 669 const double green = g4Col.GetGreen (); 670 const double blue = g4Col.GetBlue (); 671 double transparency = 1 - g4Col.GetAlpha(); 672 673 // Drawing style... 674 G4ViewParameters::DrawingStyle drawing_style = 675 GetDrawingStyle(pApplicableVisAttribs); 676 switch (drawing_style) { 677 case (G4ViewParameters::wireframe): 678 fModelingSolid = false; 679 break; 680 case (G4ViewParameters::hlr): 681 case (G4ViewParameters::hsr): 682 case (G4ViewParameters::hlhsr): 683 fModelingSolid = true; 684 break; 685 } 773 686 774 687 SoMaterial* material = … … 853 766 } 854 767 } 768 } 769 770 void G4OpenInventorSceneHandler::AddProperties(const G4VisAttributes* visAtts) 771 { 772 // Use the applicable vis attributes... 773 const G4VisAttributes* pApplicableVisAttribs = 774 fpViewer->GetApplicableVisAttributes (visAtts); 775 776 // First find the color attributes... 777 const G4Colour& g4Col = pApplicableVisAttribs->GetColour (); 778 const double red = g4Col.GetRed (); 779 const double green = g4Col.GetGreen (); 780 const double blue = g4Col.GetBlue (); 781 double transparency = 1 - g4Col.GetAlpha(); 782 783 // Drawing style... 784 G4ViewParameters::DrawingStyle drawing_style = 785 GetDrawingStyle(pApplicableVisAttribs); 786 switch (drawing_style) { 787 case (G4ViewParameters::wireframe): 788 fModelingSolid = false; 789 break; 790 case (G4ViewParameters::hlr): 791 case (G4ViewParameters::hsr): 792 case (G4ViewParameters::hlhsr): 793 fModelingSolid = true; 794 break; 795 } 796 797 // Edge visibility... 798 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pApplicableVisAttribs); 799 fReducedWireFrame = !isAuxEdgeVisible; 855 800 856 801 SoMaterial* material = … … 883 828 fCurrentSeparator->addChild(matrixTransform); 884 829 } 885 886 830 #endif
Note: See TracChangeset
for help on using the changeset viewer.