├── .gitignore ├── CMakeLists.txt ├── Makefile ├── README.md └── src ├── Makefile ├── data ├── scatter.bgeo ├── test.bgeo ├── test.geo └── test.pdb ├── doc ├── CMakeLists.txt ├── Doxyfile.in ├── cpptut.txt ├── figures │ └── circleFigure.png ├── license.txt ├── main.txt ├── partio.tex └── tutorial.txt ├── lib ├── CMakeLists.txt ├── Partio.h ├── PartioAttribute.h ├── PartioIterator.h ├── PartioSe.cpp ├── PartioSe.h ├── PartioVec3.h ├── core │ ├── KdTree.h │ ├── Mutex.h │ ├── Particle.cpp │ ├── ParticleCaching.cpp │ ├── ParticleCaching.h │ ├── ParticleHeaders.cpp │ ├── ParticleHeaders.h │ ├── ParticleSimple.cpp │ ├── ParticleSimple.h │ ├── ParticleSimpleInterleave.cpp │ └── ParticleSimpleInterleave.h └── io │ ├── BGEO.cpp │ ├── BIN.cpp │ ├── GEO.cpp │ ├── MC.cpp │ ├── PDA.cpp │ ├── PDB.cpp │ ├── PDC.cpp │ ├── PRT.cpp │ ├── PTC.cpp │ ├── PTS.cpp │ ├── ParticleIO.cpp │ ├── PartioEndian.h │ ├── RIB.cpp │ ├── ZIP.cpp │ ├── ZIP.h │ ├── half2float.h │ ├── pdb.h │ └── readers.h ├── py ├── CMakeLists.txt ├── example │ ├── circle.py │ └── listAttr.py └── partio.i ├── tests ├── CMakeLists.txt ├── Timer.h ├── makecircle.cpp ├── makeline.cpp ├── test.cpp ├── testcache.cpp ├── testclonecopy.cpp ├── testcluster.cpp ├── testiterator.cpp ├── testkdtree.cpp └── teststr.cpp └── tools ├── CMakeLists.txt ├── Camera.h ├── partattr.cpp ├── partconv.cpp ├── partconvert.cpp ├── partinfo.cpp ├── partview.cpp └── partview.h /.gitignore: -------------------------------------------------------------------------------- 1 | /.sconsign.dblite 2 | /build 3 | /bin 4 | /CMakeFiles 5 | /src/doc/doc 6 | /Makefile.config 7 | /Darwin-* 8 | /kbuild.* 9 | /*.kdev* 10 | /Linux-* 11 | *.o 12 | *.cmake 13 | *.txt 14 | *.make 15 | *.marks 16 | *.includecache 17 | *.internal 18 | *.kdev4 19 | *.bin 20 | *.check_cache 21 | *.out 22 | *.log 23 | *~ 24 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PARTIO SOFTWARE 2 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in 13 | # the documentation and/or other materials provided with the 14 | # distribution. 15 | # 16 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 17 | # Studios" or the names of its contributors may NOT be used to 18 | # endorse or promote products derived from this software without 19 | # specific prior written permission from Walt Disney Pictures. 20 | # 21 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 22 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 23 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 24 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | 34 | ## CMake compatibility issues: don't modify this, please! 35 | CMAKE_MINIMUM_REQUIRED( VERSION 2.4.6 ) 36 | MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY) 37 | ## allow more human readable "if then else" constructs 38 | SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE ) 39 | ## disable rpath when linking 40 | SET( CMAKE_SKIP_RPATH TRUE ) 41 | 42 | 43 | ## project name & version 44 | PROJECT( partio ) 45 | SET( ${PROJECT_NAME}_MAJOR_VERSION 0 ) 46 | SET( ${PROJECT_NAME}_MINOR_VERSION 1 ) 47 | SET( ${PROJECT_NAME}_PATCH_LEVEL 0 ) 48 | 49 | include(GNUInstallDirs) 50 | 51 | # PARTIO_SE_ENABLED enables SeExpr support 52 | option(PARTIO_SE_ENABLED "PARTIO_SE_ENABLED" false) 53 | 54 | ## Setup platform specific helper defines build variants 55 | IF(WIN32) 56 | ADD_DEFINITIONS (-DPARTIO_WIN32 -D_USE_MATH_DEFINES) 57 | ELSE(WIN32) 58 | ADD_DEFINITIONS (-Wextra -Wno-unused-parameter) 59 | SET( CMAKE_CXX_FLAGS "-fPIC") 60 | ENDIF(WIN32) 61 | 62 | ## Choose build options 63 | # Disney specific method of choosing variant 64 | IF("$ENV{FLAVOR}" STREQUAL "optimize") 65 | SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "type of build" FORCE) 66 | ENDIF("$ENV{FLAVOR}" STREQUAL "optimize") 67 | IF("$ENV{FLAVOR}" STREQUAL "debug") 68 | SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "type of build" FORCE) 69 | ENDIF("$ENV{FLAVOR}" STREQUAL "debug") 70 | # Set to release if nothing else defined 71 | IF(NOT CMAKE_BUILD_TYPE) 72 | SET(CMAKE_BUILD_TYPE "Release" CACHE STRING 73 | "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." 74 | FORCE) 75 | ENDIF(NOT CMAKE_BUILD_TYPE) 76 | 77 | ## Set install location 78 | IF (NOT DEFINED CMAKE_INSTALL_PREFIX) 79 | EXECUTE_PROCESS(COMMAND sh -c "echo `uname`-`uname -r | cut -d'-' -f1`-`uname -m`" OUTPUT_VARIABLE VARIANT_DIRECTORY OUTPUT_STRIP_TRAILING_WHITESPACE) 80 | SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${VARIANT_DIRECTORY}") 81 | ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX) 82 | 83 | ## Search for useful libraries 84 | find_package(GLUT REQUIRED) 85 | find_package(OpenGL REQUIRED) 86 | find_package(ZLIB) 87 | IF(ZLIB_FOUND) 88 | ADD_DEFINITIONS (-DPARTIO_USE_ZLIB) 89 | INCLUDE_DIRECTORIES ( ${ZLIB_INCLUDE_DIR} ) 90 | ELSE(ZLIB_FOUND) 91 | SET (ZLIB_LIBRARY "") 92 | ENDIF(ZLIB_FOUND) 93 | 94 | ## Make modules able to see partio library 95 | # Setup environment variable to link partio 96 | SET( PARTIO_LIBRARIES partio ${ZLIB_LIBRARY} ) 97 | 98 | # make it so partio can be found 99 | INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/lib ) 100 | 101 | if (${PARTIO_SE_ENABLED}) 102 | add_definitions(-DPARTIO_SE_ENABLED=1) 103 | SET(SEEXPR_BASE "c:/aselle/seexpr-inst" CACHE STRING "path to SeExpr") 104 | SET(SEEXPR_INCLUDE_PATH ${SEEXPR_BASE}/include) 105 | SET(SEEXPR_LIBDIR ${CMAKE_INSTALL_LIBDIR}) 106 | SET(SEEXPR_LINK_PATH ${SEEXPR_BASE}/${SEEXPR_LIBDIR}) 107 | SET(SEEXPR_LIBS "SeExpr") 108 | endif () 109 | 110 | 111 | ## Traverse subdirectories 112 | ADD_SUBDIRECTORY (src/lib) 113 | ADD_SUBDIRECTORY (src/tools) 114 | ADD_SUBDIRECTORY (src/py) 115 | ADD_SUBDIRECTORY (src/tests) 116 | ADD_SUBDIRECTORY (src/doc) 117 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env make 2 | SH ?= sh 3 | uname_S := $(shell $(SH) -c 'uname -s || echo kernel') 4 | uname_R := $(shell $(SH) -c 'uname -r | cut -d- -f1 || echo release') 5 | uname_M := $(shell $(SH) -c 'uname -m || echo machine') 6 | FLAVOR ?= optimize 7 | platformdir ?= $(uname_S)-$(uname_R)-$(uname_M)-$(FLAVOR) 8 | builddir ?= $(CURDIR)/build/$(platformdir) 9 | 10 | prefix ?= $(CURDIR)/$(platformdir) 11 | #DESTDIR = 12 | 13 | CMAKE_FLAGS = 14 | # Allow out-of-band customization 15 | -include Makefile.config 16 | 17 | ifdef V 18 | VERBOSE=1 19 | export VERBOSE 20 | endif 21 | 22 | # Installation location: prefix= 23 | CMAKE_FLAGS += -DCMAKE_INSTALL_PREFIX=$(prefix) 24 | 25 | # SeExpr v2 location: RP_SeExpr= 26 | ifdef RP_SeExpr 27 | CMAKE_FLAGS += -DSEEXPR_BASE=$(RP_SeExpr) 28 | CMAKE_FLAGS += -DPARTIO_SE_ENABLED=1 29 | endif 30 | 31 | # Extra cmake flags: CMAKE_EXTRA_FLAGS= 32 | ifdef CMAKE_EXTRA_FLAGS 33 | CMAKE_FLAGS += $(CMAKE_EXTRA_FLAGS) 34 | endif 35 | 36 | # The default target in this Makefile is... 37 | all:: 38 | 39 | install: all 40 | $(MAKE) -C $(builddir) DESTDIR=$(DESTDIR) install 41 | 42 | $(builddir)/stamp: 43 | mkdir -p $(builddir) 44 | cd $(builddir) && cmake $(CMAKE_FLAGS) ../.. 45 | touch $@ 46 | 47 | all:: $(builddir)/stamp 48 | $(MAKE) -C $(builddir) $(MAKEARGS) all 49 | 50 | clean: $(builddir)/stamp 51 | $(MAKE) -C $(builddir) $(MAKEARGS) clean 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Partio](https://www.disneyanimation.com/technology/partio.html) - A library for particle IO and manipulation 2 | ============================================================================================================= 3 | 4 | This is the initial source code release of partio a tool we used for particle 5 | reading/writing. It started out as an abstraction for the commonalities in 6 | particle models (i.e. accessing many attributes associated with an index or 7 | entity). 8 | 9 | Super impatient building guide 10 | ============================== 11 | 12 | # Install Location ~ adjust accordingly 13 | prefix=$HOME/local 14 | # Partio depends on SeExpr v2.11 15 | git clone https://github.com/wdas/seexpr.git 16 | pushd seexpr 17 | git checkout v2.11 18 | make -j prefix=$prefix install 19 | popd 20 | git clone https://github.com/wdas/partio.git 21 | cd partio 22 | make -j prefix=$prefix RP_SeExpr=$prefix install 23 | 24 | Getting Started 25 | =============== 26 | 27 | CMake is used to build the project, but we provide a top-level Makefile 28 | for convenience that takes care of all the steps. 29 | 30 | See the Makefile for the user-tweakable variables and corresponding 31 | cmake options. 32 | 33 | The typical usage for an installation into `/usr/local` 34 | with a temporary staging directory of `/tmp/stage` is: 35 | 36 | make DESTDIR=/tmp/stage RP_SeExpr=/usr/local prefix=/usr/local install 37 | 38 | SeExpr 39 | ====== 40 | Partio depends on SeExpr v2 (current `v2.11`). SeExpr v2 and v3 can co-exist, 41 | so you can have v2 for building partio installed alongside SeExpr v3+ (master). 42 | 43 | SeExpr is not strictly required. SeExpr support is disabled when `RP_SeExpr` 44 | is not specified to the Makefile. In CMake, the corresponding variables are 45 | `-DSEEXPR_BASE=` for the SeExpr location, and `-DPARTIO_SE_ENABLED=1` 46 | to enable the PartioSe class. 47 | 48 | Source code overview 49 | ==================== 50 | 51 | src/ 52 | lib/ Library code (public API in root) 53 | lib/core Core library (KDtree traversal, data representations) 54 | lib/io Input/Output (Different file formats) 55 | py/ SWIG based python bindings 56 | doc/ Doxygen documentation and (the start of) a manual 57 | tests/ Start of regression tests (I need more) 58 | tools/ Useful tools 59 | partconv 60 | partinfo 61 | partview 62 | 63 | Class Model 64 | ----------- 65 | 66 | The goal of the library is to abstract the particle interface from the data 67 | representation. That is why Partio represents particles using three classes that 68 | inherit and provide more functionality 69 | 70 | ParticlesInfo - Information about # of particles and attributes 71 | ParticlesData - Read only access to all particle data 72 | ParticlesDataMutable - Read/write access to all particle data 73 | 74 | The functions used to get particle access are these: 75 | 76 | readHeaders() 77 | returns ParticlesInfo 78 | reads only the minimum data necessary to get number of particles and 79 | attributes 80 | 81 | readCached() 82 | returns ParticlesData 83 | For multiple users in different threads using the same particle file 84 | ParticlesData 85 | 86 | create() and read() 87 | returns ParticlesDataMutable 88 | allows read/write access 89 | 90 | Behind the scenes you could implement these classes however you like. Headers 91 | only representation is called core/ParticleHeader.{h,cpp}. Simple 92 | non-interleaved attributes is core/ParticleSimple.{h,cpp}. 93 | 94 | Attribute Data Model 95 | -------------------- 96 | 97 | All particles have the same data attributes. They have the model that they are 98 | of three basic types with a count of how many scalar values they have. 99 | 100 | VECTOR[3] 101 | FLOAT[d] 102 | INT[d] 103 | 104 | VECTOR[3] and FLOAT[3] have the same data representations. 105 | VECTOR[4] is invalid however FLOAT[4] is valid as is FLOAT[1...infinity] 106 | 107 | This seems to encompass the most common file formats for particles 108 | 109 | 110 | Iterating 111 | --------- 112 | 113 | There are multiple ways to access data in the API. Here are 114 | some tips 115 | 116 | - Use SIMD functions when possible prefer dataAsFloat(),data(arrayOfIndices) as 117 | opposed to data(int singleIndex) which accesses multiple pieces of data at 118 | once 119 | 120 | - Cache ParticleAttributes for quick access instead of calling attributeInfo() 121 | over a loop of particles 122 | 123 | - Use iterators to do linear operations over all particles They are much more 124 | optimized than both data() and the dataAsFloat or 125 | 126 | 127 | Backends 128 | -------- 129 | 130 | Behind the scenes there are SimpleParticles, ParticleHeaders, and 131 | SimpleParticlesInterleaved. In the future I would like to write a disk-based 132 | cached back end that can dynamically only load the data that is necessary. 133 | create(), read() and readCached could be augmented to create different 134 | structures in these cases. 135 | 136 | Readers/Writers 137 | --------------- 138 | 139 | New readers and writers can be added in the io/ directory. You simply need to 140 | implement the interface ParticlesInfo, ParticlesData and ParticlesDataMutable 141 | (or as many as you need). Editing the io/readers.h to add prototypes and 142 | io/ParticleIO.cpp to add file extension bindings should be easy. 143 | 144 | 145 | - Andrew Selle, Walt Disney Animation Studios 146 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | CXX=g++ 2 | CXXFLAGS=-g -I/opt/local/include -fPIC 3 | LINKFLAGS= 4 | OBJS=ParticleSimple.o Particle.o DEBUG_PRINT.o \ 5 | reader/PDB.o reader/GEO.o reader/BGEO.o 6 | 7 | 8 | 9 | all: lib partinfo test 10 | lib: ${OBJS} 11 | ${CXX} ${LINKFLAGS} -shared -o libpapi.so ${OBJS} 12 | partinfo: lib partinfo.cpp 13 | ${CXX} ${LINKFLAGS} -o partinfo libpapi.so partinfo.cpp 14 | test: lib test.cpp 15 | ${CXX} ${LINKFLAGS} -o test libpapi.so test.cpp 16 | 17 | ParticleSimple.o: ParticleSimple.cpp ParticleSimple.h Particle.h 18 | Particle.o: Particle.cpp Particle.h 19 | test.o: test.cpp ParticleSimple.h Particle.h 20 | DEBUG_PRINT.o: DEBUG_PRINT.h DEBUG_PRINT.cpp 21 | reader/GEO.o: reader/GEO.cpp Particle.h ParticleSimple.h \ 22 | reader/../Particle.h 23 | reader/BGEO.o: reader/BGEO.cpp Particle.h ParticleSimple.h \ 24 | reader/../Particle.h reader/endian.h 25 | reader/PDB.o: reader/PDB.cpp Particle.h ParticleSimple.h \ 26 | reader/../Particle.h reader/pdb.h 27 | partinfo.o: partinfo.cpp Particle.h 28 | partconv.o: partconf.cpp Particle.h -------------------------------------------------------------------------------- /src/data/scatter.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redpawfx/partio/22ea26e08510a44094023a53a231b40dfe4e3b30/src/data/scatter.bgeo -------------------------------------------------------------------------------- /src/data/test.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redpawfx/partio/22ea26e08510a44094023a53a231b40dfe4e3b30/src/data/test.bgeo -------------------------------------------------------------------------------- /src/data/test.geo: -------------------------------------------------------------------------------- 1 | PGEOMETRY V5 2 | NPoints 5 NPrims 1 3 | NPointGroups 0 NPrimGroups 0 4 | NPointAttrib 2 NVertexAttrib 0 NPrimAttrib 1 NAttrib 0 5 | PointAttrib 6 | 7 | life 2 float 0 0 8 | id 1 int 0 9 | 0 0.1 0.2 1 (-1.2 10 0) 10 | 0.1 0.2 0.3 1 (-0.2 10 1) 11 | 0.2 0.3 0.4 1 (0.8 10 2) 12 | 0.3 0.4 0.5 1 (1.8 10 3) 13 | 0.4 0.5 0.6 1 (2.8 10 4) 14 | PrimitiveAttrib 15 | generator 1 index 1 papi 16 | Part 5 0 1 2 3 4 [0] 17 | beginExtra 18 | endExtra 19 | -------------------------------------------------------------------------------- /src/data/test.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/redpawfx/partio/22ea26e08510a44094023a53a231b40dfe4e3b30/src/data/test.pdb -------------------------------------------------------------------------------- /src/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PARTIO SOFTWARE 2 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in 13 | # the documentation and/or other materials provided with the 14 | # distribution. 15 | # 16 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 17 | # Studios" or the names of its contributors may NOT be used to 18 | # endorse or promote products derived from this software without 19 | # specific prior written permission from Walt Disney Pictures. 20 | # 21 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 22 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 23 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 24 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | 34 | find_package(Doxygen) 35 | 36 | IF(DOXYGEN_FOUND) 37 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) 38 | FILE(GLOB (DOCUMENTED_FILES ${CMAKE_PROJECT_DIR}/src/lib/*.h)) 39 | 40 | add_custom_command( 41 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doxygen.txt 42 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile >doxygen.txt 43 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 44 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) 45 | 46 | add_custom_target(doc ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doxygen.txt) 47 | add_dependencies(doc DOCUMENTED_FILES) 48 | 49 | INSTALL( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ DESTINATION ${CMAKE_INSTALL_DOCDIR} ) 50 | ENDIF(DOXYGEN_FOUND) 51 | -------------------------------------------------------------------------------- /src/doc/cpptut.txt: -------------------------------------------------------------------------------- 1 | /** \page cpptut C++ Tutorial 2 | 3 | Here is a simple example of some operations supported by particles. You may want 4 | to look at the includes demo applications and tools in the source tree to see 5 | more examples. 6 | 7 |

Intro

8 | 9 | The C++ API is easy to use. You just need to include 10 |
11 | #include 
12 | 
13 | Everything Partio related is in the Partio namespace. To read a particle file in 14 | and print the number of particles you could do: 15 |
16 | Partio::ParticlesDataMutable* data=Partio::read("test.bgeo");
17 | std::cout<<"Number of particles "<<data->numParticles()<<std::endl;
18 | 
19 | Now we could additionally print out the names of all attributes in the particle 20 | file as 21 |
22 | for(int i=0;i<data->numAttributes();i++){
23 |     Partio::ParticleAttribute attr;
24 |     data->attributeInfo(i,attr);
25 |     std::cout<<"attribute["<<i<<"] is "<<attr.name<<std::endl;
26 | }
27 | 
28 | Now we could convert the data into RenderMan ptc format as 29 |
30 | Partio::write("test.ptc",*data);
31 | 
32 | Whenever you are done with a particle set you need to release it as 33 |
34 | data->release();
35 | 
36 | 37 |

Simple processing

38 | 39 | Suppose we wanted to average all the positions in a particle file. We could do 40 | that by iterating over each particle and getting the position attribute value as 41 | follows: 42 |
43 | Partio::ParticleAttribute posAttr;
44 | if(!data->attributeInfo("position",attr)
45 |    || (attr.type != Partio::FLOAT && attr.type != Partio::VECTOR)
46 |    || attr.count != 3){
47 |    std::cerr<<"Failed to get proper position attribute"<<std::endl;
48 | }
49 | 
50 | float avg[3]={0,0,0};
51 | 
52 | 
53 | for(int i=0;i<data->numParticles();i++){
54 |     float *pos=data->data(posAttr,i);
55 |     for(int k=0;k<3;k++) avg[k]+=pos[k];
56 | }
57 | for(int k=0;k<3;k++) pos[k]/=data->numParticles();
58 | std::cerr<<"avg "<<pos[0]<<" "<<pos[1]<<" "<<pos[2]<
60 | 
61 | 
62 | */
63 | 


