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 IECOREMAYA_LIVESCENE_H
36 #define IECOREMAYA_LIVESCENE_H
37 
38 #include "boost/function.hpp"
39 #include "tbb/mutex.h"
40 
41 #include "IECore/SceneInterface.h"
42 #include "IECoreMaya/TypeIds.h"
43 
44 #include "maya/MDagPath.h"
45 
46 namespace IECoreMaya
47 {
48 
49 IE_CORE_FORWARDDECLARE( LiveScene );
50 
60 
62 {
63  public :
64 
65  IE_CORE_DECLARERUNTIMETYPEDEXTENSION( LiveScene, LiveSceneTypeId, IECore::SceneInterface );
66 
67  // default constructor
68  LiveScene();
69 
70  virtual ~LiveScene();
71 
72  virtual std::string fileName() const;
73 
75  virtual Name name() const;
77  virtual void path( Path &p ) const;
78 
79  /*
80  * Bounding box
81  */
82 
85  virtual Imath::Box3d readBound( double time ) const;
87  virtual void writeBound( const Imath::Box3d &bound, double time );
88 
89  /*
90  * Transform
91  */
92 
95  virtual IECore::ConstDataPtr readTransform( double time ) const;
98  virtual Imath::M44d readTransformAsMatrix( double time ) const;
100  virtual void writeTransform( const IECore::Data *transform, double time );
101 
102  /*
103  * Attributes
104  */
105 
106  virtual bool hasAttribute( const Name &name ) const;
108  virtual void attributeNames( NameList &attrs ) const;
110  virtual IECore::ConstObjectPtr readAttribute( const Name &name, double time ) const;
112  virtual void writeAttribute( const Name &name, const IECore::Object *attribute, double time );
113 
114  /*
115  * Tags
116  */
117 
119  virtual bool hasTag( const Name &name, int filter = SceneInterface::LocalTag ) const;
121  virtual void readTags( NameList &tags, int filter = SceneInterface::LocalTag ) const;
123  virtual void writeTags( const NameList &tags );
124 
125  /*
126  * Object
127  */
128 
130  virtual bool hasObject() const;
133  virtual IECore::ConstObjectPtr readObject( double time ) const;
136  virtual IECore::PrimitiveVariableMap readObjectPrimitiveVariables( const std::vector<IECore::InternedString> &primVarNames, double time ) const;
138  virtual void writeObject( const IECore::Object *object, double time );
139 
140  /*
141  * Hierarchy
142  */
143 
146  virtual void childNames( NameList &childNames ) const;
148  virtual bool hasChild( const Name &name ) const;
155  virtual IECore::SceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing );
157  virtual IECore::ConstSceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
161  virtual IECore::SceneInterfacePtr createChild( const Name &name );
162 
163 
165  virtual IECore::SceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing );
166 
168  virtual IECore::ConstSceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
169 
171  virtual void hash( HashType hashType, double time, IECore::MurmurHash &h ) const;
172 
173  typedef boost::function<bool (const MDagPath &)> HasFn;
174  typedef boost::function<IECore::ConstObjectPtr (const MDagPath &)> ReadFn;
175  typedef boost::function<IECore::ConstObjectPtr (const MDagPath &, const Name &)> ReadAttrFn;
176  typedef boost::function<bool (const MDagPath &, const Name &, int )> HasTagFn;
177  typedef boost::function<void (const MDagPath &, NameList &, int)> ReadTagsFn;
178  typedef boost::function<void (const MDagPath &, NameList &)> NamesFn;
179  typedef boost::function<bool (const MDagPath &, const Name &)> MightHaveFn;
180 
181  // Register callbacks for custom objects.
182  // The has function will be called during hasObject and it stops in the first one that returns true.
183  // The read method is called if the has method returns true, so it should return a valid Object pointer or raise an Exception.
184  static void registerCustomObject( HasFn hasFn, ReadFn readFn );
185 
186  // Register callbacks for custom attributes.
187  // The names function will be called during attributeNames and hasAttribute.
188  // The readAttr method is called if the names method returns the expected attribute, so it should return a valid Object pointer or raise an Exception.
189  // If the mightHave function is specified, it will be called before names function for early out, to see if the names function can return the expected attribute.
190  static void registerCustomAttributes( NamesFn namesFn, ReadAttrFn readFn );
191  static void registerCustomAttributes( NamesFn namesFn, ReadAttrFn readFn, MightHaveFn mightHaveFn);
192 
193  // Register callbacks for nodes to define custom tags
194  // The functions will be called during hasTag and readTags.
195  // readTags will return the union of all custom ReadTagsFns.
196  static void registerCustomTags( HasTagFn hasFn, ReadTagsFn readFn );
197 
198  private :
199 
200  IECore::SceneInterfacePtr retrieveScene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
201  IECore::SceneInterfacePtr retrieveChild( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const;
202  IECore::SceneInterfacePtr retrieveParent() const;
203 
204  void getChildDags( const MDagPath& dagPath, MDagPathArray& paths ) const;
205 
207  struct CustomReader
208  {
209  HasFn m_has;
210  ReadFn m_read;
211  };
212 
214  struct CustomTagReader
215  {
216  HasTagFn m_has;
217  ReadTagsFn m_read;
218  };
219 
221  struct CustomAttributeReader
222  {
223  NamesFn m_names;
224  ReadAttrFn m_read;
225  MightHaveFn m_mightHave;
226  };
227 
228  static std::vector< CustomReader > &customObjectReaders();
229  static std::vector< CustomAttributeReader > &customAttributeReaders();
230  static std::vector< CustomTagReader > &customTagReaders();
231 
232  protected:
233 
234  // constructor for a specific dag path:
235  LiveScene( const MDagPath& p, bool isRoot = false );
236 
237  MDagPath m_dagPath;
238  bool m_isRoot;
239 
242  virtual LiveScenePtr duplicate( const MDagPath& p, bool isRoot = false ) const;
243 
244  typedef tbb::mutex Mutex;
245  static Mutex s_mutex;
246 
247 };
248 
249 IE_CORE_DECLAREPTR( LiveScene )
250 
251 } // namespace IECoreMaya
252 
253 #endif // IECOREMAYA_LIVESCENE_H
virtual void path(Path &p) const
Returns the tokenized dag path this instance is referring to.
virtual IECore::ConstObjectPtr readAttribute(const Name &name, double time) const
Returns the attribute value at the given time, which must be equal to the current maya time in second...
virtual bool hasAttribute(const Name &name) const
Convenience method to determine if an attribute exists without reading it.
virtual bool hasTag(const Name &name, int filter=SceneInterface::LocalTag) const
Uses the custom registered tags to return whether a given tag is present in the scene location or not...
Definition: Data.h:46
virtual void attributeNames(NameList &attrs) const
Fills attrs with the names of all attributes available in the current directory.
virtual IECore::PrimitiveVariableMap readObjectPrimitiveVariables(const std::vector< IECore::InternedString > &primVarNames, double time) const
virtual LiveScenePtr duplicate(const MDagPath &p, bool isRoot=false) const
virtual void writeTransform(const IECore::Data *transform, double time)
Not currently supported - will throw an exception.
Definition: Object.h:104
virtual void hash(HashType hashType, double time, IECore::MurmurHash &h) const
Currently raises an exception.
virtual Imath::Box3d readBound(double time) const
virtual bool hasChild(const Name &name) const
Queries weather the named child exists.
virtual IECore::SceneInterfacePtr scene(const Path &path, MissingBehaviour missingBehaviour=SceneInterface::ThrowIfMissing)
Returns an object for querying the scene at the given path (full path).
Definition: MurmurHash.h:64
virtual Imath::M44d readTransformAsMatrix(double time) const
virtual IECore::ConstObjectPtr readObject(double time) const
virtual IECore::SceneInterfacePtr child(const Name &name, MissingBehaviour missingBehaviour=SceneInterface::ThrowIfMissing)
virtual void writeObject(const IECore::Object *object, double time)
Not currently supported - will throw an exception.
Definition: LiveScene.h:61
HashType
Definition: SceneInterface.h:94
virtual void childNames(NameList &childNames) const
Definition: SceneInterface.h:69
virtual void readTags(NameList &tags, int filter=SceneInterface::LocalTag) const
Uses the custom registered tags to list all the tags present in the scene location.
virtual std::string fileName() const
Returns the file that this scene is mapped to. Throws exception if there's no file.
The IECoreMaya namespace holds all the functionality of libIECoreMaya.
Definition: BoolParameterHandler.h:44
virtual void writeTags(const NameList &tags)
Not currently supported - will throw an exception.
Definition: InternedString.h:55
virtual bool hasObject() const
Checks if there are objects in the scene (convertible from Maya or registered as custom objects) ...
virtual void writeBound(const Imath::Box3d &bound, double time)
Not currently supported - will throw an exception.
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
std::map< std::string, PrimitiveVariable > PrimitiveVariableMap
A simple type to hold named PrimitiveVariables.
Definition: PrimitiveVariable.h:107
virtual IECore::SceneInterfacePtr createChild(const Name &name)
virtual void writeAttribute(const Name &name, const IECore::Object *attribute, double time)
Not currently supported - will throw an exception.