iRoCS Toolbox  1.1.0
Interpolator.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 /*======================================================================*/
29 /*======================================================================*/
30 
31 #ifndef ATBINTERPOLATOR_HH
32 #define ATBINTERPOLATOR_HH
33 
34 #ifdef HAVE_CONFIG_H
35 #include <config.hh>
36 #endif
37 
38 #include <algorithm>
39 #include <vector>
40 #include <complex>
41 
42 #ifdef HAVE_BLITZ_V9
43 #include <blitz/tinyvec-et.h>
44 #endif
45 
46 #include "BoundaryTreatment.hh"
47 
48 namespace atb
49 {
50 
51 /*======================================================================*/
58 /*======================================================================*/
62  NearestIP = 0x0001,
65  LinearIP = 0x0002,
69  CubicIP = 0x0004,
72  MinimumIP = 0x0008,
75  MaximumIP = 0x0010,
78  MedianIP = 0x0020
79  };
80 
81 /*======================================================================*/
90 /*======================================================================*/
91  template<typename DataT,int Dim>
92  class Interpolator
93  {
94 
95  public:
96 
97 /*======================================================================*/
105 /*======================================================================*/
107  DataT const &boundaryValue = traits<DataT>::zero);
108 
109 /*======================================================================*/
115 /*======================================================================*/
117 
118 /*======================================================================*/
122 /*======================================================================*/
123  virtual ~Interpolator();
124 
125 /*======================================================================*/
134 /*======================================================================*/
136  Interpolator<DataT,Dim> const &ip);
137 
138 /*======================================================================*/
144 /*======================================================================*/
145  virtual Interpolator<DataT,Dim> *clone() const = 0;
146 
147 /*======================================================================*/
153 /*======================================================================*/
154  virtual InterpolationType type() const = 0;
155 
156 /*======================================================================*/
164 /*======================================================================*/
166 
167 /*======================================================================*/
175 /*======================================================================*/
177 
178 /*======================================================================*/
185 /*======================================================================*/
188  DataT const &boundaryValue = traits<DataT>::zero);
189 
190 /*======================================================================*/
200 /*======================================================================*/
201  virtual DataT get(
202  blitz::Array<DataT,Dim> const &data,
203  blitz::TinyVector<double,Dim> const &pos) const = 0;
204 
205  protected:
206 
208 
209  };
210 
211 /*======================================================================*/
220 /*======================================================================*/
221  template<typename DataT,int Dim>
222  class NearestInterpolator : public Interpolator<DataT,Dim>
223  {
224 
225  public:
226 
227 /*======================================================================*/
235 /*======================================================================*/
237  DataT const &boundaryValue = traits<DataT>::zero);
238 
239 /*======================================================================*/
245 /*======================================================================*/
247 
248 /*======================================================================*/
252 /*======================================================================*/
254 
255 /*======================================================================*/
264 /*======================================================================*/
267 
268 /*======================================================================*/
274 /*======================================================================*/
276 
277 /*======================================================================*/
283 /*======================================================================*/
284  InterpolationType type() const;
285 
286 /*======================================================================*/
298 /*======================================================================*/
299  DataT get(
300  blitz::Array<DataT,Dim> const &data,
301  blitz::TinyVector<double,Dim> const &pos) const;
302  };
303 
304 /*======================================================================*/
313 /*======================================================================*/
314  template<typename DataT,int Dim>
315  class LinearInterpolator : public Interpolator<DataT,Dim>
316  {
317 
318  public:
319 
320 /*======================================================================*/
328 /*======================================================================*/
330  DataT const &boundaryValue = traits<DataT>::zero);
331 
332 /*======================================================================*/
338 /*======================================================================*/
340 
341 /*======================================================================*/
345 /*======================================================================*/
347 
348 /*======================================================================*/
357 /*======================================================================*/
360 
361 /*======================================================================*/
367 /*======================================================================*/
369 
370 /*======================================================================*/
376 /*======================================================================*/
377  InterpolationType type() const;
378 
379 /*======================================================================*/
391 /*======================================================================*/
392  DataT get(
393  blitz::Array<DataT,Dim> const &data,
394  blitz::TinyVector<double,Dim> const &pos) const;
395  };
396 
397 /*======================================================================*/
406 /*======================================================================*/
407  template<typename DataT,int Dim>
408  class CubicInterpolator : public Interpolator<DataT,Dim>
409  {
410 
411  public:
412 
413 /*======================================================================*/
421 /*======================================================================*/
423  DataT const &boundaryValue = traits<DataT>::zero);
424 
425 /*======================================================================*/
431 /*======================================================================*/
433 
434 /*======================================================================*/
438 /*======================================================================*/
440 
441 /*======================================================================*/
450 /*======================================================================*/
452  CubicInterpolator<DataT,Dim> const &ip);
453 
454 /*======================================================================*/
460 /*======================================================================*/
462 
463 /*======================================================================*/
469 /*======================================================================*/
470  InterpolationType type() const;
471 
472 /*======================================================================*/
484 /*======================================================================*/
485  DataT get(
486  blitz::Array<DataT,Dim> const &data,
487  blitz::TinyVector<double,Dim> const &pos) const;
488  };
489 
490 
491 /*======================================================================*/
500 /*======================================================================*/
501  template<typename DataT,int Dim>
502  class MinimumInterpolator : public Interpolator<DataT,Dim>
503  {
504 
505  public:
506 
507 /*======================================================================*/
515 /*======================================================================*/
517  DataT const &boundaryValue = traits<DataT>::zero);
518 
519 /*======================================================================*/
525 /*======================================================================*/
527 
528 /*======================================================================*/
532 /*======================================================================*/
534 
535 /*======================================================================*/
544 /*======================================================================*/
547 
548 /*======================================================================*/
554 /*======================================================================*/
556 
557 /*======================================================================*/
563 /*======================================================================*/
564  InterpolationType type() const;
565 
566 /*======================================================================*/
577 /*======================================================================*/
578  DataT get(
579  blitz::Array<DataT,Dim> const &data,
580  blitz::TinyVector<double,Dim> const &pos) const;
581  };
582 
583 
584 /*======================================================================*/
593 /*======================================================================*/
594  template<typename DataT,int Dim>
595  class MaximumInterpolator : public Interpolator<DataT,Dim>
596  {
597 
598  public:
599 
600 /*======================================================================*/
608 /*======================================================================*/
610  DataT const &boundaryValue = traits<DataT>::zero);
611 
612 /*======================================================================*/
618 /*======================================================================*/
620 
621 /*======================================================================*/
625 /*======================================================================*/
627 
628 /*======================================================================*/
637 /*======================================================================*/
640 
641 /*======================================================================*/
647 /*======================================================================*/
649 
650 /*======================================================================*/
656 /*======================================================================*/
657  InterpolationType type() const;
658 
659 /*======================================================================*/
670 /*======================================================================*/
671  DataT get(
672  blitz::Array<DataT,Dim> const &data,
673  blitz::TinyVector<double,Dim> const &pos) const;
674  };
675 
676 
677 /*======================================================================*/
686 /*======================================================================*/
687  template<typename DataT,int Dim>
688  class MedianInterpolator : public Interpolator<DataT,Dim>
689  {
690 
691  public:
692 
693 /*======================================================================*/
701 /*======================================================================*/
703  DataT const &boundaryValue = traits<DataT>::zero);
704 
705 /*======================================================================*/
711 /*======================================================================*/
713 
714 /*======================================================================*/
718 /*======================================================================*/
720 
721 /*======================================================================*/
730 /*======================================================================*/
733 
734 /*======================================================================*/
740 /*======================================================================*/
742 
743 /*======================================================================*/
749 /*======================================================================*/
750  InterpolationType type() const;
751 
752 /*======================================================================*/
763 /*======================================================================*/
764  DataT get(
765  blitz::Array<DataT,Dim> const &data,
766  blitz::TinyVector<double,Dim> const &pos) const;
767  };
768 
769 /*======================================================================*/
776 /*======================================================================*/
777  template<typename DataT,int Dim>
779  {
780 
781  public:
782 
783 /*======================================================================*/
801 /*======================================================================*/
802  static Interpolator<DataT,Dim> *get(
804  DataT const &boundaryValue = traits<DataT>::zero);
805 
806  };
807 
808 
809 /*======================================================================*/
828 /*======================================================================*/
829  template<typename DataT,typename IndexT,int Dim>
830  DataT interpolate(blitz::Array<DataT,Dim> const &data,
831  blitz::TinyVector<IndexT,Dim> const &pos,
832  InterpolationType ipType = LinearIP,
834  DataT const &boundaryValue = traits<DataT>::zero);
835 
836 }
837 
838 #include "Interpolator.icc"
839 
840 #endif
The LinearInterpolator class provides sub-pixel access to blitz++ Arrays using linear interpolation...
Interpolate linearly between the values of adjacent pixels (d-linear interpolation) ...
Definition: Interpolator.hh:65
BoundaryTreatmentType
BoundaryTreatment.hh "libArrayToolbox/BoundaryTreatment.hh".
The traits class provides means to query specific information about different data types...
Definition: TypeTraits.hh:73
Return the median of adjacent pixel values.
Definition: Interpolator.hh:78
Return the minimum of adjacent pixel values.
Definition: Interpolator.hh:72
Fit a cubic function through the local neighborhood around the query position and return it&#39;s value a...
Definition: Interpolator.hh:69
Return the maximum of adjacent pixel values.
Definition: Interpolator.hh:75
virtual InterpolationType type() const =0
Get the corresponding enumeration value for the interpolation type.
The InterpolatorFactory class contains a factory method for creating a new Interpolator object using ...
The CubicInterpolator class provides sub-pixel access to blitz++ Arrays using cubic interpolation...
The MinimumInterpolator class provides sub-pixel access to blitz++ Arrays returning the minimum of al...
BoundaryTreatment< DataT, Dim > * p_bt
BoundaryTreatment< DataT, Dim > const & boundaryTreatment() const
Get a read-only reference to the Interpolator&#39;s boundary treatment object.
InterpolationType
Interpolator.hh "libArrayToolbox/Interpolator.hh".
Definition: Interpolator.hh:59
The MaximumInterpolator class provides sub-pixel access to blitz++ Arrays returning the minimum of al...
Interpolator(BoundaryTreatmentType bt=ValueBT, DataT const &boundaryValue=traits< DataT >::zero)
Constructor.
The NearestInterpolator class provides sub-pixel access to blitz++ Arrays using the nearest neighbor ...
Treat positions beyond the Array domain as having a constant value.
The MedianInterpolator class provides sub-pixel access to blitz++ Arrays returning the median of all ...
Return the pixel value of the closest Array pixel to the query position (nearest neighbor interpolati...
Definition: Interpolator.hh:62
DataT interpolate(blitz::Array< DataT, Dim > const &data, blitz::TinyVector< IndexT, Dim > const &pos, InterpolationType ipType=LinearIP, BoundaryTreatmentType btType=ValueBT, DataT const &boundaryValue=traits< DataT >::zero)
Interpolation within an n-dimensional blitz::Array.
virtual ~Interpolator()
Destructor.
The BoundaryTreatment class provides the interface to all specific BoundaryTreatment subclasses...
The Interpolator class is the base class of all classes implementing interpolation strategies for sub...
Definition: Interpolator.hh:92
Classes and functions for handling out-of-Array access.
virtual Interpolator< DataT, Dim > * clone() const =0
Get a deep copy of this Interpolator object.
Interpolator< DataT, Dim > & operator=(Interpolator< DataT, Dim > const &ip)
Copy assignment operator.
void setBoundaryTreatment(BoundaryTreatmentType bt, DataT const &boundaryValue=traits< DataT >::zero)
Set the Interpolator&#39;s boundary treatment type.