Cortex  10.0.0-a4
LinkedScene.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_LINKEDSCENE_H
36 #define IECORE_LINKEDSCENE_H
37 
38 #include "IECore/Export.h"
39 #include "IECore/SampledSceneInterface.h"
40 #include "IECore/SimpleTypedData.h"
41 #include "IECore/VectorTypedData.h"
42 
43 namespace IECore
44 {
45 
46 IE_CORE_FORWARDDECLARE( LinkedScene );
47 //IE_CORE_FORWARDDECLARE( StringData );
48 //IE_CORE_FORWARDDECLARE( InternedStringVectorData );
49 
64 class IECORE_API LinkedScene : public SampledSceneInterface
65 {
66  public :
67 
68  IE_CORE_DECLARERUNTIMETYPED( LinkedScene, SampledSceneInterface );
69 
71  // by this class when expanding linked scenes.
72  static const Name &linkAttribute;
73 
74  static const Name &fileNameLinkAttribute;
75  static const Name &rootLinkAttribute;
76  static const Name &timeLinkAttribute;
77 
81  LinkedScene( const std::string &fileName, IndexedIO::OpenMode mode );
82 
85  LinkedScene( ConstSceneInterfacePtr mainScene );
86 
87  ~LinkedScene() override;
88 
92  void writeLink( const SceneInterface *scene );
93 
95  static IECore::CompoundDataPtr linkAttributeData( const SceneInterface *scene );
96 
99  static IECore::CompoundDataPtr linkAttributeData( const SceneInterface *scene, double time );
100 
101  /*
102  * virtual functions defined in SceneInterface.
103  */
104 
105  std::string fileName() const override;
106 
107  Name name() const override;
108  void path( Path &p ) const override;
109 
110  size_t numBoundSamples() const override;
111  double boundSampleTime( size_t sampleIndex ) const override;
112  double boundSampleInterval( double time, size_t &floorIndex, size_t &ceilIndex ) const override;
113  Imath::Box3d readBoundAtSample( size_t sampleIndex ) const override;
114  Imath::Box3d readBound( double time ) const override;
115  void writeBound( const Imath::Box3d &bound, double time ) override;
116 
117  size_t numTransformSamples() const override;
118  double transformSampleTime( size_t sampleIndex ) const override;
119  double transformSampleInterval( double time, size_t &floorIndex, size_t &ceilIndex ) const override;
120  ConstDataPtr readTransformAtSample( size_t sampleIndex ) const override;
121  Imath::M44d readTransformAsMatrixAtSample( size_t sampleIndex ) const override;
122  ConstDataPtr readTransform( double time ) const override;
123  Imath::M44d readTransformAsMatrix( double time ) const override;
124  void writeTransform( const Data *transform, double time ) override;
125 
126  bool hasAttribute( const Name &name ) const override;
127  void attributeNames( NameList &attrs ) const override;
128  size_t numAttributeSamples( const Name &name ) const override;
129  double attributeSampleTime( const Name &name, size_t sampleIndex ) const override;
130  double attributeSampleInterval( const Name &name, double time, size_t &floorIndex, size_t &ceilIndex ) const override;
131  ConstObjectPtr readAttributeAtSample( const Name &name, size_t sampleIndex ) const override;
132  ConstObjectPtr readAttribute( const Name &name, double time ) const override;
133  void writeAttribute( const Name &name, const Object *attribute, double time ) override;
134 
135  bool hasTag( const Name &name, int filter = SceneInterface::LocalTag ) const override;
136  void readTags( NameList &tags, int filter = SceneInterface::LocalTag ) const override;
137  void writeTags( const NameList &tags ) override;
138 
139  bool hasObject() const override;
140  size_t numObjectSamples() const override;
141  double objectSampleTime( size_t sampleIndex ) const override;
142  double objectSampleInterval( double time, size_t &floorIndex, size_t &ceilIndex ) const override;
143  ConstObjectPtr readObjectAtSample( size_t sampleIndex ) const override;
144  ConstObjectPtr readObject( double time ) const override;
145  PrimitiveVariableMap readObjectPrimitiveVariables( const std::vector<InternedString> &primVarNames, double time ) const override;
146  void writeObject( const Object *object, double time ) override;
147 
148  bool hasChild( const Name &name ) const override;
149  void childNames( NameList &childNames ) const override;
150  SceneInterfacePtr child( const Name &name, SceneInterface::MissingBehaviour missingBehaviour = ThrowIfMissing ) override;
151  ConstSceneInterfacePtr child( const Name &name, SceneInterface::MissingBehaviour missingBehaviour = ThrowIfMissing ) const override;
152  SceneInterfacePtr createChild( const Name &name ) override;
153  SceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = ThrowIfMissing ) override;
154  ConstSceneInterfacePtr scene( const Path &path, SceneInterface::MissingBehaviour missingBehaviour = ThrowIfMissing ) const override;
155 
156  void hash( HashType hashType, double time, MurmurHash &h ) const override;
157 
158  private :
159 
160  LinkedScene( SceneInterface *mainScene, const SceneInterface *linkedScene, int rootLinkDepth, bool readOnly, bool atLink, bool timeRemapped );
161 
162  ConstSceneInterfacePtr expandLink( const StringData *fileName, const InternedStringVectorData *root, int &linkDepth );
163 
164  void mainSceneHash( HashType hashType, double time, MurmurHash &h ) const;
165 
166  // uses the mainScene to ask what is the time the link is remapped to. Should only be called when the linkAttribute is available.
167  double remappedLinkTime( double time ) const;
168  double remappedLinkTimeAtSample( size_t sampleIndex ) const;
169 
170  SceneInterfacePtr m_mainScene;
171  ConstSceneInterfacePtr m_linkedScene;
172  unsigned int m_rootLinkDepth;
173  bool m_readOnly;
174  bool m_atLink;
175  bool m_sampled;
176  bool m_timeRemapped;
177  // \todo: std::map< Path, LinkedScenes > for quick scene calls... built by scene... dies with the instance (usually only root uses it).
178 
179  static const InternedString g_fileName;
180  static const InternedString g_root;
181  static const InternedString g_time;
182 };
183 
184 } // namespace IECore
185 
186 #endif // IECORE_LINKEDSCENE_H
static const Name & linkAttribute
Equals to "SceneInterface:link" and it's the name given to the link attribute that is recognized...
Definition: LinkedScene.h:72
Definition: Data.h:46
Definition: Object.h:104
Definition: MurmurHash.h:64
HashType
Definition: SceneInterface.h:94
Definition: LinkedScene.h:64
Definition: SceneInterface.h:69
Definition: SampledSceneInterface.h:60
Definition: InternedString.h:55
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