Configuring Manta with the Factory class.
> How do I call: > > rtrt->setShadowAlgorithm(this); > rtrt->setRenderer(this); > > from Raydumper? It used to happed in Raydumper::setupBegin. > There, rtrt is a MantaInterface, but it no longer has these functions. > I see there's a new Factory class to handle this functionality, but > I don't know how to get access to it from the Raydumper renderer. > The Raydumper needs to force Manta to use itself as the > Renderer/ShadowAlgorithm...
The Factory class now contains all of the mappings from strings to component names. These mappings are setup in the constructor so all you need to do is either pass in a Factory or just create one right there. There is some overhead associated with constructing the factory since it needs to populate all those mappings, but it shouldn't be too bad in a setup function which is only called once.
I didn't mean to suggest that there should be a singleton Factory instance for all of Manta, however it would be really easy to include something like this in a component library that you were linking to Manta. This strategy would be useful if you wanted to un-map or re-map the default component names (which are defined in RegisterKnownComponents.cc).
Right now in Raydumper.cc you have:
// Hi-jack RTRT's Renderer if (!rtrt->selectRenderer(renderer_string)) throw InternalError("renderer not found", __FILE__, __LINE__ ); renderer = rtrt->getRenderer(); rtrt->setRenderer(this);
The direct mapping of this is:
// Construct a new Factory instance Factory factory( context.rtrt_int ); // ... // Hi-jack RTRT's Renderer if (!factory.selectRenderer(renderer_string)) throw InternalError("renderer not found", __FILE__, __LINE__ ); renderer = rtrt->getRenderer(); rtrt->setRenderer(this);
However, in this code and in the original code, the select method maps the hard coded string "raytracer" to the manta component which is then returned by the getRenderer method. Another way to write this would be:
renderer = new Raytracer(); rtrt->setRenderer(this);
Of course this won't work right now since Raytracer doesn't have a default constructor, instead it has a constructor that takes a stl::vector of strings (even though it has no member variables). It's completely reasonable to add a default constructor to classes like this.
This is another example of something that works great when you want to use manta.cc, but isn't so convenient when you want to just link to Manta from somewhere else. The static create method (along with the vector<string> constructor) is left over from the pre-python days when parsing command lines with lots of quoted parenthesis was the name of the game. Now there's no reason to force someone to create an empty vector<string> just to pass it to an empty constructor. I may work through the code at some point and add appropriate constructors, but you're more then welcome to also if their absence gets in your way.