HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
COP_SlapcompDispatcher.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #pragma once
9 
10 #include "COP_API.h"
11 
13 
14 /// This class is a polymorphic slapcomp manager that can be used to interface
15 /// with different types of slapcomps. To this end, a factory must be registered
16 /// with the static installFactory() method, with a checker and an allocator.
17 /// When a manager gets enabled with a specific node, the first factory (i.e.
18 /// one registered earliest) whose check the node passes will be used to run it.
20 {
21 public:
23 
24  /// Should return true for nodes that are supported by the slapcomp type.
25  using CheckFunction = bool (*)(const OP_Node*);
26  /// Should dynamically allocate a new slapcomp manager for the slapcomp
27  /// type.
28  using AllocationFunction = COP_SlapcompManager* (*)();
29  /// Call this function to register a slapcomp factory.
30  /// The checker function should return true for a node if that slapcomp
31  /// manager should be used for it.
32  static void installFactory(CheckFunction checker,
33  AllocationFunction allocator);
34 
35 private:
36  /// List of available options for slapcomp.
37  struct Factory
38  {
39  CheckFunction myCheck;
40  AllocationFunction myAlloc;
41  };
42  static UT_Array<Factory> theFactories;
43 
44  /// Given a node, returns index of the factory that is appropriate for it.
45  /// Will return -1
46  static int getFactoryIndex(int target_node_id);
47 
48 public:
54 
55  /// Makes this object a copy of other, including the enable state.
56  void copyFrom(const COP_SlapcompDispatcher& other,
57  const OP_Context& context);
58 
59  void enable(int target_node_id, const OP_Context&) override;
60  void enable(OP_Node *const node, const OP_Context &ctx)
61  { enable(node->getUniqueId(), ctx); }
62  void disable() override;
63  bool isEnabled() const override;
64  bool hasErrors() const override;
65  int getTargetNode() const override;
66 
67  void setErrorCallback(void (*cb)(void*, const char*), void* data) override;
68  void setWarningCallback(void (*cb)(void*, const char*), void* data)
69  override;
70  void setRunCallback(void (*cb)(void*), void* data) override;
71  void setUpdateCallback(void (*cb)(void*), void* data) override;
72 
73  bool isSlapcompAOV(const UT_StringHolder& name) const override;
74 
75  bool buildForInputs(const COP_CableStructure& inputs,
76  const OP_Context& context) override;
77  void runSlapcompImpl(COP_SlapcompInputFetcher& input_fetcher,
78  const OP_Context& context) override;
79 
80  COP_CableStructure getOutputStructure() const override;
81  IMX_LayerPtr getOutputLayer(const UT_StringHolder& name) const override;
82 
83  int getVersion() const override
84  {
85  return myVersion;
86  }
87  bool hasStateChanged() const override
88  {
89  return myStateChanged;
90  }
91 
92 public:
93  void setVersion(int version) override
94  {
95  myVersion = version;
96  }
97 
98 protected:
99  void reportError(const char* message) override;
100  void reportWarning(const char* message) override;
101 
102 protected:
105  int myCurrentType = -1;
106 
107  int myVersion = 0;
108  bool myStateChanged = false;
109 };
110 
virtual IMX_LayerPtr getOutputLayer(const UT_StringHolder &name) const =0
Returns a particular output by name.
int getUniqueId() const
Definition: OP_Node.h:750
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
void setVersion(int version) override
virtual void setUpdateCallback(void(*cb)(void *), void *data)=0
Sets a callback that gets called when slapcomp changes.
bool hasStateChanged() const override
virtual COP_CableStructure getOutputStructure() const =0
Should return the outputs that this slapcomp produces.
COP_SlapcompManager & operator=(const COP_SlapcompManager &)=delete
virtual bool isEnabled() const =0
Returns the on-off state of slapcomp.
ImageBuf OIIO_API checker(int width, int height, int depth, cspan< float > color1, cspan< float > color2, int xoffset, int yoffset, int zoffset, ROI roi, int nthreads=0)
OutGridT const XformOp bool bool
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
int getVersion() const override
GLuint const GLchar * name
Definition: glcorearb.h:786
Interface for getting IMX_Layer inputs for a slapcomp program on demand.
virtual void reportWarning(const char *message)=0
Reports a warning (through the callback if possible).
Abstract interface for managing slapcomp.
UT_UniquePtr< COP_SlapcompManager > myManager
virtual void reportError(const char *message)=0
Reports an error (through the callback if possible).
GT_API const UT_StringHolder version
virtual bool isSlapcompAOV(const UT_StringHolder &name) const =0
virtual bool hasErrors() const =0
Returns true if the last run of slapcomp had errors.
bool(*)(const OP_Node *) CheckFunction
Should return true for nodes that are supported by the slapcomp type.
virtual void setWarningCallback(void(*cb)(void *, const char *), void *data)=0
Sets a callback that gets called when reporting slapcomp warnings.
virtual void setErrorCallback(void(*cb)(void *, const char *), void *data)=0
Sets a callback that gets called when reporting slapcomp errors.
virtual void enable(int target_node_id, const OP_Context &)=0
Enable slapcomp with the given node.
#define COP_API
Definition: COP_API.h:8
virtual bool buildForInputs(const COP_CableStructure &inputs, const OP_Context &context)=0
Prepares for applying slapcomp for inputs of the given types.
virtual void disable()=0
Disable slapcomp.
virtual int getTargetNode() const =0
Returns the id of the node slapcomp was built from.
void enable(OP_Node *const node, const OP_Context &ctx)
virtual void setRunCallback(void(*cb)(void *), void *data)=0
Sets a callback that gets called when slapcomp is run.
UT_SharedPtr< IMX_Layer > IMX_LayerPtr
Definition: IMX_Layer.h:26
Definition: format.h:1821
virtual void runSlapcompImpl(COP_SlapcompInputFetcher &input_fetcher, const OP_Context &context)=0
Should run slapcomp with the specified inputs and context.