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