2015-03-24 01:21:04 +08:00
|
|
|
/****************************************************************************
|
|
|
|
** GeomIO Library
|
|
|
|
** Copyright FougSys (2 Mar. 2015)
|
|
|
|
** contact@fougsys.fr
|
|
|
|
**
|
|
|
|
** This software is a reusable library whose purpose is to provide complete
|
|
|
|
** I/O support for various CAD file formats (eg. STL)
|
|
|
|
**
|
|
|
|
** This software is governed by the CeCILL-B license under French law and
|
|
|
|
** abiding by the rules of distribution of free software. You can use,
|
|
|
|
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
|
|
|
** license as circulated by CEA, CNRS and INRIA at the following URL
|
2015-03-30 15:05:25 +08:00
|
|
|
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
2015-03-24 01:21:04 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "stl_io.h"
|
|
|
|
|
|
|
|
#include "stl_error.h"
|
|
|
|
#include "stl_format.h"
|
|
|
|
#include "../gmio_core/error.h"
|
|
|
|
#include "../gmio_core/stream.h"
|
|
|
|
#include "../gmio_core/transfer.h"
|
|
|
|
#include "../gmio_core/internal/helper_stream.h"
|
|
|
|
|
|
|
|
int gmio_stl_read_file(
|
|
|
|
const char* filepath,
|
2015-03-30 15:30:55 +08:00
|
|
|
gmio_stl_mesh_creator_t* creator)
|
2015-03-24 01:21:04 +08:00
|
|
|
{
|
2015-04-02 16:04:24 +08:00
|
|
|
int error = GMIO_ERROR_OK;
|
2015-03-24 01:21:04 +08:00
|
|
|
FILE* file = NULL;
|
|
|
|
|
|
|
|
file = fopen(filepath, "rb");
|
|
|
|
if (file != NULL) {
|
|
|
|
gmio_transfer_t trsf = { 0 };
|
|
|
|
trsf.stream = gmio_stream_stdio(file);
|
2015-04-02 21:36:57 +08:00
|
|
|
trsf.buffer = gmio_buffer_default();
|
2015-03-24 01:21:04 +08:00
|
|
|
|
|
|
|
error = gmio_stl_read(&trsf, creator);
|
|
|
|
fclose(file);
|
2015-04-02 21:36:57 +08:00
|
|
|
gmio_buffer_deallocate(&trsf.buffer);
|
2015-03-24 01:21:04 +08:00
|
|
|
}
|
|
|
|
else {
|
2015-04-02 16:04:24 +08:00
|
|
|
error = GMIO_ERROR_UNKNOWN;
|
2015-03-24 01:21:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gmio_stl_read(gmio_transfer_t *trsf, gmio_stl_mesh_creator_t *creator)
|
|
|
|
{
|
2015-04-02 16:04:24 +08:00
|
|
|
int error = GMIO_ERROR_OK;
|
2015-03-24 01:21:04 +08:00
|
|
|
|
|
|
|
if (trsf != NULL) {
|
|
|
|
const gmio_stl_format_t stl_format = gmio_stl_get_format(&trsf->stream);
|
|
|
|
|
|
|
|
switch (stl_format) {
|
2015-04-02 16:58:10 +08:00
|
|
|
case GMIO_STL_FORMAT_ASCII: {
|
2015-03-30 15:30:55 +08:00
|
|
|
error = gmio_stla_read(trsf, creator);
|
2015-03-24 01:21:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-04-02 16:58:10 +08:00
|
|
|
case GMIO_STL_FORMAT_BINARY_BE: {
|
2015-04-02 15:45:02 +08:00
|
|
|
error = gmio_stlb_read(trsf, creator, GMIO_ENDIANNESS_BIG);
|
2015-03-24 01:21:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-04-02 16:58:10 +08:00
|
|
|
case GMIO_STL_FORMAT_BINARY_LE: {
|
2015-04-02 15:45:02 +08:00
|
|
|
error = gmio_stlb_read(trsf, creator, GMIO_ENDIANNESS_LITTLE);
|
2015-03-24 01:21:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-04-02 16:58:10 +08:00
|
|
|
case GMIO_STL_FORMAT_UNKNOWN: {
|
2015-04-02 16:04:24 +08:00
|
|
|
error = GMIO_STL_ERROR_UNKNOWN_FORMAT;
|
2015-03-24 01:21:04 +08:00
|
|
|
}
|
|
|
|
} /* end switch() */
|
|
|
|
}
|
|
|
|
else {
|
2015-04-02 16:04:24 +08:00
|
|
|
error = GMIO_ERROR_NULL_TRANSFER;
|
2015-03-24 01:21:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|