QGIS/external/mdal/mdal_data_model.hpp

196 lines
5.0 KiB
C++
Raw Normal View History

/*
MDAL - Mesh Data Abstraction Library (MIT License)
Copyright (C) 2018 Peter Petrik (zilolv at gmail dot com)
*/
2018-12-04 17:28:05 +01:00
#ifndef MDAL_DATA_MODEL_HPP
#define MDAL_DATA_MODEL_HPP
#include <stddef.h>
#include <vector>
2018-05-16 11:20:25 +02:00
#include <memory>
#include <map>
2018-09-10 23:12:00 +02:00
#include <string>
#include <limits>
2018-12-04 17:28:05 +01:00
#include "mdal.h"
2018-07-18 09:00:34 +02:00
namespace MDAL
{
2018-07-18 09:00:34 +02:00
class DatasetGroup;
2018-12-04 17:28:05 +01:00
class Mesh;
2018-07-18 09:00:34 +02:00
struct BBox
{
BBox() {}
BBox( double lx, double ux, double ly, double uy ): minX( lx ), maxX( ux ), minY( ly ), maxY( uy ) {}
double minX;
double maxX;
double minY;
double maxY;
};
2018-05-16 11:20:25 +02:00
typedef struct
{
2018-12-04 17:28:05 +01:00
double minimum = std::numeric_limits<double>::quiet_NaN();
double maximum = std::numeric_limits<double>::quiet_NaN();
} Statistics;
2018-05-16 11:20:25 +02:00
2018-07-18 09:00:34 +02:00
typedef std::vector< std::pair< std::string, std::string > > Metadata;
2018-05-16 11:20:25 +02:00
class Dataset
{
public:
2018-12-04 17:28:05 +01:00
Dataset( DatasetGroup *parent );
virtual ~Dataset();
std::string driverName() const;
2018-12-04 17:28:05 +01:00
size_t valuesCount() const;
virtual size_t scalarData( size_t indexStart, size_t count, double *buffer ) = 0;
virtual size_t vectorData( size_t indexStart, size_t count, double *buffer ) = 0;
virtual size_t activeData( size_t indexStart, size_t count, int *buffer ) = 0;
2018-05-16 11:20:25 +02:00
2018-12-04 17:28:05 +01:00
Statistics statistics() const;
void setStatistics( const Statistics &statistics );
2018-05-16 11:20:25 +02:00
2018-12-04 17:28:05 +01:00
bool isValid() const;
void setIsValid( bool isValid );
2018-05-16 11:20:25 +02:00
2018-12-04 17:28:05 +01:00
DatasetGroup *group() const;
Mesh *mesh() const;
double time() const;
void setTime( double time );
private:
double mTime = std::numeric_limits<double>::quiet_NaN();
bool mIsValid = true;
DatasetGroup *mParent = nullptr;
Statistics mStatistics;
2018-07-18 09:00:34 +02:00
};
2018-05-16 11:20:25 +02:00
2018-07-18 09:00:34 +02:00
typedef std::vector<std::shared_ptr<Dataset>> Datasets;
2018-05-16 11:20:25 +02:00
2018-07-18 09:00:34 +02:00
class DatasetGroup
{
public:
DatasetGroup( const std::string &driverName,
Mesh *parent,
const std::string &uri
);
2018-12-04 17:28:05 +01:00
DatasetGroup( const std::string &driverName,
Mesh *parent,
2018-12-04 17:28:05 +01:00
const std::string &uri,
const std::string &name );
2018-07-18 09:00:34 +02:00
~DatasetGroup();
std::string driverName() const;
2018-12-04 17:28:05 +01:00
std::string getMetadata( const std::string &key );
2018-07-18 09:00:34 +02:00
void setMetadata( const std::string &key, const std::string &val );
std::string name();
void setName( const std::string &name );
Metadata metadata;
Datasets datasets;
2018-12-04 17:28:05 +01:00
bool isScalar() const;
void setIsScalar( bool isScalar );
bool isOnVertices() const;
void setIsOnVertices( bool isOnVertices );
std::string uri() const;
Statistics statistics() const;
void setStatistics( const Statistics &statistics );
Mesh *mesh() const;
bool isInEditMode() const;
void startEditing();
void stopEditing();
2018-12-04 17:28:05 +01:00
private:
bool mInEditMode = false;
const std::string mDriverName;
2018-12-04 17:28:05 +01:00
Mesh *mParent = nullptr;
bool mIsScalar = true;
bool mIsOnVertices = true;
std::string mUri; // file/uri from where it came
Statistics mStatistics;
2018-05-16 11:20:25 +02:00
};
2018-07-18 09:00:34 +02:00
typedef std::vector<std::shared_ptr<DatasetGroup>> DatasetGroups;
2018-12-04 17:28:05 +01:00
class MeshVertexIterator
{
2018-12-04 17:28:05 +01:00
public:
virtual ~MeshVertexIterator();
2018-12-04 17:28:05 +01:00
virtual size_t next( size_t vertexCount, double *coordinates ) = 0;
};
2018-12-04 17:28:05 +01:00
class MeshFaceIterator
{
public:
virtual ~MeshFaceIterator();
2018-08-29 12:10:03 +02:00
2018-12-04 17:28:05 +01:00
virtual size_t next( size_t faceOffsetsBufferLen,
int *faceOffsetsBuffer,
size_t vertexIndicesBufferLen,
int *vertexIndicesBuffer ) = 0;
2018-05-16 11:20:25 +02:00
};
2018-12-04 17:28:05 +01:00
class Mesh
{
public:
Mesh( const std::string &driverName,
size_t verticesCount,
2018-12-04 17:28:05 +01:00
size_t facesCount,
size_t faceVerticesMaximumCount,
BBox extent,
const std::string &uri );
virtual ~Mesh();
std::string driverName() const;
2018-12-04 17:28:05 +01:00
void setSourceCrs( const std::string &str );
void setSourceCrsFromWKT( const std::string &wkt );
void setSourceCrsFromEPSG( int code );
void setVerticesCount( size_t verticesCount );
void setFacesCount( size_t facesCount );
void setFaceVerticesMaximumCount( size_t faceVerticesMaximumCount );
void setExtent( const BBox &extent );
virtual std::unique_ptr<MDAL::MeshVertexIterator> readVertices() = 0;
virtual std::unique_ptr<MDAL::MeshFaceIterator> readFaces() = 0;
DatasetGroups datasetGroups;
size_t verticesCount() const;
size_t facesCount() const;
std::string uri() const;
BBox extent() const;
std::string crs() const;
size_t faceVerticesMaximumCount() const;
private:
const std::string mDriverName;
2018-12-04 17:28:05 +01:00
size_t mVerticesCount = 0;
size_t mFacesCount = 0;
size_t mFaceVerticesMaximumCount = 0; //typically 3 or 4, sometimes up to 9
BBox mExtent;
const std::string mUri; // file/uri from where it came
std::string mCrs;
};
} // namespace MDAL
2018-12-04 17:28:05 +01:00
#endif //MDAL_DATA_MODEL_HPP