From b911132bd6be07c06d3ccb779087186972bc635e Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Wed, 10 Oct 2012 23:05:06 +1100 Subject: [PATCH 1/6] gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f5c40a99..4f90ed25 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ /bin /CMakeFiles Makefile + +partio.build + +src/doc/Doxyfile From fbce9f69f4f24bdc559306239e3b58cf12b509cf Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Wed, 10 Oct 2012 23:07:15 +1100 Subject: [PATCH 2/6] Added python API method to get all particle attribute data in a single python tuple This is a much faster way of getting the particle attribute data than iterating over particles in python using .get(). In my test case, loading a large point cloud for display in openGL, it's around a factor of 10 speedup. --- src/py/partio.i | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/py/partio.i b/src/py/partio.i index 2f3ab925..0218d5c8 100644 --- a/src/py/partio.i +++ b/src/py/partio.i @@ -235,6 +235,27 @@ public: return list; } + %feature("autodoc"); + %feature("docstring","Gets a single flattened tuple, containing attribute data for all particles"); + PyObject* getArray(const ParticleAttribute& attr) + { + unsigned int numparticles = $self->numParticles(); + PyObject* tuple=PyTuple_New(numparticles * attr.count); + + if(attr.type==Partio::INT){ + for(unsigned int i=0;idata(attr,i); + for(int k=0;kdata(attr,i); + for(int k=0;k Date: Sun, 14 Oct 2012 23:16:08 +1100 Subject: [PATCH 3/6] Initial framework for retrieving particle data as a numpy array --- src/py/partio.i | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/py/partio.i b/src/py/partio.i index 0218d5c8..9aff4714 100644 --- a/src/py/partio.i +++ b/src/py/partio.i @@ -37,8 +37,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. %module partio %include "std_string.i" - %{ +#include #include namespace Partio{ typedef uint64_t ParticleIndex; @@ -57,7 +57,10 @@ struct fixedFloatArray int i[16]; }; }; +%} +%init %{ +import_array(); %} // Particle Types @@ -235,6 +238,24 @@ public: return list; } + %feature("autodoc"); + %feature("docstring","Get"); + PyObject* getNDArray(const ParticleAttribute& attr) + { + unsigned int numparticles = $self->numParticles(); + + // 1 dimensional for now + npy_intp dims[1] = { numparticles*attr.count }; + PyObject *array = PyArray_SimpleNew(1, dims, NPY_CFLOAT); + + if (!array) { + PyErr_SetString(PyExc_TypeError,"Unable to create array"); + return NULL; + } + + return PyArray_Return((PyArrayObject *)array); + } + %feature("autodoc"); %feature("docstring","Gets a single flattened tuple, containing attribute data for all particles"); PyObject* getArray(const ParticleAttribute& attr) From 6c8669b5fc5b270f08e7394411148324b0924705 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Sun, 14 Oct 2012 23:16:55 +1100 Subject: [PATCH 4/6] gitignore --- .gitignore | 27 ----------- CMakeLists.txt | 106 ------------------------------------------ src/py/CMakeLists.txt | 67 -------------------------- 3 files changed, 200 deletions(-) delete mode 100644 .gitignore delete mode 100644 CMakeLists.txt delete mode 100644 src/py/CMakeLists.txt diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 4f90ed25..00000000 --- a/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -/.sconsign.dblite -/kbuild.* -/src/doc/doc -/Linux-* -/Darwin-* -/build -*~ -*.o -/*.kdev* -*.cmake -*.txt -*.make -*.marks -*.includecache -*.internal -*.kdev4 -*.bin -*.check_cache -*.out -*.log -/bin -/CMakeFiles -Makefile - -partio.build - -src/doc/Doxyfile diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index e331c9c2..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,106 +0,0 @@ -# PARTIO SOFTWARE -# Copyright 2010 Disney Enterprises, Inc. All rights reserved -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation -# Studios" or the names of its contributors may NOT be used to -# endorse or promote products derived from this software without -# specific prior written permission from Walt Disney Pictures. -# -# Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND -# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, -# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. -# IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -## CMake compatibility issues: don't modify this, please! -CMAKE_MINIMUM_REQUIRED( VERSION 2.4.6 ) -MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY) -## allow more human readable "if then else" constructs -SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE ) -## Use verbose make file -SET ( CMAKE_VERBOSE_MAKEFILE TRUE ) - - - -## project name & version -PROJECT( partio ) -SET( ${PROJECT_NAME}_MAJOR_VERSION 0 ) -SET( ${PROJECT_NAME}_MINOR_VERSION 1 ) -SET( ${PROJECT_NAME}_PATCH_LEVEL 0 ) - -# output executable and library path -SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) -SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) - -## Setup platform specific helper defines build variants -IF(WIN32) - ADD_DEFINITIONS (-DPARTIO_WIN32) -ELSE(WIN32) - ADD_DEFINITIONS (-Wextra -Wno-unused-parameter) - SET( CMAKE_CXX_FLAGS "-fPIC") -ENDIF(WIN32) - -## Choose build options -# Disney specific method of choosing variant -IF("$ENV{FLAVOR}" STREQUAL "optimize") - SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "type of build" FORCE) -ENDIF("$ENV{FLAVOR}" STREQUAL "optimize") -IF("$ENV{FLAVOR}" STREQUAL "debug") - SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "type of build" FORCE) -ENDIF("$ENV{FLAVOR}" STREQUAL "debug") -# Set to release if nothing else defined -IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE "Release" CACHE STRING - "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." - FORCE) -ENDIF(NOT CMAKE_BUILD_TYPE) - -## Set install location -EXECUTE_PROCESS(COMMAND sh -c "echo `uname`-`uname -r | cut -d'-' -f1`-`uname -m`" OUTPUT_VARIABLE VARIANT_DIRECTORY OUTPUT_STRIP_TRAILING_WHITESPACE) -#EXECUTE_PROCESS(COMMAND uname OUTPUT_VARIABLE VARIANT_DIRECTORY OUTPUT_STRIP_TRAILING_WHITESPACE) -SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${VARIANT_DIRECTORY}") - -## Search for useful libraries -find_package(GLUT REQUIRED) -find_package(OpenGL REQUIRED) -find_package(ZLIB) -IF(ZLIB_FOUND) - ADD_DEFINITIONS (-DPARTIO_USE_ZLIB) - INCLUDE_DIRECTORIES ( ${ZLIB_INCLUDE_DIR} ) -ELSE(ZLIB_FOUND) - SET (ZLIB_LIBRARY "") -ENDIF(ZLIB_FOUND) - -## Make modules able to see partio library -# Setup environment variable to link partio -SET( PARTIO_LIBRARIES ${ZLIB_LIBRARY} partio ) -# make it so partio can be found -INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/lib ) - -## Traverse subdirectories -ADD_SUBDIRECTORY (src/lib) -ADD_SUBDIRECTORY (src/tools) -ADD_SUBDIRECTORY (src/py) -ADD_SUBDIRECTORY (src/tests) -ADD_SUBDIRECTORY (src/doc) - - diff --git a/src/py/CMakeLists.txt b/src/py/CMakeLists.txt deleted file mode 100644 index 7275ca5e..00000000 --- a/src/py/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -# PARTIO SOFTWARE -# Copyright 2010 Disney Enterprises, Inc. All rights reserved -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation -# Studios" or the names of its contributors may NOT be used to -# endorse or promote products derived from this software without -# specific prior written permission from Walt Disney Pictures. -# -# Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND -# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, -# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. -# IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - - - -FIND_PACKAGE(SWIG) -IF(SWIG_FOUND) -FIND_PACKAGE(PythonLibs) -IF(PYTHONLIBS_FOUND) - -INCLUDE(${SWIG_USE_FILE}) - -EXECUTE_PROCESS( COMMAND python -c "import sys;print"%s.%s"%sys.version_info[0:2]" OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) - - -INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - -SET(CMAKE_SWIG_FLAGS "") - -# setup output path -SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/py) -SET(CMAKE_SWIG_OUTDIR ${PROJECT_BINARY_DIR}/py) - -SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES CPLUSPLUS ON) -SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES SWIG_FLAGS "-includeall") -SWIG_ADD_MODULE(partio python partio.i) -SWIG_LINK_LIBRARIES(partio ${PYTHON_LIBRARIES} ${ZLIB_LIBRARY} partio) - -SET(PYTHON_DEST "lib64/python${PYTHON_VERSION}/site-packages" ) -INSTALL(TARGETS _partio DESTINATION ${PYTHON_DEST}) -INSTALL(FILES ${CMAKE_BINARY_DIR}/${outdir}/src/py/partio.py DESTINATION ${PYTHON_DEST}) - -ENDIF(PYTHONLIBS_FOUND) -ENDIF(SWIG_FOUND) - From 628e1fde06746ad0628137508950edf2ef8db557 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Mon, 15 Oct 2012 08:48:44 +1100 Subject: [PATCH 5/6] Initial code to fill data to numpy array --- src/py/partio.i | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/py/partio.i b/src/py/partio.i index 9aff4714..9f487b0d 100644 --- a/src/py/partio.i +++ b/src/py/partio.i @@ -253,6 +253,37 @@ public: return NULL; } + + /* + PyArrayIterObject *iter; + iter = (PyArrayIterObject *)PyArray_IterNew(array); + //if (iter == NULL) goto fail; // Assume fail has clean-up code + + const float* p=$self->data(attr,i); + while (iter->index < iter->size) { + // do something with the data at it->dataptr + + PyArray_ITER_NEXT(it); + } + */ + + + npy_intp size; + unsigned int i=0; + float *dptr; // could make this any variable type + size = PyArray_SIZE(array); + dptr = (float *)PyArray_DATA(array); + //while(size--) { + for (int j=0;jdata(attr,i); + for(int k=0;k Date: Tue, 16 Oct 2012 08:55:01 +1100 Subject: [PATCH 6/6] Cleaned up numpy python bindings --- src/py/partio.i | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/py/partio.i b/src/py/partio.i index 9f487b0d..db4e9d25 100644 --- a/src/py/partio.i +++ b/src/py/partio.i @@ -246,36 +246,20 @@ public: // 1 dimensional for now npy_intp dims[1] = { numparticles*attr.count }; - PyObject *array = PyArray_SimpleNew(1, dims, NPY_CFLOAT); + PyObject *array = PyArray_SimpleNew(1, dims, NPY_FLOAT); if (!array) { PyErr_SetString(PyExc_TypeError,"Unable to create array"); return NULL; } - - /* - PyArrayIterObject *iter; - iter = (PyArrayIterObject *)PyArray_IterNew(array); - //if (iter == NULL) goto fail; // Assume fail has clean-up code - - const float* p=$self->data(attr,i); - while (iter->index < iter->size) { - // do something with the data at it->dataptr - - PyArray_ITER_NEXT(it); - } - */ - - npy_intp size; unsigned int i=0; - float *dptr; // could make this any variable type + float *dptr; size = PyArray_SIZE(array); dptr = (float *)PyArray_DATA(array); - //while(size--) { + for (int j=0;jdata(attr,i); for(int k=0;k