44import  mitsuba 
55
66
7- def  create_camera (o , d , fov = 34 , fov_axis = 'x' , s_open = 1.5 , s_close = 5 , xml_srf = "" ):
8-     from  mitsuba .core .xml  import  load_string 
9-     return  load_string (""" 
10-         <sensor version='2.0.0' type='perspective'> 
11-             <float name='near_clip' value='1'/> 
12-             <float name='far_clip' value='35'/> 
13-             <float name='focus_distance' value='15'/> 
14-             <float name='fov' value='{fov}'/> 
15-             <string name='fov_axis' value='{fov_axis}'/> 
16-             <float name='shutter_open' value='{so}'/> 
17-             <float name='shutter_close' value='{sc}'/> 
18-             <transform name="to_world"> 
19-                 <lookat origin="{ox}, {oy}, {oz}" 
20-                         target="{tx}, {ty}, {tz}" 
21-                         up    =" 0.0,  1.0,  0.0"/> 
22-             </transform> 
23-             <film type="hdrfilm"> 
24-                 <integer name="width" value="512"/> 
25-                 <integer name="height" value="256"/> 
26-             </film> 
27-             {srf} 
28-         </sensor>  
29-     """ .format (ox = o [0 ], oy = o [1 ], oz = o [2 ],
30-                tx = o [0 ] +  d [0 ], ty = o [1 ] +  d [1 ], tz = o [2 ] +  d [2 ],
31-                fov = fov , fov_axis = fov_axis , so = s_open , sc = s_close ,
32-                srf = xml_srf ))
7+ def  create_camera (o , d , fov = 34 , fov_axis = "x" , s_open = 1.5 , s_close = 5 , dict_srf = None ):
8+     from  mitsuba .core .xml  import  load_dict 
9+     from  mitsuba .core  import  Transform4f , Vector3f 
10+ 
11+     dict_camera  =  {
12+         "type" : "perspective" ,
13+         "near_clip" : 1.0 ,
14+         "far_clip" : 35.0 ,
15+         "focus_distance" : 15.0 ,
16+         "to_world" : Transform4f .look_at (
17+             origin = Vector3f (o ),
18+             target = Vector3f (o ) +  Vector3f (d ),
19+             up = [0 , 1 , 0 ]
20+         ),
21+         "fov" : fov ,
22+         "fov_axis" : fov_axis ,
23+         "shutter_open" : s_open ,
24+         "shutter_close" : s_close ,
25+         "film" : {
26+             "type" : "hdrfilm" ,
27+             "width" : 512 ,
28+             "height" : 256 ,
29+         }
30+     }
31+ 
32+     if  dict_srf :
33+         dict_camera ["srf" ] =  dict_srf 
34+ 
35+     print (dict_camera )
36+ 
37+     return  load_dict (dict_camera )
3338
3439
3540origins  =  [[1.0 , 0.0 , 1.5 ], [1.0 , 4.0 , 1.5 ]]
@@ -165,40 +170,41 @@ def check_fov(camera, sample):
165170        check_fov (camera , sample )
166171
167172
168- xml_srf_dict  =  {
173+ dicts_srf  =  {
169174    # Uniform SRF covering full spectral range 
170-     "uniform_full" : """ 
171-         <spectrum version="2.0.0" name="srf" type=" uniform">  
172-             <float name= "value" value="1"/>  
173-         </spectrum>"""  ,
175+     "uniform_full" : { 
176+         "type" :  " uniform", 
177+         "value" :  1 
178+     } ,
174179    # Uniform SRF covering the [400, 700] nm spectral range 
175-     "uniform_restricted" : """ 
176-         <spectrum version="2.0.0" name="srf" type="uniform"> 
177-             <float name="value" value="1"/> 
178-             <float name="lambda_min" value="400"/> 
179-             <float name="lambda_max" value="700"/> 
180-         </spectrum>""" ,
180+     "uniform_restricted" : {
181+         "type" : "uniform" ,
182+         "value" : 1 ,
183+         "lambda_min" : 400 ,
184+         "lambda_max" : 700 
185+ 
186+     },
181187    # Uniform SRF covering full spectral range, not equal to 1 
182-     "uniform_scaled" : """ 
183-         <spectrum version="2.0.0" name="srf" type=" uniform">  
184-             <float name= "value" value="2"/>  
185-         </spectrum>"""  , 
188+     "uniform_scaled" : { 
189+         "type" :  " uniform", 
190+         "value" :  2 
191+     } 
186192}
187193
188194
189- @pytest .mark .parametrize ("srf" , list (xml_srf_dict .keys ())) 
195+ @pytest .mark .parametrize ("srf" , list (dicts_srf .keys ())) 
190196def  test_srf (variant_scalar_spectral , srf ):
191197    # Test the spectral response function specification feature 
192-     from  mitsuba .core .xml  import  load_string 
198+     from  mitsuba .core .xml  import  load_dict 
193199    from  mitsuba .core  import  sample_shifted 
194200    from  mitsuba .render  import  SurfaceInteraction3f 
195201
196202    origin  =  [0 , 0 , 0 ]
197203    direction  =  [0 , 0 , 1 ]
198-     xml_srf  =  xml_srf_dict [srf ]
204+     dict_srf  =  dicts_srf [srf ]
199205
200-     camera  =  create_camera (origin , direction , xml_srf = xml_srf )
201-     srf  =  load_string ( xml_srf )
206+     camera  =  create_camera (origin , direction , dict_srf = dict_srf )
207+     srf  =  load_dict ( dict_srf )
202208    time  =  0.5 
203209    wav_sample  =  0.5 
204210    pos_sample  =  [0.2 , 0.6 ]
@@ -208,7 +214,8 @@ def test_srf(variant_scalar_spectral, srf):
208214
209215    # Importance sample wavelength and weight 
210216    print (sample_shifted (wav_sample ))
211-     wav , wav_weight  =  srf .sample (SurfaceInteraction3f (), sample_shifted (wav_sample ))
217+     wav , wav_weight  =  srf .sample (
218+         SurfaceInteraction3f (), sample_shifted (wav_sample ))
212219    print (wav )
213220
214221    assert  ek .allclose (ray .wavelengths , wav )
0 commit comments