pbrt_r3/core/api/
debug_context.rs

1use super::parse_context::*;
2use crate::core::base::*;
3use crate::core::param_set::*;
4use std::cell::{Cell, RefCell};
5
6pub struct Operation {
7    pub name: String,
8    pub args: Vec<String>,
9}
10
11impl Operation {
12    pub fn new(op: &str, args: &[String]) -> Self {
13        Operation {
14            name: op.to_string(),
15            args: args.to_vec(),
16        }
17    }
18}
19
20#[derive(Default)]
21pub struct DebugContext {
22    pub operations: RefCell<Vec<Operation>>,
23    pub indent: Cell<i32>,
24}
25
26impl DebugContext {
27    pub fn new() -> Self {
28        DebugContext {
29            operations: RefCell::<Vec<Operation>>::new(Vec::<Operation>::new()),
30            indent: Cell::<i32>::new(0),
31        }
32    }
33    pub fn inc_indent(&mut self) {
34        self.indent.set(self.indent.get() + 1);
35    }
36    pub fn dec_indent(&mut self) {
37        self.indent.set(self.indent.get() - 1);
38    }
39
40    pub fn get_indent(&self) -> String {
41        let mut s = String::new();
42        let count = self.indent.get();
43        for _ in 0..count {
44            s += "    ";
45        }
46        return s;
47    }
48}
49
50impl ParseContext for DebugContext {
51    fn pbrt_cleanup(&mut self) {
52        println!("{}pbrt_cleanup", self.get_indent());
53        let v = vec![];
54        self.operations
55            .borrow_mut()
56            .push(Operation::new("Cleanup", &v));
57    }
58    fn pbrt_identity(&mut self) {
59        println!("{}pbrt_identity", self.get_indent());
60        let v = vec![String::from("")];
61        self.operations
62            .borrow_mut()
63            .push(Operation::new("Identitiy", &v));
64    }
65    fn pbrt_translate(&mut self, dx: Float, dy: Float, dz: Float) {
66        println!("{}pbrt_translate:[{dx}, {dy}, {dz}]", self.get_indent());
67        let v = vec![String::from("")];
68        self.operations
69            .borrow_mut()
70            .push(Operation::new("Translate", &v));
71    }
72    fn pbrt_rotate(&mut self, angle: Float, ax: Float, ay: Float, az: Float) {
73        println!(
74            "{}pbrt_rotate:[{angle}, {ax}, {ay}, {az}]",
75            self.get_indent()
76        );
77        let v = vec![String::from("")];
78        self.operations
79            .borrow_mut()
80            .push(Operation::new("Rotate", &v));
81    }
82    fn pbrt_scale(&mut self, sx: Float, sy: Float, sz: Float) {
83        println!("{}pbrt_scale:[{sx}, {sy}, {sz}]", self.get_indent());
84        let v = vec![String::from("")];
85        self.operations
86            .borrow_mut()
87            .push(Operation::new("Scale", &v));
88    }
89    fn pbrt_look_at(
90        &mut self,
91        ex: Float,
92        ey: Float,
93        ez: Float,
94        lx: Float,
95        ly: Float,
96        lz: Float,
97        ux: Float,
98        uy: Float,
99        uz: Float,
100    ) {
101        println!(
102            "{}pbrt_look_at:[{ex}, {ey}, {ez}, {lx}, {ly}, {lz}, {ux}, {uy}, {uz}]",
103            self.get_indent()
104        );
105        let v = vec![String::from("")];
106        self.operations
107            .borrow_mut()
108            .push(Operation::new("LookAt", &v));
109    }
110
111    fn pbrt_concat_transform(&mut self, _tansform: &[Float]) {
112        println!("{}pbrt_concat_transform", self.get_indent());
113        let v = vec![String::from("")];
114        self.operations
115            .borrow_mut()
116            .push(Operation::new("ConcatTransform", &v));
117    }
118    fn pbrt_transform(&mut self, _tansform: &[Float]) {
119        println!("{}pbrt_transform", self.get_indent());
120        let v = vec![String::from("")];
121        self.operations
122            .borrow_mut()
123            .push(Operation::new("Transform", &v));
124    }
125    fn pbrt_coordinate_system(&mut self, name: &str) {
126        println!("{}pbrt_coordinate_system:\"{name}\"", self.get_indent());
127        let v = vec![String::from(name)];
128        self.operations
129            .borrow_mut()
130            .push(Operation::new("CoordinateSystem", &v));
131    }
132    fn pbrt_coord_sys_transform(&mut self, name: &str) {
133        println!("{}pbrt_coord_sys_transform:\"{name}\"", self.get_indent());
134        let v = vec![String::from(name)];
135        self.operations
136            .borrow_mut()
137            .push(Operation::new("CoordSysTransform", &v));
138    }
139    fn pbrt_active_transform_all(&mut self) {
140        println!("{}pbrt_active_transform_all", self.get_indent());
141        let v = vec![String::from("")];
142        self.operations
143            .borrow_mut()
144            .push(Operation::new("ActiveTransformAll", &v));
145    }
146    fn pbrt_active_transform_end_time(&mut self) {
147        println!("{}pbrt_active_transform_end_time", self.get_indent());
148        let v = vec![String::from("")];
149        self.operations
150            .borrow_mut()
151            .push(Operation::new("ActiveTransformEndTime", &v));
152    }
153    fn pbrt_active_transform_start_time(&mut self) {
154        println!("{}pbrt_active_transform_start_time", self.get_indent());
155        let v = vec![String::from("")];
156        self.operations
157            .borrow_mut()
158            .push(Operation::new("ActiveTransformStartTime", &v));
159    }
160    fn pbrt_transform_times(&mut self, _start: Float, _end: Float) {
161        println!("{}pbrt_transform_times", self.get_indent());
162        let v = vec![String::from("")];
163        self.operations
164            .borrow_mut()
165            .push(Operation::new("TransformTimes", &v));
166    }
167    fn pbrt_pixel_filter(&mut self, name: &str, _params: &ParamSet) {
168        println!("{}pbrt_pixel_filter:\"{name}\"", self.get_indent());
169        let v = vec![String::from(name)];
170        self.operations
171            .borrow_mut()
172            .push(Operation::new("PixelFilter", &v));
173    }
174    fn pbrt_film(&mut self, name: &str, _params: &ParamSet) {
175        println!("{}pbrt_film:\"{name}\"", self.get_indent());
176        let v = vec![String::from(name)];
177        self.operations
178            .borrow_mut()
179            .push(Operation::new("Film", &v));
180    }
181    fn pbrt_sampler(&mut self, name: &str, _params: &ParamSet) {
182        println!("{}pbrt_sampler:\"{name}\"", self.get_indent());
183        let v = vec![String::from(name)];
184        self.operations
185            .borrow_mut()
186            .push(Operation::new("Sampler", &v));
187    }
188    fn pbrt_accelerator(&mut self, name: &str, _params: &ParamSet) {
189        println!("{}pbrt_accelerator:\"{name}\"", self.get_indent());
190        let v = vec![String::from(name)];
191        self.operations
192            .borrow_mut()
193            .push(Operation::new("Accelerator", &v));
194    }
195    fn pbrt_integrator(&mut self, name: &str, _params: &ParamSet) {
196        println!("{}pbrt_integrator:\"{name}\"", self.get_indent());
197        let v = vec![String::from(name)];
198        self.operations
199            .borrow_mut()
200            .push(Operation::new("Integrator", &v));
201    }
202    fn pbrt_camera(&mut self, name: &str, _params: &ParamSet) {
203        println!("{}pbrt_camera:\"{name}\"", self.get_indent());
204        let v = vec![String::from("")];
205        self.operations
206            .borrow_mut()
207            .push(Operation::new("Camera", &v));
208    }
209    fn pbrt_make_named_medium(&mut self, name: &str, _params: &ParamSet) {
210        println!("{}pbrt_make_named_medium:\"{name}\"", self.get_indent());
211        let v = vec![String::from("")];
212        self.operations
213            .borrow_mut()
214            .push(Operation::new("NamedMedium", &v));
215    }
216    fn pbrt_medium_interface(&mut self, inside_name: &str, outside_name: &str) {
217        println!(
218            "{}pbrt_medium_interface:\"{inside_name}\", \"{outside_name}\"",
219            self.get_indent()
220        );
221        let v = vec![String::from("")];
222        self.operations
223            .borrow_mut()
224            .push(Operation::new("MediumInterface", &v));
225    }
226    fn pbrt_world_begin(&mut self) {
227        println!("{}pbrt_world_begin", self.get_indent());
228        let v = vec![String::from("")];
229        self.operations
230            .borrow_mut()
231            .push(Operation::new("WorldBegin", &v));
232        self.inc_indent();
233    }
234    fn pbrt_attribute_begin(&mut self) {
235        println!("{}pbrt_attribute_begin", self.get_indent());
236        let v = vec![String::from("")];
237        self.operations
238            .borrow_mut()
239            .push(Operation::new("AttributeBegin", &v));
240        self.inc_indent();
241    }
242    fn pbrt_attribute_end(&mut self) {
243        self.dec_indent();
244        println!("{}pbrt_attribute_end", self.get_indent());
245        let v = vec![String::from("")];
246        self.operations
247            .borrow_mut()
248            .push(Operation::new("AttributeEnd", &v));
249    }
250    fn pbrt_transform_begin(&mut self) {
251        println!("{}pbrt_transform_begin", self.get_indent());
252        let v = vec![String::from("")];
253        self.operations
254            .borrow_mut()
255            .push(Operation::new("TransformBegin", &v));
256        self.inc_indent();
257    }
258    fn pbrt_transform_end(&mut self) {
259        self.dec_indent();
260        println!("{}pbrt_transform_end", self.get_indent());
261        let v = vec![String::from("")];
262        self.operations
263            .borrow_mut()
264            .push(Operation::new("TransformEnd", &v));
265    }
266    fn pbrt_texture(&mut self, name: &str, t: &str, tex_name: &str, _params: &ParamSet) {
267        println!(
268            "{}pbrt_texture:\"{}\", \"{}\", \"{}\"",
269            self.get_indent(),
270            name,
271            t,
272            tex_name
273        );
274        let v = vec![String::from("")];
275        self.operations
276            .borrow_mut()
277            .push(Operation::new("Texture", &v));
278    }
279    fn pbrt_material(&mut self, name: &str, _params: &ParamSet) {
280        println!("{}pbrt_material:\"{name}\"", self.get_indent());
281        let v = vec![String::from(name)];
282        self.operations
283            .borrow_mut()
284            .push(Operation::new("Material", &v));
285    }
286    fn pbrt_make_named_material(&mut self, name: &str, _params: &ParamSet) {
287        println!("{}pbrt_make_named_material:\"{name}\"", self.get_indent());
288        let v = vec![String::from(name)];
289        self.operations
290            .borrow_mut()
291            .push(Operation::new("MakeNamedMaterial", &v));
292    }
293    fn pbrt_named_material(&mut self, name: &str) {
294        println!("{}pbrt_named_material:\"{name}\"", self.get_indent());
295        let v = vec![String::from("")];
296        self.operations
297            .borrow_mut()
298            .push(Operation::new("NamedMaterial", &v));
299    }
300    fn pbrt_light_source(&mut self, name: &str, _params: &ParamSet) {
301        println!("{}pbrt_light_source:\"{name}\"", self.get_indent());
302        let v = vec![String::from(name)];
303        self.operations
304            .borrow_mut()
305            .push(Operation::new("LightSource", &v));
306    }
307    fn pbrt_area_light_source(&mut self, name: &str, _params: &ParamSet) {
308        println!("{}pbrt_area_light_source:\"{name}\"", self.get_indent());
309        let v = vec![String::from(name)];
310        self.operations
311            .borrow_mut()
312            .push(Operation::new("AreaLightSource", &v));
313    }
314    fn pbrt_shape(&mut self, name: &str, _params: &ParamSet) {
315        println!("{}pbrt_shape:\"{name}\"", self.get_indent());
316        let v = vec![String::from(name)];
317        self.operations
318            .borrow_mut()
319            .push(Operation::new("Shape", &v));
320    }
321    fn pbrt_reverse_orientation(&mut self) {
322        println!("{}pbrt_reverse_orientation", self.get_indent());
323        let v = vec![String::from("")];
324        self.operations
325            .borrow_mut()
326            .push(Operation::new("ReverseOrientation", &v));
327    }
328    fn pbrt_object_begin(&mut self, name: &str) {
329        println!("{}pbrt_object_begin:\"{name}\"", self.get_indent());
330        let v = vec![String::from(name)];
331        self.operations
332            .borrow_mut()
333            .push(Operation::new("ObjectBegin", &v));
334        self.inc_indent();
335    }
336    fn pbrt_object_end(&mut self) {
337        self.dec_indent();
338        println!("{}pbrt_object_end", self.get_indent());
339        let v = vec![String::from("")];
340        self.operations
341            .borrow_mut()
342            .push(Operation::new("ObjectEnd", &v));
343    }
344    fn pbrt_object_instance(&mut self, name: &str) {
345        println!("{}pbrt_object_instance:\"{name}\"", self.get_indent());
346        let v = vec![String::from(name)];
347        self.operations
348            .borrow_mut()
349            .push(Operation::new("ObjectInstance", &v));
350    }
351    fn pbrt_world_end(&mut self) {
352        self.dec_indent();
353        println!("{}pbrt_world_end", self.get_indent());
354        let v = vec![String::from("")];
355        self.operations
356            .borrow_mut()
357            .push(Operation::new("WorldEnd", &v));
358    }
359    fn pbrt_parse_file(&mut self, file_name: &str) {
360        println!("{}pbrt_parse_file:\"{file_name}\"", self.get_indent());
361        let v = vec![String::from("")];
362        self.operations
363            .borrow_mut()
364            .push(Operation::new("ParseFile", &v));
365    }
366    fn pbrt_parse_string(&mut self, _s: &str) {
367        println!("{}pbrt_parse_string", self.get_indent());
368        let v = vec![String::from("")];
369        self.operations
370            .borrow_mut()
371            .push(Operation::new("ParseString", &v));
372    }
373
374    fn pbrt_work_dir_begin(&mut self, path: &str) {
375        println!("{}pbrt_work_dir_begin:\"{path}\"", self.get_indent());
376        let v = vec![String::from(path)];
377        self.operations
378            .borrow_mut()
379            .push(Operation::new("WorkDirBegin", &v));
380    }
381
382    fn pbrt_work_dir_end(&mut self) {
383        println!("{}pbrt_work_dir_end", self.get_indent());
384        let v = vec![String::from("")];
385        self.operations
386            .borrow_mut()
387            .push(Operation::new("WorkDirEnd", &v));
388    }
389
390    fn pbrt_include(&mut self, filename: &str, _params: &ParamSet) {
391        println!("{}pbrt_include:\"{filename}\"", self.get_indent());
392        let v = vec![String::from(filename)];
393        self.operations
394            .borrow_mut()
395            .push(Operation::new("Include", &v));
396    }
397}