MNE-CPP  beta 1.0
surfaceset.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "surfaceset.h"
42 
43 #include <QStringList>
44 
45 
46 //*************************************************************************************************************
47 //=============================================================================================================
48 // USED NAMESPACES
49 //=============================================================================================================
50 
51 using namespace FSLIB;
52 
53 
54 //*************************************************************************************************************
55 //=============================================================================================================
56 // DEFINE MEMBER METHODS
57 //=============================================================================================================
58 
60 {
61 
62 }
63 
64 
65 //*************************************************************************************************************
66 
67 SurfaceSet::SurfaceSet(const QString &subject_id, qint32 hemi, const QString &surf, const QString &subjects_dir)
68 {
69  Surface t_Surface;
70  if(hemi == 0 || hemi == 1)
71  {
72  if(Surface::read(subject_id, hemi, surf, subjects_dir, t_Surface))
73  insert(t_Surface);
74  }
75  else if(hemi == 2)
76  {
77  if(Surface::read(subject_id, 0, surf, subjects_dir, t_Surface))
78  insert(t_Surface);
79  if(Surface::read(subject_id, 1, surf, subjects_dir, t_Surface))
80  insert(t_Surface);
81  }
82 
83  calcOffset();
84 }
85 
86 
87 //*************************************************************************************************************
88 
89 SurfaceSet::SurfaceSet(const QString &path, qint32 hemi, const QString &surf)
90 {
91  Surface t_Surface;
92  if(hemi == 0 || hemi == 1)
93  {
94  if(Surface::read(path, hemi, surf, t_Surface))
95  insert(t_Surface);
96  }
97  else if(hemi == 2)
98  {
99  if(Surface::read(path, 0, surf, t_Surface))
100  insert(t_Surface);
101  if(Surface::read(path, 1, surf, t_Surface))
102  insert(t_Surface);
103  }
104 
105  calcOffset();
106 }
107 
108 
109 //*************************************************************************************************************
110 
111 SurfaceSet::SurfaceSet(const Surface& p_LHSurface, const Surface& p_RHSurface)
112 {
113  if(p_LHSurface.hemi() == 0)
114  m_qMapSurfs.insert(0, p_LHSurface);
115  else
116  qWarning("Left hemisphere id is not 0. LH surface not assigned!");
117 
118  if(p_RHSurface.hemi() == 1)
119  m_qMapSurfs.insert(1, p_RHSurface);
120  else
121  qWarning("Right hemisphere id is not 1. RH surface not assigned!");
122 
123  calcOffset();
124 }
125 
126 
127 //*************************************************************************************************************
128 
129 SurfaceSet::SurfaceSet(const QString& p_sLHFileName, const QString& p_sRHFileName)
130 {
131  SurfaceSet t_SurfaceSet;
132  if(SurfaceSet::read(p_sLHFileName, p_sRHFileName, t_SurfaceSet))
133  *this = t_SurfaceSet;
134 }
135 
136 
137 //*************************************************************************************************************
138 
140 {
141 }
142 
143 
144 //*************************************************************************************************************
145 
147 {
148  m_qMapSurfs.clear();
149 }
150 
151 
152 //*************************************************************************************************************
153 
154 void SurfaceSet::insert(const Surface& p_Surface)
155 {
156  if(p_Surface.isEmpty())
157  return;
158 
159  qint32 hemi = p_Surface.hemi();
160  m_qMapSurfs.remove(hemi);
161 
162  m_qMapSurfs.insert(hemi, p_Surface);
163 }
164 
165 
166 //*************************************************************************************************************
167 
168 bool SurfaceSet::read(const QString& p_sLHFileName, const QString& p_sRHFileName, SurfaceSet &p_SurfaceSet)
169 {
170  p_SurfaceSet.clear();
171 
172  QStringList t_qListFileName;
173  t_qListFileName << p_sLHFileName << p_sRHFileName;
174 
175  for(qint32 i = 0; i < t_qListFileName.size(); ++i)
176  {
177  Surface t_Surface;
178  if(Surface::read(t_qListFileName[i], t_Surface))
179  {
180  if(t_qListFileName[i].contains("lh."))
181  p_SurfaceSet.m_qMapSurfs.insert(0, t_Surface);
182  else if(t_qListFileName[i].contains("rh."))
183  p_SurfaceSet.m_qMapSurfs.insert(1, t_Surface);
184  else
185  return false;
186  }
187  }
188 
189  p_SurfaceSet.calcOffset();
190 
191  return true;
192 }
193 
194 
195 //*************************************************************************************************************
196 
197 const Surface& SurfaceSet::operator[] (qint32 idx) const
198 {
199  if(idx == 0)
200  return m_qMapSurfs.find(idx).value();
201  else if(idx == 1)
202  return m_qMapSurfs.find(idx).value();
203  else
204  {
205  qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
206  return m_qMapSurfs.find(0).value();
207  }
208 }
209 
210 
211 //*************************************************************************************************************
212 
214 {
215  if(idx == 0)
216  return m_qMapSurfs.find(idx).value();
217  else if(idx == 1)
218  return m_qMapSurfs.find(idx).value();
219  else
220  {
221  qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
222  return m_qMapSurfs.find(0).value();
223  }
224 }
225 
226 
227 //*************************************************************************************************************
228 
229 const Surface& SurfaceSet::operator[] (QString idt) const
230 {
231  if(idt.compare("lh") == 0)
232  return m_qMapSurfs.find(0).value();
233  else if(idt.compare("rh") == 0)
234  return m_qMapSurfs.find(1).value();
235  else
236  {
237  qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
238  return m_qMapSurfs.find(0).value();
239  }
240 }
241 
242 
243 //*************************************************************************************************************
244 
246 {
247  if(idt.compare("lh") == 0)
248  return m_qMapSurfs.find(0).value();
249  else if(idt.compare("rh") == 0)
250  return m_qMapSurfs.find(1).value();
251  else
252  {
253  qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
254  return m_qMapSurfs.find(0).value();
255  }
256 }
257 
258 
259 //*************************************************************************************************************
260 
261 void SurfaceSet::calcOffset()
262 {
263  //
264  // Correct inflated offset
265  //
266  if(m_qMapSurfs.size() == 2 && QString::compare(m_qMapSurfs.begin().value().surf(),"inflated") == 0)
267  {
268  float xOffset = m_qMapSurfs.find(0).value().rr().col(0).maxCoeff() - m_qMapSurfs.find(1).value().rr().col(0).minCoeff();
269  Vector3f vecLhOffset, vecRhOffset;
270  vecLhOffset << (xOffset/2.0f), 0, 0;
271  vecRhOffset << (-xOffset/2.0f), 0, 0;
272  m_qMapSurfs.find(0).value().offset() = vecLhOffset;
273  m_qMapSurfs.find(1).value().offset() = vecRhOffset;
274  }
275 }
bool isEmpty() const
Definition: surface.h:312
const Surface & operator[](qint32 idx) const
Definition: surfaceset.cpp:197
SurfaceSet class declaration.
void insert(const Surface &p_Surface)
Definition: surfaceset.cpp:154
static bool read(const QString &p_sLHFileName, const QString &p_sRHFileName, SurfaceSet &p_SurfaceSet)
Definition: surfaceset.cpp:168
FreeSurfer surface mesh.
Definition: surface.h:92
qint32 hemi() const
Definition: surface.h:304
static bool read(const QString &subject_id, qint32 hemi, const QString &surf, const QString &subjects_dir, Surface &p_Surface, bool p_bLoadCurvature=true)
Definition: surface.cpp:197
A hemisphere set of surfaces.
Definition: surfaceset.h:83