MNE-CPP  0.1.9
A Framework for Electrophysiology
abstractmeshtreeitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "abstractmeshtreeitem.h"
41 #include "../common/metatreeitem.h"
42 #include "../../materials/gpuinterpolationmaterial.h"
43 #include "../../materials/pervertexphongalphamaterial.h"
44 #include "../../materials/pervertextessphongalphamaterial.h"
45 #include "../../materials/shownormalsmaterial.h"
46 #include "../../3dhelpers/custommesh.h"
47 
48 //=============================================================================================================
49 // QT INCLUDES
50 //=============================================================================================================
51 
52 //=============================================================================================================
53 // EIGEN INCLUDES
54 //=============================================================================================================
55 
56 #include <Eigen/Core>
57 
58 //=============================================================================================================
59 // USED NAMESPACES
60 //=============================================================================================================
61 
62 using namespace DISP3DLIB;
63 using namespace Eigen;
64 
65 //=============================================================================================================
66 // DEFINE MEMBER METHODS
67 //=============================================================================================================
68 
69 AbstractMeshTreeItem::AbstractMeshTreeItem(QEntity* p3DEntityParent, int iType, const QString& text)
70 : Abstract3DTreeItem(p3DEntityParent, iType, text)
71 , m_pMaterial(new PerVertexPhongAlphaMaterial)
72 , m_pCustomMesh(new CustomMesh())
73 {
74  initItem();
75 }
76 
77 //=============================================================================================================
78 
80 {
81  return m_pCustomMesh;
82 }
83 
84 //=============================================================================================================
85 
86 void AbstractMeshTreeItem::setVertColor(const MatrixX4f& vertColor)
87 {
88  QVariant data;
89  data.setValue(vertColor);
90 
91  this->setData(data, Data3DTreeModelItemRoles::SurfaceCurrentColorVert);
92 }
93 
94 //=============================================================================================================
95 
97 {
98  this->setEditable(false);
99  this->setCheckable(true);
100  this->setCheckState(Qt::Checked);
101  this->setToolTip("Abstract Mesh Tree Item");
102 
103  //Add surface meta information as item children
104  QList<QStandardItem*> list;
105  QVariant data;
106 
107  //Material options
108  MetaTreeItem* pItemMaterialOptions = new MetaTreeItem(MetaTreeItemTypes::UnknownItem, "Material");
109  pItemMaterialOptions->setEditable(false);
110  list.clear();
111  list << pItemMaterialOptions;
112  list << new QStandardItem("The material options");
113  this->appendRow(list);
114 
115  QString surfaceType("Phong Alpha");
116  MetaTreeItem* pItemMaterialType = new MetaTreeItem(MetaTreeItemTypes::MaterialType, surfaceType);
117  connect(pItemMaterialType, &MetaTreeItem::dataChanged,
119  list.clear();
120  list << pItemMaterialType;
121  list << new QStandardItem(pItemMaterialType->toolTip());
122  pItemMaterialOptions->appendRow(list);
123  data.setValue(QString(surfaceType));
124  pItemMaterialType->setData(data, MetaTreeItemRoles::SurfaceMaterial);
125  pItemMaterialType->setData(data, Qt::DecorationRole);
126 
127  float fTessInner = 1.0;
128  MetaTreeItem *itemTessInner = new MetaTreeItem(MetaTreeItemTypes::SurfaceTessInner, QString("%1").arg(fTessInner));
129  connect(itemTessInner, &MetaTreeItem::dataChanged,
131  list.clear();
132  list << itemTessInner;
133  list << new QStandardItem(itemTessInner->toolTip());
134  pItemMaterialOptions->appendRow(list);
135  data.setValue(fTessInner);
136  itemTessInner->setData(data, MetaTreeItemRoles::SurfaceTessInner);
137 
138  float fTessOuter = 1.0;
139  MetaTreeItem *itemTessOuter = new MetaTreeItem(MetaTreeItemTypes::SurfaceTessOuter, QString("%1").arg(fTessOuter));
140  connect(itemTessOuter, &MetaTreeItem::dataChanged,
142  list.clear();
143  list << itemTessOuter;
144  list << new QStandardItem(itemTessOuter->toolTip());
145  pItemMaterialOptions->appendRow(list);
146  data.setValue(fTessOuter);
147  itemTessOuter->setData(data, MetaTreeItemRoles::SurfaceTessOuter);
148 
149  float fTriangleScale = 1.0;
150  MetaTreeItem *itemTriangleScale = new MetaTreeItem(MetaTreeItemTypes::SurfaceTriangleScale, QString("%1").arg(fTriangleScale));
151  connect(itemTriangleScale, &MetaTreeItem::dataChanged,
153  list.clear();
154  list << itemTriangleScale;
155  list << new QStandardItem(itemTriangleScale->toolTip());
156  pItemMaterialOptions->appendRow(list);
157  data.setValue(fTriangleScale);
158  itemTriangleScale->setData(data, MetaTreeItemRoles::SurfaceTriangleScale);
159 
160  //Init materials
161  this->onSurfaceMaterialChanged("Phong Alpha");
162 
163  //Init custom mesh
164  this->addComponent(m_pCustomMesh);
165 }
166 
167 //=============================================================================================================
168 
169 void AbstractMeshTreeItem::setData(const QVariant& value, int role)
170 {
171  Abstract3DTreeItem::setData(value, role);
172 
173  switch(role) {
174  case Data3DTreeModelItemRoles::SurfaceCurrentColorVert:
175  if(m_pCustomMesh) {
176  m_pCustomMesh->setColor(value.value<MatrixX4f>());
177  }
178  break;
179 
180  default: // do nothing;
181  break;
182  }
183 }
184 
185 //=============================================================================================================
186 
187 void AbstractMeshTreeItem::setMaterial(Qt3DRender::QMaterial* pMaterial)
188 {
189  if(!pMaterial) {
190  return;
191  }
192 
193  //Remove material here. This should also call delete since we did not specify a parent for the material
194  //before adding it as a component. Hence, QEntity should take care of delete.
195  if(m_pMaterial) {
196  this->removeComponent(m_pMaterial);
197  }
198 
199  //Set new material
200  m_pMaterial = pMaterial;
201  this->addComponent(m_pMaterial);
202 }
203 
204 //=============================================================================================================
205 
206 void AbstractMeshTreeItem::setMeshData(const MatrixX3f& tMatVert,
207  const MatrixX3f& tMatNorm,
208  const MatrixXi& tMatTris,
209  const MatrixX4f& tMatColors,
210  Qt3DRender::QGeometryRenderer::PrimitiveType primitiveType)
211 {
212  if(m_pCustomMesh) {
213  m_pCustomMesh->setMeshData(tMatVert,
214  tMatNorm,
215  tMatTris,
216  tMatColors,
217  primitiveType);
218 
219  int iNumVerts = tMatVert.rows();
220 
221  this->setData(QVariant(iNumVerts), Data3DTreeModelItemRoles::NumberVertices);
222  }
223 }
224 
225 //=============================================================================================================
226 
227 void AbstractMeshTreeItem::onSurfaceTessInnerChanged(const QVariant& fTessInner)
228 {
229  this->setMaterialParameter(fTessInner.toFloat(), "innerTess");
230 }
231 
232 //=============================================================================================================
233 
234 void AbstractMeshTreeItem::onSurfaceTessOuterChanged(const QVariant& fTessOuter)
235 {
236  this->setMaterialParameter(fTessOuter.toFloat(), "outerTess");
237 }
238 
239 //=============================================================================================================
240 
241 void AbstractMeshTreeItem::onSurfaceTriangleScaleChanged(const QVariant& fTriangleScale)
242 {
243  this->setMaterialParameter(fTriangleScale.toFloat(), "triangleScale");
244 }
245 
246 //=============================================================================================================
247 
248 void AbstractMeshTreeItem::onColorChanged(const QVariant& color)
249 {
250  QVariant data;
251  MatrixX4f matNewVertColor = createVertColor(this->data(Data3DTreeModelItemRoles::NumberVertices).toInt(),
252  color.value<QColor>());
253 
254  data.setValue(matNewVertColor);
255  this->setData(data, Data3DTreeModelItemRoles::SurfaceCurrentColorVert);
256 }
257 
258 //=============================================================================================================
259 
260 void AbstractMeshTreeItem::onSurfaceMaterialChanged(const QVariant& sMaterial)
261 {
262  QPointer<Qt3DRender::QMaterial> pMaterial;
263 
264  if(sMaterial.toString() == "Phong Alpha") {
265  pMaterial = new PerVertexPhongAlphaMaterial();
266  if(m_pCustomMesh) {
267  m_pCustomMesh->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
268  }
269  } else if(sMaterial.toString() == "Phong Alpha Tesselation") {
270  pMaterial = new PerVertexTessPhongAlphaMaterial();
271  if(m_pCustomMesh) {
272  m_pCustomMesh->setPrimitiveType(Qt3DRender::QGeometryRenderer::Patches);
273  }
274  } else if(sMaterial.toString() == "Show normals") {
275  pMaterial = new ShowNormalsMaterial();
276  if(m_pCustomMesh) {
277  m_pCustomMesh->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
278  }
279  } else if(sMaterial.toString() == "GPU Interpolation") {
280  pMaterial = new GpuInterpolationMaterial();
281  if(m_pCustomMesh) {
282  m_pCustomMesh->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
283  }
284  }
285 
286  this->setMaterial(pMaterial);
287 }
DISP3DLIB::AbstractMeshTreeItem::setData
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
Definition: abstractmeshtreeitem.cpp:169
DISP3DLIB::AbstractMeshTreeItem::AbstractMeshTreeItem
AbstractMeshTreeItem(Qt3DCore::QEntity *p3DEntityParent=Q_NULLPTR, int iType=Data3DTreeModelItemTypes::AbstractMeshItem, const QString &text="Abstract Mesh Item")
Definition: abstractmeshtreeitem.cpp:69
DISP3DLIB::CustomMesh
Custom mesh functionality.
Definition: custommesh.h:93
DISP3DLIB::AbstractMeshTreeItem::setVertColor
virtual void setVertColor(const Eigen::MatrixX4f &vertColor)
Definition: abstractmeshtreeitem.cpp:86
DISP3DLIB::AbstractMeshTreeItem::onSurfaceMaterialChanged
virtual void onSurfaceMaterialChanged(const QVariant &sMaterial)
Definition: abstractmeshtreeitem.cpp:260
DISP3DLIB::AbstractMeshTreeItem::m_pCustomMesh
QPointer< CustomMesh > m_pCustomMesh
Definition: abstractmeshtreeitem.h:200
DISP3DLIB::AbstractMeshTreeItem::onSurfaceTessInnerChanged
virtual void onSurfaceTessInnerChanged(const QVariant &fTessInner)
Definition: abstractmeshtreeitem.cpp:227
DISP3DLIB::PerVertexPhongAlphaMaterial
PerVertexPhongAlphaMaterial is provides a Qt3D material with own shader support.
Definition: pervertexphongalphamaterial.h:80
DISP3DLIB::Abstract3DTreeItem
Provides the basic tree item.
Definition: abstract3Dtreeitem.h:80
DISP3DLIB::AbstractMeshTreeItem::setMeshData
void setMeshData(const Eigen::MatrixX3f &tMatVert, const Eigen::MatrixX3f &tMatNorm, const Eigen::MatrixXi &tMatTris, const Eigen::MatrixX4f &tMatColors, Qt3DRender::QGeometryRenderer::PrimitiveType primitiveType=Qt3DRender::QGeometryRenderer::Triangles)
Definition: abstractmeshtreeitem.cpp:206
DISP3DLIB::MetaTreeItem::dataChanged
void dataChanged(const QVariant &data)
DISP3DLIB::ShowNormalsMaterial
ShowNormalsMaterial is provides a Qt3D material with own shader support.
Definition: shownormalsmaterial.h:88
DISP3DLIB::AbstractMeshTreeItem::initItem
virtual void initItem()
Definition: abstractmeshtreeitem.cpp:96
DISP3DLIB::AbstractMeshTreeItem::onSurfaceTriangleScaleChanged
virtual void onSurfaceTriangleScaleChanged(const QVariant &fTriangleScale)
Definition: abstractmeshtreeitem.cpp:241
DISP3DLIB::AbstractMeshTreeItem::getCustomMesh
virtual QPointer< CustomMesh > getCustomMesh()
Definition: abstractmeshtreeitem.cpp:79
DISP3DLIB::MetaTreeItem
Provides a generic brain tree item.
Definition: metatreeitem.h:74
DISP3DLIB::PerVertexTessPhongAlphaMaterial
PerVertexTessPhongAlphaMaterial is provides a Qt3D material with own shader support.
Definition: pervertextessphongalphamaterial.h:85
DISP3DLIB::AbstractMeshTreeItem::m_pMaterial
QPointer< Qt3DRender::QMaterial > m_pMaterial
Definition: abstractmeshtreeitem.h:199
DISP3DLIB::AbstractMeshTreeItem::onColorChanged
virtual void onColorChanged(const QVariant &color)
Definition: abstractmeshtreeitem.cpp:248
abstractmeshtreeitem.h
AbstractMeshTreeItem class declaration.
DISP3DLIB::Abstract3DTreeItem::createVertColor
static Eigen::MatrixX4f createVertColor(int numVert, const QColor &color=QColor(0, 49, 69))
Definition: abstract3Dtreeitem.cpp:246
DISP3DLIB::GpuInterpolationMaterial
Compute shader interpolation material.
Definition: gpuinterpolationmaterial.h:90
DISP3DLIB::Renderable3DEntity::setMaterialParameter
virtual void setMaterialParameter(const QVariant &data, const QString &sParameterName)
Definition: renderable3Dentity.cpp:441
DISP3DLIB::AbstractMeshTreeItem::onSurfaceTessOuterChanged
virtual void onSurfaceTessOuterChanged(const QVariant &fTessOuter)
Definition: abstractmeshtreeitem.cpp:234
DISP3DLIB::Abstract3DTreeItem::setData
void setData(const QVariant &value, int role=Qt::UserRole+1)
Definition: abstract3Dtreeitem.cpp:169