|
#include <string>
#include <RixInterfaces.h>
#include "RifPlugin.h"
#include <rx.h>
class ParamEcho : public RifPlugin {
public:
ParamEcho();
virtual ~ParamEcho() { };
virtual RifFilter &GetFilter() { return m_self; }
private:
RifFilter m_self; // reference to an instance of our class
RixMessages *m_msg;
static RtVoid attribute(RtToken name, RtInt nvals, RtToken tokens[], RtPointer params[]);
};
// Entry point required by PRMan
RifPlugin *RifPluginManufacture(int argc, char **argv) {
return new ParamEcho();
}
// Constructor
ParamEcho::ParamEcho() {
m_self.AttributeV = attribute;
m_self.Filtering = RifFilter::k_Continue;
RixContext *rixContext = RxGetRixContext();
m_msg = (RixMessages*) rixContext->GetRixInterface(k_RixMessages);
}
// Echo the text/data of each Attribute statement.
RtVoid ParamEcho::attribute(RtToken name, RtInt nvals, RtToken tokens[], RtPointer params[]) {
std::string message("Attribute ");
message = message + "\"" + name + "\"";
char buff[256];
RtFloat *fptr;
for(int n = 0; n < nvals; n++) {
message = message + " \"" + tokens[n] + "\" ";
RifTokenType tokType;
RifTokenDetail tokDetail;
RtInt arraylen;
// Here is the nifty helper function - RifGetDeclaration()
RtInt result = RifGetDeclaration(tokens[n], &tokType, &tokDetail, &arraylen);
if(result == 0) {
fptr = NULL;
switch(tokType) {
case k_RifFloat:
sprintf(buff, "[%1.4f]", *(RtFloat*)params[n]);
break;
case k_RifPoint:
fptr = (RtFloat*)params[n];
break;
case k_RifColor:
fptr = (RtFloat*)params[n];
break;
case k_RifVector:
fptr = (RtFloat*)params[n];
break;
case k_RifNormal:
fptr = (RtFloat*)params[n];
break;
case k_RifMatrix:
fptr = (RtFloat*)params[n];
sprintf(buff, "[%1.4f %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f\
%1.4f %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f]",
(*fptr)++, (*fptr)++, (*fptr)++, (*fptr)++,
(*fptr)++, (*fptr)++, (*fptr)++, (*fptr)++,
(*fptr)++, (*fptr)++, (*fptr)++, (*fptr)++,
(*fptr)++, (*fptr)++, (*fptr)++, (*fptr));
fptr = NULL;
break;
case k_RifInteger:
sprintf(buff, "[%d]", *(RtInt*)params[n]);
break;
case k_RifString:
sprintf(buff, "[\"%s\"]", *(RtToken*)params[n]);
break;
default:
sprintf(buff, "[unhandled type]");
}
if(fptr != NULL)
sprintf(buff, "[%1.4f %1.4f %1.4f]", (*fptr)++, (*fptr)++, *fptr);
message += std::string(buff);
}
}
// Pass through the attribute
RiAttributeV(name, nvals, tokens, params);
// Echo the Attribute params
ParamEcho *self = static_cast<ParamEcho*>(RifGetCurrentPlugin());
self->m_msg->Info(message.c_str());
}
|