soma-io  5.0.5
scaledcoding.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef SOMAIO_IO_SCALEDCODING_H
35 #define SOMAIO_IO_SCALEDCODING_H
36 
38 #include <vector>
39 
40 namespace soma
41 {
42 
47  template <typename T>
48  bool canEncodeAsScaledS16( const T* vol, float & slope,
49  float & offset,
50  const std::vector<long> & strides,
51  const std::vector<int> & sizes,
52  bool enableoffset = true,
53  double *maxerr = 0 );
54 
55  // declare specializations that actually do something
56  template <>
57  bool canEncodeAsScaledS16( const float* vol, float & slope,
58  float & offset,
59  const std::vector<long> & strides,
60  const std::vector<int> & sizes,
61  bool enableoffset, double * );
62  template <>
63  bool canEncodeAsScaledS16( const double* vol, float & slope,
64  float & offset,
65  const std::vector<long> & strides,
66  const std::vector<int> & sizes,
67  bool enableoffset, double * );
68 
69  // default implementation always fails
70  template <typename T>
71  inline bool canEncodeAsScaledS16( const T*, float &,
72  float &,
73  const std::vector<long> &,
74  const std::vector<int> &,
75  bool, double * )
76  {
77  return false;
78  }
79 
81  {
82  public :
84  _slope(1), _offset(0), _maxerr(0) {}
85 
86  virtual ~ScaledEncodingInfo() {}
87 
88  double & slope() { return _slope; }
89  double & offset() { return _offset; }
90  double & maxerr() { return _maxerr; }
91 
92  private :
93  double _slope;
94  double _offset;
95  double _maxerr;
96  };
97 
98  template <typename INP, typename OUTP>
100  {
101  public :
102 
106  static ScaledEncodingInfo info( const INP * thing,
107  const std::vector<long> & strides,
108  const std::vector<int> & sizes );
109 
110  static ScaledEncodingInfo rescale( const INP * in,
111  const std::vector<long> & strides,
112  const std::vector<int> & sizes,
113  OUTP * out );
114  };
115 }
116 
117 #endif
118 
119 
120 
Definition: allocator.h:48
bool canEncodeAsScaledS16(const T *vol, float &slope, float &offset, const std::vector< long > &strides, const std::vector< int > &sizes, bool enableoffset=true, double *maxerr=0)
Checks if a volume can be encoded as 16 bit signed ints with a scale factor and optionally an offset...
Definition: scaledcoding.h:71