41 #include "../common/metatreeitem.h"
42 #include "../../3dhelpers/renderable3Dentity.h"
43 #include "../../materials/networkmaterial.h"
44 #include "../../3dhelpers/custommesh.h"
45 #include "../../3dhelpers/geometrymultiplier.h"
46 #include "../../materials/geometrymultipliermaterial.h"
62 #include <Qt3DExtras/QSphereGeometry>
63 #include <Qt3DExtras/QCylinderGeometry>
64 #include <Qt3DCore/QTransform>
76 using namespace Eigen;
77 using namespace MNELIB;
78 using namespace DISP3DLIB;
79 using namespace CONNECTIVITYLIB;
80 using namespace DISPLIB;
86 NetworkTreeItem::NetworkTreeItem(Qt3DCore::QEntity *p3DEntityParent,
int iType,
const QString &text)
94 void NetworkTreeItem::initItem()
96 this->setEditable(
false);
97 this->setCheckable(
true);
98 this->setCheckState(Qt::Checked);
99 this->setToolTip(
"Network item");
102 QList<QStandardItem*> list;
105 QVector3D vecEdgeTrehshold(0,0.5,1);
106 if(!m_pItemNetworkThreshold) {
107 m_pItemNetworkThreshold =
new MetaTreeItem(MetaTreeItemTypes::DataThreshold,
108 QString(
"%1,%2,%3").arg(vecEdgeTrehshold.x()).arg(vecEdgeTrehshold.y()).arg(vecEdgeTrehshold.z()));
111 list << m_pItemNetworkThreshold;
112 list <<
new QStandardItem(m_pItemNetworkThreshold->toolTip());
113 this->appendRow(list);
114 data.setValue(vecEdgeTrehshold);
115 m_pItemNetworkThreshold->setData(data, MetaTreeItemRoles::DataThreshold);
117 this, &NetworkTreeItem::onNetworkThresholdChanged);
121 this, &NetworkTreeItem::onColormapTypeChanged);
123 list << pItemColormapType;
124 list <<
new QStandardItem(pItemColormapType->toolTip());
125 this->appendRow(list);
126 data.setValue(QString(
"Hot"));
127 pItemColormapType->setData(data, MetaTreeItemRoles::ColormapType);
131 list << pItemNetworkMatrix;
132 list <<
new QStandardItem(pItemNetworkMatrix->toolTip());
133 this->appendRow(list);
147 Network tNetwork = tNetworkData;
148 tNetwork.
setThreshold(m_pItemNetworkThreshold->data(MetaTreeItemRoles::DataThreshold).value<QVector3D>().x());
150 data.setValue(tNetwork);
151 this->
setData(data, Data3DTreeModelItemRoles::NetworkData);
155 data.setValue(matDist);
156 this->
setData(data, Data3DTreeModelItemRoles::Data);
159 if(this->checkState() == Qt::Checked) {
160 plotNetwork(tNetwork);
168 if(m_pItemNetworkThreshold) {
170 data.setValue(vecThresholds);
171 m_pItemNetworkThreshold->setData(data, MetaTreeItemRoles::DataThreshold);
173 QString sTemp = QString(
"%1,%2,%3").arg(vecThresholds.x()).arg(vecThresholds.y()).arg(vecThresholds.z());
174 data.setValue(sTemp);
175 m_pItemNetworkThreshold->setData(data, Qt::DisplayRole);
181 void NetworkTreeItem::onNetworkThresholdChanged(
const QVariant& vecThresholds)
183 if(vecThresholds.canConvert<QVector3D>()) {
184 Network tNetwork = this->data(Data3DTreeModelItemRoles::NetworkData).value<
Network>();
191 void NetworkTreeItem::onColorChanged(
const QVariant& color)
193 if(color.canConvert<QColor>()) {
194 QColor networkColor = color.value<QColor>();
196 Network tNetwork = this->data(Data3DTreeModelItemRoles::NetworkData).value<
Network>();
199 info.colEdges = Vector4i(networkColor.red(),
200 networkColor.green(),
202 networkColor.alpha());
203 info.colNodes = Vector4i(networkColor.red(),
204 networkColor.green(),
206 networkColor.alpha());
207 tNetwork.setVisualizationInfo(info);
210 data.setValue(tNetwork);
212 this->
setData(data, Data3DTreeModelItemRoles::NetworkData);
214 plotNetwork(tNetwork);
220 void NetworkTreeItem::onColormapTypeChanged(
const QVariant& sColormapType)
222 if(sColormapType.canConvert<QString>()) {
223 Network tNetwork = this->data(Data3DTreeModelItemRoles::NetworkData).value<
Network>();
226 info.sColormap = sColormapType.toString();
230 data.setValue(tNetwork);
232 this->
setData(data, Data3DTreeModelItemRoles::NetworkData);
234 plotNetwork(tNetwork);
240 void NetworkTreeItem::plotNetwork(
const Network& tNetworkData)
243 plotNodes(tNetworkData);
244 plotEdges(tNetworkData);
249 void NetworkTreeItem::plotNodes(
const Network& tNetworkData)
252 qDebug() <<
"NetworkTreeItem::plotNodes - Network data is empty. Returning.";
256 QList<NetworkNode::SPtr> lNetworkNodes = tNetworkData.
getNodes();
261 if(!m_pNodesEntity) {
262 m_pNodesEntity =
new QEntity(
this);
267 if(!m_pNodesGeometry) {
268 m_pNodesGeometry = QSharedPointer<Qt3DExtras::QSphereGeometry>::create();
269 m_pNodesGeometry->setRadius(0.6f);
274 m_pNodesEntity->addComponent(m_pNodes);
279 m_pNodesEntity->addComponent(pMaterial);
283 QVector<QMatrix4x4> vTransforms;
284 QVector<QColor> vColorsNodes;
288 for(
int i = 0; i < lNetworkNodes.size(); ++i) {
289 iDegree = lNetworkNodes.at(i)->getThresholdedDegree();
292 tempPos = QVector3D(lNetworkNodes.at(i)->getVert()(0),
293 lNetworkNodes.at(i)->getVert()(1),
294 lNetworkNodes.at(i)->getVert()(2));
297 QMatrix4x4 tempTransform;
298 tempTransform.translate(tempPos);
299 tempTransform.scale(((
float)iDegree/(
float)iMaxDegree)*(0.005f-0.0006f)+0.0006f);
301 vTransforms.push_back(tempTransform);
303 if(visualizationInfo.
sMethod ==
"Map") {
305 if(iMaxDegree != 0.0f) {
306 QColor color = ColorMap::valueToColor((
float)iDegree/(
float)iMaxDegree, visualizationInfo.
sColormap);
307 color.setAlphaF(pow((
float)iDegree/(
float)iMaxDegree,4));
308 vColorsNodes.push_back(color);
310 QColor color = ColorMap::valueToColor(0.0, visualizationInfo.
sColormap);
312 vColorsNodes.push_back(color);
315 vColorsNodes.push_back(QColor(visualizationInfo.
colEdges[0],
323 m_pNodes->setTransforms(vTransforms);
324 m_pNodes->setColors(vColorsNodes);
329 void NetworkTreeItem::plotEdges(
const Network &tNetworkData)
332 qDebug() <<
"NetworkTreeItem::plotEdges - Network data is empty. Returning.";
340 QList<NetworkNode::SPtr> lNetworkNodes = tNetworkData.
getNodes();
345 m_pEdgeEntity =
new QEntity(
this);
350 if(!m_pEdgesGeometry) {
351 m_pEdgesGeometry = QSharedPointer<Qt3DExtras::QCylinderGeometry>::create();
352 m_pEdgesGeometry->setRadius(0.001f);
353 m_pEdgesGeometry->setLength(1.0f);
358 m_pEdgeEntity->addComponent(m_pEdges);
363 m_pEdgeEntity->addComponent(pMaterial);
367 QVector<QMatrix4x4> vTransformsEdges;
368 QVector<QColor> vColorsEdges;
369 QVector3D startPos, endPos, edgePos, diff;
370 double dWeight = 0.0;
371 int iStartID, iEndID;
373 for(
int i = 0; i < lNetworkEdges.size(); ++i) {
377 if(pNetworkEdge->isActive()) {
378 iStartID = pNetworkEdge->getStartNodeID();
379 iEndID = pNetworkEdge->getEndNodeID();
381 RowVectorXf vectorStart = lNetworkNodes.at(iStartID)->getVert();
382 startPos = QVector3D(vectorStart(0),
386 RowVectorXf vectorEnd = lNetworkNodes.at(iEndID)->getVert();
387 endPos = QVector3D(vectorEnd(0),
391 if(startPos != endPos) {
392 dWeight = fabs(pNetworkEdge->getWeight());
394 diff = endPos - startPos;
395 edgePos = endPos - diff/2;
397 QMatrix4x4 tempTransform;
398 tempTransform.translate(edgePos);
399 tempTransform.rotate(QQuaternion::rotationTo(QVector3D(0,1,0), diff.normalized()).normalized());
400 tempTransform.scale(fabs((dWeight-dMinWeight)/(dMaxWeight-dMinWeight)),diff.length(),fabs((dWeight-dMinWeight)/(dMaxWeight-dMinWeight)));
403 vTransformsEdges.push_back(tempTransform);
406 if(visualizationInfo.
sMethod ==
"Map") {
408 if(dMaxWeight != 0.0f) {
409 QColor color = ColorMap::valueToColor(fabs(dWeight/dMaxWeight), visualizationInfo.
sColormap);
410 color.setAlphaF(pow(fabs(dWeight/dMaxWeight),1.5));
413 vColorsEdges.push_back(color);
415 QColor color = ColorMap::valueToColor(0.0, visualizationInfo.
sColormap);
416 color.setAlphaF(0.0);
417 vColorsEdges.push_back(color);
420 vColorsEdges.push_back(QColor(visualizationInfo.
colNodes[0],
430 m_pEdges->setTransforms(vTransformsEdges);
431 m_pEdges->setColors(vColorsEdges);