Added CElementFilm
MODIFY
ext/MitsubaLoader/CElementFactory.cpp
ext/MitsubaLoader/CElementFactory.cpp
#include "../../ext/MitsubaLoader/IElement.h"
#include "../../ext/MitsubaLoader/CElementTransform.h"
#include "../../ext/MitsubaLoader/CElementSampler.h"
+#include "../../ext/MitsubaLoader/CElementFilm.h"
#include "../../ext/MitsubaLoader/CShapeCreator.h"
#include "../../ext/MitsubaLoader/Shape.h"
@@ -37,6 +38,7 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
if (!transform->processAttributes(_atts))
{
delete transform;
+ _IRR_DEBUG_BREAK_IF(true);
return nullptr;
}
@@ -50,12 +52,27 @@ IElement* CElementFactory::createElement(const char* _el, const char** _atts)
if (!sampler->processAttributes(_atts))
{
delete sampler;
+ _IRR_DEBUG_BREAK_IF(true);
return nullptr;
}
return sampler;
}
else
+ if (!std::strcmp(_el, "film"))
+ {
+ CElementFilm* film = new CElementFilm();
+
+ if (!film->processAttributes(_atts))
+ {
+ delete film;
+ _IRR_DEBUG_BREAK_IF(true);
+ return nullptr;
+ }
+
+ return film;
+ }
+ else
{
ParserLog::invalidXMLFileStructure("element " + std::string(_el) + "is unknown. \n");
_IRR_DEBUG_BREAK_IF(true);

ADD
ext/MitsubaLoader/CElementFilm.cpp
+#include "../../ext/MitsubaLoader/CElementFilm.h"
+#include "../../ext/MitsubaLoader/ParserUtil.h"
+#include "../../ext/MitsubaLoader/PropertyElement.h"
+
+#include <functional>
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+bool CElementFilm::processAttributes(const char** _atts)
+{
+ static const core::unordered_map<std::string, EFilmType> acceptableTypes = {
+ std::make_pair("hdrfilm", EFilmType::HDR_FILM),
+ std::make_pair("tiledhdrfilm", EFilmType::TILED_HDR_FILM),
+ std::make_pair("ldrfilm", EFilmType::LDR_FILM),
+ std::make_pair("mfilm", EFilmType::M_FILM)
+ };
+
+ //only type is an acceptable argument
+ for (int i = 0; _atts[i]; i += 2)
+ {
+ if (std::strcmp(_atts[i], "type"))
+ {
+ ParserLog::invalidXMLFileStructure(std::string(_atts[i]) + " is not attribute of shape element.");
+ return false;
+ }
+ else
+ {
+ auto samplerType = acceptableTypes.find(_atts[i + 1]);
+ if (samplerType == acceptableTypes.end())
+ {
+ ParserLog::invalidXMLFileStructure("unknown type");
+ _IRR_DEBUG_BREAK_IF(false);
+ return false;
+ }
+
+ data.type = samplerType->second;
+
+ //set default values
+ switch (data.type)
+ {
+ case EFilmType::HDR_FILM:
+ {
+ data.hdrFilmData.fileFormat = EHDRFileFormat::OPENEXR;
+ data.hdrFilmData.componentFormat = EComponentFormat::FLOAT16;
+ data.hdrFilmData.attachLog = true;
+ data.hdrFilmData.banner = true;
+ data.hdrFilmData.highQualityEdges = false;
+ }
+ break;
+ case EFilmType::TILED_HDR_FILM:
+ {
+ data.tiledHdrFilmData.componentFormat = EComponentFormat::FLOAT16;
+ }
+ break;
+ case EFilmType::LDR_FILM:
+ {
+ data.ldrFilmData.fileFormat = ELDRFileFormat::PNG;
+ data.ldrFilmData.tonemapMethod = ETonemapMethod::GAMMA;
+ data.ldrFilmData.gamma = -1.0f;
+ data.ldrFilmData.exposure = 0;
+ data.ldrFilmData.key = 0.18f;
+ data.ldrFilmData.burn = 0.0f;
+ data.ldrFilmData.banner = true;
+ data.ldrFilmData.highQualityEdges = false;
+ }
+ break;
+ case EFilmType::M_FILM:
+ {
+ data.width = 1;
+ data.height = 1;
+ data.pixelFormat = EPixelFormat::LUMINANCE;
+
+ data.mFilmData.fileFormat = EMFileFormat::MATLAB;
+ data.mFilmData.digits = 4;
+ data.mFilmData.variable = "data";
+ data.mFilmData.highQualityEdges = true;
+ }
+ break;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::onEndTag(asset::IAssetManager& _assetManager)
+{
+ switch (data.type)
+ {
+ case EFilmType::HDR_FILM:
+ return processHDRFilmProperties();
+
+ case EFilmType::TILED_HDR_FILM:
+ return processTiledHDRFilmProperties();
+
+ case EFilmType::LDR_FILM:
+ return processLDRFilmProperties();
+
+ case EFilmType::M_FILM:
+ return processMFilmProperties();
+
+ default:
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+}
+
+bool CElementFilm::processSharedDataProperty(const SPropertyElementData& _property)
+{
+ if (_property.type == SPropertyElementData::Type::INTEGER)
+ {
+ if (_property.name == "width")
+ {
+ data.width = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "height")
+ {
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropOffsetX")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropOffsetY")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropWidth")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else if (_property.name == "cropHeight")
+ {
+ data.isCropUsed = true;
+ data.height = CPropertyElementManager::retriveIntValue(_property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (_property.type == SPropertyElementData::Type::STRING &&
+ _property.name == "pixelFormat")
+ {
+ if (_property.value == "luminance") data.pixelFormat = EPixelFormat::LUMINANCE; else
+ if (_property.value == "luminanceAlpha") data.pixelFormat = EPixelFormat::LUMINANCE_ALPHA; else
+ if (_property.value == "rgb") data.pixelFormat = EPixelFormat::RGB; else
+ if (_property.value == "rgba") data.pixelFormat = EPixelFormat::RGBA; else
+ if (_property.value == "xyz") data.pixelFormat = EPixelFormat::XYZ; else
+ if (_property.value == "xyza") data.pixelFormat = EPixelFormat::XYZA; else
+ if (_property.value == "spectrum") data.pixelFormat = EPixelFormat::SPECTRUM; else
+ if (_property.value == "spectrumAlpha") data.pixelFormat = EPixelFormat::SPECTRUM_ALPHA; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unkown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+
+ return true;
+}
+
+bool CElementFilm::processHDRFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "fileFormat")
+ {
+ if (property.value == "openexr") data.hdrFilmData.fileFormat = EHDRFileFormat::OPENEXR; else
+ if (property.value == "rgbe") data.hdrFilmData.fileFormat = EHDRFileFormat::RGBE; else
+ if (property.value == "pfm") data.hdrFilmData.fileFormat = EHDRFileFormat::PFM; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "componentFormat")
+ {
+ if (property.value == "float16") data.hdrFilmData.componentFormat = EComponentFormat::FLOAT16; else
+ if (property.value == "float32") data.hdrFilmData.componentFormat = EComponentFormat::FLOAT32; else
+ if (property.value == "uint32") data.hdrFilmData.componentFormat = EComponentFormat::UINT32; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::BOOLEAN)
+ {
+ if (property.name == "attachLog")
+ {
+ data.hdrFilmData.attachLog = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if (property.name == "banner")
+ {
+ data.hdrFilmData.banner = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if (property.name == "hightQualityEdges")
+ {
+ data.hdrFilmData.highQualityEdges = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::processTiledHDRFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "componentFormat")
+ {
+ if (property.value == "float16") data.tiledHdrFilmData.componentFormat = EComponentFormat::FLOAT16; else
+ if (property.value == "float32") data.tiledHdrFilmData.componentFormat = EComponentFormat::FLOAT32; else
+ if (property.value == "uint32") data.tiledHdrFilmData.componentFormat = EComponentFormat::UINT32;
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if (!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::processLDRFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "fileFormat")
+ {
+ if (property.value == "png") data.ldrFilmData.fileFormat = ELDRFileFormat::PNG; else
+ if (property.value == "jpeg") data.ldrFilmData.fileFormat = ELDRFileFormat::JPEG; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::STRING &&
+ property.name == "tonemapMethod")
+ {
+ if (property.value == "gamma") data.ldrFilmData.tonemapMethod = ETonemapMethod::GAMMA; else
+ if (property.value == "reinhard") data.ldrFilmData.tonemapMethod = ETonemapMethod::REINHARD; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::BOOLEAN)
+ {
+ if (property.name == "banner")
+ {
+ data.ldrFilmData.banner = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if (property.name == "hightQualityEdges")
+ {
+ data.ldrFilmData.highQualityEdges = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::FLOAT)
+ {
+ if (property.name == "gamma")
+ {
+ data.ldrFilmData.gamma = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "exposure")
+ {
+ data.ldrFilmData.exposure = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "key")
+ {
+ data.ldrFilmData.key = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else if (property.name == "burn")
+ {
+ data.ldrFilmData.burn = CPropertyElementManager::retriveFloatValue(property.value);
+ }
+ else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool CElementFilm::processMFilmProperties()
+{
+ for (const SPropertyElementData& property : properties)
+ {
+ if (property.type == SPropertyElementData::Type::STRING)
+ {
+ if (property.name == "fileFormat")
+ {
+ if (property.value == "matlab") data.mFilmData.fileFormat = EMFileFormat::MATLAB; else
+ if (property.value == "mathematica") data.mFilmData.fileFormat = EMFileFormat::MATHEMATICA; else
+ if (property.value == "numpy") data.mFilmData.fileFormat = EMFileFormat::NUMPY; else
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else if (property.name == "variable")
+ {
+ data.mFilmData.variable = property.value;
+ }
+ else if(property.name != "pixelFormat")
+ {
+ ParserLog::invalidXMLFileStructure("unknown property");
+ _IRR_DEBUG_BREAK_IF(true);
+ return false;
+ }
+ }
+ else
+ if (property.type == SPropertyElementData::Type::INTEGER &&
+ property.name == "digits")
+ {
+ data.mFilmData.digits = CPropertyElementManager::retriveIntValue(property.value);
+ }
+ else
+ if (property.type == SPropertyElementData::Type::BOOLEAN &&
+ property.name == "highQualityEdges")
+ {
+ data.mFilmData.highQualityEdges = CPropertyElementManager::retriveBooleanValue(property.value);
+ }
+ else if(!processSharedDataProperty(property))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+}
+}
+}
\ No newline at end of file

ADD
ext/MitsubaLoader/CElementFilm.h
+#ifndef __C_ELEMENT_FILM_H_INCLUDED__
+#define __C_ELEMENT_FILM_H_INCLUDED__
+
+#include "../../ext/MitsubaLoader/IElement.h"
+#include "irrlicht.h"
+
+namespace irr { namespace ext { namespace MitsubaLoader {
+
+ /*The options are float16, float32, or
+ uint32. (Default: float16).*/
+
+enum class ETonemapMethod
+{
+ GAMMA,
+ REINHARD
+};
+
+enum class EComponentFormat
+{
+ FLOAT16,
+ FLOAT32,
+ UINT32
+};
+
+enum class EHDRFileFormat
+{
+ OPENEXR,
+ RGBE,
+ PFM
+};
+
+enum class ELDRFileFormat
+{
+ PNG,
+ JPEG
+};
+
+enum class EMFileFormat
+{
+ MATLAB,
+ MATHEMATICA,
+ NUMPY
+};
+
+enum class EFilmType
+{
+ NONE,
+ HDR_FILM,
+ TILED_HDR_FILM,
+ LDR_FILM,
+ M_FILM
+};
+
+enum class EPixelFormat
+{
+ LUMINANCE,
+ LUMINANCE_ALPHA,
+ RGB,
+ RGBA,
+ XYZ,
+ XYZA,
+ SPECTRUM,
+ SPECTRUM_ALPHA
+};
+
+struct SFilmMetadata
+{
+ SFilmMetadata()
+ :type(EFilmType::NONE) {};
+
+ SFilmMetadata(const SFilmMetadata& other)
+ :type(other.type), width(other.width), height(other.height),
+ isCropUsed(other.isCropUsed), cropOffsetX(other.cropOffsetX), cropOffsetY(other.cropOffsetY),
+ cropWidth(other.cropWidth), cropHeight(other.cropHeight), pixelFormat(other.pixelFormat)
+ {
+ switch (other.type)
+ {
+ case EFilmType::HDR_FILM:
+ hdrFilmData = other.hdrFilmData;
+ case EFilmType::TILED_HDR_FILM:
+ tiledHdrFilmData = other.tiledHdrFilmData;
+ case EFilmType::LDR_FILM:
+ ldrFilmData = other.ldrFilmData;
+ case EFilmType::M_FILM:
+ mFilmData = other.mFilmData;
+ }
+ }
+
+ ~SFilmMetadata()
+ {
+
+ }
+
+ EFilmType type;
+
+ int width = 768;
+ int height = 576;
+
+ bool isCropUsed = false;
+ int cropOffsetX = 0.0f;
+ int cropOffsetY = 0.0f;
+ int cropWidth = 0.0f;
+ int cropHeight = 0.0f;
+
+ //rfilter
+
+ EPixelFormat pixelFormat = EPixelFormat::RGB;
+
+ union
+ {
+ struct HdrFilmData
+ {
+ EHDRFileFormat fileFormat;
+ EComponentFormat componentFormat;
+ bool attachLog;
+ bool banner;
+ bool highQualityEdges;
+ } hdrFilmData;
+
+ struct TiledHdrFilmData
+ {
+ EComponentFormat componentFormat;
+ } tiledHdrFilmData;
+
+ struct LdrFilmData
+ {
+ ELDRFileFormat fileFormat;
+ ETonemapMethod tonemapMethod;
+ float gamma;
+ float exposure;
+ float key;
+ float burn;
+ bool banner;
+ bool highQualityEdges;
+
+ } ldrFilmData;
+
+ struct MFilmData
+ {
+ EMFileFormat fileFormat;
+ int digits;
+ std::string variable;
+ bool highQualityEdges;
+
+ } mFilmData;
+ };
+};
+
+class CElementFilm : public IElement
+{
+public:
+ virtual bool processAttributes(const char** _atts) override;
+ virtual bool onEndTag(asset::IAssetManager& _assetManager) override;
+ virtual IElement::Type getType() const override { return IElement::Type::SAMPLER; }
+ virtual std::string getLogName() const override { return "sampler"; }
+
+ SFilmMetadata getMetadata() const { return data; };
+
+private:
+ bool processSharedDataProperty(const SPropertyElementData& _property);
+ bool processHDRFilmProperties();
+ bool processTiledHDRFilmProperties();
+ bool processLDRFilmProperties();
+ bool processMFilmProperties();
+
+private:
+ SFilmMetadata data;
+
+};
+
+
+
+}
+}
+}
+
+#endif
\ No newline at end of file

MODIFY
ext/MitsubaLoader/CElementSampler.cpp
ext/MitsubaLoader/CElementSampler.cpp
@@ -7,7 +7,7 @@ namespace irr { namespace ext { namespace MitsubaLoader {
bool CElementSampler::processAttributes(const char** _atts)
{
static const core::unordered_map<std::string, ESamplerType> acceptableTypes = {
- std::make_pair("independed", ESamplerType::INDEPENDEND),
+ std::make_pair("independent", ESamplerType::INDEPENDENT),
std::make_pair("stratified", ESamplerType::STRATIFIED),
std::make_pair("ldsampler", ESamplerType::LDSAMPLER),
std::make_pair("halton", ESamplerType::HALTON),
@@ -83,7 +83,7 @@ bool CElementSampler::onEndTag(asset::IAssetManager& _assetManager)
_IRR_DEBUG_BREAK_IF(true);
return false;
}
- case ESamplerType::INDEPENDEND:
+ case ESamplerType::INDEPENDENT:
{
if (dimensionSet || scrambleSet)
{

MODIFY
ext/MitsubaLoader/CElementSampler.h
ext/MitsubaLoader/CElementSampler.h
@@ -9,7 +9,7 @@ namespace irr { namespace ext { namespace MitsubaLoader {
enum class ESamplerType
{
NONE,
- INDEPENDEND,
+ INDEPENDENT,
STRATIFIED,
LDSAMPLER,
HALTON,

MODIFY
ext/MitsubaLoader/CMitsubaScene.cpp
ext/MitsubaLoader/CMitsubaScene.cpp
@@ -55,8 +55,7 @@ bool CMitsubaScene::processChildData(IElement* _child)
}
default:
ParserLog::invalidXMLFileStructure(_child->getLogName() + " is not a child element of the scene element");
- _IRR_DEBUG_BREAK_IF(true);
- return false;
+ return true;
}
return true;

Added CElementFilm