pyg4ometry.visualisation.VtkViewer¶
Attributes¶
Classes¶
Visualiser. |
|
Visualiser that extends VtkViewer. Uses "flat" interpolation and introduces control over colours. |
|
Extension of VtkViewerColoured that uses a default material dictionary for |
|
Functions¶
|
|
|
Module Contents¶
- class pyg4ometry.visualisation.VtkViewer.VtkViewer(size=(1024, 1024), interpolation='none', **kwargs)¶
Visualiser.
- Parameters:
size – (int,int) - (nPixelsHorizontal, nPixelsVeritcal), default (1024,1024)
interpolation – (str) - one of “none”, “flat”, “gouraud”, “phong”
- Examples:
>>> v = VtkViewer() >>> v.addLogicalVolume(someLV) >>> v.view()
- ren¶
- renWin¶
- iren¶
- style¶
- localmeshes¶
- localmeshesOverlap¶
- filters¶
- filtersOverlap¶
- mappers = []¶
- physicalMapperMap¶
- mappersOverlap = []¶
- physicalMapperMapOverlap¶
- actors = []¶
- physicalActorMap¶
- actorsOverlap = []¶
- physicalActorMapOverlap¶
- _xCutterOrigin = [0, 0, 0]¶
- _yCutterOrigin = [0, 0, 0]¶
- _zCutterOrigin = [0, 0, 0]¶
- _xCutterNormal = [1, 0, 0]¶
- _yCutterNormal = [0, 1, 0]¶
- _zCutterNormal = [0, 0, 1]¶
- xcutters = []¶
- ycutters = []¶
- zcutters = []¶
- usercutters = []¶
- axes = []¶
- materialVisOptions = None¶
- interps = ('none', 'flat', 'gouraud', 'phong')¶
- interpolation¶
- addAxes(length=20.0, origin=(0, 0, 0))¶
Add x,y,z axis to the scene.
- Parameters:
length – float - length of each axis in mm
origin – (float,float,float) - (x,y,z) of origin in mm
- addAxesWidget()¶
- setOpacity(v, iActor=-1)¶
- setWireframe(iActor=-1)¶
- setSurface(iActor=-1)¶
- setOpacityOverlap(v, iActor=-1)¶
- setWireframeOverlap(iActor=-1)¶
- setSurfaceOverlap(iActor=-1)¶
- setRandomColours(seed=0)¶
- setCutterOrigin(dimension, origin)¶
- Parameters:
dimension – str - ‘x’, ‘y’, or ‘z’
origin – list([x,y,z])
- setCutterNormal(dimension, normal)¶
- Parameters:
dimension – str - ‘x’, ‘y’, or ‘z’
normal – list([x,y,z]) - should be unit vector
- addMaterialVisOption(materialName, visOptionInstance)¶
Append a visualisation option instance to the dictionary of materials.
- Parameters:
materialName – str - material name to match
visOptionInstance –
VisualisationOptionsinstance
- setMaterialVisOptions(materialDict)¶
Replace the (by default None) dictionary for materials to colours :param materialDict: {“materialName”: VisualisationOptions}
See also
VisualisationOptions.
- setCameraFocusPosition(focalPoint=[0, 0, 0], position=[100, 100, 100])¶
- start()¶
- exportOBJScene(fileName='scene')¶
- exportVRMLScene(fileName='scene')¶
- exportGLTFScene(fileName='scene.gltf')¶
- exportScreenShot(fileName='screenshot.png', rgba=True)¶
Write the render window view to an image file.
Image types supported are: BMP, JPEG, PNM, PNG, PostScript, TIFF. The default parameters are used for all writers, change as needed.
- Parameters:
fileName – The file name, if no extension then PNG is assumed.
renWin – The render window.
rgba – Used to set the buffer type.
- Returns:
- addLogicalVolume(logical, mtra=_np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), tra=_np.array([0, 0, 0]), recursive=True, addWorld=True)¶
- addLogicalVolumeBounding(logical)¶
- addSolid(solid, rotation=[0, 0, 0], position=[0, 0, 0], representation='surface', colour=[0.5, 0.5, 0.5], opacity=0.2)¶
Add a solid to the view with an optional rotation and translation.
- Parameters:
solid (any solid in pyg4ometry.geant4.solid) – solid to add to the view
rotation (list(float, float, float) - 3 values) – list of TB rotation angles in radians
position (list(float, float, float) - 3 values) – translation in global from from centre in mm
representation (str) – the way to visualise it, e.g. ‘surface’ or ‘wireframe’
colour (list(float, float, float) - 3 values ranging from 0 - 1) – normalised rgb colour to use for the solid mesh
opacity (float, from 0 to 1) – the opacity of the solid if surface style
- addBooleanSolidRecursive(solid, mtra=_np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), tra=_np.array([0, 0, 0]), first=True)¶
- Parameters:
solid (pyg4ometry.geant4.solid.SolidBase) – pyg4ometry.geant4.solid instance.
Other parameters are for internal recursion and don’t need to be provided.
Render only a Boolean solid. If one of the constituent solids is also a Boolean, visualise those too. The resultant Boolean is shown in solid form and each constituent in a wireframe. In the case of a null mesh, only the constituents can be shown.
- addMeshSimple(csgMesh, visOptions=_VisOptions(), clip=False, name='mesh')¶
- addLogicalVolumeRecursive(logical, mtra=_np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), tra=_np.array([0, 0, 0]))¶
- addMesh(pv_name, solid_name, mesh, mtra, tra, localmeshes, filters, mappers, mapperMap, actors, actorMap, visOptions=None, overlap=False, cutters=True, clippers=False)¶
- view(interactive=True, resetCamera=True)¶
- _getCutterData(axis='x', scaling=1.0)¶
- exportCutterSection(filename, normal='x', scaling=1.0)¶
Export the section lines in plane perpendicular to normal. Exported as json text.
- Parameters:
filename – (str) - name of file to export to
normal – (str) - one of “x”, “y” or “z”
scaling – (float) - multiplier for all cutter line coordinates on export
- Examples:
>>> v.exportCutterSection("xz-section.dat", normal="y", scaling=1000)
- viewSection(dir='x')¶
- addCutterPlane(position, normal, colour=None)¶
Add a cutting plane at position=[x,y,z] with normal [nx,ny,nz].
- Parameters:
position – [float, float, float] - (x,y,z) position in scene (mm)
normal – [float, float, float] - (nx,ny,z) normal unit vector
colour – None or [float, float, float] - [r,g,b] in range [0:1]
Cutters are stored in self.usercutters.
- addActor(actor)¶
- getOverlapVisOptions(overlaptype)¶
- getMaterialVisOptions(pv)¶
- _getDefaultVis(pv)¶
- printViewParameters()¶
- class pyg4ometry.visualisation.VtkViewer.VtkViewerColoured(*args, defaultColour=None, materialVisOptions=None, **kwargs)¶
Bases:
VtkViewerVisualiser that extends VtkViewer. Uses “flat” interpolation and introduces control over colours.
- Keyword Arguments:
materialVisOptions: {“materialName”:
VisualisationOptionsor list or tuple, …}interpolation (str): see
VtkViewerdefaultColour (str): “random” or [r,g,b]
- Examples:
>>> vMaterialMap = VtkViewerColoured(materialVisOptions={"G4_WATER":[0,0,1]}) >>> vRandom = VtkViewerColoured(defaultColour="random") >>> vColoured = VtkViewerColoured(defaultColour=[0.1,0.1,0.1]) >>> vColourAlpha = VtkViewerColoured(defaultColour=[0.1,0.1,0.1,0.5])
of use visualisation options instances
>>> vo = pyg4ometry.visualisation.VisualisationOptions() >>> vo.colour = [0.1,1.0,0.5] >>> vo.alpha = 0.3 >>> options = {'G4_WATER':vo} >>> vis = VtkViewerColoured(materialVisOptions=options)
If the value in the materialVisOptions is a list or a tuple, it will be upgraded to a
VisualisationOptionsinstance.- materialVisOptions¶
- _defaultVis¶
- randomColour¶
- _getDefaultVis(pv)¶
- pyg4ometry.visualisation.VtkViewer.PubViewer¶
- class pyg4ometry.visualisation.VtkViewer.VtkViewerColouredMaterial(*args, **kwargs)¶
Bases:
PubViewerExtension of VtkViewerColoured that uses a default material dictionary for several common materials. Material colours are in defined Colour.py for many Geant4, FLUKA and BDSIM materials.
- class pyg4ometry.visualisation.VtkViewer.MouseInteractorNamePhysicalVolume(renderer, vtkviewer)¶
Bases:
vtk.vtkInteractorStyleTrackballCamera- renderer¶
- vtkviewer¶
- rightButtonPressEvent(obj, event)¶
- pyg4ometry.visualisation.VtkViewer.axesFromExtents(extent)¶
- pyg4ometry.visualisation.VtkViewer.viewLogicalVolumeDifference(referenceLV, otherLV, otherTranslation=[0, 0, 0], otherRotation=[0, 0, 0], viewDifference=True)¶
- Parameters:
referenceLV (pyg4ometry.geant4.LogicalVolume.) – LogicalVolume instance to view viewed in red.
referenceLV – LogicalVolume instance to view viewed in blue.
otherTranslation ([float, float, float]) – Translation (in native units, mm) of otherLV w.r.t. referenceLV
otherRotation ([float, float, float]) – Rotation (in native units, rad) of other LV w.r.t. referenceLV.
View the shapes of 2 logical volumes without their contents. The reference one will be red and the ‘other’ one will be blue.
The other one may optionally be translated and rotated (Tait-Bryant x,y,z) relative to the reference.