Skip to content

Commit

Permalink
Merge pull request #225 from lnevay/docs-fix-step-figure
Browse files Browse the repository at this point in the history
Fix filename for image in manual that doesn't show.
  • Loading branch information
lnevay authored Jan 26, 2025
2 parents fee1003 + 0f44c14 commit f9c8bf2
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 58 deletions.
4 changes: 3 additions & 1 deletion docs/source/manual/loading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ used for visualisation or other operations.

Here, we use example files provided in the g4edge-testdata package that can be installed with:
::
pip install g4edge-testdata

pip install g4edge-testdata


An instance of the test data can be used to access any file.

Expand Down
7 changes: 5 additions & 2 deletions docs/source/manual/rendering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ format is Universal Scene Description (USD). USD can be loaded in
many packages and so a dedicated UDS converter/viewer is available
in pyg4ometry. For example to load and convert a file to USD

.. code-block:: python
.. code-block:: python
:linenos:
r = pyg4ometry.gdml.Reader("lht.gdml")
l = r.getRegistry().getWorldVolume()
v = pyg4ometry.visualisation.UsdViewer("lht.usd")
v.traverseHierarchy(l)
v.save()
This will write a file called lht.gdml which can be viewed in
a USD viewer like usdview. USD has a preview shader. The settings
can set via the `VisualisationOptions` stored in logical volumes
(`visOption`), so for example

.. code-block:: python
.. code-block:: python
:linenos:
r = pyg4ometry.gdml.Reader("lht.gdml")
reg = r.getRegistry()
reg.logicalVolumeDict["vCalorimeter"].visOptions.color = [1, 0, 0]
Expand Down
4 changes: 3 additions & 1 deletion docs/source/manual/validating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Validating Geometry
===================



Overlap Checking
----------------

Expand All @@ -23,13 +22,15 @@ the following code:
lv.checkOverlaps()
This will check only the immediate daughters of this logical volume. To descend further into
a geometry, the recursive flag can be used:

.. code-block :: python
lv.checkOverlaps(recursive=True)
See :ref:`g4-module` : :code:`LogicalVolume.checkOverlaps()` for full details. A more
complete example is:

Expand All @@ -46,6 +47,7 @@ complete example is:
v.addLogicalVolume(l)
v.view()
.. figure:: pythonscripting/pythonscripting2.png
:alt: Example overlap visualisation

Expand Down
101 changes: 58 additions & 43 deletions docs/source/manual/viewing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and have the same functionality and differ only in colouring of volumes.
Generally:

.. code-block:: python
:linenos:
v = pyg4ometry.visualisation.VtkViewer()
v.addLogicalVolume(lv)
Expand Down Expand Up @@ -123,6 +124,7 @@ logical volume has no concept of translation or rotation on its own, so it is pl
in the centre of the visualiser coordinate system, i.e. in its own frame.

.. code-block:: python
:linenos:
lv # pyg4ometry.geant4.LogicalVolume instance
v = pyg4ometry.visualisation.VtkViewer()
Expand All @@ -133,29 +135,34 @@ It is possible to view the logical volume with an offset (i.e. translation) and
rotation. This is purely for adding the scene of the viewer and does not affect
the logical volume itself or anything it is used in. We can see the docstring:

>>> v = pyg4ometry.visualisation.VtkViewer()
>>> v.addLogicalVolume?
Signature:
v.addLogicalVolume(
logical,
mtra=matrix([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]),
tra=array([0, 0, 0]),
recursive=True,
)
::

v = pyg4ometry.visualisation.VtkViewer()
v.addLogicalVolume?
Signature:
v.addLogicalVolume(
logical,
mtra=matrix([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]),
tra=array([0, 0, 0]),
recursive=True,
)


If we start from a rotation as a series of Tait-Bryan angles, we can turn this into
a matrix with:

.. code-block::
.. code-block:: python
:linenos:
import numpy as np
import numpy as np
rotation = [0, np.pi/2, 0] # for example
matrix = np.linalg.inv(pyg4ometry.transformation.tbxyz2matrix(rotation))
l # a pyg4ometry.geant4.LogicalVolume instance
v = pyg4ometry.visualisation.VtkViewer()
v.addLogicalVolume(l, mtra=rotation, tra=[0,0,500])
rotation = [0, np.pi / 2, 0] # for example
matrix = np.linalg.inv(pyg4ometry.transformation.tbxyz2matrix(rotation))
l # a pyg4ometry.geant4.LogicalVolume instance
v = pyg4ometry.visualisation.VtkViewer()
v.addLogicalVolume(l, mtra=rotation, tra=[0, 0, 500])
.. note::
Expand Down Expand Up @@ -183,16 +190,19 @@ Similarly to a logical volume, an individual solid has no concept of placement p
and will by default be placed at the centre of the scene. It is also possible to add it
to the scene with a rotation and translation.

