/usr/include/vigra/multi_blocking.hxx is in libvigraimpex-dev 1.10.0+git20160211.167be93+dfsg-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | /************************************************************************/
/* */
/* Copyright 2015 by Thorsten Beier */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_MULTI_BLOCKING_HXX
#define VIGRA_MULTI_BLOCKING_HXX
#include "vigra/tinyvector.hxx"
#include "vigra/box.hxx"
#include "vigra/multi_iterator.hxx"
#include "vigra/multi_convolution.hxx"
#include "vigra/transform_iterator.hxx"
namespace vigra{
// forward declaration
template<unsigned int DIM, class C>
class MultiBlocking;
/// \cond
namespace detail_multi_blocking{
template<unsigned int DIM, class C>
class BlockWithBorder{
public:
typedef C PointValue;
typedef TinyVector<PointValue, DIM> Point;
typedef Point Shape;
typedef Box<PointValue, DIM> Block;
typedef MultiCoordinateIterator< DIM> MultiCoordIter;
BlockWithBorder(const Block & core = Block(), const Block & border = Block())
: core_(core),
border_(border){
}
/// get the core block
const Block & core()const{
return core_;
}
Block localCore()const{
return core_-border_.begin();
}
const Block & border()const{
return border_;
}
bool operator == (const BlockWithBorder & rhs) const{
return core_ == rhs.core_ && border_ == rhs.border_;
}
bool operator != (const BlockWithBorder & rhs) const{
return core_ != rhs.core_ || border_ != rhs.border_;
}
private:
Block core_;
Block border_;
};
template<class VALUETYPE, unsigned int DIMENSION>
std::ostream& operator<< (std::ostream& stream, const BlockWithBorder<DIMENSION,VALUETYPE> & bwb) {
stream<<"["<<bwb.core()<<", "<<bwb.border()<<" ]";
return stream;
}
template<class MB>
class MultiCoordToBlockWithBoarder{
public:
typedef typename MB::Shape Shape;
typedef typename MB::BlockDesc BlockDesc;
typedef typename MB::BlockWithBorder result_type;
MultiCoordToBlockWithBoarder()
: mb_(NULL),
width_(){
}
MultiCoordToBlockWithBoarder(const MB & mb, const Shape & width)
: mb_(&mb),
width_(width){
}
result_type operator()(const BlockDesc & blockDesc)const{
return mb_->getBlockWithBorder(blockDesc, width_);
}
private:
const MB * mb_;
Shape width_;
};
template<class MB>
class MultiCoordToBlock{
public:
typedef typename MB::Shape Shape;
typedef typename MB::BlockDesc BlockDesc;
typedef typename MB::Block result_type;
MultiCoordToBlock()
: mb_(NULL){
}
MultiCoordToBlock(const MB & mb)
: mb_(&mb){
}
result_type operator()(const BlockDesc & blockDesc)const{
return mb_->getBlock(blockDesc);
}
private:
const MB * mb_;
};
}
/// \endcond
/**
MultiBlocking is used to split a image / volume / multiarray
into non-overlapping blocks.
These non overlapping blocks are called cores.
A border can be added to the core boxes.
These 'core+border' blocks are just called border.
The core block within the coordinate system
of the border block is called local core.
*/
template<unsigned int DIM, class C = MultiArrayIndex>
class MultiBlocking{
public:
typedef MultiBlocking<DIM, C> SelfType;
friend class detail_multi_blocking::MultiCoordToBlock<SelfType>;
friend class detail_multi_blocking::MultiCoordToBlockWithBoarder<SelfType>;
typedef C PointValue;
typedef TinyVector<PointValue, DIM> Point;
typedef Point Shape;
typedef Point BlockDesc;
typedef Box<PointValue, DIM> Block;
typedef MultiCoordinateIterator< DIM> MultiCoordIter;
typedef detail_multi_blocking::BlockWithBorder<DIM, PointValue> BlockWithBorder;
// iterators
typedef detail_multi_blocking::MultiCoordToBlockWithBoarder<SelfType> CoordToBwb;
typedef detail_multi_blocking::MultiCoordToBlock<SelfType> CoordToB;
typedef EndAwareTransformIterator<CoordToBwb, MultiCoordIter> BlockWithBorderIter;
typedef EndAwareTransformIterator<CoordToB, MultiCoordIter> BlockIter;
MultiBlocking(const Shape & shape,
const Shape & blockShape,
const Shape & roiBegin = Shape(0),
const Shape & roiEnd = Shape(0)
)
: shape_(shape),
roiBlock_(roiBegin,roiEnd == Shape(0) ? shape : roiEnd),
blockShape_(blockShape),
blocksPerAxis_(vigra::SkipInitialization),
numBlocks_(1)
{
const Shape roiShape = roiBlock_.size();
blocksPerAxis_ = roiShape / blockShape_;
// blocking
for(size_t d=0; d<DIM; ++d){
if(blocksPerAxis_[d]*blockShape_[d] < roiShape[d] ){
++blocksPerAxis_[d];
}
numBlocks_ *= blocksPerAxis_[d];
}
// total image border blocks
Shape beginCA(0),endCB(shape);
for(size_t d=0; d<DIM; ++d){
{
// fix coordinate d to zero
Shape endCA(shape);
endCA[d] = 1;
volumeBorderBlocks_.push_back(Block(beginCA,endCA));
}
{
// fix coordinate d to shape[dim]-1
Shape beginCB(shape);
beginCB[d] -= 1;
volumeBorderBlocks_.push_back(Block(beginCB,endCB));
}
}
insideVolBlock_.setBegin(Shape(1));
Shape insideVolBlockShapeEnd(shape);
insideVolBlockShapeEnd -= Shape(1);
insideVolBlock_.setEnd(insideVolBlockShapeEnd);
}
/// total number of blocks
size_t numBlocks()const{
return numBlocks_;
}
BlockWithBorderIter blockWithBorderBegin(const Shape & width)const{
return BlockWithBorderIter(MultiCoordIter(blocksPerAxis_),
CoordToBwb(*this, width));
}
BlockWithBorderIter blockWithBorderEnd(const Shape & width)const{
const MultiCoordIter beginIter(blocksPerAxis_);
return BlockWithBorderIter(beginIter.getEndIterator(),
CoordToBwb(*this, width));
}
Block blockDescToBlock(const BlockDesc & desc){
MultiCoordIter beginIter(blocksPerAxis_);
beginIter+=desc;
return *BlockIter(beginIter,CoordToB(*this));
}
BlockIter blockBegin()const{
return BlockIter(MultiCoordIter(blocksPerAxis_),CoordToB(*this));
}
BlockIter blockEnd()const{
const MultiCoordIter beginIter(blocksPerAxis_);
return BlockIter(beginIter.getEndIterator(),CoordToB(*this));
}
Block blockDescToBlock(const BlockDesc & blockDesc)const{
MultiCoordIter iter(blocksPerAxis_);
iter+=blockDesc;
return *BlockIter(iter,CoordToB(*this));
}
/// does this block intersect with the volume border
bool containsVolumeBorder(const Block & block) const {
return !insideVolBlock_.contains(block);
}
const Shape & roiBegin()const{
return roiBlock_.begin();
}
const Shape & roiEnd()const{
return roiBlock_.end();
}
const Shape & shape()const{
return shape_;
}
const Shape & blockShape()const{
return blockShape_;
}
const Shape & blocksPerAxis()const{
return blocksPerAxis_;
}
const std::vector<Block> & volumeBorderBlocks()const{
return volumeBorderBlocks_;
}
std::vector<UInt32> intersectingBlocks(
const Shape roiBegin,
const Shape roiEnd
)const{
size_t i=0;
std::vector<UInt32> iBlocks;
const Block testBlock(roiBegin, roiEnd);
for(BlockIter iter=blockBegin(); iter!=blockEnd(); ++iter){
if(testBlock.intersects(*iter)){
iBlocks.push_back(i);
}
++i;
}
return iBlocks;
}
private:
/// get a block with border
BlockWithBorder getBlockWithBorder(const BlockDesc & blockDesc, const Shape & width )const{
const Point blockStart(blockDesc * blockShape_ + roiBlock_.begin());
const Point blockEnd(blockStart + blockShape_);
const Block core = Block(blockStart, blockEnd) & roiBlock_ ;
Block border = core;
border.addBorder(width);
border &= Block(shape_);
return BlockWithBorder( core, border );
}
/// get a block (without any overlap)
Block getBlock(const BlockDesc & blockDesc)const{
const Point blockStart(blockDesc * blockShape_ + roiBlock_.begin());
const Point blockEnd(blockStart + blockShape_);
return Block(blockStart, blockEnd) & roiBlock_;
}
Shape shape_; // total shape of the input volume
Block roiBlock_; // ROI in which to compute filters/algorithms
Shape blockShape_; // shape sub-block for each thread (without border pixels)
Shape blocksPerAxis_; // how many blocks are on each axis
size_t numBlocks_; // total number of blocks
std::vector<Block> volumeBorderBlocks_;
Block insideVolBlock_;
};
}
#endif // VIGRA_MULTI_BLOCKING_HXX
|