HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ROP_Dumper.C
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2018
3 * Side Effects Software Inc. All rights reserved.
4 *
5 * Redistribution and use of Houdini Development Kit samples in source and
6 * binary forms, with or without modification, are permitted provided that the
7 * following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. The name of Side Effects Software may not be used to endorse or
11 * promote products derived from this software without specific prior
12 * written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 
26 #include "ROP_Dumper.h"
27 
28 #include <ROP/ROP_Error.h>
29 #include <ROP/ROP_Templates.h>
30 #include <SOP/SOP_Node.h>
31 
32 #include <OP/OP_Director.h>
33 #include <OP/OP_OperatorTable.h>
34 #include <PRM/PRM_Include.h>
35 #include <CH/CH_LocalVariable.h>
36 
37 #include <UT/UT_DSOVersion.h>
38 #include <UT/UT_OFStream.h>
39 
40 
41 using namespace HDK_Sample;
42 
43 int *ROP_Dumper::ifdIndirect = 0;
44 
45 static PRM_Name theFileName("file", "Save to file");
46 static PRM_Default theFileDefault(0, "junk.out");
47 
48 static PRM_Template *
49 getTemplates()
50 {
51  static PRM_Template *theTemplate = 0;
52 
53  if (theTemplate)
54  return theTemplate;
55 
56  theTemplate = new PRM_Template[14];
57  theTemplate[0] = PRM_Template(PRM_FILE, 1, &theFileName, &theFileDefault);
58  theTemplate[1] = theRopTemplates[ROP_TPRERENDER_TPLATE];
59  theTemplate[2] = theRopTemplates[ROP_PRERENDER_TPLATE];
60  theTemplate[3] = theRopTemplates[ROP_LPRERENDER_TPLATE];
61  theTemplate[4] = theRopTemplates[ROP_TPREFRAME_TPLATE];
62  theTemplate[5] = theRopTemplates[ROP_PREFRAME_TPLATE];
63  theTemplate[6] = theRopTemplates[ROP_LPREFRAME_TPLATE];
64  theTemplate[7] = theRopTemplates[ROP_TPOSTFRAME_TPLATE];
65  theTemplate[8] = theRopTemplates[ROP_POSTFRAME_TPLATE];
66  theTemplate[9] = theRopTemplates[ROP_LPOSTFRAME_TPLATE];
67  theTemplate[10] = theRopTemplates[ROP_TPOSTRENDER_TPLATE];
68  theTemplate[11] = theRopTemplates[ROP_POSTRENDER_TPLATE];
69  theTemplate[12] = theRopTemplates[ROP_LPOSTRENDER_TPLATE];
70  theTemplate[13] = PRM_Template();
71 
72  return theTemplate;
73 }
74 
77 {
78  static OP_TemplatePair *ropPair = 0;
79  if (!ropPair)
80  {
81  OP_TemplatePair *base;
82 
83  base = new OP_TemplatePair(getTemplates());
84  ropPair = new OP_TemplatePair(ROP_Node::getROPbaseTemplate(), base);
85  }
86  return ropPair;
87 }
88 
91 {
92  static OP_VariablePair *pair = 0;
93  if (!pair)
95  return pair;
96 }
97 
98 OP_Node *
100 {
101  return new ROP_Dumper(net, name, op);
102 }
103 
105  : ROP_Node(net, name, entry)
106 {
107 
108  if (!ifdIndirect)
109  ifdIndirect = allocIndirect(16);
110 }
111 
112 
114 {
115 }
116 
117 //------------------------------------------------------------------------------
118 // The startRender(), renderFrame(), and endRender() render methods are
119 // invoked by Houdini when the ROP runs.
120 
121 int
122 ROP_Dumper::startRender(int /*nframes*/, fpreal tstart, fpreal tend)
123 {
124  myEndTime = tend;
125  if (error() < UT_ERROR_ABORT)
126  executePreRenderScript(tstart);
127 
128  return 1;
129 }
130 
131 static void
132 printNode(std::ostream &os, OP_Node *node, int indent)
133 {
134  UT_WorkBuffer wbuf;
135  wbuf.sprintf("%*s", indent, "");
136  os << wbuf.buffer() << node->getName() << "\n";
137 
138  for (int i=0; i<node->getNchildren(); ++i)
139  printNode(os, node->getChild(i), indent+2);
140 }
141 
144 {
145  // Execute the pre-render script.
146  executePreFrameScript(time);
147 
148  // Evaluate the parameter for the file name and write something to the
149  // file.
150  UT_String file_name;
151  OUTPUT(file_name, time);
152 
153  UT_OFStream os(file_name);
154  printNode(os, OPgetDirector(), 0);
155  os.close();
156 
157  // Execute the post-render script.
158  if (error() < UT_ERROR_ABORT)
160 
161  return ROP_CONTINUE_RENDER;
162 }
163 
166 {
167  if (error() < UT_ERROR_ABORT)
168  executePostRenderScript(myEndTime);
169  return ROP_CONTINUE_RENDER;
170 }
171 
172 void
174 {
175  table->addOperator(new OP_Operator("hdk_dumper",
176  "Dump Tree",
179  0,
180  0,
183 }
184 
virtual OP_ERROR error()
const UT_String & getName() const
ROP_RENDER_CODE
Definition: ROP_Node.h:48
static OP_TemplatePair * getTemplatePair()
Provides access to our parm templates.
Definition: ROP_Dumper.C:76
static PRM_Template * getROPbaseTemplate()
ROP_Dumper(OP_Network *net, const char *name, OP_Operator *entry)
Definition: ROP_Dumper.C:104
#define OP_FLAG_GENERATOR
Definition: OP_Operator.h:67
virtual ROP_RENDER_CODE renderFrame(fpreal time, UT_Interrupt *boss)
Definition: ROP_Dumper.C:143
void close()
Close the stream.
Definition: UT_OFStream.h:79
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
png_uint_32 i
Definition: png.h:2877
virtual OP_Node * getChild(const char *name, int *hint=0) const
virtual int getNchildren() const
ROP_API PRM_Template theRopTemplates[]
static CH_LocalVariable myVariableList[]
Definition: ROP_Node.h:267
PRM_API const PRM_Type PRM_FILE
bool executePostRenderScript(fpreal ttime)
virtual int startRender(int nframes, fpreal s, fpreal e)
Definition: ROP_Dumper.C:122
GLuint const GLchar * name
Definition: glcorearb.h:785
Portable replacement for std::ofstream.
Definition: UT_OFStream.h:26
void OUTPUT(UT_String &str, fpreal t)
A convenience method to evaluate our custom file parameter.
Definition: ROP_Dumper.h:85
static OP_VariablePair * getVariablePair()
Provides access to our variables.
Definition: ROP_Dumper.C:90
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
static OP_Node * myConstructor(OP_Network *net, const char *name, OP_Operator *op)
Creates an instance of this node.
Definition: ROP_Dumper.C:99
double fpreal
Definition: SYS_Types.h:269
int * allocIndirect(int size=64)
OP_API OP_Director * OPgetDirector()
const char * buffer() const
bool executePreRenderScript(fpreal ttime)
void newDriverOperator(OP_OperatorTable *table)
Definition: ROP_Dumper.C:173
bool executePreFrameScript(fpreal ttime)
virtual ROP_RENDER_CODE endRender()
Definition: ROP_Dumper.C:165
bool executePostFrameScript(fpreal ttime)