--------------------------------------------------------------------------------
/src/doc/figures/circleFigure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/redpawfx/partio/22ea26e08510a44094023a53a231b40dfe4e3b30/src/doc/figures/circleFigure.png


--------------------------------------------------------------------------------
/src/doc/license.txt:
--------------------------------------------------------------------------------
 1 | 
 2 |  PARTIO SOFTWARE
 3 |  Copyright 2010-2011 Disney Enterprises, Inc. All rights reserved
 4 |  
 5 |  Redistribution and use in source and binary forms, with or without
 6 |  modification, are permitted provided that the following conditions are
 7 |  met:
 8 |  
 9 |  * Redistributions of source code must retain the above copyright
10 |  notice, this list of conditions and the following disclaimer.
11 |  
12 |  * Redistributions in binary form must reproduce the above copyright
13 |  notice, this list of conditions and the following disclaimer in
14 |  the documentation and/or other materials provided with the
15 |  distribution.
16 |  
17 |  * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
18 |  Studios" or the names of its contributors may NOT be used to
19 |  endorse or promote products derived from this software without
20 |  specific prior written permission from Walt Disney Pictures.
21 |  
22 |  Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
23 |  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 |  BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
25 |  FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
26 |  IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
27 |  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 |  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 |  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 |  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
31 |  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 |  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 |  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
34 | 
35 | -------------------------------------------------------------------------------- /src/doc/main.txt: -------------------------------------------------------------------------------- 1 | /*! \mainpage Partio 2 | * 3 | * Partio is a library for reading/writing/processing particle files. 4 | * The layout of the API is as follows. There is also a Python API 5 | * which you can get documentation for if you have installed partio 6 | * by typing "pydoc partio" or viewing the tutorial or demo apps. 7 | * 8 | * \section demos Simple Tutorial 9 | * - \subpage pytut - Simple Python Tutorial 10 | * - \subpage cpptut - Simple C++ Tutorial 11 | * \section mainapi Main API pages 12 | * - Partio - Namespace containing all code 13 | * - Partio::read() - Read particle set from disk 14 | * - Partio::write() - Write particle set to disk 15 | * - Partio::readCached() - Read shared read-only version of particle set from disk 16 | * - Partio::ParticlesData - Access particle data in read only way 17 | * - Partio::ParticlesDataMutable - Access particle data in read/write way 18 | * - Partio::ParticleAttribute - Particle attribute handle, avoids string 19 | lookups when reading data 20 | * - Partio::ParticleIterator - Optimized read iterator 21 | * 22 | * \section Other 23 | * - \subpage license 24 | */ 25 | 26 | /** 27 | \page license License 28 | \htmlinclude license.txt 29 | */ 30 | -------------------------------------------------------------------------------- /src/doc/partio.tex: -------------------------------------------------------------------------------- 1 | % 2 | % PARTIO SOFTWARE 3 | % Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | % 5 | % Redistribution and use in source and binary forms, with or without 6 | % modification, are permitted provided that the following conditions are 7 | % met: 8 | % 9 | % * Redistributions of source code must retain the above copyright 10 | % notice, this list of conditions and the following disclaimer. 11 | % 12 | % * Redistributions in binary form must reproduce the above copyright 13 | % notice, this list of conditions and the following disclaimer in 14 | % the documentation and/or other materials provided with the 15 | % distribution. 16 | % 17 | % * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | % Studios" or the names of its contributors may NOT be used to 19 | % endorse or promote products derived from this software without 20 | % specific prior written permission from Walt Disney Pictures. 21 | % 22 | % Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | % CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | % BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | % FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | % IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | % CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | % EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | % PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | % PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | % THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | % (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | % OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | 35 | 36 | \documentclass{article} 37 | \usepackage{graphicx} 38 | \usepackage{fullpage} 39 | \begin{document} 40 | \title{Partio: Tutorial and Documentation} 41 | \author{Andrew Selle} 42 | \maketitle 43 | 44 | \section{Introduction} 45 | 46 | Partio is a library for manipulating and handling particles. It is designed to be as easy to use as possible while still allowing relatively good performance. The data model is designed to 47 | accomidate most particle formats in some way. 48 | 49 | \section{Data Model} 50 | 51 | Partio does not specify how data should be organized in a memory or on the file. It does have a model interface that all particle formats need to implement. This consists of three different 52 | levels of data access 53 | 54 | \begin{enumerate} 55 | \item ParticlesHeaders - Number of particles, attribute types and names 56 | \item ParticlesData - Read access to all data 57 | \item ParticlesDataMutable - Write access to all data 58 | \end{enumerate} 59 | 60 | Fundamentally a particle is an indexable item that has associated attributes. There can be zero or more attributes, and technically, position is not requires. On the other hand, many of the 61 | file formats (BGEO, GEO, PTC) require position to be present to write a useful file. 62 | 63 | \subsection{Attribute Data Types} 64 | 65 | There are three data types supported. 66 | \begin{enumerate} 67 | \item FLOAT - Floating point data, 4 bytes per float 68 | \item VECTOR - Floating point data 69 | \item INT - Integer data type 70 | \end{enumerate} 71 | In addition each attribute is actually an array that can consist of one or more elements. A vector is a special case of a FLOAT and must have a count of 3. This is to match a common case 72 | where a position is a 3 float value. (This is modeled loosely after PDB/PDA formats). 73 | 74 | \subsection{Attributes} 75 | 76 | Each particle set has a list of attributes that are available. Each of these attributes has a data type and a string representing the name of the attribute. Particle attributes are 77 | represented by the class \verb|ParticleAttribute|. A particle class can be queried for individual particle attributes which then become handles that allow stringless (efficient) access to 78 | particle attributes. 79 | 80 | \section{Python API} 81 | 82 | The python API is designed for ease of use. For speed critical applications, C++ API should be used. Looping in python is extremely slow. It is hoped that in the future a mapping to numpy 83 | might be provided to allow manipulating particles in a SIMD fashion. Nevertheless, python API remains useful for manipulating particles 84 | 85 | To use Partio's python API first import partio as 86 | \begin{verbatim} 87 | >>> import partio 88 | \end{verbatim} 89 | Help on functions that are available are shown in 90 | \begin{verbatim} 91 | >>> help(partio) 92 | \end{verbatim} 93 | 94 | \subsection{Creating a Particle Set} 95 | 96 | To create a particle set and add a couple of attributes one could write 97 | \begin{verbatim} 98 | particleSet=partio.create() 99 | P=particleSet.addAttribute("position",partio.VECTOR,3) 100 | V=particleSet.addAttribute("velocity",partio.VECTOR,3) 101 | id=particleSet.addAttribute("id",partio.INT,1) 102 | \end{verbatim} 103 | Once this is done, we could add a series of particles that form a circle 104 | \begin{verbatim} 105 | n=30 106 | radiansPer=2*math.pi/n 107 | particleSet.addParticles(n) 108 | for i in range(n): 109 | particleSet.set(P,i,(math.cos(i*radiansPer),0,math.sin(i*radiansPer))) 110 | particleSet.set(V,i,(0,0,0)) 111 | particleSet.set(id,i,(i,)) 112 | \end{verbatim} 113 | Finally, we can write the particle file into a BGEO by writing 114 | \begin{verbatim} 115 | partio.write("circle.bgeo",particleSet) # write uncompressed 116 | partio.write("circle.bgeo",particleSet,True) # write compressed 117 | partio.write("circle.bgeo.gz",particleSet) # write compressed 118 | \end{verbatim} 119 | We can then visualize the particle set with 120 | \begin{verbatim} 121 | partview circle.bgeo 122 | \end{verbatim} 123 | giving\\ 124 | \includegraphics{figures/circleFigure.png} 125 | 126 | 127 | \subsection{Loading a particle set} 128 | 129 | Loading a particle set is relatively easy. If you only want to know how many particles are available or what headers are available you can do 130 | \begin{verbatim} 131 | >>> pHeaders=partio.readHeaders("circle.bgeo") 132 | \end{verbatim} 133 | If you want everything associated with the file 134 | \begin{verbatim} 135 | >>> p=partio.read("circle.bgeo") 136 | \end{verbatim} 137 | \end{document} 138 | 139 | \subsection{Finding nearest neighbors} 140 | 141 | A KD-Tree mode is supported in partio. To use it, you must first sort the particles into a KD-Tree. This is done with the \verb|sort()| function. Once that is done a query can be done. The 142 | basic query requires a maximum distance to look for particles as well as a maximum number of particles to return. For example, we could read our circle back in and look for particles nearby 143 | (1,0,0) like so: 144 | \begin{verbatim} 145 | p=partio.read("circle.bgeo") 146 | p.sort() 147 | p.findNPoints((1.,0.,0.),.1,3) 148 | \end{verbatim} -------------------------------------------------------------------------------- /src/doc/tutorial.txt: -------------------------------------------------------------------------------- 1 | /** \page pytut Python Tutorial 2 | 3 |

Python API

4 | 5 |

6 | The python API is designed for ease of use. For speed critical applications, C++ API should be used. Looping in python is extremely slow. It is hoped that in the future a mapping to numpy 7 | might be provided to allow manipulating particles in a SIMD fashion. 8 | Nevertheless, python API remains useful for manipulating particles. 9 |

10 | 11 | To use Partio's python API first import partio as 12 |
13 | >>> import partio
14 | 
15 | Help on functions that are available are shown in 16 |
17 | >>> help(partio)
18 | 
19 | 20 | 21 | 22 |

Creating a Particle Set

23 | 24 | To create a particle set and add a couple of attributes one could write 25 |
26 | particleSet=partio.create()
27 | P=particleSet.addAttribute("position",partio.VECTOR,3)
28 | V=particleSet.addAttribute("velocity",partio.VECTOR,3)
29 | id=particleSet.addAttribute("id",partio.INT,1)
30 | 
31 | Once this is done, we could add a series of particles that form a circle 32 |
33 | n=30
34 | radiansPer=2*math.pi/n
35 | particleSet.addParticles(n)
36 | for i in range(n):
37 |     particleSet.set(P,i,(math.cos(i*radiansPer),0,math.sin(i*radiansPer)))
38 |     particleSet.set(V,i,(0,0,0))
39 |     particleSet.set(id,i,(i,))
40 | 
41 | Finally, we can write the particle file into a BGEO by writing 42 |
43 | partio.write("circle.bgeo",particleSet) # write uncompressed
44 | partio.write("circle.bgeo",particleSet,True) # write compressed
45 | partio.write("circle.bgeo.gz",particleSet) # write compressed
46 | 
47 | We can then visualize the particle set with 48 |
49 | partview circle.bgeo
50 | 
51 | yielding the image 52 | \image html figures/circleFigure.png 53 | 54 | 55 |

Loading a particle set

56 | 57 | Loading a particle set is relatively easy. If you only want to know how many particles are available or what headers are available you can do 58 |
59 | >>> pHeaders=partio.readHeaders("circle.bgeo")
60 | 
61 | If you want everything associated with the file 62 |
63 | >>> p=partio.read("circle.bgeo")
64 | 
65 | \end{document} 66 | 67 |

Finding nearest neighbors

