19 #if !defined(__NORI_OBJECT_H)
20 #define __NORI_OBJECT_H
22 #include <nori/proplist.h>
46 EReconstructionFilter,
53 case EScene:
return "scene";
54 case EMesh:
return "shape";
55 case ETexture:
return "texture";
56 case EBSDF:
return "bsdf";
57 case EEmitter:
return "emitter";
58 case ECamera:
return "camera";
59 case EIntegrator:
return "integrator";
60 case ESampler:
return "sampler";
61 case ETest:
return "test";
62 default:
return "<unknown>";
83 "NoriObject::addChild() is not implemented for objects of type '%s'!",
114 void setIdName(
const std::string & name) { m_idname = name; }
115 const std::string & getIdName()
const {
return m_idname; }
118 std::string m_idname;
145 static void registerClass(
const std::string &name,
const Constructor &constr);
160 if (!m_constructors || m_constructors->find(name) == m_constructors->end())
161 throw NoriException(
"A constructor for class \"%s\" could not be found!", name);
162 return (*m_constructors)[name](propList);
165 static void printRegisteredClasses() {
167 for(
auto v : *m_constructors)
168 std::cout << v.first << std::endl;
172 static std::map<std::string, Constructor> *m_constructors;
176 #define NORI_REGISTER_CLASS(cls, name) \
177 cls *cls ##_create(const PropertyList &list) { \
178 return new cls(list); \
180 static struct cls ##_{ \
182 NoriObjectFactory::registerClass(name, cls ##_create); \
187 #define NORI_REGISTER_TEMPLATED_CLASS(cls, T, name) \
188 cls<T> * cls ##_## T ##_create(const PropertyList &list) { \
189 return new cls<T>(list); \
191 static struct cls ##_## T ##_{ \
192 cls ##_## T ##_() { \
193 NoriObjectFactory::registerClass(name, cls ##_## T ##_create); \
195 } cls ## T ##__NORI_;
Simple exception class, which stores a human-readable error description.
Factory for Nori objects.
static NoriObject * createInstance(const std::string &name, const PropertyList &propList)
Construct an instance from the class of the given name.
static void registerClass(const std::string &name, const Constructor &constr)
Register an object constructor with the object factory.
Base class of all objects.
virtual void activate()
Perform some action associated with the object.
virtual ~NoriObject()
Virtual destructor.
virtual void setParent(NoriObject *parent)
Set the parent object.
void setIdName(const std::string &name)
Allow to assign a name to the object.
virtual void addChild(NoriObject *child)
Add a child object to the current instance.
virtual std::string toString() const =0
Return a brief string summary of the instance (for debugging purposes)
static std::string classTypeName(EClassType type)
Turn a class type into a human-readable string.
virtual EClassType getClassType() const =0
Return the type of object (i.e. Mesh/BSDF/etc.) provided by this instance.
This is an associative container used to supply the constructors of NoriObject subclasses with parame...