StereoView::StereoView(QWidget *parent) : QGLView(parent) { scene = new QGLSceneNode(this); QGLSceneNode *teapot; QGLSceneNode *cube; { QGLBuilder builder; builder << QGLTeapot(); teapot = builder.finalizedSceneNode(); } { QGLBuilder builder; builder.newSection(QGL::Faceted); builder << QGLCube(1.0f); cube = builder.finalizedSceneNode(); } cube->setPosition(QVector3D(-1.0f, 0.0f, 2.0f)); scene->addNode(teapot); scene->addNode(cube); QGLMaterial *china = new QGLMaterial(this); china->setAmbientColor(QColor(192, 150, 128)); china->setSpecularColor(QColor(60, 60, 60)); china->setShininess(128); scene->setMaterial(china); scene->setEffect(QGL::LitMaterial); camera()->setEye(QVector3D(0.0f, 0.0f, 15.0f)); camera()->setEyeSeparation(0.2f); }
void ViewportWidget::buildPane() { QGLBuilder builder; if (_bgr) { delete _bgr; _bgr = NULL; } builder.newSection(); QGraphicsTranslation3D *trans = new QGraphicsTranslation3D(); QGraphicsRotation3D *rot = new QGraphicsRotation3D(); trans->setTranslate(QVector3D(0.0f, 0.0f, -1.0f)); rot->setAxis(QVector3D(1, 0, 0)); rot->setAngle(180); qreal size = 7.3f; builder.addPane(QSizeF(size, size * (qreal)SCREEN_HEIGHT / (qreal)SCREEN_WIDTH)); _bgr = builder.finalizedSceneNode(); _bgr->addTransform(trans) ; _bgr->addTransform(rot); _bgrImage = QImage(SCREEN_WIDTH, SCREEN_HEIGHT, QImage::Format_RGB888); _texture = new QGLTexture2D(); _texture->setImage(_bgrImage); }
/*! Construct a new QuadPlane with \a size, subdivided \a level times. By default the plane is 100.0f x 100.0f, and is subdivided 3 times - that is into an 8 x 8 grid. It is centered on the origin, and lies in the z = 0 plane. */ QuadPlane::QuadPlane(QObject *parent, QSizeF size, int level) : QGLSceneNode(parent) { setObjectName(QLatin1String("QuadPlane")); if (level > 8) level = 8; if (level < 1) level = 1; int divisions = 1; for ( ; level--; divisions *= 2) {} // integer 2**n QSizeF div = size / float(divisions); QSizeF half = size / 2.0f; QGLBuilder builder; QGeometryData zip; QGeometryData zip2; for (int yy = 0; yy <= divisions; ++yy) { float y = half.height() - float(yy) * div.height(); float texY = float(yy) / divisions; for (int xx = 0; xx <= divisions; ++xx) { float x = half.width() - float(xx) * div.width(); float texX = float(xx) / divisions; zip.appendVertex(QVector3D(x, y, 0)); zip.appendTexCoord(QVector2D(1.0f - texX, 1.0f - texY)); } if (yy > 0) builder.addQuadsInterleaved(zip, zip2); zip2 = zip; zip2.detach(); zip.clear(); } QGLSceneNode *n = builder.finalizedSceneNode(); addNode(n); }
sphere3d::sphere3d(float x_, float y_, float z_, float rad, int r, int g, int b, int a) : x(x_), y(y_), z(z_), radius(rad), node(NULL), col(r, g, b, a) { QGLBuilder builder; builder << QGLSphere(radius * 2); node = builder.finalizedSceneNode(); //EDEBUG("win3d added: " << describe()); }
coordinates::coordinates( float size, float thickness ): m_node( new QGLSceneNode() ) { QGLBuilder builder; builder << QGLCylinder( thickness, thickness, size, 12 ); QGLSceneNode* cylinder = builder.finalizedSceneNode(); cylinder->setPosition( QVector3D( 0, 0, 0.5 * size ) ); cylinder->setEffect( QGL::LitMaterial ); QGLBuilder arrowBuilder; arrowBuilder << QGLCylinder( 0.01, 2 * thickness, size / 3, 12 ); QGLSceneNode* arrow = arrowBuilder.finalizedSceneNode(); arrow->setPosition( QVector3D( 0, 0, size ) ); arrow->setEffect( QGL::LitMaterial ); QGLSceneNode* x = new QGLSceneNode( m_node ); x->addNode(cylinder); QMatrix4x4 matrix; QQuaternion q = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f); matrix.rotate( q ); x->setLocalTransform( matrix ); QGLSceneNode* xArrow = new QGLSceneNode( m_node ); xArrow->addNode( arrow ); xArrow->setLocalTransform( matrix ); QGLMaterial* xMaterial = new QGLMaterial; xMaterial->setDiffuseColor( QColor( 255, 0, 0, 128 ) ); x->setMaterial( xMaterial ); xArrow->setMaterial( xMaterial ); QGLSceneNode* y = new QGLSceneNode( m_node ); y->addNode(cylinder); q = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -90.0f); matrix.rotate( q ); y->setLocalTransform( matrix ); QGLSceneNode* yArrow = new QGLSceneNode( m_node ); yArrow->addNode( arrow ); yArrow->setLocalTransform( matrix ); QGLMaterial* yMaterial = new QGLMaterial; yMaterial->setDiffuseColor(Qt::green); y->setMaterial( yMaterial ); QGLMaterial* yArrowMaterial = new QGLMaterial; yArrowMaterial->setDiffuseColor( QColor( 0, 255, 0, 128 ) ); yArrow->setMaterial( yArrowMaterial ); QGLSceneNode* z = new QGLSceneNode( m_node ); z->addNode(cylinder); QGLSceneNode* zArrow = new QGLSceneNode( m_node ); zArrow->addNode( arrow ); QGLMaterial* zMaterial = new QGLMaterial; zMaterial->setDiffuseColor(Qt::blue); z->setMaterial( zMaterial ); QGLMaterial* zArrowMaterial = new QGLMaterial; zArrowMaterial->setDiffuseColor( QColor( 0, 0, 255, 128 ) ); zArrow->setMaterial( zArrowMaterial ); }
line3d::line3d(float x_, float y_, float z_, float x1_, float y1_, float z1_, int r, int g, int b, int a) : x(x_), y(y_), z(z_), x1(x1_), y1(y1_), z1(z1_), node(NULL), col(r, g, b, a) { QGLBuilder builder; builder.addPane(1); node = builder.finalizedSceneNode(); node->setDrawingMode(QGL::Lines); //EDEBUG("win3d added: " << describe()); eblerror("not implemented"); }
/*! Constuctor, creates 2D pane by using Qt3D QGLBuilder to which there is a light material set. */ LightParticle::LightParticle(QGLMaterialCollection *materialCollection, int materialIndex) { QGLBuilder builder; builder.newSection(QGL::Faceted); builder.addPane(QSizeF(4.0f, 4.0f)); addNode(builder.finalizedSceneNode()); setEffect(QGL::FlatReplaceTexture2D); setPalette(materialCollection); setMaterialIndex(materialIndex); }
cylinder3d::cylinder3d(float x_, float y_, float z_, float length, float top_radius_, float base_radius_, float a1_, float a2_, int r, int g, int b, int a, bool tops_) : x(x_), y(y_), z(z_), a1(a1_), a2(a2_), top_radius(top_radius_), base_radius(base_radius_), tops(tops_), node(NULL), col(r, g, b, a) { QGLBuilder builder; builder << QGLCylinder(top_radius * 2, base_radius * 2, length, 10, 3, tops, tops); node = builder.finalizedSceneNode(); //EDEBUG("win3d added: " << describe()); }
CylinderView::CylinderView(QWindow *parent) : QGLView(parent) { QGLBuilder builder; // Evil hack: it is not possible to just call glClearColor on any device // but it is possible to have a huge, dark SkyBox. Without this hack the // cylinder floats over a transparent background, displaying the contents // of the last app builder << QGL::Smooth << QGLCube(1000.0f); // Add the cylinder builder << QGL::Smooth << QGLCylinder(2.0, 1.5, 2.0, 36, 3, true, true); QGLMaterial *matLid = new QGLMaterial; matLid->setAmbientColor(Qt::gray); matLid->setDiffuseColor(Qt::gray); QUrl urlLid; urlLid.setPath(QLatin1String(":/latte.png")); urlLid.setScheme(QLatin1String("file")); matLid->setTextureUrl(urlLid); QGLMaterial *matSides = new QGLMaterial; matSides->setColor(QColor(170, 202, 0)); QUrl urlSides; urlSides.setPath(QLatin1String(":/cupTexture.png")); urlSides.setScheme(QLatin1String("file")); matSides->setTextureUrl(urlSides); QGLSceneNode *root = builder.sceneNode(); QGLSceneNode *lid = root->findChild<QGLSceneNode *>("Cylinder Top"); int lidMat = root->palette()->addMaterial(matLid); lid->setMaterialIndex(lidMat); lid->setEffect(QGL::LitDecalTexture2D); QGLSceneNode *sides = root->findChild<QGLSceneNode *>("Cylinder Sides"); int sideMat = root->palette()->addMaterial(matSides); sides->setMaterialIndex(sideMat); sides->setEffect(QGL::LitDecalTexture2D); cylinder = builder.finalizedSceneNode(); QGLMaterial *mat = new QGLMaterial; mat->setAmbientColor(Qt::gray); mat->setDiffuseColor(Qt::gray); cylinder->setMaterial(mat); cylinder->setEffect(QGL::LitMaterial); }
void ModelDisplay::buildPane() { _displayValue.fill(0); QGLBuilder builder; QGraphicsTranslation3D *trans = new QGraphicsTranslation3D(); trans->setTranslate(QVector3D(-0.125f, 1.5f, -0.12f)); builder.newSection(); builder.addPane(QSizeF(0.9f, 0.75f)); _mainNode = builder.finalizedSceneNode(); _mainNode->addTransform(trans); _texture = new QGLTexture2D(); _texture->setImage(_displayValue); }
/*! Constructor, creates Qt3D Cube object as a particle, with lighting normals separated for each face for a faceted appearance. */ ExplosionParticle::ExplosionParticle(QGLShaderProgramEffect *effect, QGLMaterialCollection *materialCollection) : IParticle() { m_DiffuseLoc = -1; QGLBuilder builder; builder.newSection(QGL::Faceted); builder << QGLCube(0.6); addNode(builder.finalizedSceneNode()); if (effect) setUserEffect(effect); setPalette(materialCollection); }
CubeItem::CubeItem(QGraphicsItem *parent) : QGLGraphicsViewportItem(parent) , mScene(0) , fbo(0) , navigating(false) , pressedFace(-1) , pressedButton(Qt::NoButton) { startNavCamera = new QGLCamera(); setFlag(ItemIsFocusable, true); QGLBuilder builder; builder.newSection(QGL::Faceted); builder << QGLCube(CubeSize); cube = builder.finalizedSceneNode(); }
QGLSceneNode * Boid::boidObject() { static QGLSceneNode *v = 0; if (!v) { QGLBuilder build; build << QGLSphere(2.0f); v = build.finalizedSceneNode(); v->setObjectName("Boid"); QGraphicsRotation3D * rot = new QGraphicsRotation3D(v); rot->setAngle(90.0f); rot->setAxis(QVector3D(1, 0, 0)); v->addTransform(rot); v->setY(-v->boundingBox().minimum().y()); } return v; }
void CubeView::initializeGL(QGLPainter *painter) { QGLBuilder builder; builder.newSection(QGL::Faceted); builder << QGLCube(1.5f); cube = builder.currentNode(); builder << QGLTeapot(); teapot = builder.currentNode(); scene = builder.finalizedSceneNode(); scene->setParent(this); fbo = new QGLFramebufferObject(512, 512, QGLFramebufferObject::Depth); QImage textureImage(":/qtlogo.png"); qtlogo.setImage(textureImage); painter->setBlendingEnabled(true); }
void CubeMesh::createGeometry() { QGLSceneNode* geometry; QGLBuilder builder; builder.newSection(QGL::NoSmoothing); QGeometryData quad; // QVector3DArray vertices = { // 0.0, 0.0, 0.0, // 0.0, 0.0, 1.0 // }; // quad.appendVertexArray(); geometry = builder.finalizedSceneNode(); geometry->setParent(this); if (!d->sceneSet) { setScene(new CubeScene(d->topNode)); d->sceneSet = true; } }
QGLSceneNode *Tank::tankObject() { #ifndef QT_NO_DEBUG // NOT THREADSAFE, NOT RE-ENTRANT Q_ASSERT(QThread::currentThread() == qApp->thread()); #endif static QGLSceneNode *theTank = 0; if (!theTank) { QGLBuilder build; build << QGLCylinder(1.0f, 1.0f, 1.0f, 32); theTank = build.finalizedSceneNode(); theTank->setObjectName("Tank Component"); QGraphicsRotation3D *rot = new QGraphicsRotation3D(theTank); rot->setAxis(QVector3D(1, 0, 0)); rot->setAngle(-90.0f); theTank->addTransform(rot); theTank->setY(-theTank->boundingBox().minimum().y()); } return theTank; }
/*! Constructor, the material collection and indexes of 10 materials are given to access the materials for each digit. */ ScoreDigit::ScoreDigit(QGLMaterialCollection *materialCollection, int materialIndex, const QVector3D &pos, QGLSceneNode *parent) : QGLSceneNode(parent) { QGLBuilder builder; builder.addPane(0.7f); QGLSceneNode *rootNode = builder.finalizedSceneNode(); addNode(rootNode->children()[0]->clone(this)); delete rootNode; rootNode = 0; setPosition(pos); setPalette(materialCollection); setMaterialIndex(materialIndex); setEffect(QGL::FlatReplaceTexture2D); // Hide the digit at start setValue(-1); }
/* Creates an individual randomly positioned ball */ QGLSceneNode *ModelBall::createNode(QGLMaterial *material) { const float defaultSize = 1.0; const float positionX = -1.5; const float positionY = 40.0; const float randomPositionScale = 1000.0; QGLBuilder builder; QGLSceneNode *node; builder.newNode(); builder << QGLSphere(defaultSize); node = builder.finalizedSceneNode(); node->setMaterial(material); node->setEffect(QGL::LitMaterial); QGraphicsTranslation3D *trans = new QGraphicsTranslation3D(); node->addTransform(trans); QGraphicsTranslation3D *transStart = new QGraphicsTranslation3D(); QVector3D *randomStart = new QVector3D(positionX + randomPosition()/randomPositionScale, positionY + randomPosition()/randomPositionScale, randomPosition()/randomPositionScale); transStart->setTranslate(*randomStart); node->addTransform(transStart); return node; }
void BrainView::genSurfacePerVertex() { if(m_SurfaceSet.size() == 0) return; if(m_pSceneNode) { delete m_pSceneNode; m_pSceneNode = NULL; } // in the constructor construct a builder on the stack QGLBuilder builder; float fac = 100.0f; // too small vertices distances cause clipping errors --> 100 is a good value for freesurfer brain measures builder << QGL::Smooth;//QGL::Faceted; m_pSceneNodeBrain = builder.currentNode(); builder.pushNode(); // // get bounding box // calcBoundingBox(); // // Build each surface in its separate node // QMap<qint32, Surface>::const_iterator it = m_SurfaceSet.data().constBegin(); for (it = m_SurfaceSet.data().begin(); it != m_SurfaceSet.data().end(); ++it) { builder.pushNode(); { Matrix3Xf rr = it.value().rr().transpose(); //Centralize for(qint32 i = 0; i < 3; ++i) rr.row(i) = rr.row(i).array() - (m_vecBoundingBoxCenter[i] + it.value().offset()[i]); QGeometryData t_GeometryDataTri; MatrixXf t_TriCoords = MatrixXf::Zero(3,3*(it.value().tris().rows())); QArray<QColor4ub> cdata; for(qint32 i = 0; i < it.value().tris().rows(); ++i) { for(qint32 j = 0; j < 3; ++j) { t_TriCoords.col(i*3+j) = rr.col( it.value().tris()(i,j) ); if(it.value().curv()[it.value().tris()(i,j)] >= 0) cdata.append(QColor( 50, 50, 50, 230));//Sulci else cdata.append(QColor( 200, 200, 200, 230));//Gyri } } t_TriCoords *= fac; t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() )); t_GeometryDataTri.appendColorArray(cdata); // // Add triangles to current node // builder.addTriangles(t_GeometryDataTri); } // Go one level up builder.popNode(); } m_bRenderPerVertex = true; // Optimze current scene for display and calculate lightning normals m_pSceneNode = builder.finalizedSceneNode(); m_pSceneNode->setParent(this); }
ImageViewer::ImageViewer(int w, int h) { // the body QGLBuilder builder; builder.newSection(QGL::Faceted); builder.addPane(QSizeF(w, h)); body = builder.finalizedSceneNode(); body->setMaterial(new QGLMaterial()); body->setEffect(QGL::FlatReplaceTexture2D); // prev button QVector3DArray vertices; vertices.append(-w * 0.4, 0, 0.01); vertices.append(-w * 0.3, -h * 0.1, 0.01); vertices.append(-w * 0.3, h * 0.1, 0.01); QGeometryData triangle; triangle.appendVertexArray(vertices); QGLBuilder prevBuilder; prevBuilder.newSection(QGL::Faceted); prevBuilder.addTriangles(triangle); prevBtn = prevBuilder.finalizedSceneNode(); prevBtn->setEffect(QGL::FlatColor); // next button vertices.clear(); vertices.append(w * 0.4, 0, 0); vertices.append(w * 0.3, h * 0.1, 0.01); vertices.append(w * 0.3, -h * 0.1, 0.01); triangle.clear(); triangle.appendVertexArray(vertices); QGLBuilder nextBuilder; nextBuilder.newSection(QGL::Faceted); nextBuilder.addTriangles(triangle); nextBtn = nextBuilder.finalizedSceneNode(); nextBtn->setEffect(QGL::FlatColor); }
PlyLoader::PlyLoader( const std::string& file, boost::optional< QColor4ub > color, double scale ) : color_( color ), scale_( scale ) { std::ifstream stream( file.c_str() ); std::string line; std::getline( stream, line ); if( line != "ply" ) { COMMA_THROW( comma::exception, "expected ply file; got \"" << line << "\" in " << file ); } unsigned int numVertex = 0; unsigned int numFace = 0; bool has_normals = false; std::vector< std::string > fields; while( stream.good() && !stream.eof() && line != "end_header" ) { std::getline( stream, line ); if( line.empty() ) { continue; } std::vector< std::string > v = comma::split( comma::strip( line ), ' ' ); if( v[0] == "element" ) // quick and dirty { if( v[1] == "vertex" ) { numVertex = boost::lexical_cast< unsigned int >( v[2] ); } else if( v[1] == "face" ) { numFace = boost::lexical_cast< unsigned int >( v[2] ); } } else if( v[0] == "format" && v[1] != "ascii" ) { COMMA_THROW( comma::exception, "only ascii supported; got: " << v[1] ); } else if( line == "property float x" ) { fields.push_back( "point/x" ); } else if( line == "property float y" ) { fields.push_back( "point/y" ); } else if( line == "property float z" ) { fields.push_back( "point/z" ); } else if( line == "property float nx" ) { fields.push_back( "normal/x" ); has_normals = true; } else if( line == "property float ny" ) { fields.push_back( "normal/y" ); } else if( line == "property float nz" ) { fields.push_back( "normal/z" ); } else if( line == "property uchar red" ) { fields.push_back( "r" ); } else if( line == "property uchar green" ) { fields.push_back( "g" ); } else if( line == "property uchar blue" ) { fields.push_back( "b" ); } else if( line == "property uchar alpha" ) { fields.push_back( "a" ); } } comma::csv::options csv; csv.fields = comma::join( fields, ',' ); csv.full_xpath = true; csv.delimiter = ' '; comma::csv::ascii< ply_vertex > ascii( csv ); QGeometryData geometry; QArray< QVector3D > vertices; QArray< QColor4ub > colors; for( unsigned int i = 0; i < numVertex; i++ ) { std::string s; if( stream.eof() ) { break; } std::getline( stream, s ); if( s.empty() ) { continue; } ply_vertex v; if( color_ ) { v.color = *color_; } // quick and dirty ascii.get( v, s ); if( numFace > 0 ) { geometry.appendVertex( QVector3D( v.point.x() * scale_, v.point.y() * scale_, v.point.z() * scale_ ) ); if( has_normals ) { geometry.appendNormal( QVector3D( v.normal.x(), v.normal.y(), v.normal.z() ) ); } geometry.appendColor( v.color ); } else { vertices.append( QVector3D( v.point.x() * scale_, v.point.y() * scale_, v.point.z() * scale_ ) ); // todo: normals? colors.append( v.color ); } } if( numFace > 0 ) { for( unsigned int i = 0; i < numFace; i++ ) // quick and dirty { std::string s; if( stream.eof() ) { break; } std::getline( stream, s ); if( s.empty() ) { continue; } std::vector< std::string > v = comma::split( comma::strip( s ), ' ' ); unsigned int vertices_per_face = boost::lexical_cast< unsigned int >( v[0] ); if( ( vertices_per_face + 1 ) != v.size() ) { COMMA_THROW( comma::exception, "invalid line \"" << s << "\"" ); } QGL::IndexArray indices; switch( vertices_per_face ) { case 3: for( unsigned int i = 0; i < 3; ++i ) { indices.append( boost::lexical_cast< unsigned int >( v[i+1] ) ); } break; case 4: // quick and dirty for now: triangulate boost::array< unsigned int, 4 > a; for( unsigned int i = 0; i < 4; ++i ) { a[i] = boost::lexical_cast< unsigned int >( v[i+1] ); } indices.append( a[0] ); indices.append( a[1] ); indices.append( a[2] ); indices.append( a[0] ); indices.append( a[2] ); indices.append( a[3] ); break; default: // never here break; } geometry.appendIndices( indices ); } QGLBuilder builder; builder.addTriangles( geometry ); //switch( vertices_per_face ) //{ // case 3: builder.addTriangles( geometry ); break; // case 4: builder.addQuads( geometry ); break; // default: COMMA_THROW( comma::exception, "only triangles and quads supported; but got " << vertices_per_face << " vertices per face" ); //} m_sceneNode = builder.finalizedSceneNode(); } else { m_vertices.addAttribute( QGL::Position, vertices ); // todo: normals? m_vertices.addAttribute( QGL::Color, colors ); m_vertices.upload(); m_sceneNode = NULL; } stream.close(); }
/*! \internal */ void CapsuleMesh::createGeometry(bool bForce) { // Create a new geometry node for this level of detail if necessary. QGLSceneNode *geometry = 0; QMap<int, QGLSceneNode *>::iterator It = d->lodGeometry.find(d->lod); if (It != d->lodGeometry.end()) geometry = *It; if (geometry && bForce) { if (d->currentCapsule) d->topNode->removeNode(d->currentCapsule); d->currentCapsule = 0; d->lodGeometry.erase(It); geometry->setParent(0); delete geometry; geometry = 0; } if (!geometry) { QGLBuilder builder; // For the cylinder int facets = 4 * (1 << d->lod); int layers = (1 << d->lod) - 1; // For the spheres int divisions = d->lod; // Sanity check - the height of the capsule must not be less than its // diameter. A minimal capsule is a sphere - where diameter == height. if (d->length < 2.0f * d->radius) { qWarning() << "Length of capsule must exceed its diameter" << " - correcting length."; d->length = 2.0f * d->radius; } float diameter = d->radius+d->radius; float cylinderHeight = d->length - diameter; float offset = cylinderHeight/2.0f; builder << QGL::Faceted; QGLSceneNode *s = 0; s = builder.newNode(); s->setObjectName(QLatin1String("Cylinder")); builder << QGLCylinder(diameter, diameter, cylinderHeight, facets, layers, false, false); s = builder.newNode(); s->setObjectName(QLatin1String("LeftEndCap")); builder << QGLDome(diameter, divisions, false); QMatrix4x4 translateMatrix; translateMatrix.setToIdentity(); translateMatrix.rotate(180.0f, 0.0f, 1.0f, 0.0f); translateMatrix.translate(0.0f, 0.0f, offset); builder.currentNode()->setLocalTransform(translateMatrix); s = builder.newNode(); s->setObjectName(QLatin1String("RightEndCap")); builder << QGLDome(diameter, divisions, false); translateMatrix.setToIdentity(); translateMatrix.translate(0.0f, 0.0f, offset); builder.currentNode()->setLocalTransform(translateMatrix); geometry = builder.finalizedSceneNode(); geometry->setParent(this); d->lodGeometry.insert(d->lod, geometry); } Q_ASSERT_X(geometry != 0, Q_FUNC_INFO, "Could not create/find geometry!"); if (d->currentCapsule != geometry) { if (d->currentCapsule) d->topNode->removeNode(d->currentCapsule); d->topNode->addNode(geometry); d->currentCapsule = geometry; } if (!d->sceneSet) { setScene(new CapsuleScene(d->topNode)); d->sceneSet = true; } }
void BrainView::genSurface() { if(m_SurfaceSet.size() == 0) return; if(m_pSceneNode) { delete m_pSceneNode; m_pSceneNode = NULL; } // in the constructor construct a builder on the stack QGLBuilder builder; float fac = 100.0f; // too small vertices distances cause clipping errors --> 100 is a good value for freesurfer brain measures builder << QGL::Smooth;//QGL::Faceted; m_pSceneNodeBrain = builder.currentNode(); builder.pushNode(); // // Collor palette // qint32 index; QSharedPointer<QGLMaterialCollection> palette = builder.sceneNode()->palette(); // register color palette within the root node // // get bounding box // calcBoundingBox(); // // Build each surface in its separate node // QMap<qint32, Surface>::const_iterator it = m_SurfaceSet.data().constBegin(); for (it = m_SurfaceSet.data().begin(); it != m_SurfaceSet.data().end(); ++it) { builder.pushNode(); { Matrix3Xf rr = it.value().rr().transpose(); //Centralize for(qint32 i = 0; i < 3; ++i) rr.row(i) = rr.row(i).array() - m_vecBoundingBoxCenter[i]; QGeometryData t_GeometryDataTri; MatrixXf t_TriCoords = MatrixXf::Zero(3,3*(it.value().tris().rows())); for(qint32 i = 0; i < it.value().tris().rows(); ++i) for(qint32 j = 0; j < 3; ++j) t_TriCoords.col(i*3+j) = rr.col( it.value().tris()(i,j) ); t_TriCoords *= fac; t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() )); // // Add triangles to current node // builder.addTriangles(t_GeometryDataTri); // // Colorize Surface // QGLMaterial *t_pMaterialROI = new QGLMaterial(); t_pMaterialROI->setColor(QColor(100,100,100,230)); index = palette->addMaterial(t_pMaterialROI); builder.currentNode()->setMaterialIndex(index); } // Go one level up builder.popNode(); } m_bRenderPerVertex = false; // Optimze current scene for display and calculate lightning normals m_pSceneNode = builder.finalizedSceneNode(); m_pSceneNode->setParent(this); }
/*! \internal */ void SphereMesh::createGeometry() { // We cache a maximum of 10 levels of detail for lod animations. // Create a new geometry node for this level of detail if necessary. QGLSceneNode *geometry = d->lodGeometry.value(d->lod, 0); if (!geometry) { QGLBuilder builder; builder.newSection(QGL::Faceted); builder << QGLSphere(2.0f, d->lod); geometry = builder.finalizedSceneNode(); geometry->setParent(this); d->lodGeometry.insert(d->lod, geometry); } Q_ASSERT_X(geometry != 0, Q_FUNC_INFO, "Could not create/find geometry!"); if (d->currentSphere != geometry) { if (d->currentSphere) d->topNode->removeNode(d->currentSphere); d->topNode->addNode(geometry); d->currentSphere = geometry; } // Set the radius as a scale on the modelview transformation. // This way, we don't have to regenerate the geometry every // frame if the radius is being animated. if (d->radius != 1.0f) { if (!d->scale) { d->scale = new QGraphicsScale3D(d->topNode); d->topNode->addTransform(d->scale); } if (d->scale->scale().x() != d->radius) { d->scale->setScale(QVector3D(d->radius, d->radius, d->radius)); } } else { // If there is already a scale set it to be the identity scale. // This case is optimised for in QGraphicsScale. Removing it from // the transform list is too expensive, especially if the size is // being animated, and the next frame will recreate it. if (d->scale) d->scale->setScale(QVector3D(1, 1, 1)); } // Also rotate the geometry into the correct axis orientation. const QVector3D Y_AXIS = QVector3D(0, 1, 0); // for Qt::XAxis we rotate around Y const QVector3D X_AXIS = QVector3D(1, 0, 0); // for Qt::YAxis we rotate around X if (d->axis != Qt::ZAxis && !d->rot) { d->rot = new QGraphicsRotation3D(d->topNode); d->topNode->addTransform(d->rot); } if (d->axis == Qt::XAxis && d->rot->axis().y() != Y_AXIS.y()) { d->rot->setAxis(Y_AXIS); d->rot->setAngle(90.0f); } else if (d->axis == Qt::YAxis && d->rot->axis().x() != X_AXIS.x()) { d->rot->setAxis(X_AXIS); d->rot->setAngle(-90.0f); } else if (d->axis == Qt::ZAxis && d->rot && d->rot->angle() != 0.0f) { d->rot->setAngle(0.0f); d->rot->setAxis(QVector3D(0, 0, 0)); } if (!d->sceneSet) { setScene(new SphereScene(d->topNode)); d->sceneSet = true; } }
void LabelView::initializeGL(QGLPainter *painter) { // in the constructor construct a builder on the stack QGLBuilder builder; float fac = 10.0f; builder << QGL::Faceted; m_pSceneNodeBrain = builder.currentNode(); builder.pushNode(); // Collor palette qint32 index; QSharedPointer<QGLMaterialCollection> palette = builder.sceneNode()->palette(); // register color palette within the root node // // Build each hemisphere in its separate node // for(qint32 h = 0; h < 2; ++h) { builder.newNode();//create new hemisphere node { MatrixX3i tris; MatrixX3f rr = m_surfSet[h].rr(); builder.pushNode(); // // Create each ROI in its own node // for(qint32 k = 0; k < m_qListLabels.size(); ++k) { //check if label hemi fits current hemi if(m_qListLabels[k].hemi != h) continue; //Ggenerate label tri information tris = m_qListLabels[k].selectTris(m_surfSet[h]); // add new ROI node when current ROI node is not empty if(builder.currentNode()->count() > 0) builder.newNode(); QGeometryData t_GeometryDataTri; MatrixXf t_TriCoords(3,3*tris.rows()); for(qint32 i = 0; i < tris.rows(); ++i) { t_TriCoords.col(i*3) = rr.row( tris(i,0) ).transpose(); t_TriCoords.col(i*3+1) = rr.row( tris(i,1) ).transpose(); t_TriCoords.col(i*3+2) = rr.row( tris(i,2) ).transpose(); } t_TriCoords *= fac; t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() )); // // If triangles are available. // if (t_GeometryDataTri.count() > 0) { // // Add triangles to current node // builder.addTriangles(t_GeometryDataTri); // // Colorize ROI // QGLMaterial *t_pMaterialROI = new QGLMaterial(); int r, g, b; r = m_qListRGBAs[k][0]; g = m_qListRGBAs[k][1]; b = m_qListRGBAs[k][2]; t_pMaterialROI->setColor(QColor(r,g,b,200)); // t_pMaterialROI->setEmittedLight(QColor(100,100,100,255)); // t_pMaterialROI->setSpecularColor(QColor(10,10,10,20)); index = palette->addMaterial(t_pMaterialROI); builder.currentNode()->setMaterialIndex(index); } } } // Go one level up builder.popNode(); } // Go one level up builder.popNode(); // Optimze current scene for display and calculate lightning normals m_pSceneNode = builder.finalizedSceneNode(); m_pSceneNode->setParent(this); // // Create light models // m_pLightModel = new QGLLightModel(this); m_pLightModel->setAmbientSceneColor(Qt::white); m_pLightModel->setViewerPosition(QGLLightModel::LocalViewer); m_pLightModel = new QGLLightModel(this); m_pLightParametersScene = new QGLLightParameters(this); m_pLightParametersScene->setPosition(QVector3D(0.0f, 0.0f, 3.0f)); painter->setMainLight(m_pLightParametersScene); simCount = 0; // // Set stereo type // if (m_bStereo) { this->setStereoType(QGLView::RedCyanAnaglyph); camera()->setEyeSeparation(0.4f); m_pCameraFrontal->setEyeSeparation(0.1f); } }
void ClustStcView::initializeGL(QGLPainter *painter) { if(!m_pModel) return; // in the constructor construct a builder on the stack QGLBuilder builder; float fac = 100.0f; // too small vertices distances cause clipping errors --> 100 is a good value for freesurfer brain measures builder << QGL::Faceted; if(m_pSceneNodeBrain) delete m_pSceneNodeBrain; m_pSceneNodeBrain = builder.currentNode(); builder.pushNode(); // Collor palette qint32 index; QSharedPointer<QGLMaterialCollection> palette = builder.sceneNode()->palette(); // register color palette within the root node m_qMapLabelIdIndex.clear(); // // // // Build each hemisphere in its separate node // // // for(qint32 h = 0; h < 1; ++h) // { builder.newNode();//create new hemisphere node { // // Create each ROI in its own node // for(qint32 k = 0; k < m_pModel->rowCount(); ++k) { // add new ROI node when current ROI node is not empty if(builder.currentNode()->count() > 0) builder.newNode(); QGeometryData t_GeometryDataTri; Matrix3Xf t_TriCoords = m_pModel->data(k,6,Qt::DisplayRole).value<Matrix3Xf>(); t_TriCoords *= fac; t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() )); // // If triangles are available. // if (t_GeometryDataTri.count() > 0) { // // Add triangles to current node // builder.addTriangles(t_GeometryDataTri); // // Colorize ROI // QGLMaterial *t_pMaterialROI = new QGLMaterial(); if(m_bShowRegions) t_pMaterialROI->setColor(m_pModel->data(k,5,Qt::DisplayRole).value<QColor>()); else t_pMaterialROI->setColor(QColor(100,100,100,230)); index = palette->addMaterial(t_pMaterialROI); builder.currentNode()->setMaterialIndex(index); m_qMapLabelIdIndex.insert(m_pModel->data(k,4,Qt::DisplayRole).value<Label>().label_id, index); } } } // Go one level up builder.popNode(); // } // // Go one level up // builder.popNode(); // Optimze current scene for display and calculate lightning normals if(m_pSceneNode) delete m_pSceneNode; m_pSceneNode = builder.finalizedSceneNode(); m_pSceneNode->setParent(this); // // Create light models // if(m_pLightModel) delete m_pLightModel; m_pLightModel = new QGLLightModel(this); m_pLightModel->setAmbientSceneColor(Qt::white); m_pLightModel->setViewerPosition(QGLLightModel::LocalViewer); m_pLightModel = new QGLLightModel(this); if(m_pLightParametersScene) delete m_pLightParametersScene; m_pLightParametersScene = new QGLLightParameters(this); m_pLightParametersScene->setPosition(QVector3D(0.0f, 0.0f, 3.0f)); painter->setMainLight(m_pLightParametersScene); // // Set stereo type // if (m_bStereo) { this->setStereoType(m_stereoType); // camera()->setEyeSeparation(0.4f); // m_pCameraFrontal->setEyeSeparation(0.1f); //LNdT DEMO camera()->setCenter(QVector3D(0,0,m_fOffsetZ));//0.8f*fac)); camera()->setEyeSeparation(0.4f); camera()->setFieldOfView(30); camera()->setEye(QVector3D(0,0,m_fOffsetZEye)); //LNdT DEMO end } else { camera()->setCenter(QVector3D(0,0,m_fOffsetZ)); camera()->setFieldOfView(30); camera()->setEye(QVector3D(0,0,m_fOffsetZEye)); } // //set background to light grey-blue // glClearColor(0.8f, 0.8f, 1.0f, 0.0f); // //set background to light white glClearColor(1.0f, 1.0f, 1.0f, 0.0f); m_bIsInitialized = true; }