OpenStructure
Loading...
Searching...
No Matches
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
45namespace ost { namespace img {
46
47struct DLLEXPORT InvalidExtentException: public Error
48{
50 Error(String("an invalid extent occurred ("+m+String(")")))
51 {}
52};
53
55
61 public:
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
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 */
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
153
154DLLEXPORT_OST_IMG_BASE std::ostream& operator<<(std::ostream& os, const img::Extent &b);
155
156}} // namespace img
157
158
159#endif
Defines lower and upper valid indices.
Definition extent.hh:60
bool Contains(const Extent &e) const
Returns true if the given exten is within extent.
Extent(const Size &s)
initialize with Size
int GetDepth() const
Extent()
default constructor
void SetStart(const Point &o)
Set start point, changing size.
Extent(const Point &start, const Size &size)
initialize with Size and start point
int GetWidth() const
Point GetCenter() const
return center
Extent(const Extent &r)
copy constructor
int GetHeight() const
int GetVolume() const
bool operator!=(const Extent &b) const
Definition extent.hh:137
int GetDim() const
Return dimension.
void SetEnd(const Point &e)
Set end point, changing size.
Extent(const Point &p1, const Point &p2)
initialize with start and end point
Extent(const Size &size, const Point &center)
initialize with center point and size
const Point & GetEnd() const
Return upper/right/back corner.
const Point & GetStart() const
Return lower/left/front corner.
void Shift(const Point &p)
unsigned int Point2Offset(const Point &p)
Generates a continues, uniqe index per point contained within extent.
bool operator==(const Extent &b) const
Definition extent.hh:136
Size GetSize() const
Return size of extent.
Point WrapAround(const Point &p)
Wrap point around.
bool Contains(const Point &p) const
Returns true if the given point is within extent.
Extent Mirror(int planes)
Return new extent mirrored according to planes.
class encapsulating 1D to 3D point
Definition point.hh:47
class encapsulating 1D to 3D size
Definition size.hh:39
#define DLLEXPORT_OST_IMG_BASE
std::string String
Definition base.hh:54
DLLEXPORT_OST_IMG_BASE bool HasOverlap(const Extent &e1, const Extent &e2)
DLLEXPORT_OST_IMG_BASE std::ostream & operator<<(std::ostream &os, const img::Extent &b)
DLLEXPORT_OST_IMG_BASE Extent Overlap(const Extent &e1, const Extent &e2)
Definition base.dox:1
InvalidExtentException(const String &m=String(""))
Definition extent.hh:49