Cortex  10.0.0-a4
SceneCacheReader.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 IENUKE_SCENECACHEREADER_H
36 #define IENUKE_SCENECACHEREADER_H
37 
38 #include "DDImage/SourceGeo.h"
39 #include "DDImage/Knobs.h"
40 #include "DDImage/Row.h"
41 #include "DDImage/Filter.h"
42 #include "IECore/LensModel.h"
43 
44 #include "DDImage/Op.h"
45 #include "DDImage/Matrix4.h"
46 #include "DDImage/ViewerContext.h"
47 
48 #include "IECoreGL/Scene.h"
49 #include "IECoreGL/Renderer.h"
50 
51 #include "IECore/SceneInterface.h"
52 
53 #include "OpenEXR/ImathMatrix.h"
54 
55 namespace IECoreNuke
56 {
57 
59 class SceneCacheReader : public DD::Image::SourceGeo
60 {
61  public :
62 
63  SceneCacheReader( Node *node );
65 
66  virtual void knobs( DD::Image::Knob_Callback f );
67  virtual const char *Class() const;
68  virtual const char *node_help() const;
69 
70  protected :
71 
72  virtual void _validate( bool forReal );
73  virtual void append( DD::Image::Hash &hash );
74  virtual void get_geometry_hash();
75  virtual void geometry_engine( DD::Image::Scene& scene, DD::Image::GeometryList &out );
76  virtual void create_geometry( DD::Image::Scene &scene, DD::Image::GeometryList &out );
77  virtual int knob_changed( DD::Image::Knob* k);
78 
79  private :
80 
81  static const DD::Image::Op::Description m_description;
82  static DD::Image::Op *build( Node *node );
83  virtual void build_handles( DD::Image::ViewerContext* ctx);
84 
89 
90  void tagSelection( std::string &selection ) const;
92  // Returns whether the item at index itemIndex is selected in the SceneView_knob.
93  inline bool itemSelected( int itemIndex ) const;
94  // Returns the name of the item at index itemIndex in the SceneView_knob.
95  const std::string &itemName( int itemIndex ) const;
96  // Returns a SceneInterface for the root item.
97  IECore::ConstSceneInterfacePtr getSceneInterface();
98  // Returns a SceneInterface for the item at path.
99  IECore::ConstSceneInterfacePtr getSceneInterface( const std::string &path );
101 
109 
110  void loadAllFromKnobs();
118  void rebuildSceneView();
124  void filterScene( const std::string &filterText, const std::string &tagText, bool keepSelection = true );
126  void clearSceneViewSelection();
128 
131  void updateTagFilterKnob();
133  void loadPrimitive( DD::Image::GeometryList &out, const std::string &path );
135  DD::Image::Hash sceneHash() const;
137  DD::Image::Hash selectionHash( bool force = false ) const;
138 
139  Imath::M44d worldTransform( IECore::ConstSceneInterfacePtr scene, IECore::SceneInterface::Path root, double time );
140 
141  // uses firstOp to return the Op that has the up-to-date private data
142  SceneCacheReader *firstReader();
143  const SceneCacheReader *firstReader() const;
144 
145  class SharedData;
146 
147  // this function should only be called from the firstReader() object.
148  SharedData *sharedData();
149  const SharedData *sharedData() const;
150 
151  // Knob Members.
152  const char *m_filePath; // Holds the raw SceneCache file path.
153  std::string m_root; // Holds the root item in the SceneCache.
154  std::string m_filter; // The text to filter the scene with.
155  bool m_worldSpace; // Set to ignore local transforms..
156  DD::Image::Matrix4 m_baseParentMatrix; // The global matrix that is applied to the geo.
157 
158  // Pointers to various knobs.
159  DD::Image::Knob *m_filePathKnob;
160  DD::Image::Knob *m_baseParentMatrixKnob;
161  DD::Image::Knob *m_sceneKnob;
162  DD::Image::Knob *m_tagFilterKnob;
163  DD::Image::Knob *m_sceneFilterKnob;
164  DD::Image::Knob *m_rootKnob;
165 
166  // only the first reader allocates the shared data
167  SharedData *m_data;
168 };
169 
170 } // namespace IECoreNuke
171 
172 #endif // IENUKE_SCENECACHEREADER_H
173 
The IECoreNuke namespace holds all the functionality of libIECoreNuke.
Definition: BoolParameterHandler.h:40
Loads and displays geometry from a scene cache file.
Definition: SceneCacheReader.h:59