00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 by the OpenStructure authors 00005 // Copyright (C) 2003-2010 by the IPLT authors 00006 // 00007 // This library is free software; you can redistribute it and/or modify it under 00008 // the terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 3.0 of the License, or (at your option) 00010 // any later version. 00011 // This library is distributed in the hope that it will be useful, but WITHOUT 00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00014 // details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this library; if not, write to the Free Software Foundation, Inc., 00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 //------------------------------------------------------------------------------ 00020 00021 /* 00022 Extent 00023 00024 Author: Ansgar Philippsen 00025 */ 00026 00027 #ifndef IMG_EXTENT_H 00028 #define IMG_EXTENT_H 00029 00030 #include <ost/message.hh> 00031 #include <iosfwd> 00032 #include <ost/message.hh> 00033 00034 #include "point.hh" 00035 #include "size.hh" 00036 00037 /* 00038 TODO: 00039 00040 add CenterOrigin() -> return extent who's (0,0,0) is in the center 00041 add TLFOrigin() -> return extent with start=(0,0,0) 00042 add operators -> add/sub with point and extent 00043 */ 00044 00045 namespace ost { namespace img { 00046 00047 struct DLLEXPORT InvalidExtentException: public Error 00048 { 00049 InvalidExtentException(const String& m= String("") ): 00050 Error(String("an invalid extent occured ("+m+String(")"))) 00051 {} 00052 }; 00053 00055 00060 class DLLEXPORT_OST_IMG_BASE Extent { 00061 public: 00063 Extent(); 00064 00066 Extent(const Extent &r); 00067 00069 Extent(const Point& p1, const Point& p2); 00070 00072 00078 Extent(const Size& s); 00079 00081 /* 00082 The given point will be the in the center of the 00083 extent, with the size according to the even/odd rule 00084 as described for Extent(const Size& s) 00085 */ 00086 Extent(const Size& size, const Point& center); 00087 00089 /* 00090 The extent will go from start to (size-1)+start 00091 */ 00092 Extent(const Point& start, const Size& size); 00093 00095 const Point& GetStart() const; 00097 const Point& GetEnd() const; 00098 00100 void SetStart(const Point& o); 00102 void SetEnd(const Point& e); 00103 00105 bool Contains(const Point& p) const; 00107 bool Contains(const Extent& e) const; 00108 00110 Point GetCenter() const; 00111 00113 Size GetSize() const; 00114 int GetWidth() const; 00115 int GetHeight() const; 00116 int GetDepth() const; 00117 int GetVolume() const; 00118 00120 int GetDim() const; 00121 00123 /* 00124 Ensures that the given point lies within Extent, 00125 using wrap around if necessary 00126 */ 00127 Point WrapAround(const Point& p); 00128 00130 Extent Mirror(int planes); 00131 00133 unsigned int Point2Offset(const Point& p); 00134 00135 // operators 00136 bool operator==(const Extent& b) const {return equal(b);} 00137 bool operator!=(const Extent& b) const {return !equal(b);} 00138 00139 void Shift(const Point& p); 00140 00141 private: 00142 Point start_,end_; 00143 00144 void set(const Point& p1, const Point& p2); 00145 bool equal(const Extent& b) const; 00146 00147 }; 00148 00149 // 'global' functions using extent 00150 00151 DLLEXPORT_OST_IMG_BASE bool HasOverlap(const Extent& e1, const Extent& e2); 00152 DLLEXPORT_OST_IMG_BASE Extent Overlap(const Extent& e1, const Extent& e2); 00153 00154 DLLEXPORT_OST_IMG_BASE std::ostream& operator<<(std::ostream& os, const img::Extent &b); 00155 00156 }} // namespace img 00157 00158 00159 #endif