ViewportPrivate::ViewportPrivate() : picking(true) , showPicking(false) , navigation(true) , blending(false) , itemsInitialized(false) , needsPick(true) , camera(0) , lightModel(0) , backdrop(0) , backgroundColor(Qt::black) , view(0) , viewWidget(0) , pickId(1) , pickFbo(0) { // Construct the vertices for a quad with (0, 0) as the // texture co-ordinate for the bottom-left of the screen // and (1, 1) as the texture co-ordinate for the top-right. backdropVertices.setPackingHint(QGLVertexBuffer::Append); QArray<QVector2D> pos; pos.append(QVector2D(-1.0f, -1.0f)); pos.append(QVector2D(-1.0f, 1.0f)); pos.append(QVector2D( 1.0f, 1.0f)); pos.append(QVector2D( 1.0f, -1.0f)); QArray<QVector2D> tex; pos.append(QVector2D(0.0f, 0.0f)); pos.append(QVector2D(0.0f, 1.0f)); pos.append(QVector2D(1.0f, 1.0f)); pos.append(QVector2D(1.0f, 0.0f)); backdropVertices.addAttribute(QGL::Position, pos); backdropVertices.addAttribute(QGL::TextureCoord0, tex); //backdropVertices.append(-1.0f, -1.0f); //backdropVertices.append(0.0f, 0.0f); //backdropVertices.append(-1.0f, 1.0f); //backdropVertices.append(0.0f, 1.0f); //backdropVertices.append(1.0f, 1.0f); //backdropVertices.append(1.0f, 1.0f); //backdropVertices.append(1.0f, -1.0f); //backdropVertices.append(1.0f, 0.0f); }
void QGLIndexBufferPrivate::append (const QGLIndexBufferPrivate *other, uint offset, int start) { if (elementType == GL_UNSIGNED_SHORT && other->elementType == GL_UNSIGNED_SHORT) { // Both buffers are ushort. const ushort *data = other->indexesShort.constData() + start; int count = other->indexesShort.count() - start; indexesShort.reserve(indexesShort.count() + count); indexCount += count; while (count-- > 0) indexesShort.append(ushort(*data++ + offset)); } else if (elementType == GL_UNSIGNED_SHORT) { // Only first buffer is ushort: convert it to int first. const ushort *indexes = indexesShort.constData(); int count = indexesShort.count(); indexesInt.reserve(count + other->indexesInt.count()); while (count-- > 0) indexesInt.append(*indexes++); indexesShort = QArray<ushort>(); elementType = GL_UNSIGNED_INT; const uint *data = other->indexesInt.constData() + start; count = other->indexesInt.count() - start; indexCount += count; while (count-- > 0) indexesInt.append(*data++ + offset); } else if (other->elementType == GL_UNSIGNED_SHORT) { // Only second buffer is ushort. const ushort *data = other->indexesShort.constData() + start; int count = other->indexesShort.count() - start; indexesInt.reserve(indexesInt.count() + count); indexCount += count; while (count-- > 0) indexesInt.append(*data++ + offset); } else { // Neither buffer is ushort. const uint *data = other->indexesInt.constData() + start; int count = other->indexesInt.count() - start; indexesInt.reserve(indexesInt.count() + count); indexCount += count; while (count-- > 0) indexesInt.append(*data++ + offset); } }
static QArray<ushort> qt_qarray_uint_to_ushort(const QArray<uint> &array) { QArray<ushort> result; const uint *values = array.constData(); int size = array.size(); bool largeValue = false; result.reserve(size); while (size-- > 0) { uint value = *values++; if (ushort(value) != value) largeValue = true; result.append(ushort(value)); } if (largeValue) qWarning("QGLIndexBuffer::setIndexes: large 32-bit value provided to a 16-bit only buffer"); return result; }
/*! \internal Processes a list of floating point numbers. If the list contains only 1 element, a QVariant<float> is returned. If the list containst 2, 3 or 4 elements, they are converted into a QVariant containing a QVector2D, QVector3D, or QVector4D respectively. If the list containst more elements than that, they are returned as a QArray<float>. */ QVariant QGLColladaFxEffectFactory::processFloatList( QXmlStreamReader& xml ) { QArray<float> floats; QString elementString = xml.readElementText(); QStringList list = elementString.split( QRegExp( "\\s+" ), QString::SkipEmptyParts ); bool ok; float f; foreach( QString string, list ) { f = string.toFloat( &ok ); if( ok ) floats.append(string.toFloat()); else { qWarning() << "Warning: malformed float ( line" << xml.lineNumber() << ")"; } }
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); }
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(); }