MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
abstractmeshtreeitem.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
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
62using namespace DISP3DLIB;
63using namespace Eigen;
64
65//=============================================================================================================
66// DEFINE MEMBER METHODS
67//=============================================================================================================
68
69AbstractMeshTreeItem::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
86void 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
169void 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
187void 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
206void 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
228{
229 this->setMaterialParameter(fTessInner.toFloat(), "innerTess");
230}
231
232//=============================================================================================================
233
235{
236 this->setMaterialParameter(fTessOuter.toFloat(), "outerTess");
237}
238
239//=============================================================================================================
240
241void AbstractMeshTreeItem::onSurfaceTriangleScaleChanged(const QVariant& fTriangleScale)
242{
243 this->setMaterialParameter(fTriangleScale.toFloat(), "triangleScale");
244}
245
246//=============================================================================================================
247
248void 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
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}
AbstractMeshTreeItem class declaration.
Custom mesh functionality.
Definition custommesh.h:94
virtual void setMaterialParameter(const QVariant &data, const QString &sParameterName)
Provides the basic tree item.
static Eigen::MatrixX4f createVertColor(int numVert, const QColor &color=QColor(0, 49, 69))
void setData(const QVariant &value, int role=Qt::UserRole+1)
virtual void onSurfaceMaterialChanged(const QVariant &sMaterial)
virtual void onColorChanged(const QVariant &color)
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)
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
AbstractMeshTreeItem(Qt3DCore::QEntity *p3DEntityParent=Q_NULLPTR, int iType=Data3DTreeModelItemTypes::AbstractMeshItem, const QString &text="Abstract Mesh Item")
virtual void setVertColor(const Eigen::MatrixX4f &vertColor)
virtual void onSurfaceTriangleScaleChanged(const QVariant &fTriangleScale)
virtual void onSurfaceTessInnerChanged(const QVariant &fTessInner)
QPointer< Qt3DRender::QMaterial > m_pMaterial
virtual QPointer< CustomMesh > getCustomMesh()
virtual void onSurfaceTessOuterChanged(const QVariant &fTessOuter)
Provides a generic brain tree item.
void dataChanged(const QVariant &data)
void setData(const QVariant &value, int role=Qt::UserRole+1)
Compute shader interpolation material.
PerVertexPhongAlphaMaterial is provides a Qt3D material with own shader support.
PerVertexTessPhongAlphaMaterial is provides a Qt3D material with own shader support.
ShowNormalsMaterial is provides a Qt3D material with own shader support.