[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30062] branches/soc-2010-leifandersen/ tests: 1.

Leif Andersen leif.a.andersen at gmail.com
Wed Jul 7 01:28:23 CEST 2010


Revision: 30062
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30062
Author:   leifandersen
Date:     2010-07-07 01:28:23 +0200 (Wed, 07 Jul 2010)

Log Message:
-----------
1.  Am about 75% of the way through implementing animations in the image diff class, I think.

2.  Realized that the image diffs that the physics render tests relied on didn't have the needed images in the working copy, so I added the tests.

Modified Paths:
--------------
    branches/soc-2010-leifandersen/tests/render/run.py

Added Paths:
-----------
    branches/soc-2010-leifandersen/tests/pyunit/ops/physics/render/cube_hair_group.png
    branches/soc-2010-leifandersen/tests/pyunit/ops/physics/render/cube_hair_object.png

Added: branches/soc-2010-leifandersen/tests/pyunit/ops/physics/render/cube_hair_group.png
===================================================================
(Binary files differ)


Property changes on: branches/soc-2010-leifandersen/tests/pyunit/ops/physics/render/cube_hair_group.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: branches/soc-2010-leifandersen/tests/pyunit/ops/physics/render/cube_hair_object.png
===================================================================
(Binary files differ)


Property changes on: branches/soc-2010-leifandersen/tests/pyunit/ops/physics/render/cube_hair_object.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: branches/soc-2010-leifandersen/tests/render/run.py
===================================================================
--- branches/soc-2010-leifandersen/tests/render/run.py	2010-07-06 21:19:01 UTC (rev 30061)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-07-06 23:28:23 UTC (rev 30062)
@@ -40,6 +40,9 @@
     difference = None
     message = ""
     ID = None
