00001
00002
00003
00004 #ifndef CCTBX_MAPTBX_ACCESSORS_C_GRID_PADDED_P1_H
00005 #define CCTBX_MAPTBX_ACCESSORS_C_GRID_PADDED_P1_H
00006
00007 #include <scitbx/array_family/accessors/flex_grid.h>
00008 #include <cctbx/import_scitbx_af.h>
00009 #include <scitbx/math/modulo.h>
00010
00011 namespace cctbx { namespace maptbx {
00012
00013 template <std::size_t Nd>
00014 class c_grid_padded_p1;
00015
00016 template <>
00017 class c_grid_padded_p1<3>
00018 {
00019 public:
00020 typedef af::tiny<int, 3> index_type;
00021 typedef index_type::value_type index_value_type;
00022
00023 c_grid_padded_p1()
00024 : all_(0,0,0),
00025 focus_(0,0,0)
00026 {}
00027
00028 c_grid_padded_p1(index_type const& all,
00029 index_type const& focus)
00030 : all_(all),
00031 focus_(focus)
00032 {}
00033
00034 template <typename FlexIndexType>
00035 c_grid_padded_p1(af::flex_grid<FlexIndexType> const& flex_g)
00036 :
00037 all_(af::adapt(flex_g.all()))
00038 {
00039 SCITBX_ASSERT(flex_g.is_0_based());
00040 focus_ = index_type(af::adapt(flex_g.focus()));
00041 }
00042
00043 af::flex_grid<>
00044 as_flex_grid() const
00045 {
00046 return af::flex_grid<>(af::adapt(all_))
00047 .set_focus(af::adapt(focus_));
00048 }
00049
00050 std::size_t
00051 size_1d() const
00052 {
00053 return all_[0] * all_[1] * all_[2];
00054 }
00055
00056 index_type const&
00057 all() const { return all_; }
00058
00059 index_type const&
00060 focus() const { return focus_; }
00061
00062 std::size_t
00063 focus_size_1d() const
00064 {
00065 return focus_[0] * focus_[1] * focus_[2];
00066 }
00067
00068 bool is_padded() const
00069 {
00070 SCITBX_ASSERT(all_.all_ge(focus_));
00071 return !all_.all_eq(focus_);
00072 }
00073
00074 std::size_t operator()(index_type const& i) const
00075 {
00076 return (scitbx::math::mod_positive(i[0], focus_[0]) * all_[1]
00077 + scitbx::math::mod_positive(i[1], focus_[1])) * all_[2]
00078 + scitbx::math::mod_positive(i[2], focus_[2]);
00079 }
00080
00081 std::size_t
00082 operator()(index_value_type const& i0,
00083 index_value_type const& i1,
00084 index_value_type const& i2) const
00085 {
00086 return (scitbx::math::mod_positive(i0, focus_[0]) * all_[1]
00087 + scitbx::math::mod_positive(i1, focus_[1])) * all_[2]
00088 + scitbx::math::mod_positive(i2, focus_[2]);
00089 }
00090
00091 protected:
00092 index_type all_;
00093 index_type focus_;
00094 };
00095
00096 }}
00097
00098 #endif // CCTBX_MAPTBX_ACCESSORS_C_GRID_PADDED_P1_H