gmio_stl: cache add/get triangle function pointers
This commit is contained in:
parent
83725f4201
commit
a66370a76a
40
src/gmio_stl/internal/stl_funptr_typedefs.h
Normal file
40
src/gmio_stl/internal/stl_funptr_typedefs.h
Normal file
@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
** gmio
|
||||
** Copyright Fougue (2 Mar. 2015)
|
||||
** contact@fougue.pro
|
||||
**
|
||||
** 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
|
||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef GMIO_INTERNAL_STL_FUNPTR_TYPEDEFS_H
|
||||
#define GMIO_INTERNAL_STL_FUNPTR_TYPEDEFS_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../stl_mesh.h"
|
||||
#include "../stl_mesh_creator.h"
|
||||
|
||||
/* gmio_stl_triangle */
|
||||
typedef void (*gmio_stl_triangle_func_fix_endian_t)(gmio_stl_triangle_t*);
|
||||
|
||||
/* gmio_stl_mesh */
|
||||
typedef void (*gmio_stl_mesh_func_get_triangle_t)(
|
||||
const void*, uint32_t, gmio_stl_triangle_t*);
|
||||
|
||||
/* gmio_stl_mesh_creator */
|
||||
typedef void (*gmio_stl_mesh_creator_func_ascii_begin_solid_t)(
|
||||
void*, size_t, const char*);
|
||||
typedef void (*gmio_stl_mesh_creator_func_binary_begin_solid_t)(
|
||||
void*, uint32_t, const gmio_stlb_header_t*);
|
||||
typedef void (*gmio_stl_mesh_creator_func_add_triangle_t)(
|
||||
void*, uint32_t, const gmio_stl_triangle_t*);
|
||||
typedef void (*gmio_stl_mesh_creator_func_end_solid_t)(void*);
|
||||
|
||||
#endif /* GMIO_INTERNAL_STL_FUNPTR_TYPEDEFS_H */
|
@ -18,6 +18,8 @@
|
||||
#ifndef GMIO_INTERNAL_STL_RW_COMMON_H
|
||||
#define GMIO_INTERNAL_STL_RW_COMMON_H
|
||||
|
||||
#include "stl_funptr_typedefs.h"
|
||||
|
||||
#include "../../gmio_core/global.h"
|
||||
#include "../../gmio_core/endian.h"
|
||||
#include "../../gmio_core/transfer.h"
|
||||
@ -28,7 +30,7 @@ struct gmio_stlb_readwrite_helper
|
||||
{
|
||||
uint32_t facet_count;
|
||||
uint32_t i_facet_offset;
|
||||
void (*func_fix_endian)(gmio_stl_triangle_t* tri);
|
||||
gmio_stl_triangle_func_fix_endian_t func_fix_endian;
|
||||
};
|
||||
typedef struct gmio_stlb_readwrite_helper gmio_stlb_readwrite_helper_t;
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "stla_write.h"
|
||||
|
||||
#include "stl_funptr_typedefs.h"
|
||||
#include "stl_rw_common.h"
|
||||
#include "../stl_error.h"
|
||||
|
||||
@ -190,6 +191,9 @@ int gmio_stla_write(
|
||||
ifacet < total_facet_count && gmio_no_error(error);
|
||||
ifacet += buffer_facet_count)
|
||||
{
|
||||
const gmio_stl_mesh_func_get_triangle_t func_get_triangle =
|
||||
mesh->func_get_triangle;
|
||||
const void* mesh_cookie = mesh->cookie;
|
||||
const uint32_t clamped_facet_count =
|
||||
GMIO_MIN(ifacet + buffer_facet_count, total_facet_count);
|
||||
gmio_stl_triangle_t tri;
|
||||
@ -203,7 +207,7 @@ int gmio_stla_write(
|
||||
ibuffer_facet < clamped_facet_count;
|
||||
++ibuffer_facet)
|
||||
{
|
||||
mesh->func_get_triangle(mesh->cookie, ibuffer_facet, &tri);
|
||||
func_get_triangle(mesh_cookie, ibuffer_facet, &tri);
|
||||
buffc = gmio_write_string(buffc, "facet normal ");
|
||||
buffc = gmio_write_coords(buffc, coords_format, &tri.normal);
|
||||
buffc = gmio_write_eol(buffc);
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "stlb_write.h"
|
||||
|
||||
#include "stl_funptr_typedefs.h"
|
||||
#include "stl_rw_common.h"
|
||||
#include "stlb_byte_swap.h"
|
||||
#include "../stl_error.h"
|
||||
@ -42,25 +43,26 @@ static void gmio_stlb_write_facets(
|
||||
{
|
||||
const uint32_t facet_count = wparams->facet_count;
|
||||
const uint32_t i_facet_offset = wparams->i_facet_offset;
|
||||
const gmio_stl_triangle_func_fix_endian_t func_fix_endian =
|
||||
wparams->func_fix_endian;
|
||||
const gmio_stl_mesh_func_get_triangle_t func_get_triangle =
|
||||
mesh != NULL ? mesh->func_get_triangle : NULL;
|
||||
const void* cookie = mesh->cookie;
|
||||
gmio_stl_triangle_t triangle;
|
||||
uint32_t mblock_offset = 0;
|
||||
uint32_t i_facet = 0;
|
||||
|
||||
if (mesh == NULL || mesh->func_get_triangle == NULL)
|
||||
if (func_get_triangle == NULL)
|
||||
return;
|
||||
|
||||
triangle.attribute_byte_count = 0;
|
||||
for (i_facet = i_facet_offset;
|
||||
i_facet < (i_facet_offset + facet_count);
|
||||
++i_facet)
|
||||
{
|
||||
mesh->func_get_triangle(mesh->cookie, i_facet, &triangle);
|
||||
for (i_facet = 0; i_facet < facet_count; ++i_facet) {
|
||||
func_get_triangle(cookie, i_facet_offset + i_facet, &triangle);
|
||||
|
||||
if (wparams->func_fix_endian != NULL)
|
||||
wparams->func_fix_endian(&triangle);
|
||||
if (func_fix_endian != NULL)
|
||||
func_fix_endian(&triangle);
|
||||
|
||||
write_triangle_memcpy(&triangle, mblock + mblock_offset);
|
||||
|
||||
mblock_offset += GMIO_STLB_TRIANGLE_RAWSIZE;
|
||||
} /* end for */
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "stl_error.h"
|
||||
#include "internal/helper_stl_mesh_creator.h"
|
||||
#include "internal/stl_funptr_typedefs.h"
|
||||
#include "internal/stl_rw_common.h"
|
||||
|
||||
#include "../gmio_core/error.h"
|
||||
@ -473,13 +474,17 @@ static void parse_facet(
|
||||
|
||||
static void parse_facets(gmio_stla_parse_data_t* data)
|
||||
{
|
||||
const gmio_stl_mesh_creator_func_add_triangle_t func_add_triangle =
|
||||
data->creator->func_add_triangle;
|
||||
void* creator_cookie = data->creator->cookie;
|
||||
uint32_t i_facet = 0;
|
||||
gmio_stl_triangle_t facet;
|
||||
|
||||
facet.attribute_byte_count = 0;
|
||||
while (data->token == FACET_token && parsing_can_continue(data)) {
|
||||
parse_facet(data, &facet);
|
||||
gmio_stl_mesh_creator_add_triangle(data->creator, i_facet, &facet);
|
||||
if (func_add_triangle != NULL)
|
||||
func_add_triangle(creator_cookie, i_facet, &facet);
|
||||
++i_facet;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "stl_error.h"
|
||||
#include "internal/helper_stl_mesh_creator.h"
|
||||
#include "internal/stl_funptr_typedefs.h"
|
||||
#include "internal/stl_rw_common.h"
|
||||
#include "internal/stlb_byte_swap.h"
|
||||
|
||||
@ -37,11 +38,6 @@ GMIO_INLINE void read_triangle_memcpy(
|
||||
memcpy(triangle, buffer, GMIO_STLB_TRIANGLE_RAWSIZE);
|
||||
}
|
||||
|
||||
typedef void (*gmio_stl_func_fix_endian_t)(gmio_stl_triangle_t*);
|
||||
|
||||
typedef void (*gmio_stl_func_add_triangle_t)(
|
||||
void*, uint32_t, const gmio_stl_triangle_t*);
|
||||
|
||||
static void gmio_stlb_read_facets(
|
||||
gmio_stl_mesh_creator_t* creator,
|
||||
const uint8_t* buffer,
|
||||
@ -49,8 +45,9 @@ static void gmio_stlb_read_facets(
|
||||
{
|
||||
const uint32_t facet_count = rparams->facet_count;
|
||||
const uint32_t i_facet_offset = rparams->i_facet_offset;
|
||||
const gmio_stl_func_fix_endian_t func_fix_endian = rparams->func_fix_endian;
|
||||
const gmio_stl_func_add_triangle_t func_add_triangle =
|
||||
const gmio_stl_triangle_func_fix_endian_t func_fix_endian =
|
||||
rparams->func_fix_endian;
|
||||
const gmio_stl_mesh_creator_func_add_triangle_t func_add_triangle =
|
||||
creator != NULL ? creator->func_add_triangle : NULL;
|
||||
void* cookie = creator->cookie;
|
||||
gmio_stl_triangle_t triangle;
|
||||
|
Loading…
Reference in New Issue
Block a user