+    
+    def __init__(self, blend_path, good_path, test_path):
+        self.__init(self, ID, blend_path, good_path, test_path)
 
     def __init__(self, ID, blend_path, good_path, test_path):
         '''Sets up a test case, with the blend_path, the known good path, and the test path
@@ -49,12 +52,33 @@
             self.ID = ID
         else:
             self.ID = 'FAIL'
-        self.blend_path = blend_path
-        self.good_path = good_path
         self.name = os.path.split(blend_path)[1]
-        self.good_image = Image.open(good_path)
-        self.test_path = test_path
+        if self.ID == 'Image':
+            self.good_image = Image.open(good_path)
+            self.blend_path = blend_path
+            self.good_path = good_path
+            self.test_path = test_path
+        if self.ID == 'Animation':
+            self.good_path = []
+            self.good_image = []
+            self.test_path = []
 
+            (good_directory, good_file) = os.path.split(blend_path)
+            (test_directroy, test_file) = os.path.split(blend_path)
+            i=1
+            for imagename in os.listdir(good_directory):
+                self.good_path.append(os.path.join(good_directory, string.replace(self.name, '.blend', '_' + self.format_frame(i) + '.blend')
+                im = Image.open(imagename)
+                self.good_image.append(im)
+                self.test_path.append(os.path.join(test_directory, string.replace(self.name, '.blend', '_' + self.format_frame(i) + 'blend'))
+                i+=1
+
+    def format_frame(self, num)
+        frame_num = str(num)
+        while len(frame_num) < 4:
+            frame_num+='0'
+        return frame_num
+
     def render_image(self):
         '''Renders a single image of the first frame of the blend file.
             Also changes output_path slightly'''
@@ -62,7 +86,7 @@
         os.system(command)
         self.test_path += '_0001.png'
         try:
-           self.test_image = Image.open(self.test_path)
+            self.test_image = Image.open(self.test_path)
         except IOError:
             self.ID = 'Fail'
             self.test_image = None
@@ -75,11 +99,15 @@
             self.message = "Failed to render"
 
     def render_anim(self):
-        command = BLENDER_BIN + " -b " + self.blend_path + " -o " + self.test_path + "_#### -F PNG -x 1 -a"
+        ''''''
+        command = BLENDER_BIN + " -b " + self.blend_path + " -o " + string.replace(self.test_path[0], '_0001.png', '') + "_#### -F PNG -x 1 -a"
         os.system(command)
 
         try:
-           self.test_image = Image.open(self.test_path)
+            self.test_image = []
+            for imagename in self.test_path:
+                im = Image.open(imagename)
+                self.test_image.append(im)
         except IOError:
             self.test_image = None
             self.passed = False
@@ -93,23 +121,32 @@
     def setup_test(self):
         '''Runs the test, filling in all of the usefull fields'''
         if self.test_image != None:
-            self.diff_sum = 0
-            self.diff_image = ImageChops.difference(self.good_image, self.test_image)
-            self.bad_pixels = 0
-            self.pixel_range = len(self.diff_image.histogram())
-            self.pixel_count = self.diff_image.size[0] * self.diff_image.size[1]
-            for i in range(0,self.diff_image.size[0]):
-                for j in range(0, self.diff_image.size[1]):
-                    p = self.diff_image.getpixel((i,j))
-                    self.diff_sum+= p[0] + p[1] + p[2]
-                    if p[0] + p[1] + p[2] > 10:
-                        self.bad_pixels+=1
-            self.difference = float(self.diff_sum)/float(self.pixel_range*self.pixel_count)
-            if self.bad_pixels < self.pixel_count/5 and self.difference < 0.01:
-                self.passed = True
-            else:
-                self.passed = False
-            return self.passed
+            if ID == 'Image':
+                self.diff_sum = 0
+                self.diff_image = ImageChops.difference(self.good_image, self.test_image)
+                self.bad_pixels = 0
+                self.pixel_range = len(self.diff_image.histogram())
+                self.pixel_count = self.diff_image.size[0] * self.diff_image.size[1]
+                for i in range(0,self.diff_image.size[0]):
+                    for j in range(0, self.diff_image.size[1]):
+                        p = self.diff_image.getpixel((i,j))
+                        self.diff_sum+= p[0] + p[1] + p[2]
+                        if p[0] + p[1] + p[2] > 10:
+                            self.bad_pixels+=1
+                self.difference = float(self.diff_sum)/float(self.pixel_range*self.pixel_count)
+                if self.bad_pixels < self.pixel_count/5 and self.difference < 0.01:
+                    self.passed = True
+                else:
+                    self.passed = False
+                return self.passed
+            if ID == 'Animation':
+                self.diff_sum = []
+                self.bad_pixels = []
+                
+                self.diff_image = []
+                i= 0
+                for diff_image in self.good_image:
+                    self.diff_image.append(ImageChops.difference(self.good_image, self.test_image))
 
     def save_diff(self, output_path):
         '''Saves the diff image to output_path'''
@@ -118,7 +155,8 @@
                 self.diff_path = output_path
                 self.diff_image.save(output_path)
             if self.ID == 'Animation':
-                self.diff_path = output_path
+                self.diff_path []
+                (diff_directory, diff_file) = os.path.split(output_path)
                 i = 1
                 for image in self.diff_image:
                     self.diff_image.save(output_path + '_diff_' + i + '.png')
@@ -237,9 +275,9 @@
     for frame in animation.test_image:
         file.write('<tr>\n')
         file.write('<td>' + i + '</td>\n')
-        file.write('<td><a href="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '"><img src="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '" alt="Good Image" width="200" height="150"></a></td>\n')
-        file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '" alt="Latest Render" width="200" height="150"></a></td>\n')
-        file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '" alt="Image Diff" width="200" height="150"></a></td>\n')
+        file.write('<td><a href="' + os.path.join('render', string.replace(animation.name, '.blend', '_000' + i + '.png')) + '"><img src="' + os.path.join('render', string.replace(animation.name, '.blend', '_000' + i + '.png')) + '" alt="Good Image" width="200" height="150"></a></td>\n')
+        file.write('<td><a href="' + os.path.join('output', string.replace(animation.name, '.blend', '_000' + i + '.png')) + '"><img src="' + os.path.join('output', string.replace(animation.name, '.blend', '_000' + i + '.png')) + '" alt="Latest Render" width="200" height="150"></a></td>\n')
+        file.write('<td><a href="' + os.path.join('output', string.replace(animation.name, '.blend', '_diff_000' + i + '.png')) + '"><img src="' + os.path.join('output', string.replace(animation.name, '.blend', '_diff_000' + i + '.png')) + '" alt="Image Diff" width="200" height="150"></a></td>\n')
         
         file.write('</tr>\n')
         i+=1





More information about the Bf-blender-cvs mailing list