68 | 69 | A KD-Tree mode is supported in partio. To use it, you must first sort the particles into a KD-Tree. This is done with the \verb|sort()| function. Once that is done a query can be done. The 70 | basic query requires a maximum distance to look for particles as well as a maximum number of particles to return. For example, we could read our circle back in and look for particles nearby 71 | (1,0,0) like so: 72 |
73 | p=partio.read("circle.bgeo")
74 | p.sort()
75 | p.findNPoints((1.,0.,0.),.1,3)
76 | 
77 | */ 78 | -------------------------------------------------------------------------------- /src/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PARTIO SOFTWARE 2 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in 13 | # the documentation and/or other materials provided with the 14 | # distribution. 15 | # 16 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 17 | # Studios" or the names of its contributors may NOT be used to 18 | # endorse or promote products derived from this software without 19 | # specific prior written permission from Walt Disney Pictures. 20 | # 21 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 22 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 23 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 24 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | 34 | FILE(GLOB io_cpp "io/*.cpp") 35 | FILE(GLOB core_cpp "core/*.cpp") 36 | ADD_LIBRARY (partio SHARED ${io_cpp} ${core_cpp}) 37 | SET_TARGET_PROPERTIES(partio PROPERTIES OUTPUT_NAME partio) 38 | IF(ZLIB_FOUND) 39 | target_link_libraries(partio ${ZLIB_LIBRARY}) 40 | ENDIF(ZLIB_FOUND) 41 | INSTALL (TARGETS partio DESTINATION ${CMAKE_INSTALL_LIBDIR}) 42 | 43 | IF(SEEXPR_BASE) 44 | INCLUDE_DIRECTORIES(${SEEXPR_INCLUDE_PATH}) 45 | LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) 46 | LINK_DIRECTORIES(${SEEXPR_LINK_PATH}) 47 | if (${PARTIO_SE_ENABLED}) 48 | ADD_LIBRARY (partioSe SHARED PartioSe.cpp) 49 | target_link_libraries(partioSe ${PARTIO_LIBRARIES} ${SEEXPR_LIBS}) 50 | INSTALL (TARGETS partioSe DESTINATION ${CMAKE_INSTALL_LIBDIR}) 51 | endif () 52 | ENDIF(SEEXPR_BASE) 53 | 54 | FILE(GLOB public_includes "*.h") 55 | INSTALL (FILES ${public_includes} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 56 | -------------------------------------------------------------------------------- /src/lib/PartioAttribute.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | /*! 37 | The interface of the particle API (Partio) 38 | what type the primitive is, how many instances of the primitive there, name of 39 | the attribute and an index which speeds lookups of data 40 | */ 41 | 42 | #ifndef _PartioParticleAttribute_h_ 43 | #define _PartioParticleAttribute_h_ 44 | namespace Partio{ 45 | 46 | // Particle Types 47 | enum ParticleAttributeType {NONE=0,VECTOR=1,FLOAT=2,INT=3,INDEXEDSTR=4}; 48 | 49 | template struct ETYPE_TO_TYPE 50 | {struct UNUSABLE;typedef UNUSABLE TYPE;}; 51 | template<> struct ETYPE_TO_TYPE{typedef float TYPE;}; 52 | template<> struct ETYPE_TO_TYPE{typedef float TYPE;}; 53 | template<> struct ETYPE_TO_TYPE{typedef int TYPE;}; 54 | template<> struct ETYPE_TO_TYPE{typedef int TYPE;}; 55 | 56 | template struct 57 | IS_SAME{static const bool value=false;}; 58 | template struct IS_SAME{static const bool value=true;}; 59 | 60 | template bool 61 | typeCheck(const ParticleAttributeType& type) 62 | { 63 | // if T is void, don't bother checking what we passed in 64 | if (IS_SAME::value) return true; 65 | switch(type){ 66 | case VECTOR: return IS_SAME::TYPE,T>::value; 67 | case FLOAT: return IS_SAME::TYPE,T>::value; 68 | case INT: return IS_SAME::TYPE,T>::value; 69 | case INDEXEDSTR: return IS_SAME::TYPE,T>::value; 70 | default: return false; // unknown type 71 | } 72 | } 73 | 74 | inline 75 | int TypeSize(ParticleAttributeType attrType) 76 | { 77 | switch(attrType){ 78 | case NONE: return 0; 79 | case VECTOR: return sizeof(float); 80 | case FLOAT: return sizeof(float); 81 | case INT: return sizeof(int); 82 | case INDEXEDSTR: return sizeof(int); 83 | default: return 0; 84 | } 85 | } 86 | 87 | std::string TypeName(ParticleAttributeType attrType); 88 | 89 | // Particle Attribute Specifier 90 | //! Particle Collection Interface 91 | /*! 92 | This class provides a handle and description of an attribute. This includes 93 | what type the primitive is, the number of entries, the name of 94 | the attribute and an index which speeds lookups of data 95 | */ 96 | class ParticleAttribute 97 | { 98 | public: 99 | //! Type of attribute 100 | ParticleAttributeType type; 101 | 102 | //! Number of entries, should be 3 if type is VECTOR 103 | int count; 104 | 105 | //! Name of attribute 106 | std::string name; 107 | 108 | //! Internal method of fast access, user should not use or change 109 | int attributeIndex; 110 | 111 | //! Comment used by various data/readers for extra attribute information 112 | //! for example for a PTC file to read and write this could be "color" or "point" 113 | // std::string comment; 114 | }; 115 | 116 | // Fixed Attribute Specifier 117 | //! Fixed Attribute Interface 118 | /*! 119 | This class provides a handle and description of an attribute. This includes 120 | what type the primitive is, the number of entries, the name of 121 | the attribute and an index which speeds lookups of data 122 | */ 123 | class FixedAttribute 124 | { 125 | public: 126 | //! Type of attribute 127 | ParticleAttributeType type; 128 | 129 | //! Number of entries, should be 3 if type is VECTOR 130 | int count; 131 | 132 | //! Name of attribute 133 | std::string name; 134 | 135 | //! Internal method of fast access, user should not use or change 136 | int attributeIndex; 137 | 138 | //! Comment used by various data/readers for extra attribute information 139 | //! for example for a PTC file to read and write this could be "color" or "point" 140 | // std::string comment; 141 | }; 142 | } 143 | #endif 144 | -------------------------------------------------------------------------------- /src/lib/PartioIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #ifndef _PartioParticleIterator_h_ 36 | #define _PartioParticleIterator_h_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include "PartioAttribute.h" 42 | 43 | namespace Partio{ 44 | 45 | class ParticlesData; 46 | struct ParticleAccessor; 47 | 48 | //! Data 49 | /*! 50 | This class represents a piece of data stored in a particle attribute. 51 | The only allowed values are float and d 52 | */ 53 | template 54 | struct Data 55 | { 56 | T x[d]; 57 | 58 | const T& operator[](const int i) const {return x[i];} 59 | T& operator[](const int i) {return x[i];} 60 | }; 61 | typedef Data DataI; 62 | typedef Data DataF; 63 | typedef Data DataV; 64 | 65 | 66 | template class ParticleIterator; 67 | 68 | struct Provider 69 | { 70 | virtual void setupIteratorNextBlock(ParticleIterator& iterator) const=0; 71 | virtual void setupIteratorNextBlock(ParticleIterator& iterator)=0; 72 | virtual void setupAccessor(ParticleIterator& iterator,ParticleAccessor& accessor) const=0; 73 | virtual void setupAccessor(ParticleIterator& iterator,ParticleAccessor& accessor)=0; 74 | virtual ~Provider(){} 75 | }; 76 | 77 | template 78 | struct PROVIDER 79 | { 80 | typedef Provider TYPE; 81 | }; 82 | template<> 83 | struct PROVIDER 84 | { 85 | typedef const Provider TYPE; 86 | }; 87 | 88 | // TODO: non copyable 89 | struct ParticleAccessor 90 | { 91 | int stride; 92 | char* basePointer; 93 | int attributeIndex; // index of attribute opaque, do not touch 94 | int count; 95 | private: 96 | ParticleAttributeType type; 97 | 98 | ParticleAccessor* next; 99 | 100 | public: 101 | ParticleAccessor(const ParticleAttribute& attr) 102 | :stride(0),basePointer(0),attributeIndex(attr.attributeIndex), 103 | count(attr.count),type(attr.type),next(0) 104 | {} 105 | 106 | template TDATA* raw(const TITERATOR& it) 107 | {return reinterpret_cast(basePointer+it.index*stride);} 108 | 109 | template const TDATA* raw(const TITERATOR& it) const 110 | {return reinterpret_cast(basePointer+it.index*stride);} 111 | 112 | template TDATA& data(const TITERATOR& it) 113 | {return *reinterpret_cast(basePointer+it.index*stride);} 114 | 115 | template const TDATA& data(const TITERATOR& it) const 116 | {return *reinterpret_cast(basePointer+it.index*stride);} 117 | 118 | friend class ParticleIterator; 119 | friend class ParticleIterator; 120 | }; 121 | 122 | 123 | template 124 | class ParticleIterator 125 | { 126 | public: 127 | private: 128 | typedef typename PROVIDER::TYPE PROVIDER; 129 | 130 | //! Delegate, null if the iterator is false 131 | PROVIDER* particles; 132 | 133 | public: 134 | //! Start of non-interleaved index of contiguous block 135 | size_t index; 136 | private: 137 | 138 | //! End of non-interleaved index of contiguous block 139 | size_t indexEnd; 140 | 141 | //! This is used for both non-interleaved and interleaved particle attributes 142 | ParticleAccessor* accessors; 143 | 144 | public: 145 | //! Construct an invalid iterator 146 | ParticleIterator() 147 | :particles(0),index(0),indexEnd(0),accessors(0) 148 | {} 149 | 150 | //! Copy constructor. NOTE: Invalidates any accessors that have been registered with it 151 | ParticleIterator(const ParticleIterator& other) 152 | :particles(other.particles),index(other.index),indexEnd(other.indexEnd),accessors(0) 153 | {} 154 | 155 | //! Construct an iterator with iteration parameters. This is typically only 156 | //! called by implementations of Particle (not by users). For users, use 157 | //! begin() and end() on the particle type 158 | ParticleIterator(PROVIDER* particles,size_t index,size_t indexEnd) 159 | :particles(particles),index(index),indexEnd(indexEnd) 160 | {} 161 | 162 | //! Whether the iterator is valid 163 | bool valid() const 164 | {return particles;} 165 | 166 | //! Increment the iterator (postfix). Prefer the prefix form below to this one. 167 | ParticleIterator operator++(int) 168 | { 169 | ParticleIterator newIt(*this); 170 | index++; 171 | return newIt; 172 | } 173 | 174 | //! Increment the iterator (prefix). 175 | ParticleIterator& operator++() 176 | { 177 | index++; 178 | // TODO: make particles==0 check unnecessary by using indexEnd=0 to signify invalid iterator 179 | if((index>indexEnd) && particles) particles->setupIteratorNextBlock(*this); 180 | return *this; 181 | } 182 | 183 | //! Iterator comparison equals 184 | bool operator==(const ParticleIterator& other) 185 | { 186 | // TODO: this is really really expensive 187 | // TODO: this needs a block or somethingt o say which segment it is 188 | return particles==other.particles && index==other.index; 189 | } 190 | 191 | //! Iterator comparison not-equals 192 | bool operator!=(const ParticleIterator& other) 193 | { 194 | if(other.particles!=particles) return true; // if not same delegate 195 | else if(particles==0) return false; // if both are invalid iterators 196 | else return !(*this==other); 197 | } 198 | 199 | void addAccessor(ParticleAccessor& newAccessor) 200 | { 201 | newAccessor.next=accessors; 202 | accessors=&newAccessor; 203 | if(particles) particles->setupAccessor(*this,newAccessor); 204 | } 205 | 206 | 207 | // TODO: add copy constructor that wipes out accessor linked list 208 | 209 | }; 210 | 211 | template 212 | std::ostream& operator<<(std::ostream& output,const Data& v) 213 | { 214 | output< 36 | #include 37 | #include 38 | 39 | namespace Partio{ 40 | 41 | template 42 | class AttribVar:public SeExprVarRef 43 | { 44 | Partio::ParticlesDataMutable* parts; 45 | Partio::ParticleAttribute attr; 46 | int& currentIndex; 47 | int clampedCount; 48 | public: 49 | AttribVar(Partio::ParticlesDataMutable* parts, 50 | Partio::ParticleAttribute attr,int& currentIndex) 51 | :parts(parts),attr(attr),currentIndex(currentIndex),clampedCount(std::min(attr.count,3)) 52 | {} 53 | 54 | bool isVec(){return attr.count!=1;} 55 | void eval(const SeExprVarNode* node,SeVec3d& result){ 56 | const T* ptr=parts->data(attr,currentIndex); 57 | //std::cerr<<"in eval for "< class VarToPartio; 79 | 80 | /// NOTE: This class is experimental and may be deleted/modified in future versions 81 | class PartioSe:public SeExpression{ 82 | bool isPaired; 83 | int currentIndex; 84 | Partio::ParticleAttribute pairH1,pairH2; 85 | int pairIndex1,pairIndex2; 86 | Partio::ParticlesDataMutable* parts; 87 | Partio::ParticlesDataMutable* partsPairing; 88 | typedef std::map*> IntVarMap; 89 | mutable IntVarMap intVars; 90 | typedef std::map*> FloatVarMap; 91 | mutable FloatVarMap floatVars; 92 | 93 | typedef std::vector*> IntVarToPartio; 94 | typedef std::vector*> FloatVarToPartio; 95 | IntVarToPartio intVarToPartio; 96 | FloatVarToPartio floatVarToPartio; 97 | 98 | mutable SimpleVar indexVar,countVar,timeVar; 99 | 100 | public: 101 | typedef SeExpression::LocalVarTable::const_iterator LocalVarTableIterator; 102 | 103 | PartioSe(Partio::ParticlesDataMutable* parts,const char* expr); 104 | PartioSe(Partio::ParticlesDataMutable* partsPairing,Partio::ParticlesDataMutable* parts,const char* expr); 105 | void addSet(const char* prefix,Partio::ParticlesDataMutable* parts,int& setIndex); 106 | void addExport(const std::string& name,LocalVarTableIterator it,Partio::ParticlesDataMutable* parts,int& setIndex); 107 | virtual ~PartioSe(); 108 | bool runAll(); 109 | bool runRandom(); 110 | void run(int i); 111 | bool runRange(int istart,int iend); 112 | void setTime(float val); 113 | SeExprVarRef* resolveVar(const std::string& s) const; 114 | private: 115 | PartioSe(const PartioSe&); 116 | PartioSe& operator=(const PartioSe&); 117 | }; 118 | } 119 | -------------------------------------------------------------------------------- /src/lib/PartioVec3.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace Partio{ 43 | 44 | class Vec3 45 | { 46 | public: 47 | float x,y,z; 48 | 49 | inline Vec3() 50 | :x(0),y(0),z(0) 51 | {} 52 | 53 | inline Vec3(const float x,const float y,const float z) 54 | :x(x),y(y),z(z) 55 | {} 56 | 57 | inline Vec3(const float v[3]) 58 | :x(v[0]),y(v[1]),z(v[2]) 59 | {} 60 | 61 | inline float length() 62 | {return std::sqrt(x*x+y*y+z*z);} 63 | 64 | inline float normalize() 65 | {float l=length();x/=l;y/=l;z/=l;return l;} 66 | 67 | inline Vec3 normalized() const 68 | {Vec3 foo(x,y,z);foo.normalize();return foo;} 69 | 70 | inline Vec3 operator*(const float a) const 71 | {return Vec3(a*x,a*y,a*z);} 72 | 73 | inline Vec3 operator-(const Vec3& v) const 74 | {return Vec3(x-v.x,y-v.y,z-v.z);} 75 | 76 | inline Vec3 operator+(const Vec3& v) const 77 | {return Vec3(x+v.x,y+v.y,z+v.z);} 78 | 79 | inline Vec3 operator+=(const Vec3& v) 80 | {x+=v.x;y+=v.y;z+=v.z;return *this;} 81 | 82 | inline Vec3 cross(const Vec3& v) const 83 | {Vec3 ret(y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x);return ret;} 84 | 85 | inline Vec3 min(const Vec3& v) const 86 | { 87 | return Vec3(std::min(x,v.x),std::min(y,v.y),std::min(z,v.z)); 88 | } 89 | 90 | inline Vec3 max(const Vec3& v) const 91 | { 92 | return Vec3(std::max(x,v.x),std::max(y,v.y),std::max(z,v.z)); 93 | } 94 | }; 95 | 96 | 97 | std::ostream& operator<<(std::ostream& stream,const Vec3& v) 98 | {return stream< 42 | 43 | namespace Partio 44 | { 45 | 46 | #ifndef PARTIO_USE_SPINLOCK 47 | 48 | class PartioMutex 49 | { 50 | pthread_mutex_t CacheLock; 51 | 52 | public: 53 | inline PartioMutex() 54 | { 55 | pthread_mutex_init(&CacheLock,0); 56 | } 57 | 58 | inline ~PartioMutex() 59 | { 60 | pthread_mutex_destroy(&CacheLock); 61 | } 62 | 63 | inline void lock() 64 | { 65 | pthread_mutex_lock(&CacheLock); 66 | } 67 | 68 | inline void unlock() 69 | { 70 | pthread_mutex_unlock(&CacheLock); 71 | } 72 | }; 73 | 74 | #else 75 | 76 | class PartioMutex 77 | { 78 | pthread_spinlock_t CacheLock; 79 | 80 | public: 81 | inline PartioMutex() 82 | { 83 | pthread_spinlock_init(&CacheLock,PTHREAD_PROCESS_PRIVATE); 84 | } 85 | 86 | inline ~PartioMutex() 87 | { 88 | pthread_spinlock_destroy(&CacheLock); 89 | } 90 | 91 | inline void lock() 92 | { 93 | pthread_spinlock_lock(&CacheLock); 94 | } 95 | 96 | inline void unlock() 97 | { 98 | pthread_spinlock_unlock(&CacheLock); 99 | } 100 | }; 101 | 102 | #endif // USE_PTHREAD_SPINLOCK 103 | } 104 | 105 | #else 106 | #include 107 | namespace Partio{ 108 | 109 | class PartioMutex 110 | { 111 | HANDLE CacheLock; 112 | 113 | public: 114 | inline PartioMutex() 115 | { 116 | CacheLock=CreateMutex(0,FALSE,"partiocache"); 117 | } 118 | 119 | inline ~PartioMutex() 120 | { 121 | CloseHandle(CacheLock); 122 | } 123 | 124 | inline void lock() 125 | { 126 | WaitForSingleObject(CacheLock,INFINITE); 127 | } 128 | 129 | inline void unlock() 130 | { 131 | ReleaseMutex(CacheLock); 132 | } 133 | }; 134 | } 135 | #endif // USE_PTHREADS 136 | #endif // Header guard 137 | -------------------------------------------------------------------------------- /src/lib/core/ParticleCaching.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include 36 | #include 37 | #include "Mutex.h" 38 | #include "../Partio.h" 39 | 40 | //##################################################################### 41 | namespace Partio{ 42 | 43 | namespace 44 | { 45 | static PartioMutex mutex; 46 | } 47 | 48 | // cached read write 49 | std::map cachedParticlesCount; 50 | std::map cachedParticles; 51 | 52 | ParticlesData* readCached(const char* filename,const bool sort,const bool verbose,std::ostream& error) 53 | { 54 | mutex.lock(); 55 | std::map::iterator i=cachedParticles.find(filename); 56 | 57 | ParticlesData* p=0; 58 | if(i!=cachedParticles.end()){ 59 | p=i->second; 60 | cachedParticlesCount[p]++; 61 | }else{ 62 | ParticlesDataMutable* p_rw=read(filename,verbose); 63 | if(p_rw){ 64 | if(sort) p_rw->sort(); 65 | p=p_rw; 66 | cachedParticles[filename]=p; 67 | cachedParticlesCount[p]=1; 68 | } 69 | } 70 | mutex.unlock(); 71 | return p; 72 | } 73 | 74 | void freeCached(ParticlesData* particles) 75 | { 76 | if(!particles) return; 77 | 78 | mutex.lock(); 79 | 80 | std::map::iterator i=cachedParticlesCount.find(particles); 81 | if(i==cachedParticlesCount.end()){ // Not found in cache, just free 82 | delete (ParticlesInfo*)particles; 83 | }else{ // found in cache 84 | i->second--; // decrement ref count 85 | if(i->second==0){ // ref count is now zero, remove from structure 86 | delete (ParticlesInfo*)particles; 87 | cachedParticlesCount.erase(i); 88 | for(std::map::iterator i2=cachedParticles.begin(); 89 | i2!=cachedParticles.end();++i2){ 90 | if(i2->second==particles){ 91 | cachedParticles.erase(i2); 92 | goto exit_and_release; 93 | } 94 | } 95 | assert(false); 96 | } 97 | } 98 | exit_and_release: 99 | mutex.unlock(); 100 | } 101 | 102 | void beginCachedAccess(ParticlesData* particles) 103 | { 104 | // TODO: for future use 105 | } 106 | 107 | void endCachedAccess(ParticlesData* particles) 108 | { 109 | // TODO: for future use 110 | } 111 | 112 | } // namespace Partio 113 | -------------------------------------------------------------------------------- /src/lib/core/ParticleCaching.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #ifndef _ParticleCaching_h_ 37 | #define _ParticleCaching_h_ 38 | 39 | namespace Partio{ 40 | class Particles; 41 | void freeCached(ParticlesInfo* particles); 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/lib/core/ParticleHeaders.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include "ParticleHeaders.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | using namespace Partio; 42 | 43 | ParticleHeaders:: 44 | ParticleHeaders() 45 | :particleCount(0) 46 | { 47 | } 48 | 49 | ParticleHeaders:: 50 | ~ParticleHeaders() 51 | {} 52 | 53 | void ParticleHeaders:: 54 | release() const 55 | { 56 | delete this; 57 | } 58 | 59 | int ParticleHeaders:: 60 | numParticles() const 61 | { 62 | return particleCount; 63 | } 64 | 65 | int ParticleHeaders:: 66 | numAttributes() const 67 | { 68 | return attributes.size(); 69 | } 70 | 71 | int ParticleHeaders:: 72 | numFixedAttributes() const 73 | { 74 | return fixedAttributes.size(); 75 | } 76 | 77 | bool ParticleHeaders:: 78 | attributeInfo(const int attributeIndex,ParticleAttribute& attribute) const 79 | { 80 | if(attributeIndex<0 || attributeIndex>=(int)attributes.size()) return false; 81 | attribute=attributes[attributeIndex]; 82 | return true; 83 | } 84 | 85 | bool ParticleHeaders:: 86 | fixedAttributeInfo(const int attributeIndex,FixedAttribute& attribute) const 87 | { 88 | if(attributeIndex<0 || attributeIndex>=(int)fixedAttributes.size()) return false; 89 | attribute=fixedAttributes[attributeIndex]; 90 | return true; 91 | } 92 | 93 | bool ParticleHeaders:: 94 | attributeInfo(const char* attributeName,ParticleAttribute& attribute) const 95 | { 96 | std::map::const_iterator it=nameToAttribute.find(attributeName); 97 | if(it!=nameToAttribute.end()){ 98 | attribute=attributes[it->second]; 99 | return true; 100 | } 101 | return false; 102 | } 103 | 104 | bool ParticleHeaders:: 105 | fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const 106 | { 107 | std::map::const_iterator it=nameToFixedAttribute.find(attributeName); 108 | if(it!=nameToFixedAttribute.end()){ 109 | attribute=fixedAttributes[it->second]; 110 | return true; 111 | } 112 | return false; 113 | } 114 | 115 | void ParticleHeaders:: 116 | sort() 117 | { 118 | assert(false); 119 | } 120 | 121 | 122 | int ParticleHeaders:: 123 | registerIndexedStr(const ParticleAttribute& attribute,const char* str) 124 | { 125 | assert(false); 126 | return -1; 127 | } 128 | 129 | int ParticleHeaders:: 130 | registerFixedIndexedStr(const FixedAttribute& attribute,const char* str) 131 | { 132 | assert(false); 133 | return -1; 134 | } 135 | 136 | int ParticleHeaders:: 137 | lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const 138 | { 139 | assert(false); 140 | return -1; 141 | } 142 | 143 | int ParticleHeaders:: 144 | lookupFixedIndexedStr(const FixedAttribute& attribute,const char* str) const 145 | { 146 | assert(false); 147 | return -1; 148 | } 149 | 150 | const std::vector& ParticleHeaders:: 151 | indexedStrs(const ParticleAttribute& attr) const 152 | { 153 | static std::vector dummy; 154 | assert(false); 155 | return dummy; 156 | } 157 | 158 | const std::vector& ParticleHeaders:: 159 | fixedIndexedStrs(const FixedAttribute& attr) const 160 | { 161 | static std::vector dummy; 162 | assert(false); 163 | return dummy; 164 | } 165 | 166 | void ParticleHeaders:: 167 | findPoints(const float bboxMin[3],const float bboxMax[3],std::vector& points) const 168 | { 169 | assert(false); 170 | } 171 | 172 | float ParticleHeaders:: 173 | findNPoints(const float center[3],const int nPoints,const float maxRadius,std::vector& points, 174 | std::vector& pointDistancesSquared) const 175 | { 176 | assert(false); 177 | return 0; 178 | } 179 | 180 | int ParticleHeaders:: 181 | findNPoints(const float center[3],int nPoints,const float maxRadius, ParticleIndex *points, 182 | float *pointDistancesSquared, float *finalRadius2) const 183 | { 184 | assert(false); 185 | return 0; 186 | } 187 | 188 | ParticleAttribute ParticleHeaders:: 189 | addAttribute(const char* attribute,ParticleAttributeType type,const int count) 190 | { 191 | // TODO: check if attribute already exists and if so what data type 192 | ParticleAttribute attr; 193 | attr.name=attribute; 194 | attr.type=type; 195 | attr.attributeIndex=attributes.size(); // all arrays separate so we don't use this here! 196 | attr.count=count; 197 | attributes.push_back(attr); 198 | nameToAttribute[attribute]=attributes.size()-1; 199 | return attr; 200 | } 201 | 202 | FixedAttribute ParticleHeaders:: 203 | addFixedAttribute(const char* attribute,ParticleAttributeType type,const int count) 204 | { 205 | // TODO: check if attribute already exists and if so what data type 206 | FixedAttribute attr; 207 | attr.name=attribute; 208 | attr.type=type; 209 | attr.attributeIndex=fixedAttributes.size(); // all arrays separate so we don't use this here! 210 | attr.count=count; 211 | fixedAttributes.push_back(attr); 212 | nameToFixedAttribute[attribute]=fixedAttributes.size()-1; 213 | return attr; 214 | } 215 | 216 | ParticleIndex ParticleHeaders:: 217 | addParticle() 218 | { 219 | ParticleIndex index=particleCount; 220 | particleCount++; 221 | return index; 222 | } 223 | 224 | ParticlesDataMutable::iterator ParticleHeaders:: 225 | addParticles(const int countToAdd) 226 | { 227 | particleCount+=countToAdd; 228 | return iterator(); 229 | } 230 | 231 | void* ParticleHeaders:: 232 | dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const 233 | { 234 | assert(false); 235 | return 0; 236 | } 237 | 238 | void* ParticleHeaders:: 239 | fixedDataInternal(const FixedAttribute& attribute) const 240 | { 241 | assert(false); 242 | return 0; 243 | } 244 | 245 | void ParticleHeaders:: 246 | dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount, 247 | const ParticleIndex* particleIndices,const bool sorted,char* values) const 248 | { 249 | assert(false); 250 | } 251 | 252 | void ParticleHeaders:: 253 | dataAsFloat(const ParticleAttribute& attribute,const int indexCount, 254 | const ParticleIndex* particleIndices,const bool sorted,float* values) const 255 | { 256 | assert(false); 257 | } 258 | 259 | 260 | void ParticleHeaders:: 261 | setIndexedStr(const ParticleAttribute& attribute,int indexedStringToken,const char* str){ 262 | assert(false); 263 | } 264 | 265 | void ParticleHeaders:: 266 | setFixedIndexedStr(const FixedAttribute& attribute,int indexedStringToken,const char* str){ 267 | assert(false); 268 | } 269 | -------------------------------------------------------------------------------- /src/lib/core/ParticleHeaders.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #ifndef _ParticlesHeaders_h_ 36 | #define _ParticlesHeaders_h_ 37 | 38 | #include "../Partio.h" 39 | namespace Partio{ 40 | 41 | class ParticleHeaders:public ParticlesDataMutable 42 | { 43 | public: 44 | ParticleHeaders(); 45 | void release() const; 46 | protected: 47 | virtual ~ParticleHeaders(); 48 | 49 | int numAttributes() const; 50 | int numFixedAttributes() const; 51 | int numParticles() const; 52 | bool attributeInfo(const char* attributeName,ParticleAttribute& attribute) const; 53 | bool fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const; 54 | bool attributeInfo(const int attributeInfo,ParticleAttribute& attribute) const; 55 | bool fixedAttributeInfo(const int attributeInfo,FixedAttribute& attribute) const; 56 | 57 | int registerIndexedStr(const ParticleAttribute& attribute,const char* str); 58 | int registerFixedIndexedStr(const FixedAttribute& attribute,const char* str); 59 | int lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const; 60 | int lookupFixedIndexedStr(const FixedAttribute& attribute,const char* str) const; 61 | void setIndexedStr(const ParticleAttribute& attribute,int indexedStrHandle,const char* str); 62 | void setFixedIndexedStr(const FixedAttribute& attribute,int indexedStrHandle,const char* str); 63 | const std::vector& indexedStrs(const ParticleAttribute& attr) const; 64 | const std::vector& fixedIndexedStrs(const FixedAttribute& attr) const; 65 | 66 | virtual void dataAsFloat(const ParticleAttribute& attribute,const int indexCount, 67 | const ParticleIndex* particleIndices,const bool sorted,float* values) const; 68 | 69 | void sort(); 70 | 71 | void findPoints(const float bboxMin[3],const float bboxMax[3],std::vector& points) const; 72 | float findNPoints(const float center[3],int nPoints,const float maxRadius, 73 | std::vector& points,std::vector& pointDistancesSquared) const; 74 | int findNPoints(const float center[3],int nPoints,const float maxRadius, 75 | ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const; 76 | ParticlesDataMutable* computeClustering(const int numNeighbors,const double radiusSearch,const double radiusInside,const int connections,const double density) 77 | {assert(false);} 78 | 79 | ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,const int count); 80 | FixedAttribute addFixedAttribute(const char* attribute,ParticleAttributeType type,const int count); 81 | ParticleIndex addParticle(); 82 | iterator addParticles(const int count); 83 | 84 | const_iterator setupConstIterator(const int index=0) const 85 | {return const_iterator();} 86 | 87 | iterator setupIterator(const int index=0) 88 | {return iterator();} 89 | 90 | private: 91 | void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const; 92 | void* fixedDataInternal(const FixedAttribute& attribute) const; 93 | void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount, 94 | const ParticleIndex* particleIndices,const bool sorted,char* values) const; 95 | 96 | private: 97 | int particleCount; 98 | std::vector attributes; 99 | std::map nameToAttribute; 100 | std::vector fixedAttributes; 101 | std::map nameToFixedAttribute; 102 | }; 103 | } 104 | #endif 105 | -------------------------------------------------------------------------------- /src/lib/core/ParticleSimple.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "Mutex.h" 40 | #include "../Partio.h" 41 | 42 | namespace Partio{ 43 | 44 | template class KdTree; 45 | 46 | class ParticlesSimple:public ParticlesDataMutable, 47 | public Provider 48 | { 49 | protected: 50 | virtual ~ParticlesSimple(); 51 | public: 52 | using ParticlesDataMutable::iterator; 53 | using ParticlesData::const_iterator; 54 | 55 | void release() const; 56 | 57 | ParticlesSimple(); 58 | 59 | int numAttributes() const; 60 | int numFixedAttributes() const; 61 | int numParticles() const; 62 | bool attributeInfo(const char* attributeName,ParticleAttribute& attribute) const; 63 | bool fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const; 64 | bool attributeInfo(const int attributeInfo,ParticleAttribute& attribute) const; 65 | bool fixedAttributeInfo(const int attributeInfo,FixedAttribute& attribute) const; 66 | void dataAsFloat(const ParticleAttribute& attribute,const int indexCount, 67 | const ParticleIndex* particleIndices,const bool sorted,float* values) const; 68 | int registerIndexedStr(const ParticleAttribute& attribute,const char* str); 69 | int registerFixedIndexedStr(const FixedAttribute& attribute,const char* str); 70 | void setIndexedStr(const ParticleAttribute& attribute,int indexedStringToken,const char* str); 71 | void setFixedIndexedStr(const FixedAttribute& attribute,int indexedStringToken,const char* str); 72 | int lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const; 73 | int lookupFixedIndexedStr(const FixedAttribute& attribute,const char* str) const; 74 | const std::vector& indexedStrs(const ParticleAttribute& attr) const; 75 | const std::vector& fixedIndexedStrs(const FixedAttribute& attr) const; 76 | void sort(); 77 | void findPoints(const float bboxMin[3],const float bboxMax[3],std::vector& points) const; 78 | float findNPoints(const float center[3],int nPoints,const float maxRadius, 79 | std::vector& points,std::vector& pointDistancesSquared) const; 80 | int findNPoints(const float center[3],int nPoints,const float maxRadius, 81 | ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const; 82 | ParticlesDataMutable* computeClustering(const int numNeighbors,const double radiusSearch,const double radiusInside,const int connections,const double density); 83 | 84 | ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,const int count); 85 | FixedAttribute addFixedAttribute(const char* attribute,ParticleAttributeType type,const int count); 86 | ParticleIndex addParticle(); 87 | iterator addParticles(const int count); 88 | 89 | 90 | iterator setupIterator(const int index=0); 91 | const_iterator setupConstIterator(const int index=0) const; 92 | void setupIteratorNextBlock(Partio::ParticleIterator& iterator); 93 | void setupIteratorNextBlock(Partio::ParticleIterator& iterator) const; 94 | void setupAccessor(Partio::ParticleIterator& iterator,ParticleAccessor& accessor); 95 | void setupAccessor(Partio::ParticleIterator& iterator,ParticleAccessor& accessor) const; 96 | private: 97 | void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const; 98 | void* fixedDataInternal(const FixedAttribute& attribute) const; 99 | void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount, 100 | const ParticleIndex* particleIndices,const bool sorted,char* values) const; 101 | 102 | private: 103 | int particleCount; 104 | int allocatedCount; 105 | std::vector attributeData; // Inside is data of appropriate type 106 | std::vector attributeOffsets; // Inside is data of appropriate type 107 | struct IndexedStrTable{ 108 | std::map stringToIndex; // TODO: this should be a hash table unordered_map 109 | std::vector strings; 110 | }; 111 | std::vector attributeIndexedStrs; 112 | std::vector attributes; 113 | std::vector attributeStrides; 114 | std::map nameToAttribute; 115 | std::vector fixedAttributeData; // Inside is data of appropriate type 116 | std::vector fixedAttributeIndexedStrs; 117 | std::vector fixedAttributes; 118 | std::map nameToFixedAttribute; 119 | 120 | PartioMutex kdtree_mutex; 121 | KdTree<3>* kdtree; 122 | }; 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/lib/core/ParticleSimpleInterleave.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #ifndef _ParticleSimpleInterleave_h_ 36 | #define _ParticleSimpleInterleave_h_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include "Mutex.h" 42 | #include "../Partio.h" 43 | 44 | namespace Partio{ 45 | 46 | template class KdTree; 47 | 48 | class ParticlesSimpleInterleave:public ParticlesDataMutable, 49 | public Provider 50 | { 51 | protected: 52 | virtual ~ParticlesSimpleInterleave(); 53 | public: 54 | using ParticlesDataMutable::iterator; 55 | using ParticlesData::const_iterator; 56 | 57 | void release() const; 58 | 59 | ParticlesSimpleInterleave(); 60 | 61 | int numAttributes() const; 62 | int numFixedAttributes() const; 63 | int numParticles() const; 64 | bool attributeInfo(const char* attributeName,ParticleAttribute& attribute) const; 65 | bool fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const; 66 | bool attributeInfo(const int attributeInfo,ParticleAttribute& attribute) const; 67 | bool fixedAttributeInfo(const int attributeInfo,FixedAttribute& attribute) const; 68 | 69 | virtual void dataAsFloat(const ParticleAttribute& attribute,const int indexCount, 70 | const ParticleIndex* particleIndices,const bool sorted,float* values) const; 71 | int registerIndexedStr(const ParticleAttribute& attribute,const char* str); 72 | int registerFixedIndexedStr(const FixedAttribute& attribute,const char* str); 73 | void setIndexedStr(const ParticleAttribute& attribute,int indexedStringToken,const char* str); 74 | void setFixedIndexedStr(const FixedAttribute& attribute,int indexedStringToken,const char* str); 75 | int lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const; 76 | int lookupFixedIndexedStr(const FixedAttribute& attribute,const char* str) const; 77 | const std::vector& indexedStrs(const ParticleAttribute& attr) const; 78 | const std::vector& fixedIndexedStrs(const FixedAttribute& attr) const; 79 | 80 | void sort(); 81 | void findPoints(const float bboxMin[3],const float bboxMax[3],std::vector& points) const; 82 | float findNPoints(const float center[3],int nPoints,const float maxRadius, 83 | std::vector& points,std::vector& pointDistancesSquared) const; 84 | int findNPoints(const float center[3],int nPoints,const float maxRadius, 85 | ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const; 86 | ParticlesDataMutable* computeClustering(const int numNeighbors,const double radiusSearch,const double radiusInside,const int connections,const double density) {} 87 | 88 | ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,const int count); 89 | FixedAttribute addFixedAttribute(const char* attribute,ParticleAttributeType type,const int count); 90 | ParticleIndex addParticle(); 91 | iterator addParticles(const int count); 92 | 93 | 94 | iterator setupIterator(const int index=0); 95 | const_iterator setupConstIterator(const int index=0) const; 96 | void setupIteratorNextBlock(Partio::ParticleIterator& iterator); 97 | void setupIteratorNextBlock(Partio::ParticleIterator& iterator) const; 98 | void setupAccessor(Partio::ParticleIterator& iterator,ParticleAccessor& accessor); 99 | void setupAccessor(Partio::ParticleIterator& iterator,ParticleAccessor& accessor) const; 100 | private: 101 | void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const; 102 | void* fixedDataInternal(const FixedAttribute& attribute) const; 103 | void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount, 104 | const ParticleIndex* particleIndices,const bool sorted,char* values) const; 105 | 106 | private: 107 | int particleCount; 108 | int allocatedCount; 109 | char* data; 110 | char* fixedData; 111 | int stride; 112 | struct IndexedStrTable{ 113 | std::map stringToIndex; // TODO: this should be a hash table unordered_map 114 | std::vector strings; 115 | }; 116 | std::vector attributeIndexedStrs; 117 | std::vector attributeOffsets; // Inside is data of appropriate type 118 | std::vector attributes; 119 | std::map nameToAttribute; 120 | std::vector fixedAttributeIndexedStrs; 121 | std::vector fixedAttributeOffsets; // Inside is data of appropriate type 122 | std::vector fixedAttributes; 123 | std::map nameToFixedAttribute; 124 | 125 | PartioMutex kdtree_mutex; 126 | KdTree<3>* kdtree; 127 | }; 128 | 129 | } 130 | #endif 131 | -------------------------------------------------------------------------------- /src/lib/io/PDA.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2011 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include "../Partio.h" 36 | #include "../core/ParticleHeaders.h" 37 | #include "ZIP.h" 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace Partio 46 | { 47 | 48 | using namespace std; 49 | 50 | // TODO: convert this to use iterators like the rest of the readers/writers 51 | 52 | ParticlesDataMutable* readPDA(const char* filename,const bool headersOnly,std::ostream* errorStream) 53 | { 54 | unique_ptr input(Gzip_In(filename,ios::in|ios::binary)); 55 | if(!*input){ 56 | if(errorStream) *errorStream <<"Partio: Can't open particle data file: "<good()){ 68 | *input>>word; 69 | if(word!="ATTRIBUTES"){simple->release();return 0;} 70 | } 71 | 72 | vector attrNames; 73 | vector attrs; 74 | 75 | while(input->good()){ 76 | *input>>word; 77 | if(word=="TYPES") break;; 78 | attrNames.push_back(word); 79 | } 80 | 81 | size_t index=0; 82 | while(input->good()){ 83 | *input>>word; 84 | if(word=="NUMBER_OF_PARTICLES:") break; 85 | 86 | if(index>=attrNames.size()) continue; 87 | 88 | if(word=="V"){ 89 | attrs.push_back(simple->addAttribute(attrNames[index].c_str(),Partio::VECTOR,3)); 90 | }else if(word=="R"){ 91 | attrs.push_back(simple->addAttribute(attrNames[index].c_str(),Partio::FLOAT,1)); 92 | }else if(word=="I"){ 93 | attrs.push_back(simple->addAttribute(attrNames[index].c_str(),Partio::INT,1)); 94 | } 95 | 96 | index++; 97 | } 98 | 99 | unsigned int num=0; 100 | if(input->good()){ 101 | *input>>num; 102 | simple->addParticles(num); 103 | if(headersOnly) return simple; // escape before we try to touch data 104 | }else{ 105 | simple->release(); 106 | return 0; 107 | } 108 | 109 | // look for beginning of header 110 | if(input->good()){ 111 | *input>>word; 112 | if(word != "BEGIN"){simple->release();return 0;} 113 | } 114 | if(input->good()){ 115 | *input>>word; 116 | if(word != "DATA"){simple->release();return 0;} 117 | } 118 | 119 | // Read actual particle data 120 | if(!input->good()){simple->release();return 0;} 121 | for(unsigned int particleIndex=0;input->good() && particleIndexdataWrite(attrs[attrIndex],particleIndex); 125 | for(int count=0;count>ival; 128 | data[count]=ival; 129 | } 130 | }else if(attrs[attrIndex].type==Partio::FLOAT || attrs[attrIndex].type==Partio::VECTOR){ 131 | float* data=simple->dataWrite(attrs[attrIndex],particleIndex); 132 | for(int count=0;count>fval; 135 | data[count]=fval; 136 | } 137 | } 138 | } 139 | } 140 | 141 | return simple; 142 | } 143 | 144 | bool writePDA(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) 145 | { 146 | unique_ptr output( 147 | compressed ? 148 | Gzip_Out(filename,ios::out|ios::binary) 149 | :new ofstream(filename,ios::out|ios::binary)); 150 | 151 | *output<<"ATTRIBUTES"< attrs; 154 | for (int aIndex=0;aIndex(attrs[attrIndex],particleIndex); 181 | for(int count=0;count(attrs[attrIndex],particleIndex); 185 | for(int count=0;count 46 | #include 47 | #include 48 | #include 49 | 50 | namespace Partio{ 51 | 52 | using namespace std; 53 | 54 | static const int PDC_MAGIC = (((((' '<<8)|'C')<<8)|'D')<<8)|'P'; // " CDP" 55 | 56 | typedef struct{ 57 | int magic; 58 | int version; 59 | int bitorder; 60 | int tmp1; 61 | int tmp2; 62 | int numParticles; 63 | int numAttrs; 64 | } PDC_HEADER; 65 | 66 | string readName(istream& input){ 67 | int nameLen = 0; 68 | read(input, nameLen); 69 | char* name = new char[nameLen]; 70 | input.read(name, nameLen); 71 | string result(name, name+nameLen); 72 | delete [] name; 73 | return result; 74 | } 75 | 76 | ParticlesDataMutable* readPDC(const char* filename, const bool headersOnly,std::ostream* errorStream){ 77 | 78 | unique_ptr input(Gzip_In(filename,std::ios::in|std::ios::binary)); 79 | if(!*input){ 80 | if(errorStream) *errorStream << "Partio: Unable to open file " << filename << std::endl; 81 | return 0; 82 | } 83 | 84 | PDC_HEADER header; 85 | input->read((char*)&header, sizeof(header)); 86 | if(PDC_MAGIC != header.magic){ 87 | if(errorStream) *errorStream << "Partio: Magic number '" << header.magic << "' of '" << filename << "' doesn't match pdc magic '" << PDC_MAGIC << "'" << std::endl; 88 | return 0; 89 | } 90 | 91 | BIGEND::swap(header.numParticles); 92 | BIGEND::swap(header.numAttrs); 93 | 94 | ParticlesDataMutable* simple = headersOnly ? new ParticleHeaders: create(); 95 | simple->addParticles(header.numParticles); 96 | 97 | for(int attrIndex = 0; attrIndex < header.numAttrs; attrIndex++){ 98 | // add attribute 99 | ParticleAttribute attr; 100 | string attrName = readName(*input); 101 | int type; 102 | read(*input, type); 103 | if(type == 3){ 104 | attr = simple->addAttribute(attrName.c_str(), FLOAT, 1); 105 | } 106 | else if(type == 5){ 107 | attr = simple->addAttribute(attrName.c_str(), VECTOR, 3); 108 | } 109 | 110 | // if headersOnly, skip 111 | if(headersOnly){ 112 | input->seekg((int)input->tellg() + header.numParticles*sizeof(double)*attr.count); 113 | continue; 114 | } 115 | else{ 116 | double tmp[3]; 117 | for(int partIndex = 0; partIndex < simple->numParticles(); partIndex++){ 118 | for(int dim = 0; dim < attr.count; dim++){ 119 | read(*input, tmp[dim]); 120 | simple->dataWrite(attr, partIndex)[dim] = (float)tmp[dim]; 121 | } 122 | } 123 | } 124 | } 125 | 126 | return simple; 127 | } 128 | 129 | bool writePDC(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream){ 130 | unique_ptr output( 131 | compressed ? 132 | Gzip_Out(filename,ios::out|ios::binary) 133 | :new std::ofstream(filename,ios::out|ios::binary)); 134 | 135 | if(!*output){ 136 | if(errorStream) *errorStream << "Partio Unable to open file " << filename << endl; 137 | return false; 138 | } 139 | 140 | // write .pdc header 141 | write(*output, PDC_MAGIC); 142 | write(*output, (int)1); // version 143 | write(*output, (int)1); // bitorder 144 | write(*output, (int)0); // tmp1 145 | write(*output, (int)0); // tmp2 146 | write(*output, (int)p.numParticles()); 147 | write(*output, (int)p.numAttributes()); 148 | 149 | for(int attrIndex = 0; attrIndex < p.numAttributes(); attrIndex++){ 150 | ParticleAttribute attr; 151 | p.attributeInfo(attrIndex,attr); 152 | 153 | // write attribute name 154 | write(*output, (int)attr.name.length()); 155 | output->write(attr.name.c_str(), (int)attr.name.length()); 156 | 157 | // write type 158 | int count = 1; // FLOAT 159 | if(attr.type == VECTOR){ 160 | count = 3; 161 | } 162 | write(*output, (int)(count+2)); 163 | 164 | // write data 165 | for(int partIndex = 0; partIndex < p.numParticles(); partIndex++){ 166 | const float* data = p.data(attr, partIndex); 167 | for(int dim = 0; dim < count; dim++){ 168 | write(*output, (double)data[dim]); 169 | } 170 | } 171 | } 172 | return true; 173 | } 174 | 175 | }// end of namespace Partio 176 | -------------------------------------------------------------------------------- /src/lib/io/PTS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright (c) 2011 Disney Enterprises, Inc. and Contributors, All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | 35 | Format Contributed by github user: redpawfx (redpawFX@gmail.com) and Luma Pictures 2011 36 | Some code for this format was helped along by referring to an implementation by 37 | */ 38 | #include "../Partio.h" 39 | #include "../core/ParticleHeaders.h" 40 | #include "ZIP.h" 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | namespace Partio 51 | { 52 | 53 | using namespace std; 54 | 55 | // TODO: convert this to use iterators like the rest of the readers/writers 56 | 57 | ParticlesDataMutable* readPTS(const char* filename,const bool headersOnly,std::ostream* errorStream) 58 | { 59 | unique_ptr input(Gzip_In(filename,ios::in|ios::binary)); 60 | if (!*input) 61 | { 62 | if(errorStream) *errorStream<<"Partio: Can't open particle data file: "< attrNames; 74 | vector attrs; 75 | 76 | /// we're going to fake the ID attribute since there's no such thing in PTS Files 77 | attrNames.push_back((string)"id"); 78 | attrs.push_back(simple->addAttribute(attrNames[0].c_str(),Partio::INT,1)); 79 | 80 | /// FORMAT is up to 8 elements space delimited { posX posY posZ remission quality red green blue } 81 | // since there's no header data to parse we're just going to hard code this 82 | 83 | /* Start from the beginning */ 84 | input->seekg(0,ios::beg); 85 | 86 | /* Determine amount of values per line */ 87 | char line[1024]; 88 | /* Jump over first line. */ 89 | input->getline(line,1024); 90 | input->getline(line,1024); 91 | int valcount = 0; 92 | char * pch = strtok( line, "\t " ); 93 | while ( pch ) 94 | { 95 | if ( *pch != 0 && *pch != '\n' ) 96 | { 97 | valcount++; 98 | } 99 | pch = strtok( NULL, "\t " ); 100 | } 101 | 102 | 103 | switch ( valcount ) 104 | { 105 | case 3: // position only 106 | { 107 | attrNames.push_back((string)"position"); 108 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 109 | } 110 | break; 111 | case 4: // position and remission 112 | { 113 | attrNames.push_back((string)"position"); 114 | attrNames.push_back((string)"remission"); 115 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 116 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::FLOAT,1)); 117 | } 118 | break; 119 | case 6: // position and RGB 120 | { 121 | attrNames.push_back((string)"position"); 122 | attrNames.push_back((string)"pointColor"); 123 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 124 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::VECTOR,3)); 125 | } 126 | break; 127 | case 7: // position remission and RGB 128 | { 129 | attrNames.push_back((string)"position"); 130 | attrNames.push_back((string)"remission"); 131 | attrNames.push_back((string)"pointColor"); 132 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 133 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::FLOAT,1)); 134 | attrs.push_back(simple->addAttribute(attrNames[3].c_str(),Partio::VECTOR,3)); 135 | } 136 | break; 137 | case 8: // everything 138 | { 139 | attrNames.push_back((string)"position"); 140 | attrNames.push_back((string)"remission"); 141 | attrNames.push_back((string)"quality"); 142 | attrNames.push_back((string)"pointColor"); 143 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 144 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::FLOAT,1)); 145 | attrs.push_back(simple->addAttribute(attrNames[3].c_str(),Partio::INT,1)); 146 | attrs.push_back(simple->addAttribute(attrNames[4].c_str(),Partio::VECTOR,3)); 147 | } 148 | break; 149 | default: 150 | { 151 | return 0; 152 | } 153 | break; 154 | 155 | } 156 | 157 | input->seekg(0,ios::beg); 158 | 159 | unsigned int num=0; 160 | simple->addParticles(num); 161 | if (headersOnly) return simple; // escape before we try to touch data 162 | 163 | if (input->good()) 164 | { // garbage count at top of file 165 | char junk[1024]; 166 | input->getline(junk,1024); 167 | } 168 | 169 | // Read actual particle data 170 | if (!input->good()) { 171 | simple->release(); 172 | return 0; 173 | } 174 | 175 | // we have to read line by line, because data is not clean and consistent so we skip any lines that dont' conform 176 | 177 | for (unsigned int particleIndex=0;input->good();) 178 | { 179 | string token = ""; 180 | char line[1024]; 181 | input->getline(line, 1024); 182 | 183 | stringstream ss(line); 184 | 185 | float lineData[8]; 186 | int i = 0; 187 | 188 | while (ss >> token) 189 | { 190 | stringstream foo(token); 191 | float x; 192 | foo >> x; 193 | lineData[i] = x; 194 | i++; 195 | } 196 | 197 | if (i == valcount) 198 | { 199 | simple->addParticle(); 200 | for (unsigned int attrIndex=0;attrIndexdataWrite(attrs[attrIndex],particleIndex); 205 | if (attrs[attrIndex].name == "id") 206 | { 207 | data[0]=particleIndex; 208 | } 209 | else 210 | { 211 | data[0] = (int)lineData[4]; 212 | } 213 | 214 | 215 | } 216 | else if (attrs[attrIndex].type==Partio::FLOAT || attrs[attrIndex].type==Partio::VECTOR) 217 | { 218 | float* data=simple->dataWrite(attrs[attrIndex],particleIndex); 219 | 220 | if (attrs[attrIndex].name == "pointColor") 221 | { 222 | // 8 bit color conversion 223 | data[0]=lineData[4]/255; 224 | data[1]=lineData[5]/255; 225 | data[2]=lineData[6]/255; 226 | } 227 | else if (attrs[attrIndex].name == "position") 228 | { 229 | // position, we flip y/z 230 | data[0]=lineData[0]; 231 | data[1]=lineData[2]; 232 | data[2]=lineData[1]; 233 | } 234 | else if (attrs[attrIndex].name == "remission") 235 | { 236 | data[0] = lineData[3]; 237 | } 238 | 239 | } 240 | } 241 | particleIndex++; 242 | } 243 | } 244 | return simple; 245 | } 246 | 247 | /// THIS DOESENT WORK YET>> 248 | /* 249 | bool writePTS(const char* filename,const ParticlesData& p,const bool compressed) 250 | { 251 | unique_ptr output( 252 | compressed ? 253 | Gzip_Out(filename,ios::out|ios::binary) 254 | :new ofstream(filename,ios::out|ios::binary)); 255 | 256 | *output<<"ATTRIBUTES"< attrs; 259 | for (int aIndex=0;aIndex(attrs[attrIndex],particleIndex); 286 | for(int count=0;count(attrs[attrIndex],particleIndex); 290 | for(int count=0;count 37 | #include "../core/Mutex.h" 38 | #include "../Partio.h" 39 | #include "readers.h" 40 | 41 | namespace Partio{ 42 | using namespace std; 43 | 44 | // reader and writer code 45 | typedef ParticlesDataMutable* (*READER_FUNCTION)(const char*,const bool,std::ostream*); 46 | typedef bool (*WRITER_FUNCTION)(const char*,const ParticlesData&,const bool,std::ostream*); 47 | 48 | PartioMutex initializationMutex; 49 | 50 | map& 51 | readers() 52 | { 53 | static map data; 54 | static bool initialized=false; 55 | if(!initialized){ 56 | initializationMutex.lock(); 57 | data["bgeo"]=readBGEO; 58 | data["bhclassic"]=readBGEO; 59 | data["geo"]=readGEO; 60 | data["hclassic"]=readGEO; 61 | data["pdb"]=readPDB; 62 | data["pdb32"]=readPDB32; 63 | data["pdb64"]=readPDB64; 64 | data["pda"]=readPDA; 65 | data["mc"]=readMC; 66 | data["ptc"]=readPTC; 67 | data["pdc"]=readPDC; 68 | data["prt"]=readPRT; 69 | data["bin"]=readBIN; 70 | data["pts"]=readPTS; 71 | data["ptf"]=readPTC; 72 | data["itbl"]=readBGEO; 73 | data["atbl"]=readBGEO; 74 | initialized=true; 75 | initializationMutex.unlock(); 76 | } 77 | return data; 78 | } 79 | 80 | map& 81 | writers() 82 | { 83 | static map data; 84 | static bool initialized=false; 85 | if(!initialized){ 86 | initializationMutex.lock(); 87 | data["bgeo"]=writeBGEO; 88 | data["bhclassic"]=writeBGEO; 89 | data["geo"]=writeGEO; 90 | data["hclassic"]=writeGEO; 91 | data["pdb"]=writePDB; 92 | data["pdb32"]=writePDB32; 93 | data["pdb64"]=writePDB64; 94 | data["pda"]=writePDA; 95 | data["ptc"]=writePTC; 96 | data["rib"]=writeRIB; 97 | data["pdc"]=writePDC; 98 | data["prt"]=writePRT; 99 | data["bin"]=writeBIN; 100 | data["ptf"]=writePTC; 101 | data["itbl"]=writeBGEO; 102 | data["atbl"]=writeBGEO; 103 | initialized=true; 104 | initializationMutex.unlock(); 105 | } 106 | return data; 107 | } 108 | 109 | //! Gives extension of a file ignoring any trailing .gz 110 | //! i.e. for 'foo.pdb.gz' it gives 'pdb', for 'foo.pdb' it gives 'pdb' 111 | bool extensionIgnoringGz(const string& filename,string& ret,bool &endsWithGz,std::ostream& errorStream) 112 | { 113 | size_t period=filename.rfind('.'); 114 | endsWithGz=false; 115 | if(period==string::npos){ 116 | errorStream<<"Partio: No extension detected in filename"<::iterator i=readers().find(extension); 143 | if(i==readers().end()){ 144 | errorStream<<"Partio: No reader defined for extension "<second)(c_filename,false,verbose ? &errorStream : 0); 148 | } 149 | 150 | ParticlesInfo* 151 | readHeaders(const char* c_filename,bool verbose,std::ostream& errorStream) 152 | { 153 | string filename(c_filename); 154 | string extension; 155 | bool endsWithGz; 156 | if(!extensionIgnoringGz(filename,extension,endsWithGz,errorStream)) return 0; 157 | map::iterator i=readers().find(extension); 158 | if(i==readers().end()){ 159 | errorStream<<"Partio: No reader defined for extension "<second)(c_filename,true,verbose ? &errorStream : 0); 163 | } 164 | 165 | void 166 | write(const char* c_filename,const ParticlesData& particles,const bool forceCompressed,bool verbose,std::ostream& errorStream) 167 | { 168 | string filename(c_filename); 169 | string extension; 170 | bool endsWithGz; 171 | if(!extensionIgnoringGz(filename,extension,endsWithGz,errorStream)) return; 172 | map::iterator i=writers().find(extension); 173 | if(i==writers().end()){ 174 | errorStream<<"Partio: No writer defined for extension "<second)(c_filename,particles,forceCompressed || endsWithGz,verbose ? &errorStream : 0); 178 | } 179 | 180 | } // namespace Partio 181 | -------------------------------------------------------------------------------- /src/lib/io/PartioEndian.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #ifndef _partioendian_h_ 37 | #define _partioendian_h_ 38 | 39 | #include 40 | #include 41 | 42 | namespace Partio{ 43 | 44 | #ifdef PartioBIG_ENDIAN 45 | static const bool big_endian=true; 46 | #else 47 | static const bool big_endian=false; 48 | #endif 49 | 50 | template 51 | void endianSwap(T& value) 52 | { 53 | T temp=value; 54 | char* src=(char*)&temp; 55 | char* dest=(char*)&value; 56 | for(unsigned int i=0;i static void swap(T& x){ 63 | if(!big_endian) endianSwap(x); 64 | } 65 | }; 66 | 67 | struct LITEND { 68 | template static void swap(T& x){ 69 | if(big_endian) endianSwap(x); 70 | } 71 | }; 72 | 73 | template inline void 74 | read(std::istream& input,T& d) 75 | { 76 | input.read((char*)&d,sizeof(T)); 77 | E::swap(d); 78 | } 79 | 80 | template inline void 81 | write(std::ostream& output,const T& d) 82 | { 83 | T copy=d; 84 | E::swap(copy); 85 | output.write((char*)©,sizeof(T)); 86 | } 87 | 88 | template 89 | void read(std::istream& input,T1& d1,T2& d2) 90 | {read(input,d1);read(input,d2);} 91 | 92 | template 93 | void read(std::istream& input,T1& d1,T2& d2,T3& d3) 94 | {read(input,d1);read(input,d2,d3);} 95 | 96 | template 97 | void read(std::istream& input,T1& d1,T2& d2,T3& d3,T4& d4) 98 | {read(input,d1);read(input,d2,d3,d4);} 99 | 100 | template 101 | void read(std::istream& input,T1& d1,T2& d2,T3& d3,T4& d4,T5& d5) 102 | {read(input,d1);read(input,d2,d3,d4,d5);} 103 | 104 | template 105 | void read(std::istream& input,T1& d1,T2& d2,T3& d3,T4& d4,T5& d5,T6& d6) 106 | {read(input,d1);read(input,d2,d3,d4,d5,d6);} 107 | 108 | template 109 | void write(std::ostream& output,const T1& d1,const T2& d2) 110 | {write(output,d1);write(output,d2);} 111 | 112 | template 113 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3) 114 | {write(output,d1);write(output,d2,d3);} 115 | 116 | template 117 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3,const T4& d4) 118 | {write(output,d1);write(output,d2,d3,d4);} 119 | 120 | template 121 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3,const T4& d4,const T5& d5) 122 | {write(output,d1);write(output,d2,d3,d4,d5);} 123 | 124 | template 125 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3,const T4& d4,const T5& d5,const T6& d6) 126 | {write(output,d1);write(output,d2,d3,d4,d5,d6);} 127 | 128 | } 129 | #endif 130 | -------------------------------------------------------------------------------- /src/lib/io/RIB.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 - 2011 Sebastien Noury 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "../Partio.h" 25 | #include "../core/ParticleHeaders.h" 26 | #include "ZIP.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace Partio 35 | { 36 | 37 | using namespace std; 38 | 39 | bool writeRIB(const char* filename, const ParticlesData& p, const bool compressed,std::ostream* errorStream) 40 | { 41 | unique_ptr output( 42 | compressed ? Gzip_Out(filename, ios::out | ios::binary) 43 | : new ofstream(filename, ios::out | ios::binary)); 44 | 45 | ParticleAttribute dummy; 46 | bool foundP = p.attributeInfo("position", dummy) || p.attributeInfo("P", dummy); 47 | bool foundP2 = p.attributeInfo("position2", dummy) || p.attributeInfo("P2", dummy); 48 | bool foundWidth = p.attributeInfo("radius", dummy) || p.attributeInfo("width", dummy) || p.attributeInfo("radiusPP", dummy); 49 | 50 | if (!foundP) 51 | { 52 | if(errorStream) *errorStream << "Partio: failed to find attr 'position' or 'P' for RIB output" << endl; 53 | return false; 54 | } 55 | 56 | if (!foundWidth) 57 | if(errorStream) *errorStream << "Partio: failed to find attr 'width','radius', or 'radiusPP' for RIB output, using constantwidth = 1" << endl; 58 | 59 | *output << "version 3.04" << endl; 60 | 61 | if (foundP2) 62 | *output << "GeometricApproximation \"motionfactor\" 1.0" << endl; 63 | 64 | *output << "AttributeBegin" << endl; 65 | *output << " ResourceBegin" << endl; 66 | *output << " Attribute \"identifier\" \"name\" [\"|partioParticle1|partioParticleShape1\"]" << endl; 67 | 68 | int numPasses = foundP2 ? 2 : 1; 69 | 70 | if (foundP2) 71 | *output << " MotionBegin [0.0 1.0]" << endl; 72 | 73 | for (int passIndex = 0; passIndex < numPasses; ++passIndex) 74 | { 75 | *output << (foundP2 ? " " : "") << " Points "; 76 | 77 | for (int attrIndex = 0; attrIndex < p.numAttributes(); ++attrIndex) 78 | { 79 | ParticleAttribute attr; 80 | p.attributeInfo(attrIndex, attr); 81 | 82 | if ((passIndex == 0 && (attr.name == "P2" || attr.name == "position2")) || 83 | (passIndex == 1 && (attr.name == "P" || attr.name == "position"))) continue; 84 | 85 | string attrname = (attr.name == "position" || attr.name == "position2" || attr.name == "P" || attr.name == "P2") 86 | ? "P" 87 | : (attr.name == "radius" ? "width" : attr.name); 88 | 89 | *output << "\"" << attrname << "\" [ "; 90 | int spaceCount = 0; 91 | switch (attr.type) 92 | { 93 | case Partio::FLOAT: 94 | case Partio::VECTOR: 95 | { 96 | for (int particleIndex = 0; particleIndex < p.numParticles(); ++particleIndex) 97 | { 98 | const float *data = p.data(attr, particleIndex); 99 | for (int count = 0; count < attr.count; ++count) 100 | { 101 | *output << data[count] << " "; 102 | spaceCount ++; 103 | } 104 | if (spaceCount > 12) 105 | { 106 | *output << "\n "; 107 | spaceCount = 0; 108 | } 109 | } 110 | break; 111 | } 112 | case Partio::INT: 113 | { 114 | for (int particleIndex = 0; particleIndex < p.numParticles(); ++particleIndex) 115 | { 116 | const int *data = p.data(attr, particleIndex); 117 | for (int count = 0; count < attr.count; ++count) 118 | { 119 | *output << data[count] << " "; 120 | spaceCount ++; 121 | } 122 | if (spaceCount > 12) 123 | { 124 | *output << "\n "; 125 | spaceCount = 0; 126 | } 127 | } 128 | break; 129 | } 130 | case Partio::NONE: 131 | default: 132 | break; 133 | } 134 | 135 | *output << "]\n "; 136 | } 137 | 138 | if (!foundWidth) 139 | *output << "\"constantwidth\" [1.0]"; 140 | 141 | *output << endl; 142 | } 143 | 144 | if (foundP2) 145 | *output << " MotionEnd" << endl; 146 | 147 | *output << " ResourceEnd" << endl; 148 | *output << "AttributeEnd" << endl; 149 | 150 | return true; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/lib/io/ZIP.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #ifndef __ZIP__ 37 | #define __ZIP__ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace Partio{ 46 | struct ZipFileHeader; 47 | //##################################################################### 48 | // Functions Gzip_Out/Gzip_In - Create streams that read/write .gz 49 | //##################################################################### 50 | std::istream* Gzip_In(const std::string& filename,std::ios::openmode mode); 51 | std::ostream* Gzip_Out(const std::string& filename,std::ios::openmode mode); 52 | //##################################################################### 53 | // Class ZipFileWriter 54 | //##################################################################### 55 | class ZipFileWriter 56 | { 57 | std::ofstream ostream; 58 | std::vector files; 59 | public: 60 | 61 | //##################################################################### 62 | ZipFileWriter(const std::string& filename); 63 | virtual ~ZipFileWriter(); 64 | std::ostream* Add_File(const std::string& filename,const bool binary=true); 65 | //##################################################################### 66 | }; 67 | 68 | //##################################################################### 69 | // Class ZipFileReader 70 | //##################################################################### 71 | class ZipFileReader 72 | { 73 | std::ifstream istream; 74 | public: 75 | std::map filename_to_header; 76 | 77 | //##################################################################### 78 | ZipFileReader(const std::string& filename); 79 | virtual ~ZipFileReader(); 80 | std::istream* Get_File(const std::string& filename,const bool binary=true); 81 | void Get_File_List(std::vector& filenames) const; 82 | private: 83 | bool Find_And_Read_Central_Header(); 84 | //##################################################################### 85 | }; 86 | } 87 | #endif 88 | -------------------------------------------------------------------------------- /src/lib/io/pdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | 35 | This code is based on the Gifts/readpdb directory of Autodesk Maya 36 | 37 | NOTE: some modifications were made and "32-bit" versions of the 38 | structures were created to allow us to assume the pointers were 39 | 32-bit integers instead of system dependent pointers. As originally 40 | defined, this format would be architecture dependent (behave 41 | differently on 32-bit and 64-bit architectures). Maya's writers 42 | may or may not also be doing this. If you have any files that 43 | don't work, please let me know. But in general, it would be 44 | difficult/error prone to detect what type the PDB file is. 45 | 46 | */ 47 | 48 | 49 | #define PDB_VECTOR 1 50 | #define PDB_REAL 2 51 | #define PDB_LONG 3 52 | #define PDB_CHAR 4 53 | #define PDB_POINTERT 5 54 | 55 | typedef float Real; 56 | 57 | typedef struct { Real x,y,z; } Vector; 58 | 59 | 60 | typedef struct Channel_Data32 { 61 | int type; 62 | unsigned int datasize; 63 | unsigned int blocksize; 64 | int num_blocks; 65 | unsigned int block; //was void **block; 66 | } Channel_Data32; 67 | 68 | typedef struct { 69 | int type; 70 | unsigned int datasize; 71 | unsigned int blocksize; 72 | int num_blocks; 73 | void **block; 74 | } Channel_Data; 75 | 76 | typedef struct Channel { 77 | 78 | char *name; 79 | int type; 80 | unsigned int size; 81 | unsigned int active_start; 82 | unsigned int active_end; 83 | 84 | char hide; 85 | char disconnect; 86 | Channel_Data *data; 87 | 88 | struct Channel *link; 89 | struct Channel *next; } Channel; 90 | 91 | typedef struct Channel32 { 92 | unsigned int name; 93 | int type; 94 | unsigned int size; 95 | unsigned int active_start; 96 | unsigned int active_end; 97 | 98 | char hide; 99 | char disconnect; 100 | unsigned int data; 101 | 102 | unsigned int link; 103 | unsigned int next; 104 | } Channel32; 105 | 106 | 107 | 108 | typedef struct { 109 | 110 | char magic; 111 | unsigned short swap; 112 | char encoding; 113 | char type; } Channel_io_Header; 114 | 115 | typedef struct { 116 | 117 | int numAttributes; 118 | int numParticles; 119 | float time; 120 | short *types; 121 | char **names; 122 | void **data; } PDBdata; 123 | 124 | typedef struct { 125 | 126 | int numAttributes; 127 | int numParticles; 128 | float time; 129 | short *types; 130 | char **names; 131 | unsigned int data; } PDBdata32; 132 | #define PDB_MAGIC 670 133 | 134 | 135 | typedef struct { 136 | 137 | int magic; 138 | unsigned short swap; 139 | float version; 140 | float time; 141 | unsigned data_size; 142 | unsigned num_data; 143 | 144 | char padding[32]; 145 | 146 | Channel **data; 147 | } PDB_Header; 148 | 149 | 150 | typedef struct { 151 | int magic; 152 | unsigned short swap; 153 | float version; 154 | float time; 155 | unsigned data_size; 156 | unsigned num_data; 157 | 158 | char padding[32]; 159 | 160 | unsigned int data; 161 | } PDB_Header32; 162 | 163 | -------------------------------------------------------------------------------- /src/lib/io/readers.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2011 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #ifndef _READERS_h_ 36 | #define _READERS_h_ 37 | 38 | namespace Partio{ 39 | ParticlesDataMutable* readBGEO( const char* filename,const bool headersOnly,std::ostream* errorStream); 40 | ParticlesDataMutable* readGEO( const char* filename,const bool headersOnly,std::ostream* errorStream); 41 | ParticlesDataMutable* readPDB( const char* filename,const bool headersOnly,std::ostream* errorStream); 42 | ParticlesDataMutable* readPDB32(const char* filename,const bool headersOnly,std::ostream* errorStream); 43 | ParticlesDataMutable* readPDB64(const char* filename,const bool headersOnly,std::ostream* errorStream); 44 | ParticlesDataMutable* readPDA( const char* filename,const bool headersOnly,std::ostream* errorStream); 45 | ParticlesDataMutable* readMC( const char* filename,const bool headersOnly,std::ostream* errorStream); 46 | ParticlesDataMutable* readPTC( const char* filename,const bool headersOnly,std::ostream* errorStream); 47 | ParticlesDataMutable* readPDC( const char* filename,const bool headersOnly,std::ostream* errorStream); 48 | ParticlesDataMutable* readPRT( const char* filename,const bool headersOnly,std::ostream* errorStream); 49 | ParticlesDataMutable* readBIN( const char* filename,const bool headersOnly,std::ostream* errorStream); 50 | ParticlesDataMutable* readPTS( const char* filename,const bool headersOnly,std::ostream* errorStream); 51 | 52 | bool writeBGEO(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 53 | bool writeGEO(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 54 | bool writePDB(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 55 | bool writePDB32(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 56 | bool writePDB64(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 57 | bool writePDA(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 58 | bool writePTC(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 59 | bool writeRIB(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 60 | bool writePDC(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 61 | bool writePRT(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 62 | bool writeBIN(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream); 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/py/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PARTIO SOFTWARE 2 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in 13 | # the documentation and/or other materials provided with the 14 | # distribution. 15 | # 16 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 17 | # Studios" or the names of its contributors may NOT be used to 18 | # endorse or promote products derived from this software without 19 | # specific prior written permission from Walt Disney Pictures. 20 | # 21 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 22 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 23 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 24 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | 34 | 35 | 36 | FIND_PACKAGE(SWIG) 37 | #IF(SWIG_FOUND) 38 | FIND_PACKAGE(PythonLibs) 39 | SET(TEST1 "test1" CACHE STRING "test val 1" FORCE) 40 | IF(PYTHONLIBS_FOUND) 41 | 42 | INCLUDE(${SWIG_USE_FILE}) 43 | 44 | EXECUTE_PROCESS(COMMAND python -c "import sys;print('%s.%s'%sys.version_info[0:2])" 45 | OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) 46 | 47 | SET(TEST1 "test2" CACHE STRING "test val 2" FORCE) 48 | 49 | INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) 50 | 51 | INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) 52 | LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/lib) 53 | 54 | SET(CMAKE_SWIG_FLAGS "") 55 | 56 | # setup output path 57 | SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/py) 58 | SET(CMAKE_SWIG_OUTDIR ${PROJECT_BINARY_DIR}/py) 59 | 60 | INCLUDE_DIRECTORIES(${SEEXPR_INCLUDE_PATH}) 61 | SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES CPLUSPLUS ON) 62 | SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES SWIG_FLAGS "-includeall") 63 | LINK_DIRECTORIES(${SEEXPR_LINK_PATH}) 64 | SWIG_ADD_MODULE(partio python partio.i) 65 | if (${PARTIO_SE_ENABLED}) 66 | SWIG_LINK_LIBRARIES(partio ${PYTHON_LIBRARIES} ${ZLIB_LIBRARY} partio partioSe ${SEEXPR_LIBS}) 67 | else () 68 | SWIG_LINK_LIBRARIES(partio ${PYTHON_LIBRARIES} ${ZLIB_LIBRARY} partio) 69 | endif () 70 | 71 | SET(PYTHON_DEST "${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION}/site-packages" ) 72 | INSTALL(TARGETS _partio DESTINATION ${PYTHON_DEST}) 73 | INSTALL(FILES ${CMAKE_BINARY_DIR}/${outdir}/py/partio.py DESTINATION ${PYTHON_DEST}) 74 | INSTALL(FILES partio.i DESTINATION share/swig) 75 | 76 | ENDIF(PYTHONLIBS_FOUND) 77 | #ENDIF(SWIG_FOUND) 78 | -------------------------------------------------------------------------------- /src/py/example/circle.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # PARTIO SOFTWARE 4 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # 18 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 19 | # Studios" or the names of its contributors may NOT be used to 20 | # endorse or promote products derived from this software without 21 | # specific prior written permission from Walt Disney Pictures. 22 | # 23 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 24 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 25 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 26 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 27 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 28 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 32 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 35 | 36 | import partio 37 | 38 | # create a particle set and attributes 39 | p=partio.create() 40 | position=p.addAttribute("position",partio.VECTOR,3) 41 | color=p.addAttribute("Cd",partio.FLOAT,3) 42 | radius=p.addAttribute("radius",partio.FLOAT,1) 43 | normal=p.addAttribute("normal",partio.VECTOR,3) 44 | 45 | # make a spiral circle thingy 46 | t=0 47 | dt=.01 48 | import math 49 | 50 | while t<2*math.pi: 51 | # allocate new particle 52 | i=p.addParticle() 53 | 54 | # set particle attributes 55 | r=.25*math.sin(10*t)+1. 56 | x,y,z=-r*math.sin(t),0,r*math.cos(t) 57 | 58 | p.set(position,i,(x,y,z)) 59 | p.set(color,i,(t/2./math.pi,1-(t/2./math.pi),0)) 60 | p.set(radius,i,(.02,)) 61 | p.set(normal,i,(0,1,0)) 62 | foo=p.get(position,i) 63 | 64 | t+=dt 65 | 66 | # Write to a point cloud 67 | partio.write("spiral.ptc",p) 68 | -------------------------------------------------------------------------------- /src/py/example/listAttr.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # PARTIO SOFTWARE 4 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in 15 | # the documentation and/or other materials provided with the 16 | # distribution. 17 | # 18 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 19 | # Studios" or the names of its contributors may NOT be used to 20 | # endorse or promote products derived from this software without 21 | # specific prior written permission from Walt Disney Pictures. 22 | # 23 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 24 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 25 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 26 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 27 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 28 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 32 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 35 | 36 | import sys 37 | import papi 38 | 39 | if __name__=="__main__": 40 | filename=None 41 | try: 42 | filename=sys.argv[1] 43 | except: 44 | print "Usage: listAttr.py " 45 | sys.exit(1) 46 | 47 | # read particle name 48 | p=papi.read(filename) 49 | 50 | for i in range(p.numAttributes()): 51 | attr=p.attributeInfo(i) 52 | typeStr="NONE" 53 | if attr.type==papi.VECTOR: typeStr="VECTOR" 54 | if attr.type==papi.FLOAT: typeStr="FLOAT" 55 | if attr.type==papi.INT: typeStr="INT" 56 | print "%10s[%d] %-30s "%(typeStr,attr.count,attr.name) 57 | 58 | -------------------------------------------------------------------------------- /src/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PARTIO SOFTWARE 2 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in 13 | # the documentation and/or other materials provided with the 14 | # distribution. 15 | # 16 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 17 | # Studios" or the names of its contributors may NOT be used to 18 | # endorse or promote products derived from this software without 19 | # specific prior written permission from Walt Disney Pictures. 20 | # 21 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 22 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 23 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 24 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | 34 | link_directories(${CMAKE_BINARY_DIR}/src/lib) 35 | 36 | foreach(item testiterator test testcache testclonecopy testcluster teststr makecircle makeline testkdtree) 37 | ADD_EXECUTABLE(${item} "${item}.cpp") 38 | target_link_libraries(${item} ${PARTIO_LIBRARIES}) 39 | install(TARGETS ${item} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/partio/test) 40 | endforeach(item) 41 | -------------------------------------------------------------------------------- /src/tests/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #ifndef _timer_h_ 37 | #define _timer_h_ 38 | 39 | #ifndef PARTIO_WIN32 40 | 41 | #include 42 | #include 43 | 44 | struct Timer 45 | { 46 | const char* name; 47 | struct timeval start; 48 | bool running; 49 | 50 | Timer(const char* name) 51 | :name(name) 52 | { 53 | gettimeofday(&start,0); 54 | running=true; 55 | } 56 | 57 | double Stop_Time() 58 | { 59 | struct timeval end; 60 | gettimeofday(&end,0); 61 | double seconds=(double)1e-6*(double)((end.tv_sec * 1000000 + end.tv_usec) 62 | - (start.tv_sec * 1000000 + start.tv_usec)); 63 | std::cerr<<"Time for '"< 78 | #include 79 | 80 | struct Timer 81 | { 82 | const char* name; 83 | bool running; 84 | 85 | __int64 start; 86 | __int64 counts_per_sec; 87 | 88 | Timer(const char* name) 89 | :name(name) 90 | { 91 | QueryPerformanceFrequency((LARGE_INTEGER*)&counts_per_sec); 92 | QueryPerformanceCounter((LARGE_INTEGER*)&start); 93 | running=true; 94 | } 95 | 96 | double Stop_Time() 97 | { 98 | __int64 end; 99 | QueryPerformanceCounter((LARGE_INTEGER*)&end); 100 | double seconds=float(end-start)/float(counts_per_sec); 101 | std::cerr<<"Time for '"< 37 | #include 38 | #ifdef PARTIO_WIN32 39 | #define M_PI (3.14159265359893238) 40 | #endif 41 | 42 | #include 43 | 44 | using namespace Partio; 45 | 46 | int main(int argc,char *argv[]) 47 | { 48 | ParticlesDataMutable* p=create(); 49 | ParticleAttribute positionAttr=p->addAttribute("position",VECTOR,3); 50 | ParticleAttribute normalAttr=p->addAttribute("normal",VECTOR,3); 51 | int n=30; 52 | for(int i=0;iaddParticle(); 54 | float* pos=p->dataWrite(positionAttr,particle); 55 | float* norm=p->dataWrite(normalAttr,particle); 56 | float theta=i*2*M_PI/(float)n; 57 | pos[2]=cos(theta); 58 | pos[0]=sin(theta); 59 | pos[1]=0; 60 | norm[0]=cos(theta); 61 | norm[2]=-sin(theta); 62 | norm[1]=0; 63 | 64 | } 65 | write("circle.00001.bgeo",*p); 66 | write("circle.00001.geo",*p); 67 | write("circle.00001.bin",*p); 68 | write("circle.00001.pdc",*p); 69 | write("circle.00001.pdb",*p); 70 | write("circle.00001.pda",*p); 71 | write("circle.00001.ptc",*p); 72 | write("circle.00001.rib",*p); 73 | write("circle.00001.mc",*p); 74 | 75 | 76 | p->release(); 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /src/tests/makeline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | int main(int argc,char *argv[]) 41 | { 42 | 43 | Partio::ParticlesDataMutable* particles=Partio::createInterleave(); 44 | 45 | particles->addParticles(10); 46 | 47 | Partio::ParticleAttribute position=particles->addAttribute("position",Partio::VECTOR,3); 48 | Partio::ParticleAttribute id=particles->addAttribute("id",Partio::INT,1); 49 | 50 | 51 | 52 | Partio::ParticlesDataMutable::iterator it=particles->begin(); 53 | Partio::ParticleAccessor positionAccess(position); 54 | it.addAccessor(positionAccess); 55 | Partio::ParticleAccessor idAccess(id); 56 | it.addAccessor(idAccess); 57 | 58 | float x=0; 59 | int idCounter=0; 60 | for(;it!=particles->end();++it){ 61 | Partio::Data& P=positionAccess.data >(it); 62 | Partio::Data& id=idAccess.data >(it); 63 | P[0]=x;P[1]=-x;P[2]=0; 64 | id[0]=idCounter; 65 | x+=1.; 66 | idCounter++; 67 | } 68 | 69 | Partio::write("test.bgeo",*particles); 70 | Partio::write("test.geo",*particles); 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/tests/test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | 37 | #include 38 | #include 39 | 40 | Partio::ParticlesDataMutable* makeData() 41 | { 42 | Partio::ParticlesDataMutable& foo=*Partio::create(); 43 | Partio::ParticleAttribute positionAttr=foo.addAttribute("position",Partio::VECTOR,3); 44 | Partio::ParticleAttribute lifeAttr=foo.addAttribute("life",Partio::FLOAT,2); 45 | Partio::ParticleAttribute idAttr=foo.addAttribute("id",Partio::INT,1); 46 | 47 | for(int i=0;i<5;i++){ 48 | Partio::ParticleIndex index=foo.addParticle(); 49 | float* pos=foo.dataWrite(positionAttr,index); 50 | float* life=foo.dataWrite(lifeAttr,index); 51 | int* id=foo.dataWrite(idAttr,index); 52 | 53 | pos[0]=.1*i; 54 | pos[1]=.1*(i+1); 55 | pos[2]=.1*(i+2); 56 | life[0]=-1.2+i; 57 | life[1]=10.; 58 | id[0]=index; 59 | 60 | } 61 | return &foo; 62 | } 63 | 64 | void testEmptySaveLoad(const char* filename) 65 | { 66 | Partio::ParticlesDataMutable* p=Partio::create(); 67 | p->addAttribute("position",Partio::VECTOR,3); 68 | std::cerr<<"Testing empty save with file '"<release(); 71 | Partio::ParticlesDataMutable* pread=Partio::read(filename); 72 | pread->release(); 73 | } 74 | 75 | void testSaveLoad(Partio::ParticlesData* p,const char* filename) 76 | { 77 | std::cerr<<"Testing with file '"<release(); 81 | } 82 | 83 | int main(int argc,char *argv[]) 84 | { 85 | { 86 | Partio::ParticlesDataMutable* foo=makeData(); 87 | testSaveLoad(foo,"test.bgeo"); 88 | testSaveLoad(foo,"test.bgeo.gz"); 89 | testSaveLoad(foo,"test.geo"); 90 | testSaveLoad(foo,"test.geo.gz"); 91 | testSaveLoad(foo,"test.ptc"); 92 | testSaveLoad(foo,"test.ptc.gz"); 93 | testSaveLoad(foo,"test.pdb"); 94 | testSaveLoad(foo,"test.pdb.gz"); 95 | testEmptySaveLoad("testEmpty.geo"); 96 | testEmptySaveLoad("testEmpty.bgeo"); 97 | testEmptySaveLoad("testEmpty.pdb"); 98 | testEmptySaveLoad("testEmpty.ptc"); 99 | foo->release(); 100 | } 101 | 102 | 103 | return 0; 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/tests/testcache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include 36 | #include 37 | #include 38 | 39 | int main(int argc,char* argv[]) 40 | { 41 | Partio::ParticlesDataMutable* p=Partio::create(); 42 | Partio::ParticleAttribute attr=p->addAttribute("position",Partio::VECTOR,3); 43 | p->addParticle(); 44 | float* pos=p->dataWrite(attr,0); 45 | pos[0]=1;pos[1]=2;pos[2]=3; 46 | Partio::write("/tmp/test.bgeo",*p); 47 | p->release(); 48 | 49 | Partio::ParticlesInfo* p1=Partio::readCached("/tmp/test.bgeo",false); 50 | Partio::ParticlesInfo* p2=Partio::readCached("/tmp/test.bgeo",false); 51 | assert(p1==p2); 52 | p1->release();p2->release(); 53 | Partio::ParticlesInfo* p3=Partio::readCached("/tmp/test.bgeo",false); 54 | p3->release(); 55 | //assert(p2!=p3); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/tests/testcluster.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | 37 | #include 38 | #include 39 | 40 | int main(int argc,char *argv[]) 41 | { 42 | Partio::ParticlesDataMutable* p=Partio::read("/tmp/scatter.bgeo"); 43 | Partio::ParticlesDataMutable* c=Partio::computeClustering(p,5,1.5,100,2,5); 44 | Partio::write("/tmp/cluster.bgeo",*c); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/tests/testiterator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "Timer.h" 42 | 43 | int main(int argc,char *argv[]) 44 | { 45 | Timer* timer=new Timer("make array"); 46 | 47 | Partio::ParticlesDataMutable& foo=*Partio::create(); 48 | int nParticles=10000000; 49 | foo.addParticles(nParticles); 50 | Partio::ParticleAttribute position=foo.addAttribute("position",Partio::VECTOR,3); 51 | Partio::ParticleAttribute radius=foo.addAttribute("radius",Partio::FLOAT,1); 52 | Partio::ParticleAttribute life=foo.addAttribute("life",Partio::FLOAT,2); 53 | delete timer; 54 | 55 | { 56 | 57 | Timer timer("write data"); 58 | for(int i=0;i(position,i); 60 | float* rad=foo.dataWrite(radius,i); 61 | float* lifeVal=foo.dataWrite(life,i); 62 | pos[0]=i;pos[1]=2*i;pos[2]=3*i; 63 | rad[0]=.1*i; 64 | lifeVal[0]=.01*i; 65 | lifeVal[1]=1.; 66 | //std::cerr<<"writing data "<& X=Xacc.data >(it); 76 | // Partio::Data& X=it.data >(position); 77 | //const Partio::Data& r=it.data >(radius); 78 | //const Partio::Data& l=it.data >(life); 79 | 80 | // std::cerr<<"write guy X="<& X=Xacc.data >(it); 102 | const Partio::Data& r=racc.data >(it); 103 | const Partio::Data& l=lacc.data >(it); 104 | 105 | // std::cerr<<"guy X="<(position,i); 119 | const float* r=fooc.data(radius,i); 120 | const float* l=fooc.data(life,i); 121 | 122 | // std::cerr<<"guy X="<(position,0); 145 | const float* r=fooc.data(radius,0); 146 | const float* l=fooc.data(life,0); 147 | for(int i=0;i 38 | #include 39 | #include 40 | #include 41 | #define GRIDN 9 42 | 43 | 44 | #define TESTASSERT(x)\ 45 | if(!(x)) throw std::runtime_error(__FILE__ ": Test failed on " #x ); 46 | 47 | 48 | Partio::ParticlesDataMutable* makeData() 49 | { 50 | Partio::ParticlesDataMutable& foo=*Partio::create(); 51 | Partio::ParticleAttribute positionAttr=foo.addAttribute("position",Partio::VECTOR,3); 52 | Partio::ParticleAttribute idAttr=foo.addAttribute("id",Partio::INT,1); 53 | 54 | 55 | std::cout << "Inserting points ...\n"; 56 | for (int i = 0; i < GRIDN; i++) 57 | for (int j = 0; j < GRIDN; ++j) 58 | for (int k = 0; k < GRIDN; ++k) { 59 | Partio::ParticleIndex pi = foo.addParticle(); 60 | float* pos = foo.dataWrite(positionAttr, pi); 61 | int* id = foo.dataWrite(idAttr, pi); 62 | 63 | pos[0] = i * 1.0f / (GRIDN - 1); 64 | pos[1] = j * 1.0f / (GRIDN - 1); 65 | pos[2] = k * 1.0f / (GRIDN - 1); 66 | id[0]= i * 100 + j * 10 + k; 67 | } 68 | std::cout << "Building tree ...\n"; 69 | foo.sort(); 70 | std::cout << "Done\n"; 71 | return &foo; 72 | } 73 | 74 | int main(int argc,char *argv[]) 75 | { 76 | Partio::ParticlesDataMutable* foo=makeData(); 77 | Partio::ParticleAttribute posAttr; 78 | TESTASSERT (foo->attributeInfo("position", posAttr)); 79 | 80 | 81 | std::cout << "Testing lookup with stl types ...\n"; 82 | { 83 | std::vector indices; 84 | std::vector dists; 85 | float point[3] = {0.51, 0.52, 0.53}; 86 | 87 | foo->findNPoints(point, 5, 0.15f, indices, dists); 88 | TESTASSERT (indices.size() == 5); 89 | 90 | const float *pos = foo->data(posAttr, indices[0]); 91 | TESTASSERT (pos[0] == 0.375f && pos[1] == 0.5 && pos[2] == 0.5); 92 | pos = foo->data(posAttr, indices[1]); 93 | TESTASSERT (pos[0] == 0.625 && pos[1] == 0.5 && pos[2] == 0.5); 94 | pos = foo->data(posAttr, indices[2]); 95 | TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.625); 96 | pos = foo->data(posAttr, indices[3]); 97 | TESTASSERT (pos[0] == 0.5 && pos[1] == 0.625 && pos[2] == 0.5); 98 | pos = foo->data(posAttr, indices[4]); 99 | TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.5); 100 | 101 | std::cout << "Test passed\n"; 102 | } 103 | std::cout << "Testing lookup with pod types ...\n"; 104 | { 105 | uint64_t indices[10]; 106 | float dists[10]; 107 | float point[3] = {0.51, 0.52, 0.53}; 108 | 109 | float finalDist; 110 | int returned=foo->findNPoints(point, 5, 0.15f, indices, dists,&finalDist); 111 | TESTASSERT(returned == 5); 112 | 113 | const float *pos = foo->data(posAttr, indices[0]); 114 | TESTASSERT (pos[0] == 0.375f && pos[1] == 0.5 && pos[2] == 0.5); 115 | pos = foo->data(posAttr, indices[1]); 116 | TESTASSERT (pos[0] == 0.625 && pos[1] == 0.5 && pos[2] == 0.5); 117 | pos = foo->data(posAttr, indices[2]); 118 | TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.625); 119 | pos = foo->data(posAttr, indices[3]); 120 | TESTASSERT (pos[0] == 0.5 && pos[1] == 0.625 && pos[2] == 0.5); 121 | pos = foo->data(posAttr, indices[4]); 122 | TESTASSERT (pos[0] == 0.5 && pos[1] == 0.5 && pos[2] == 0.5); 123 | 124 | std::cout << "Test passed\n"; 125 | } 126 | foo->release(); 127 | 128 | return 0; 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/tests/teststr.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace Partio; 10 | 11 | void failure(const std::string& x) 12 | { 13 | std::cerr<<"teststr failed "<addAttribute("position",VECTOR,3); 22 | ParticleAttribute fileAttr=p->addAttribute("filename",INDEXEDSTR,1); 23 | ParticleAttribute stateAttr=p->addAttribute("state",INDEXEDSTR,1); 24 | 25 | int test1Token=p->registerIndexedStr(fileAttr,"test1"); 26 | int test2Token=p->registerIndexedStr(fileAttr,"test2 with space"); 27 | 28 | int aliveState=p->registerIndexedStr(stateAttr,"alive"); 29 | int deadState=p->registerIndexedStr(stateAttr,"dead"); 30 | int zombieState=p->registerIndexedStr(stateAttr,"zombie"); 31 | int stateChoices[]={aliveState,deadState,zombieState}; 32 | 33 | for(int i=0;i<10;i++){ 34 | p->addParticle(); 35 | float* f=p->dataWrite(posAttr,i); 36 | int* tok=p->dataWrite(fileAttr,i); 37 | int* state=p->dataWrite(stateAttr,i); 38 | tok[0]=i%2==0 ? test1Token : test2Token; 39 | state[0]=stateChoices[i%3]; 40 | f[0]=i; 41 | f[1]=0; 42 | f[2]=0; 43 | } 44 | 45 | 46 | Partio::write("foo.bgeo",*p); 47 | p->release(); 48 | } 49 | 50 | { 51 | ParticlesDataMutable* p=Partio::read("foo.bgeo"); 52 | if(!p) failure("failed to get foo.bgeo"); 53 | ParticleAttribute posAttr,fileAttr,stateAttr; 54 | if(!p->attributeInfo("position",posAttr)) failure("couldn't get position"); 55 | if(!p->attributeInfo("filename",fileAttr)) failure("couldn't get filnename"); 56 | if(!p->attributeInfo("state",stateAttr)) failure("couldn't get state"); 57 | 58 | 59 | // lookup the string codes in a way that is efficient to check later 60 | int alive=p->lookupIndexedStr(stateAttr,"alive"); 61 | int dead=p->lookupIndexedStr(stateAttr,"dead"); 62 | int zombie=p->lookupIndexedStr(stateAttr,"zombie"); 63 | int states[]={alive,dead,zombie}; // every ith particle should be asigned these in order 64 | if(alive == -1 || dead == -1 || zombie == -1){ std::cerr<<"don't have tokens I expect!"<numParticles();i++){ 67 | //const int* tok=p->data(fileAttr,i); 68 | const int* state=p->data(stateAttr,i); 69 | 70 | // Note this is not what you would like to do ideally because it uses strings a lot! 71 | //std::cerr<<"Particle index "<indexedStrs(fileAttr)[num]<< 72 | // " state is "<indexedStrs(stateAttr)[state[0]]<release(); 79 | } 80 | return 0; 81 | } 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # PARTIO SOFTWARE 2 | # Copyright 2010 Disney Enterprises, Inc. All rights reserved 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are 6 | # met: 7 | # 8 | # * Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 11 | # * Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in 13 | # the documentation and/or other materials provided with the 14 | # distribution. 15 | # 16 | # * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 17 | # Studios" or the names of its contributors may NOT be used to 18 | # endorse or promote products derived from this software without 19 | # specific prior written permission from Walt Disney Pictures. 20 | # 21 | # Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 22 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 23 | # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 24 | # FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 25 | # IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 26 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | 34 | include_directories( 35 | ${CMAKE_SOURCE_DIR}/src/lib 36 | ) 37 | 38 | link_directories(${CMAKE_BINARY_DIR}/src/lib) 39 | 40 | IF(GLUT_FOUND AND OPENGL_FOUND) 41 | INCLUDE_DIRECTORIES(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) 42 | ADD_EXECUTABLE(partview partview.cpp) 43 | target_link_libraries(partview ${PARTIO_LIBRARIES} ${GLUT_LIBRARY} ${OPENGL_LIBRARY}) 44 | install(TARGETS partview DESTINATION ${CMAKE_INSTALL_BINDIR}) 45 | ENDIF(GLUT_FOUND AND OPENGL_FOUND) 46 | 47 | ADD_EXECUTABLE(partinfo partinfo.cpp) 48 | target_link_libraries(partinfo ${PARTIO_LIBRARIES}) 49 | 50 | ADD_EXECUTABLE(partconv partconv.cpp) 51 | target_link_libraries(partconv ${PARTIO_LIBRARIES}) 52 | 53 | ADD_EXECUTABLE(partattr partattr.cpp) 54 | target_link_libraries(partattr ${PARTIO_LIBRARIES}) 55 | 56 | install(TARGETS partattr partconv partinfo DESTINATION ${CMAKE_INSTALL_BINDIR}) 57 | -------------------------------------------------------------------------------- /src/tools/Camera.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | #ifndef _Camera_h_ 37 | #define _Camera_h_ 38 | 39 | #include 40 | 41 | #ifdef PARTIO_WIN32 42 | #define M_PI 3.141592653589793238 43 | #endif 44 | 45 | class Camera 46 | { 47 | public: 48 | Partio::Vec3 lookAt; 49 | float theta; 50 | float phi; 51 | float distance; 52 | 53 | Camera() 54 | :lookAt(0,0,0), 55 | theta(0.8),phi(0.3), 56 | distance(3), 57 | tumble(false),pan(false),zoom(false) 58 | {} 59 | 60 | void look() const 61 | { 62 | Partio::Vec3 view=distance*Partio::Vec3(sin(theta)*cos(phi),sin(phi),cos(theta)*cos(phi)); 63 | Partio::Vec3 up=distance*Partio::Vec3(sin(theta)*cos(phi+M_PI/2),sin(phi+M_PI/2),cos(theta)*cos(phi+M_PI/2)); 64 | Partio::Vec3 eye=lookAt+view; 65 | // Vec3 up(0,1,0); 66 | gluLookAt(eye.x,eye.y,eye.z,lookAt.x,lookAt.y,lookAt.z,up.x,up.y,up.z); 67 | //std::cout<<"eye "<x=x;this->y=y;tumble=true;} 78 | 79 | void startPan(const int x,const int y) 80 | {this->x=x;this->y=y;pan=true;} 81 | 82 | void startZoom(const int x,const int y) 83 | {this->x=x;this->y=y;zoom=true;} 84 | 85 | void update(const int x,const int y) 86 | { 87 | if(tumble){ 88 | theta+=-(x-this->x)*M_PI/180.; 89 | phi+=(y-this->y)*M_PI/180.; 90 | }else if(pan){ 91 | Partio::Vec3 view=Partio::Vec3(sin(theta)*cos(phi),sin(phi),cos(theta)*cos(phi)); 92 | Partio::Vec3 up=Partio::Vec3(sin(theta)*cos(phi+M_PI/2),sin(phi+M_PI/2),cos(theta)*cos(phi+M_PI/2)); 93 | Partio::Vec3 right=view.normalized().cross(up.normalized()).normalized(); 94 | lookAt+=right*distance*.001*(x-this->x); 95 | lookAt+=up*distance*.001*(y-this->y); 96 | }else if(zoom){ 97 | int move=y-this->y; 98 | distance*=exp(move*.01); 99 | } 100 | this->x=x;this->y=y; 101 | } 102 | 103 | void stop() 104 | {tumble=pan=zoom=false;} 105 | 106 | void fit(const float fov,const Partio::Vec3& boxmin,const Partio::Vec3& boxmax) 107 | { 108 | lookAt=.5*(boxmin+boxmax); 109 | Partio::Vec3 edges=boxmax-boxmin; 110 | float half_extent=.5*std::max(edges.x,std::max(edges.y,edges.z)); 111 | distance=std::max(1e-3,half_extent/tan(.5*fov*M_PI/180.)); 112 | } 113 | }; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /src/tools/partattr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | // Original contributor drakeguan on github 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int main(int argc,char *argv[]) 43 | { 44 | if(argc != 3){ 45 | std::cerr<<"Usage is: "< { particle attribute to print info } "<attributeInfo(argv[2], attrhandle); 52 | 53 | for(int i = 0; i < std::min(10, p->numParticles()); i++){ 54 | const float* data = p->data(attrhandle,i); 55 | std::cout << argv[2] << i << " "; 56 | for(int j = 0; j < attrhandle.count; j++){ 57 | std::cout << data[j] << " "; 58 | } 59 | std::cout << std::endl; 60 | } 61 | 62 | p->release(); 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /src/tools/partconv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include 36 | #include 37 | 38 | int main(int argc,char *argv[]) 39 | { 40 | if(argc!=3){ 41 | std::cerr<<"Usage is: "< "<release(); 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /src/tools/partconvert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include "Partio.h" 36 | #include 37 | #include 38 | 39 | int main(int argc,char *argv[]) 40 | { 41 | if(argc!=2){ 42 | std::cerr<<"Usage is: "<"<release(); 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /src/tools/partinfo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | int main(int argc,char *argv[]) 41 | { 42 | if(argc<2){ 43 | std::cerr<<"Usage is: "< { particle indices to print full info } "<numParticles()<numAttributes(); 50 | std::cout<attributeInfo(i,attr); 55 | std::cout<attributeInfo("position",positionhandle); 62 | if(argc==2){ 63 | for(int i=0;inumParticles());i++){ 64 | const float* data=p->data(positionhandle,i);; 65 | std::cout<<"particle "<p->numParticles() || particleIndex<0){ 73 | std::cout<<"OUT OF RANGE"<attributeInfo(i,attr); 78 | std::cout<data(attr,particleIndex)[ii]; 82 | std::cout<<" "<indexedStrs(attr).size();index++){ 84 | std::cout<indexedStrs(attr)[index]<<"'"; 85 | } 86 | }else if(attr.type==Partio::INT) std::cout<<" "<data(attr,particleIndex)[ii]; 87 | else std::cout<<" "<data(attr,particleIndex)[ii]; 88 | } 89 | std::cout<numFixedAttributes(); 96 | if (numFixedAttr) { 97 | std::cout<<"---------------------------"<fixedAttributeInfo(i,attr); 104 | std::cout<fixedAttributeInfo(i,attr); 112 | std::cout<fixedData(attr)[ii]; 116 | std::cout<<" "<fixedIndexedStrs(attr).size();index++){ 118 | std::cout<fixedIndexedStrs(attr)[index]<<"'"; 119 | } 120 | }else if(attr.type==Partio::INT) std::cout<<" "<fixedData(attr)[ii]; 121 | else std::cout<<" "<fixedData(attr)[ii]; 122 | } 123 | std::cout<release(); 128 | } 129 | 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /src/tools/partview.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #if defined(__DARWIN__) || defined(__APPLE__) 45 | #include 46 | #else 47 | #include 48 | #endif 49 | #include 50 | 51 | #include 52 | #include "Camera.h" 53 | 54 | using namespace Partio; 55 | using namespace std; 56 | 57 | 58 | // global vars 59 | ParticlesData* particles; 60 | ParticlesData* connectivity; 61 | 62 | 63 | Camera camera; 64 | ParticleAttribute positionAttr; 65 | ParticleAttribute colorAttr; 66 | ParticleAttribute alphaAttr; 67 | 68 | ParticleAttribute attr1; 69 | ParticleAttribute attr2; 70 | 71 | int numPoints; 72 | int frameNumberOGL; 73 | GLuint PreviousClock; 74 | double fov; 75 | double pointSize; 76 | double brightness; 77 | 78 | bool useColor; 79 | bool useAlpha; 80 | bool sourceChanged; 81 | bool frameForwardPressed; 82 | bool frameBackwardPressed; 83 | bool brightnessUpPressed; 84 | bool brightnessDownPressed; 85 | bool* keyStates; 86 | bool frameMissing; 87 | bool anyKeyPressed; 88 | bool colorMissing; 89 | bool alphaMissing; 90 | 91 | string loadError; 92 | string particleFile; 93 | string lastParticleFile; 94 | string connectivityFile; 95 | string lastConnectivityFile; 96 | 97 | void restorePerspectiveProjection(); 98 | void setOrthographicProjection(); 99 | void renderBitmapString( float x,float y,float z,void *font,char *string); 100 | static void render(); 101 | void reloadParticleFile(int direction); 102 | static void mouseFunc(int button,int state,int x,int y); 103 | static void motionFunc(int x,int y); 104 | static void processNormalKeys(unsigned char key, int x, int y); 105 | static void processNormalUpKeys(unsigned char key, int x, int y); 106 | static void processSpecialKeys(int key, int x, int y); 107 | static void processSpecialUpKeys(int key, int x, int y); 108 | void timer(); 109 | 110 | int main(int argc,char *argv[]); 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | --------------------------------------------------------------------------------