# save picture in file
# Construct image file name
- pic_name = picturedir + "params_" + repr.replace(' ', '_') + "_any_" + \
+ base_name = "params_" + repr.replace(' ', '_') + "_any_" + \
str(sha) + "_" + str(opa) + "_" + str(lwi) + "." + pictureext
+ pic_name = os.path.join(picturedir, base_name)
# Show and record the presentation
process_prs_for_test(plot3d, my_view, pic_name)
+
+ # Compare to baseline
+ current_dir = os.path.dirname(os.path.realpath(__file__))
+ baseline = os.path.join(current_dir, "_refs", base_name)
+ compare_view_to_ref_image(my_view, baseline, threshold=1)
import sys
import os
-from paravistest import datadir, pictureext, get_picture_dir, get_png_picture_resolution
+from paravistest import datadir, pictureext, get_picture_dir, compare_view_to_ref_image
from pvsimple import GetActiveSource, GetRenderView, Render, OpenDataFile
from presentations import ScalarMapOnField, hide_all, EntityType, PrsTypeEnum,reset_view,process_prs_for_test
aFieldEntity = EntityType.NODE
aFieldName = "MODES___DEPL____________________"
-#create list to store picture files sizes
-sizesw=[]
-sizesh=[]
#create Scalar Map presentations for 10 timestamps
for i in range(1,11):
hide_all(aView, True)
reset_view(aView)
Render(aView)
- # Add path separator to the end of picture path if necessery
- if not picturedir.endswith(os.sep):
- picturedir += os.sep
prs_type = PrsTypeEnum.SCALARMAP
# Get name of presentation type
prs_name = PrsTypeEnum.get_name(prs_type)
f_prs_type = prs_name.replace(' ', '').upper()
# Construct image file name
- pic_name = picturedir + aFieldName + "_" + str(i) + "_" + f_prs_type + "." + pictureext
+ base_name = aFieldName + "_" + str(i) + "_" + f_prs_type + "." + pictureext
+ pic_name = os.path.join(picturedir, base_name)
# Show and record the presentation
process_prs_for_test(aPrs, aView, pic_name)
- (w,h) = get_png_picture_resolution(pic_name)
- sizesw.append(w)
- sizesh.append(h)
-
-# check sizes of pictures: width
-if abs(max(sizesw)-min(sizesw)) > 0:
- print "<b>ERROR!!! Pictures have different width !!!</b>";
- for i in range(1,11):
- picture_name = "time_stamp_"+str(i)+"."+pictureext
- print "Picture: "+picture_name+"; width : "+str(sizesw[i-1])
- raise RuntimeError
-
-# check sizes of pictures: height
-if abs(max(sizesh)-min(sizesh)) > 0:
- print "<b>WARNING!!! Pictures have different height !!!</b>";
- for i in range(1,11):
- picture_name = "time_stamp_"+str(i)+"."+pictureext
- print "Picture: "+picture_name+"; height : "+str(sizesh[i-1])
- raise RuntimeError
+ # Compare to baseline
+ current_dir = os.path.dirname(os.path.realpath(__file__))
+ baseline = os.path.join(current_dir, "_refs", base_name)
+ compare_view_to_ref_image(aView, baseline, threshold=1)
import getpass
from datetime import date
import struct
+import sys
# Auxiliary variables
pvsimple.Delete(tmp_obj)
def get_png_picture_resolution(infile):
- """Returns size (width, height) of the PNG image"""
- f = open(infile, 'rb')
+ """Returns size (width, height) of the PNG image"""
+ f = open(infile, 'rb')
data = f.read(24)
f.close()
if not (data[:8] == '\211PNG\r\n\032\n'and (data[12:16] == 'IHDR')):
height = int(h)
return (width,height)
-def save_trace(afile,atrace):
- """Saves atrace in afile"""
+def save_trace(afile,atrace):
+ """Saves atrace in afile"""
f = open(afile, 'w')
f.write(atrace)
f.close()
+
+def compare_view_to_ref_image(view, image_file, threshold=10):
+ import vtk.test.Testing
+ # warning: vtkGetTempDir looks at sys.argv contents...
+ save_sys_argv = sys.argv
+ sys.argv = []
+ vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
+
+ try:
+ vtk.test.Testing.compareImage(view.GetRenderWindow(),
+ image_file,
+ threshold=threshold)
+ vtk.test.Testing.interact()
+ except:
+ sys.argv = save_sys_argv
+ print "<b>ERROR!!! Pictures differs from reference image !!!</b>";
+ print "Picture: "+image_file
+ raise
+ pass
+ sys.argv = save_sys_argv