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

Last change on this file since 1013 was 904, checked in by garnier, 16 years ago

ajout de la doc

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