v2.0.0
Loading...
Searching...
No Matches
braintreemodel.cpp
Go to the documentation of this file.
1//=============================================================================================================
38
39//=============================================================================================================
40// INCLUDES
41//=============================================================================================================
42
43#include "braintreemodel.h"
52#include <mne/mne_hemisphere.h>
53
55 : QStandardItemModel(parent)
56{
57 // Set headers
58 setHorizontalHeaderLabels(QStringList() << "Data" << "Description");
59}
60
61SurfaceTreeItem* BrainTreeModel::addSurface(const QString &subject, const QString &hemi, const QString &surfType, const FSLIB::Surface &surface)
62{
63 QStandardItem* subjectItem = getSubjectItem(subject);
64
65 // Find or create Hemi item
66 QStandardItem* hemiItem = nullptr;
67 for(int i = 0; i < subjectItem->rowCount(); ++i) {
68 if (subjectItem->child(i)->text() == hemi) {
69 hemiItem = subjectItem->child(i);
70 break;
71 }
72 }
73
74 if (!hemiItem) {
75 hemiItem = new QStandardItem(hemi);
76 subjectItem->appendRow(hemiItem);
77 }
78
79 // Create Surface Item
80 SurfaceTreeItem* surfItem = new SurfaceTreeItem(surfType);
81 surfItem->setSurfaceData(surface);
82
83 hemiItem->appendRow(surfItem);
84 return surfItem;
85}
86
87bool BrainTreeModel::addAnnotation(const QString &subject, const QString &hemi, const FSLIB::Annotation &annotation)
88{
89 QStandardItem* subjectItem = getSubjectItem(subject);
90 if (!subjectItem) return false;
91
92 QStandardItem* hemiItem = nullptr;
93 for(int i = 0; i < subjectItem->rowCount(); ++i) {
94 if (subjectItem->child(i)->text() == hemi) {
95 hemiItem = subjectItem->child(i);
96 break;
97 }
98 }
99
100 if (!hemiItem) return false;
101
102 // Apply annotation to ALL surfaces in this hemi? Or just one?
103 // Ex_brain_view logic applies atlas to the loaded surfaces of that hemi.
104 // So we iterate children of hemiItem and if they are SurfaceTreeItems, set annotation.
105 bool applied = false;
106 for(int i = 0; i < hemiItem->rowCount(); ++i) {
107 SurfaceTreeItem* item = dynamic_cast<SurfaceTreeItem*>(hemiItem->child(i));
108 if (item) {
109 item->setAnnotationData(annotation);
110 applied = true;
111 }
112 }
113 return applied;
114}
115
116QStandardItem* BrainTreeModel::getSubjectItem(const QString &subject)
117{
118 // Search top level
119 QList<QStandardItem*> items = findItems(subject);
120 if (!items.isEmpty()) {
121 return items.first();
122 }
123
124 // Create new
125 QStandardItem* item = new QStandardItem(subject);
126 appendRow(item);
127 return item;
128}
129
130BemTreeItem* BrainTreeModel::addBemSurface(const QString &subject, const QString &bemName, const MNELIB::MNEBemSurface &bemSurf)
131{
132 QStandardItem *subjItem = getSubjectItem(subject);
133
134 // Check if BEM item already exists to avoid duplicates?
135 // Usually BEM is added once.
136
137 BemTreeItem *bemItem = new BemTreeItem(bemName, bemSurf);
138 bemItem->setVisible(true); // Default to visible
139
140 // Set default colors based on type/name
141 // Set colors based on ID (matching zeiss-intent)
142 // 4=Head (Reddish), 3=OuterSkull (Greenish), 1=InnerSkull (Blueish)
143 if (bemSurf.id == 4) {
144 bemItem->setColor(QColor(128, 77, 77)); // Reddish
145 } else if (bemSurf.id == 3) {
146 bemItem->setColor(QColor(77, 128, 77)); // Greenish
147 } else if (bemSurf.id == 1) {
148 bemItem->setColor(QColor(77, 77, 128)); // Blueish
149 } else {
150 bemItem->setColor(QColor(100, 100, 100)); // Grey default
151 }
152
153 subjItem->appendRow(bemItem);
154
155 return bemItem;
156}
157
158//=============================================================================================================
159
160void BrainTreeModel::addSensors(const QString &type, const QList<QStandardItem*> &items)
161{
162 QStandardItem* parentItem = new QStandardItem(type);
163 parentItem->setCheckable(true);
164 parentItem->setCheckState(Qt::Checked);
165
166 for(auto* item : items) {
167 parentItem->appendRow(item);
168 }
169
170 this->appendRow(parentItem);
171}
172
173//=============================================================================================================
174
176{
177 DipoleTreeItem* item = new DipoleTreeItem("Dipoles", set);
178 item->setCheckable(true);
179 item->setCheckState(Qt::Checked);
180 this->appendRow(item);
181}
182
183//=============================================================================================================
184
186{
187 QStandardItem* parentItem = new QStandardItem("Source Space");
188 parentItem->setCheckable(true);
189 parentItem->setCheckState(Qt::Checked);
190
191 // Color: pinkish-red matching disp3D's source space rendering
192 QColor srcColor(212, 28, 92);
193
194 for (int h = 0; h < srcSpace.size(); ++h) {
195 const auto &hemi = srcSpace[h];
196 QString hemiLabel = (h == 0) ? "LH" : "RH";
197
198 // Collect all source point positions for this hemisphere
199 QVector<QVector3D> positions;
200 positions.reserve(hemi.vertno.size());
201 for (int i = 0; i < hemi.vertno.size(); ++i) {
202 int vIdx = hemi.vertno(i);
203 if (vIdx < 0 || vIdx >= hemi.rr.rows()) continue;
204 positions.append(QVector3D(hemi.rr(vIdx, 0), hemi.rr(vIdx, 1), hemi.rr(vIdx, 2)));
205 }
206
207 // One item per hemisphere with all positions batched (0.00075 = 0.75mm radius, same as disp3D)
208 parentItem->appendRow(new SourceSpaceTreeItem(hemiLabel, positions, srcColor, 0.00075f));
209 qDebug() << "BrainTreeModel: Source space" << hemiLabel
210 << "- points:" << positions.size()
211 << "coord_frame:" << hemi.coord_frame;
212 if (!positions.isEmpty()) {
213 qDebug() << " First point:" << positions.first()
214 << " Last point:" << positions.last();
215 }
216 }
217
218 this->appendRow(parentItem);
219}
220
221//=============================================================================================================
222
223void BrainTreeModel::addDigitizerData(const QList<FIFFLIB::FiffDigPoint> &digitizerPoints)
224{
225 if (digitizerPoints.isEmpty()) return;
226
227 auto *setItem = new DigitizerSetTreeItem("Digitizer", digitizerPoints);
228 this->appendRow(setItem);
229
230 qDebug() << "BrainTreeModel: Added digitizer set with"
231 << setItem->totalPointCount() << "points in"
232 << setItem->rowCount() << "categories";
233}
234
235//=============================================================================================================
236
238{
239 QString displayName = name;
240 if (displayName.isEmpty()) {
241 displayName = network.getConnectivityMethod();
242 if (displayName.isEmpty()) displayName = "Network";
243 }
244
245 QString objectKey = "net_" + displayName.toLower().replace(" ", "_");
246
247 auto *item = new NetworkTreeItem(displayName, objectKey);
248 item->setCheckable(true);
249 item->setCheckState(Qt::Checked);
250
251 this->appendRow(item);
252
253 qDebug() << "BrainTreeModel: Added network" << displayName
254 << "with" << network.getNodes().size() << "nodes and"
255 << network.getFullEdges().size() << "edges";
256
257 return item;
258}
BrainTreeModel class declaration.
SurfaceTreeItem class declaration.
NetworkTreeItem class declaration.
BemTreeItem class declaration.
SourceSpaceTreeItem class declaration.
DipoleTreeItem class declaration.
DigitizerSetTreeItem class declaration.
SensorTreeItem class declaration.
MNEHemisphere class declaration.
FiffDigPointSet class declaration.
This class holds information about a network, can compute a distance table and provide network metric...
Definition network.h:92
QString getConnectivityMethod() const
Definition network.cpp:203
const QList< QSharedPointer< NetworkNode > > & getNodes() const
Definition network.cpp:156
const QList< QSharedPointer< NetworkEdge > > & getFullEdges() const
Definition network.cpp:142
BemTreeItem * addBemSurface(const QString &subject, const QString &bemName, const MNELIB::MNEBemSurface &bemSurf)
void addDigitizerData(const QList< FIFFLIB::FiffDigPoint > &digitizerPoints)
void addSensors(const QString &type, const QList< QStandardItem * > &items)
NetworkTreeItem * addNetwork(const CONNECTIVITYLIB::Network &network, const QString &name="Network")
SurfaceTreeItem * addSurface(const QString &subject, const QString &hemi, const QString &surfType, const FSLIB::Surface &surface)
void addSourceSpace(const MNELIB::MNESourceSpaces &srcSpace)
void addDipoles(const INVERSELIB::ECDSet &set)
BrainTreeModel(QObject *parent=nullptr)
bool addAnnotation(const QString &subject, const QString &hemi, const FSLIB::Annotation &annotation)
void setColor(const QColor &color)
void setVisible(bool visible)
Tree item representing a BEM surface layer in the 3-D scene hierarchy.
Definition bemtreeitem.h:52
Digitizer point set container tree item.
Tree item representing a set of fitted dipoles in the 3-D scene hierarchy.
Tree item representing a connectivity network.
Source space point tree item.
Tree item representing a FreeSurfer cortical surface in the 3-D scene hierarchy.
void setSurfaceData(const FSLIB::Surface &surface)
void setAnnotationData(const FSLIB::Annotation &annotation)
Free surfer annotation.
Definition annotation.h:81
FreeSurfer surface mesh.
Definition surface.h:76
Holds a set of Electric Current Dipoles.
Definition ecd_set.h:81
BEM surface provides geometry information.
Source Space descritpion.