Skip to content

Commit

Permalink
fix build errors, use MDAL 0.0.2 (int API)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Apr 19, 2018
1 parent 50422a1 commit 1efdbc5
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 253 deletions.
20 changes: 9 additions & 11 deletions external/mdal/api/mdal.h
Expand Up @@ -36,10 +36,8 @@
extern "C" {
#endif

#include <stddef.h>

/* Statuses */
enum Status
enum MDAL_Status
{
None,
// Errors
Expand All @@ -57,32 +55,32 @@ enum Status
Warn_NodeNotUnique
};

/* Mesh */
//! Mesh
typedef void *MeshH;

//! Return MDAL version
MDAL_EXPORT const char *MDAL_Version();

//! Return last status message
MDAL_EXPORT Status MDAL_LastStatus();
MDAL_EXPORT MDAL_Status MDAL_LastStatus();

//! Load mesh file. On error see MDAL_LastStatus for error type This effectively loads whole mesh in-memory
MDAL_EXPORT MeshH MDAL_LoadMesh( const char *meshFile );
//! Close mesh, free the memory
MDAL_EXPORT void MDAL_CloseMesh( MeshH mesh );

//! Return vertex count for the mesh
MDAL_EXPORT size_t MDAL_M_vertexCount( MeshH mesh );
MDAL_EXPORT int MDAL_M_vertexCount( MeshH mesh );
//! Return vertex X coord for the mesh
MDAL_EXPORT double MDAL_M_vertexXCoordinatesAt( MeshH mesh, size_t index );
MDAL_EXPORT double MDAL_M_vertexXCoordinatesAt( MeshH mesh, int index );
//! Return vertex Y coord for the mesh
MDAL_EXPORT double MDAL_M_vertexYCoordinatesAt( MeshH mesh, size_t index );
MDAL_EXPORT double MDAL_M_vertexYCoordinatesAt( MeshH mesh, int index );
//! Return face count for the mesh
MDAL_EXPORT size_t MDAL_M_faceCount( MeshH mesh );
MDAL_EXPORT int MDAL_M_faceCount( MeshH mesh );
//! Return number of vertices face consist of, e.g. 3 for triangle
MDAL_EXPORT size_t MDAL_M_faceVerticesCountAt( MeshH mesh, size_t index );
MDAL_EXPORT int MDAL_M_faceVerticesCountAt( MeshH mesh, int index );
//! Return vertex index for face
MDAL_EXPORT size_t MDAL_M_faceVerticesIndexAt( MeshH mesh, size_t face_index, size_t vertex_index );
MDAL_EXPORT int MDAL_M_faceVerticesIndexAt( MeshH mesh, int face_index, int vertex_index );

#ifdef __cplusplus
}
Expand Down
20 changes: 10 additions & 10 deletions external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -22,21 +22,21 @@ MDAL::Loader2dm::Loader2dm( const std::string &meshFile ):
{
}

MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
MDAL::Mesh *MDAL::Loader2dm::load( MDAL_Status *status )
{
if ( status ) *status = Status::None;
if ( status ) *status = MDAL_Status::None;

if ( !MDAL::fileExists( mMeshFile ) )
{
if ( status ) *status = Status::Err_FileNotFound;
if ( status ) *status = MDAL_Status::Err_FileNotFound;
return 0;
}

std::ifstream in( mMeshFile, std::ifstream::in );
std::string line;
if ( !std::getline( in, line ) || !startsWith( line, "MESH2D" ) )
{
if ( status ) *status = Status::Err_UnknownFormat;
if ( status ) *status = MDAL_Status::Err_UnknownFormat;
return 0;
}

Expand All @@ -61,7 +61,7 @@ MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
startsWith( line, "E8Q" ) ||
startsWith( line, "E9Q" ) )
{
if ( status ) *status = Status::Warn_UnsupportedElement;
if ( status ) *status = MDAL_Status::Warn_UnsupportedElement;
elemCount += 1; // We still count them as elements
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
std::map<size_t, size_t>::iterator search = elemIDtoIndex.find( elemID );
if ( search != elemIDtoIndex.end() )
{
if ( status ) *status = Status::Warn_ElementNotUnique;
if ( status ) *status = MDAL_Status::Warn_ElementNotUnique;
continue;
}
elemIDtoIndex[elemID] = elemIndex;
Expand All @@ -114,7 +114,7 @@ MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
std::map<size_t, size_t>::iterator search = elemIDtoIndex.find( elemID );
if ( search != elemIDtoIndex.end() )
{
if ( status ) *status = Status::Warn_ElementNotUnique;
if ( status ) *status = MDAL_Status::Warn_ElementNotUnique;
continue;
}
elemIDtoIndex[elemID] = elemIndex;
Expand Down Expand Up @@ -143,7 +143,7 @@ MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
std::map<size_t, size_t>::iterator search = elemIDtoIndex.find( elemID );
if ( search != elemIDtoIndex.end() )
{
if ( status ) *status = Status::Warn_ElementNotUnique;
if ( status ) *status = MDAL_Status::Warn_ElementNotUnique;
continue;
}
elemIDtoIndex[elemID] = elemIndex;
Expand All @@ -159,7 +159,7 @@ MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
std::map<size_t, size_t>::iterator search = nodeIDtoIndex.find( nodeID );
if ( search != nodeIDtoIndex.end() )
{
if ( status ) *status = Status::Warn_NodeNotUnique;
if ( status ) *status = MDAL_Status::Warn_NodeNotUnique;
continue;
}
nodeIDtoIndex[nodeID] = nodeIndex;
Expand Down Expand Up @@ -188,7 +188,7 @@ MDAL::Mesh *MDAL::Loader2dm::load( Status *status )
{
assert( false ); //TODO mark element as unusable

if ( status ) *status = Status::Warn_ElementWithInvalidNode;
if ( status ) *status = MDAL_Status::Warn_ElementWithInvalidNode;
}
}

Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_2dm.hpp
Expand Up @@ -18,7 +18,7 @@ namespace MDAL
{
public:
Loader2dm( const std::string &meshFile );
Mesh *load( Status *status );
Mesh *load( MDAL_Status *status );

private:
std::string mMeshFile;
Expand Down
54 changes: 34 additions & 20 deletions external/mdal/mdal.cpp
Expand Up @@ -6,14 +6,14 @@
#include "mdal_loader.hpp"
#include "mdal_defines.hpp"

static Status sLastStatus;
static MDAL_Status sLastStatus;

const char *MDAL_Version()
{
return "0.0.1";
return "0.0.2";
}

Status MDAL_LastStatus()
MDAL_Status MDAL_LastStatus()
{
return sLastStatus;
}
Expand All @@ -38,49 +38,63 @@ void MDAL_CloseMesh( MeshH mesh )
}


size_t MDAL_M_vertexCount( MeshH mesh )
int MDAL_M_vertexCount( MeshH mesh )
{
assert( mesh );
MDAL::Mesh *m = ( MDAL::Mesh * ) mesh;
return m->vertices.size();
int len = static_cast<int>( m->vertices.size() );
return len;
}

double MDAL_M_vertexXCoordinatesAt( MeshH mesh, size_t index )
double MDAL_M_vertexXCoordinatesAt( MeshH mesh, int index )
{
assert( mesh );
MDAL::Mesh *m = ( MDAL::Mesh * ) mesh;
assert( m->vertices.size() > index );
return m->vertices[index].x;
assert( index > -1 );
size_t i = static_cast<size_t>( index );
assert( m->vertices.size() > i );
return m->vertices[i].x;
}

double MDAL_M_vertexYCoordinatesAt( MeshH mesh, size_t index )
double MDAL_M_vertexYCoordinatesAt( MeshH mesh, int index )
{
assert( mesh );
MDAL::Mesh *m = ( MDAL::Mesh * ) mesh;
assert( m->vertices.size() > index );
return m->vertices[index].y;
assert( index > -1 );
size_t i = static_cast<size_t>( index );
assert( m->vertices.size() > i );
return m->vertices[i].y;
}

