4040class TestSHWDeepImageReader ( unittest .TestCase ) :
4141
4242 __shw = "test/IECoreRI/data/shw/translucentBoxes.shw"
43+ __shwConstantPlane = "test/IECoreRI/data/shw/constantPlane.shw"
44+ __shwConstantPlane2 = "test/IECoreRI/data/shw/constantPlane2.shw"
45+ __shwOrtho = "test/IECoreRI/data/shw/constantPlaneOrtho.shw"
46+
4347 __exr = "test/IECoreRI/data/shw/groundPlane.exr"
4448
4549 def testConstructor ( self ) :
@@ -113,16 +117,16 @@ def testReadPixel( self ) :
113117 p = reader .readPixel ( 100 , 100 )
114118 self .assertEqual ( p .channelNames (), ( "A" , ) )
115119 self .assertEqual ( p .numSamples (), 1 )
116- self .assertAlmostEqual ( p .getDepth ( 0 ), 107.5978927 , 6 )
120+ self .assertAlmostEqual ( p .getDepth ( 0 ), 102.17636108 , 6 )
117121 self .assertAlmostEqual ( p [0 ][0 ], 1.0 , 6 )
118122
119123 # hits one box then ground plane
120124 p2 = reader .readPixel ( 256 , 256 )
121125 self .assertEqual ( p2 .channelNames (), tuple (reader .channelNames ()) )
122126 self .assertEqual ( p2 .numSamples (), 3 )
123- self .assertAlmostEqual ( p2 .getDepth ( 0 ), 71.7940826 , 6 )
124- self .assertAlmostEqual ( p2 .getDepth ( 1 ), 76.9240646 , 6 )
125- self .assertAlmostEqual ( p2 .getDepth ( 2 ), 84.8475646 , 6 )
127+ self .assertAlmostEqual ( p2 .getDepth ( 0 ), 72.6087493 , 6 )
128+ self .assertAlmostEqual ( p2 .getDepth ( 1 ), 77.7387313 , 6 )
129+ self .assertAlmostEqual ( p2 .getDepth ( 2 ), 85.6622314 , 6 )
126130
127131 expected = ( 0.5 , 0.5 , 1.0 )
128132 for i in range ( 0 , len (expected ) ) :
@@ -132,11 +136,11 @@ def testReadPixel( self ) :
132136 p3 = reader .readPixel ( 195 , 225 )
133137 self .assertEqual ( p3 .channelNames (), tuple (reader .channelNames ()) )
134138 self .assertEqual ( p3 .numSamples (), 5 )
135- self .assertAlmostEqual ( p3 .getDepth ( 0 ), 68.2118148 , 6 )
136- self .assertAlmostEqual ( p3 .getDepth ( 1 ), 74.9367370 , 6 )
137- self .assertAlmostEqual ( p3 .getDepth ( 2 ), 77.0554046 , 6 )
138- self .assertAlmostEqual ( p3 .getDepth ( 3 ), 79.7311859 , 6 )
139- self .assertAlmostEqual ( p3 .getDepth ( 4 ), 88.5616073 , 6 )
139+ self .assertAlmostEqual ( p3 .getDepth ( 0 ), 68.6177368 , 6 )
140+ self .assertAlmostEqual ( p3 .getDepth ( 1 ), 75.3023605 , 6 )
141+ self .assertAlmostEqual ( p3 .getDepth ( 2 ), 77.4083328 , 6 )
142+ self .assertAlmostEqual ( p3 .getDepth ( 3 ), 80.0680771 , 6 )
143+ self .assertAlmostEqual ( p3 .getDepth ( 4 ), 88.8455811 , 6 )
140144
141145 expected = ( 0.5 , 0.75 , 0.5 , 0.5 , 1.0 )
142146 for i in range ( 0 , len (expected ) ) :
@@ -170,5 +174,31 @@ def testComposite( self ) :
170174 for i in range ( imageData .size () ) :
171175 self .assertAlmostEqual ( imageData [i ], realImageData [i ], 6 )
172176
177+ def __testDepthConversionWithFile ( self , filename , tolerance ) :
178+
179+ reader = IECore .DeepImageReader .create ( filename )
180+ dataWindow = reader .dataWindow ()
181+
182+ for y in range ( dataWindow .min .y , dataWindow .max .y + 1 ) :
183+ for x in range ( dataWindow .min .x , dataWindow .max .x + 1 ) :
184+ p = reader .readPixel ( x , y )
185+ s = p .numSamples ()
186+ avgDepth = 0
187+ for i in range ( s ):
188+ avgDepth += p .getDepth ( i ) / s
189+ self .assertAlmostEqual ( avgDepth , 10 , tolerance )
190+
191+ def testDepthConversion ( self ) :
192+
193+ # The first constant plane test is rendered with a single sample, and no jittering, so the depth should match to 6 significant digits
194+ self .__testDepthConversionWithFile ( TestSHWDeepImageReader .__shwConstantPlane , 4 )
195+
196+ # The second constant plane was rendered with a small number of jittered samples, and because of the low resolution, there is quite a bit
197+ # of variation in the correction factor across the pixel, so it won't be a perfect match, but it should still be close
198+ self .__testDepthConversionWithFile ( TestSHWDeepImageReader .__shwConstantPlane2 , 2 )
199+
200+ # Test out an ortho render as well
201+ self .__testDepthConversionWithFile ( TestSHWDeepImageReader .__shwOrtho , 2 )
202+
173203if __name__ == "__main__" :
174204 unittest .main ()
0 commit comments