| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>8.6. Visualization Attributes</title><link rel="stylesheet" href="../xml/XSLCustomizationLayer/G4HTMLStylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="Geant4 User's Guide for Application Developers"><link rel="up" href="ch08.html" title="Chapter 8. Visualization"><link rel="prev" href="ch08s05.html" title="8.5. Controlling Visualization from Compiled Code"><link rel="next" href="ch08s07.html" title="8.7. Enhanced Trajectory Drawing"><script language="JavaScript">
|
|---|
| 2 | function remote_win(fName)
|
|---|
| 3 | {
|
|---|
| 4 | var url = "AllResources/Detector/geometry.src/" + fName;
|
|---|
| 5 | RemoteWin=window.open(url,"","resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=520,height=520")
|
|---|
| 6 | RemoteWin.creator=self
|
|---|
| 7 | }
|
|---|
| 8 | </script></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">8.6.
|
|---|
| 9 | Visualization Attributes
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch08s05.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 8.
|
|---|
| 11 | Visualization
|
|---|
| 12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch08s07.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect.VisAtt"></a>8.6.
|
|---|
| 13 | Visualization Attributes
|
|---|
| 14 | </h2></div></div></div><p>
|
|---|
| 15 | Visualization attributes are extra pieces of information associated
|
|---|
| 16 | with the visualizable objects. This information is necessary only
|
|---|
| 17 | for visualization, and is not included in geometrical information
|
|---|
| 18 | such as shapes, position, and orientation. Typical examples of
|
|---|
| 19 | visualization attributes are Color, Visible/Invisible,
|
|---|
| 20 | Wireframe/Solid. For example, in visualizing a box, the
|
|---|
| 21 | Visualization Manager must know its colour. If an object to be
|
|---|
| 22 | visualized has not been assigned a set of visualization attributes,
|
|---|
| 23 | then an appropriate default set is used automatically.
|
|---|
| 24 | </p><p>
|
|---|
| 25 | A set of visualization attributes is held by an instance of
|
|---|
| 26 | class <span class="emphasis"><em>G4VisAttributes</em></span> defined in the
|
|---|
| 27 | <code class="literal">graphics_reps</code> category. In the following, we
|
|---|
| 28 | explain the main fields of the <span class="emphasis"><em>G4VisAttributes</em></span>
|
|---|
| 29 | one by one.
|
|---|
| 30 | </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisAtt.Vsblty"></a>8.6.1.
|
|---|
| 31 | Visibility
|
|---|
| 32 | </h3></div></div></div><p>
|
|---|
| 33 | Visibility is a boolean flag to control the visibility of objects
|
|---|
| 34 | that are passed to the Visualization Manager for visualization.
|
|---|
| 35 | Visibility is set with the following access function:
|
|---|
| 36 |
|
|---|
| 37 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 38 | void G4VisAttributes::SetVisibility (G4bool visibility);
|
|---|
| 39 | </pre></div><p>
|
|---|
| 40 | </p><p>
|
|---|
| 41 | If you give <code class="literal">false</code> to the argument, and if culling is
|
|---|
| 42 | activated (see below), visualization is skipped for objects for
|
|---|
| 43 | which this set of visualization attributes is assigned. The default
|
|---|
| 44 | value of visibility is <code class="literal">true</code>.
|
|---|
| 45 | </p><p>
|
|---|
| 46 | Note that whether an object is visible or not is also affected
|
|---|
| 47 | by the current culling policy, which can be tuned with
|
|---|
| 48 | visualization commands.
|
|---|
| 49 | </p><p>
|
|---|
| 50 | By default the following public static function is defined:
|
|---|
| 51 |
|
|---|
| 52 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 53 | static const G4VisAttributes& GetInvisible();
|
|---|
| 54 | </pre></div><p>
|
|---|
| 55 |
|
|---|
| 56 | which returns a reference to a const object in which visibility is
|
|---|
| 57 | set to <code class="literal">false</code>. It can be used as follows:
|
|---|
| 58 |
|
|---|
| 59 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 60 | experimentalHall_logical -> SetVisAttributes (G4VisAttributes::GetInvisible());
|
|---|
| 61 | </pre></div><p>
|
|---|
| 62 | </p><p>
|
|---|
| 63 | Direct access to the public static const data member
|
|---|
| 64 | <code class="literal">G4VisAttributes::Invisible</code> is also possible but deprecated
|
|---|
| 65 | on account of initialisation issues with dynamic libraries.
|
|---|
| 66 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisAtt.Colr"></a>8.6.2.
|
|---|
| 67 | Colour
|
|---|
| 68 | </h3></div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.VisAtt.Colr.Cnstr"></a>8.6.2.1.
|
|---|
| 69 | Construction
|
|---|
| 70 | </h4></div></div></div><p>
|
|---|
| 71 | Class <span class="emphasis"><em>G4Colour</em></span> (an equivalent class name,
|
|---|
| 72 | <span class="emphasis"><em>G4Color</em></span>, is also available) has 4 fields,
|
|---|
| 73 | which represent the RGBA (red, green,
|
|---|
| 74 | blue, and alpha) components of colour. Each component takes a value
|
|---|
| 75 | between 0 and 1. If an irrelevant value, i.e., a value less than 0
|
|---|
| 76 | or greater than 1, is given as an argument of the constructor, such
|
|---|
| 77 | a value is automatically clipped to 0 or 1. Alpha is opacity, which
|
|---|
| 78 | is not used at present. You can use its default value <code class="literal">1</code>,
|
|---|
| 79 | which means "opaque" in instantiation of <span class="emphasis"><em>G4Colour</em></span>.
|
|---|
| 80 | </p><p>
|
|---|
| 81 | A <span class="emphasis"><em>G4Colour</em></span> object is instantiated by giving red, green,
|
|---|
| 82 | and blue components to its constructor, i.e.,
|
|---|
| 83 |
|
|---|
| 84 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 85 | G4Colour::G4Colour ( G4double r = 1.0,
|
|---|
| 86 | G4double g = 1.0,
|
|---|
| 87 | G4double b = 1.0,
|
|---|
| 88 | G4double a = 1.0);
|
|---|
| 89 | // 0<=red, green, blue <= 1.0
|
|---|
| 90 | </pre></div><p>
|
|---|
| 91 | </p><p>
|
|---|
| 92 | The default value of each component is 1.0. That is to say, the
|
|---|
| 93 | default colour is "white" (opaque).
|
|---|
| 94 | </p><p>
|
|---|
| 95 | For example, colours which are often used can be instantiated as
|
|---|
| 96 | follows:
|
|---|
| 97 |
|
|---|
| 98 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 99 | G4Colour white () ; // <span class="color_white">white</span>
|
|---|
| 100 | G4Colour white (1.0, 1.0, 1.0) ; // <span class="color_white">white</span>
|
|---|
| 101 | G4Colour gray (0.5, 0.5, 0.5) ; // <span class="color_gray">gray</span>
|
|---|
| 102 | G4Colour black (0.0, 0.0, 0.0) ; // <span class="color_black">black</span>
|
|---|
| 103 | G4Colour red (1.0, 0.0, 0.0) ; // <span class="color_red">red</span>
|
|---|
| 104 | G4Colour green (0.0, 1.0, 0.0) ; // <span class="color_green">green</span>
|
|---|
| 105 | G4Colour blue (0.0, 0.0, 1.0) ; // <span class="color_blue">blue</span>
|
|---|
| 106 | G4Colour cyan (0.0, 1.0, 1.0) ; // <span class="color_cyan">cyan</span>
|
|---|
| 107 | G4Colour magenta (1.0, 0.0, 1.0) ; // <span class="color_magenta">magenta</span>
|
|---|
| 108 | G4Colour yellow (1.0, 1.0, 0.0) ; // <span class="color_yellow">yellow</span>
|
|---|
| 109 | </pre></div><p>
|
|---|
| 110 | </p><p>
|
|---|
| 111 | It is also possible to instantiate common colours through static
|
|---|
| 112 | public data member functions:
|
|---|
| 113 |
|
|---|
| 114 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 115 | static const G4Colour& White ();
|
|---|
| 116 | static const G4Colour& Gray ();
|
|---|
| 117 | static const G4Colour& Grey ();
|
|---|
| 118 | static const G4Colour& Black ();
|
|---|
| 119 | static const G4Colour& Red ();
|
|---|
| 120 | static const G4Colour& Green ();
|
|---|
| 121 | static const G4Colour& Blue ();
|
|---|
| 122 | static const G4Colour& Cyan ();
|
|---|
| 123 | static const G4Colour& Magenta ();
|
|---|
| 124 | static const G4Colour& Yellow ();
|
|---|
| 125 | </pre></div><p>
|
|---|
| 126 | </p><p>
|
|---|
| 127 | For example, a local <span class="emphasis"><em>G4Colour</em></span> could be constructed
|
|---|
| 128 | as:
|
|---|
| 129 |
|
|---|
| 130 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 131 | G4Colour myRed(G4Colour::Red());
|
|---|
| 132 | </pre></div><p>
|
|---|
| 133 | </p><p>
|
|---|
| 134 | After instantiation of a <span class="emphasis"><em>G4Colour</em></span> object, you can access
|
|---|
| 135 | to its components with the following access functions:
|
|---|
| 136 |
|
|---|
| 137 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 138 | G4double G4Colour::GetRed () const ; // Get the red component.
|
|---|
| 139 | G4double G4Colour::GetGreen () const ; // Get the green component.
|
|---|
| 140 | G4double G4Colour::GetBlue () const ; // Get the blue component.
|
|---|
| 141 | </pre></div><p>
|
|---|
| 142 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.VisAtt.Colr.ColrMap"></a>8.6.2.2.
|
|---|
| 143 | Colour Map
|
|---|
| 144 | </h4></div></div></div><p>
|
|---|
| 145 | <span class="emphasis"><em>G4Colour</em></span> also provides a static colour map, giving access to
|
|---|
| 146 | predefined <span class="emphasis"><em>G4Colour</em></span>'s through a
|
|---|
| 147 | <span class="emphasis"><em>G4String</em></span>
|
|---|
| 148 | key. The default mapping is:
|
|---|
| 149 | </p><p>
|
|---|
| 150 |
|
|---|
| 151 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 152 | G4String G4Colour
|
|---|
| 153 | ---------------------------------------
|
|---|
| 154 | white G4Colour::White ()
|
|---|
| 155 | gray G4Colour::Gray ()
|
|---|
| 156 | grey G4Colour::Grey ()
|
|---|
| 157 | black G4Colour::Black ()
|
|---|
| 158 | red G4Colour::Red ()
|
|---|
| 159 | green G4Colour::Green ()
|
|---|
| 160 | blue G4Colour::Blue ()
|
|---|
| 161 | cyan G4Colour::Cyan ()
|
|---|
| 162 | magenta G4Colour::Magenta ()
|
|---|
| 163 | yellow G4Colour::Yellow ()
|
|---|
| 164 | </pre></div><p>
|
|---|
| 165 | </p><p>
|
|---|
| 166 | Colours can be retrieved through the GetColour method:
|
|---|
| 167 |
|
|---|
| 168 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 169 | bool G4Colour::GetColour(const G4String& key, G4Colour& result)
|
|---|
| 170 | </pre></div><p>
|
|---|
| 171 | </p><p>
|
|---|
| 172 | For example:
|
|---|
| 173 |
|
|---|
| 174 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 175 | G4Colour myColour(G4Colour::Black());
|
|---|
| 176 | if (G4Colour::GetColour("red", myColour)) {
|
|---|
| 177 | // Successfully retrieved colour "red". myColour is now red
|
|---|
| 178 | }
|
|---|
| 179 | else {
|
|---|
| 180 | // Colour did not exist in map. myColour is still black
|
|---|
| 181 | }
|
|---|
| 182 | </pre></div><p>
|
|---|
| 183 | </p><p>
|
|---|
| 184 | If the key is not registered in the colour map, a warning
|
|---|
| 185 | message is printed and the input colour is not changed. The colour
|
|---|
| 186 | map is case insensitive.
|
|---|
| 187 | </p><p>
|
|---|
| 188 | It is also possible to load user defined <span class="emphasis"><em>G4Colour</em></span>'s into
|
|---|
| 189 | the map through the public AddToMap method. For example:
|
|---|
| 190 |
|
|---|
| 191 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 192 | G4Colour myColour(0.2, 0.2, 0.2, 1);
|
|---|
| 193 | G4Colour::AddToMap("custom", myColour);
|
|---|
| 194 | </pre></div><p>
|
|---|
| 195 | </p><p>
|
|---|
| 196 | This loads a user defined <span class="emphasis"><em>G4Colour</em></span> with key "custom" into
|
|---|
| 197 | the colour map.
|
|---|
| 198 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="sect.VisAtt.Colr.G4VisAtt"></a>8.6.2.3.
|
|---|
| 199 | Colour and G4VisAttributes
|
|---|
| 200 | </h4></div></div></div><p>
|
|---|
| 201 | Class <span class="emphasis"><em>G4VisAttributes</em></span> holds its colour entry as an object of
|
|---|
| 202 | class <span class="emphasis"><em>G4Colour</em></span>. A <span class="emphasis"><em>G4Colour</em></span> object is
|
|---|
| 203 | passed to a <span class="emphasis"><em>G4VisAttributes</em></span> object with the following
|
|---|
| 204 | access
|
|---|
| 205 | functions:
|
|---|
| 206 |
|
|---|
| 207 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 208 | //----- Set functions of G4VisAttributes.
|
|---|
| 209 | void G4VisAttributes::SetColour (const G4Colour& colour);
|
|---|
| 210 | void G4VisAttributes::SetColor (const G4Color& color );
|
|---|
| 211 | </pre></div><p>
|
|---|
| 212 | </p><p>
|
|---|
| 213 | We can also set RGBA components directly:
|
|---|
| 214 |
|
|---|
| 215 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 216 | //----- Set functions of G4VisAttributes
|
|---|
| 217 | void G4VisAttributes::SetColour ( G4double red ,
|
|---|
| 218 | G4double green ,
|
|---|
| 219 | G4double blue ,
|
|---|
| 220 | G4double alpha = 1.0);
|
|---|
| 221 |
|
|---|
| 222 | void G4VisAttributes::SetColor ( G4double red ,
|
|---|
| 223 | G4double green ,
|
|---|
| 224 | G4double blue ,
|
|---|
| 225 | G4double alpha = 1.);
|
|---|
| 226 | </pre></div><p>
|
|---|
| 227 | </p><p>
|
|---|
| 228 | The following constructor with <span class="emphasis"><em>G4Colour</em></span> as its argument is
|
|---|
| 229 | also supported:
|
|---|
| 230 |
|
|---|
| 231 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 232 | //----- Constructor of G4VisAttributes
|
|---|
| 233 | G4VisAttributes::G4VisAttributes (const G4Colour& colour);
|
|---|
| 234 | </pre></div><p>
|
|---|
| 235 | </p><p>
|
|---|
| 236 | Note that colour assigned to a <span class="emphasis"><em>G4VisAttributes</em></span> object is
|
|---|
| 237 | not always the colour that ultimately appears in the visualization.
|
|---|
| 238 | The ultimate appearance may be affected by shading and lighting
|
|---|
| 239 | models applied in the selected visualization driver or stand-alone
|
|---|
| 240 | graphics system.
|
|---|
| 241 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisAtt.FrcAtt"></a>8.6.3.
|
|---|
| 242 | Forcing attributes
|
|---|
| 243 | </h3></div></div></div><p>
|
|---|
| 244 | As you will see later, you can select a "drawing style" from
|
|---|
| 245 | various options. For example, you can select your detector
|
|---|
| 246 | components to be visualized in "wireframe" or with "surfaces". In
|
|---|
| 247 | the former, only the edges of your detector are drawn and so the
|
|---|
| 248 | detector looks transparent. In the latter, your detector looks
|
|---|
| 249 | opaque with shading effects.
|
|---|
| 250 | </p><p>
|
|---|
| 251 | The forced wireframe and forced solid styles make it possible to
|
|---|
| 252 | mix the wireframe and surface visualization (if your selected
|
|---|
| 253 | graphics system supports such visualization). For example, you can
|
|---|
| 254 | make only the outer wall of your detector "wired" (transparent) and
|
|---|
| 255 | can see inside in detail.
|
|---|
| 256 | </p><p>
|
|---|
| 257 | Forced wireframe style is set with the following access
|
|---|
| 258 | function:
|
|---|
| 259 |
|
|---|
| 260 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 261 | void G4VisAttributes::SetForceWireframe (G4bool force);
|
|---|
| 262 | </pre></div><p>
|
|---|
| 263 | </p><p>
|
|---|
| 264 | If you give <code class="literal">true</code> as the argument, objects for which this
|
|---|
| 265 | set of visualization attributes is assigned are always visualized
|
|---|
| 266 | in wireframe even if in general, the surface drawing style has been
|
|---|
| 267 | requested. The default value of the forced wireframe style is
|
|---|
| 268 | <code class="literal">false</code>.
|
|---|
| 269 | </p><p>
|
|---|
| 270 | Similarly, forced solid style, i.e., to force that objects are
|
|---|
| 271 | always visualized with surfaces, is set with:
|
|---|
| 272 |
|
|---|
| 273 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 274 | void G4VisAttributes::SetForceSolid (G4bool force);
|
|---|
| 275 | </pre></div><p>
|
|---|
| 276 | </p><p>
|
|---|
| 277 | The default value of the forced solid style is <code class="literal">false</code>, too.
|
|---|
| 278 | </p><p>
|
|---|
| 279 | You can also force auxiliary edges to be visible. Normally they
|
|---|
| 280 | are not visible unless you set the appropriate view parameter.
|
|---|
| 281 | Forcing the auxiliary edges to be visible means that auxiliary
|
|---|
| 282 | edges will be seen whatever the view parameters.
|
|---|
| 283 | </p><p>
|
|---|
| 284 | Auxiliary edges are not genuine edges of the volume. They may be
|
|---|
| 285 | in a curved surface made out of polygons, for example, or in plane
|
|---|
| 286 | surface of complicated shape that has to be broken down into
|
|---|
| 287 | simpler polygons. HepPolyhedron breaks all surfaces into triangles
|
|---|
| 288 | or quadrilaterals. There will be auxiliary edges for any volumes
|
|---|
| 289 | with a curved surface, such as a tube or a sphere, or a volume
|
|---|
| 290 | resulting from a Boolean operation. Normally, they are not shown,
|
|---|
| 291 | but sometimes it is useful to see them. In particular, a sphere,
|
|---|
| 292 | because it has no egdes, will not be seen in wireframe mode in some
|
|---|
| 293 | graphics systems unless requested by the view parameters or forced,
|
|---|
| 294 | as described here.
|
|---|
| 295 | </p><p>
|
|---|
| 296 | To force auxiliary edges to be visible, use:
|
|---|
| 297 |
|
|---|
| 298 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 299 | void G4VisAttributes::SetForceAuxEdgeVisible (G4bool force);
|
|---|
| 300 | </pre></div><p>
|
|---|
| 301 | </p><p>
|
|---|
| 302 | The default value of the force auxiliary edges visible flag is
|
|---|
| 303 | <code class="literal">false</code>.
|
|---|
| 304 | </p><p>
|
|---|
| 305 | For volumes with edges that are parts of a circle, such as a
|
|---|
| 306 | tube (G4Tubs), etc., it is possible to force the precision of
|
|---|
| 307 | polyhedral representation for visualisation. This is recommended
|
|---|
| 308 | for volumes containing only a small angle of circle, for example, a
|
|---|
| 309 | thin tube segment.
|
|---|
| 310 | </p><p>
|
|---|
| 311 | For visualisation, a circle is represented by an N-sided
|
|---|
| 312 | polygon. The default is 24 sides or segments. The user may change
|
|---|
| 313 | this for all volumes in a particular viewer at run time with
|
|---|
| 314 | /vis/viewer/set/lineSegmentsPerCircle; alternatively it can be
|
|---|
| 315 | forced for a particular volume with:
|
|---|
| 316 |
|
|---|
| 317 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 318 | void G4VisAttributes::SetForceLineSegmentsPerCircle (G4int nSegments);
|
|---|
| 319 | </pre></div><p>
|
|---|
| 320 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisAtt.CnstAtt"></a>8.6.4.
|
|---|
| 321 | Constructors of G4VisAttributes
|
|---|
| 322 | </h3></div></div></div><p>
|
|---|
| 323 | The following constructors are supported for class
|
|---|
| 324 | <span class="emphasis"><em>G4VisAttributes</em></span>:
|
|---|
| 325 |
|
|---|
| 326 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 327 | //----- Constructors of class G4VisAttributes
|
|---|
| 328 | G4VisAttributes (void);
|
|---|
| 329 | G4VisAttributes (G4bool visibility);
|
|---|
| 330 | G4VisAttributes (const G4Colour& colour);
|
|---|
| 331 | G4VisAttributes (G4bool visibility, const G4Colour& colour);
|
|---|
| 332 | </pre></div><p>
|
|---|
| 333 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisAtt.AssgLgVol"></a>8.6.5.
|
|---|
| 334 | How to assign G4VisAttributes to a logical volume
|
|---|
| 335 | </h3></div></div></div><p>
|
|---|
| 336 | In constructing your detector components, you may assign a set of
|
|---|
| 337 | visualization attributes to each "logical volume" in order to
|
|---|
| 338 | visualize them later (if you do not do this, the graphics system
|
|---|
| 339 | will use a default set). You cannot make a solid such as
|
|---|
| 340 | <span class="emphasis"><em>G4Box</em></span> hold a set of visualization attributes; this is
|
|---|
| 341 | because a solid should hold only geometrical information. At
|
|---|
| 342 | present, you cannot make a physical volume hold one, but there are
|
|---|
| 343 | plans to design a memory-efficient way to do it; however, you can
|
|---|
| 344 | visualize a transient piece of solid or physical volume with a
|
|---|
| 345 | temporary assigned set of visualization attributes.
|
|---|
| 346 | </p><p>
|
|---|
| 347 | Class <span class="emphasis"><em>G4LogicalVolume</em></span> holds a pointer of
|
|---|
| 348 | <span class="emphasis"><em>G4VisAttributes.</em></span> This field is set and referenced with the
|
|---|
| 349 | following access functions:
|
|---|
| 350 |
|
|---|
| 351 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 352 | //----- Set functions of G4VisAttributes
|
|---|
| 353 | void G4VisAttributes::SetVisAttributes (const G4VisAttributes* pVA);
|
|---|
| 354 | void G4VisAttributes::SetVisAttributes (const G4VisAttributes& VA);
|
|---|
| 355 |
|
|---|
| 356 | //----- Get functions of G4VisAttributes
|
|---|
| 357 | const G4VisAttributes* G4VisAttributes::GetVisAttributes () const;
|
|---|
| 358 | </pre></div><p>
|
|---|
| 359 | </p><p>
|
|---|
| 360 | The following is sample C++ source codes for assigning a set of
|
|---|
| 361 | visualization attributes with cyan colour and forced wireframe
|
|---|
| 362 | style to a logical volume:
|
|---|
| 363 |
|
|---|
| 364 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 365 | //----- C++ source codes: Assigning G4VisAttributes to a logical volume
|
|---|
| 366 | ...
|
|---|
| 367 | // Instantiation of a logical volume
|
|---|
| 368 | myTargetLog = new G4LogicalVolume( myTargetTube,BGO, "TLog", 0, 0, 0);
|
|---|
| 369 | ...
|
|---|
| 370 | // Instantiation of a set of visualization attributes with cyan colour
|
|---|
| 371 | G4VisAttributes * calTubeVisAtt = new G4VisAttributes(G4Colour(0.,1.,1.));
|
|---|
| 372 | // Set the forced wireframe style
|
|---|
| 373 | calTubeVisAtt->SetForceWireframe(true);
|
|---|
| 374 | // Assignment of the visualization attributes to the logical volume
|
|---|
| 375 | myTargetLog->SetVisAttributes(calTubeVisAtt);
|
|---|
| 376 |
|
|---|
| 377 | //----- end of C++ source codes
|
|---|
| 378 | </pre></div><p>
|
|---|
| 379 | </p><p>
|
|---|
| 380 | Note that the life of the visualization attributes must be at
|
|---|
| 381 | least as long as the objects to which they are assigned; it is the
|
|---|
| 382 | users' responsibility to ensure this, and to delete the
|
|---|
| 383 | visualization attributes when they are no longer needed (or just
|
|---|
| 384 | leave them to die at the end of the job).
|
|---|
| 385 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.VisAtt.AddUdefAtt"></a>8.6.6.
|
|---|
| 386 | Additional User-Defined Attributes
|
|---|
| 387 | </h3></div></div></div><p>
|
|---|
| 388 | Geant4 Trajectories and Hits can be assigned additional arbitrary
|
|---|
| 389 | attributes that will be displayed when you click on the relevant
|
|---|
| 390 | object in the WIRED or FRED HepRep browsers. WIRED then lets you
|
|---|
| 391 | label objects by any of these attributes or cut visibility based on
|
|---|
| 392 | these attributes.
|
|---|
| 393 | </p><p>
|
|---|
| 394 | Define the attributes with lines such as:
|
|---|
| 395 |
|
|---|
| 396 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 397 | std::map<G4String,G4AttDef>* store = G4AttDefStore::GetInstance("G4Trajectory",isNew);
|
|---|
| 398 | G4String PN("PN");
|
|---|
| 399 | (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
|
|---|
| 400 | G4String IMom("IMom");
|
|---|
| 401 | (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", "Physics", "",
|
|---|
| 402 | "G4ThreeVector");
|
|---|
| 403 | </pre></div><p>
|
|---|
| 404 | </p><p>
|
|---|
| 405 | Then fill the attributes with lines such as:
|
|---|
| 406 |
|
|---|
| 407 | </p><div class="informalexample"><pre class="programlisting">
|
|---|
| 408 | std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
|
|---|
| 409 | values->push_back(G4AttValue("PN",ParticleName,""));
|
|---|
| 410 | s.seekp(std::ios::beg);
|
|---|
| 411 | s << G4BestUnit(initialMomentum,"Energy") << std::ends;
|
|---|
| 412 | values->push_back(G4AttValue("IMom",c,""));
|
|---|
| 413 | </pre></div><p>
|
|---|
| 414 | </p><p>
|
|---|
| 415 | See geant4/source/tracking/src/G4Trajectory.cc for a good example.
|
|---|
| 416 | </p><p>
|
|---|
| 417 | <span class="emphasis"><em>G4AttValue</em></span> objects are light, containing just the value;
|
|---|
| 418 | for the long description and other sharable information the
|
|---|
| 419 | <span class="emphasis"><em>G4AttValue</em></span> object refers to a <span class="emphasis"><em>G4AttDef</em></span>
|
|---|
| 420 | object. They are based on the HepRep standard described at
|
|---|
| 421 | <a href="http://www.slac.stanford.edu/~perl/heprep/" target="_top">
|
|---|
| 422 | http://www.slac.stanford.edu/~perl/heprep/
|
|---|
| 423 | </a>.
|
|---|
| 424 | Geant4 also provides an <span class="emphasis"><em>G4AttDefStore</em></span>.
|
|---|
| 425 | </p><p>
|
|---|
| 426 | Geant4 provides some default examples of the use of this
|
|---|
| 427 | facility in the trajectory classes in /source/tracking such as
|
|---|
| 428 | <span class="emphasis"><em>G4Trajectory</em></span>, <span class="emphasis"><em>G4SmoothTrajectory</em></span>.
|
|---|
| 429 | <span class="emphasis"><em>G4Trajectory::CreateAttValues</em></span> shows how
|
|---|
| 430 | <span class="emphasis"><em>G4AttValue</em></span> objects can be made and
|
|---|
| 431 | <span class="emphasis"><em>G4Trajectory::GetAttDefs</em></span> shows how
|
|---|
| 432 | to make the corresponding <span class="emphasis"><em>G4AttDef</em></span> objects and use the
|
|---|
| 433 | <span class="emphasis"><em>G4AttDefStore</em></span>. Note that the "user" of CreateAttValues
|
|---|
| 434 | guarantees to destroy them; this is a way of allowing creation on
|
|---|
| 435 | demand and leaving the <span class="emphasis"><em>G4Trajectory</em></span> object, for example,
|
|---|
| 436 | free of such objects in memory. The comments in
|
|---|
| 437 | <span class="emphasis"><em>G4VTrajectory.hh</em></span> explain further and additional insights
|
|---|
| 438 | might be obtained by looking at two methods which use them, namely
|
|---|
| 439 | <span class="emphasis"><em>G4VTrajectory::DrawTrajectory</em></span> and
|
|---|
| 440 | <span class="emphasis"><em>G4VTrajectory::ShowTrajectory</em></span>.
|
|---|
| 441 | </p><p>
|
|---|
| 442 | Hits classes in examples /extended/analysis/A01 and
|
|---|
| 443 | /extended/runAndEvent/RE01 show how to do the same for your hits.
|
|---|
| 444 | The base class no-action methods CreateAttValues and GetAttDefs
|
|---|
| 445 | should be overridden in your concrete class. The comments in
|
|---|
| 446 | <span class="emphasis"><em>G4VHit.hh</em></span> explain further.
|
|---|
| 447 | </p><p>
|
|---|
| 448 | In addition, the user is free to add a
|
|---|
| 449 | <span class="emphasis"><em>G4std::vector<G4AttValue>*</em></span> and a
|
|---|
| 450 | <span class="emphasis"><em>G4std::vector<G4AttDef>*</em></span> to a
|
|---|
| 451 | <span class="emphasis"><em>G4VisAttributes</em></span> object as could, for example,
|
|---|
| 452 | be used by a <span class="emphasis"><em>G4LogicalVolume</em></span> object.
|
|---|
| 453 | </p><p>
|
|---|
| 454 | At the time of writing, only the HepRep graphics systems are
|
|---|
| 455 | capable of displaying the G4AttValue information, but this
|
|---|
| 456 | information will become useful for all Geant4 visualization systems
|
|---|
| 457 | through improvements in release 8.1 or later.
|
|---|
| 458 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch08s05.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch08.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch08s07.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">8.5.
|
|---|
| 459 | Controlling Visualization from Compiled Code
|
|---|
| 460 | </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="AllResources/IconsGIF/home.gif" alt="Home"></a></td><td width="40%" align="right" valign="top"> 8.7.
|
|---|
| 461 | Enhanced Trajectory Drawing
|
|---|
| 462 | </td></tr></table></div></body></html>
|
|---|