Commit 120c8aec authored by Méso Star's avatar Méso Star

First draft of the S3DSTL API

Implement the management functions of the S3DSTL device.
parents
.gitignore
CMakeCache.txt
CMakeFiles
Makefile
tmp
[Bb]uild*
*.sw[po]
*.[ao]
*~
tags
This diff is collapsed.
This diff is collapsed.
# Star 3D shapes from STereo Lithography geometries
This library creates *Star-3D* shapes from geometries saved in the stl
fileformats.
## How to build
This library depends on the
[Star-STL](https://gitlab.com/meso-star/star-stl/#tab-readme) library to load
Stereo Lithography files and on the
[Star-3D](https://gitlab.com/meso-star/star-3d/#tab-readme) library to define
the in-core representation of the loaded shapes. It also uses
[CMake](http://www.cmake.org) and the
[RCMake](https://gitlab.com/vaplv/rcmake/#tab-readme) package to build and
depends on the [RSys](https://gitlab.com/vaplv/rsys/#tab-readme) library.
First ensure that CMake is installed on your system. Then install the RCMake
package as well as the RSys, STL and Star-3D libraries. Finally generate the
project from the `cmake/CMakeLists.txt` file by appending to the
`CMAKE_PREFIX_PATH` variable the install directories of the previously defined
dependencies. The generated project can be edited, built, tested and installed
as any CMake project.
## License
*Star-3DSTL* is Copyright (C) |Meso|Star> 2015-2016 (<contact@meso-star.com>).
It is a free software released under the [OSI](http://opensource.org)-approved
CeCILL license. You are welcome to redistribute it under certain conditions;
refer to the COPYING files for details.
# Copyright (C) |Meso|Star> 2015-2016 (contact@meso-star.com)
#
# This software is governed by the CeCILL 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
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
cmake_minimum_required(VERSION 2.8)
project(star-3dstl C)
enable_testing()
option(NO_TEST "Do not compile the test pograms" OFF)
set(S3DSTL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
################################################################################
# Dependencies
################################################################################
find_package(RCMake REQUIRED)
find_package(RSys 0.3 REQUIRED)
find_package(Star3D 0.3 REQUIRED)
find_package(StarSTL 0.3 REQUIRED)
include_directories(
${RSys_INCLUDE_DIR}
${Star3D_INCLUDE_DIR}
${StarSTL_INCLUDE_DIR})
set(CMAKE_MODULE_PATH ${RCMAKE_SOURCE_DIR})
include(rcmake)
include(rcmake_runtime)
rcmake_append_runtime_dirs(_runtime_dirs RSys Star3D StarSTL)
################################################################################
# Define targets
################################################################################
set(S3DSTL_FILES_INC_API s3dstl.h)
set(S3DSTL_FILES_SRC s3dstl.c)
set(S3DSTL_FILES_DOC COPYING.fr COPYING.en README.md)
rcmake_prepend_path(S3DSTL_FILES_SRC ${S3DSTL_SOURCE_DIR})
rcmake_prepend_path(S3DSTL_FILES_INC_API ${S3DSTL_SOURCE_DIR})
rcmake_prepend_path(S3DSTL_FILES_DOC ${S3DSTL_SOURCE_DIR}/../)
add_library(s3dstl SHARED ${S3DSTL_FILES_SRC} ${S3DSTL_FILES_INC_API})
target_link_libraries(s3dstl RSys Star3D StarSTL)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 3)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set_target_properties(s3dstl PROPERTIES
DEFINE_SYMBOL S3DSTL_SHARED_BUILD
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR})
rcmake_setup_devel(s3dstl Star3DSTL ${VERSION} star/s3dstl_version.h)
################################################################################
# Define tests
################################################################################
if(NOT NO_TEST)
# add_executable(test_sstl ${SSTL_SOURCE_DIR}/test_sstl.c)
# target_link_libraries(test_sstl sstl)
# add_test(test_sstl test_sstl)
# rcmake_set_test_runtime_dirs(test_sstl _runtime_dirs)
endif(NOT NO_TEST)
################################################################################
# Install directories
################################################################################
install(TARGETS s3dstl
ARCHIVE DESTINATION bin
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(FILES ${S3DSTL_FILES_INC_API} DESTINATION include/star)
install(FILES ${S3DSTL_FILES_DOC} DESTINATION doc/s3dstl)
/* Copyright (C) |Meso|Star> 2015-2016 (contact@meso-star.com)
*
* This software is governed by the CeCILL 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
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms. */
#include "s3dstl.h"
#include <rsys/logger.h>
#include <rsys/mem_allocator.h>
#include <rsys/ref_count.h>
#include <star/s3d.h>
#include <star/sstl.h>
struct s3dstl {
struct s3d_device* s3d;
struct s3d_shape* shape;
struct sstl* sstl;
struct logger* logger;
struct mem_allocator* allocator;
int verbose;
ref_T ref;
};
/*******************************************************************************
* Helper functions
******************************************************************************/
static void
release_s3dstl(ref_T* ref)
{
struct s3dstl* s3dstl;
ASSERT(ref);
s3dstl = CONTAINER_OF(ref, struct s3dstl, ref);
if(s3dstl->sstl) SSTL(ref_put(s3dstl->sstl));
if(s3dstl->s3d) S3D(device_ref_put(s3dstl->s3d));
if(s3dstl->shape) S3D(shape_ref_put(s3dstl->shape));
MEM_RM(s3dstl->allocator, s3dstl);
}
/*******************************************************************************
* Exported functions
******************************************************************************/
res_T
s3dstl_create
(struct logger* log,
struct mem_allocator* allocator,
struct sstl* sstl,
struct s3d_device* s3d,
const int verbose,
struct s3dstl** out_s3dstl)
{
struct s3dstl* s3dstl = NULL;
struct mem_allocator* mem_allocator;
struct logger* logger = NULL;
res_T res = RES_OK;
if(!s3d || !out_s3dstl) {
res = RES_BAD_ARG;
goto error;
}
mem_allocator = allocator ? allocator : &mem_default_allocator;
logger = log ? log : LOGGER_DEFAULT;
s3dstl = MEM_CALLOC(allocator, 1, sizeof(struct s3dstl));
if(!s3dstl) {
if(verbose) {
logger_print(logger, LOG_ERROR,
"Couldn't allocate the Star-3DSTL device.\n");
}
res = RES_MEM_ERR;
goto error;
}
ref_init(&s3dstl->ref);
s3dstl->allocator = mem_allocator;
s3dstl->logger = logger;
s3dstl->verbose = verbose;
S3D(device_ref_get(s3d));
s3dstl->s3d = s3d;
if(sstl) {
SSTL(ref_get(sstl));
s3dstl->sstl = sstl;
} else {
res = sstl_create(logger, allocator, verbose, &s3dstl->sstl);
if(res != RES_OK) {
if(verbose) {
logger_print(logger, LOG_ERROR,
"Couldn't create the loader of the STL fileformat.\n");
}
goto error;
}
}
exit:
if(out_s3dstl) *out_s3dstl = s3dstl;
return res;
error:
if(s3dstl) {
S3DSTL(ref_put(s3dstl));
s3dstl = NULL;
}
goto exit;
}
res_T
s3dstl_ref_get(struct s3dstl* s3dstl)
{
if(!s3dstl) return RES_BAD_ARG;
ref_get(&s3dstl->ref);
return RES_OK;
}
res_T
s3dstl_ref_put(struct s3dstl* s3dstl)
{
if(!s3dstl) return RES_BAD_ARG;
ref_put(&s3dstl->ref, release_s3dstl);
return RES_OK;
}
res_T
s3dstl_get_sstl(struct s3dstl* s3dstl, struct sstl** sstl)
{
if(!s3dstl || !sstl) return RES_BAD_ARG;
*sstl = s3dstl->sstl;
return RES_OK;
}
/* Copyright (C) |Meso|Star> 2015-2016 (contact@meso-star.com)
*
* This software is governed by the CeCILL 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
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms. */
#ifndef S3DSTL_H
#define S3DSTL_H
#include <rsys/rsys.h>
/* Library symbol management */
#if defined(S3DSTL_SHARED_BUILD)
#define S3DSTL_API extern EXPORT_SYM /* Build shared library */
#elif defined(S3DSTL_STATUC) /* Use/build statuc library */
#define S3DSTL_API extern LOCAL_SYM
#else /* Use shared library */
#define S3DSTL_API extern IMPORT_SYM
#endif
/* Helper macro that asserts if the invocation of the s3dstl function `Func'
* returns an error. One should use this macro on s3dstl function calls for which
* no explicit error checking is performed. */
#ifndef NDEBUG
#define S3DSTL(Func) ASSERT(s3dstl_ ## Func == RES_OK)
#else
#define S3DSTL(Func) s3dstl_ ## Func
#endif
/* Forward declaration of external types */
struct logger;
struct mem_allocator;
struct s3d_device;
struct s3d_shape;
struct sstl;
/* Forward declaration of opaque data types */
struct s3dstl;
/*******************************************************************************
* Star-3DSTL API
******************************************************************************/
BEGIN_DECLS
S3DSTL_API res_T
s3dstl_create
(struct logger* logger, /* May be NULL <=> use default logger */
struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
struct sstl* loader_sstl, /* May be NULL <=> Internally create the loader */
struct s3d_device* s3d,
const int verbose, /* Verbosity level */
struct s3dstl** s3dstl);
S3DSTL_API res_T
s3dstl_ref_get
(struct s3dstl* s3dstl);
S3DSTL_API res_T
s3dstl_ref_put
(struct s3dstl* s3dstl);
S3DSTL_API res_T
s3dstl_get_sstl
(struct s3dstl* s3dstl,
struct sstl** sstl);
S3DSTL_API res_T
s3dstl_load
(struct s3dstl* s3dstl,
const char* filename);
S3DSTL_API res_T
s3dstl_load_stream
(struct s3dstl* s3dstl,
FILE* file);
/* Remove the loaded shape */
S3DSTL_API res_T
s3dstl_clear
(struct s3dstl* s3dstl);
S3DSTL_API res_T
s3dstl_get_shape
(struct s3dstl* s3dstl,
struct s3d_shape** shape);
END_DECLS
#endif /* S3DSTL_H */
Markdown is supported
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