Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VViewer Class Referenceabstract

#include <G4VViewer.hh>

+ Inheritance diagram for G4VViewer:

Classes

class  G4Spline
 

Public Member Functions

 G4VViewer (G4VSceneHandler &, G4int id, const G4String &name="")
 
virtual ~G4VViewer ()
 
virtual void Initialise ()
 
virtual void ResetView ()
 
virtual void SetView ()=0
 
virtual void ClearView ()=0
 
virtual void DrawView ()=0
 
void RefreshView ()
 
virtual void ShowView ()
 
virtual void FinishView ()
 
std::vector< G4ThreeVectorComputeFlyThrough (G4Vector3D *)
 
const G4StringGetName () const
 
const G4StringGetShortName () const
 
void SetName (const G4String &)
 
G4int GetViewId () const
 
G4VSceneHandlerGetSceneHandler () const
 
const G4ViewParametersGetViewParameters () const
 
const G4ViewParametersGetDefaultViewParameters () const
 
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers () const
 
void SetViewParameters (const G4ViewParameters &vp)
 
void SetDefaultViewParameters (const G4ViewParameters &vp)
 
const G4VisAttributesGetApplicableVisAttributes (const G4VisAttributes *) const
 
void SetNeedKernelVisit (G4bool need)
 
void NeedKernelVisit ()
 
void ProcessView ()
 

Protected Member Functions

