source: trunk/documents/UserDoc/DocBookUsersGuides/ForToolkitDeveloper/xml/GuideToExtendFunctionality/Geometry/geometry.xml @ 1222

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

ajout de la doc

File size: 13.3 KB
Line 
1<!-- ******************************************************** -->
2<!--  Docbook Version:  For Toolkit Developers Guide          -->
3<!-- ******************************************************** -->
4
5<!-- ******************* Section (Level#1) ****************** -->
6<sect1 id="sect.ExtdFuncGeom">
7<title>
8Geometry
9</title>
10
11<!-- ******************* Section (Level#2) ****************** -->
12<sect2 id="sect.ExtdFuncGeom.WhtCan">
13<title>
14What can be extended ?
15</title>
16
17<para>
18Geant4 already allows a user to describe any desired solid,
19and to use it in a detector description, in some cases, however,
20the user may want or need to extend Geant4's geometry.
21One reason can be that some methods and types in the geometry
22are general and the user can utilise specialised knowledge about
23his or her geometry to gain a speedup. The most evident case where
24this can happen is when a particular type of solid is a key
25element for a specific detector geometry and an investment in
26improving its runtime performance may be worthwhile.
27</para>
28
29<para>
30To extend the functionality of the Geometry in this way,
31a toolkit developer must write a small number of methods for
32the new solid.
33We will document below these methods and their specifications.
34Note that the implementation details for some methods are not a
35trivial matter: these methods must provide the functionality of
36finding whether a point is inside a solid, finding the
37intersection of a line with it, and finding the distance to the
38solid along any direction. However once the solid class has been
39created with all its specifications fulfilled, it can be used like
40any Geant4 solid, as it implements the abstract interface of G4VSolid.
41</para>
42
43<para>
44Other additions can also potentially be achieved. For example,
45an advanced user could add a new way of creating physical volumes.
46However, because each type of volume has a corresponding navigator
47helper, this would require to create a new Navigator as well.
48To do this the user would have to inherit from G4Navigator and
49modify the new Navigator to handle this type of volumes.
50This can certainly be done, but will probably be made easier to
51achieve in the future versions of the Geant4 toolkit.
52</para>
53
54</sect2>
55
56<!-- ******************* Section (Level#2) ****************** -->
57<sect2 id="sect.ExtdFuncGeom.AddSld">
58<title>
59Adding a new type of Solid
60</title>
61
62<para>
63We list below the required methods for integrating a new type
64of solid in Geant4. Note that Geant4's specifications for a
65solid pay significant attention to what happens at points that
66are within a small distance (tolerance,
67<emphasis role="bold">kCarTolerance</emphasis> 
68in the code) of the surface. So special care must be taken to
69handle these cases in considering all different possible
70scenarios, in order to respect the specifications and allow
71the solid to be used correctly by the other components of the
72geometry module.
73</para>
74
75<!-- ******* Bridgehead ******* -->
76<bridgehead renderas='sect4'>
77Creating a derived class of G4VSolid
78</bridgehead>
79
80<para>
81The solid must inherit from G4VSolid or one of its
82derived classes and implement its virtual functions.
83</para>
84
85<para>
86Mandatory member functions you must define are the following
87pure virtual of G4VSolid:
88
89<informalexample><programlisting>
90 EInside Inside(const G4ThreeVector&amp; p)
91 G4double DistanceToIn(const G4ThreeVector&amp; p)
92 G4double DistanceToIn(const G4ThreeVector&amp; p, const G4ThreeVector&amp; v)
93 G4ThreeVector SurfaceNormal(const G4ThreeVector&amp; p)
94 G4double DistanceToOut(const G4ThreeVector&amp; p)
95 G4double DistanceToOut(const G4ThreeVector&amp; p, const G4ThreeVector&amp; v,
96                        const G4bool calcNorm=false,
97                              G4bool *validNorm=0, G4ThreeVector *n)
98 G4bool CalculateExtent(const EAxis pAxis,
99                        const G4VoxelLimits&amp; pVoxelLimit,
100                        const G4AffineTransform&amp; pTransform,
101                              G4double&amp; pMin,
102                              G4double&amp; pMax) const
103 G4GeometryType GetEntityType() const
104 std::ostream&amp; StreamInfo(std::ostream&amp; os) const
105</programlisting></informalexample>
106</para>
107
108<para>
109They must perform the following functions
110
111<informalexample><programlisting>
112  EInside Inside(const G4ThreeVector&amp; p)
113</programlisting></informalexample>
114
115This method must return:
116
117<itemizedlist spacing="compact">
118  <listitem><para>
119    kOutside if the point at offset p is outside the shape
120    boundaries plus Tolerance/2,
121  </para></listitem>
122  <listitem><para>
123    kSurface if the point is &lt;= Tolerance/2 from a surface, or
124  </para></listitem>
125  <listitem><para>
126    kInside otherwise.
127  </para></listitem>
128</itemizedlist>
129</para>
130
131<para>
132<informalexample><programlisting>
133G4ThreeVector SurfaceNormal(const G4ThreeVector&amp; p)
134</programlisting></informalexample>
135
136Return the outwards pointing unit normal of the shape for the
137surface closest to the point at offset p.
138
139<informalexample><programlisting>
140G4double DistanceToIn(const G4ThreeVector&amp; p)
141</programlisting></informalexample>
142
143Calculate distance to nearest surface of shape from an outside
144point p. The distance can be an underestimate.
145
146<informalexample><programlisting>
147G4double DistanceToIn(const G4ThreeVector&amp; p, const G4ThreeVector&amp; v)
148</programlisting></informalexample>
149
150Return the distance along the normalised vector v to the shape,
151from the point at offset p. If there is no intersection, return
152kInfinity. The first intersection resulting from `leaving'
153a surface/volume is discarded. Hence, this is tolerant of points on
154surface of shape.
155
156<informalexample><programlisting>
157G4double DistanceToOut(const G4ThreeVector&amp; p)
158</programlisting></informalexample>
159
160Calculate distance to nearest surface of shape from an inside
161point. The distance can be an underestimate.
162
163<informalexample><programlisting>
164G4double DistanceToOut(const G4ThreeVector&amp; p, const G4ThreeVector&amp; v,
165                        const G4bool calcNorm=false,
166                        G4bool *validNorm=0, G4ThreeVector *n=0);
167</programlisting></informalexample>
168
169Return distance along the normalised vector v to the shape, from
170a point at an offset p inside or on the surface of the shape.
171Intersections with surfaces, when the point is not greater than
172kCarTolerance/2 from a surface, must be ignored.
173</para>
174
175<para>
176If calcNorm is true, then it must also set validNorm to either
177<itemizedlist spacing="compact">
178<listitem><para></para></listitem>true, if the solid lies entirely behind or on the exiting
179      surface. Then it must set n to the outwards normal vector (the
180      Magnitude of the vector is not defined).
181<listitem><para></para></listitem>false, if the solid does not lie entirely behind or on the
182      exiting surface.
183</itemizedlist>
184</para>
185
186<para>
187If calcNorm is false, then validNorm and n are unused.
188
189<informalexample><programlisting>
190G4bool CalculateExtent(const EAxis pAxis,
191                        const G4VoxelLimits&amp; pVoxelLimit,
192                        const G4AffineTransform&amp; pTransform,
193                              G4double&amp; pMin,
194                              G4double&amp; pMax) const
195</programlisting></informalexample>
196
197Calculate the minimum and maximum extent of the solid, when under the
198specified transform, and within the specified limits. If the solid
199is not intersected by the region, return false, else return true.
200
201<informalexample><programlisting>
202G4GeometryType GetEntityType() const;
203</programlisting></informalexample>
204
205Provide identification of the class of an object (required for
206persistency and STEP interface).
207
208<informalexample><programlisting>
209std::ostream&amp; StreamInfo(std::ostream&amp; os) const
210</programlisting></informalexample>
211
212Should dump the contents of the solid to an output stream.
213</para>
214
215<para>
216The method:
217
218<informalexample><programlisting>
219G4double GetCubicVolume()
220</programlisting></informalexample>
221
222should be implemented for every solid in order to cache the computed
223value (and therefore reuse it for future calls to the method) and to
224eventually implement a precise computation of the solid's volume. If
225the method will not be overloaded, the default implementation from the
226base class will be used (estimation through a Monte Carlo algorithm)
227and the computed value will not be stored.
228</para>
229
230<para>
231There are a few member functions to be defined for the purpose of
232visualisation. The first method is mandatory, and the next four are not.
233
234<informalexample><programlisting>
235  // Mandatory
236  virtual void DescribeYourselfTo (G4VGraphicsScene&amp; scene) const = 0;
237
238  // Not mandatory
239  virtual G4VisExtent GetExtent() const;
240  virtual G4Polyhedron* CreatePolyhedron () const;
241  virtual G4NURBS*      CreateNURBS      () const;
242  virtual G4Polyhedron* GetPolyhedron    () const;
243</programlisting></informalexample>
244
245What these methods should do and how they should be implemented is
246described here.
247
248<informalexample><programlisting>
249 void DescribeYourselfTo (G4VGraphicsScene&amp; scene) const;
250</programlisting></informalexample>
251
252This method is required in order to identify the solid to the graphics scene.
253It is used for the purposes of ``double dispatch''. All implementations
254should be similar to the one for G4Box:
255
256<informalexample><programlisting>
257void G4Box::DescribeYourselfTo (G4VGraphicsScene&amp; scene) const
258{
259  scene.AddSolid (*this);
260}
261</programlisting></informalexample>
262
263The method:
264
265<informalexample><programlisting>
266 G4VisExtent GetExtent() const;
267</programlisting></informalexample>
268
269provides extent (bounding box) as a possible hint to the graphics view.
270You must create it by finding a box that encloses your solid, and returning
271a VisExtent that is created from this.
272The G4VisExtent must presumably be given the minus x, plus x,
273minus y, plus y, minus z and plus z extents of this ``box''.
274For example a cylinder can say
275
276<informalexample><programlisting>
277G4VisExtent G4Tubs::GetExtent() const
278{
279  // Define the sides of the box into which the G4Tubs instance would fit.
280  return G4VisExtent (-fRMax, fRMax, -fRMax, fRMax, -fDz, fDz);
281}
282</programlisting></informalexample>
283
284The method:
285
286<informalexample><programlisting>
287 G4Polyhedron* CreatePolyhedron () const;
288</programlisting></informalexample>
289
290is required by the visualisation system, in order to create a
291realistic rendering of your solid. To create a G4Polyhedron for
292your solid, consult G4Polyhedron.
293</para>
294
295<para>
296While the method:
297
298<informalexample><programlisting>
299 G4Polyhedron* GetPolyhedron () const;
300</programlisting></informalexample>
301
302is a ``smart'' access function that creates on requests a polyhedron
303and stores it for future access and should be customised for every solid.
304</para>
305
306<para>
307The method:
308
309<informalexample><programlisting>
310 G4NURBS* CreateNURBS () const;
311</programlisting></informalexample>
312
313is not currently utilised, so you do not have to implement it.
314</para>
315
316</sect2>
317
318<!-- ******************* Section (Level#2) ****************** -->
319<sect2 id="sect.ExtdFuncGeom.ModNav">
320<title>
321Modifying the Navigator
322</title>
323
324<para>
325For the vast majority of use-cases, it is not indeed necessary
326(and definitely not advised) to extend or modify the existing
327classes for navigation in the geometry.
328A possible use-case for which this may apply, is for the
329description of a new kind of physical volume to be integrated.
330We believe that our set of choices for creating physical volumes
331is varied enough for nearly all needs.
332Future extensions of the Geant4 toolkit will probably make
333easier exchanging or extending the G4Navigator, by introducing an
334abstraction level simplifying the customisation. At this time,
335a simple abstraction level of the navigator is provided by allowing
336overloading of the relevant functionalities.
337</para>
338
339<!-- ******* Bridgehead ******* -->
340<bridgehead renderas='sect4'>
341Extending the Navigator
342</bridgehead>
343
344<para>
345The main responsibilities of the Navigator are:
346
347<itemizedlist spacing="compact">
348  <listitem><para>
349    locate a point in the tree of the geometrical volumes;
350  </para></listitem>
351  <listitem><para>
352    compute the length a particle can travel from a point
353    in a certain direction before encountering a volume
354      boundary.
355  </para></listitem>
356</itemizedlist>
357</para>
358
359<para>
360The Navigator utilises one helper class for each type of physical
361volume that exists. You will have to reuse the helper classes provided
362in the base Navigator or create new ones for the new type of physical volume.
363</para>
364
365<para>
366To extend G4Navigator you will have then to inherit from it
367and modify these functions in your ModifiedNavigator to
368request the answers for your new physical volume type from the
369new helper class. The ModifiedNavigator should delegate other
370cases to the Geant4's standard Navigator.
371</para>
372
373
374<!-- ******* Bridgehead ******* -->
375<bridgehead renderas='sect4'>
376Replacing the Navigator
377</bridgehead>
378
379<para>
380Replacing the Navigator is another possible operation. It is
381similar to extending the Navigator, in that any types of physical
382volume that will be allowed must be handled by it. The same
383functionality is required as described in the previous section.
384</para>
385
386<para>
387However the amount of work is probably potentially larger, if
388support for all the current types of physical volumes is required.
389</para>
390
391<para>
392The Navigator utilises one helper class for each type of
393physical volume that exists. These could also potentially be
394replaced, allowing a simpler way to create a new navigation
395system.
396</para>
397
398</sect2>
399</sect1>
Note: See TracBrowser for help on using the repository browser.