Line data Source code
1 :
2 : /* Copyright (c) 2008-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #ifndef EQS_TREEEQUALIZER_H
20 : #define EQS_TREEEQUALIZER_H
21 :
22 : #include "../channelListener.h" // base class
23 : #include "equalizer.h" // base class
24 :
25 : #include <eq/client/types.h>
26 : #include <eq/fabric/range.h> // member
27 : #include <eq/fabric/viewport.h> // member
28 :
29 : #include <deque>
30 : #include <vector>
31 :
32 : namespace eq
33 : {
34 : namespace server
35 : {
36 : std::ostream& operator << ( std::ostream& os, const TreeEqualizer* );
37 :
38 : /** Adapts the 2D tiling or DB range of the attached compound's children. */
39 : class TreeEqualizer : public Equalizer, protected ChannelListener
40 : {
41 : public:
42 : EQSERVER_API TreeEqualizer();
43 : TreeEqualizer( const TreeEqualizer& from );
44 : virtual ~TreeEqualizer();
45 0 : virtual void toStream( std::ostream& os ) const { os << this; }
46 :
47 : /** @sa CompoundListener::notifyUpdatePre */
48 : virtual void notifyUpdatePre( Compound* compound,
49 : const uint32_t frameNumber );
50 :
51 : /** @sa ChannelListener::notifyLoadData */
52 : virtual void notifyLoadData( Channel* channel,
53 : const uint32_t frameNumber,
54 : const Statistics& statistics,
55 : const Viewport& region );
56 :
57 0 : virtual uint32_t getType() const { return fabric::TREE_EQUALIZER; }
58 :
59 : protected:
60 0 : void notifyChildAdded( Compound*, Compound* ) override
61 0 : { LBASSERT( !_tree ); }
62 0 : void notifyChildRemove( Compound*, Compound* ) override
63 0 : { LBASSERT( !_tree ); }
64 :
65 : private:
66 : struct Node
67 : {
68 0 : Node() : left(0), right(0), compound(0), mode( MODE_VERTICAL )
69 : , resources( 0.0f ), split( 0.5f ), oldsplit( 0.0f ), boundaryf( 0.0f )
70 0 : , resistancef( 0.0f ), time( 1 ) {}
71 0 : ~Node() { delete left; delete right; }
72 :
73 : Node* left; //<! Left child (only on non-leafs)
74 : Node* right; //<! Right child (only on non-leafs)
75 : Compound* compound; //<! The corresponding child (only on leafs)
76 : TreeEqualizer::Mode mode; //<! What to adapt
77 : float resources; //<! total amount of resources of subtree
78 : float split; //<! 0..1 local (vp, range) split
79 : float oldsplit;
80 : float boundaryf;
81 : Vector2i boundary2i;
82 : float resistancef;
83 : Vector2i resistance2i;
84 : Vector2i maxSize;
85 : int64_t time;
86 : };
87 : friend std::ostream& operator << ( std::ostream& os, const Node* node );
88 : typedef std::vector< Node* > LBNodes;
89 :
90 : Node* _tree; // <! The binary split tree of all children
91 :
92 : //-------------------- Methods --------------------
93 : /** @return true if we have a valid LB tree */
94 : Node* _buildTree( const Compounds& children );
95 :
96 : /** Clear the tree, does not delete the nodes. */
97 : void _clearTree( Node* node );
98 :
99 : void _notifyLoadData( Node* node, Channel* channel,
100 : const Statistics& statistics );
101 :
102 : /** Update all node fields influencing the split */
103 : void _update( Node* node );
104 :
105 : /** Adjust the split of each node based on the front-most _history. */
106 : void _split( Node* node );
107 : void _assign( Node* node, const Viewport& vp, const Range& range );
108 : };
109 : }
110 : }
111 :
112 : #endif // EQS_TREEEQUALIZER_H
|