source: trunk/documents/UserDoc/DocBookUsersGuides/ForApplicationDeveloper/xml/Visualization/attributes.xml@ 1345

Last change on this file since 1345 was 904, checked in by garnier, 17 years ago

ajout de la doc

File size: 21.3 KB
Line 
1<!-- ******************************************************** -->
2<!-- -->
3<!-- [History] -->
4<!-- Proof read by: Joe Chuma, 5-Jul-1999 -->
5<!-- Changed by: Katsuya Dosanjh, 15-Jul-2000 -->
6<!-- Changed by: Dennis Wright, 27-Nov-2001 -->
7<!-- Changed by: Satoshi Tanaka, 8-Dec-2002 -->
8<!-- Converted to DocBook: Katsuya Amako, Aug-2006 -->
9<!-- -->
10<!-- ******************************************************** -->
11
12
13<!-- ******************* Section (Level#1) ****************** -->
14<sect1 id="sect.VisAtt">
15<title>
16Visualization Attributes
17</title>
18
19<para>
20Visualization attributes are extra pieces of information associated
21with the visualizable objects. This information is necessary only
22for visualization, and is not included in geometrical information
23such as shapes, position, and orientation. Typical examples of
24visualization attributes are Color, Visible/Invisible,
25Wireframe/Solid. For example, in visualizing a box, the
26Visualization Manager must know its colour. If an object to be
27visualized has not been assigned a set of visualization attributes,
28then an appropriate default set is used automatically.
29</para>
30
31<para>
32A set of visualization attributes is held by an instance of
33class <emphasis>G4VisAttributes</emphasis> defined in the
34<literal>graphics_reps</literal> category. In the following, we
35explain the main fields of the <emphasis>G4VisAttributes</emphasis>
36one by one.
37</para>
38
39<!-- ******************* Section (Level#2) ****************** -->
40<sect2 id="sect.VisAtt.Vsblty">
41<title>
42Visibility
43</title>
44
45<para>
46Visibility is a boolean flag to control the visibility of objects
47that are passed to the Visualization Manager for visualization.
48Visibility is set with the following access function:
49
50<informalexample>
51<programlisting>
52 void G4VisAttributes::SetVisibility (G4bool visibility);
53</programlisting>
54</informalexample>
55</para>
56
57<para>
58If you give <literal>false</literal> to the argument, and if culling is
59activated (see below), visualization is skipped for objects for
60which this set of visualization attributes is assigned. The default
61value of visibility is <literal>true</literal>.
62</para>
63
64<para>
65Note that whether an object is visible or not is also affected
66by the current culling policy, which can be tuned with
67visualization commands.
68</para>
69
70<para>
71By default the following public static function is defined:
72
73<informalexample>
74<programlisting>
75 static const G4VisAttributes&amp; GetInvisible();
76</programlisting>
77</informalexample>
78
79which returns a reference to a const object in which visibility is
80set to <literal>false</literal>. It can be used as follows:
81
82<informalexample>
83<programlisting>
84 experimentalHall_logical -&gt; SetVisAttributes (G4VisAttributes::GetInvisible());
85</programlisting>
86</informalexample>
87</para>
88
89<para>
90Direct access to the public static const data member
91<literal>G4VisAttributes::Invisible</literal> is also possible but deprecated
92on account of initialisation issues with dynamic libraries.
93</para>
94
95</sect2>
96
97
98<!-- ******************* Section (Level#2) ****************** -->
99<sect2 id="sect.VisAtt.Colr">
100<title>
101Colour
102</title>
103
104
105<!-- ******************* Section (Level#3) ****************** -->
106<sect3 id="sect.VisAtt.Colr.Cnstr">
107<title>
108Construction
109</title>
110
111<para>
112Class <emphasis>G4Colour</emphasis> (an equivalent class name,
113<emphasis>G4Color</emphasis>, is also available) has 4 fields,
114which represent the RGBA (red, green,
115blue, and alpha) components of colour. Each component takes a value
116between 0 and 1. If an irrelevant value, i.e., a value less than 0
117or greater than 1, is given as an argument of the constructor, such
118a value is automatically clipped to 0 or 1. Alpha is opacity, which
119is not used at present. You can use its default value <literal>1</literal>,
120which means "opaque" in instantiation of <emphasis>G4Colour</emphasis>.
121</para>
122
123<para>
124A <emphasis>G4Colour</emphasis> object is instantiated by giving red, green,
125and blue components to its constructor, i.e.,
126
127<informalexample>
128<programlisting>
129 G4Colour::G4Colour ( G4double r = 1.0,
130 G4double g = 1.0,
131 G4double b = 1.0,
132 G4double a = 1.0);
133 // 0&lt;=red, green, blue &lt;= 1.0
134</programlisting>
135</informalexample>
136</para>
137
138<para>
139The default value of each component is 1.0. That is to say, the
140default colour is "white" (opaque).
141</para>
142
143<para>
144For example, colours which are often used can be instantiated as
145follows:
146
147<informalexample>
148<programlisting>
149 G4Colour white () ; // <emphasis role="color_white">white</emphasis>
150 G4Colour white (1.0, 1.0, 1.0) ; // <emphasis role="color_white">white</emphasis>
151 G4Colour gray (0.5, 0.5, 0.5) ; // <emphasis role="color_gray">gray</emphasis>
152 G4Colour black (0.0, 0.0, 0.0) ; // <emphasis role="color_black">black</emphasis>
153 G4Colour red (1.0, 0.0, 0.0) ; // <emphasis role="color_red">red</emphasis>
154 G4Colour green (0.0, 1.0, 0.0) ; // <emphasis role="color_green">green</emphasis>
155 G4Colour blue (0.0, 0.0, 1.0) ; // <emphasis role="color_blue">blue</emphasis>
156 G4Colour cyan (0.0, 1.0, 1.0) ; // <emphasis role="color_cyan">cyan</emphasis>
157 G4Colour magenta (1.0, 0.0, 1.0) ; // <emphasis role="color_magenta">magenta</emphasis>
158 G4Colour yellow (1.0, 1.0, 0.0) ; // <emphasis role="color_yellow">yellow</emphasis>
159</programlisting>
160</informalexample>
161</para>
162
163<para>
164It is also possible to instantiate common colours through static
165public data member functions:
166
167<informalexample>
168<programlisting>
169 static const G4Colour&amp; White ();
170 static const G4Colour&amp; Gray ();
171 static const G4Colour&amp; Grey ();
172 static const G4Colour&amp; Black ();
173 static const G4Colour&amp; Red ();
174 static const G4Colour&amp; Green ();
175 static const G4Colour&amp; Blue ();
176 static const G4Colour&amp; Cyan ();
177 static const G4Colour&amp; Magenta ();
178 static const G4Colour&amp; Yellow ();
179</programlisting>
180</informalexample>
181</para>
182
183<para>
184For example, a local <emphasis>G4Colour</emphasis> could be constructed
185as:
186
187<informalexample>
188<programlisting>
189 G4Colour myRed(G4Colour::Red());
190</programlisting>
191</informalexample>
192</para>
193
194<para>
195After instantiation of a <emphasis>G4Colour</emphasis> object, you can access
196to its components with the following access functions:
197
198<informalexample>
199<programlisting>
200 G4double G4Colour::GetRed () const ; // Get the red component.
201 G4double G4Colour::GetGreen () const ; // Get the green component.
202 G4double G4Colour::GetBlue () const ; // Get the blue component.
203</programlisting>
204</informalexample>
205</para>
206
207</sect3>
208
209<!-- ******************* Section (Level#3) ****************** -->
210<sect3 id="sect.VisAtt.Colr.ColrMap">
211<title>
212Colour Map
213</title>
214
215<para>
216<emphasis>G4Colour</emphasis> also provides a static colour map, giving access to
217predefined <emphasis>G4Colour</emphasis>'s through a
218<emphasis>G4String</emphasis>
219key. The default mapping is:
220</para><para>
221
222<informalexample>
223<programlisting>
224 G4String G4Colour
225 ---------------------------------------
226 white G4Colour::White ()
227 gray G4Colour::Gray ()
228 grey G4Colour::Grey ()
229 black G4Colour::Black ()
230 red G4Colour::Red ()
231 green G4Colour::Green ()
232 blue G4Colour::Blue ()
233 cyan G4Colour::Cyan ()
234 magenta G4Colour::Magenta ()
235 yellow G4Colour::Yellow ()
236</programlisting>
237</informalexample>
238</para>
239
240<para>
241Colours can be retrieved through the GetColour method:
242
243<informalexample>
244<programlisting>
245 bool G4Colour::GetColour(const G4String&amp; key, G4Colour&amp; result)
246</programlisting>
247</informalexample>
248</para>
249
250<para>
251For example:
252
253<informalexample>
254<programlisting>
255 G4Colour myColour(G4Colour::Black());
256 if (G4Colour::GetColour("red", myColour)) {
257 // Successfully retrieved colour "red". myColour is now red
258 }
259 else {
260 // Colour did not exist in map. myColour is still black
261 }
262</programlisting>
263</informalexample>
264</para>
265
266<para>
267If the key is not registered in the colour map, a warning
268message is printed and the input colour is not changed. The colour
269map is case insensitive.
270</para>
271
272<para>
273It is also possible to load user defined <emphasis>G4Colour</emphasis>'s into
274the map through the public AddToMap method. For example:
275
276<informalexample>
277<programlisting>
278 G4Colour myColour(0.2, 0.2, 0.2, 1);
279 G4Colour::AddToMap("custom", myColour);
280</programlisting>
281</informalexample>
282</para>
283
284<para>
285This loads a user defined <emphasis>G4Colour</emphasis> with key "custom" into
286the colour map.
287</para>
288
289</sect3>
290
291<!-- ******************* Section (Level#3) ****************** -->
292<sect3 id="sect.VisAtt.Colr.G4VisAtt">
293<title>
294Colour and G4VisAttributes
295</title>
296
297<para>
298Class <emphasis>G4VisAttributes</emphasis> holds its colour entry as an object of
299class <emphasis>G4Colour</emphasis>. A <emphasis>G4Colour</emphasis> object is
300passed to a <emphasis>G4VisAttributes</emphasis> object with the following
301access
302functions:
303
304<informalexample>
305<programlisting>
306 //----- Set functions of G4VisAttributes.
307 void G4VisAttributes::SetColour (const G4Colour&amp; colour);
308 void G4VisAttributes::SetColor (const G4Color&amp; color );
309</programlisting>
310</informalexample>
311</para>
312
313<para>
314We can also set RGBA components directly:
315
316<informalexample>
317<programlisting>
318 //----- Set functions of G4VisAttributes
319 void G4VisAttributes::SetColour ( G4double red ,
320 G4double green ,
321 G4double blue ,
322 G4double alpha = 1.0);
323
324 void G4VisAttributes::SetColor ( G4double red ,
325 G4double green ,
326 G4double blue ,
327 G4double alpha = 1.);
328</programlisting>
329</informalexample>
330</para>
331
332<para>
333The following constructor with <emphasis>G4Colour</emphasis> as its argument is
334also supported:
335
336<informalexample>
337<programlisting>
338 //----- Constructor of G4VisAttributes
339 G4VisAttributes::G4VisAttributes (const G4Colour&amp; colour);
340</programlisting>
341</informalexample>
342</para>
343
344<para>
345Note that colour assigned to a <emphasis>G4VisAttributes</emphasis> object is
346not always the colour that ultimately appears in the visualization.
347The ultimate appearance may be affected by shading and lighting
348models applied in the selected visualization driver or stand-alone
349graphics system.
350</para>
351
352</sect3>
353</sect2>
354
355
356<!-- ******************* Section (Level#2) ****************** -->
357<sect2 id="sect.VisAtt.FrcAtt">
358<title>
359Forcing attributes
360</title>
361
362<para>
363As you will see later, you can select a "drawing style" from
364various options. For example, you can select your detector
365components to be visualized in "wireframe" or with "surfaces". In
366the former, only the edges of your detector are drawn and so the
367detector looks transparent. In the latter, your detector looks
368opaque with shading effects.
369</para>
370
371<para>
372The forced wireframe and forced solid styles make it possible to
373mix the wireframe and surface visualization (if your selected
374graphics system supports such visualization). For example, you can
375make only the outer wall of your detector "wired" (transparent) and
376can see inside in detail.
377</para>
378
379<para>
380Forced wireframe style is set with the following access
381function:
382
383<informalexample>
384<programlisting>
385 void G4VisAttributes::SetForceWireframe (G4bool force);
386</programlisting>
387</informalexample>
388</para>
389
390<para>
391If you give <literal>true</literal> as the argument, objects for which this
392set of visualization attributes is assigned are always visualized
393in wireframe even if in general, the surface drawing style has been
394requested. The default value of the forced wireframe style is
395<literal>false</literal>.
396</para>
397
398<para>
399Similarly, forced solid style, i.e., to force that objects are
400always visualized with surfaces, is set with:
401
402<informalexample>
403<programlisting>
404 void G4VisAttributes::SetForceSolid (G4bool force);
405</programlisting>
406</informalexample>
407</para>
408
409<para>
410The default value of the forced solid style is <literal>false</literal>, too.
411</para>
412
413<para>
414You can also force auxiliary edges to be visible. Normally they
415are not visible unless you set the appropriate view parameter.
416Forcing the auxiliary edges to be visible means that auxiliary
417edges will be seen whatever the view parameters.
418</para>
419
420<para>
421Auxiliary edges are not genuine edges of the volume. They may be
422in a curved surface made out of polygons, for example, or in plane
423surface of complicated shape that has to be broken down into
424simpler polygons. HepPolyhedron breaks all surfaces into triangles
425or quadrilaterals. There will be auxiliary edges for any volumes
426with a curved surface, such as a tube or a sphere, or a volume
427resulting from a Boolean operation. Normally, they are not shown,
428but sometimes it is useful to see them. In particular, a sphere,
429because it has no egdes, will not be seen in wireframe mode in some
430graphics systems unless requested by the view parameters or forced,
431as described here.
432</para>
433
434<para>
435To force auxiliary edges to be visible, use:
436
437<informalexample>
438<programlisting>
439 void G4VisAttributes::SetForceAuxEdgeVisible (G4bool force);
440</programlisting>
441</informalexample>
442</para>
443
444<para>
445The default value of the force auxiliary edges visible flag is
446<literal>false</literal>.
447</para>
448
449<para>
450For volumes with edges that are parts of a circle, such as a
451tube (G4Tubs), etc., it is possible to force the precision of
452polyhedral representation for visualisation. This is recommended
453for volumes containing only a small angle of circle, for example, a
454thin tube segment.
455</para>
456
457<para>
458For visualisation, a circle is represented by an N-sided
459polygon. The default is 24 sides or segments. The user may change
460this for all volumes in a particular viewer at run time with
461/vis/viewer/set/lineSegmentsPerCircle; alternatively it can be
462forced for a particular volume with:
463
464<informalexample>
465<programlisting>
466 void G4VisAttributes::SetForceLineSegmentsPerCircle (G4int nSegments);
467</programlisting>
468</informalexample>
469</para>
470
471</sect2>
472
473
474<!-- ******************* Section (Level#2) ****************** -->
475<sect2 id="sect.VisAtt.CnstAtt">
476<title>
477Constructors of G4VisAttributes
478</title>
479
480<para>
481The following constructors are supported for class
482<emphasis>G4VisAttributes</emphasis>:
483
484<informalexample>
485<programlisting>
486 //----- Constructors of class G4VisAttributes
487 G4VisAttributes (void);
488 G4VisAttributes (G4bool visibility);
489 G4VisAttributes (const G4Colour&amp; colour);
490 G4VisAttributes (G4bool visibility, const G4Colour&amp; colour);
491</programlisting>
492</informalexample>
493</para>
494
495</sect2>
496
497
498<!-- ******************* Section (Level#2) ****************** -->
499<sect2 id="sect.VisAtt.AssgLgVol">
500<title>
501How to assign G4VisAttributes to a logical volume
502</title>
503
504<para>
505In constructing your detector components, you may assign a set of
506visualization attributes to each "logical volume" in order to
507visualize them later (if you do not do this, the graphics system
508will use a default set). You cannot make a solid such as
509<emphasis>G4Box</emphasis> hold a set of visualization attributes; this is
510because a solid should hold only geometrical information. At
511present, you cannot make a physical volume hold one, but there are
512plans to design a memory-efficient way to do it; however, you can
513visualize a transient piece of solid or physical volume with a
514temporary assigned set of visualization attributes.
515</para>
516
517<para>
518Class <emphasis>G4LogicalVolume</emphasis> holds a pointer of
519<emphasis>G4VisAttributes.</emphasis> This field is set and referenced with the
520following access functions:
521
522<informalexample>
523<programlisting>
524 //----- Set functions of G4VisAttributes
525 void G4VisAttributes::SetVisAttributes (const G4VisAttributes* pVA);
526 void G4VisAttributes::SetVisAttributes (const G4VisAttributes&amp; VA);
527
528 //----- Get functions of G4VisAttributes
529 const G4VisAttributes* G4VisAttributes::GetVisAttributes () const;
530</programlisting>
531</informalexample>
532</para>
533
534<para>
535The following is sample C++ source codes for assigning a set of
536visualization attributes with cyan colour and forced wireframe
537style to a logical volume:
538
539<informalexample>
540<programlisting>
541 //----- C++ source codes: Assigning G4VisAttributes to a logical volume
542 ...
543 // Instantiation of a logical volume
544 myTargetLog = new G4LogicalVolume( myTargetTube,BGO, "TLog", 0, 0, 0);
545 ...
546 // Instantiation of a set of visualization attributes with cyan colour
547 G4VisAttributes * calTubeVisAtt = new G4VisAttributes(G4Colour(0.,1.,1.));
548 // Set the forced wireframe style
549 calTubeVisAtt-&gt;SetForceWireframe(true);
550 // Assignment of the visualization attributes to the logical volume
551 myTargetLog-&gt;SetVisAttributes(calTubeVisAtt);
552
553 //----- end of C++ source codes
554</programlisting>
555</informalexample>
556</para>
557
558<para>
559Note that the life of the visualization attributes must be at
560least as long as the objects to which they are assigned; it is the
561users' responsibility to ensure this, and to delete the
562visualization attributes when they are no longer needed (or just
563leave them to die at the end of the job).
564</para>
565
566</sect2>
567
568
569<!-- ******************* Section (Level#2) ****************** -->
570<sect2 id="sect.VisAtt.AddUdefAtt">
571<title>
572Additional User-Defined Attributes
573</title>
574
575<para>
576Geant4 Trajectories and Hits can be assigned additional arbitrary
577attributes that will be displayed when you click on the relevant
578object in the WIRED or FRED HepRep browsers. WIRED then lets you
579label objects by any of these attributes or cut visibility based on
580these attributes.
581</para>
582
583<para>
584Define the attributes with lines such as:
585
586<informalexample>
587<programlisting>
588 std::map&lt;G4String,G4AttDef&gt;* store = G4AttDefStore::GetInstance("G4Trajectory",isNew);
589 G4String PN("PN");
590 (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
591 G4String IMom("IMom");
592 (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", "Physics", "",
593 "G4ThreeVector");
594</programlisting>
595</informalexample>
596</para>
597
598<para>
599Then fill the attributes with lines such as:
600
601<informalexample>
602<programlisting>
603 std::vector&lt;G4AttValue&gt;* values = new std::vector&lt;G4AttValue&gt;;
604 values-&gt;push_back(G4AttValue("PN",ParticleName,""));
605 s.seekp(std::ios::beg);
606 s &lt;&lt; G4BestUnit(initialMomentum,"Energy") &lt;&lt; std::ends;
607 values-&gt;push_back(G4AttValue("IMom",c,""));
608</programlisting>
609</informalexample>
610</para>
611
612<para>
613See geant4/source/tracking/src/G4Trajectory.cc for a good example.
614</para>
615
616<para>
617<emphasis>G4AttValue</emphasis> objects are light, containing just the value;
618for the long description and other sharable information the
619<emphasis>G4AttValue</emphasis> object refers to a <emphasis>G4AttDef</emphasis>
620object. They are based on the HepRep standard described at
621<ulink url="http://www.slac.stanford.edu/~perl/heprep/">
622http://www.slac.stanford.edu/~perl/heprep/
623</ulink>.
624Geant4 also provides an <emphasis>G4AttDefStore</emphasis>.
625</para>
626
627<para>
628Geant4 provides some default examples of the use of this
629facility in the trajectory classes in /source/tracking such as
630<emphasis>G4Trajectory</emphasis>, <emphasis>G4SmoothTrajectory</emphasis>.
631<emphasis>G4Trajectory::CreateAttValues</emphasis> shows how
632<emphasis>G4AttValue</emphasis> objects can be made and
633<emphasis>G4Trajectory::GetAttDefs</emphasis> shows how
634to make the corresponding <emphasis>G4AttDef</emphasis> objects and use the
635<emphasis>G4AttDefStore</emphasis>. Note that the "user" of CreateAttValues
636guarantees to destroy them; this is a way of allowing creation on
637demand and leaving the <emphasis>G4Trajectory</emphasis> object, for example,
638free of such objects in memory. The comments in
639<emphasis>G4VTrajectory.hh</emphasis> explain further and additional insights
640might be obtained by looking at two methods which use them, namely
641<emphasis>G4VTrajectory::DrawTrajectory</emphasis> and
642<emphasis>G4VTrajectory::ShowTrajectory</emphasis>.
643</para>
644
645<para>
646Hits classes in examples /extended/analysis/A01 and
647/extended/runAndEvent/RE01 show how to do the same for your hits.
648The base class no-action methods CreateAttValues and GetAttDefs
649should be overridden in your concrete class. The comments in
650<emphasis>G4VHit.hh</emphasis> explain further.
651</para>
652
653<para>
654In addition, the user is free to add a
655<emphasis>G4std::vector&lt;G4AttValue&gt;*</emphasis> and a
656<emphasis>G4std::vector&lt;G4AttDef&gt;*</emphasis> to a
657<emphasis>G4VisAttributes</emphasis> object as could, for example,
658be used by a <emphasis>G4LogicalVolume</emphasis> object.
659</para>
660
661<para>
662At the time of writing, only the HepRep graphics systems are
663capable of displaying the G4AttValue information, but this
664information will become useful for all Geant4 visualization systems
665through improvements in release 8.1 or later.
666</para>
667
668
669</sect2>
670</sect1>
Note: See TracBrowser for help on using the repository browser.