v2.0.0
Loading...
Searching...
No Matches
fs_surfaceset.cpp
Go to the documentation of this file.
1//=============================================================================================================
12
13//=============================================================================================================
14// INCLUDES
15//=============================================================================================================
16
17#include "fs_surfaceset.h"
18
19//=============================================================================================================
20// QT INCLUDES
21//=============================================================================================================
22
23#include <QStringList>
24
25//=============================================================================================================
26// USED NAMESPACES
27//=============================================================================================================
28
29using namespace FSLIB;
30using namespace Eigen;
31
32//=============================================================================================================
33// DEFINE MEMBER METHODS
34//=============================================================================================================
35
39
40//=============================================================================================================
41
42FsSurfaceSet::FsSurfaceSet(const QString &subject_id, qint32 hemi, const QString &surf, const QString &subjects_dir)
43{
44 FsSurface t_Surface;
45 if(hemi == 0 || hemi == 1)
46 {
47 if(FsSurface::read(subject_id, hemi, surf, subjects_dir, t_Surface))
48 insert(t_Surface);
49 }
50 else if(hemi == 2)
51 {
52 if(FsSurface::read(subject_id, 0, surf, subjects_dir, t_Surface))
53 insert(t_Surface);
54 if(FsSurface::read(subject_id, 1, surf, subjects_dir, t_Surface))
55 insert(t_Surface);
56 }
57
58 calcOffset();
59}
60
61//=============================================================================================================
62
63FsSurfaceSet::FsSurfaceSet(const QString &path, qint32 hemi, const QString &surf)
64{
65 FsSurface t_Surface;
66 if(hemi == 0 || hemi == 1)
67 {
68 if(FsSurface::read(path, hemi, surf, t_Surface))
69 insert(t_Surface);
70 }
71 else if(hemi == 2)
72 {
73 if(FsSurface::read(path, 0, surf, t_Surface))
74 insert(t_Surface);
75 if(FsSurface::read(path, 1, surf, t_Surface))
76 insert(t_Surface);
77 }
78
79 calcOffset();
80}
81
82//=============================================================================================================
83
84FsSurfaceSet::FsSurfaceSet(const FsSurface& p_LHSurface, const FsSurface& p_RHSurface)
85{
86 if(p_LHSurface.hemi() == 0)
87 m_qMapSurfs.insert(0, p_LHSurface);
88 else
89 qWarning("Left hemisphere id is not 0. LH surface not assigned!");
90
91 if(p_RHSurface.hemi() == 1)
92 m_qMapSurfs.insert(1, p_RHSurface);
93 else
94 qWarning("Right hemisphere id is not 1. RH surface not assigned!");
95
96 calcOffset();
97}
98
99//=============================================================================================================
100
101FsSurfaceSet::FsSurfaceSet(const QString& p_sLHFileName, const QString& p_sRHFileName)
102{
103 FsSurfaceSet t_SurfaceSet;
104 if(FsSurfaceSet::read(p_sLHFileName, p_sRHFileName, t_SurfaceSet))
105 *this = t_SurfaceSet;
106}
107
108//=============================================================================================================
109
113
114//=============================================================================================================
115
117{
118 m_qMapSurfs.clear();
119}
120
121//=============================================================================================================
122
123void FsSurfaceSet::insert(const FsSurface& p_Surface)
124{
125 if(p_Surface.isEmpty())
126 return;
127
128 qint32 hemi = p_Surface.hemi();
129 m_qMapSurfs.remove(hemi);
130
131 m_qMapSurfs.insert(hemi, p_Surface);
132}
133
134//=============================================================================================================
135
136bool FsSurfaceSet::read(const QString& p_sLHFileName, const QString& p_sRHFileName, FsSurfaceSet &p_SurfaceSet)
137{
138 p_SurfaceSet.clear();
139
140 QStringList t_qListFileName;
141 t_qListFileName << p_sLHFileName << p_sRHFileName;
142
143 for(qint32 i = 0; i < t_qListFileName.size(); ++i)
144 {
145 FsSurface t_Surface;
146 if(FsSurface::read(t_qListFileName[i], t_Surface))
147 {
148 if(t_qListFileName[i].contains("lh."))
149 p_SurfaceSet.m_qMapSurfs.insert(0, t_Surface);
150 else if(t_qListFileName[i].contains("rh."))
151 p_SurfaceSet.m_qMapSurfs.insert(1, t_Surface);
152 else
153 return false;
154 }
155 }
156
157 if(p_SurfaceSet.m_qMapSurfs.isEmpty())
158 return false;
159
160 p_SurfaceSet.calcOffset();
161
162 return true;
163}
164
165//=============================================================================================================
166
167const FsSurface& FsSurfaceSet::operator[] (qint32 idx) const
168{
169 if(idx == 0)
170 return m_qMapSurfs.find(idx).value();
171 else if(idx == 1)
172 return m_qMapSurfs.find(idx).value();
173 else
174 {
175 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
176 return m_qMapSurfs.find(0).value();
177 }
178}
179
180//=============================================================================================================
181
183{
184 if(idx == 0)
185 return m_qMapSurfs.find(idx).value();
186 else if(idx == 1)
187 return m_qMapSurfs.find(idx).value();
188 else
189 {
190 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
191 return m_qMapSurfs.find(0).value();
192 }
193}
194
195//=============================================================================================================
196
197const FsSurface& FsSurfaceSet::operator[] (QString idt) const
198{
199 if(idt.compare("lh") == 0)
200 return m_qMapSurfs.find(0).value();
201 else if(idt.compare("rh") == 0)
202 return m_qMapSurfs.find(1).value();
203 else
204 {
205 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
206 return m_qMapSurfs.find(0).value();
207 }
208}
209
210//=============================================================================================================
211
213{
214 if(idt.compare("lh") == 0)
215 return m_qMapSurfs.find(0).value();
216 else if(idt.compare("rh") == 0)
217 return m_qMapSurfs.find(1).value();
218 else
219 {
220 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
221 return m_qMapSurfs.find(0).value();
222 }
223}
224
225//=============================================================================================================
226
227void FsSurfaceSet::calcOffset()
228{
229 //
230 // Correct inflated offset
231 //
232 if(m_qMapSurfs.size() == 2 && QString::compare(m_qMapSurfs.begin().value().surf(),"inflated") == 0)
233 {
234 float xOffset = m_qMapSurfs.find(0).value().rr().col(0).maxCoeff() - m_qMapSurfs.find(1).value().rr().col(0).minCoeff();
235 Vector3f vecLhOffset, vecRhOffset;
236 vecLhOffset << (xOffset/2.0f), 0, 0;
237 vecRhOffset << (-xOffset/2.0f), 0, 0;
238 m_qMapSurfs.find(0).value().offset() = vecLhOffset;
239 m_qMapSurfs.find(1).value().offset() = vecRhOffset;
240 }
241}
Bi-hemispheric grouping of FreeSurfer surfaces (lh + rh) loaded as a single object.
FreeSurfer surface, annotation and parcellation I/O for mne-cpp.
In-memory FreeSurfer triangular cortical surface for one hemisphere.
Definition fs_surface.h:92
bool isEmpty() const
Definition fs_surface.h:362
qint32 hemi() const
Definition fs_surface.h:355
static bool read(const QString &subject_id, qint32 hemi, const QString &surf, const QString &subjects_dir, FsSurface &p_Surface, bool p_bLoadCurvature=true)
const FsSurface & operator[](qint32 idx) const
QString surf() const
static bool read(const QString &p_sLHFileName, const QString &p_sRHFileName, FsSurfaceSet &p_SurfaceSet)
void insert(const FsSurface &p_Surface)