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
159const FsSurface& FsSurfaceSet::operator[](qint32 idx) const
160{
161 if (idx == 0)
162 return m_qMapSurfs.find(idx).value();
163 else if (idx == 1)
164 return m_qMapSurfs.find(idx).value();
165 else {
166 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
167 return m_qMapSurfs.find(0).value();
168 }
169}
170
171//=============================================================================================================
172
174{
175 if (idx == 0)
176 return m_qMapSurfs.find(idx).value();
177 else if (idx == 1)
178 return m_qMapSurfs.find(idx).value();
179 else {
180 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
181 return m_qMapSurfs.find(0).value();
182 }
183}
184
185//=============================================================================================================
186
187const FsSurface& FsSurfaceSet::operator[](QString idt) const
188{
189 if (idt.compare("lh") == 0)
190 return m_qMapSurfs.find(0).value();
191 else if (idt.compare("rh") == 0)
192 return m_qMapSurfs.find(1).value();
193 else {
194 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
195 return m_qMapSurfs.find(0).value();
196 }
197}
198
199//=============================================================================================================
200
202{
203 if (idt.compare("lh") == 0)
204 return m_qMapSurfs.find(0).value();
205 else if (idt.compare("rh") == 0)
206 return m_qMapSurfs.find(1).value();
207 else {
208 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
209 return m_qMapSurfs.find(0).value();
210 }
211}
212
213//=============================================================================================================
214
215void FsSurfaceSet::calcOffset()
216{
217 //
218 // Correct inflated offset
219 //
220 if (m_qMapSurfs.size() == 2 && QString::compare(m_qMapSurfs.begin().value().surf(), "inflated") == 0) {
221 float xOffset = m_qMapSurfs.find(0).value().rr().col(0).maxCoeff() - m_qMapSurfs.find(1).value().rr().col(0).minCoeff();
222 Vector3f vecLhOffset, vecRhOffset;
223 vecLhOffset << (xOffset / 2.0f), 0, 0;
224 vecRhOffset << (-xOffset / 2.0f), 0, 0;
225 m_qMapSurfs.find(0).value().offset() = vecLhOffset;
226 m_qMapSurfs.find(1).value().offset() = vecRhOffset;
227 }
228}
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)