Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

FileInterface.h 1.63 KB
Newer Older
Anakin's avatar
Anakin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#pragma once
#include <fstream>
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QOpenGLFunctions>


struct BoundingBox {
	QQuaternion rotation;
	QVector3D center;
	QVector3D extents;
};

17 18 19 20 21 22
struct VertexData
{
	QVector3D position;
	QVector2D texCoord;
};

Anakin's avatar
Anakin committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
struct Segment {
	std::uint32_t textureIndex = 0;
	QVector<VertexData> vertices;
	QVector<GLuint> indices;
};

struct Model {
	std::string name = "";
	std::string parent = "";
	QMatrix4x4 m4x4Translation;
	std::vector<Segment*> segmList;
};

class FileInterface
{
public:
	explicit FileInterface(const char* path)
		: m_models(new QVector<Model*>)
		, m_textureNames(new QVector<std::string>)
	{
		//open file
		m_file.open(path, std::ios::in | std::ios::binary);

		if (!m_file.is_open())
			throw std::invalid_argument(std::string("file not found: ") += path);
	};

	virtual ~FileInterface()
	{
		// close file
		m_file.close();
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

		//clean up
		m_textureNames->clear();
		delete m_textureNames;

		for (Model* modelIt : *m_models)
		{
			for (Segment* segIt : modelIt->segmList)
			{
				segIt->indices.clear();
				segIt->vertices.clear();
				delete segIt;
			}
			modelIt->segmList.clear();

			delete modelIt;
		}
		m_models->clear();
		delete m_models;
Anakin's avatar
Anakin committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	};

protected:
	QVector<Model*>* m_models;
	std::fstream m_file;
	QVector<std::string>* m_textureNames;
	BoundingBox m_sceneBbox;

	virtual void import() = 0;

public:
	virtual QVector<Model*>* getModels() const { return m_models; };
	virtual QVector<std::string>* getTextureNames() const { return m_textureNames; };
	virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
};