1 | // this : |
---|
2 | #include <G4Lab/SoVisitedVolume.h> |
---|
3 | |
---|
4 | // Inventor : |
---|
5 | #include <Inventor/errors/SoDebugError.h> |
---|
6 | #include <Inventor/SoPickedPoint.h> |
---|
7 | #include <Inventor/nodes/SoSeparator.h> |
---|
8 | #include <Inventor/nodes/SoTransform.h> |
---|
9 | #include <Inventor/nodes/SoLightModel.h> |
---|
10 | #include <Inventor/nodes/SoDrawStyle.h> |
---|
11 | #include <Inventor/nodes/SoEventCallback.h> |
---|
12 | #include <Inventor/events/SoMouseButtonEvent.h> |
---|
13 | |
---|
14 | // HEPVis : |
---|
15 | #include <HEPVis/SbPolyhedron.h> |
---|
16 | #include <HEPVis/nodes/SoPolyhedron.h> |
---|
17 | #include <HEPVis/nodes/SoHighlightMaterial.h> |
---|
18 | #include <HEPVis/misc/SoGC.h> |
---|
19 | #include <HEPVis/misc/SoStyleCache.h> |
---|
20 | |
---|
21 | #ifdef WIN32 |
---|
22 | #undef pascal // Clash between windef.h and Geant4/SystemOfnits.hh |
---|
23 | #endif |
---|
24 | |
---|
25 | // Geant4 : |
---|
26 | #include <G4Polyhedra.hh> |
---|
27 | #include <G4Polyhedron.hh> |
---|
28 | #include <G4Polyline.hh> |
---|
29 | #include <G4Transform3D.hh> |
---|
30 | #include <G4VPhysicalVolume.hh> |
---|
31 | #include <G4Normal3D.hh> |
---|
32 | #include <G4LogicalVolume.hh> |
---|
33 | #include <G4VisAttributes.hh> |
---|
34 | |
---|
35 | #include <G4Lab/GeometryVisitor.h> |
---|
36 | #include <G4Lab/Transform3D.h> |
---|
37 | #include <G4Lab/Polyhedron.h> |
---|
38 | |
---|
39 | // Lib : |
---|
40 | #include <Lib/smanip.h> |
---|
41 | |
---|
42 | #define NOT_FOUND (-1) |
---|
43 | |
---|
44 | ////////////////////////////////////////////////////////////////////////////// |
---|
45 | G4Lab::SoVisitedVolume::SoVisitedVolume( |
---|
46 | SoGC& aGC |
---|
47 | ,SoGroup& aParent |
---|
48 | ,G4VPhysicalVolume& aPhysicalVolume |
---|
49 | ) |
---|
50 | :fSoGC(aGC) |
---|
51 | ,fParent(aParent) |
---|
52 | ,fPhysicalVolume(aPhysicalVolume) |
---|
53 | ////////////////////////////////////////////////////////////////////////////// |
---|
54 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
55 | { |
---|
56 | } |
---|
57 | ////////////////////////////////////////////////////////////////////////////// |
---|
58 | G4Lab::SoVisitedVolume::~SoVisitedVolume( |
---|
59 | ) |
---|
60 | ////////////////////////////////////////////////////////////////////////////// |
---|
61 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
62 | { |
---|
63 | } |
---|
64 | ////////////////////////////////////////////////////////////////////////////// |
---|
65 | G4Lab::IVisitedVolume::Status G4Lab::SoVisitedVolume::beginVolume( |
---|
66 | G4VPhysicalVolume* aPV |
---|
67 | ,G4VSolid* aSolid |
---|
68 | ,G4Material* |
---|
69 | ,const G4Transform3D& aTransform |
---|
70 | ,int //aIndex |
---|
71 | ) |
---|
72 | ////////////////////////////////////////////////////////////////////////////// |
---|
73 | // Return true -> do not process daughters. |
---|
74 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
75 | { |
---|
76 | if(aPV!=(&fPhysicalVolume)) return IVisitedVolume::DAUGHTERS; |
---|
77 | |
---|
78 | if(aSolid) { |
---|
79 | G4Polyhedron* g4Polyhedron = aSolid->CreatePolyhedron(); |
---|
80 | // Have to convert to an SbPolyhedron : |
---|
81 | Polyhedron* polyhedron = new Polyhedron(*g4Polyhedron); |
---|
82 | delete g4Polyhedron; |
---|
83 | if(polyhedron) { |
---|
84 | |
---|
85 | if(aPV->GetLogicalVolume()) { |
---|
86 | const G4VisAttributes* visAtbs = |
---|
87 | aPV->GetLogicalVolume()->GetVisAttributes(); |
---|
88 | if(visAtbs && (fSoGC.getLocalSetup()==TRUE)) { |
---|
89 | const G4Color& color = visAtbs->GetColor(); |
---|
90 | //visible = visAtbs->IsVisible(); |
---|
91 | |
---|
92 | float r = (float)color.GetRed(); |
---|
93 | float g = (float)color.GetGreen(); |
---|
94 | float b = (float)color.GetBlue(); |
---|
95 | float t = 1 - (float)color.GetAlpha(); |
---|
96 | |
---|
97 | std::string s; |
---|
98 | Lib::smanip::printf(s,128,"color %g %g %g\ntransparency %g",r,g,b,t); |
---|
99 | fSoGC.setFromString(s.c_str()); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | // Build name (for picking) : |
---|
104 | std::string s; |
---|
105 | Lib::smanip::printf(s,128,"PV/0x%lx",aPV); |
---|
106 | SbName name(s.c_str()); |
---|
107 | |
---|
108 | //FIXME : can't cache due to the below setName for picking. |
---|
109 | //FIXME SoPolyhedron* soPolyhedron = fSoGC.getPolyhedron(*polyhedron); |
---|
110 | SoPolyhedron* soPolyhedron = new SoPolyhedron(*polyhedron); |
---|
111 | if(fSoGC.getModeling()==SbModeling_wire_frame) { |
---|
112 | soPolyhedron->solid.setValue(FALSE); |
---|
113 | //FIXME : handle reduceWireFrame. |
---|
114 | soPolyhedron->reducedWireFrame.setValue(TRUE); |
---|
115 | } else { |
---|
116 | soPolyhedron->solid.setValue(TRUE); |
---|
117 | } |
---|
118 | delete polyhedron; |
---|
119 | soPolyhedron->setName(name); |
---|
120 | |
---|
121 | #ifdef DEBUG |
---|
122 | printf("debug : G4Lab::SoVisitedVolume::visit : %s %s mode %d\n", |
---|
123 | aPV->GetName().c_str(),name.getString(),fMode); |
---|
124 | #endif |
---|
125 | SoSeparator* separator = new SoSeparator; |
---|
126 | separator->setName("sceneGraph"); |
---|
127 | |
---|
128 | separator->addChild(fSoGC.getHighlightMaterial()); |
---|
129 | separator->addChild(fSoGC.getDrawStyle()); |
---|
130 | separator->addChild(fSoGC.getLightModel()); |
---|
131 | |
---|
132 | //separator->addChild(fSoGC.getStyleCache()->getResetTransform()); |
---|
133 | |
---|
134 | SoTransform* transform = new SoTransform; |
---|
135 | Transform3D* t = new Transform3D(aTransform); |
---|
136 | SbMatrix* matrix = t->getMatrix(); |
---|
137 | transform->setMatrix(*matrix); |
---|
138 | delete matrix; |
---|
139 | delete t; |
---|
140 | separator->addChild(transform); |
---|
141 | |
---|
142 | separator->addChild(soPolyhedron); |
---|
143 | |
---|
144 | fParent.addChild(separator); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | // Continue to next sibling PV |
---|
149 | // (because a PV cannot be a daughter of itself). |
---|
150 | return IVisitedVolume::SIBLING; |
---|
151 | } |
---|
152 | ////////////////////////////////////////////////////////////////////////////// |
---|
153 | void G4Lab::SoVisitedVolume::endVolume( |
---|
154 | G4VPhysicalVolume* |
---|
155 | ) |
---|
156 | ////////////////////////////////////////////////////////////////////////////// |
---|
157 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
158 | { |
---|
159 | } |
---|
160 | ////////////////////////////////////////////////////////////////////////////// |
---|
161 | void G4Lab::SoVisitedVolume::beginDaughters( |
---|
162 | G4VPhysicalVolume* |
---|
163 | ,int |
---|
164 | ) |
---|
165 | ////////////////////////////////////////////////////////////////////////////// |
---|
166 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
167 | { |
---|
168 | } |
---|
169 | ////////////////////////////////////////////////////////////////////////////// |
---|
170 | void G4Lab::SoVisitedVolume::endDaughters( |
---|
171 | G4VPhysicalVolume* |
---|
172 | ,int |
---|
173 | ) |
---|
174 | ////////////////////////////////////////////////////////////////////////////// |
---|
175 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
176 | { |
---|
177 | } |
---|