fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Cluster / Window / SortFirst / OSGTileLoadBalancer.inl
blob97cf50e3c0dd2521dcab4bad0964501a57f1ed98
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *                     Copyright 2000-2002 by 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 OSG_BEGIN_NAMESPACE
39 /** Constructor
40  **/
41 inline 
42 TileLoadBalancer::RegionLoad::RegionLoad(TileGeometryLoad *load):
43     _visibleFaces  (0.f ),
44     _invisibleFaces(0.f ),
45     _pixel         (0.f ),
46     _load          (load)
50 /** Update region dependent values
51  **/
52 inline 
53 void TileLoadBalancer::RegionLoad::updateCost(const Int32 wmin[2],
54                                               const Int32 wmax[2])
56     Real32 faces  =Real32(_load->getFaces());
57     Real32 visible;
58     Int32 vismin[2];
59     Int32 vismax[2];
61     visible=_load->getVisibleFraction(wmin,wmax,vismin,vismax);
62     if(visible)
63     {
64         _visibleFaces=faces*visible;
65         _invisibleFaces=faces-_visibleFaces;
66         _pixel=Real32(
67             (vismax[0] - vismin[0] + 1)*
68             (vismax[1] - vismin[1] + 1));
69     }
70     else
71     {
72         _pixel=0;
73         _invisibleFaces=0;
74         _visibleFaces=0;
75     }
78 /** Calculate the rendering cost
79  *
80  * \param renderNode  Node to render the geometry
81  **/
83 inline 
84 Real32 TileLoadBalancer::RegionLoad::getCost(const RenderNode &renderNode)
86     return renderNode.estimatePerformance(_invisibleFaces,
87                                           _visibleFaces,
88                                           _pixel);
91 /** Calculate the rendering cost for the given region
92  *
93  * \param renderNode  Node to render the geometry
94  * \param wmin        bottom, left corner of the area
95  * \param wmax        top, right corner of the area
96  **/
98 inline 
99 Real32 TileLoadBalancer::RegionLoad::getCost(const RenderNode &renderNode,
100                                              const Int32 wmin[2],
101                                              const Int32 wmax[2]) const
103     Int32 vismin[2];
104     Int32 vismax[2];
105     Real32 visibleFaces;
106     Real32 invisibleFaces;
107     Real32 visible;
109     Real32 faces  =Real32(_load->getFaces());
110     visible=_load->getVisibleFraction(wmin,wmax,vismin,vismax);
111     if(visible==0.0)
112         return 0.0;
113     visibleFaces=faces*visible;
114     invisibleFaces=faces-visibleFaces;
115     Real32 pixel=Real32(
116         (vismax[0] - vismin[0] + 1)*
117         (vismax[1] - vismin[1] + 1));
118     return renderNode.estimatePerformance(invisibleFaces,
119                                           visibleFaces,
120                                           pixel);
123 /** Return gemetry load info object
124  **/
125 inline 
126 TileGeometryLoad * TileLoadBalancer::RegionLoad::getLoad(void)
128     return _load;
131 OSG_END_NAMESPACE