36 #ifndef _USE_MATH_DEFINES
37 # define _USE_MATH_DEFINES // For MSVC
54 #include "qtorusmesh.h"
56 #include "qattribute.h"
57 #include "qmeshdata.h"
76 : QAbstractMesh(parent)
85 : QAbstractMesh(parent)
87 , m_qmVertexColor(qmVertexColor)
95 void BrainSurfaceMesh::copy(
const QNode *ref)
97 QAbstractMesh::copy(ref);
99 m_surface = mesh->m_surface;
100 m_qmVertexColor = mesh->m_qmVertexColor;
106 QAbstractMeshFunctorPtr BrainSurfaceMesh::meshFunctor()
const
114 void BrainSurfaceMesh::updateActivation(
const QMap<int, QColor> &qmVertexColor)
121 if(qmVertexColor.size() != m_qmVertexColor.size()) {
122 std::cout<<
"newly provided colors from source estimate do not match loaded number of vertices"<<std::endl;
123 std::cout<<
"vertexColor.size()"<<qmVertexColor.size()<<std::endl;
124 std::cout<<
"m_qlVertexColor.size()"<<m_qmVertexColor.size()<<std::endl;
129 m_qmVertexColor = qmVertexColor;
138 int BrainSurfaceMesh::getNumberOfVertices()
140 return m_surface.
rr().rows();
146 BrainSurfaceMeshFunctor::BrainSurfaceMeshFunctor(
const Surface &surf,
const QMap<int, QColor> &qmVertexColor)
147 : QAbstractMeshFunctor()
149 , m_qmVertexColor(qmVertexColor)
156 QMeshDataPtr BrainSurfaceMeshFunctor::operator ()()
158 m_qMeshDataPtr = createSurfaceMesh(m_surface, m_qmVertexColor);
159 return m_qMeshDataPtr;
165 bool BrainSurfaceMeshFunctor::operator ==(
const QAbstractMeshFunctor &other)
const
177 QMeshDataPtr BrainSurfaceMeshFunctor::createSurfaceMesh(
const Surface &surface,
const QMap<int, QColor> &qmVertexColor)
179 QMeshDataPtr mesh(
new QMeshData(QMeshData::Triangles));
183 std::cout<<
"BrainSurfaceMesh - createSurfaceMesh() - Given surface is empty"<<std::endl;
188 Matrix3Xf vertices = surface.
rr().transpose();
189 Matrix3Xf normals = surface.
nn().transpose();
190 Matrix3Xi faces = surface.
tris().transpose();
192 int nVerts = vertices.cols();
194 quint32 elementSizeVertNorm = 3 + 3;
195 quint32 elementSizeColor = 3;
196 quint32 strideVertNorm = elementSizeVertNorm *
sizeof(float);
197 quint32 strideColor = elementSizeColor *
sizeof(float);
199 QByteArray bufferBytesVertNorm;
200 bufferBytesVertNorm.resize(strideVertNorm * nVerts);
202 float* fptrVertNorm =
reinterpret_cast<float*
>(bufferBytesVertNorm.data());
204 QByteArray bufferBytesColor;
205 bufferBytesColor.resize(strideColor * nVerts);
207 float* fptrColor =
reinterpret_cast<float*
>(bufferBytesColor.data());
209 for(
int i = 0; i<nVerts; i++) {
211 *fptrVertNorm++ = vertices(0,i);
212 *fptrVertNorm++ = vertices(1,i);
213 *fptrVertNorm++ = vertices(2,i);
216 *fptrVertNorm++ = normals(0,i);
217 *fptrVertNorm++ = normals(1,i);
218 *fptrVertNorm++ = normals(2,i);
221 *fptrColor++ = (float)qmVertexColor[i].redF();
222 *fptrColor++ = (float)qmVertexColor[i].greenF();
223 *fptrColor++ = (float)qmVertexColor[i].blueF();
229 BufferPtr bufVertNorm(
new Buffer(QOpenGLBuffer::VertexBuffer));
230 bufVertNorm->setUsage(QOpenGLBuffer::StaticDraw);
231 bufVertNorm->setData(bufferBytesVertNorm);
233 BufferPtr bufColor(
new Buffer(QOpenGLBuffer::VertexBuffer));
234 bufColor->setUsage(QOpenGLBuffer::StaticDraw);
235 bufColor->setData(bufferBytesColor);
238 mesh->addAttribute(QMeshData::defaultPositionAttributeName(), QAbstractAttributePtr(
new Attribute(bufVertNorm, GL_FLOAT_VEC3, nVerts, 0, strideVertNorm)));
239 quint32 offset =
sizeof(float) * 3;
242 mesh->addAttribute(QMeshData::defaultNormalAttributeName(), QAbstractAttributePtr(
new Attribute(bufVertNorm, GL_FLOAT_VEC3, nVerts, offset, strideVertNorm)));
245 mesh->addAttribute(QMeshData::defaultColorAttributeName(), QAbstractAttributePtr(
new Attribute(bufColor, GL_FLOAT_VEC3, nVerts, 0, strideColor)));
248 QByteArray indexBytes;
249 int number_faces = faces.cols();
250 int indices = number_faces * 3;
252 indexBytes.resize(indices *
sizeof(quint32));
253 quint32* indexPtr =
reinterpret_cast<quint32*
>(indexBytes.data());
255 for(
int i = 0; i < number_faces; i++)
257 *indexPtr++ = faces(0,i);
258 *indexPtr++ = faces(1,i);
259 *indexPtr++ = faces(2,i);
262 BufferPtr indexBuffer(
new Buffer(QOpenGLBuffer::IndexBuffer));
263 indexBuffer->setUsage(QOpenGLBuffer::StaticDraw);
264 indexBuffer->setData(indexBytes);
265 mesh->setIndexAttribute(AttributePtr(
new Attribute(indexBuffer, GL_UNSIGNED_INT, indices, 0, 0)));
267 mesh->computeBoundsFromAttribute(QMeshData::defaultPositionAttributeName());
Holds the data of one hemisphere in form of a mesh.
const MatrixX3f & nn() const
const MatrixX3i & tris() const
Declaration of BrainSurfaceMesh which holds the data of one hemisphere in form of a mesh...
BrainSurfaceMesh(QNode *parent=0)
const MatrixX3f & rr() const