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-2020 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 occurred ("+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  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 
144  void set(const Point& p1, const Point& p2);
145  bool equal(const Extent& b) const;
146 
147 };
148 
149 // 'global' functions using extent
150 
151 DLLEXPORT_OST_IMG_BASE bool HasOverlap(const Extent& e1, const Extent& e2);
152 DLLEXPORT_OST_IMG_BASE Extent Overlap(const Extent& e1, const Extent& e2);
153 
154 DLLEXPORT_OST_IMG_BASE std::ostream& operator<<(std::ostream& os, const img::Extent &b);
155 
156 }} // namespace img
157 
158 
159 #endif
ImageStateConstModOPAlgorithm< ShiftFnc > Shift
Definition: alg_shift.hh:73
std::string String
Definition: base.hh:54
DLLEXPORT_OST_IMG_BASE std::ostream & operator<<(std::ostream &os, const img::Extent &b)
class encapsulating 1D to 3D size
Definition: size.hh:39
DLLEXPORT_OST_IMG_BASE bool HasOverlap(const Extent &e1, const Extent &e2)
DLLEXPORT_OST_IMG_BASE Extent Overlap(const Extent &e1, const Extent &e2)
bool operator==(const Extent &b) const
Definition: extent.hh:136
ImageStateConstModOPAlgorithm< MirrorFnc > Mirror
Definition: alg_mirror.hh:51
Defines lower and upper valid indices.
Definition: extent.hh:60
InvalidExtentException(const String &m=String(""))
Definition: extent.hh:49
class encapsulating 1D to 3D point
Definition: point.hh:43
#define DLLEXPORT_OST_IMG_BASE
bool operator!=(const Extent &b) const
Definition: extent.hh:137