Commit 25bf69f3 authored by Martin Schultz's avatar Martin Schultz
Browse files

refs #2421

*objLoader now uses readAll modifications

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20898 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ee3740b1
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh> #include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh> #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/Utils/Memory/RAMInfo.hh>
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
#include <QtWidgets> #include <QtWidgets>
...@@ -63,6 +64,7 @@ ...@@ -63,6 +64,7 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <ACG/Utils/SmartPointer.hh>
#include <OpenFlipper/Utils/FileIO/NumberParsing.hh> #include <OpenFlipper/Utils/FileIO/NumberParsing.hh>
// Defines for the type handling drop down box // Defines for the type handling drop down box
...@@ -561,21 +563,31 @@ void FileOBJPlugin::addTextures(OBJImporter& _importer, int _objectID ){ ...@@ -561,21 +563,31 @@ void FileOBJPlugin::addTextures(OBJImporter& _importer, int _objectID ){
} }
} }
void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer) void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OBJImporter& _importer)
{ {
QString path = QFileInfo(_filename).absolutePath(); QString path = QFileInfo(_filename).absolutePath();
ptr::shared_ptr<QTextStream> streamPointer;
ptr::shared_ptr<QFile> sourceFile;
//setup filestream ////setup filestream if not in memory
if (_bufferedFile.isNull())
QFile sourceFile(_filename);
if(!sourceFile.open(QFile::ReadOnly))
{ {
emit log(LOGERR, tr("readOBJFile : cannot open file %1").arg(_filename) ); sourceFile.reset(new QFile(_filename) );
return; if(!sourceFile->open(QFile::ReadOnly))
{
emit log(LOGERR, tr("readOBJFile : cannot open file %1").arg(_filename) );
return;
}
//use the QTextStream and QString objects, since they seem to be more efficient when parsing strings.
//especially regarding copy operations.
streamPointer.reset( new QTextStream(sourceFile.get()));
} }
//use the QTextStream and QString objects, since they seem to be more efficient when parsing strings. else
//especially regarding copy operations. {
QTextStream input(&sourceFile); streamPointer.reset( new QTextStream(&_bufferedFile));
}
QTextStream input(streamPointer->device());
input.seek(0);
QTextStream stream; QTextStream stream;
QTextStream lineData; QTextStream lineData;
QTextStream tmp; QTextStream tmp;
...@@ -1251,18 +1263,27 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer) ...@@ -1251,18 +1263,27 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
} }
///check file types and read general info like vertices ///check file types and read general info like vertices
void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStringList& _includes) void FileOBJPlugin::checkTypes(QByteArray& _bufferedFile, QString _filename, OBJImporter& _importer, QStringList& _includes)
{ {
//setup filestream ptr::shared_ptr<QTextStream> streamPointer;
ptr::shared_ptr<QFile> sourceFile;
//setup filestream if not in memory
if (_bufferedFile.isNull() || _bufferedFile.isEmpty())
{
QFile sourceFile(_filename); sourceFile.reset(new QFile(_filename));
if(!sourceFile.open(QFile::ReadOnly)) if(!sourceFile->open(QFile::ReadOnly))
{
emit log(LOGERR, tr("readOBJFile : cannot open file %1 while checking Types").arg(_filename) );
return;
}
streamPointer.reset(new QTextStream(sourceFile.get()));
}
else
{ {
emit log(LOGERR, tr("readOBJFile : cannot open file %1 while checking Types").arg(_filename) ); streamPointer.reset(new QTextStream(&_bufferedFile));
return;
} }
QTextStream input(streamPointer->device());
QTextStream input( &sourceFile );
QTextStream stream; QTextStream stream;
QTextStream lineData; QTextStream lineData;
QTextStream tmp; QTextStream tmp;
...@@ -1698,7 +1719,9 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin ...@@ -1698,7 +1719,9 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
} }
if (TriMeshCount == 0 && PolyMeshCount == 0) if (TriMeshCount == 0 && PolyMeshCount == 0)
{
return; return;
}
if (forceTriangleMesh_){ if (forceTriangleMesh_){
_importer.forceMeshType( OBJImporter::TRIMESH ); _importer.forceMeshType( OBJImporter::TRIMESH );
...@@ -1747,6 +1770,7 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin ...@@ -1747,6 +1770,7 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
} }
} }
} }
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
...@@ -1758,8 +1782,24 @@ int FileOBJPlugin::loadObject(QString _filename) { ...@@ -1758,8 +1782,24 @@ int FileOBJPlugin::loadObject(QString _filename) {
//included filenames //included filenames
QStringList includes; QStringList includes;
QFile sourceFile(_filename);
if (!sourceFile.open(QFile::ReadOnly))
{
emit log(LOGERR, tr("readOBJFile : cannot open file %1 while checking Types").arg(_filename));
return -1;
}
QByteArray bufferedFile = QByteArray();
//load the entire file to ram if we have at least double the size as free memory.
//otherwise the bytearray stays null and the file is read when it is processed.
unsigned long freeMem = Utils::Memory::queryFreeRAM();
unsigned long fs = sourceFile.size() / 1024 / 1024;
if (freeMem >= 2*fs)
{
bufferedFile = sourceFile.readAll();
}
//preprocess file and store types in ObjectOptions //preprocess file and store types in ObjectOptions
checkTypes( _filename, importer, includes ); checkTypes( bufferedFile, _filename, importer, includes );
IdList objIDs; IdList objIDs;
...@@ -1787,7 +1827,7 @@ int FileOBJPlugin::loadObject(QString _filename) { ...@@ -1787,7 +1827,7 @@ int FileOBJPlugin::loadObject(QString _filename) {
} }
//then parse the obj //then parse the obj
readOBJFile( _filename, importer ); readOBJFile( bufferedFile, _filename, importer );
// finish up // finish up
importer.finish(); importer.finish();
...@@ -2021,7 +2061,6 @@ int FileOBJPlugin::loadObject(QString _filename) { ...@@ -2021,7 +2061,6 @@ int FileOBJPlugin::loadObject(QString _filename) {
// if ( topLevelObj ) // if ( topLevelObj )
// OpenFlipper::Options::loadingSettings(false); // OpenFlipper::Options::loadingSettings(false);
return returnID; return returnID;
} }
......
...@@ -171,10 +171,10 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte ...@@ -171,10 +171,10 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
private: private:
/// Reader functions /// Reader functions
void checkTypes(QString _filename, OBJImporter& _importer, QStringList& _includes); void checkTypes(QByteArray& _bufferedFile, QString _filename, OBJImporter& _importer, QStringList& _includes);
bool readMaterial(QString _filename, OBJImporter& _importer); bool readMaterial(QString _filename, OBJImporter& _importer);
void readOBJFile(QString _filename, OBJImporter& _importer); void readOBJFile(QByteArray& _bufferedFile, QString _filename, OBJImporter& _importer);
void createAllGroupObjects(OBJImporter& _importer); void createAllGroupObjects(OBJImporter& _importer);
//void addNewObject(OBJImporter& _importer, QString _name ); //void addNewObject(OBJImporter& _importer, QString _name );
template <class MeshT> template <class MeshT>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment