Skip to content

Commit 1eb3eb9

Browse files
author
devsh
committed
get some parsing going
1 parent f850ce7 commit 1eb3eb9

28 files changed

+574
-597
lines changed

include/nbl/ext/MitsubaLoader/CElementBSDF.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class CElementBSDF : public IElement
370370
}
371371

372372
bool addProperty(SNamedPropertyElement&& _property, system::logger_opt_ptr logger) override;
373-
bool onEndTag(asset::IAssetLoader::IAssetLoaderOverride* _override, CMitsubaMetadata* globalMetadata) override;
373+
bool onEndTag(CMitsubaMetadata* globalMetadata, system::logger_opt_ptr logger) override;
374374
IElement::Type getType() const override { return IElement::Type::BSDF; }
375375
std::string getLogName() const override { return "bsdf"; }
376376

@@ -380,16 +380,16 @@ class CElementBSDF : public IElement
380380
{
381381
switch (type)
382382
{
383-
case COATING: [[fallthrough]];
384-
case ROUGHCOATING: [[fallthrough]];
385-
case TWO_SIDED: [[fallthrough]];
386-
case MASK: [[fallthrough]];
387-
case BLEND_BSDF: [[fallthrough]];
388-
case MIXTURE_BSDF: [[fallthrough]];
389-
case BUMPMAP:
390-
return true;
391-
default:
392-
return false;
383+
case COATING: [[fallthrough]];
384+
case ROUGHCOATING: [[fallthrough]];
385+
case TWO_SIDED: [[fallthrough]];
386+
case MASK: [[fallthrough]];
387+
case BLEND_BSDF: [[fallthrough]];
388+
case MIXTURE_BSDF: [[fallthrough]];
389+
case BUMPMAP:
390+
return true;
391+
default:
392+
return false;
393393
}
394394
}
395395

include/nbl/ext/MitsubaLoader/CElementEmissionProfile.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ struct CElementEmissionProfile final : public IElement
4444
}
4545

4646
bool addProperty(SNamedPropertyElement&& _property, system::logger_opt_ptr logger) override;
47-
inline bool onEndTag(asset::IAssetLoader::IAssetLoaderOverride* _override, CMitsubaMetadata* globalMetadata) override {
48-
return true;
49-
}
47+
inline bool onEndTag(CMitsubaMetadata* globalMetadata, system::logger_opt_ptr logger) override {return true;}
5048
bool processChildData(IElement* _child, const std::string& name) override;
5149
inline IElement::Type getType() const override { return IElement::Type::EMISSION_PROFILE; }
5250
inline std::string getLogName() const override { return "emissionprofile "; }
@@ -60,7 +58,7 @@ struct CElementEmissionProfile final : public IElement
6058

6159
};
6260

63-
std::string filename;
61+
std::string filename; // TODO: test destructor runs
6462
E_NORMALIZE normalization;
6563
float flatten; // TODO: why is this named this way?
6664
};

include/nbl/ext/MitsubaLoader/CElementEmitter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CElementEmitter : public IElement
8787
};*/
8888
struct EnvMap : SampledEmitter
8989
{
90-
SPropertyElementData filename;
90+
SPropertyElementData filename; // TODO: make sure destructor runs
9191
float scale = 1.f;
9292
float gamma = NAN;
9393
//bool cache = false;
@@ -201,7 +201,7 @@ class CElementEmitter : public IElement
201201
}
202202

203203
bool addProperty(SNamedPropertyElement&& _property, system::logger_opt_ptr logger) override;
204-
bool onEndTag(asset::IAssetLoader::IAssetLoaderOverride* _override, CMitsubaMetadata* globalMetadata) override;
204+
bool onEndTag(CMitsubaMetadata* globalMetadata, system::logger_opt_ptr logger) override;
205205
IElement::Type getType() const override { return IElement::Type::EMITTER; }
206206
std::string getLogName() const override { return "emitter"; }
207207

include/nbl/ext/MitsubaLoader/CElementFilm.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class CElementFilm final : public IElement
2222
LDR_FILM,
2323
MFILM
2424
};
25+
static inline core::unordered_map<core::string,Type,core::CaseInsensitiveHash,core::CaseInsensitiveEquals> compStringToTypeMap()
26+
{
27+
return {
28+
{"hdrfilm", Type::HDR_FILM},
29+
{"tiledhdrfilm",Type::TILED_HDR},
30+
{"ldrfilm", Type::LDR_FILM},
31+
{"mfilm", Type::MFILM}
32+
};
33+
}
34+
2535
enum PixelFormat : uint8_t
2636
{
2737
LUMINANCE,
@@ -93,8 +103,29 @@ class CElementFilm final : public IElement
93103
{
94104
}
95105

106+
inline void initialize()
107+
{
108+
switch (type)
109+
{
110+
case CElementFilm::Type::LDR_FILM:
111+
fileFormat = CElementFilm::FileFormat::PNG;
112+
//componentFormat = UINT8;
113+
ldrfilm = CElementFilm::LDR();
114+
break;
115+
case CElementFilm::Type::MFILM:
116+
width = 1;
117+
height = 1;
118+
fileFormat = CElementFilm::FileFormat::MATLAB;
119+
pixelFormat = CElementFilm::PixelFormat::LUMINANCE;
120+
mfilm = CElementFilm::M();
121+
break;
122+
default:
123+
break;
124+
}
125+
}
126+
96127
bool addProperty(SNamedPropertyElement&& _property, system::logger_opt_ptr logger) override;
97-
bool onEndTag(asset::IAssetLoader::IAssetLoaderOverride* _override, CMitsubaMetadata* globalMetadata) override;
128+
bool onEndTag(CMitsubaMetadata* globalMetadata, system::logger_opt_ptr logger) override;
98129
inline IElement::Type getType() const override { return IElement::Type::FILM; }
99130
inline std::string getLogName() const override { return "film"; }
100131

include/nbl/ext/MitsubaLoader/CElementIntegrator.h

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ namespace nbl::ext::MitsubaLoader
1515
class CElementIntegrator final : public IElement
1616
{
1717
public:
18-
enum Type
18+
enum Type : uint8_t
1919
{
20-
INVALID,
2120
AO,
2221
DIRECT,
2322
PATH,
@@ -35,8 +34,33 @@ class CElementIntegrator final : public IElement
3534
VPL,
3635
IRR_CACHE,
3736
MULTI_CHANNEL,
38-
FIELD_EXTRACT
37+
FIELD_EXTRACT,
38+
INVALID
3939
};
40+
static inline core::unordered_map<core::string,Type,core::CaseInsensitiveHash,core::CaseInsensitiveEquals> compStringToTypeMap()
41+
{
42+
return {
43+
{"ao", Type::AO},
44+
{"direct", Type::DIRECT},
45+
{"path", Type::PATH},
46+
{"volpath_simple", Type::VOL_PATH_SIMPLE},
47+
{"volpath", Type::VOL_PATH},
48+
{"bdpt", Type::BDPT},
49+
{"photonmapper", Type::PHOTONMAPPER},
50+
{"ppm", Type::PPM},
51+
{"sppm", Type::SPPM},
52+
{"pssmlt", Type::PSSMLT},
53+
{"mlt", Type::MLT},
54+
{"erpt", Type::ERPT},
55+
{"ptracer", Type::ADJ_P_TRACER},
56+
{"adaptive", Type::ADAPTIVE},
57+
{"vpl", Type::VPL},
58+
{"irrcache", Type::IRR_CACHE},
59+
{"multichannel", Type::MULTI_CHANNEL},
60+
{"field", Type::FIELD_EXTRACT}
61+
};
62+
}
63+
4064
struct AmbientOcclusion
4165
{
4266
int32_t shadingSamples = 1;
@@ -49,8 +73,8 @@ class CElementIntegrator final : public IElement
4973
};
5074
struct DirectIllumination : EmitterHideableBase
5175
{
52-
int32_t emitterSamples = 0xdeadbeefu;
53-
int32_t bsdfSamples = 0xdeadbeefu;
76+
int32_t emitterSamples = static_cast<int32_t>(0xdeadbeefu);
77+
int32_t bsdfSamples = static_cast<int32_t>(0xdeadbeefu);
5478
bool strictNormals = false;
5579
};
5680
struct MonteCarloTracingBase
@@ -161,7 +185,7 @@ class CElementIntegrator final : public IElement
161185
}
162186

163187
Type field;
164-
SPropertyElementData undefined;
188+
SPropertyElementData undefined; // TODO: test destructor runs
165189
};
166190
struct MetaIntegrator
167191
{
@@ -198,74 +222,89 @@ class CElementIntegrator final : public IElement
198222
{
199223
}
200224

201-
inline CElementIntegrator& operator=(const CElementIntegrator& other)
225+
template<typename Visitor>
226+
inline void visit(Visitor&& visitor)
202227
{
203-
IElement::operator=(other);
204-
type = other.type;
205228
switch (type)
206229
{
207230
case CElementIntegrator::Type::AO:
208-
ao = other.ao;
231+
visitor(ao);
209232
break;
210233
case CElementIntegrator::Type::DIRECT:
211-
direct = other.direct;
234+
visitor(direct);
212235
break;
213236
case CElementIntegrator::Type::PATH:
214-
path = other.path;
237+
visitor(path);
215238
break;
216239
case CElementIntegrator::Type::VOL_PATH_SIMPLE:
217-
volpath_simple = other.volpath_simple;
240+
visitor(volpath_simple);
218241
break;
219242
case CElementIntegrator::Type::VOL_PATH:
220-
volpath = other.volpath;
243+
visitor(volpath);
221244
break;
222245
case CElementIntegrator::Type::BDPT:
223-
bdpt = other.bdpt;
246+
visitor(bdpt);
224247
break;
225248
case CElementIntegrator::Type::PHOTONMAPPER:
226-
photonmapper = other.photonmapper;
249+
visitor(photonmapper);
227250
break;
228251
case CElementIntegrator::Type::PPM:
229-
ppm = other.ppm;
252+
visitor(ppm);
230253
break;
231254
case CElementIntegrator::Type::SPPM:
232-
sppm = other.sppm;
255+
visitor(sppm);
233256
break;
234257
case CElementIntegrator::Type::PSSMLT:
235-
pssmlt = other.pssmlt;
258+
visitor(pssmlt);
236259
break;
237260
case CElementIntegrator::Type::MLT:
238-
mlt = other.mlt;
261+
visitor(mlt);
239262
break;
240263
case CElementIntegrator::Type::ERPT:
241-
erpt = other.erpt;
264+
visitor(erpt);
242265
break;
243266
case CElementIntegrator::Type::ADJ_P_TRACER:
244-
ptracer = other.ptracer;
267+
visitor(ptracer);
245268
break;
246269
case CElementIntegrator::Type::ADAPTIVE:
247-
adaptive = other.adaptive;
270+
visitor(adaptive);
248271
break;
249272
case CElementIntegrator::Type::VPL:
250-
vpl = other.vpl;
273+
visitor(vpl);
251274
break;
252275
case CElementIntegrator::Type::IRR_CACHE:
253-
irrcache = other.irrcache;
276+
visitor(irrcache);
254277
break;
255278
case CElementIntegrator::Type::MULTI_CHANNEL:
256-
multichannel = other.multichannel;
279+
visitor(multichannel);
257280
break;
258281
case CElementIntegrator::Type::FIELD_EXTRACT:
259-
field = other.field;
282+
visitor(field);
260283
break;
261284
default:
262285
break;
263286
}
287+
}
288+
template<typename Visitor>
289+
inline void visit(Visitor&& visitor) const
290+
{
291+
const_cast<CElementIntegrator*>(this)->visit([&]<typename T>(T& var)->void
292+
{
293+
visitor(const_cast<const T&>(var));
294+
}
295+
);
296+
}
297+
298+
inline CElementIntegrator& operator=(const CElementIntegrator& other)
299+
{
300+
IElement::operator=(other);
301+
type = other.type;
302+
IElement::copyVariant(this,&other);
264303
return *this;
265304
}
266305

267306
bool addProperty(SNamedPropertyElement&& _property, system::logger_opt_ptr logger) override;
268-
bool onEndTag(asset::IAssetLoader::IAssetLoaderOverride* _override, CMitsubaMetadata* globalMetadata) override;
307+
bool onEndTag(CMitsubaMetadata* globalMetadata, system::logger_opt_ptr logger) override;
269308
inline IElement::Type getType() const override { return IElement::Type::INTEGRATOR; }
270309
inline std::string getLogName() const override { return "integrator"; }
271310

include/nbl/ext/MitsubaLoader/CElementRFilter.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ class CElementRFilter final : public IElement
2626
CATMULLROM,
2727
LANCZOS
2828
};
29+
static inline core::unordered_map<core::string,Type,core::CaseInsensitiveHash,core::CaseInsensitiveEquals> compStringToTypeMap()
30+
{
31+
return {
32+
std::make_pair("box", Type::BOX),
33+
std::make_pair("tent", Type::TENT),
34+
std::make_pair("gaussian", Type::GAUSSIAN),
35+
std::make_pair("mitchell", Type::MITCHELL),
36+
std::make_pair("catmullrom", Type::CATMULLROM),
37+
std::make_pair("lanczos", Type::LANCZOS)
38+
};
39+
}
40+
2941
struct Gaussian
3042
{
3143
float sigma = NAN; // can't look at mitsuba source to figure out the default it uses
@@ -46,8 +58,43 @@ class CElementRFilter final : public IElement
4658
}
4759
inline ~CElementRFilter() {}
4860

