OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
extent.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  Extent
23 
24  Author: Ansgar Philippsen
25 */
26 
27 #ifndef IMG_EXTENT_H
28 #define IMG_EXTENT_H
29 
30 #include <ost/message.hh>
31 #include <iosfwd>
32 #include <ost/message.hh>
33 
34 #include "point.hh"
35 #include "size.hh"
36 
37 /*
38  TODO:
39 
40  add CenterOrigin() -> return extent who's (0,0,0) is in the center
41  add TLFOrigin() -> return extent with start=(0,0,0)
42  add operators -> add/sub with point and extent
43 */
44 
45 namespace ost { namespace img {
46 
47 struct DLLEXPORT InvalidExtentException: public Error
48 {
50  Error(String("an invalid extent occured ("+m+String(")")))
51  {}
52 };
53 
55 
61  public:
63  Extent();
64 
66  Extent(const Extent &r);
67 
69  Extent(const Point& p1, const Point& p2);
70 
72 
78  Extent(const Size& s);
79 
81  /*
82  The given point will be the in the center of the
83  extent, with the size according to the even/odd rule
84  as described for Extent(const Size& s)
85  */
86  Extent(const Size& size, const Point& center);
87 
89  /*
90  The extent will go from start to (size-1)+start
91  */
92  Extent(const Point& start, const Size& size);
93 
95  const Point& GetStart() const;
97  const Point& GetEnd() const;
98 
100  void SetStart(const Point& o);
102  void SetEnd(const Point& e);
103 
105  bool Contains(const Point& p) const;
107  bool Contains(const Extent& e) const;
108 
110  Point GetCenter() const;
111 
113  const Size& GetSize() const;
114  int GetWidth() const;
115  int GetHeight() const;
116  int GetDepth() const;
117  int GetVolume() const;
118 
120  int GetDim() const;
121 
123  /*
124  Ensures that the given point lies within Extent,
125  using wrap around if necessary
126  */
127  Point WrapAround(const Point& p);
128 
130  Extent Mirror(int planes);
131 
133  unsigned int Point2Offset(const Point& p);
134 
135  // operators
136  bool operator==(const Extent& b) const {return equal(b);}
137  bool operator!=(const Extent& b) const {return !equal(b);}
138 
139  void Shift(const Point& p);
140 
141  private:
142  Point start_,end_;
143  Size size_;
144  int dim_;
145 
146  void set(const Point& p1, const Point& p2);
147  bool equal(const Extent& b) const;
148 
149 };
150 
151 // 'global' functions using extent
152 
153 DLLEXPORT_OST_IMG_BASE bool HasOverlap(const Extent& e1, const Extent& e2);
154 DLLEXPORT_OST_IMG_BASE Extent Overlap(const Extent& e1, const Extent& e2);
155 
156 DLLEXPORT_OST_IMG_BASE std::ostream& operator<<(std::ostream& os, const img::Extent &b);
157 
158 }} // namespace img
159 
160 
161 #endif