fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Cluster / Window / BalancedMultiWindow / OSGBalancedMultiWindow.h
blob51130b8d02e9408585f9f5a4970ff3a3eaddf5dc
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGBALANCEDMULTIWINDOW_H_
40 #define _OSGBALANCEDMULTIWINDOW_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include <vector>
47 #include "OSGBalancedMultiWindowBase.h"
48 #include "OSGNode.h"
49 #include "OSGViewport.h"
51 OSG_BEGIN_NAMESPACE
53 //#define MW_TILE_SIZE 21
54 //#define MW_TILE_SIZE 44
55 #define MW_TILE_SIZE 256
57 // TODO use dynamic performance values
58 #define MW_INDICES_PER_SEC 100000000.0
59 #define MW_VISIBLE_INDICES_PER_SEC 30000000.0
60 #define MW_PIXEL_PER_SEC 1000000000.0
61 #define MW_SHADED_PIXEL_PER_SEC 5000000.0
63 /*! \brief BalancedMultiWindow class. See \ref
64 PageSystemBalancedMultiWindow for a description.
65 \ingroup GrpClusterWindowObj
66 \ingroup GrpLibOSGCluster
67 \includebasedoc
70 class OSG_CLUSTER_DLLMAPPING BalancedMultiWindow :
71 public BalancedMultiWindowBase
73 private:
75 typedef BalancedMultiWindowBase Inherited;
77 enum
79 LEFT = 0,
80 BOTTOM = 1,
81 RIGHT = 2,
82 TOP = 3
85 /*========================== PUBLIC =================================*/
87 public:
89 /*---------------------------------------------------------------------*/
90 /*! \name Sync */
91 /*! \{ */
93 virtual void changed(ConstFieldMaskArg whichField,
94 UInt32 origin,
95 BitVector detail);
97 /*! \} */
98 /*---------------------------------------------------------------------*/
99 /*! \name Output */
100 /*! \{ */
102 virtual void dump( UInt32 uiIndent = 0,
103 const BitVector bvFlags = 0) const;
105 /*! \} */
106 /*========================= PROTECTED ===============================*/
108 protected:
110 struct LoadGroup;
111 struct BBox;
112 struct VPort;
113 struct Server;
114 struct WorkPackage;
115 struct Tile;
116 struct Area;
117 struct Cluster;
118 struct Worker;
119 struct OpenBBox;
120 struct ServerComp;
121 struct BBoxList;
123 friend struct LoadGroup;
124 friend struct BBox;
125 friend struct VPort;
126 friend struct Server;
127 friend struct WorkPackage;
128 friend struct Tile;
129 friend struct Area;
130 friend struct Cluster;
131 friend struct Worker;
132 friend struct OpenBBox;
133 friend struct ServerComp;
134 friend struct BBoxList;
136 /*! \nohierarchy
139 struct LoadGroup
141 NodeUnrecPtr root;
142 NodeUnrecPtr node;
143 Real32 pixel;
144 Real32 constant;
145 Real32 ratio;
147 LoadGroup(void) :
148 root (NULL),
149 node (NULL),
150 pixel (0.f ),
151 constant(0.f ),
152 ratio (0.f ) {}
155 /*! \nohierarchy
158 struct BBox
160 UInt32 groupId;
161 Int32 rect[4];
164 /*! \nohierarchy
167 struct VPort
169 UInt32 serverId;
170 ViewportUnrecPtr serverPort;
171 NodeUnrecPtr root;
172 UInt16 id;
173 Real32 load;
174 Int32 rect[4];
175 Real32 loadCenter[2];
176 std::vector<BBox> bboxes;
178 VPort(void) :
179 serverId (0 ),
180 serverPort(NULL),
181 root (NULL),
182 id (0 ),
183 load (0.f ),
184 bboxes ( ) {}
187 /*! \nohierarchy
190 struct Server
192 UInt16 id;
193 Real32 load;
194 std::vector<VPort> viewports;
195 Window *window;
197 Server(void) :
198 id (0 ),
199 load (0.f ),
200 viewports( ),
201 window (NULL) {}
203 Server(const Server &other) :
204 id (other.id ),
205 load (other.load ),
206 viewports(other.viewports),
207 window (other.window ) {}
209 Server &operator =(const Server &rhs)
211 id = rhs.id;
212 load = rhs.load;
213 viewports = rhs.viewports;
214 window = rhs.window;
216 return *this;
220 /*! \nohierarchy
223 struct WorkPackage
225 UInt16 viewportId;
226 UInt16 drawServer;
227 UInt16 sendToServer;
228 Int32 rect[4];
231 /*! \nohierarchy
234 struct Tile
236 /*! \nohierarchy
239 struct Header
241 unsigned int x :16;
242 unsigned int y :16;
243 unsigned int width :16;
244 unsigned int height :15;
245 unsigned int last :1 ;
246 } header;
248 UInt8 pixel[MW_TILE_SIZE*MW_TILE_SIZE*3];
251 /*! \nohierarchy
254 struct Area
256 UInt16 workpackageId;
257 std::vector<Tile> tiles;
259 Area(void) :
260 workpackageId(0),
261 tiles ( ) {}
264 /*! \nohierarchy
267 struct Cluster
269 UInt32 load;
270 std::vector<NodeUnrecPtr> rootNodes;
271 std::vector<LoadGroup> loadGroups;
272 std::vector<Server> servers;
273 std::vector<WorkPackage> workpackages;
274 std::vector<Area> areas;
276 Cluster(void) :
277 load (0),
278 rootNodes ( ),
279 loadGroups ( ),
280 servers ( ),
281 workpackages( ),
282 areas ( ) {}
285 /*! \nohierarchy
288 struct Worker
290 UInt32 serverId;
291 Real32 takeLoad;
292 Real32 assignedLoad;
295 /*! \nohierarchy
298 struct OpenBBox
300 Real32 lineLoad;
301 Real32 cnostLoast;
304 /*! \nohierarchy
307 struct ServerComp
309 bool operator () (Server *s1,Server *s2)
311 return (s1->load < s2->load);
315 /*! \nohierarchy
318 struct BBoxList
320 BBoxList *next;
321 Real32 pixel;
322 Real32 constant;
325 Cluster _cluster;
326 std::vector<BBoxList*> _groupOpen;
327 std::vector<BBoxList*> _groupClose;
328 std::vector<BBoxList> _bboxlist;
329 VPort _foreignPort;
330 bool _preloadCache;
332 UInt32 _triCount;
333 Real64 _drawTime;
334 Real64 _pixelTime;
335 Real64 _loadTime;
336 Real64 _balanceTime;
337 Real64 _netTime;
339 bool _rebuildLoadGroups;
342 /*---------------------------------------------------------------------*/
344 // calculate rendering load
345 inline Real32 getVisibleLoad(Int32 const (&rect)[4],
346 BBox &bbox);
347 // get number of tiles for the given area
348 UInt32 calcTileCount(Int32 const (&rect)[4]);
349 // project group and calculate bounding box
350 bool calculateProjectedBBox(VPort &port,
351 LoadGroup &group,
352 BBox &bbox,
353 Matrix &proj);
354 // create load groups for all root nodes
355 void createLoadGroups(void);
356 // collect load for a subtree
357 void collectLoadGroups(Node *node,Node *root);
358 // collect visible viewports
359 void collectVisibleViewports(Server &server);
360 // calculate server viewport
361 bool calculateServerPort(VPort &port, Int32 const (&rect)[4]);
362 // create view dependent bboxes
363 void createBBoxes(Server &server);
364 // do load balancing for all servers
365 void balanceServer(void);
366 // split viewport
367 void splitViewport(std::vector<Worker> &worker,
368 VPort &port,
369 Int32 const (&rect)[4],
370 Real32 load);
371 // sort bboxes
372 void sortBBoxes(VPort &port,UInt32 axis, Int32 const (&rect)[4]);
373 // split load at a given axis
374 void splitAxis(Real32 const (&load)[2],
375 VPort &port,
376 Int32 const (&rect)[4],
377 int axis,
378 Real32 (&resultLoad)[2],
379 Int32 (&resultRect)[2][4]);
381 // render part of a viewport viewport
382 void renderViewport(Window *serverWindow,
383 UInt32 id,
384 RenderActionBase *action,
385 UInt32 portId,
386 Int32 const (&rect)[4]);
387 // clear local ports
388 void clearViewports(Window *serverWindow,
389 UInt32 id,
390 RenderActionBase *action);
392 // store viewport
393 void storeViewport(Area &area,Viewport *vp, Int32 const (&rect)[4]);
395 // do rendering and network transfer
396 void drawSendAndRecv(Window *serverWindow,
397 RenderActionBase *action,
398 UInt32 id);
400 // preload display lists and textures
401 void preloadCache(Window *window,
402 RenderActionBase *action);
405 /*---------------------------------------------------------------------*/
406 /*! \name Constructors */
407 /*! \{ */
409 BalancedMultiWindow(void);
410 BalancedMultiWindow(const BalancedMultiWindow &source);
412 /*! \} */
413 /*---------------------------------------------------------------------*/
414 /*! \name Destructors */
415 /*! \{ */
417 virtual ~BalancedMultiWindow(void);
419 /*! \} */
420 /*---------------------------------------------------------------------*/
421 /*! \name Init */
422 /*! \{ */
424 static void initMethod(InitPhase ePhase);
426 /*! \} */
427 /*---------------------------------------------------------------------*/
428 /*! \name Sync */
429 /*! \{ */
431 virtual void resolveLinks(void);
433 /*! \} */
434 /*--------------------------------------------------------------------*/
435 /*! \name server window funcitons */
436 /*! \{ */
438 virtual void serverInit (Window *serverWindow,
439 UInt32 id );
441 virtual void serverRender(Window *serverWindow,
442 UInt32 id,
443 RenderActionBase *action );
445 /*! \} */
446 /*--------------------------------------------------------------------*/
447 /*! \name client window functions */
448 /*! \{ */
450 virtual void clientInit (void );
451 virtual void clientPreSync(void );
452 virtual void clientRender (RenderActionBase *action);
454 /*! \} */
455 /*========================== PRIVATE ================================*/
457 private:
459 friend class FieldContainer;
460 friend class BalancedMultiWindowBase;
462 // prohibit default functions (move to 'public' if you need one)
463 void operator =(const BalancedMultiWindow &source);
466 typedef BalancedMultiWindow *BalancedMultiWindowP;
468 OSG_END_NAMESPACE
470 #include "OSGBalancedMultiWindowBase.inl"
471 #include "OSGBalancedMultiWindow.inl"
473 #endif /* _OSGBALANCEDMULTIWINDOW_H_ */