61+
template<typename Visitor>
62+
inline void visit(Visitor&& visitor)
63+
{
64+
switch (type)
65+
{
66+
case Type::BOX:
67+
[[fallthrough]];
68+
case Type::TENT:
69+
break;
70+
case Type::GAUSSIAN:
71+
visit(gaussian);
72+
break;
73+
case Type::MITCHELL:
74+
visit(mitchell);
75+
break;
76+
case Type::CATMULLROM:
77+
visit(catmullrom);
78+
break;
79+
case Type::LANCZOS:
80+
visit(lanczos);
81+
break;
82+
default:
83+
break;
84+
}
85+
}
86+
template<typename Visitor>
87+
inline void visit(Visitor&& visitor) const
88+
{
89+
const_cast<CElementRFilter*>(this)->visit([&]<typename T>(T& var)->void
90+
{
91+
visitor(const_cast<const T&>(var));
92+
}
93+
);
94+
}
95+
4996
bool addProperty(SNamedPropertyElement&& _property, system::logger_opt_ptr logger) override;
50-
bool onEndTag(asset::IAssetLoader::IAssetLoaderOverride* _override, CMitsubaMetadata* globalMetadata) override;
97+
bool onEndTag(CMitsubaMetadata* globalMetadata, system::logger_opt_ptr logger) override;
5198
inline IElement::Type getType() const override { return IElement::Type::RFILTER; }
5299
inline std::string getLogName() const override { return "rfilter"; }
53100

0 commit comments

Comments
 (0)