Skip to content

Commit

Permalink
Turn module code into C (which it almost was already) to
Browse files Browse the repository at this point in the history
work around the issue of using both C and C++ sources
of building a Python extension
  • Loading branch information
Paul Melis committed Aug 20, 2019
1 parent ce91cc2 commit 4276e74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 11 additions & 11 deletions readply.cpp → readply.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
#include <Python.h>
#include <numpy/arrayobject.h>
#include <rply.h>
#include <cstdio>
#include <cassert>
#include <stdio.h>
#include <assert.h>

#ifdef _MSC_VER
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <cstdint>
#include <stdint.h>
#endif

//#define DEBUG
Expand Down Expand Up @@ -206,7 +206,7 @@ face_cb(p_ply_argument argument)

if (next_face_element_index == face_indices_size)
{
face_indices_size = int(face_indices_size * 1.1);
face_indices_size = (int)(face_indices_size * 1.1);
faces = (uint32_t*) realloc(faces, face_indices_size*sizeof(uint32_t));
if (faces == NULL)
{
Expand Down Expand Up @@ -288,9 +288,9 @@ readply(PyObject* self, PyObject* args, PyObject *kwds)

// Set optional per-vertex callbacks

bool have_vertex_colors = false;
bool have_vertex_normals = false;
bool have_vertex_texcoords = false; // Either s,t or u,v sets will be used, but not both
int have_vertex_colors = 0;
int have_vertex_normals = 0;
int have_vertex_texcoords = 0; // Either s,t or u,v sets will be used, but not both

p_ply_property prop;
e_ply_type ptype, plength_type, pvalue_type;
Expand All @@ -308,7 +308,7 @@ readply(PyObject* self, PyObject* args, PyObject *kwds)
{
// Assumes green and blue properties are also available
// XXX is there ever an alpha value?
have_vertex_colors = true;
have_vertex_colors = 1;

if (ptype == PLY_UCHAR)
vertex_color_scale_factor = 1.0f / 255;
Expand All @@ -324,7 +324,7 @@ readply(PyObject* self, PyObject* args, PyObject *kwds)
else if (strcmp(name, "nx") == 0)
{
// Assumes ny and nz properties are also available
have_vertex_normals = true;
have_vertex_normals = 1;

ply_set_read_cb(ply, "vertex", "nx", vertex_normal_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "ny", vertex_normal_cb, NULL, 0);
Expand All @@ -333,15 +333,15 @@ readply(PyObject* self, PyObject* args, PyObject *kwds)
else if (strcmp(name, "s") == 0 && !have_vertex_texcoords)
{
// Assumes t property is also available
have_vertex_texcoords = true;
have_vertex_texcoords = 1;

ply_set_read_cb(ply, "vertex", "s", vertex_texcoord_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "t", vertex_texcoord_cb, NULL, 1);
}
else if (strcmp(name, "u") == 0 && !have_vertex_texcoords)
{
// Assumes v property is also available
have_vertex_texcoords = true;
have_vertex_texcoords = 1;

ply_set_read_cb(ply, "vertex", "u", vertex_texcoord_cb, NULL, 0);
ply_set_read_cb(ply, "vertex", "v", vertex_texcoord_cb, NULL, 1);
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

module1 = Extension('readply',
include_dirs = ['./rply', numpy.get_include()],
sources = ['readply.cpp', 'rply/rply.c'],
extra_compile_args = ['-std=c++11']
sources = ['readply.c', 'rply/rply.c']
)

setup(
Expand Down

0 comments on commit 4276e74

Please sign in to comment.