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 if (FsSurface::read(subject_id, hemi, surf, subjects_dir, t_Surface))
47 insert(t_Surface);
48 } else if (hemi == 2) {
49 if (FsSurface::read(subject_id, 0, surf, subjects_dir, t_Surface))
50 insert(t_Surface);
51 if (FsSurface::read(subject_id, 1, surf, subjects_dir, t_Surface))
52 insert(t_Surface);
53 }
54
55 calcOffset();
56}
57
58//=============================================================================================================
59
60FsSurfaceSet::FsSurfaceSet(const QString& path, qint32 hemi, const QString& surf)
61{
62 FsSurface t_Surface;
63 if (hemi == 0 || hemi == 1) {
64 if (FsSurface::read(path, hemi, surf, t_Surface))
65 insert(t_Surface);
66 } else if (hemi == 2) {
67 if (FsSurface::read(path, 0, surf, t_Surface))
68 insert(t_Surface);
69 if (FsSurface::read(path, 1, surf, t_Surface))
70 insert(t_Surface);
71 }
72
73 calcOffset();
74}
75
76//=============================================================================================================
77
78FsSurfaceSet::FsSurfaceSet(const FsSurface& p_LHSurface, const FsSurface& p_RHSurface)
79{
80 if (p_LHSurface.hemi() == 0)
81 m_qMapSurfs.insert(0, p_LHSurface);
82 else
83 qWarning("Left hemisphere id is not 0. LH surface not assigned!");
84
85 if (p_RHSurface.hemi() == 1)
86 m_qMapSurfs.insert(1, p_RHSurface);
87 else
88 qWarning("Right hemisphere id is not 1. RH surface not assigned!");
89
90 calcOffset();
91}
92
93//=============================================================================================================
94
95FsSurfaceSet::FsSurfaceSet(const QString& p_sLHFileName, const QString& p_sRHFileName)
96{
97 FsSurfaceSet t_SurfaceSet;
98 if (FsSurfaceSet::read(p_sLHFileName, p_sRHFileName, t_SurfaceSet))
99 *this = t_SurfaceSet;
100}
101
102//=============================================================================================================
103
107
108//=============================================================================================================
109
111{
112 m_qMapSurfs.clear();
113}
114
115//=============================================================================================================
116
117void FsSurfaceSet::insert(const FsSurface& p_Surface)
118{
119 if (p_Surface.isEmpty())
120 return;
121
122 qint32 hemi = p_Surface.hemi();
123 m_qMapSurfs.remove(hemi);
124
125 m_qMapSurfs.insert(hemi, p_Surface);
126}
127
128//=============================================================================================================
129
130bool FsSurfaceSet::read(const QString& p_sLHFileName, const QString& p_sRHFileName, FsSurfaceSet& p_SurfaceSet)
131{
132 p_SurfaceSet.clear();
133
134 QStringList t_qListFileName;
135 t_qListFileName << p_sLHFileName << p_sRHFileName;
136
137 for (qint32 i = 0; i < t_qListFileName.size(); ++i) {
138 FsSurface t_Surface;
139 if (FsSurface::read(t_qListFileName[i], t_Surface)) {
140 if (t_qListFileName[i].contains("lh."))
141 p_SurfaceSet.m_qMapSurfs.insert(0, t_Surface);
142 else if (t_qListFileName[i].contains("rh."))
143 p_SurfaceSet.m_qMapSurfs.insert(1, t_Surface);
144 else
145 return false;
146 }
147 }
148
149 if (p_SurfaceSet.m_qMapSurfs.isEmpty())
150 return false;
151
152 p_SurfaceSet.calcOffset();
153
154 return true;
155}
156
157//=============================================================================================================
158
159namespace
160{
161
162qint32 hemiIndex(qint32 idx)
163{
164 if (idx != 0 && idx != 1) {
165 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
166 return 0;
167 }
168 return idx;
169}
170
171qint32 hemiIndex(const QString& idt)
172{
173 if (idt == QLatin1String("rh"))
174 return 1;
175 if (idt != QLatin1String("lh"))
176 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
177 return 0;
178}
179
180const FsSurface& surfaceOrEmpty(const QMap<qint32, FsSurface>& surfs, qint32 hemi)
181{
182 static const FsSurface empty;
183 const auto it = surfs.constFind(hemi);
184 return it != surfs.constEnd() ? it.value() : empty;
185}
186
187} // namespace
188
189//=============================================================================================================
190
191const FsSurface& FsSurfaceSet::operator[](qint32 idx) const
192{
193 return surfaceOrEmpty(m_qMapSurfs, hemiIndex(idx));
194}
195
196//=============================================================================================================
197
199{
200 return m_qMapSurfs[hemiIndex(idx)];
201}
202
203//=============================================================================================================
204
205const FsSurface& FsSurfaceSet::operator[](QString idt) const
206{
207 return surfaceOrEmpty(m_qMapSurfs, hemiIndex(idt));
208}
209
210//=============================================================================================================
211
213{
214 return m_qMapSurfs[hemiIndex(idt)];
215}
216
217//=============================================================================================================
218
219void FsSurfaceSet::calcOffset()
220{
221 //
222 // Correct inflated offset
223 //
224 if (m_qMapSurfs.size() == 2 && QString::compare(m_qMapSurfs.begin().value().surf(), "inflated") == 0) {
225 float xOffset = m_qMapSurfs.find(0).value().rr().col(0).maxCoeff() - m_qMapSurfs.find(1).value().rr().col(0).minCoeff();
226 Vector3f vecLhOffset, vecRhOffset;
227 vecLhOffset << (xOffset / 2.0f), 0, 0;
228 vecRhOffset << (-xOffset / 2.0f), 0, 0;
229 m_qMapSurfs.find(0).value().offset() = vecLhOffset;
230 m_qMapSurfs.find(1).value().offset() = vecRhOffset;
231 }
232}
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:94
bool isEmpty() const
Definition fs_surface.h:364
qint32 hemi() const
Definition fs_surface.h:357
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)