Line data Source code
1 :
2 : /* Copyright (c) 2006-2015, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQFABRIC_RANGE_H
19 : #define EQFABRIC_RANGE_H
20 :
21 : #include <eq/fabric/api.h>
22 : #include <lunchbox/bitOperation.h>
23 : #include <algorithm> // min,max
24 : #include <iostream>
25 :
26 : namespace eq
27 : {
28 : namespace fabric
29 : {
30 : /** A fractional database range with methods for manipulation. */
31 : class Range
32 : {
33 : public:
34 : /** @name Constructors */
35 : //@{
36 : /** Construct a new range covering all data. @version 1.0 */
37 27796 : Range() : start(0.f), end(1.f) {}
38 :
39 : /** Construct a new range with default values. @version 1.0 */
40 731 : Range( const float start_, const float end_ )
41 731 : : start(start_), end(end_) {}
42 : //@}
43 :
44 : /** @name Data Access */
45 : //@{
46 : /** @return true if the two ranges are identical. @version 1.0 */
47 6 : bool operator == ( const Range& rhs ) const
48 6 : { return start==rhs.start && end==rhs.end; }
49 :
50 : /** @return true if the two ranges are not identical. @version 1.0 */
51 2055 : bool operator != ( const Range& rhs ) const
52 2055 : { return start!=rhs.start || end!=rhs.end; }
53 :
54 : /** @return the interval spanned by this range. @version 1.3 */
55 0 : float getSize() const { return end - start; }
56 :
57 : /** @internal Invalidate the database range. */
58 : void invalidate() { start=0.f; end=0.f; }
59 :
60 : /** @internal @return true if the database range is valid. */
61 2054 : bool isValid() const
62 2054 : { return ( start>=0.f && end <=1.f && (end - start) >= 0.f ); }
63 :
64 : /** @internal @return true if the database range covers some data. */
65 0 : bool hasData() const { return (end - start) > 0.f; }
66 :
67 : /** @internal Apply (accumulate) another database range. */
68 2 : void apply( const Range& rhs )
69 : {
70 2 : const float w = end-start;
71 2 : end = start + rhs.end * w;
72 2 : start += rhs.start * w;
73 2 : }
74 :
75 : /** Merge the two ranges (form the union). @version 1.11 */
76 4 : void merge( const Range& rhs )
77 : {
78 4 : start = std::min( start, rhs.start );
79 4 : end = std::max( end, rhs.end );
80 4 : }
81 :
82 : float start; //!< The start position
83 : float end; //!< The end position
84 :
85 : EQFABRIC_API static const Range ALL; //!< A full database range
86 : };
87 :
88 362 : inline std::ostream& operator << ( std::ostream& os, const Range& range )
89 : {
90 362 : os << "range [ " << range.start << " " << range.end << " ]";
91 362 : return os;
92 : }
93 : }
94 : }
95 :
96 : namespace lunchbox
97 : {
98 0 : template<> inline void byteswap( eq::fabric::Range& value )
99 : {
100 0 : byteswap( value.start );
101 0 : byteswap( value.end );
102 0 : }
103 : }
104 : #endif // EQFABRIC_RANGE_H
|