aimsdata  5.1.2
Neuroimaging data handling
cutmesh_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 #ifndef AIMS_MESH_CUTMESH_D_H
35 #define AIMS_MESH_CUTMESH_D_H
36 
37 #include <aims/mesh/cutmesh.h>
38 #include <aims/mesh/surfacemanip.h>
39 
40 namespace aims
41 {
42 
43  template <typename T>
45  const std::vector<const AimsSurfaceTriangle *> & insurf,
46  const std::vector<std::vector<const TimeTexture<T> *> > & intex,
47  const Point4df & plane )
48  : CutMesh( insurf, plane ), _intex( intex )
49  {
50  }
51 
52 
53  template <typename T>
55  const std::vector<const AimsSurfaceTriangle *> & insurf,
56  const std::vector<std::vector<carto::rc_ptr<TimeTexture<T> > > > & intex,
57  const Point4df & plane )
58  : CutMesh( insurf, plane )
59  {
60  setTextures( intex );
61  }
62 
63 
64  template <typename T>
66  {
67  }
68 
69 
70  template <typename T>
72  const std::vector<std::vector<carto::rc_ptr<TimeTexture<T> > > >
73  & intex )
74  {
75  _intexrc = intex;
76  _intex.clear();
77  _intex.resize( intex.size(), std::vector<const TimeTexture<T> *>() );
78  typename std::vector<std::vector<
79  carto::rc_ptr<TimeTexture<T> > > >::const_iterator
80  it, et = intex.end();
81  typename std::vector<std::vector<const TimeTexture<T> *> >::iterator ipt;
82  typename std::vector<carto::rc_ptr<TimeTexture<T> > >::const_iterator
83  iit, eit;
84 
85  for( it=intex.begin(), ipt=_intex.begin(); it!=et; ++it, ++ipt )
86  for( iit=it->begin(), eit=it->end(); iit!=eit; ++iit )
87  ipt->push_back( iit->get() );
88  }
89 
90 
91  template <typename T>
93  const std::vector<std::vector<const TimeTexture<T> *> > & intex )
94  {
95  _intex = intex;
96  _intexrc.clear();
97  }
98 
99 
100  template <typename T>
102  {
103  _cuttex.clear();
104  _cuttex.resize( _insurf.size() );
105  unsigned i, n = _intex.size();
106  if( n > _insurf.size() )
107  n = _insurf.size();
108  for( i=0; i<n; ++i )
109  _cuttex[i].resize( _intex[i].size(),
111  );
112  }
113 
114 
115  template <typename T>
117  {
118  std::vector<const TimeTexture<T> *> & itexs = _intex[ mesh ];
119  std::vector<carto::rc_ptr<TimeTexture<T> > > & otexs = _cuttex[ mesh ];
120  typename std::vector<const TimeTexture<T> *>::const_iterator
121  itex, etex = itexs.end();
122  typename std::vector<carto::rc_ptr<TimeTexture<T> > >::iterator otex;
123 
124  // add one texture point for each input texture
125  for( itex=itexs.begin(), otex=otexs.begin(); itex!=etex; ++itex, ++otex )
126  {
127  const Texture<T> & tex = (*itex)->begin()->second;
128  (**otex)[0].push_back( tex[v] );
129  }
130  }
131 
132 
133  namespace
134  {
135 
136  template <typename T>
137  inline T _interpol( const T & v1, float w1, const T & v2, float w2 )
138  {
139  return ( v1 * w1 + v2 * w2 ) / ( w1 + w2 );
140  }
141 
142 
143  template <>
144  inline int32_t _interpol( const int32_t & v1, float w1,
145  const int32_t & v2, float w2 )
146  {
147  return int32_t( rint( ( v1 * w1 + v2 * w2 ) / ( w1 + w2 ) ) );
148  }
149 
150 
151  template <>
152  inline int16_t _interpol( const int16_t & v1, float w1,
153  const int16_t & v2, float w2 )
154  {
155  return int16_t( rint( ( v1 * w1 + v2 * w2 ) / ( w1 + w2 ) ) );
156  }
157 
158 
159  template <>
160  inline uint32_t _interpol( const uint32_t & v1, float w1,
161  const uint32_t & v2, float w2 )
162  {
163  return uint32_t( rint( ( v1 * w1 + v2 * w2 ) / ( w1 + w2 ) ) );
164  }
165 
166 
167  template <>
168  inline uint16_t _interpol( const uint16_t & v1, float w1,
169  const uint16_t & v2, float w2 )
170  {
171  return uint16_t( rint( ( v1 * w1 + v2 * w2 ) / ( w1 + w2 ) ) );
172  }
173 
174 
175  template <>
176  inline Point2df _interpol( const Point2df & v1, float w1,
177  const Point2df & v2, float w2 )
178  {
179  return ( v1 * w1 + v2 * w2 ) / ( w1 + w2 );
180  }
181 
182  }
183 
184 
185  template <typename T>
187  uint w, float w2 )
188  {
189  std::vector<const TimeTexture<T> *> & itexs = _intex[ mesh ];
190  std::vector<carto::rc_ptr<TimeTexture<T> > > & otexs = _cuttex[ mesh ];
191  typename std::vector<const TimeTexture<T> *>::const_iterator
192  itex, etex = itexs.end();
193  typename std::vector<carto::rc_ptr<TimeTexture<T> > >::iterator otex;
194 
195  // add one texture point for each input texture
196  for( itex=itexs.begin(), otex=otexs.begin(); itex!=etex; ++itex, ++otex )
197  {
198  const Texture<T> & tex = (*itex)->begin()->second;
199  (**otex)[0].push_back( _interpol( tex[v], w1, tex[w], w2 ) );
200  }
201  }
202 
203 
204 }
205 
206 #endif
void push_back(const T &item)
Definition: texture.h:80
Cut meshes by a plane.
Definition: cutmesh.h:60
virtual ~CutTexturedMesh()
Definition: cutmesh_d.h:65
void setTextures(const std::vector< std::vector< carto::rc_ptr< TimeTexture< T > > > > &intex)
Definition: cutmesh_d.h:71
virtual void addTextureInterpolPoint(int mesh, uint v, float w1, uint w, float w2)
this callback is called to handle textures: add tex corresponding to an interpolation between two ver...
Definition: cutmesh_d.h:186
virtual void initializeOutputTextures()
Definition: cutmesh_d.h:101
virtual void addTexturePoint(int mesh, uint v)
this callback is called to handle textures: add tex corresponding to a vertex in the given mesh
Definition: cutmesh_d.h:116
CutTexturedMesh(const std::vector< const AimsSurfaceTriangle * > &insurf, const std::vector< std::vector< const TimeTexture< T > * > > &intex, const Point4df &plane)
Definition: cutmesh_d.h:44
The class for EcatSino data write operation.
Definition: borderfiller.h:13
unsigned int uint