Cortex  10.0.0-a4
SceneInterface.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 IECORE_SCENEINTERFACE_H
36 #define IECORE_SCENEINTERFACE_H
37 
38 #include "OpenEXR/ImathBox.h"
39 #include "OpenEXR/ImathMatrix.h"
40 
41 #include "IECore/Export.h"
42 #include "IECore/Object.h"
43 #include "IECore/Renderable.h"
44 #include "IECore/PrimitiveVariable.h"
45 
46 namespace IECore
47 {
48 
49 IE_CORE_FORWARDDECLARE( SceneInterface );
50 
69 class IECORE_API SceneInterface : public RunTimeTyped
70 {
71  public :
72 
73  IE_CORE_DECLARERUNTIMETYPED( SceneInterface, RunTimeTyped );
74 
75  typedef IndexedIO::EntryID Name;
76  typedef IndexedIO::EntryIDList NameList;
77  typedef IndexedIO::EntryIDList Path;
78 
79  typedef enum {
80  ThrowIfMissing = IndexedIO::ThrowIfMissing,
81  NullIfMissing = IndexedIO::NullIfMissing,
82  CreateIfMissing = IndexedIO::CreateIfMissing
83  } MissingBehaviour;
84 
85  enum TagFilter {
86  DescendantTag = 1,
87  LocalTag = 2,
88  AncestorTag = 4,
89  EveryTag = DescendantTag | LocalTag | AncestorTag
90  };
91 
94  enum HashType {
95  TransformHash,
96  AttributesHash,
97  BoundHash,
98  ObjectHash,
99  ChildNamesHash,
100  HierarchyHash,
101  };
102 
104  static const Name &rootName;
106  static const Path &rootPath;
108  static const Name &visibilityName;
109 
117  static SceneInterfacePtr create(const std::string &path, IndexedIO::OpenMode mode);
118 
121  static std::vector<std::string> supportedExtensions( IndexedIO::OpenMode modes = IndexedIO::Read|IndexedIO::Write|IndexedIO::Append );
122 
126  template< class T >
128  {
129  public :
130  FileFormatDescription(const std::string &extension, IndexedIO::OpenMode modes);
131 
132  private :
133  static SceneInterfacePtr creator( const std::string &fileName, IndexedIO::OpenMode mode );
134  };
135 
136  ~SceneInterface() override = 0;
137 
139  virtual std::string fileName() const = 0;
140 
142  virtual Name name() const = 0;
144  virtual void path( Path &p ) const = 0;
145 
146  /*
147  * Bounding box
148  */
149 
152  virtual bool hasBound() const;
156  virtual Imath::Box3d readBound( double time ) const = 0;
161  virtual void writeBound( const Imath::Box3d &bound, double time ) = 0;
162 
163  /*
164  * Transform
165  */
166 
169  virtual ConstDataPtr readTransform( double time ) const = 0;
172  virtual Imath::M44d readTransformAsMatrix( double time ) const = 0;
176  virtual void writeTransform( const Data *transform, double time ) = 0;
177 
178  /*
179  * Attributes
180  */
181 
183  virtual bool hasAttribute( const Name &name ) const = 0;
185  virtual void attributeNames( NameList &attrs ) const = 0;
187  virtual ConstObjectPtr readAttribute( const Name &name, double time ) const = 0;
190  virtual void writeAttribute( const Name &name, const Object *attribute, double time ) = 0;
191 
192  /*
193  * Tags
194  */
195 
199  virtual bool hasTag( const Name &name, int filter = LocalTag ) const = 0;
203  virtual void readTags( NameList &tags, int filter = LocalTag ) const = 0;
205  virtual void writeTags( const NameList &tags ) = 0;
206 
207  /*
208  * Object
209  */
210 
212  virtual bool hasObject() const = 0;
214  virtual ConstObjectPtr readObject( double time ) const = 0;
217  virtual PrimitiveVariableMap readObjectPrimitiveVariables( const std::vector<InternedString> &primVarNames, double time ) const = 0;
220  virtual void writeObject( const Object *object, double time ) = 0;
221 
222  /*
223  * Hierarchy
224  */
225 
227  virtual bool hasChild( const Name &name ) const = 0;
230  virtual void childNames( NameList &childNames ) const = 0;
237  virtual SceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = ThrowIfMissing ) = 0;
239  virtual ConstSceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = ThrowIfMissing ) const = 0;
243  virtual SceneInterfacePtr createChild( const Name &name ) = 0;
245  virtual SceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = ThrowIfMissing ) = 0;
247  virtual ConstSceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = ThrowIfMissing ) const = 0;
248 
249  /*
250  * Hash
251  */
252 
260  virtual void hash( HashType hashType, double time, MurmurHash &h ) const;
261 
262  /*
263  * Utility functions
264  */
265 
267  static void pathToString( const Path &p, std::string &path );
272  static void stringToPath( const std::string &path, Path &p );
273 
274  protected:
275 
276  typedef SceneInterfacePtr (*CreatorFn)(const std::string &, IndexedIO::OpenMode );
277  class CreatorMap;
278  static CreatorMap &fileCreators();
279  static void registerCreator( const std::string &extension, IndexedIO::OpenMode modes, CreatorFn f );
280 
281 };
282 
283 } // namespace IECore
284 
285 #include "IECore/SceneInterface.inl"
286 
287 #endif // IECORE_SCENEINTERFACE_H
static const Name & rootName
Constant name assigned to the root location "/".
Definition: SceneInterface.h:104
Definition: Data.h:46
Definition: Object.h:104
static const Name & visibilityName
Name of the visibility attribute.
Definition: SceneInterface.h:108
Definition: SceneInterface.h:127
Definition: MurmurHash.h:64
HashType
Definition: SceneInterface.h:94
Definition: SceneInterface.h:69
Definition: InternedString.h:55
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
Definition: RunTimeTyped.h:211
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43
std::map< std::string, PrimitiveVariable > PrimitiveVariableMap
A simple type to hold named PrimitiveVariables.
Definition: PrimitiveVariable.h:107