Equalizer  1.11.0
Parallel Rendering Framework
range.h
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 {
31 class Range
32 {
33 public:
37  Range() : start(0.f), end(1.f) {}
38 
40  Range( const float start_, const float end_ )
41  : start(start_), end(end_) {}
43 
47  bool operator == ( const Range& rhs ) const
48  { return start==rhs.start && end==rhs.end; }
49 
51  bool operator != ( const Range& rhs ) const
52  { return start!=rhs.start || end!=rhs.end; }
53 
55  float getSize() const { return end - start; }
56 
58  void invalidate() { start=0.f; end=0.f; }
59 
61  bool isValid() const
62  { return ( start>=0.f && end <=1.f && (end - start) >= 0.f ); }
63 
65  bool hasData() const { return (end - start) > 0.f; }
66 
68  void apply( const Range& rhs )
69  {
70  const float w = end-start;
71  end = start + rhs.end * w;
72  start += rhs.start * w;
73  }
74 
76  void merge( const Range& rhs )
77  {
78  start = std::min( start, rhs.start );
79  end = std::max( end, rhs.end );
80  }
81 
82  float start;
83  float end;
84 
85  EQFABRIC_API static const Range ALL;
86 };
87 
88 inline std::ostream& operator << ( std::ostream& os, const Range& range )
89 {
90  os << "range [ " << range.start << " " << range.end << " ]";
91  return os;
92 }
93 }
94 }
95 
96 namespace lunchbox
97 {
98 template<> inline void byteswap( eq::fabric::Range& value )
99 {
100  byteswap( value.start );
101  byteswap( value.end );
102 }
103 }
104 #endif // EQFABRIC_RANGE_H
Range(const float start_, const float end_)
Construct a new range with default values.
Definition: range.h:40
void merge(const Range &rhs)
Merge the two ranges (form the union).
Definition: range.h:76
bool operator==(const Range &rhs) const
Definition: range.h:47
Defines export visibility macros for library EqualizerFabric.
static EQFABRIC_API const Range ALL
A full database range.
Definition: range.h:85
float start
The start position.
Definition: range.h:82
float getSize() const
Definition: range.h:55
bool operator!=(const Range &rhs) const
Definition: range.h:51
The Equalizer client library.
Definition: eq/agl/types.h:23
float end
The end position.
Definition: range.h:83
Range()
Construct a new range covering all data.
Definition: range.h:37
A fractional database range with methods for manipulation.
Definition: range.h:31