Skip to content
Snippets Groups Projects
Commit 0fe22e9f authored by Andreas Schenk's avatar Andreas Schenk
Browse files

moved some often used methods in basic img classes to headers to allow inlining

parent 2df719e0
Branches
Tags
No related merge requests found
......@@ -33,26 +33,37 @@
namespace ost { namespace img {
Extent::Extent() {set(Point(),Point());}
Extent::Extent():
start_(),
end_()
{}
Extent::Extent(const Extent &r) {set(r.start_,r.end_);}
Extent::Extent(const Extent &r):
start_(r.start_),
end_(r.end_)
{}
Extent::Extent(const Point& p1, const Point& p2) {set(p1,p2);}
Extent::Extent(const Point& p1, const Point& p2):
start_(std::min(p1[0],p2[0]),std::min(p1[1],p2[1]),std::min(p1[2],p2[2])),
end_(std::max(p1[0],p2[0]),std::max(p1[1],p2[1]),std::max(p1[2],p2[2]))
{}
Extent::Extent(const Size& size)
Extent::Extent(const Size& size):
start_(),
end_(size - Point(1,1,1))
{
set(Point(0,0,0), size - Point(1,1,1));
}
Extent::Extent(const Size& size, const Point& cen)
Extent::Extent(const Size& size, const Point& cen):
start_(-size.GetHalf() + cen),
end_(size + start_ - Point(1,1,1))
{
Point st = -size.GetHalf() + cen;
set(st, size + st - Point(1,1,1));
}
Extent::Extent(const Point& start, const Size& size)
Extent::Extent(const Point& start, const Size& size):
start_(start),
end_(size + start_ - Point(1,1,1))
{
set(start, size + start - Point(1,1,1));
}
const Point& Extent::GetStart() const {return start_;}
......@@ -72,8 +83,8 @@ const Point& Extent::GetEnd() const {return end_;}
bool Extent::Contains(const Point& p) const
{
return (p[0]>=start_[0] && p[0]<=end_[0] &&
p[1]>=start_[1] && p[1]<=end_[1] &&
p[2]>=start_[2] && p[2]<=end_[2]);
p[1]>=start_[1] && p[1]<=end_[1] &&
p[2]>=start_[2] && p[2]<=end_[2]);
}
bool Extent::Contains(const Extent& e) const
......@@ -83,27 +94,28 @@ bool Extent::Contains(const Extent& e) const
Point Extent::GetCenter() const
{
return size_.GetHalf()+start_;
return Size(start_,end_).GetHalf()+start_;
}
const Size& Extent::GetSize() const {return size_;}
Size Extent::GetSize() const {return Size(start_,end_);}
int Extent::GetWidth() const {return size_.GetWidth();}
int Extent::GetWidth() const {return end_[0]-start_[0]+1;}
int Extent::GetHeight() const {return size_.GetHeight();}
int Extent::GetHeight() const {return end_[1]-start_[1]+1;}
int Extent::GetDepth() const {return size_.GetDepth();}
int Extent::GetDepth() const {return end_[2]-start_[2]+1;}
int Extent::GetVolume() const {return size_.GetVolume();}
int Extent::GetVolume() const {return Size(start_,end_).GetVolume();}
int Extent::GetDim() const {return dim_;}
int Extent::GetDim() const {return Size(start_,end_).GetDim();}
Point Extent::WrapAround(const Point& p)
{
Point r(p-start_);
Size size=GetSize();
for(int i=0;i<3;i++) {
r[i] = start_[i] + (r[i]<0 ? size_[i]+std::div(r[i],size_[i]).rem : std::div(r[i],size_[i]).rem);
r[i] = start_[i] + (r[i]<0 ? size[i]+std::div(r[i],size[i]).rem : std::div(r[i],size[i]).rem);
}
return r;
}
......@@ -112,16 +124,16 @@ Point Extent::WrapAround(const Point& p)
Extent Extent::Mirror(int planes)
{
Point new_start(planes & Plane::YZ ? -end_[0] : start_[0],
planes & Plane::XZ ? -end_[1] : start_[1],
planes & Plane::XY ? -end_[2] : start_[2]);
return Extent(new_start,size_);
planes & Plane::XZ ? -end_[1] : start_[1],
planes & Plane::XY ? -end_[2] : start_[2]);
return Extent(new_start,GetSize());
}
unsigned int Extent::Point2Offset(const Point& p)
{
if(this->Contains(p)) {
Point d(p-start_);
return d[0]+size_[0]*(d[1]+d[2]*size_[1]);
return d[0]+GetWidth()*(d[1]+d[2]*GetHeight());
} else {
return 0;
}
......@@ -146,8 +158,6 @@ void Extent::set(const Point& p1, const Point& p2)
end_[i]=p1[i];
}
}
size_ = Size(start_,end_);
dim_ = size_.GetDim();
}
bool Extent::equal(const Extent& b) const
......
......@@ -110,7 +110,7 @@ class DLLEXPORT_OST_IMG_BASE Extent {
Point GetCenter() const;
//! Return size of extent
const Size& GetSize() const;
Size GetSize() const;
int GetWidth() const;
int GetHeight() const;
int GetDepth() const;
......@@ -140,8 +140,6 @@ class DLLEXPORT_OST_IMG_BASE Extent {
private:
Point start_,end_;
Size size_;
int dim_;
void set(const Point& p1, const Point& p2);
bool equal(const Extent& b) const;
......
......@@ -311,19 +311,6 @@ void ImageStateImpl<T,D>::AdjustPhaseOrigin(const Point& p)
}
template <typename T, class D>
T& ImageStateImpl<T,D>::Value(const Point& p)
{
assert(domain_.GetExtent().Contains(p));
return data_.Value(domain_.Point2Index(p));
}
template <typename T, class D>
const T& ImageStateImpl<T,D>::Value(const Point& p) const
{
assert(domain_.GetExtent().Contains(p));
return data_.Value(domain_.Point2Index(p));
}
template <typename T, class D>
T ImageStateImpl<T,D>::GetCheckedValue(const Point& p) const
......
......@@ -142,10 +142,18 @@ public:
retrieve actual value. No boundary check is performed
here, this is the responsibility of the caller!
*/
T& Value(const Point& p);
T& Value(const Point& p)
{
assert(domain_.GetExtent().Contains(p));
return data_.Value(domain_.Point2Index(p));
}
// retrieve ro value at specified point
const T& Value(const Point& p) const;
const T& Value(const Point& p) const
{
assert(domain_.GetExtent().Contains(p));
return data_.Value(domain_.Point2Index(p));
}
//! retrieve boundary checked value
T GetCheckedValue(const Point& p) const;
......
......@@ -108,9 +108,10 @@ public:
}
Index Point2Index(const Point& p) const {
return Index(p[0]-extent_.GetStart()[0],
p[1]-extent_.GetStart()[1],
p[2]-extent_.GetStart()[2]);
Point start=extent_.GetStart();
return Index(p[0]-start[0],
p[1]-start[1],
p[2]-start[2]);
}
private:
......
......@@ -31,9 +31,6 @@ namespace ost { namespace img { namespace image_state {
// Index
Index::Index(unsigned int uu,unsigned int vv, unsigned int ww):
u(uu),v(vv),w(ww)
{}
bool Index::equal(const Index& i) const {
return u==i.u && v==i.v && w==i.w;
......
......@@ -39,7 +39,9 @@ namespace ost { namespace img { namespace image_state {
provides a compact mean to adress values in a ValueHolder
*/
struct DLLEXPORT_OST_IMG_BASE Index {
Index(unsigned int uu,unsigned int vv, unsigned int ww);
Index(unsigned int uu,unsigned int vv, unsigned int ww):
u(uu),v(vv),w(ww)
{}
bool equal(const Index& i) const;
......
......@@ -35,7 +35,6 @@
#include <ost/img/size.hh>
#include "value_holder.hh"
#include "index.hh"
namespace ost { namespace img { namespace image_state {
......@@ -151,29 +150,6 @@ void ValueHolder<V>::Swap(ValueHolder& vh)
}
template <typename V>
V& ValueHolder<V>::Value(const Index& i)
{
#ifdef USE_ROW_ORDER
assert(i.w<depth_);
return data_[i.u*height_depth_ + i.v*depth_ +i.w];
#else
assert(i.v<height_);
return data_[i.w*width_height_ + i.v*height_ +i.u];
#endif
}
template <typename V>
const V& ValueHolder<V>::Value(const Index& i) const
{
#ifdef USE_ROW_ORDER
assert(i.w<depth_);
return data_[i.u*height_depth_ + i.v*depth_ +i.w];
#else
assert(i.v<height_);
return data_[i.w*width_height_ + i.v*height_ +i.u];
#endif
}
template <typename V>
......
......@@ -32,6 +32,7 @@
#include <ost/img/data_types.hh>
#include <ost/img/size.hh>
#include "index.hh"
#include "type_fw.hh"
namespace value_holder_test {
......@@ -104,14 +105,32 @@ public:
The lookup is based on an integer triplet encapsulated within
Index.
*/
V& Value(const Index& i);
V& Value(const Index& i)
{
#ifdef USE_ROW_ORDER
assert(i.w<depth_);
return data_[i.u*height_depth_ + i.v*depth_ +i.w];
#else
assert(i.v<height_);
return data_[i.w*width_height_ + i.v*height_ +i.u];
#endif
}
//! return direct ro access to the value without boundary check
/*!
The lookup is based on an integer triplet encapsulated within
Index.
*/
const V& Value(const Index& i) const;
const V& Value(const Index& i) const
{
#ifdef USE_ROW_ORDER
assert(i.w<depth_);
return data_[i.u*height_depth_ + i.v*depth_ +i.w];
#else
assert(i.v<height_);
return data_[i.w*width_height_ + i.v*height_ +i.u];
#endif
}
//! return pointer to raw data
VPtr GetData() {return &data_[0];}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment