/
Scene.h
768 lines (609 loc) · 29.8 KB
/
Scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
// ======================================================================== //
// Copyright 2015-2019 Ingo Wald //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
// You may obtain a copy of the License at //
// //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
// Unless required by applicable law or agreed to in writing, software //
// distributed under the License is distributed on an "AS IS" BASIS, //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and //
// limitations under the License. //
// ======================================================================== //
#pragma once
/*! \file pbrt/sytax/Scene.h Defines the root pbrt scene - at least
the *syntactci* part of it - to be created/parsed by this parser */
#include "pbrtParser/math.h"
// stl
#include <map>
#include <vector>
#include <string>
#include <memory>
#include <assert.h>
/*! namespace for all things pbrt parser, both syntactical *and* semantical parser */
namespace pbrt {
/*! namespace for syntax-only parser - this allows to distringuish
high-level objects such as shapes from objects or transforms,
but does *not* make any difference between what types of
shapes, what their parameters mean, etc. Basically, at this
level a triangle mesh is nothing but a shape that has a string
with a given name, and parameters of given names and types */
namespace syntactic {
/*! @{ forward definitions so we can use those in shared_ptrs in the attribute class */
struct AreaLightSource;
struct LightSource;
struct Object;
struct Material;
struct Medium;
struct Texture;
/* @} */
/*! the PBRT_PARSER_VECTYPE_NAMESPACE #define allows the
application/user to override the 'internal' vec3f, vec3i, and
affine3f classes with whatever the application wants us to
use.
- if PBRT_PARSER_VECTYPE_NAMESPACE is _not defined_, we will
define our own pbrt::syntactic::vec3f, pbrt::syntactic::vec3i, and
pbrt::syntactic::affine3f types as plain structs. Vec3i and vec3f
are three 32-bit ints and floats, respectively, and affine3f is
a 4xvec3f matrix as defined below.
- if PBRT_PARSER_VECTYPE_NAMESPACE _is_ defined, we will instead
use the types vec3f,vec3i,affine3f in the namespace as supplied
through this macro. Eg, if PBRT_PARSER_VECTYPE_NAMESPACE is set
to "myveclib" we will be usign the types myveclib::vec3f,
myveclib::vec3i, etc. For this to work, the following conditions
ahve to be fulfilled:
1) the given naemsapce has to contain all three type names:
vec3f, vec3i, and affine3f. (though note that with the C++-11
"using" statement you can alias these to whatevr you like (e.g.,
if your vector class is called Vec3f or float3, you can simply
add a "using vec3f = Vec3f;" resp "using vec3f =
anyOtherNameSpace::float3", etc; and since these are aliased to
the same type you can continue to use them in your own
aplication as you see fit).
2) these types _have_ to be binary compatible with the fallback
types we wold be using otherwise (ie, 3 floats for vec3f,
4xvec3f for an affine3f, etc. The reason behind this is that the
library itself internally uses this binary layout, so making the
app use a different data layout will create trouble
*/
using vec2f = math::vec2f;
using vec3f = math::vec3f;
using vec4f = math::vec4f;
using vec2i = math::vec2i;
using vec3i = math::vec3i;
using vec4i = math::vec4i;
using affine3f = math::affine3f;
using box3f = math::box3f;
using pairNf = math::pairNf;
/*! start-time and end-time transform - PBRT allows for specifying
transform at both 'start' and 'end' time, to allow for linear
motion */
struct Transform {
affine3f atStart;
affine3f atEnd;
};
class PBRT_PARSER_INTERFACE Attributes {
public:
// NOT copyable!
Attributes() = default;
Attributes(const Attributes&) = delete;
Attributes& operator=(const Attributes&) = delete;
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Attributes> SP;
/*! Save the current graphics state and initialize a new one */
static void push(Attributes::SP& graphicsState) {
Attributes::SP newGraphicsState = std::make_shared<Attributes>();
newGraphicsState->areaLightSources = graphicsState->areaLightSources;
newGraphicsState->mediumInterface = graphicsState->mediumInterface;
newGraphicsState->reverseOrientation = graphicsState->reverseOrientation;
newGraphicsState->parent = graphicsState;
graphicsState = newGraphicsState;
}
/*! Restore the parent graphics state */
static void pop(Attributes::SP& graphicsState) {
if (!graphicsState)
throw std::runtime_error("Invalid graphics state");
graphicsState = graphicsState->parent;
}
/*! Freeze the current graphics state so that it won't be affected
by subsequent changes. Returns the frozen graphics state */
static Attributes::SP freeze(Attributes::SP& graphicsState) {
#if 1
// iw - this CLONES the state, else I get stack overflow in
// destructor chain: for pbrt-v3-scenes/straight-hair.pbrt i
// get 1M hair shapes, and the shapes::clear() then triggers
// what looks like an infinite (or at least,
// too-deep-for-the-stack) chain of Attribute::~Attribute
// calls.
Attributes::SP newGraphicsState = std::make_shared<Attributes>();
newGraphicsState->areaLightSources = graphicsState->areaLightSources;
newGraphicsState->mediumInterface = graphicsState->mediumInterface;
newGraphicsState->reverseOrientation = graphicsState->reverseOrientation;
newGraphicsState->parent = graphicsState->parent;
newGraphicsState->prev = graphicsState;
return newGraphicsState;
#else
// iw, 1/1/20 - this is the code szellman adde to avoid
// un-necessary clones
Attributes::SP newGraphicsState = std::make_shared<Attributes>();
newGraphicsState->areaLightSources = graphicsState->areaLightSources;
newGraphicsState->mediumInterface = graphicsState->mediumInterface;
newGraphicsState->reverseOrientation = graphicsState->reverseOrientation;
newGraphicsState->parent = graphicsState->parent;
newGraphicsState->prev = graphicsState;
Attributes::SP oldGraphicsState = graphicsState;
graphicsState = newGraphicsState;
return oldGraphicsState;
#endif
}
/*! Insert named material */
void insertNamedMaterial(std::string name, std::shared_ptr<Material> material) {
namedMaterial[name] = material;
}
/*! Insert named medium */
void insertNamedMedium(std::string name, std::shared_ptr<Medium> medium) {
namedMedium[name] = medium;
}
/*! Insert named texture */
void insertNamedTexture(std::string name, std::shared_ptr<Texture> texture) {
namedTexture[name] = texture;
}
/*! Find named material either in this or in a parent scope */
std::shared_ptr<Material> findNamedMaterial(std::string name) {
return findNamedItem(std::shared_ptr<Material>{}, name);
}
/*! Find named medium either in this or in a parent scope */
std::shared_ptr<Medium> findNamedMedium(std::string name) {
return findNamedItem(std::shared_ptr<Medium>{}, name);
}
/*! Find named texture either in this or in a parent scope */
std::shared_ptr<Texture> findNamedTexture(std::string name) {
return findNamedItem(std::shared_ptr<Texture>{}, name);
}
std::vector<std::shared_ptr<AreaLightSource>> areaLightSources;
std::pair<std::string,std::string> mediumInterface;
bool reverseOrientation { false };
private:
/*! Parent graphics state */
Attributes::SP parent = nullptr;
/*! Previous graphics state, for "versioning"
(call freeze() to make a new version) */
Attributes::SP prev = nullptr;
std::map<std::string,std::shared_ptr<Material> > namedMaterial;
std::map<std::string,std::shared_ptr<Medium> > namedMedium;
std::map<std::string,std::shared_ptr<Texture> > namedTexture;
/*! get reference to namedMedium */
decltype(namedMedium)& get(std::shared_ptr<Medium>) { return namedMedium; }
/*! get reference to namedMaterial */
decltype(namedMaterial)& get(std::shared_ptr<Material>) { return namedMaterial; }
/*! get reference to namedTexture */
decltype(namedTexture)& get(std::shared_ptr<Texture>) { return namedTexture; }
/*! search this scope for the named item, descend into
parent scopes if not found. Also search prior versions */
template <typename Item>
Item findNamedItem(Item, std::string name) {
Attributes* curr = this;
while (curr != nullptr) {
if (curr->get(Item{}).find(name) != curr->get(Item{}).end())
return curr->get(Item{})[name];
if (curr->prev != nullptr)
curr = curr->prev.get();
else
curr = curr->parent.get();
}
return nullptr;
}
};
/*! forward definition of a typed parameter */
template<typename T>
struct ParamArray;
#ifdef WIN32
# pragma warning (disable : 4251)
#endif
/*! base abstraction for any type of parameter - typically,
parameters in pbrt can be either single values or
arbitrarily-sized arrays of values, so we will eventually
implement them as std::vectors, with the special case of a
single-value parameter being a std::vector with one element */
struct PBRT_PARSER_INTERFACE Param : public std::enable_shared_from_this<Param> {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Param> SP;
virtual std::string getType() const = 0;
virtual size_t getSize() const = 0;
virtual std::string toString() const = 0;
/*! used during parsing, to add a newly parsed parameter value
to the list */
virtual void add(const std::string &text) = 0;
template<typename T>
std::shared_ptr<ParamArray<T>> as();
};
template<typename T>
struct PBRT_PARSER_INTERFACE ParamArray : public Param, std::vector<T> {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<ParamArray<T>> SP;
ParamArray(const std::string &type) : type(type) {};
virtual std::string getType() const { return type; };
virtual size_t getSize() const { return this->size(); }
virtual std::string toString() const;
T get(const size_t idx) const { return (*this)[idx]; }
/*! used during parsing, to add a newly parsed parameter value
to the list */
virtual void add(const std::string &text);
/*! type */
std::string type;
};
struct Texture;
template<>
struct PBRT_PARSER_INTERFACE ParamArray<Texture> : public Param {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<ParamArray<Texture>> SP;
ParamArray(const std::string &type) : type(type) {};
virtual std::string getType() const { return type; };
virtual size_t getSize() const { return 1; }
virtual std::string toString() const;
/*! used during parsing, to add a newly parsed parameter value
to the list */
virtual void add(const std::string &) { throw std::runtime_error("should never get called.."); }
// private:
std::string type;
std::shared_ptr<Texture> texture;
};
/*! any class that can store (and query) parameters */
struct PBRT_PARSER_INTERFACE ParamSet {
ParamSet() = default;
ParamSet(ParamSet &&) = default;
ParamSet(const ParamSet &) = default;
/*! query number of (float,float) pairs N. Store in result if the former != NULL */
bool getParamPairNf(pairNf::value_type *result, std::size_t* N, const std::string &name) const;
/*! query parameter of 3f type, and if found, store in result and
return true; else return false */
bool getParam3f(float *result, const std::string &name) const;
bool getParam2f(float *result, const std::string &name) const;
math::pairNf getParamPairNf(const std::string &name, const math::pairNf &fallBack) const;
math::vec3f getParam3f(const std::string &name, const math::vec3f &fallBack) const;
math::vec2f getParam2f(const std::string &name, const math::vec2f &fallBack) const;
#if defined(PBRT_PARSER_VECTYPE_NAMESPACE)
vec2f getParam2f(const std::string &name, const vec2f &fallBack) const {
math::vec2f res = getParam2f(name, (const math::vec2f&)fallBack);
return *(vec2f*)&res;
}
vec3f getParam3f(const std::string &name, const vec3f &fallBack) const {
math::vec3f res = getParam3f(name, (const math::vec3f&)fallBack);
return *(vec3f*)&res;
}
#endif
float getParam1f(const std::string &name, const float fallBack=0) const;
int getParam1i(const std::string &name, const int fallBack=0) const;
bool getParamBool(const std::string &name, const bool fallBack=false) const;
std::string getParamString(const std::string &name) const;
std::shared_ptr<Texture> getParamTexture(const std::string &name) const;
bool hasParamTexture(const std::string &name) const {
return (bool)findParam<Texture>(name);
}
bool hasParamString(const std::string &name) const {
return (bool)findParam<std::string>(name);
}
bool hasParam1i(const std::string &name) const {
return (bool)findParam<int>(name) && findParam<int>(name)->size() == 1;
}
bool hasParam1f(const std::string &name) const {
return (bool)findParam<float>(name) && findParam<float>(name)->size() == 1;
}
bool hasParam2f(const std::string &name) const {
return (bool)findParam<float>(name) && findParam<float>(name)->size() == 2;
}
bool hasParam3f(const std::string &name) const {
return (bool)findParam<float>(name) && findParam<float>(name)->size() == 3;
}
template<typename T>
std::shared_ptr<ParamArray<T> > findParam(const std::string &name) const {
auto it = param.find(name);
if (it == param.end()) return typename ParamArray<T>::SP();
return it->second->as<T>(); //std::dynamic_pointer_cast<ParamArray<T> >(it->second);
}
std::map<std::string,std::shared_ptr<Param> > param;
};
struct PBRT_PARSER_INTERFACE Material : public ParamSet {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Material> SP;
/*! constructor */
Material(const std::string &type) : type(type) {};
/*! pretty-print this material (for debugging) */
std::string toString() const;
Attributes::SP attributes;
/*! the 'type' of the material, such as 'uber'material, 'matte',
'mix' etc. Note that the PBRT format has two inconsistent
ways of specifying that type: for the 'Material' command it
specifies the type explicitly right after the 'matierla'
command; for the 'makenamedmaterial' it uses an implicit
'type' parameter */
std::string type;
/*! the logical name that this was defined under, such as
"BackWall". Note this may be an empty string for some scenes
(it is only defined for 'NamedMaterial's) */
std::string name;
};
struct PBRT_PARSER_INTERFACE Medium : public ParamSet {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Medium> SP;
Medium(const std::string &type) : type(type) {};
/*! pretty-print this medium (for debugging) */
std::string toString() const;
/*! the 'type' of the medium */
std::string type;
};
struct PBRT_PARSER_INTERFACE Texture : public ParamSet {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Texture> SP;
Texture(const std::string &name,
const std::string &texelType,
const std::string &mapType)
: name(name), texelType(texelType), mapType(mapType)
{};
/*! pretty-print this medium (for debugging) */
virtual std::string toString() const { return "Texture(name="+name+",texelType="+texelType+",mapType="+mapType+")"; }
std::string name;
std::string texelType;
std::string mapType;
/*! the attributes active when this was created - some texture
use implicitly named textures, so have to keep this
around */
Attributes::SP attributes;
};
/*! base abstraction for any PBRT scene graph node - all shapes,
volumes, etc are eventually derived from this comon base
class */
struct PBRT_PARSER_INTERFACE Node : public ParamSet {
Node(const std::string &type)
: type(type)
{}
/*! pretty-printing, for debugging */
virtual std::string toString() const = 0;
/*! the 'type' as specified in the PBRT field, such as
'trianglemesh' for a tri mesh shape, etc */
std::string type;
};
/*! a PBRT "Camera" object - does not actually specify any
particular members by itself, all semantics is included in the
'type' field and its (type-specfic) parameters */
struct PBRT_PARSER_INTERFACE Camera : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Camera> SP;
/*! constructor */
Camera(const std::string &type,
const Transform &transform)
: Node(type),
transform(transform)
{};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Camera<"+type+">"; }
const Transform transform;
};
struct PBRT_PARSER_INTERFACE Sampler : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Sampler> SP;
/*! constructor */
Sampler(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Sampler<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE Integrator : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Integrator> SP;
/*! constructor */
Integrator(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Integrator<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE SurfaceIntegrator : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<SurfaceIntegrator> SP;
/*! constructor */
SurfaceIntegrator(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "SurfaceIntegrator<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE VolumeIntegrator : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<VolumeIntegrator> SP;
/*! constructor */
VolumeIntegrator(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "VolumeIntegrator<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE PixelFilter : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<PixelFilter> SP;
/*! constructor */
PixelFilter(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "PixelFilter<"+type+">"; }
};
/*! a PBRT 'geometric shape' (a shape in ospray terms) - ie,
something that has primitives that together form some sort of
surface(s) that a ray can intersect*/
struct PBRT_PARSER_INTERFACE Shape : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Shape> SP;
/*! constructor */
Shape(const std::string &type,
std::shared_ptr<Material> material,
std::shared_ptr<Attributes> attributes,
const Transform &transform);
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Shape<"+type+">"; }
/*! material active when the shape was generated - PBRT has only
one material per shape */
std::shared_ptr<Material> material;
std::shared_ptr<Attributes> attributes;
Transform transform;
};
struct PBRT_PARSER_INTERFACE Volume : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Volume> SP;
Volume(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Volume<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE LightSource : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<LightSource> SP;
LightSource(const std::string &type,
const Transform &transform)
: Node(type),
transform(transform)
{}
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "LightSource<"+type+">"; }
const Transform transform;
};
/*! area light sources are different from regular light sources in
that they get attached to getometry (shapes), whereas regular
light sources are not. Thus, from a type perspective a
AreaLightSource is _not_ "related" to a LightSource, which is
why we don't have one derived from the other. */
struct PBRT_PARSER_INTERFACE AreaLightSource : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<AreaLightSource> SP;
AreaLightSource(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "AreaLightSource<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE Film : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Film> SP;
Film(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Film<"+type+">"; }
};
struct PBRT_PARSER_INTERFACE Accelerator : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Accelerator> SP;
Accelerator(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Accelerator<"+type+">"; }
};
/*! the type of renderer to be used for rendering the given scene */
struct PBRT_PARSER_INTERFACE Renderer : public Node {
/*! a "Type::SP" shorthand for std::shared_ptr<Type> - makes code
more concise, and easier to read */
typedef std::shared_ptr<Renderer> SP;
Renderer(const std::string &type) : Node(type) {};
/*! pretty-printing, for debugging */
virtual std::string toString() const override { return "Renderer<"+type+">"; }
};
//! what's in a objectbegin/objectned, as well as the root object
struct PBRT_PARSER_INTERFACE Object {
/*! allows for writing pbrt::syntactic::Scene::SP, which is somewhat
more concise than std::shared_ptr<pbrt::syntactic::Scene> */
typedef std::shared_ptr<Object> SP;
Object(const std::string &name) : name(name) {}
struct PBRT_PARSER_INTERFACE Instance {
/*! allows for writing pbrt::syntactic::Scene::SP, which is somewhat
more concise than std::shared_ptr<pbrt::syntactic::Scene> */
typedef std::shared_ptr<Instance> SP;
Instance(std::shared_ptr<Object> object,
const Transform &xfm)
: object(object), xfm(xfm)
{}
std::string toString() const;
std::shared_ptr<Object> object;
Transform xfm;
};
//! pretty-print scene info into a std::string
virtual std::string toString(const int depth = 0) const;
/*! logical name of this object */
std::string name;
//! list of all shapes defined in this object
std::vector<std::shared_ptr<Shape> > shapes;
//! list of all volumes defined in this object
std::vector<std::shared_ptr<Volume> > volumes;
//! list of all instances defined in this object
std::vector<std::shared_ptr<Object::Instance> > objectInstances;
//! list of all light sources defined in this object
std::vector<std::shared_ptr<LightSource> > lightSources;
};
/*! The main object defined by each pbrt (root) file is a scene - a
scene contains all kind of global settings (such as integrator
to use, cameras defined in this scene, which pixel filter to
use, etc, plus some shape. */
struct PBRT_PARSER_INTERFACE Scene {
/*! allows for writing pbrt::syntactic::Scene::SP, which is somewhat more concise
than std::shared_ptr<pbrt::syntactic::Scene> */
typedef std::shared_ptr<Scene> SP;
/*! default constructor - creates a new (and at first, empty) scene */
Scene()
: world(std::make_shared<Object>("<root>"))
{}
virtual ~Scene()
{
std::cout << "destructor in scene .." << std::endl;
world = nullptr;
std::cout << "deleted world" << std::endl;
}
/*! parse the given file name, return parsed scene */
static std::shared_ptr<Scene> parse(const std::string &fileName, const std::string &basePath = "");
//! pretty-print scene info into a std::string
std::string toString(const int depth = 0) { return world->toString(depth); }
//! list of cameras defined in this object
std::vector<Camera::SP> cameras;
std::shared_ptr<Film> film;
// //! last lookat specified in the scene, or nullptr if none.
// std::shared_ptr<LookAt> lookAt;
//! last sampler specified in the scene, or nullptr if none.
std::shared_ptr<Sampler> sampler;
//! last integrator specified in the scene, or nullptr if none.
std::shared_ptr<Integrator> integrator;
//! last volume integrator specified in the scene, or nullptr if none.
std::shared_ptr<VolumeIntegrator> volumeIntegrator;
//! last surface integrator specified in the scene, or nullptr if none.
std::shared_ptr<SurfaceIntegrator> surfaceIntegrator;
//! last pixel filter specified in the scene, or nullptr if none.
std::shared_ptr<PixelFilter> pixelFilter;
/*! the root scene shape, defined in the
'WorldBegin'/'WorldEnd' statements */
std::shared_ptr<Object> world;
std::string makeGlobalFileName(const std::string &relativePath)
{ return basePath + relativePath; }
/*! the base path for all filenames defined in this scene. In
pbrt, lots of objects (a ply mesh shape, a texture, etc)
will require additional files in other formats (e.g., the
actual .ply file that the ply shape refers to; and the file
names will typically be relative to the file that referenced
them. To help computing a global file name for this we compute
- and store - the name of the directory that contained the
first file we parsed (ie, the "entry point" into the entire
scene */
std::string basePath;
};
template<typename T> std::shared_ptr<ParamArray<T>> Param::as()
{ return std::dynamic_pointer_cast<ParamArray<T>>(shared_from_this()); }
extern "C"
void pbrt_helper_loadPlyTriangles(const std::string &fileName,
std::vector<pbrt::syntactic::vec3f> &v,
std::vector<pbrt::syntactic::vec3f> &n,
std::vector<pbrt::syntactic::vec3i> &idx);
} // ::pbrt::syntactic
} // ::pbrt