Cortex  10.0.0-a4
LiveScene.h
1 //
3 // Copyright (c) 2013-2014, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IECOREHOUDINI_LIVESCENE_H
36 #define IECOREHOUDINI_LIVESCENE_H
37 
38 #include "OP/OP_Node.h"
39 #include "UT/UT_String.h"
40 
41 #include "IECore/SceneInterface.h"
42 
43 #include "IECoreHoudini/DetailSplitter.h"
44 #include "IECoreHoudini/TypeIds.h"
45 
46 namespace IECoreHoudini
47 {
48 
49 IE_CORE_FORWARDDECLARE( LiveScene );
50 
55 {
56  public :
57 
58  IE_CORE_DECLARERUNTIMETYPEDEXTENSION( LiveScene, LiveSceneTypeId, IECore::SceneInterface );
59 
60  LiveScene();
61  LiveScene( const UT_String &nodePath, const Path &contentPath, const Path &rootPath, double defaultTime = std::numeric_limits<double>::infinity() );
62 
63  virtual ~LiveScene();
64 
65  virtual std::string fileName() const;
66 
67  virtual Name name() const;
68  virtual void path( Path &p ) const;
69 
70  virtual Imath::Box3d readBound( double time ) const;
71  virtual void writeBound( const Imath::Box3d &bound, double time );
72 
73  virtual IECore::ConstDataPtr readTransform( double time ) const;
74  virtual Imath::M44d readTransformAsMatrix( double time ) const;
76  IECore::ConstDataPtr readWorldTransform( double time ) const;
77  Imath::M44d readWorldTransformAsMatrix( double time ) const;
78  virtual void writeTransform( const IECore::Data *transform, double time );
79 
80  virtual bool hasAttribute( const Name &name ) const;
81  virtual void attributeNames( NameList &attrs ) const;
82  virtual IECore::ConstObjectPtr readAttribute( const Name &name, double time ) const;
83  virtual void writeAttribute( const Name &name, const IECore::Object *attribute, double time );
84 
85  virtual bool hasTag( const Name &name, int filter = SceneInterface::LocalTag ) const;
86  virtual void readTags( NameList &tags, int filter = SceneInterface::LocalTag ) const;
87  virtual void writeTags( const NameList &tags );
88 
89  virtual bool hasObject() const;
90  virtual IECore::ConstObjectPtr readObject( double time ) const;
91  virtual IECore::PrimitiveVariableMap readObjectPrimitiveVariables( const std::vector<IECore::InternedString> &primVarNames, double time ) const;
92  virtual void writeObject( const IECore::Object *object, double time );
93 
94  virtual void childNames( NameList &childNames ) const;
95  virtual bool hasChild( const Name &name ) const;
96  virtual IECore::SceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing );
97  virtual IECore::ConstSceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
98  virtual IECore::SceneInterfacePtr createChild( const Name &name );
99 
100  virtual IECore::SceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing );
101  virtual IECore::ConstSceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
102 
104  virtual void hash( HashType hashType, double time, IECore::MurmurHash &h ) const;
105 
107  const OP_Node *node() const;
108 
110  bool embedded() const;
111 
117  double getDefaultTime() const;
118  void setDefaultTime( double time );
119 
122  static PRM_Name pTags;
123 
124  typedef boost::function<bool (const OP_Node *)> HasFn;
125  typedef boost::function<IECore::ConstObjectPtr (const OP_Node *, double &)> ReadFn;
126  typedef boost::function<IECore::ConstObjectPtr (const OP_Node *, const Name &, double &)> ReadAttrFn;
127  typedef boost::function<bool (const OP_Node *, const Name &, int)> HasTagFn;
128  typedef boost::function<void (const OP_Node *, NameList &, int)> ReadTagsFn;
129  typedef boost::function<void (const OP_Node *, NameList &)> ReadNamesFn;
130 
131  // Register callbacks for custom named attributes.
132  // The names function will be called during attributeNames and hasAttribute.
133  // The read method is called if the names method returns the expected attribute, so it should return a valid Object pointer or raise an Exception.
134  static void registerCustomAttributes( ReadNamesFn namesFn, ReadAttrFn readFn );
135 
136  // Register callbacks for nodes to define custom tags
137  // The functions will be called during hasTag and readTags.
138  // readTags will return the union of all custom ReadTagsFns.
139  static void registerCustomTags( HasTagFn hasFn, ReadTagsFn readFn );
140 
141 
142  protected :
143 
144  LiveScene( const UT_String &nodePath, const Path &contentPath, const Path &rootPath, const LiveScene& parent);
145 
146  virtual LiveScenePtr create() const;
147  virtual LiveScenePtr duplicate( const UT_String &nodePath, const Path &contentPath, const Path &rootPath) const;
148 
149  private :
150 
151  void constructCommon( const UT_String &nodePath, const Path &contentPath, const Path &rootPath, DetailSplitter *splitter );
152 
153  OP_Node *retrieveNode( bool content = false, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
154  OP_Node *locateContent( OP_Node *node ) const;
155  OP_Node *retrieveChild( const Name &name, Path &contentPath, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
156  IECore::SceneInterfacePtr retrieveScene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
157  bool hasInput( const OP_Node *node ) const;
158  // We need to adjust the time internally, because SceneInterfaces treat time
159  // starting at Frame 0, while Houdini treats time starting at Frame 1.
160  double adjustTime( double time ) const;
161  double adjustedDefaultTime() const;
162 
163  void calculatePath( const Path &contentPath, const Path &rootPath );
164  const char *matchPath( const char *value ) const;
165  bool matchPattern( const char *value, const char *pattern ) const;
166  std::pair<const char *, size_t> nextWord( const char *value ) const;
167  void relativeContentPath( IECore::SceneInterface::Path &path ) const;
168  GU_DetailHandle contentHandle() const;
169 
171  struct CustomAttributeReader
172  {
173  ReadNamesFn m_names;
174  ReadAttrFn m_read;
175  };
176 
178  struct CustomTagReader
179  {
180  HasTagFn m_has;
181  ReadTagsFn m_read;
182  };
183 
184  static std::vector<CustomAttributeReader> &customAttributeReaders();
185  static std::vector<CustomTagReader> &customTagReaders();
186 
187  UT_String m_nodePath;
188  size_t m_rootIndex;
189  size_t m_contentIndex;
190  IECore::SceneInterface::Path m_path;
191 
192  // used by instances which track the hierarchy inside a SOP
193  mutable DetailSplitterPtr m_splitter;
194 
195  // used as the default cook time for methods that do not accept a time
196  double m_defaultTime;
197 
198 };
199 
200 } // namespace IECoreHoudini
201 
202 #endif // IECOREHOUDINI_LIVESCENE_H
virtual bool hasAttribute(const Name &name) const
Convenience method to determine if an attribute exists without reading it.
Definition: Data.h:46
double getDefaultTime() const
virtual IECore::PrimitiveVariableMap readObjectPrimitiveVariables(const std::vector< IECore::InternedString > &primVarNames, double time) const
Definition: LiveScene.h:54
The IECoreHoudini namespace holds all the functionality of libIECoreHoudini.
Definition: CoreHoudini.h:51
virtual bool hasChild(const Name &name) const
Convenience method to determine if a child exists.
virtual void writeBound(const Imath::Box3d &bound, double time)
bool embedded() const
Convenience method to determine if this scene refers to hierarchy embedded inside a SOP...
Definition: Object.h:104
virtual bool hasTag(const Name &name, int filter=SceneInterface::LocalTag) const
const OP_Node * node() const
Convenience method to access the Houdini node this scene refers to.
virtual IECore::ConstObjectPtr readAttribute(const Name &name, double time) const
Returns the attribute value at the given time.
virtual Imath::Box3d readBound(double time) const
virtual Name name() const
Returns the name of the scene location which this instance is referring to. The root path returns "/"...
virtual IECore::ConstDataPtr readTransform(double time) const
IECore::ConstDataPtr readWorldTransform(double time) const
Definition: MurmurHash.h:64
virtual std::string fileName() const
Returns the file that this scene is mapped to. Throws exception if there's no file.
virtual void writeTransform(const IECore::Data *transform, double time)
static PRM_Name pTags
Definition: LiveScene.h:122
virtual void hash(HashType hashType, double time, IECore::MurmurHash &h) const
Currently raises an exception.
HashType
Definition: SceneInterface.h:94
virtual void writeObject(const IECore::Object *object, double time)
Definition: SceneInterface.h:69
virtual IECore::SceneInterfacePtr createChild(const Name &name)
virtual IECore::SceneInterfacePtr child(const Name &name, MissingBehaviour missingBehaviour=SceneInterface::ThrowIfMissing)
Definition: InternedString.h:55
Definition: DetailSplitter.h:52
virtual Imath::M44d readTransformAsMatrix(double time) const
virtual IECore::ConstObjectPtr readObject(double time) const
Reads the object stored at this path in the scene at the given time.
static const Path & rootPath
Utility variable that can be used anytime you want to refer to the root path in the Scene...
Definition: SceneInterface.h:106
virtual void writeAttribute(const Name &name, const IECore::Object *attribute, double time)
virtual bool hasObject() const
Convenience method to determine if a piece of geometry exists without reading it. ...
std::map< std::string, PrimitiveVariable > PrimitiveVariableMap
A simple type to hold named PrimitiveVariables.
Definition: PrimitiveVariable.h:107