00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <fstream.h>
00027 #include <UT/UT_DSOVersion.h>
00028 #include <CH/CH_LocalVariable.h>
00029 #include <PRM/PRM_Include.h>
00030 #include <OP/OP_OperatorTable.h>
00031 #include <OP/OP_Director.h>
00032 #include <SOP/SOP_Node.h>
00033 #include <ROP/ROP_Error.h>
00034 #include <ROP/ROP_Templates.h>
00035 #include "ROP_Dumper.h"
00036
00037 using namespace HDK_Sample;
00038
00039 int *ROP_Dumper::ifdIndirect = 0;
00040
00041 static PRM_Name theFileName("file", "Save to file");
00042 static PRM_Default theFileDefault(0, "junk.out");
00043
00044 static PRM_Template *
00045 getTemplates()
00046 {
00047 static PRM_Template *theTemplate = 0;
00048
00049 if (theTemplate)
00050 return theTemplate;
00051
00052 theTemplate = new PRM_Template[14];
00053 theTemplate[0] = PRM_Template(PRM_FILE, 1, &theFileName, &theFileDefault);
00054 theTemplate[1] = theRopTemplates[ROP_TPRERENDER_TPLATE];
00055 theTemplate[2] = theRopTemplates[ROP_PRERENDER_TPLATE];
00056 theTemplate[3] = theRopTemplates[ROP_LPRERENDER_TPLATE];
00057 theTemplate[4] = theRopTemplates[ROP_TPREFRAME_TPLATE];
00058 theTemplate[5] = theRopTemplates[ROP_PREFRAME_TPLATE];
00059 theTemplate[6] = theRopTemplates[ROP_LPREFRAME_TPLATE];
00060 theTemplate[7] = theRopTemplates[ROP_TPOSTFRAME_TPLATE];
00061 theTemplate[8] = theRopTemplates[ROP_POSTFRAME_TPLATE];
00062 theTemplate[9] = theRopTemplates[ROP_LPOSTFRAME_TPLATE];
00063 theTemplate[10] = theRopTemplates[ROP_TPOSTRENDER_TPLATE];
00064 theTemplate[11] = theRopTemplates[ROP_POSTRENDER_TPLATE];
00065 theTemplate[12] = theRopTemplates[ROP_LPOSTRENDER_TPLATE];
00066 theTemplate[13] = PRM_Template();
00067
00068 return theTemplate;
00069 }
00070
00071 OP_TemplatePair *
00072 ROP_Dumper::getTemplatePair()
00073 {
00074 static OP_TemplatePair *ropPair = 0;
00075 if (!ropPair)
00076 {
00077 OP_TemplatePair *base;
00078
00079 base = new OP_TemplatePair(getTemplates());
00080 ropPair = new OP_TemplatePair(ROP_Node::getROPbaseTemplate(), base);
00081 }
00082 return ropPair;
00083 }
00084
00085 OP_VariablePair *
00086 ROP_Dumper::getVariablePair()
00087 {
00088 static OP_VariablePair *pair = 0;
00089 if (!pair)
00090 pair = new OP_VariablePair(ROP_Node::myVariableList);
00091 return pair;
00092 }
00093
00094 OP_Node *
00095 ROP_Dumper::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00096 {
00097 return new ROP_Dumper(net, name, op);
00098 }
00099
00100 ROP_Dumper::ROP_Dumper(OP_Network *net, const char *name, OP_Operator *entry)
00101 : ROP_Node(net, name, entry)
00102 {
00103
00104 if (!ifdIndirect)
00105 ifdIndirect = allocIndirect(16);
00106 }
00107
00108
00109 ROP_Dumper::~ROP_Dumper()
00110 {
00111 }
00112
00113
00114
00115
00116
00117 int
00118 ROP_Dumper::startRender(int , float tstart, float tend)
00119 {
00120 myEndTime = tend;
00121 if (error() < UT_ERROR_ABORT)
00122 executePreRenderScript(tstart);
00123
00124 return 1;
00125 }
00126
00127 static void
00128 printNode(ostream &os, OP_Node *node, int indent)
00129 {
00130 UT_WorkBuffer wbuf;
00131 wbuf.sprintf("%*s", indent, "");
00132 os << wbuf.buffer() << node->getName() << endl;
00133
00134 for (int i=0; i<node->getNchildren(); ++i)
00135 printNode(os, node->getChild(i), indent+2);
00136 }
00137
00138 ROP_RENDER_CODE
00139 ROP_Dumper::renderFrame(float time, UT_Interrupt *)
00140 {
00141
00142 executePreFrameScript(time);
00143
00144
00145
00146 UT_String file_name;
00147 OUTPUT(file_name, time);
00148
00149 ofstream os(file_name);
00150 printNode(os, OPgetDirector(), 0);
00151 os.close();
00152
00153
00154 if (error() < UT_ERROR_ABORT)
00155 executePostFrameScript(time);
00156
00157 return ROP_CONTINUE_RENDER;
00158 }
00159
00160 ROP_RENDER_CODE
00161 ROP_Dumper::endRender()
00162 {
00163 if (error() < UT_ERROR_ABORT)
00164 executePostRenderScript(myEndTime);
00165 return ROP_CONTINUE_RENDER;
00166 }
00167
00168 void
00169 newDriverOperator(OP_OperatorTable *table)
00170 {
00171 table->addOperator(new OP_Operator("dumper",
00172 "Dump Tree",
00173 ROP_Dumper::myConstructor,
00174 ROP_Dumper::getTemplatePair(),
00175 0,
00176 0,
00177 ROP_Dumper::getVariablePair(),
00178 OP_FLAG_GENERATOR));
00179 }
00180