void SetTouchable (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
 
void TouchableSetVisibility (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
 
void TouchableSetColour (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
 

Protected Attributes

G4VSceneHandlerfSceneHandler
 
G4int fViewId
 
G4String fName
 
G4String fShortName
 
G4ViewParameters fVP
 
G4ViewParameters fDefaultVP
 
G4bool fNeedKernelVisit
 

Friends

std::ostream & operator<< (std::ostream &os, const G4VViewer &v)
 

Detailed Description

Definition at line 45 of file G4VViewer.hh.

Constructor & Destructor Documentation

◆ G4VViewer()

G4VViewer::G4VViewer ( G4VSceneHandler sceneHandler,
G4int  id,
const G4String name = "" 
)

Definition at line 45 of file G4VViewer.cc.

46 :
47fSceneHandler (sceneHandler),
48fViewId (id),
49//fModified (true),
51{
52 if (name == "") {
53 std::ostringstream ost;
54 ost << fSceneHandler.GetName () << '-' << fViewId;
55 fName = ost.str();
56 }
57 else {
58 fName = name;
59 }
60 fShortName = fName (0, fName.find (' '));
62
65}
G4String strip(G4int strip_Type=trailing, char c=' ')
const G4String & GetName() const
G4bool fNeedKernelVisit
Definition: G4VViewer.hh:224
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:215
G4String fShortName
Definition: G4VViewer.hh:218
G4String fName
Definition: G4VViewer.hh:217
G4ViewParameters fDefaultVP
Definition: G4VViewer.hh:220
G4int fViewId
Definition: G4VViewer.hh:216
G4ViewParameters fVP
Definition: G4VViewer.hh:219
const G4ViewParameters & GetDefaultViewParameters() const
static G4VisManager * GetInstance()
const char * name(G4int ptype)

◆ ~G4VViewer()

G4VViewer::~G4VViewer ( )
virtual

Definition at line 67 of file G4VViewer.cc.

67 {
69}
void RemoveViewerFromList(G4VViewer *pView)

Member Function Documentation

◆ ClearView()

◆ ComputeFlyThrough()

std::vector< G4ThreeVector > G4VViewer::ComputeFlyThrough ( G4Vector3D )

Definition at line 205 of file G4VViewer.cc.

206{
207 enum CurveType {
208 Bezier,
209 G4SplineTest};
210
211 // Choose a curve type (for testing)
212// int myCurveType = Bezier;
213
214 // number if step points
215 int stepPoints = 500;
216
217
218 G4Spline spline;
219
220
221 // At the moment we don't use the aVect parameters, but build it here :
222 // Good step points for exampleB5
223 spline.AddSplinePoint(G4Vector3D(0,1000,-14000));
224 spline.AddSplinePoint(G4Vector3D(0,1000,0));
225 spline.AddSplinePoint(G4Vector3D(-4000,1000,4000));
226
227
228 std::vector <G4ThreeVector> viewVect;
229
230// if(myCurveType == Bezier) {
231
232
233 // Draw the spline
234
235 for (int i = 0; i < stepPoints; i++) {
236 float t = (float)i / (float)stepPoints;
237 G4Vector3D cameraPosition = spline.GetInterpolatedSplinePoint(t);
238 // G4Vector3D targetPoint = spline.GetInterpolatedSplinePoint(t);
239
240 // viewParam->SetViewAndLights(G4ThreeVector (cameraPosition.x(), cameraPosition.y(), cameraPosition.z()));
241 // viewParam->SetCurrentTargetPoint(targetPoint);
242 G4cout << "FLY CR("<< i << "):" << cameraPosition << G4endl;
243 viewVect.push_back(G4ThreeVector (cameraPosition.x(), cameraPosition.y(), cameraPosition.z()));
244 }
245
246// } else if (myCurveType == G4SplineTest) {
247 /*
248 This method is a inspire from a Bezier curve. The problem of the Bezier curve is that the path does not go straight between two waypoints.
249 This method add "stay straight" parameter which could be between 0 and 1 where the pass will follow exactly the line between the waypoints
250 Ex : stay straight = 50%
251 m1 = 3*(P1+P0)/2
252
253 Ex : stay straight = 0%
254 m1 = (P1+P0)/2
255
256 P1
257 / \
258 / \
259 a--x--b
260 / ° ° \
261 / ° ° \
262 m1 m2
263 / \
264 / \
265 / \
266 / \
267 P0 P2
268
269 */
270// G4Vector3D a;
271// G4Vector3D b;
272// G4Vector3D m1;
273// G4Vector3D m2;
274// G4Vector3D P0;
275// G4Vector3D P1;
276// G4Vector3D P2;
277// G4double stayStraight = 0;
278// G4double bezierSpeed = 0.4; // Spend 40% time in bezier curve (time between m1-m2 is 40% of time between P0-P1)
279//
280// G4Vector3D firstPoint;
281// G4Vector3D lastPoint;
282//
283// float nbBezierSteps = (stepPoints * bezierSpeed*(1-stayStraight)) * (2./spline.GetNumPoints());
284// float nbFirstSteps = ((stepPoints/2-nbBezierSteps/2) /(1+stayStraight)) * (2./spline.GetNumPoints());
285//
286// // First points
287// firstPoint = spline.GetPoint(0);
288// lastPoint = (firstPoint + spline.GetPoint(1))/2;
289//
290// for( float j=0; j<1; j+= 1/nbFirstSteps) {
291// G4ThreeVector pt = firstPoint + (lastPoint - firstPoint) * j;
292// viewVect.push_back(pt);
293// G4cout << "FLY Bezier A1("<< viewVect.size()<< "):" << pt << G4endl;
294// }
295//
296// for (int i = 0; i < spline.GetNumPoints()-2; i++) {
297// P0 = spline.GetPoint(i);
298// P1 = spline.GetPoint(i+1);
299// P2 = spline.GetPoint(i+2);
300//
301// m1 = P1 - (P1-P0)*(1-stayStraight)/2;
302// m2 = P1 + (P2-P1)*(1-stayStraight)/2;
303//
304// // We have to get straight path from (middile of P0-P1) to (middile of P0-P1 + (dist P0-P1) * stayStraight/2)
305// if (stayStraight >0) {
306//
307// firstPoint = (P0 + P1)/2;
308// lastPoint = (P0 + P1)/2 + (P1-P0)*stayStraight/2;
309//
310// for( float j=0; j<1; j+= 1/(nbFirstSteps*stayStraight)) {
311// G4ThreeVector pt = firstPoint + (lastPoint - firstPoint)* j;
312// viewVect.push_back(pt);
313// G4cout << "FLY Bezier A2("<< viewVect.size()<< "):" << pt << G4endl;
314// }
315// }
316// // Compute Bezier curve
317// for( float delta = 0 ; delta < 1 ; delta += 1/nbBezierSteps)
318// {
319// // The Green Line
320// a = m1 + ( (P1 - m1) * delta );
321// b = P1 + ( (m2 - P1) * delta );
322//
323// // Final point
324// G4ThreeVector pt = a + ((b-a) * delta );
325// viewVect.push_back(pt);
326// G4cout << "FLY Bezier("<< viewVect.size()<< "):" << pt << G4endl;
327// }
328//
329// // We have to get straight path
330// if (stayStraight >0) {
331// firstPoint = (P1 + P2)/2 - (P2-P1)*stayStraight/2;
332// lastPoint = (P1 + P2)/2;
333//
334// for( float j=0; j<1; j+= 1/(nbFirstSteps*stayStraight)) {
335// G4ThreeVector pt = firstPoint + (lastPoint - firstPoint)* j;
336// viewVect.push_back(pt);
337// G4cout << "FLY Bezier B1("<< viewVect.size()<< "):" << pt << G4endl;
338// }
339// }
340// }
341//
342// // last points
343// firstPoint = spline.GetPoint(spline.GetNumPoints()-2);
344// lastPoint = spline.GetPoint(spline.GetNumPoints()-1);
345// for( float j=1; j>0; j-= 1/nbFirstSteps) {
346// G4ThreeVector pt = lastPoint - ((lastPoint-firstPoint)*((1-stayStraight)/2) * j );
347// viewVect.push_back(pt);
348// G4cout << "FLY Bezier B2("<< viewVect.size()<< "):" << pt << G4endl;
349// }
350// }
351 return viewVect;
352}
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:34
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout

◆ DrawView()

◆ FinishView()

◆ GetApplicableVisAttributes()

const G4VisAttributes * G4VViewer::GetApplicableVisAttributes ( const G4VisAttributes ) const

◆ GetDefaultViewParameters()

const G4ViewParameters & G4VViewer::GetDefaultViewParameters ( ) const

◆ GetName()

◆ GetPrivateVisAttributesModifiers()

virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * G4VViewer::GetPrivateVisAttributesModifiers ( ) const
virtual

◆ GetSceneHandler()

◆ GetShortName()

const G4String & G4VViewer::GetShortName ( ) const

◆ GetViewId()

◆ GetViewParameters()

const G4ViewParameters & G4VViewer::GetViewParameters ( ) const

◆ Initialise()

virtual void G4VViewer::Initialise ( )
virtual

Reimplemented in G4RayTracerViewer.

◆ NeedKernelVisit()

void G4VViewer::NeedKernelVisit ( )

Definition at line 77 of file G4VViewer.cc.

77 {
78
79 fNeedKernelVisit = true;
80
81 // At one time I thought we'd better notify all viewers. But I guess
82 // each viewer can take care of itself, so the following code is
83 // redundant (but keep it commented out for now). (John Allison)
84 // Notify all viewers that a kernel visit is required.
85 // const G4ViewerList& viewerList = fSceneHandler.GetViewerList ();
86 // G4ViewerListConstIterator i;
87 // for (i = viewerList.begin(); i != viewerList.end(); i++) {
88 // (*i) -> SetNeedKernelVisit ();
89 // }
90 // ??...but, there's a problem in OpenGL Stored which seems to
91 // require *all* viewers to revisit the kernel, so...
92 // const G4ViewerList& viewerList = fSceneHandler.GetViewerList ();
93 // G4ViewerListConstIterator i;
94 // for (i = viewerList.begin(); i != viewerList.end(); i++) {
95 // (*i) -> SetNeedKernelVisit (true);
96 // }
97 // Feb 2005 - commented out. Let's fix OpenGL if necessary.
98}

Referenced by G4DAWNFILEViewer::DrawView(), G4GMocrenFileViewer::DrawView(), G4HepRepFileViewer::DrawView(), G4HepRepViewer::DrawView(), G4VTreeViewer::DrawView(), G4VRML1FileViewer::DrawView(), G4VRML2FileViewer::DrawView(), G4XXXFileViewer::DrawView(), G4XXXViewer::DrawView(), G4VisManager::GeometryHasChanged(), G4XXXSGViewer::KernelVisitDecision(), G4XXXStoredViewer::KernelVisitDecision(), G4VisManager::NotifyHandlers(), and G4VisCommandViewerRebuild::SetNewValue().

◆ ProcessView()

void G4VViewer::ProcessView ( )

Definition at line 104 of file G4VViewer.cc.

105{
106 // If the scene has changed, or if the concrete viewer has decided
107 // that it necessary to visit the kernel, perhaps because the view
108 // parameters have changed significantly (this should be done in the
109 // concrete viewer's DrawView)...
110 if (fNeedKernelVisit) {
111 // Reset flag. This must be done before ProcessScene to prevent
112 // recursive calls when recomputing transients...
113 fNeedKernelVisit = false;
116 }
117}
virtual void ProcessScene()
virtual void ClearStore()

Referenced by G4DAWNFILEViewer::DrawView(), G4GMocrenFileViewer::DrawView(), G4HepRepFileViewer::DrawView(), G4HepRepViewer::DrawView(), G4RayTracerViewer::DrawView(), G4VTreeViewer::DrawView(), G4VRML1FileViewer::DrawView(), G4VRML2FileViewer::DrawView(), G4XXXFileViewer::DrawView(), G4XXXSGViewer::DrawView(), G4XXXStoredViewer::DrawView(), and G4XXXViewer::DrawView().

◆ RefreshView()

void G4VViewer::RefreshView ( )

◆ ResetView()

virtual void G4VViewer::ResetView ( )
virtual

◆ SetDefaultViewParameters()

void G4VViewer::SetDefaultViewParameters ( const G4ViewParameters vp)

◆ SetName()

void G4VViewer::SetName ( const G4String name)

Definition at line 71 of file G4VViewer.cc.

71 {
72 fName = name;
73 fShortName = fName (0, fName.find (' '));
75}

◆ SetNeedKernelVisit()

void G4VViewer::SetNeedKernelVisit ( G4bool  need)

◆ SetTouchable()

void G4VViewer::SetTouchable ( const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &  fullPath)
protected

Definition at line 123 of file G4VViewer.cc.

125{
126 // Set the touchable for /vis/touchable/set/... commands.
127 std::ostringstream oss;
128 for (const auto& pvNodeId: fullPath) {
129 oss
130 << ' ' << pvNodeId.GetPhysicalVolume()->GetName()
131 << ' ' << pvNodeId.GetCopyNo();
132 }
133 G4UImanager::GetUIpointer()->ApplyCommand("/vis/set/touchable" + oss.str());
134}
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77

◆ SetView()

◆ SetViewParameters()

◆ ShowView()

◆ TouchableSetColour()

void G4VViewer::TouchableSetColour ( const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &  fullPath,
const G4Colour colour 
)
protected

Definition at line 170 of file G4VViewer.cc.

173{
174 // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
175
176 std::ostringstream oss;
177 oss << "/vis/touchable/set/colour "
178 << colour.GetRed() << ' ' << colour.GetGreen()
179 << ' ' << colour.GetBlue() << ' ' << colour.GetAlpha();
180
181 // The following is equivalent to
182 // G4UImanager::GetUIpointer()->ApplyCommand(oss.str());
183 // (assuming the touchable has already been set), but avoids view rebuild.
184
185 // Instantiate a working copy of a G4VisAttributes object...
186 G4VisAttributes workingVisAtts;
187 // and set the colour.
188 workingVisAtts.SetColour(colour);
189
192 (workingVisAtts,
195 // G4ModelingParameters::VASColour (VAS = Vis Attribute Signifier)
196 // signifies that it is the colour that should be picked out
197 // and merged with the touchable's normal vis attributes.
198
199 // Record on G4cout (with #) for information.
200 if (G4UImanager::GetUIpointer()->GetVerboseLevel() >= 2) {
201 G4cout << "# " << oss.str() << G4endl;
202 }
203}
G4double GetBlue() const
Definition: G4Colour.hh:152
G4double GetAlpha() const
Definition: G4Colour.hh:153
G4double GetRed() const
Definition: G4Colour.hh:150
G4double GetGreen() const
Definition: G4Colour.hh:151
static G4ModelingParameters::PVNameCopyNoPath GetPVNameCopyNoPath(const std::vector< G4PhysicalVolumeNodeID > &)
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
void SetColour(const G4Colour &)

◆ TouchableSetVisibility()

void G4VViewer::TouchableSetVisibility ( const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &  fullPath,
G4bool  visibility 
)
protected

Definition at line 136 of file G4VViewer.cc.

139{
140 // Changes the Vis Attribute Modifiers WITHOUT triggering a rebuild.
141
142 std::ostringstream oss;
143 oss << "/vis/touchable/set/visibility ";
144 if (visibiity) oss << "true"; else oss << "false";
145
146 // The following is equivalent to
147 // G4UImanager::GetUIpointer()->ApplyCommand(oss.str());
148 // (assuming the touchable has already been set), but avoids view rebuild.
149
150 // Instantiate a working copy of a G4VisAttributes object...
151 G4VisAttributes workingVisAtts;
152 // and set the visibility.
153 workingVisAtts.SetVisibility(visibiity);
154
157 (workingVisAtts,
160 // G4ModelingParameters::VASVisibility (VAS = Vis Attribute Signifier)
161 // signifies that it is the visibility that should be picked out
162 // and merged with the touchable's normal vis attributes.
163
164 // Record on G4cout (with #) for information.
165 if (G4UImanager::GetUIpointer()->GetVerboseLevel() >= 2) {
166 G4cout << "# " << oss.str() << G4endl;
167 }
168}
void SetVisibility(G4bool=true)

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const G4VViewer v 
)
friend

Definition at line 383 of file G4VViewer.cc.

383 {
384 os << "View " << v.fName << ":\n";
385 os << v.fVP;
386 return os;
387}

Member Data Documentation

◆ fDefaultVP

◆ fName

G4String G4VViewer::fName
protected

◆ fNeedKernelVisit

G4bool G4VViewer::fNeedKernelVisit
protected

◆ fSceneHandler

◆ fShortName

G4String G4VViewer::fShortName
protected

Definition at line 218 of file G4VViewer.hh.

Referenced by G4RayTracerViewer::DrawView(), G4VViewer(), and SetName().

◆ fViewId

G4int G4VViewer::fViewId
protected

Definition at line 216 of file G4VViewer.hh.

Referenced by G4RayTracerViewer::G4RayTracerViewer(), and G4VViewer().

◆ fVP


The documentation for this class was generated from the following files: