Equalizer  2.1.0
Parallel Rendering Framework
range.h
1 
2 /* Copyright (c) 2006-2017, 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 <algorithm> // min,max
22 #include <eq/fabric/api.h>
23 #include <iostream>
24 #include <lunchbox/bitOperation.h>
25 
26 namespace eq
27 {
28 namespace fabric
29 {
31 class Range
32 {
33 public:
38  : start(0.f)
39  , end(1.f)
40  {
41  }
42 
44  Range(const float start_, const float end_)
45  : start(start_)
46  , end(end_)
47  {
48  }
50 
54  bool operator==(const Range& rhs) const
55  {
56  return start == rhs.start && end == rhs.end;
57  }
58 
60  bool operator!=(const Range& rhs) const
61  {
62  return start != rhs.start || end != rhs.end;
63  }
64 
66  float getSize() const { return end - start; }
68  void invalidate()
69  {
70  start = 0.f;
71  end = 0.f;
72  }
73 
75  bool isValid() const
76  {
77  return (start >= 0.f && end <= 1.f && (end - start) >= 0.f);
78  }
79 
81  bool hasData() const { return (end - start) > 0.f; }
83  void apply(const Range& rhs)
84  {
85  const float w = end - start;
86  end = start + rhs.end * w;
87  start += rhs.start * w;
88  }
89 
91  void merge(const Range& rhs)
92  {
93  start = std::min(start, rhs.start);
94  end = std::max(end, rhs.end);
95  }
96 
97  float start;
98  float end;
99 
100  EQFABRIC_API static const Range ALL;
101 };
102 
103 inline std::ostream& operator<<(std::ostream& os, const Range& range)
104 {
105  os << "range [ " << range.start << " " << range.end << " ]";
106  return os;
107 }
108 }
109 }
110 
111 #endif // EQFABRIC_RANGE_H
Range(const float start_, const float end_)
Construct a new range with default values.
Definition: range.h:44
void merge(const Range &rhs)
Merge the two ranges (form the union).
Definition: range.h:91
bool operator==(const Range &rhs) const
Definition: range.h:54
Defines export visibility macros for library EqualizerFabric.
static EQFABRIC_API const Range ALL
A full database range.
Definition: range.h:100
float start
The start position.
Definition: range.h:97
float getSize() const
Definition: range.h:66
bool operator!=(const Range &rhs) const
Definition: range.h:60
The Equalizer client library.
Definition: eq/agl/types.h:23
std::ostream & operator<<(std::ostream &os, const AxisEvent &event)
Print the axis event to the given output stream.
Definition: axisEvent.h:49
float end
The end position.
Definition: range.h:98
Range()
Construct a new range covering all data.
Definition: range.h:37
A fractional database range with methods for manipulation.
Definition: range.h:31