fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Cluster / Window / BalancedMultiWindow / OSGBalancedMultiWindow.inl
blobd45a525f5ff40ea1177dcc60718f337524910408
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
6  *                                                                           *
7  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
8  *                                                                           *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11  *                                License                                    *
12  *                                                                           *
13  * This library is free software; you can redistribute it and/or modify it   *
14  * under the terms of the GNU Library General Public License as published    *
15  * by the Free Software Foundation, version 2.                               *
16  *                                                                           *
17  * This library is distributed in the hope that it will be useful, but       *
18  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
20  * Library General Public License for more details.                          *
21  *                                                                           *
22  * You should have received a copy of the GNU Library General Public         *
23  * License along with this library; if not, write to the Free Software       *
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
25  *                                                                           *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28  *                                Changes                                    *
29  *                                                                           *
30  *                                                                           *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35 \*---------------------------------------------------------------------------*/
37 //---------------------------------------------------------------------------
38 //  Includes
39 //---------------------------------------------------------------------------
41 OSG_BEGIN_NAMESPACE
43 /*! calculate the load for a given group rendered into the given rectangle
44  */
46 inline 
47 Real32 BalancedMultiWindow::getVisibleLoad(Int32 const (&rect)[4],
48                                            BBox      &bbox)
50     LoadGroup &group=_cluster.loadGroups[bbox.groupId];
51     // invisible
52     if(bbox.rect[LEFT]   > rect[RIGHT] ||
53        bbox.rect[RIGHT]  < rect[LEFT] ||
54        bbox.rect[BOTTOM] > rect[TOP] ||
55        bbox.rect[TOP]    < rect[BOTTOM])
56         return 0;
57     Int32 l = osgMax(rect[0],bbox.rect[0]);
58     Int32 b = osgMax(rect[1],bbox.rect[1]);
59     Int32 r = osgMin(rect[2],bbox.rect[2]);
60     Int32 t = osgMin(rect[3],bbox.rect[3]);
61     Real32 visibleArea = (r-l+1) * (t-b+1);
62     Real32 area = (bbox.rect[2] - bbox.rect[0] + 1) *
63                   (bbox.rect[3] - bbox.rect[1] + 1);
64     // constant
65     Real32 load = group.constant;
66     // pixel
67     load += visibleArea * group.pixel;
68     // relative
69     if(area)
70         load += group.ratio * visibleArea / area;
71     return load;
74 OSG_END_NAMESPACE