>>> v.addSolid?
Signature:
v.addSolid(
solid,
rotation=[0, 0, 0],
position=[0, 0, 0],
representation='surface',
colour=[0.5, 0.5, 0.5],
opacity=0.2,
)
::

v.addSolid?
Signature:
v.addSolid(
solid,
rotation=[0, 0, 0],
position=[0, 0, 0],
representation='surface',
colour=[0.5, 0.5, 0.5],
opacity=0.2,
)


This uses Tait-Bryan angles for the rotation.

Expand All @@ -204,12 +214,14 @@ in these and it is useful to understand the individual constituents even if the
a valid solid or mesh (i.e. completely disconnected solids). To do this we can visualise just
a Boolean solid on its own.

.. code-block::
.. code-block:: python
:linenos:
s # e.g. a pyg4ometry.geant4.solid.Subtraction instance
v = pyg4ometry.visualisation.VtkViewer()
v.addBooleanSolidRecursive(s)
v.view()
s # e.g. a pyg4ometry.geant4.solid.Subtraction instance
v = pyg4ometry.visualisation.VtkViewer()
v.addBooleanSolidRecursive(s)
v.view()
This will work recursively for each solid that makes up the Boolean even if they are Booleans
themselves. It will tolerate shapes that cannot form a valid mesh such as the resultant Boolean
Expand All @@ -232,7 +244,7 @@ Random Colours
With the :code:`VtkViewerColoured` class, we can supply the default colour as :code:`"random"`,
which will result in every volume being visualised with a random colour to be different.

.. code-block::
.. code-block:: python
v = pyg4ometry.visualisation.VtkViewerColoured(defaultColour="random")
Expand All @@ -258,22 +270,25 @@ Cutters are a feature in the visualiser to generate the usually red, green, blue
that intercept the edges of the geometry in a given plane. By default, these are along
each axis aligned with 0,0,0. These can be plotted or added to an existing plot as follows:

:: code-block::
.. code-block:: python
:linenos:
pyg4ometry.visualisation.Plot.AddCutterDataToPlot("crosssection-ZX.dat",
"zx",
unitsFactor=0.001)
pyg4ometry.visualisation.Plot.AddCutterDataToPlot(
"crosssection-ZX.dat", "zx", unitsFactor=0.001
)
An optional Matplotlib axes instance can be given if there is one from an existing plot.

:: code-block::
.. code-block:: python
:linenos:
f = matplotlib.pyplot.figure()
ax = f.add_subplot(111)
ax.plot([0,1],[0,1])
pyg4ometry.visualisation.Plot.AddCutterDataToPlot("crosssection-ZX.dat",
"zx", ax,
unitsFactor=0.001)
ax.plot([0, 1], [0, 1])
pyg4ometry.visualisation.Plot.AddCutterDataToPlot(
"crosssection-ZX.dat", "zx", ax, unitsFactor=0.001
)
The full documentation can be found for :meth:`pyg4ometry.visualisation.Plot.AddCutterDataToPlot`.
46 changes: 35 additions & 11 deletions src/pyg4ometry/mcnp/Transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,44 @@


class TR:
"""
r"""
Coordinate Transformation
:param o1, o2, o3: Displacement vector of the transformation. DEFAULT: (0, 0, 0).
:param rotation Matrix: The rotation Matrix default is /
[xx' yx' zx'] [1 0 0]
[xy' yy' zy'] = [0 1 0]
[xz' yz' zz'] [0 0 1]
:param displacementOrigin: Displacement vector origin /
If = positive 1 the displacement vector is the location of the origin of the auxiliary coordinate system, /
defined in the main system. (DEFAULT)
If = negative 1 the displacement vector is the location of the origin of the main coordinate system, /
defined in the auxiliary system.
:param o1: x-component of displacement vector of the transformation
:type o1: float
:param o2: y-component of displacement vector of the transformation
:type o2: float
:param o3: z-component of displacement vector of the transformation
:type o3: float
:param rotxx: x x' component of rotation matrix. Other parameters are as below in the default matrix.
:type rotxx: float
:param displacementOrigin: Displacement vector origin - either 1 or -1
:type displacementOrigin: int
:param transformationNumber: Number assigned to the transformation.
The default rotation matrix is:
.. math::
\begin{equation}
\begin{bmatrix}
xx' & yx' & zx' \\
xy' & yy' & zy' \\
xz' & yz' & zz'
\end{bmatrix}
=
\begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
\end{equation}
For `displacementOrigin = 1` the displacement vector is the location of the origin of the
auxiliary coordinate system, defined in the main system. (DEFAULT). For `displacementOrigin = -1`,
the displacement vector is the location of the origin of the main coordinate system, defined
in the auxiliary system.
"""

def __init__(
Expand Down

0 comments on commit f9c8bf2

Please sign in to comment.