saveImage()

Create and save an image of the screen.

Usage

savedFileName = vis.saveImage( width = 600, height = 400,
                                         fileName = None, fileType = 'png',
                                         dirName = None )

Parameters

width (integer)
Width of image in pixels.
height (integer)
Height of image in pixels.
fileName (string)
Image file name.
  • If the extension is included, the argument of fileType is ignored and the actual file type is determined by the extension.
  • If the extension is not included, the actual file type is taken from the argument fileType.
  • If fileName is None, fileType is used to generate the actual file name of Image_*.fileType.
fileType (string)
Image file type. Currently only .png format is supported.
dirName (string)
The directory that the image will be saved in. CWD represents the current working directory of AcuSolve. If dirName is not specified, the image file will be saved in CWD/Figures/. Otherwise the file will be saved in CWD/Figures/dirName/.

Return Value

savedFileName (string)
Saved image file name, which contains the full directory of the file savedFileName = CWD/Figures/dirName/filename.

Errors

None

Description

It was found that 600 pixels can fit well into the width of a regular letter paper. If you would like to save the image with more pixels, the following way is suggested:
scaleFactor=3
imageFileName = vis.saveImage( width=600*scaleFactor, height=400*scaleFactor )
addFigure(imageFileName, scale=1.0/scaleFactor)

Here the scaleFactor is an integer. At first an image with pixels of 600*scaleFactor x 400*scaleFactor is saved. But this raw image cannot fit into the paper very well. So in addFigure the image is scaled smaller with the same scaleFactor. In the final .pdf report, the image has more pixels but the same physical size, so a higher resolution is obtained.

The following section of code generates a figure in which the size of the actor fits well:
# cpl_y is a cut plane object produced by vis.addCPlane
cutBndBox=cpl_y.sceneGraph.getBoundingBox()
# cutBndBox gives the bounding box of the coordinates of cpl_y, which is a list contains [xmin,ymin,zmin,xmax,ymax,zmax]
aspectRatio=(cutBndBox[3]-cutBndBox[0])/(cutBndBox[5]-cutBndBox[2])
# Since the cut plane is normal to Y axis, the camera will be adjusted normal to Y axis. The width of the actor is measured along X axis and the height is along Z axis. The aspect ratio is obtained by (xmax-xmin)/(zmax-zmin)
vis.zoom( -math.log(aspectRatio)  )
# The command above gives a view in which the actor fits the image best.
imgFct=4
fname = vis.saveImage( width =600*imgFct , height = 600*imgFct/aspectRatio, fileName='Mesh_xz.png')
# The size of the image depends on the aspect ratio of the actor