source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Visualization/compiledcontrol.xml

Last change on this file was 1208, checked in by garnier, 15 years ago

CVS update

File size: 24.3 KB
Line 
1<!-- ******************************************************** -->
2<!--                                                          -->
3<!--  [History]                                               -->
4<!--    Proof read by: Joe Chuma,  6-Jul-1999                 -->
5<!--    Changed by: Katsuya Amako, 15-Jul-2000                -->
6<!--    Changed by: Dennis Wright, 27-Nov-2001                -->
7<!--    Converted to DocBook: Katsuya Amako, Aug-2006         -->
8<!--    Corrected Get methods: Joseph Perl, 17-Mar-2009       -->
9<!--                                                          -->
10<!-- ******************************************************** -->
11
12
13<!-- ******************* Section (Level#1) ****************** -->
14<sect1 id="sect.VisCntCmpl">
15<title>
16Controlling Visualization from Compiled Code
17</title>
18
19
20<para>
21While a Geant4 simulation is running, visualization can be
22performed without user intervention. This is accomplished by
23calling methods of the Visualization Manager from methods of the
24user action classes (<emphasis>G4UserRunAction</emphasis> and
25<emphasis>G4UserEventAction</emphasis>, for example). In this section methods of
26the class <emphasis>G4VVisManager</emphasis>, which is part of the
27<literal>graphics_reps</literal> category, are described and examples of
28their use are given.
29</para>
30
31<!-- ******************* Section (Level#2) ****************** -->
32<sect2 id="sect.VisCntCmpl.VsMng">
33<title>
34G4VVisManager
35</title>
36
37<para>
38The Visualization Manager is implemented by classes
39<emphasis>G4VisManager</emphasis> and <emphasis>G4VisExecutive</emphasis>.
40See <xref linkend="sect.VisAddExe" />
41"<emphasis role="bold">Making a Visualization Executable</emphasis>". In order
42that your Geant4 be compilable either with or without the visualization
43category, you should not use these classes directly in your C++
44source code, other than in the <literal>main()</literal> function. Instead,
45you should use their abstract base class <emphasis>G4VVisManager</emphasis>,
46defined in the <literal>intercoms</literal> category.
47</para>
48
49<para>
50The pointer to the concrete instance of the real Visualization
51Manager can be obtained as follows:
52
53<informalexample>
54<programlisting>
55  //----- Getting a pointer to the concrete Visualization Manager instance
56  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
57</programlisting>
58</informalexample> 
59</para>
60
61<para>
62The method <literal>G4VVisManager::GetConcreteInstance()</literal> returns
63<literal>NULL</literal> if Geant4 is not ready for visualization. Thus your
64C++ source code should be protected as follows:
65
66<informalexample>
67<programlisting>
68  //----- How to protect your C++ source codes in visualization
69  if (pVVisManager) {
70      ....
71      pVVisManager -&gt;Draw (...);
72      ....
73  }
74</programlisting>
75</informalexample> 
76</para>
77
78</sect2>
79
80
81<!-- ******************* Section (Level#2) ****************** -->
82<sect2 id="sect.VisCntCmpl.DtcCmp">
83<title>
84Visualization of detector components
85</title>
86
87<para>
88If you have already constructed detector components with logical
89volumes to which visualization attributes are properly assigned,
90you are almost ready for visualizing detector components. All you
91have to do is to describe proper visualization commands within your
92C++ codes, using the <literal>ApplyCommand()</literal> method.
93</para>
94
95<para>
96For example, the following is sample C++ source codes to
97visualize the detector components:
98
99<informalexample>
100<programlisting>
101  //----- C++ source code: How to visualize detector components (2)
102  //                       ... using visualization commands in source codes
103 
104  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance() ;
105
106  if(pVVisManager)
107  {
108      ... (camera setting etc) ...
109      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/drawVolume");
110      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/viewer/flush");
111  }
112
113  //-----  end of C++ source code
114 
115</programlisting>
116</informalexample>
117</para>
118
119<para>
120In the above, you should also describe <literal>/vis/open</literal> command
121somewhere in your C++ codes or execute the command from (G)UI at
122the executing stage.
123</para>
124
125</sect2>
126
127
128<!-- ******************* Section (Level#2) ****************** -->
129<sect2 id="sect.VisCntCmpl.Trjct">
130<title>
131Visualization of trajectories
132</title>
133
134<para>
135In order to visualize trajectories, you can use the method <literal>void
136G4Trajectory::DrawTrajectory()</literal> defined in the tracking
137category. In the implementation of this method, the following
138drawing method of <emphasis>G4VVisManager</emphasis> is used:
139
140<informalexample>
141<programlisting>
142    //----- A drawing method of G4Polyline
143    virtual void G4VVisManager::Draw (const G4Polyline&amp;, ...) ;
144</programlisting>
145</informalexample>
146</para>
147
148<para>
149The real implementation of this method is described in the class
150<emphasis>G4VisManager</emphasis>.
151</para>
152
153<para>
154At the end of one event, a set of trajectories can be stored as
155a list of <emphasis>G4Trajectory</emphasis> objects. Therefore you can visualize
156trajectories, for example, at the end of each event, by
157implementing the method <literal>MyEventAction::EndOfEventAction()</literal>
158as follows:
159
160<informalexample>
161<programlisting>
162  //----- C++ source codes
163  void ExN03EventAction::EndOfEventAction(const G4Event* evt)
164  {
165    ..... 
166    // extract the trajectories and draw them
167    if (G4VVisManager::GetConcreteInstance())
168      {
169       G4TrajectoryContainer* trajectoryContainer = evt-&gt;GetTrajectoryContainer();
170       G4int n_trajectories = 0;
171       if (trajectoryContainer) n_trajectories = trajectoryContainer-&gt;entries();
172 
173       for (G4int i=0; i &lt; n_trajectories; i++)
174          { G4Trajectory* trj=(G4Trajectory*)((*(evt-&gt;GetTrajectoryContainer()))[i]);
175            if (drawFlag == "all") trj-&gt;DrawTrajectory(50);
176            else if ((drawFlag == "charged")&amp;&amp;(trj-&gt;GetCharge() != 0.))
177                                    trj-&gt;DrawTrajectory(50);
178            else if ((drawFlag == "neutral")&amp;&amp;(trj-&gt;GetCharge() == 0.))
179                                    trj-&gt;DrawTrajectory(50);
180          }
181    }
182  } 
183  //----- end of C++ source codes
184</programlisting>
185</informalexample>
186</para>
187
188</sect2>
189
190
191<!-- ******************* Section (Level#2) ****************** -->
192<sect2 id="sect.VisCntCmpl.EnhTrjct">
193<title>
194Enhanced trajectory drawing
195</title>
196
197<para>
198It is possible to use the enhanced trajectory drawing functionality
199in compiled code as well as from commands. Multiple trajectory
200models can be instantiated, configured and registered with
201G4VisManager. For details, see the section on
202<xref linkend="sect.VisEnhTrj.CntlCmpl" /> 
203Enhanced Trajectory Drawing.
204</para>
205
206</sect2>
207
208
209<!-- ******************* Section (Level#2) ****************** -->
210<sect2 id="sect.VisCntCmpl.AttTrjct">
211<title>
212HepRep Attributes for Trajectories
213</title>
214
215<para>
216The HepRep file formats, HepRepFile and HepRepXML, attach various
217attributes to trajectories such that you can view these attributes,
218label trajectories by these attributes or make visibility cuts
219based on these attributes. If you use the default Geant4 trajectory
220class, from /tracking/src/G4Trajectory.cc, available attributes
221will be:
222
223<itemizedlist spacing="compact">
224  <listitem><para>
225    Track ID
226  </para></listitem>
227  <listitem><para>
228    Parent ID
229  </para></listitem>
230  <listitem><para>
231    Particle Name
232  </para></listitem>
233  <listitem><para>
234    Charge
235  </para></listitem>
236  <listitem><para>
237    PDG Encoding
238  </para></listitem>
239  <listitem><para>
240    Momentum 3-Vector
241  </para></listitem>
242  <listitem><para>
243    Momentum magnitude
244  </para></listitem>
245  <listitem><para>
246    Number of points
247  </para></listitem>
248</itemizedlist>
249</para>
250
251<para>
252You can add additional attributes of your choosing by modifying the
253relevant part of G4Trajectory (look for the methods GetAttDefs and
254CreateAttValues). If you are using your own trajectory class, you
255may want to consider copying these methods from G4Trajectory.
256</para>
257
258</sect2>
259
260
261<!-- ******************* Section (Level#2) ****************** -->
262<sect2 id="sect.VisCntCmpl.Hits">
263<title>
264Visualization of hits
265</title>
266
267<para>
268Hits are visualized with classes <emphasis>G4Square</emphasis> or
269<emphasis>G4Circle</emphasis>, or other user-defined classes inheriting the
270abstract base class <emphasis>G4VMarker</emphasis>. Drawing methods for hits are
271not supported by default. Instead, ways of their implementation are
272guided by virtual methods, <literal>G4VHit::Draw()</literal> and
273<literal>G4VHitsCollection::DrawAllHits()</literal>, of the abstract base
274classes <emphasis>G4VHit</emphasis> and <emphasis>G4VHitsCollection</emphasis>.
275These methods are defined as empty functions in the <literal>digits+hits</literal>
276category. You can overload these methods, using the following
277drawing methods of class <emphasis>G4VVisManager</emphasis>, in order to
278visualize hits:
279
280<informalexample>
281<programlisting>
282  //----- Drawing methods of G4Square and G4Circle
283  virtual void G4VVisManager::Draw (const G4Circle&amp;, ...) ;
284  virtual void G4VVisManager::Draw (const G4Square&amp;, ...) ;
285</programlisting>
286</informalexample>
287</para>
288
289<para>
290The real implementations of these <literal>Draw()</literal> methods are
291described in class <emphasis>G4VisManager</emphasis>.
292</para>
293
294<para>
295The overloaded implementation of <literal>G4VHits::Draw()</literal> will
296be held by, for example, class <emphasis>MyTrackerHits</emphasis> inheriting
297<emphasis>G4VHit</emphasis> as follows:
298
299<informalexample>
300<programlisting>
301  //----- C++ source codes: An example of giving concrete implementation of
302  //       G4VHit::Draw(), using  class MyTrackerHit : public G4VHit {...}
303  //     
304 void MyTrackerHit::Draw()
305 {
306    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
307    if(pVVisManager)
308    {
309      // define a circle in a 3D space
310      G4Circle circle(pos);
311      circle.SetScreenSize(0.3);
312      circle.SetFillStyle(G4Circle::filled);
313
314      // make the circle red
315      G4Colour colour(1.,0.,0.);
316      G4VisAttributes attribs(colour);
317      circle.SetVisAttributes(attribs);
318
319      // make a 3D data for visualization
320      pVVisManager-&gt;Draw(circle);
321    }
322  }
323
324  //----- end of C++ source codes
325 
326</programlisting>
327</informalexample>
328</para>
329
330<para>
331The overloaded implementation of
332<literal>G4VHitsCollection::DrawAllHits()</literal> will be held by, for
333example, class <emphasis>MyTrackerHitsCollection</emphasis> inheriting class
334<emphasis>G4VHitsCollection</emphasis> as follows:
335
336<informalexample>
337<programlisting>
338  //----- C++ source codes: An example of giving concrete implementation of
339  //       G4VHitsCollection::Draw(),
340  //       using  class MyTrackerHit : public G4VHitsCollection{...}
341  //     
342  void MyTrackerHitsCollection::DrawAllHits()
343  {
344    G4int n_hit = theCollection.entries();
345    for(G4int i=0;i &lt; n_hit;i++)
346    {
347      theCollection[i].Draw();
348    }
349  }
350
351  //----- end of C++ source codes
352 
353</programlisting>
354</informalexample>
355</para>
356
357<para>
358Thus, you can visualize hits as well as trajectories, for
359example, at the end of each event by implementing the method
360<literal>MyEventAction::EndOfEventAction()</literal> as follows:
361
362<informalexample>
363<programlisting>
364  void MyEventAction::EndOfEventAction()
365  {
366    const G4Event* evt = fpEventManager-&gt;GetConstCurrentEvent();
367
368    G4SDManager * SDman = G4SDManager::GetSDMpointer();
369    G4String colNam;
370    G4int trackerCollID = SDman-&gt;GetCollectionID(colNam="TrackerCollection");
371    G4int calorimeterCollID = SDman-&gt;GetCollectionID(colNam="CalCollection");
372
373    G4TrajectoryContainer * trajectoryContainer = evt-&gt;GetTrajectoryContainer();
374    G4int n_trajectories = 0;
375    if(trajectoryContainer)
376    { n_trajectories = trajectoryContainer-&gt;entries(); }
377
378    G4HCofThisEvent * HCE = evt-&gt;GetHCofThisEvent();
379    G4int n_hitCollection = 0;
380    if(HCE)
381    { n_hitCollection = HCE-&gt;GetCapacity(); }
382 
383    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
384
385    if(pVVisManager)
386    {
387 
388      // Declare begininng of visualization
389      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/scene/notifyHandlers");
390
391      // Draw trajectories
392      for(G4int i=0; i &lt; n_trajectories; i++)
393      {
394          (*(evt-&gt;GetTrajectoryContainer()))[i]-&gt;DrawTrajectory();
395      }
396
397      // Construct 3D data for hits
398      MyTrackerHitsCollection* THC
399        = (MyTrackerHitsCollection*)(HCE-&gt;GetHC(trackerCollID));
400      if(THC) THC-&gt;DrawAllHits();
401      MyCalorimeterHitsCollection* CHC
402        = (MyCalorimeterHitsCollection*)(HCE-&gt;GetHC(calorimeterCollID));
403      if(CHC) CHC-&gt;DrawAllHits();
404
405      // Declare end of visualization
406      G4UImanager::GetUIpointer()-&gt;ApplyCommand("/vis/viewer/update");
407   
408    }
409
410  }
411
412  //----- end of C++ codes
413 
414</programlisting>
415</informalexample>
416</para>
417
418<para>
419You can re-visualize a physical volume, where a hit is detected,
420with a highlight color, in addition to the whole set of detector
421components. It is done by calling a drawing method of a physical
422volume directly. The method is:
423
424<informalexample>
425<programlisting>
426
427  //----- Drawing methods of a physical volume
428  virtual void Draw (const G4VPhysicalVolume&amp;, ...) ;
429 
430</programlisting>
431</informalexample>
432</para>
433
434<para>
435This method is, for example, called in a method
436<literal>MyXXXHit::Draw()</literal>, describing the visualization of hits
437with markers. The following is an example for this:
438
439<informalexample>
440<programlisting>
441  //----- C++ source codes: An example of visualizing hits with
442  void MyCalorimeterHit::Draw()
443  {
444    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
445    if(pVVisManager)
446    {
447      G4Transform3D trans(rot,pos);
448      G4VisAttributes attribs;
449      G4LogicalVolume* logVol = pPhys-&gt;GetLogicalVolume();
450      const G4VisAttributes* pVA = logVol-&gt;GetVisAttributes();
451      if(pVA) attribs = *pVA;
452      G4Colour colour(1.,0.,0.);
453      attribs.SetColour(colour);
454      attribs.SetForceSolid(true);
455
456      //----- Re-visualization of a selected physical volume with red color
457      pVVisManager-&gt;Draw(*pPhys,attribs,trans);
458
459    }
460  }
461
462  //----- end of C++ codes
463 
464</programlisting>
465</informalexample>
466</para>
467
468</sect2>
469
470
471<!-- ******************* Section (Level#2) ****************** -->
472<sect2 id="sect.VisCntCmpl.AttHits">
473<title>
474HepRep Attributes for Hits
475</title>
476
477<para>
478The HepRep file formats, HepRepFile and HepRepXML, attach various
479attributes to hits such that you can view these attributes, label
480trajectories by these attributes or make visibility cuts based on
481these attributes. Examples of adding HepRep attributes to hit
482classes can be found in examples /extended/analysis/A01 and
483/extended/runAndEvent/RE01.
484</para>
485
486<para>
487For example, in example RE01's class RE01CalorimeterHit.cc,
488available attributes will be:
489
490<itemizedlist spacing="compact">
491  <listitem><para>
492    Hit Type
493  </para></listitem>
494  <listitem><para>
495    Track ID
496  </para></listitem>
497  <listitem><para>
498    Z Cell ID
499  </para></listitem>
500  <listitem><para>
501    Phi Cell ID
502  </para></listitem>
503  <listitem><para>
504    Energy Deposited
505  </para></listitem>
506  <listitem><para>
507    Energy Deposited by Track
508  </para></listitem>
509  <listitem><para>
510    Position
511  </para></listitem>
512  <listitem><para>
513    Logical Volume
514  </para></listitem>
515</itemizedlist>
516</para>
517
518<para>
519You can add additional attributes of your choosing by modifying the
520relevant part of the hit class (look for the methods GetAttDefs and
521CreateAttValues).
522</para>
523
524</sect2>
525
526
527<!-- ******************* Section (Level#2) ****************** -->
528<sect2 id="sect.VisCntCmpl.txt">
529<title>
530Visualization of text
531</title>
532
533<para>
534In Geant4 Visualization, a text, i.e., a character string, is
535described by class <emphasis>G4Text</emphasis> inheriting
536<emphasis>G4VMarker</emphasis> as well as <emphasis>G4Square</emphasis> 
537and <emphasis>G4Circle</emphasis>. Therefore, the way to
538visualize text is the same as for hits. The corresponding drawing
539method of <emphasis>G4VVisManager</emphasis> is:
540
541<informalexample>
542<programlisting>
543  //----- Drawing methods of G4Text
544  virtual void G4VVisManager::Draw (const G4Text&amp;, ...);
545 
546</programlisting>
547</informalexample>
548</para>
549
550<para>
551The real implementation of this method is described in class
552<emphasis>G4VisManager</emphasis>.
553</para>
554
555</sect2>
556
557
558<!-- ******************* Section (Level#) ****************** -->
559<sect2 id="sect.VisCntCmpl.PlyTrkStp">
560<title>
561Visualization of polylines and tracking steps
562</title>
563
564<para>
565Polylines, i.e., sets of successive line segments, are described by
566class <emphasis>G4Polyline</emphasis>. For <emphasis>G4Polyline</emphasis>,
567the following drawing method of class <emphasis>G4VVisManager</emphasis> 
568is prepared:
569
570<informalexample>
571<programlisting>
572   //----- A drawing method of G4Polyline
573    virtual void G4VVisManager::Draw (const G4Polyline&amp;, ...) ;
574 
575</programlisting>
576</informalexample>
577</para>
578
579<para>
580The real implementation of this method is described in class
581<emphasis>G4VisManager</emphasis>.
582</para>
583
584<para>
585Using this method, C++ source codes to visualize
586<emphasis>G4Polyline</emphasis> are described as follows:
587
588<informalexample>
589<programlisting>
590 //----- C++ source code: How to visualize a polyline
591  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
592 
593  if (pVVisManager) {
594      G4Polyline polyline ;
595   
596      ..... (C++ source codes to set vertex positions, color, etc)
597 
598      pVVisManager -&gt; Draw(polyline);
599   
600  }
601 
602  //----- end of C++ source codes
603 
604</programlisting>
605</informalexample>
606</para>
607
608<para>
609Tracking steps are able to be visualized based on the above
610visualization of <emphasis>G4Polyline</emphasis>. You can visualize tracking
611steps at each step automatically by writing a proper implementation
612of class <emphasis>MySteppingAction</emphasis> inheriting
613<emphasis>G4UserSteppingAction</emphasis>, and also with the help of the Run
614Manager.
615</para>
616
617<para>
618First, you must implement a method,
619<literal>MySteppingAction::UserSteppingAction()</literal>. A typical
620implementation of this method is as follows:
621
622<informalexample>
623<programlisting>
624  //----- C++ source code: An example of visualizing tracking steps
625  void MySteppingAction::UserSteppingAction()
626  {
627      G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
628
629      if (pVVisManager) {
630
631        //----- Get the Stepping Manager
632        const G4SteppingManager* pSM = GetSteppingManager();
633
634        //----- Define a line segment
635        G4Polyline polyline;
636        G4double charge = pSM-&gt;GetTrack()-&gt;GetDefinition()-&gt;GetPDGCharge();
637        G4Colour colour;
638        if      (charge &lt; 0.) colour = G4Colour(1., 0., 0.);
639        else if (charge &lt; 0.) colour = G4Colour(0., 0., 1.);
640        else                  colour = G4Colour(0., 1., 0.);
641        G4VisAttributes attribs(colour);
642        polyline.SetVisAttributes(attribs);
643        polyline.push_back(pSM-&gt;GetStep()-&gt;GetPreStepPoint()-&gt;GetPosition());
644        polyline.push_back(pSM-&gt;GetStep()-&gt;GetPostStepPoint()-&gt;GetPosition());
645
646        //----- Call a drawing method for G4Polyline
647        pVVisManager -&gt; Draw(polyline);
648     
649      }
650  }
651
652  //----- end of C++ source code
653 
654</programlisting>
655</informalexample>
656</para>
657
658<para>
659Next, in order that the above C++ source code works, you have to
660pass the information of the <emphasis>MySteppingAction</emphasis> to the Run
661Manager in the <literal>main()</literal> function:
662
663<informalexample>
664<programlisting>
665 
666  //----- C++ source code: Passing what to do at each step to the Run Manager
667
668  int main()
669  {
670     ...
671 
672     // Run Manager
673     G4RunManager * runManager = new G4RunManager;
674
675     // User initialization classes
676     ...
677     runManager-&gt;SetUserAction(new MySteppingAction);
678     ...
679  }
680
681  //----- end of C++ source code
682 
683</programlisting>
684</informalexample>
685</para>
686
687<para>
688Thus you can visualize tracking steps with various visualization
689attributes, e.g., color, at each step, automatically.
690</para>
691
692<para>
693As well as tracking steps, you can visualize any kind 3D object
694made of line segments, using class <emphasis>G4Polyline</emphasis> and its
695drawing method, defined in class <emphasis>G4VVisManager</emphasis>. See, for
696example, the implementation of the <literal>/vis/scene/add/axes</literal>
697command.
698</para>
699
700</sect2>
701
702
703<!-- ******************* Section (Level#2) ****************** -->
704<sect2 id="sect.VisCntCmpl.UsrAct">
705<title>
706Visualization User Action
707</title>
708
709<para>
710You can implement the <literal>Draw</literal> method of
711<literal>G4VUserVisAction</literal>, e.g., the class definition could be:
712
713<informalexample>
714<programlisting>
715class StandaloneVisAction: public G4VUserVisAction {
716  void Draw();
717};
718</programlisting>
719</informalexample>
720
721and the implementation:
722
723<informalexample>
724<programlisting>
725void StandaloneVisAction::Draw() {
726  G4VVisManager* pVisManager = G4VVisManager::GetConcreteInstance();
727  if (pVisManager) {
728
729    // Simple box...
730    pVisManager-&gt;Draw(G4Box("box",2*m,2*m,2*m),
731                      G4VisAttributes(G4Colour(1,1,0)));
732
733    // Boolean solid...
734    G4Box boxA("boxA",3*m,3*m,3*m);
735    G4Box boxB("boxB",1*m,1*m,1*m);
736    G4SubtractionSolid subtracted("subtracted_boxes",&amp;boxA,&amp;boxB,
737                       G4Translate3D(3*m,3*m,3*m));
738    pVisManager-&gt;Draw(subtracted,
739                      G4VisAttributes(G4Colour(0,1,1)),
740                      G4Translate3D(6*m,6*m,6*m));
741  }
742}
743</programlisting>
744</informalexample>
745</para>
746
747<para>
748Explicit use of polyhedron objects is equivalent, e.g.:
749
750<informalexample>
751<programlisting>
752
753    // Same, but explicit polyhedron...
754    G4Polyhedron* pA = G4Box("boxA",3*m,3*m,3*m).CreatePolyhedron();
755    G4Polyhedron* pB = G4Box("boxB",1*m,1*m,1*m).CreatePolyhedron();
756    pB-&gt;Transform(G4Translate3D(3*m,3*m,3*m));
757    G4Polyhedron* pSubtracted = new G4Polyhedron(pA-&gt;subtract(*pB));
758    G4VisAttributes subVisAtts(G4Colour(0,1,1));
759    pSubtracted-&gt;SetVisAttributes(&amp;subVisAtts);
760    pVisManager-&gt;Draw(*pSubtracted,G4Translate3D(6*m,6*m,6*m));
761    delete pA;
762    delete pB;
763    delete pSubtracted;
764</programlisting>
765</informalexample>
766</para>
767
768<para>
769If efficiency is an issue, create the objects in the constructor,
770delete them in the destructor and draw them in your <literal>Draw</literal>
771method. Anyway, an instance of your class needs to be registered
772with the vis manager, e.g.:
773
774<informalexample>
775<programlisting>
776  ...
777  G4VisManager* visManager = new G4VisExecutive;
778  visManager-&gt;Initialize ();
779
780  visManager-&gt;SetUserAction
781    (new StandaloneVisAction,
782     G4VisExtent(-5*m,5*m,-5*m,5*m,-5*m,5*m));  // 2nd argument optional.
783  ...
784</programlisting>
785</informalexample>
786
787then activate by adding to a scene, e.g:
788
789<informalexample>
790<programlisting>
791/control/verbose 2
792/vis/verbose c
793/vis/open OGLSXm
794/vis/scene/create
795#/vis/scene/add/userAction
796/vis/scene/add/userAction -10 10 -10 10 -10 10 m
797#/vis/scene/add/axes 0 0 0 10 m
798#/vis/scene/add/scale 10 m
799/vis/sceneHandler/attach
800/vis/viewer/refresh
801</programlisting>
802</informalexample>
803</para>
804
805<para>
806The extent can be added on registration or on the command line or
807neither (if the extent of the scene is set by other components).
808Your <literal>Draw</literal> method will be called whenever needed to refresh
809the screen or rebuild a graphics database, for any chosen viewer.
810The scene can be attached to any scene handler and your drawing
811will be shown.
812</para>
813
814</sect2>
815
816
817<!-- ******************* Section (Level#2) ****************** -->
818<sect2 id="sect.VisCntCmpl.StdAln">
819<title>
820Standalone Visualization
821</title>
822
823<para>
824The above raises the possibility of using Geant4 as a "standalone"
825graphics package without invoking the run manager. The following
826main program, together with a user visualization action and a macro
827file, will allow you to view your drawing interactively on any of
828the supported graphics systems.
829
830<informalexample>
831<programlisting>
832#include "globals.hh"
833#include "G4VisExecutive.hh"
834#include "G4VisExtent.hh"
835#include "G4UImanager.hh"
836#include "G4UIterminal.hh"
837#include "G4UItcsh.hh"
838
839#include "StandaloneVisAction.hh"
840
841int main() {
842
843  G4VisManager* visManager = new G4VisExecutive;
844  visManager-&gt;Initialize ();
845
846  visManager-&gt;SetUserAction
847    (new StandaloneVisAction,
848     G4VisExtent(-5*m,5*m,-5*m,5*m,-5*m,5*m));  // 2nd argument optional.
849
850  G4UImanager* UI = G4UImanager::GetUIpointer ();
851  UI-&gt;ApplyCommand ("/control/execute standalone.g4m");
852
853  G4UIsession* session = new G4UIterminal(new G4UItcsh);
854  session-&gt;SessionStart();
855
856  delete session;
857  delete visManager;
858}
859</programlisting>
860</informalexample>
861</para>
862
863
864</sect2>
865</sect1>
Note: See TracBrowser for help on using the repository browser.