Example #1
0
QHash<int, QVariantList> DatasetParser::parseDataFolder(QDir datasetFolder)
{
    QFileInfo dataFileInfo(datasetFolder, datasetDescriptorFileName);
    QVariantList datasetDescriptor = this->parseDataFile(dataFileInfo);
    QList<QFileInfo> imageFileInfoList = datasetFolder.entryInfoList(extentions, QDir::Files, QDir::Name);
    return this->matchUniqueIDWithImage(datasetDescriptor, imageFileInfoList);
}
bool Vocabulary::save( const QString& filename ) const {
    QByteArray data;

    QDataStream out( &data, QIODevice::WriteOnly );
    out.setVersion( QDataStream::Qt_2_1 );

    // 0x0010 means 0.10.x version.  
    out << qint32( Vocabulary::magicNumber ) << qint16( 0x0010 ) << *this;

    QByteArray compressedData( qCompress( data ) ); 

    QFile dataFile( filename );
    QFileInfo dataFileInfo( dataFile );
    QDir dataFileDir( dataFileInfo.absoluteDir() );

    if( !dataFileDir.mkpath( dataFileDir.path() ) )
        return( false );

    if( !dataFile.open( QIODevice::WriteOnly ) )
        return( false );

    int ret = dataFile.write( compressedData );
    dataFile.close();

    if( ret == -1 || dataFile.error() != QFile::NoError ) {
        dataFile.unsetError();
        return( false );
    }

    return( true );
}
PolylineImportConfiguration::PolylineImportConfiguration( QFile& file )
{
    QDomDocument dom;
    if( !dom.setContent( &file ) )
    {
        throw UnexpectedFormatException();
    }

    QDomElement root = dom.documentElement();
    if( root.tagName() != "PolylineImport" )
    {
        throw UnexpectedFormatException();
    }

    // read settings

    fileName = root.attribute( "file" );
    const QString vertexPattern = root.attribute( "vertex" );
    const QString space = root.attribute( "space" );
    vertexSize = std::max( 0.f, root.attribute( "vertexsize" ).toFloat() );
    lineWidth = std::max( 1.f, root.attribute( "width" ).toFloat() );
    withBorder = ( root.attribute( "border" ).toInt() > 0 );

    if( fileName.isNull() || vertexPattern.isNull() || space.isNull()
        || fileName.isEmpty() || vertexPattern.isEmpty() || space.isEmpty() )
    {
        throw UnexpectedFormatException();
    }

    QFileInfo dataFileInfo( fileName );
    if( !dataFileInfo.exists() && !dataFileInfo.isAbsolute() )
    {
        const QDir fileDir = QFileInfo( file ).absoluteDir();
        fileName = fileDir.filePath( fileName );
    }

    if( space == "model" )
    {
        units = millimeters;
    }
    else
    if( space == "volume" || space == "texture" )
    {
        units = volumeUnits;
    }
    else
    {
        throw UnexpectedFormatException();
    }

    vertexRegex = QRegExp( vertexPattern );
}