iRoCS Toolbox  1.1.0
BoundaryTreatment.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2015 Thorsten Falk
4  *
5  * Image Analysis Lab, University of Freiburg, Germany
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  **************************************************************************/
22 
23 /*======================================================================*/
28 /*======================================================================*/
29 
30 #ifndef ATBBOUNDARYTREATMENT_HH
31 #define ATBBOUNDARYTREATMENT_HH
32 
33 #ifdef HAVE_CONFIG_H
34 #include <config.hh>
35 #endif
36 
37 #include <blitz/array.h>
38 
39 #include "TypeTraits.hh"
40 #include "RuntimeError.hh"
41 
42 namespace atb
43 {
44 
45 /*======================================================================*/
51 /*======================================================================*/
55  ValueBT = 0x0001,
59  CyclicBT = 0x0002,
62  RepeatBT = 0x0004,
65  MirrorBT = 0x0008,
73  CropBT = 0x0010
74  };
75 
76 /*======================================================================*/
82 /*======================================================================*/
83  template< typename DataT, int Dim >
85  {
86 
87  public:
88 
89 /*======================================================================*/
93 /*======================================================================*/
95 
96 /*======================================================================*/
102 /*======================================================================*/
104 
105 /*======================================================================*/
109 /*======================================================================*/
110  virtual ~BoundaryTreatment();
111 
112 /*======================================================================*/
121 /*======================================================================*/
123  BoundaryTreatment<DataT,Dim> const &bt);
124 
125 /*======================================================================*/
131 /*======================================================================*/
132  virtual BoundaryTreatment<DataT,Dim> *clone() const = 0;
133 
134 /*======================================================================*/
140 /*======================================================================*/
141  virtual BoundaryTreatmentType type() const = 0;
142 
143 /*======================================================================*/
153 /*======================================================================*/
154  virtual bool providesIndices() const = 0;
155 
156 /*======================================================================*/
167 /*======================================================================*/
168  virtual DataT get(blitz::Array<DataT,Dim> const &data,
169  blitz::TinyVector<ptrdiff_t,Dim> pos) const = 0;
170 
171 /*======================================================================*/
188 /*======================================================================*/
189  virtual blitz::TinyVector<ptrdiff_t,Dim> getIndex(
190  blitz::TinyVector<ptrdiff_t,Dim> pos,
191  blitz::TinyVector<ptrdiff_t,Dim> const &shape) const = 0;
192 
193 /*======================================================================*/
205 /*======================================================================*/
206  virtual DataT get(
207  DataT const *data, ptrdiff_t pos, ptrdiff_t length) const = 0;
208 
209 /*======================================================================*/
226 /*======================================================================*/
227  virtual ptrdiff_t getIndex(ptrdiff_t pos, ptrdiff_t length) const = 0;
228 
229  };
230 
231 /*======================================================================*/
237 /*======================================================================*/
238  template< typename DataT, int Dim >
239  class ValueBoundaryTreatment : public BoundaryTreatment<DataT,Dim>
240  {
241 
242  public:
243 
244 /*======================================================================*/
250 /*======================================================================*/
251  ValueBoundaryTreatment(DataT const &value = traits<DataT>::zero);
252 
253 /*======================================================================*/
259 /*======================================================================*/
261 
262 /*======================================================================*/
266 /*======================================================================*/
268 
269 /*======================================================================*/
278 /*======================================================================*/
281 
282 /*======================================================================*/
288 /*======================================================================*/
290 
291 /*======================================================================*/
297 /*======================================================================*/
298  BoundaryTreatmentType type() const;
299 
300 /*======================================================================*/
309 /*======================================================================*/
310  bool providesIndices() const;
311 
312 /*======================================================================*/
323 /*======================================================================*/
324  DataT get(blitz::Array<DataT,Dim> const &data,
325  blitz::TinyVector<ptrdiff_t,Dim> pos) const;
326 
327 /*======================================================================*/
342 /*======================================================================*/
343  blitz::TinyVector<ptrdiff_t,Dim> getIndex(
344  blitz::TinyVector<ptrdiff_t,Dim> pos,
345  blitz::TinyVector<ptrdiff_t,Dim> const &shape) const;
346 
347 /*======================================================================*/
359 /*======================================================================*/
360  DataT get(DataT const *data, ptrdiff_t pos, ptrdiff_t length) const;
361 
362 /*======================================================================*/
379 /*======================================================================*/
380  ptrdiff_t getIndex(ptrdiff_t pos, ptrdiff_t length) const;
381 
382 /*======================================================================*/
389 /*======================================================================*/
390  DataT const &boundaryValue() const;
391 
392 /*======================================================================*/
399 /*======================================================================*/
400  void setBoundaryValue(DataT const &boundaryValue);
401 
402  private:
403 
404  DataT _value;
405 
406  };
407 
408 /*======================================================================*/
414 /*======================================================================*/
415  template< typename DataT, int Dim >
416  class CyclicBoundaryTreatment : public BoundaryTreatment<DataT,Dim>
417  {
418 
419  public:
420 
421 /*======================================================================*/
425 /*======================================================================*/
427 
428 /*======================================================================*/
434 /*======================================================================*/
436 
437 /*======================================================================*/
441 /*======================================================================*/
443 
444 /*======================================================================*/
453 /*======================================================================*/
456 
457 /*======================================================================*/
463 /*======================================================================*/
465 
466 /*======================================================================*/
472 /*======================================================================*/
473  BoundaryTreatmentType type() const;
474 
475 /*======================================================================*/
484 /*======================================================================*/
485  bool providesIndices() const;
486 
487 /*======================================================================*/
498 /*======================================================================*/
499  DataT get(blitz::Array<DataT,Dim> const &data,
500  blitz::TinyVector<ptrdiff_t,Dim> pos) const;
501 
502 /*======================================================================*/
512 /*======================================================================*/
513  blitz::TinyVector<ptrdiff_t,Dim> getIndex(
514  blitz::TinyVector<ptrdiff_t,Dim> pos,
515  blitz::TinyVector<ptrdiff_t,Dim> const &shape) const;
516 
517 /*======================================================================*/
529 /*======================================================================*/
530  DataT get(
531  DataT const *data, ptrdiff_t pos, ptrdiff_t length) const;
532 
533 /*======================================================================*/
550 /*======================================================================*/
551  ptrdiff_t getIndex(ptrdiff_t pos, ptrdiff_t length) const;
552 
553  };
554 
555 /*======================================================================*/
561 /*======================================================================*/
562  template< typename DataT, int Dim >
563  class RepeatBoundaryTreatment : public BoundaryTreatment<DataT,Dim>
564  {
565 
566  public:
567 
568 /*======================================================================*/
572 /*======================================================================*/
574 
575 /*======================================================================*/
581 /*======================================================================*/
583 
584 /*======================================================================*/
588 /*======================================================================*/
590 
591 /*======================================================================*/
600 /*======================================================================*/
603 
604 /*======================================================================*/
610 /*======================================================================*/
612 
613 /*======================================================================*/
619 /*======================================================================*/
620  BoundaryTreatmentType type() const;
621 
622 /*======================================================================*/
631 /*======================================================================*/
632  bool providesIndices() const;
633 
634 /*======================================================================*/
645 /*======================================================================*/
646  DataT get(blitz::Array<DataT,Dim> const &data,
647  blitz::TinyVector<ptrdiff_t,Dim> pos) const;
648 
649 /*======================================================================*/
659 /*======================================================================*/
660  blitz::TinyVector<ptrdiff_t,Dim> getIndex(
661  blitz::TinyVector<ptrdiff_t,Dim> pos,
662  blitz::TinyVector<ptrdiff_t,Dim> const &shape) const;
663 
664 /*======================================================================*/
676 /*======================================================================*/
677  DataT get(
678  DataT const *data, ptrdiff_t pos, ptrdiff_t length) const;
679 
680 /*======================================================================*/
697 /*======================================================================*/
698  ptrdiff_t getIndex(ptrdiff_t pos, ptrdiff_t length) const;
699 
700  };
701 
702 /*======================================================================*/
708 /*======================================================================*/
709  template< typename DataT, int Dim >
710  class MirrorBoundaryTreatment : public BoundaryTreatment<DataT,Dim>
711  {
712 
713  public:
714 
715 /*======================================================================*/
719 /*======================================================================*/
721 
722 /*======================================================================*/
728 /*======================================================================*/
730 
731 /*======================================================================*/
735 /*======================================================================*/
737 
738 /*======================================================================*/
747 /*======================================================================*/
750 
751 /*======================================================================*/
757 /*======================================================================*/
759 
760 /*======================================================================*/
766 /*======================================================================*/
767  BoundaryTreatmentType type() const;
768 
769 /*======================================================================*/
778 /*======================================================================*/
779  bool providesIndices() const;
780 
781 /*======================================================================*/
792 /*======================================================================*/
793  DataT get(blitz::Array<DataT,Dim> const &data,
794  blitz::TinyVector<ptrdiff_t,Dim> pos) const;
795 
796 /*======================================================================*/
806 /*======================================================================*/
807  blitz::TinyVector<ptrdiff_t,Dim> getIndex(
808  blitz::TinyVector<ptrdiff_t,Dim> pos,
809  blitz::TinyVector<ptrdiff_t,Dim> const &shape) const;
810 
811 /*======================================================================*/
823 /*======================================================================*/
824  DataT get(
825  DataT const *data, ptrdiff_t pos, ptrdiff_t length) const;
826 
827 /*======================================================================*/
844 /*======================================================================*/
845  ptrdiff_t getIndex(ptrdiff_t pos, ptrdiff_t length) const;
846 
847  };
848 
849 /*======================================================================*/
857 /*======================================================================*/
858  template< typename DataT, int Dim >
859  class CropBoundaryTreatment : public BoundaryTreatment<DataT,Dim>
860  {
861 
862  public:
863 
864 /*======================================================================*/
868 /*======================================================================*/
870 
871 /*======================================================================*/
877 /*======================================================================*/
879 
880 /*======================================================================*/
884 /*======================================================================*/
886 
887 /*======================================================================*/
896 /*======================================================================*/
899 
900 /*======================================================================*/
906 /*======================================================================*/
908 
909 /*======================================================================*/
915 /*======================================================================*/
916  BoundaryTreatmentType type() const;
917 
918 /*======================================================================*/
927 /*======================================================================*/
928  bool providesIndices() const;
929 
930 /*======================================================================*/
943 /*======================================================================*/
944  DataT get(blitz::Array<DataT,Dim> const &data,
945  blitz::TinyVector<ptrdiff_t,Dim> pos) const;
946 
947 /*======================================================================*/
960 /*======================================================================*/
961  blitz::TinyVector<ptrdiff_t,Dim> getIndex(
962  blitz::TinyVector<ptrdiff_t,Dim> pos,
963  blitz::TinyVector<ptrdiff_t,Dim> const &shape) const;
964 
965 /*======================================================================*/
977 /*======================================================================*/
978  DataT get(
979  DataT const *data, ptrdiff_t pos, ptrdiff_t length) const;
980 
981 /*======================================================================*/
998 /*======================================================================*/
999  ptrdiff_t getIndex(ptrdiff_t pos, ptrdiff_t length) const;
1000 
1001  };
1002 
1003 /*======================================================================*/
1010 /*======================================================================*/
1011  template<typename DataT, int Dim>
1013  {
1014 
1015  public:
1016 
1017 /*======================================================================*/
1034 /*======================================================================*/
1035  static BoundaryTreatment<DataT,Dim> *get(
1036  BoundaryTreatmentType type, DataT const &value = traits<DataT>::zero);
1037 
1038  };
1039 
1040 }
1041 
1042 #include "BoundaryTreatment.icc"
1043 
1044 #endif
virtual ~BoundaryTreatment()
Destructor.
The BoundaryTreatmentFactory class contains a factory method for creating a BoundaryTreatment object ...
Exception specialization for error handling within libArrayToolbox.
BoundaryTreatmentType
BoundaryTreatment.hh "libArrayToolbox/BoundaryTreatment.hh".
virtual BoundaryTreatment< DataT, Dim > * clone() const =0
Get a deep copy of this BoundaryTreatment object.
The traits class provides means to query specific information about different data types...
Definition: TypeTraits.hh:73
The MirrorBoundaryTreatment class implements mirroring border treatment when accessing Arrays...
Query specific information about different data types.
The CyclicBoundaryTreatment class implements cyclic border treatment when accessing Arrays...
Treat values beyond the Array as if the Array continues cyclically at the boundaries.
The RepeatBoundaryTreatment class implements repeating border treatment when accessing Arrays...
Mirror out-of-Array coordinates at the Array boundaries to get in-Array indices and values...
Treat positions beyond the Array domain as having a constant value.
BoundaryTreatment()
Constructor.
Don&#39;t use out-of-bounds pixels at all.
Always pick the closest in-Array position to the position passed.
The BoundaryTreatment class provides the interface to all specific BoundaryTreatment subclasses...
The ValueBoundaryTreatment class implements constant value border treatment when accessing Arrays...
virtual blitz::TinyVector< ptrdiff_t, Dim > getIndex(blitz::TinyVector< ptrdiff_t, Dim > pos, blitz::TinyVector< ptrdiff_t, Dim > const &shape) const =0
Get the in-Array-Index to the given position.
The CropBoundaryTreatment class has actually no function.
virtual bool providesIndices() const =0
The returned boolean indicates, whether the boundary treatment is able to transform the incoming coor...
virtual BoundaryTreatmentType type() const =0
Get the corresponding enumeration value for the boundary treatment type.
BoundaryTreatment< DataT, Dim > & operator=(BoundaryTreatment< DataT, Dim > const &bt)
Copy assignment operator.