aimsalgo  5.1.2
Neuroimaging image processing
meshinterpoler_d.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 
35 #ifndef AIMS_MESH_MESHINTERPOLER_D_H
36 #define AIMS_MESH_MESHINTERPOLER_D_H
37 
39 
40 namespace aims
41 {
42 
43  template <typename T> TimeTexture<T> *
45  InterpolationType inttype ) const
46  {
47  TimeTexture<T> *tex = new TimeTexture<T>;
48  typename TimeTexture<T>::const_iterator it, et = stex.end();
49  for( it=stex.begin(); it!=et; ++it )
50  resampleTexture( it->second, (*tex)[ it->first ], it->first, inttype );
51 
52  return tex;
53  }
54 
55 
56  template <typename T> void
58  Texture<T> & dest, int timestep,
59  InterpolationType inttype ) const
60  {
61  int stimestep;
62 
63  if( d->sourceVert )
64  {
65  stimestep = 0;
66  }
67  else
68  {
69  // get corresponding timestep on source time mesh
70  AimsSurfaceTriangle::const_iterator its;
71  its = d->source->upper_bound( timestep );
72  --its;
73  stimestep = its->first;
74  }
75  size_t n = d->projTriangles[stimestep].data().size();
76  std::vector<T> & tx = dest.data();
77  tx.clear();
78  tx.reserve( n );
79  tx.insert( tx.end(), n, T() );
80  resampleTexture( &source.data()[0], &tx[0], timestep, inttype );
81  }
82 
83 
84  template <typename T> void
85  MeshInterpoler::resampleTexture( const T *source, T *dest,
86  int timestep,
87  InterpolationType inttype ) const
88  {
89  int stimestep;
90  const AimsVector<uint,3> *poly1;
91 
92  if( d->sourceVert )
93  {
94  stimestep = 0;
95  poly1 = d->sourcePoly;
96  }
97  else
98  {
99  // get corresponding timestep on source time mesh
100  AimsSurfaceTriangle::const_iterator its;
101  its = d->source->upper_bound( timestep );
102  --its;
103  stimestep = its->first;
104  const AimsSurface<3,Void> & s1 = its->second;
105  poly1 = &s1.polygon()[0];
106  }
107 
108  const std::vector<float> & coord1 = d->projCoord1[stimestep].data();
109  const std::vector<float> & coord2 = d->projCoord2[stimestep].data();
110  const std::vector<float> & coord3 = d->projCoord3[stimestep].data();
111  const std::vector<unsigned> & triCorresp
112  = d->projTriangles[stimestep].data();
113  size_t i, n = triCorresp.size();
114 
115  switch( inttype )
116  {
117  case Linear:
118  for( i=0; i<n; ++i )
119  {
120  const AimsVector<uint,3> & tri = poly1[ triCorresp[i] ];
121  const T & v1 = source[ tri[0] ];
122  const T & v2 = source[ tri[1] ];
123  const T & v3 = source[ tri[2] ];
124  float a = coord1[i], b = coord2[i], c = coord3[i];
125  dest[i] = v1 * a + v2 * b + v3 * c;
126  }
127  break;
128  case NearestNeighbour:
129  for( i=0; i<n; ++i )
130  {
131  const AimsVector<uint,3> & tri = poly1[ triCorresp[i] ];
132  const T & v1 = source[ tri[0] ];
133  const T & v2 = source[ tri[1] ];
134  const T & v3 = source[ tri[2] ];
135  float a = fabs( coord1[i] ), b = fabs( coord2[i] ),
136  c = fabs( coord3[i] );
137  if( a >= b && a >= c )
138  dest[i] = v1;
139  else if( b >= a && b >= c )
140  dest[i] = v2;
141  else
142  dest[i] = v3;
143  }
144  break;
145  default:
146  break;
147  }
148  }
149 
150 
151 }
152 
153 #endif
154 
const std::vector< AimsVector< uint, D > > & polygon() const
const std::vector< T > & data() const
std::map< int, Texture< T > >::const_iterator const_iterator
TimeTexture< T > * resampleTexture(const TimeTexture< T > &, InterpolationType=Linear) const
TimeTexture< float > projCoord3
TimeTexture< float > projCoord1
TimeTexture< uint > projTriangles
TimeTexture< float > projCoord2
const AimsSurfaceTriangle * source
const AimsVector< uint, 3 > * sourcePoly