Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VtkSceneHandler.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29// John Allison 5th April 2001
30// A template for a simplest possible graphics driver.
31//?? Lines or sections marked like this require specialisation for your driver.
32
33#include "G4VtkSceneHandler.hh"
34
35#include "G4Box.hh"
36#include "G4Circle.hh"
37#include "G4LogicalVolume.hh"
39#include "G4Material.hh"
40#include "G4Mesh.hh"
42#include "G4Polyhedron.hh"
43#include "G4Polyline.hh"
44#include "G4PseudoScene.hh"
45#include "G4Square.hh"
46#include "G4SystemOfUnits.hh"
47#include "G4Text.hh"
48#include "G4UnitsTable.hh"
50#include "G4VPhysicalVolume.hh"
51#include "G4VtkStore.hh"
52#include "G4VtkVisContext.hh"
53
54#include <vtkColorTransferFunction.h>
55#include <vtkContourValues.h>
56#include <vtkPiecewiseFunction.h>
57#include <vtkVolumeProperty.h>
58
59#include <cstdlib>
60
62// Counter for XXX scene handlers.
63
67
69{
70#ifdef G4VTKDEBUG
71 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Polyline&)" << G4endl;
72#endif
73 auto vc = MakeDefaultVisContext();
74
76 transientStore.AddPrimitive(polyline, vc);
77 else
78 store.AddPrimitive(polyline, vc);
79}
80
82{
83#ifdef G4VTKDEBUG
84 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Text& text)" << G4endl;
85#endif
86
87 auto vc = MakeDefaultVisContext();
88
90 transientStore.AddPrimitive(text, vc);
91 else
92 store.AddPrimitive(text, vc);
93}
94
96{
97#ifdef G4VTKDEBUG
98 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Circle& circle)" << G4endl;
99#endif
100
101 auto vc = MakeDefaultVisContext();
103 vc.fSize = GetMarkerSize(circle, sizeType);
104
106 transientStore.AddPrimitive(circle, vc);
107 else
108 store.AddPrimitive(circle, vc);
109}
110
112{
113#ifdef G4VTKDEBUG
114 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Square& square)" << G4endl;
115#endif
116
117 auto vc = MakeDefaultVisContext();
119 vc.fSize = GetMarkerSize(square, sizeType);
120
122 transientStore.AddPrimitive(square, vc);
123 else
124 store.AddPrimitive(square, vc);
125}
126
128{
129#ifdef G4VTKDEBUG
130 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron)" << G4endl;
131#endif
132
133 auto vc = MakeDefaultVisContext();
134 auto visAtt = vc.fViewer->GetApplicableVisAttributes(polyhedron.GetVisAttributes());
135 auto colour = visAtt->GetColour();
136
137 vc.fDrawingStyle = GetDrawingStyle(visAtt);
138 vc.alpha = colour.GetAlpha();
139 vc.red = colour.GetRed();
140 vc.green = colour.GetGreen();
141 vc.blue = colour.GetBlue();
142
143 auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
144 if (pPVModel != nullptr) {
145 vc.fDepth = pPVModel->GetCurrentDepth();
146 vc.fDescription = pPVModel->GetCurrentDescription();
147 }
148
150 if (polyhedronPipelineType == "tensor")
151 transientStore.AddPrimitiveTensorGlyph(polyhedron, vc);
152 else if (polyhedronPipelineType == "append")
153 transientStore.AddPrimitiveAppend(polyhedron, vc);
154 else if (polyhedronPipelineType == "bake")
155 transientStore.AddPrimitiveTransformBake(polyhedron, vc);
156 else if (polyhedronPipelineType == "separate")
157 transientStore.AddPrimitiveSeparate(polyhedron, vc);
158 }
159 else {
160 if (polyhedronPipelineType == "tensor")
161 store.AddPrimitiveTensorGlyph(polyhedron, vc);
162 else if (polyhedronPipelineType == "append")
163 store.AddPrimitiveAppend(polyhedron, vc);
164 else if (polyhedronPipelineType == "bake")
165 store.AddPrimitiveTransformBake(polyhedron, vc);
166 else if (polyhedronPipelineType == "separate")
167 store.AddPrimitiveSeparate(polyhedron, vc);
168 }
169}
170
172{
173#ifdef G4VTKDEBUG
174 G4cout << "G4VtkSceneHandler::Modified()" << G4endl;
175#endif
176
177 store.Modified();
178 transientStore.Modified();
179}
180
182{
183#ifdef G4VTKDEBUG
184 G4cout << "G4VtkSceneHandler::ClearStore()" << G4endl;
185#endif
186 store.Clear();
187 transientStore.Clear();
188}
189
191{
192#ifdef G4VTKDEBUG
193 G4cout << "G4VtkSceneHandler::ClearTransientStore()" << G4endl;
194#endif
195 transientStore.Clear();
196}
197
199{
202
203 if (fpVisAttribs != nullptr) {
204 G4Colour c = fpVisAttribs->GetColour();
205 vc.red = c.GetRed();
206 vc.green = c.GetGreen();
207 vc.blue = c.GetBlue();
208 vc.alpha = c.GetAlpha();
209 vc.fDrawingStyle = fpViewer->GetViewParameters().GetDrawingStyle();
210 }
211
212 return vc;
213}
214
216{
218
219 return;
220
221 const G4VModel* pv_model = GetModel();
222 if (pv_model == nullptr) {
223 return;
224 }
225
226 auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
227 if (pPVModel == nullptr) {
228 return;
229 }
230
231 //-- debug information
232#ifdef G4VTKDEBUG
233 G4VPhysicalVolume* pv = pPVModel->GetCurrentPV();
235 G4cout << "name=" << box.GetName() << " volumeType=" << pv->VolumeType()
236 << " pvName=" << pv->GetName() << " lvName=" << lv->GetName()
237 << " multiplicity=" << pv->GetMultiplicity() << " isparametrised=" << pv->IsParameterised()
238 << " isreplicated=" << pv->IsReplicated()
239 << " parametrisation=" << pv->GetParameterisation()
240 << G4endl
241
242 G4Material* mat = pPVModel->GetCurrentMaterial();
243 G4String name = mat->GetName();
244 G4double dens = mat->GetDensity() / (g / cm3);
245 G4int copyNo = pPVModel->GetCurrentPV()->GetCopyNo();
246 G4int depth = pPVModel->GetCurrentDepth();
247 G4cout << " name : " << box.GetName() << G4endl;
248 G4cout << " copy no.: " << copyNo << G4endl;
249 G4cout << " depth : " << depth << G4endl;
250 G4cout << " density : " << dens << " [g/cm3]" << G4endl;
251 G4cout << " location: " << pPVModel->GetCurrentPV()->GetObjectTranslation() << G4endl;
252 G4cout << " Multiplicity : " << pPVModel->GetCurrentPV()->GetMultiplicity() << G4endl;
253 G4cout << " Is replicated? : " << pPVModel->GetCurrentPV()->IsReplicated() << G4endl;
254 G4cout << " Is parameterised? : " << pPVModel->GetCurrentPV()->IsParameterised() << G4endl;
255 G4cout << " top phys. vol. name : " << pPVModel->GetTopPhysicalVolume()->GetName() << G4endl;
256#endif
257}
258
260{
261#ifdef G4VTKDEBUG
262 G4cout << "G4VtkSceneHandler::AddCompound> mesh type " << mesh.GetMeshType() << " "
263 << fpViewer->GetViewParameters().GetSpecialMeshRenderingOption() << G4endl;
264#endif
265
266 if(fpViewer->GetViewParameters().GetSpecialMeshRenderingOption() == G4ViewParameters::meshAsDefault)
267 {
268 auto vc = MakeDefaultVisContext();
269
271 transientStore.AddCompound(mesh, vc);
272 else
273 store.AddCompound(mesh, vc);
274 }
275 else {
277 }
278}
279
281
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4Box is a cuboid of given half lengths dx,dy,dz. The Box is centred on the origin with sides paralle...
Definition G4Box.hh:58
G4double GetBlue() const
Definition G4Colour.hh:172
G4double GetAlpha() const
Definition G4Colour.hh:173
G4double GetRed() const
Definition G4Colour.hh:170
G4double GetGreen() const
Definition G4Colour.hh:171
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
const G4String & GetName() const
MeshType GetMeshType() const
Definition G4Mesh.hh:75
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
virtual G4bool IsReplicated() const =0
virtual EVolume VolumeType() const =0
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetMultiplicity() const
const G4String & GetName() const
virtual G4VPVParameterisation * GetParameterisation() const =0
virtual G4bool IsParameterised() const =0
G4VModel * GetModel() const
G4Transform3D fObjectTransformation
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
G4VSceneHandler(G4VGraphicsSystem &system, G4int id, const G4String &name="")
const G4VisAttributes * fpVisAttribs
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
virtual void AddSolid(const G4Box &)
void StandardSpecialMeshRendering(const G4Mesh &)
G4String GetName() const
const G4VisAttributes * GetVisAttributes() const
void ClearTransientStore() override
void AddCompound(const G4Mesh &mesh) override
void AddPrimitive(const G4Polyline &) override
void SetPolyhedronPipeline(const G4String &str)
void ClearStore() override
void AddSolid(const G4Box &box) override
G4VtkSceneHandler(G4VGraphicsSystem &system, const G4String &name)
G4VtkVisContext MakeDefaultVisContext()