size_t MDAL_M_faceCount( MeshH mesh )
int MDAL_M_faceCount( MeshH mesh )
{
assert( mesh );
MDAL::Mesh *m = ( MDAL::Mesh * ) mesh;
return m->faces.size();
int len = static_cast<int>( m->faces.size() );
return len;
}

size_t MDAL_M_faceVerticesCountAt( MeshH mesh, size_t index )
int MDAL_M_faceVerticesCountAt( MeshH mesh, int index )
{
assert( mesh );
MDAL::Mesh *m = ( MDAL::Mesh * ) mesh;
assert( m->faces.size() > index );
return m->faces[index].size();
assert( index > -1 );
size_t i = static_cast<size_t>( index );
assert( m->faces.size() > i );
int len = static_cast<int>( m->faces[i].size() );
return len;
}

size_t MDAL_M_faceVerticesIndexAt( MeshH mesh, size_t face_index, size_t vertex_index )
int MDAL_M_faceVerticesIndexAt( MeshH mesh, int face_index, int vertex_index )
{
assert( mesh );
MDAL::Mesh *m = ( MDAL::Mesh * ) mesh;
assert( m->faces.size() > face_index );
assert( m->faces[face_index].size() > vertex_index );
return m->faces[face_index][vertex_index];
assert( face_index > -1 );
size_t fi = static_cast<size_t>( face_index );
assert( m->faces.size() > fi );
assert( vertex_index > -1 );
size_t vi = static_cast<size_t>( vertex_index );
assert( m->faces[fi].size() > vi );
int len = static_cast<int>( m->faces[fi][vi] );
return len;
}
2 changes: 1 addition & 1 deletion external/mdal/mdal_loader.cpp
Expand Up @@ -6,7 +6,7 @@
#include "mdal_loader.hpp"
#include "frmts/mdal_2dm.hpp"

MDAL::Mesh *MDAL::Loader::load( const std::string &meshFile, Status *status )
MDAL::Mesh *MDAL::Loader::load( const std::string &meshFile, MDAL_Status *status )
{
MDAL::Loader2dm loader( meshFile );
return loader.load( status );
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/mdal_loader.hpp
Expand Up @@ -17,7 +17,7 @@ namespace MDAL
class Loader
{
public:
static Mesh *load( const std::string &meshFile, Status *status );
static Mesh *load( const std::string &meshFile, MDAL_Status *status );
};

} // namespace MDAL
Expand Down
78 changes: 78 additions & 0 deletions images/themes/default/mIconMeshLayer.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 7 additions & 8 deletions python/core/mesh/qgsmeshdataprovider.sip.in
Expand Up @@ -10,9 +10,8 @@




typedef QgsPoint QgsMeshVertex; //xyz coords of vertex
typedef QVector<size_t> QgsMeshFace; //list of vertex indexes
typedef QVector<int> QgsMeshFace; //list of vertex indexes

class QgsMeshSource /Abstract/
{
Expand All @@ -33,28 +32,28 @@ read on demand
public:
virtual ~QgsMeshSource();

virtual size_t vertexCount() const = 0;
virtual int vertexCount() const = 0;
%Docstring
Return number of vertexes in the native mesh
Return number of vertices in the native mesh

:return: Number of vertexes in the mesh
:return: Number of vertices in the mesh
%End

virtual size_t faceCount() const = 0;
virtual int faceCount() const = 0;
%Docstring
Return number of faces in the native mesh

:return: Number of faces in the mesh
%End

virtual QgsMeshVertex vertex( size_t index ) const = 0;
virtual QgsMeshVertex vertex( int index ) const = 0;
%Docstring
Factory for mesh vertex with index

:return: new mesh vertex on index
%End

virtual QgsMeshFace face( size_t index ) const = 0;
virtual QgsMeshFace face( int index ) const = 0;
%Docstring
Factory for mesh face with index

Expand Down

0 comments on commit 1efdbc5

Please sign in to comment.