I made a dummy node to log notify and eval plugs.
Every time notify() or eval() is called, plug's full name and new value is logged on the console.
When you connect a node like this,
Something like this is displayed on the Shake console.
It should be useful to analyze a tree.
#include <nriiplug.h>
#include <nrifx.h>
class NRiFx_Linkage logNode : public NRiMonadic {
public:
logNode();
virtual ~logNode(){}
virtual int eval(NRiPlug *p);
virtual int notify(NRiPlug *p);
NRiDeclareNodeName(logNode);
protected:
void passData_(NRiPlug *from, NRiPlug* to);
void log_(NRiPlug* p, NRiName msg);
};
const NRiName logNode::thisClassName = "logNode";
logNode::logNode() : NRiMonadic()
{
in->setNotify(1, 1);
out->setNotify(1, 1);
in->time()->addDependency(out->time());
in->enable()->addDependency(out->enable());
in->roi()->addDependency(out->roi());
in->mask()->addDependency(out->mask());
in->iBuf()->addDependency(out->iBuf());
in->cacheLevel()->addDependency(out->cacheLevel());
out->width()->addDependency(in->width());
out->height()->addDependency(in->height());
out->bytes()->addDependency(in->bytes());
out->active()->addDependency(in->active());
out->oBuf()->addDependency(in->oBuf());
out->dod()->addDependency(in->dod());
out->bPixel()->addDependency(in->bPixel());
out->cacheId()->addDependency(in->cacheId());
out->bData()->addDependency(in->bData());
out->timeRange()->addDependency(in->timeRange());
}
int logNode::eval(NRiPlug *p)
{
NRiPlug* parent = p->getParent();
NRiPlug* otherParent = (parent == in)? out : in;
NRiPlug* otherPlug = otherParent->getChild(p->getName());
passData_(otherPlug, p);
log_(p, "eval");
return NRiMonadic::eval(p);
}
int logNode::notify(NRiPlug *p)
{
log_(p, "ntfy");
return NRiMonadic::notify(p);
}
void logNode::log_(NRiPlug* p, NRiName msg)
{
NRiName buf;
NRiSys::error((msg + ": " + p->getFullPathName() + " value=").getString());
switch(p->getType())
{
case kString:
NRiSys::error(p->asString().getString());
break;
case kInt:
NRiSys::error(NRiName(p->asInt()).getString());
break;
case kFloat:
NRiSys::error(NRiName(p->asFloat()).getString());
break;
case kDouble:
NRiSys::error(NRiName(p->asDouble()).getString());
break;
case kPtr:
buf.sprintf("0x%x", p->asPtr());
NRiSys::error(buf.getString());
break;
default:
break;
}
NRiSys::error("\n");
}
void logNode::passData_(NRiPlug *from, NRiPlug* to)
{
switch(from->getType())
{
case kString:
to->set(from->asString());
break;
case kInt:
to->set(from->asInt());
break;
case kFloat:
to->set(from->asFloat());
break;
case kDouble:
to->set(from->asDouble());
break;
case kPtr:
to->set(from->asPtr());
break;
default:
break;
}
}
extern "C"
{
NRiExport NRiIPlug *LogNode_(NRiIPlug *img)
{
logNode* fx = new logNode;
fx->in->connect(img);
fx->setParent(NRiNode::getRoot());
return fx->out;
}
}
No comments:
Post a Comment