HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_BlindData.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
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  * The BlindData SOP. This SOP simply saves some additional information to the
27  * HIP file. It's cook method is simply copies the source geometry.
28  */
29 
30 #include "SOP_BlindData.h"
31 
32 #include <GU/GU_Detail.h>
33 #include <OP/OP_AutoLockInputs.h>
34 #include <OP/OP_Operator.h>
35 #include <OP/OP_OperatorTable.h>
36 #include <OP/OP_SaveFlags.h>
37 #include <PRM/PRM_Include.h>
38 
39 #include <UT/UT_CPIO.h> // For saving/loading need CPIO packets
40 #include <UT/UT_DSOVersion.h>
41 #include <UT/UT_StringStream.h>
42 
43 using namespace HDK_Sample;
44 
45 void
47 {
48  table->addOperator(new OP_Operator(
49  "hdk_blinddata",
50  "BlindData",
53  1,
54  1,
55  0));
56 }
57 
60  PRM_Template(),
61 };
62 
63 
64 OP_Node *
66 {
67  return new SOP_BlindData(net, name, op);
68 }
69 
71  : SOP_Node(net, name, op)
72 {
73  // This SOP does nothing to the input geometry, so it might as
74  // well not bump all data IDs when cooking.
76 }
77 
79 
82 {
83  // We must lock our inputs before we try to access their geometry.
84  // OP_AutoLockInputs will automatically unlock our inputs when we return.
85  // NOTE: Don't call unlockInputs yourself when using this!
86  OP_AutoLockInputs inputs(this);
87  if (inputs.lock(context) >= UT_ERROR_ABORT)
88  return error();
89 
90  duplicateSource(0, context);
91 
92  return error();
93 }
94 
95 const char *
97 {
98  return "Source Geometry";
99 }
100 
101 static const char *theExtension = "mydata";
102 
103 OP_ERROR
104 SOP_BlindData::save(std::ostream &os, const OP_SaveFlags &flags,
105  const char *path_prefix, const UT_String &name_override)
106 {
107  UT_CPIO packet;
108 
109  clearErrors();
110 
111  // First, let the base class save its stuff.
112  if (SOP_Node::save(os, flags, path_prefix, name_override) >= UT_ERROR_ABORT)
113  return error();
114 
115  UT_OStringStream ts;
116  ts << path_prefix << getName() << "." << theExtension << std::ends;
117  packet.open(os, ts.str().buffer());
118  savePrivateData(os, flags.getBinary());
119  packet.close(os);
120 
121  return error();
122 }
123 
124 bool
125 SOP_BlindData::load(UT_IStream &is, const char *extension, const char *path)
126 {
127  if (!strcmp(extension, theExtension))
128  {
129  // Here's my blind data!
130  loadPrivateData(is);
131  return (error() < UT_ERROR_ABORT);
132  }
133  return SOP_Node::load(is, extension, path);
134 }
135 
136 int
137 SOP_BlindData::loadPrivateData(UT_IStream &is)
138 {
139  UT_String data;
140  bool result = data.load(is);
141  return !result ? 0 : 1;
142 }
143 
144 int
145 SOP_BlindData::savePrivateData(std::ostream &os, int binary)
146 {
147  UT_String data;
148  data = "This is my private data";
149  data.save(os, binary);
150  return !os ? 0 : 1;
151 }
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_BlindData.C:65
void newSopOperator(OP_OperatorTable *table)
Definition: SOP_BlindData.C:46
GLbitfield flags
Definition: glcorearb.h:1596
virtual int open(UT_IStream &is, UT_WorkBuffer &pathname)
virtual OP_ERROR error()
bool getBinary() const
Definition: OP_SaveFlags.h:20
const char * inputLabel(unsigned idx) const override
Definition: SOP_BlindData.C:96
OP_ERROR lock(OP_Context &context)
Locks all inputs.
GLboolean * data
Definition: glcorearb.h:131
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
SYS_FORCE_INLINE const char * buffer() const
UT_ErrorSeverity
Definition: UT_Error.h:25
An output stream object that owns its own string buffer storage.
**But if you need a result
Definition: thread.h:613
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
const UT_WorkBuffer & str()
Returns a read-only reference to the underlying UT_WorkBuffer.
bool load(UT_IStream &is)
Load string from stream. Use is.eof() to check eof status.
static PRM_Template myTemplateList[]
Definition: SOP_BlindData.h:43
bool load(UT_IStream &is, const char *extension, const char *path=0) override
OP_ERROR cookMySop(OP_Context &context) override
Definition: SOP_BlindData.C:81
bool load(UT_IStream &is, const char *extension, const char *path) override
SOP_NodeFlags mySopFlags
Definition: SOP_Node.h:1628
GLuint const GLchar * name
Definition: glcorearb.h:786
GLenum GLenum GLsizei void * table
Definition: glad.h:5129
void setManagesDataIDs(bool onOff)
Definition: SOP_NodeFlags.h:36
OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *path_prefix, const UT_String &name_override=UT_String()) override
void save(std::ostream &os, bool binary) const
Save string to stream. Saves as binary if binary is true.
virtual int close(UT_IStream &is)
SYS_FORCE_INLINE const UT_String & getName() const
SOP_BlindData(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_BlindData.C:70
OP_ERROR save(std::ostream &os, const OP_SaveFlags &flags, const char *pathPrefix, const UT_String &name_override=UT_String()) override
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
OP_ERROR duplicateSource(unsigned index, OP_Context &context, GU_Detail *gdp, bool clean=true)