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/fabric/range.h> // member
26 : #include <eq/fabric/viewport.h> // member
27 :
28 : #include <deque>
29 : #include <vector>
30 :
31 : namespace eq
32 : {
33 : namespace server
34 : {
35 : std::ostream& operator << ( std::ostream& os, const TreeEqualizer* );
36 :
37 : /** Adapts the 2D tiling or DB range of the attached compound's children. */
38 : class TreeEqualizer : public Equalizer, protected ChannelListener
39 : {
40 : public:
41 : EQSERVER_API TreeEqualizer();
42 : TreeEqualizer( const TreeEqualizer& from );
43 : virtual ~TreeEqualizer();
44 0 : void toStream( std::ostream& os ) const final { os << this; }
45 :
46 : /** @sa CompoundListener::notifyUpdatePre */
47 : void notifyUpdatePre( Compound* compound,
48 : const uint32_t frameNumber ) final;
49 :
50 : /** @sa ChannelListener::notifyLoadData */
51 : void notifyLoadData( Channel* channel, uint32_t frameNumber,
52 : const Statistics& statistics,
53 : const Viewport& region ) final;
54 :
55 0 : uint32_t getType() const final { return fabric::TREE_EQUALIZER; }
56 :
57 : protected:
58 0 : void notifyChildAdded( Compound*, Compound* ) override
59 0 : { LBASSERT( !_tree ); }
60 0 : void notifyChildRemove( Compound*, Compound* ) override
61 0 : { LBASSERT( !_tree ); }
62 :
63 : private:
64 : struct Node
65 : {
66 0 : Node() : left(0), right(0), compound(0), mode( MODE_VERTICAL )
67 : , resources( 0.0f ), split( 0.5f ), oldsplit( 0.0f ), boundaryf( 0.0f )
68 0 : , resistancef( 0.0f ), time( 1 ) {}
69 0 : ~Node() { delete left; delete right; }
70 :
71 : Node* left; //<! Left child (only on non-leafs)
72 : Node* right; //<! Right child (only on non-leafs)
73 : Compound* compound; //<! The corresponding child (only on leafs)
74 : TreeEqualizer::Mode mode; //<! What to adapt
75 : float resources; //<! total amount of resources of subtree
76 : float split; //<! 0..1 local (vp, range) split
77 : float oldsplit;
78 : float boundaryf;
79 : Vector2i boundary2i;
80 : float resistancef;
81 : Vector2i resistance2i;
82 : Vector2i maxSize;
83 : int64_t time;
84 : };
85 : friend std::ostream& operator << ( std::ostream& os, const Node* node );
86 : typedef std::vector< Node* > LBNodes;
87 :
88 : Node* _tree; // <! The binary split tree of all children
89 :
90 : //-------------------- Methods --------------------
91 : /** @return true if we have a valid LB tree */
92 : Node* _buildTree( const Compounds& children );
93 :
94 : /** Clear the tree, does not delete the nodes. */
95 : void _clearTree( Node* node );
96 :
97 : void _notifyLoadData( Node* node, Channel* channel,
98 : const Statistics& statistics );
99 :
100 : /** Update all node fields influencing the split */
101 : void _update( Node* node );
102 :
103 : /** Adjust the split of each node based on the front-most _history. */
104 : void _split( Node* node );
105 : void _assign( Node* node, const Viewport& vp, const Range& range );
106 : };
107 : }
108 : }
109 :
110 : #endif // EQS_TREEEQUALIZER_H
|