├── .workonrc.products ├── src ├── data │ ├── base.bgeo │ ├── delta.bgeo │ ├── json.bgeo │ ├── test.bgeo │ ├── test.pdb │ ├── scatter.bgeo │ ├── reindeer.bgeo │ └── test.geo ├── doc │ ├── figures │ │ └── circleFigure.png │ ├── main.txt │ ├── license.txt │ ├── cpptut.txt │ ├── CMakeLists.txt │ ├── tutorial.txt │ └── partio.tex ├── Makefile ├── tests │ ├── testpartjson.py │ ├── testcluster.cpp │ ├── testcache.cpp │ ├── CMakeLists.txt │ ├── makeline.cpp │ ├── makecircle.cpp │ ├── teststr.cpp │ ├── Timer.h │ ├── testio.cpp │ ├── testkdtree.cpp │ ├── testmerge.cpp │ └── testiterator.cpp ├── lib │ ├── core │ │ ├── ParticleCaching.h │ │ ├── Mutex.h │ │ ├── ParticleCaching.cpp │ │ ├── ParticleHeaders.h │ │ ├── ParticleSimple.h │ │ ├── ParticleSimpleInterleave.h │ │ └── ParticleHeaders.cpp │ ├── CMakeLists.txt │ ├── PartioVec3.h │ ├── io │ │ ├── ZIP.h │ │ ├── readers.h │ │ ├── PartioEndian.h │ │ ├── pdb.h │ │ ├── RIB.cpp │ │ ├── PDC.cpp │ │ ├── ParticleIO.cpp │ │ └── PDA.cpp │ ├── PartioAttribute.h │ └── PartioIterator.h ├── tools │ ├── partconvert.cpp │ ├── CMakeLists.txt │ ├── partattr.cpp │ ├── partview.h │ ├── Camera.h │ ├── partjson.py │ └── partinfo.cpp └── py │ ├── example │ ├── listAttr.py │ └── circle.py │ └── CMakeLists.txt ├── .gitignore ├── Makefile ├── LICENSE ├── CMakeLists.txt └── README.md /.workonrc.products: -------------------------------------------------------------------------------- 1 | partio 2 | -------------------------------------------------------------------------------- /src/data/base.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/base.bgeo -------------------------------------------------------------------------------- /src/data/delta.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/delta.bgeo -------------------------------------------------------------------------------- /src/data/json.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/json.bgeo -------------------------------------------------------------------------------- /src/data/test.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/test.bgeo -------------------------------------------------------------------------------- /src/data/test.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/test.pdb -------------------------------------------------------------------------------- /src/data/scatter.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/scatter.bgeo -------------------------------------------------------------------------------- /src/data/reindeer.bgeo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/data/reindeer.bgeo -------------------------------------------------------------------------------- /src/doc/figures/circleFigure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anderslanglands/partio/master/src/doc/figures/circleFigure.png -------------------------------------------------------------------------------- /.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 | workspace.mel 25 | -------------------------------------------------------------------------------- /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/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 | partconvert.o: partconf.cpp Particle.h 29 | -------------------------------------------------------------------------------- /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/tests/testpartjson.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for partjson - back and forth 5 | """ 6 | 7 | __copyright__ = """ 8 | CONFIDENTIAL INFORMATION: This software is the confidential and 9 | proprietary information of Walt Disney Animation Studios ("WDAS"). 10 | This software may not be used, disclosed, reproduced or distributed 11 | for any purpose without prior written authorization and license 12 | from WDAS. Reproduction of any section of this software must 13 | include this legend and all copyright notices. 14 | Copyright Disney Enterprises, Inc. All rights reserved. 15 | """ 16 | 17 | import os, unittest 18 | import partjson, partio 19 | 20 | 21 | class test(unittest.TestCase): 22 | """ Test json conversions """ 23 | 24 | def testPartJson(self): 25 | """ Test round-tripping """ 26 | 27 | testdir = os.path.dirname(os.path.abspath(__file__)) 28 | srcdir = os.path.dirname(testdir) 29 | filename = os.path.join(srcdir, 'data', 'json.bgeo') 30 | particleSet = partio.read(filename) 31 | json1 = partjson.toJson(particleSet) 32 | particleSet2 = partjson.fromJson(json1) 33 | json2 = partjson.toJson(particleSet2) 34 | self.assertEquals(json1, json2) 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /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 | lib ?= lib64 7 | FLAVOR ?= optimize 8 | platformdir ?= $(uname_S)-$(uname_R)-$(uname_M)-$(FLAVOR) 9 | builddir ?= $(CURDIR)/build/$(platformdir) 10 | 11 | prefix ?= $(CURDIR)/$(platformdir) 12 | #DESTDIR = 13 | 14 | CMAKE_FLAGS = 15 | # Allow out-of-band customization 16 | -include Makefile.config 17 | 18 | ifdef V 19 | VERBOSE=1 20 | export VERBOSE 21 | endif 22 | 23 | # Installation location: prefix= 24 | CMAKE_FLAGS += -DCMAKE_INSTALL_PREFIX=$(prefix) 25 | 26 | # gtest location: RP_gtest= 27 | ifdef RP_gtest 28 | CMAKE_FLAGS += -DGTEST_LOCATION=$(RP_gtest) 29 | CMAKE_FLAGS += -DGTEST_ENABLED=1 30 | endif 31 | 32 | # Extra cmake flags: CMAKE_EXTRA_FLAGS= 33 | ifdef CMAKE_EXTRA_FLAGS 34 | CMAKE_FLAGS += $(CMAKE_EXTRA_FLAGS) 35 | endif 36 | 37 | ifdef RP_zlib 38 | CMAKE_FLAGS += -DZLIB_INCLUDE_DIR=$(RP_zlib)/include 39 | CMAKE_FLAGS += -DZLIB_LIBRARY_RELEASE=$(RP_zlib)/$(lib)/libz.so 40 | endif 41 | 42 | # The default target in this Makefile is... 43 | all:: 44 | 45 | install: all 46 | $(MAKE) -C $(builddir) DESTDIR=$(DESTDIR) install 47 | 48 | test: all 49 | $(MAKE) -C $(builddir) DESTDIR=$(DESTDIR) test 50 | 51 | $(builddir)/stamp: 52 | mkdir -p $(builddir) 53 | cd $(builddir) && cmake $(CMAKE_FLAGS) ../.. 54 | touch $@ 55 | 56 | all:: $(builddir)/stamp 57 | $(MAKE) -C $(builddir) $(MAKEARGS) all 58 | 59 | clean: $(builddir)/stamp 60 | $(MAKE) -C $(builddir) $(MAKEARGS) clean 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | PARTIO SOFTWARE 2 | 3 | Copyright 2018 Disney Enterprises, Inc. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | 3. The names "Disney", "Walt Disney Pictures", "Walt Disney Animation Studios" 16 | or the names of its contributors may NOT be used to endorse or promote products 17 | derived from this software without specific prior written permission from Walt 18 | Disney Pictures. 19 | 20 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 23 | NONINFRINGEMENT AND TITLE ARE DISCLAIMED. IN NO EVENT SHALL WALT DISNEY 24 | PICTURES, THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 31 | -------------------------------------------------------------------------------- /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/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/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/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 | #ifndef PARTIO_DATA_DIR
41 | #error "PARTIO_DATA_DIR must be defined."
42 | #endif
43 | 
44 | int main(int argc,char *argv[])
45 | {
46 |     Partio::ParticlesDataMutable* p=Partio::read(PARTIO_DATA_DIR "/scatter.bgeo");
47 |     Partio::ParticlesDataMutable* c=Partio::computeClustering(p,5,1.5,100,2,5);
48 |     Partio::write("/tmp/partio-cluster.bgeo",*c);
49 |     return 0;
50 | }
51 | 


--------------------------------------------------------------------------------
/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 
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/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 partio
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=partio.read(filename)
49 | 
50 |     for i in range(p.numAttributes()):
51 |         attr=p.attributeInfo(i)
52 |         typeStr="NONE"
53 |         if attr.type==partio.VECTOR: typeStr="VECTOR"
54 |         if attr.type==partio.FLOAT: typeStr="FLOAT"
55 |         if attr.type==partio.INT: typeStr="INT"
56 |         print("%10s[%d] %-30s "%(typeStr,attr.count,attr.name))
57 | 


--------------------------------------------------------------------------------
/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 ${PROJECT_SOURCE_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 ${DOCUMENTED_FILES})
47 | 
48 |   INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DOCDIR})
49 | ENDIF(DOXYGEN_FOUND)
50 | 


--------------------------------------------------------------------------------
/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/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 | 
37 | add_library(partio ${io_cpp} ${core_cpp})
38 | set_target_properties(partio PROPERTIES OUTPUT_NAME partio POSITION_INDEPENDENT_CODE ON)
39 | 
40 | target_include_directories(partio
41 |     PUBLIC
42 |         $
43 |         $)
44 | 
45 | if (ZLIB_FOUND)
46 |     target_include_directories(partio
47 |         PUBLIC
48 |             $
49 |             $)
50 |     target_link_libraries(partio PUBLIC ${ZLIB_LIBRARY})
51 | endif (ZLIB_FOUND)
52 | 
53 | install(TARGETS partio DESTINATION ${CMAKE_INSTALL_LIBDIR})
54 | 
55 | file(GLOB public_includes "*.h")
56 | install(FILES ${public_includes} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
57 | 


--------------------------------------------------------------------------------
/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/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/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 | set(CMAKE_INSTALL_PARTIO_TESTDIR ${CMAKE_INSTALL_DATAROOTDIR}/partio/test) 35 | find_library(GTEST_LIB gtest HINTS ${GTEST_LINK_PATH}) 36 | 37 | if ("${GTEST_LIB}" STREQUAL "GTEST_LIB-NOTFOUND") 38 | message(STATUS "${GTEST_LIB} not found in ${GTEST_LINK_PATH}, tests disabled") 39 | else() 40 | link_directories(${CMAKE_BINARY_DIR}/src/lib ${GTEST_LINK_PATH}) 41 | 42 | foreach(item testiterator testio testcache testclonecopy testcluster teststr makecircle makeline testkdtree testmerge) 43 | add_executable(${item} "${item}.cpp") 44 | target_include_directories(${item} PRIVATE ${GTEST_INCLUDE_PATH}) 45 | target_link_libraries(${item} ${PARTIO_LIBRARIES} ${GTEST_LIB}) 46 | target_compile_definitions(${item} PRIVATE -DPARTIO_DATA_DIR="${PROJECT_SOURCE_DIR}/src/data") 47 | install(TARGETS ${item} DESTINATION ${CMAKE_INSTALL_PARTIO_TESTDIR}) 48 | add_test(NAME ${item} COMMAND ${item}) 49 | endforeach(item) 50 | 51 | install(PROGRAMS testpartjson.py DESTINATION ${CMAKE_INSTALL_PARTIO_TESTDIR} RENAME testpartjson) 52 | 53 | endif() 54 | -------------------------------------------------------------------------------- /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/makecircle.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 | #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/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(${CMAKE_SOURCE_DIR}/src/lib) 35 | link_directories(${CMAKE_BINARY_DIR}/src/lib) 36 | 37 | IF(GLUT_FOUND AND OPENGL_FOUND) 38 | INCLUDE_DIRECTORIES(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) 39 | ADD_EXECUTABLE(partview partview.cpp) 40 | target_link_libraries(partview ${PARTIO_LIBRARIES} ${GLUT_LIBRARY} ${OPENGL_LIBRARY}) 41 | install(TARGETS partview DESTINATION ${CMAKE_INSTALL_BINDIR}) 42 | ENDIF(GLUT_FOUND AND OPENGL_FOUND) 43 | 44 | ADD_EXECUTABLE(partinfo partinfo.cpp) 45 | target_link_libraries(partinfo ${PARTIO_LIBRARIES}) 46 | 47 | ADD_EXECUTABLE(partconvert partconvert.cpp) 48 | target_link_libraries(partconvert ${PARTIO_LIBRARIES}) 49 | 50 | ADD_EXECUTABLE(partattr partattr.cpp) 51 | target_link_libraries(partattr ${PARTIO_LIBRARIES}) 52 | 53 | install(TARGETS partattr partconvert partinfo DESTINATION ${CMAKE_INSTALL_BINDIR}) 54 | 55 | install(PROGRAMS partedit.py DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME partedit) 56 | 57 | install(PROGRAMS partjson.py DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME partjson) 58 | 59 | install(PROGRAMS partinspect.py DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME partinspect) 60 | 61 | EXECUTE_PROCESS(COMMAND python -c "import sys;print('%s.%s'%sys.version_info[0:2])" 62 | OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) 63 | SET(PYTHON_DEST "${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION}/site-packages" ) 64 | INSTALL(FILES partedit.py partjson.py partinspect.py DESTINATION ${PYTHON_DEST}) 65 | -------------------------------------------------------------------------------- /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/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 | inline std::ostream& operator<<(std::ostream& stream,const Vec3& v) 98 | {return stream< 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 '"< 38 | #include 39 | #include 40 | #include 41 | 42 | #define MAXPARTICLES 10 43 | 44 | int main(int argc,char *argv[]) 45 | { 46 | if (argc != 3 && argc != 4){ 47 | std::cerr<<"Usage is: "< [numParticles (default " << MAXPARTICLES << ")\n"; 48 | return 1; 49 | } 50 | int maxParticles = (argc == 4) ? atoi(argv[3]) : MAXPARTICLES; 51 | std::string attrName = argv[2]; 52 | Partio::ParticlesDataMutable* p=Partio::read(argv[1]); 53 | if (!p) { 54 | std::cerr << "Cannot read " << argv[1] << std::endl; 55 | return 1; 56 | } 57 | 58 | Partio::ParticleAttribute attrhandle; 59 | p->attributeInfo(attrName.c_str(), attrhandle); 60 | maxParticles = std::min(maxParticles, p->numParticles()); 61 | 62 | if (attrhandle.type == Partio::INT) { 63 | for(int i = 0; i < maxParticles; i++){ 64 | const int* data = p->data(attrhandle,i); 65 | std::cout << attrName << "[" << i << "]=" << data[0] << std::endl; 66 | } 67 | } 68 | else if (attrhandle.type == Partio::INDEXEDSTR){ 69 | const std::vector& indexedStrs = p->indexedStrs(attrhandle); 70 | for(int i = 0; i < std::min(maxParticles, p->numParticles());i++){ 71 | const int index = p->data(attrhandle,i)[0]; 72 | std::cout << attrName << "[" << i << "]='" << indexedStrs[index]<<"'\n"; 73 | } 74 | } 75 | else { 76 | for(int i = 0; i < std::min(maxParticles, p->numParticles());i++){ 77 | const float* data = p->data(attrhandle,i); 78 | std::cout << attrName << "[" << i << "]=("; 79 | for(int j = 0; j < attrhandle.count; j++) { 80 | if (j) std::cout << ","; 81 | std::cout << data[j]; 82 | } 83 | std::cout << ")\n"; 84 | } 85 | } 86 | 87 | p->release(); 88 | 89 | return 0; 90 | } -------------------------------------------------------------------------------- /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 | #include 45 | 46 | namespace Partio{ 47 | struct ZipFileHeader; 48 | //##################################################################### 49 | // Functions Gzip_Out/Gzip_In - Create streams that read/write .gz 50 | //##################################################################### 51 | std::istream* Gzip_In(const std::string& filename,std::ios::openmode mode); 52 | std::ostream* Gzip_Out(const std::string& filename,std::ios::openmode mode); 53 | //##################################################################### 54 | // Class ZipFileWriter 55 | //##################################################################### 56 | class ZipFileWriter 57 | { 58 | std::ofstream ostream; 59 | std::vector files; 60 | public: 61 | 62 | //##################################################################### 63 | ZipFileWriter(const std::string& filename); 64 | virtual ~ZipFileWriter(); 65 | std::ostream* Add_File(const std::string& filename,const bool binary=true); 66 | //##################################################################### 67 | }; 68 | 69 | //##################################################################### 70 | // Class ZipFileReader 71 | //##################################################################### 72 | class ZipFileReader 73 | { 74 | std::ifstream istream; 75 | public: 76 | std::map filename_to_header; 77 | 78 | //##################################################################### 79 | ZipFileReader(const std::string& filename); 80 | virtual ~ZipFileReader(); 81 | std::istream* Get_File(const std::string& filename,const bool binary=true); 82 | void Get_File_List(std::vector& filenames) const; 83 | private: 84 | bool Find_And_Read_Central_Header(); 85 | //##################################################################### 86 | }; 87 | } 88 | #endif 89 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/lib/core/Mutex.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 _Mutex_ 37 | #define _Mutex_ 38 | 39 | #ifndef PARTIO_WIN32 40 | 41 | #include 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 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 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*) 103 | { 104 | // TODO: for future use 105 | } 106 | 107 | void endCachedAccess(ParticlesData*) 108 | { 109 | // TODO: for future use 110 | } 111 | 112 | } // namespace Partio 113 | -------------------------------------------------------------------------------- /src/tests/testio.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/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/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 WIN32 42 | #define _USE_MATH_DEFINES 43 | #include 44 | #endif // 45 | 46 | #ifdef PARTIO_WIN32 47 | #define M_PI 3.141592653589793238 48 | #endif 49 | 50 | class Camera 51 | { 52 | public: 53 | Partio::Vec3 lookAt; 54 | float theta; 55 | float phi; 56 | float distance; 57 | 58 | Camera() 59 | :lookAt(0,0,0), 60 | theta(0.8),phi(0.3), 61 | distance(3), 62 | tumble(false),pan(false),zoom(false) 63 | {} 64 | 65 | void look() const 66 | { 67 | Partio::Vec3 view=distance*Partio::Vec3(sin(theta)*cos(phi),sin(phi),cos(theta)*cos(phi)); 68 | 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)); 69 | Partio::Vec3 eye=lookAt+view; 70 | // Vec3 up(0,1,0); 71 | gluLookAt(eye.x,eye.y,eye.z,lookAt.x,lookAt.y,lookAt.z,up.x,up.y,up.z); 72 | //std::cout<<"eye "<x=x;this->y=y;tumble=true;} 83 | 84 | void startPan(const int x,const int y) 85 | {this->x=x;this->y=y;pan=true;} 86 | 87 | void startZoom(const int x,const int y) 88 | {this->x=x;this->y=y;zoom=true;} 89 | 90 | void update(const int x,const int y) 91 | { 92 | if(tumble){ 93 | theta+=-(x-this->x)*M_PI/180.; 94 | phi+=(y-this->y)*M_PI/180.; 95 | }else if(pan){ 96 | Partio::Vec3 view=Partio::Vec3(sin(theta)*cos(phi),sin(phi),cos(theta)*cos(phi)); 97 | Partio::Vec3 up=Partio::Vec3(sin(theta)*cos(phi+M_PI/2),sin(phi+M_PI/2),cos(theta)*cos(phi+M_PI/2)); 98 | Partio::Vec3 right=view.normalized().cross(up.normalized()).normalized(); 99 | lookAt+=right*distance*.001*(x-this->x); 100 | lookAt+=up*distance*.001*(y-this->y); 101 | }else if(zoom){ 102 | int move=y-this->y; 103 | distance*=exp(move*.01); 104 | } 105 | this->x=x;this->y=y; 106 | } 107 | 108 | void stop() 109 | {tumble=pan=zoom=false;} 110 | 111 | void fit(const float fov,const Partio::Vec3& boxmin,const Partio::Vec3& boxmax) 112 | { 113 | lookAt=.5*(boxmin+boxmax); 114 | Partio::Vec3 edges=boxmax-boxmin; 115 | float half_extent=.5*std::max(edges.x,std::max(edges.y,edges.z)); 116 | distance=std::max(1e-3,half_extent/tan(.5*fov*M_PI/180.)); 117 | } 118 | }; 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /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_MINIMUM_REQUIRED( VERSION 3.8.0 ) 35 | SET( CMAKE_SKIP_RPATH TRUE ) 36 | 37 | ## project name & version 38 | PROJECT(partio LANGUAGES CXX VERSION 1.5.2) 39 | 40 | option(GTEST_ENABLED "Enable GTest for tests" false) 41 | 42 | # Enable C++11 43 | SET(CMAKE_CXX_STANDARD 11) 44 | SET(CMAKE_CXX_STANDARD_REQUIRED YES) 45 | SET(CMAKE_CXX_EXTENSIONS NO) 46 | 47 | ## Setup platform specific helper defines build variants 48 | IF(WIN32) 49 | IF(MSVC) 50 | ADD_DEFINITIONS (-DPARTIO_WIN32) 51 | ENDIF() 52 | ADD_DEFINITIONS (-D_USE_MATH_DEFINES) 53 | ELSE() 54 | ADD_COMPILE_OPTIONS (-Wextra -Wno-unused-parameter) 55 | ENDIF() 56 | IF(APPLE) 57 | set (CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup") 58 | ENDIF() 59 | 60 | ## Choose build options 61 | # Disney specific method of choosing variant 62 | IF("$ENV{FLAVOR}" STREQUAL "optimize") 63 | SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "type of build" FORCE) 64 | ENDIF("$ENV{FLAVOR}" STREQUAL "optimize") 65 | IF("$ENV{FLAVOR}" STREQUAL "debug") 66 | SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "type of build" FORCE) 67 | ENDIF("$ENV{FLAVOR}" STREQUAL "debug") 68 | # Set to release if nothing else defined 69 | IF(NOT CMAKE_BUILD_TYPE) 70 | SET(CMAKE_BUILD_TYPE "Release" CACHE STRING 71 | "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." 72 | FORCE) 73 | ENDIF(NOT CMAKE_BUILD_TYPE) 74 | 75 | include(CTest) 76 | enable_testing() 77 | 78 | ## Set install location 79 | IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 80 | IF(WIN32) 81 | set(VARIANT_DIRECTORY "Windows-x86_64") 82 | ELSE() 83 | execute_process(COMMAND sh -c "echo `uname`-`uname -r | cut -d'-' -f1`-`uname -m`" OUTPUT_VARIABLE VARIANT_DIRECTORY OUTPUT_STRIP_TRAILING_WHITESPACE) 84 | ENDIF() 85 | set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/${VARIANT_DIRECTORY}") 86 | ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 87 | 88 | include(GNUInstallDirs) 89 | 90 | # Prefer libglvnd for OpenGL 91 | set(OpenGL_GL_PREFERENCE GLVND) 92 | 93 | ## Search for useful libraries 94 | find_package(GLUT REQUIRED) 95 | find_package(OpenGL REQUIRED) 96 | find_package(ZLIB) 97 | IF(ZLIB_FOUND) 98 | ADD_DEFINITIONS (-DPARTIO_USE_ZLIB) 99 | ELSE(ZLIB_FOUND) 100 | SET (ZLIB_LIBRARY "") 101 | ENDIF(ZLIB_FOUND) 102 | 103 | option(BUILD_SHARED_LIBS "Enabled shared libraries" ON) 104 | 105 | ## Make modules able to see partio library 106 | # Setup environment variable to link partio 107 | SET( PARTIO_LIBRARIES partio ${ZLIB_LIBRARY} ) 108 | 109 | if (${GTEST_ENABLED}) 110 | set($GEST_LOCATION "/usr" CACHE STRING "gtest installation prefix") 111 | set(GTEST_INCLUDE_PATH ${GTEST_LOCATION}/include) 112 | set(GTEST_LIBDIR ${CMAKE_INSTALL_LIBDIR}) 113 | set(GTEST_LINK_PATH ${GTEST_LOCATION}/${GTEST_LIBDIR} CACHE STRING "gtest library directory") 114 | endif() 115 | 116 | ## Traverse subdirectories 117 | ADD_SUBDIRECTORY (src/lib) 118 | ADD_SUBDIRECTORY (src/tools) 119 | ADD_SUBDIRECTORY (src/py) 120 | ADD_SUBDIRECTORY (src/tests) 121 | ADD_SUBDIRECTORY (src/doc) 122 | -------------------------------------------------------------------------------- /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 | template 45 | void endianSwap(T& value) 46 | { 47 | T temp=value; 48 | char* src=(char*)&temp; 49 | char* dest=(char*)&value; 50 | for(unsigned int i=0;i static void swap(T&){ 58 | } 59 | }; 60 | 61 | struct LITEND { 62 | template static void swap(T& x){ 63 | endianSwap(x); 64 | } 65 | }; 66 | #else 67 | struct BIGEND { 68 | template static void swap(T& x){ 69 | endianSwap(x); 70 | } 71 | }; 72 | 73 | struct LITEND { 74 | template static void swap(T&){ 75 | } 76 | }; 77 | #endif 78 | 79 | template inline void 80 | read(std::istream& input,T& d) 81 | { 82 | input.read((char*)&d,sizeof(T)); 83 | E::swap(d); 84 | } 85 | 86 | template inline void 87 | write(std::ostream& output,const T& d) 88 | { 89 | T copy=d; 90 | E::swap(copy); 91 | output.write((char*)©,sizeof(T)); 92 | } 93 | 94 | template 95 | void read(std::istream& input,T1& d1,T2& d2) 96 | {read(input,d1);read(input,d2);} 97 | 98 | template 99 | void read(std::istream& input,T1& d1,T2& d2,T3& d3) 100 | {read(input,d1);read(input,d2,d3);} 101 | 102 | template 103 | void read(std::istream& input,T1& d1,T2& d2,T3& d3,T4& d4) 104 | {read(input,d1);read(input,d2,d3,d4);} 105 | 106 | template 107 | void read(std::istream& input,T1& d1,T2& d2,T3& d3,T4& d4,T5& d5) 108 | {read(input,d1);read(input,d2,d3,d4,d5);} 109 | 110 | template 111 | void read(std::istream& input,T1& d1,T2& d2,T3& d3,T4& d4,T5& d5,T6& d6) 112 | {read(input,d1);read(input,d2,d3,d4,d5,d6);} 113 | 114 | template 115 | void write(std::ostream& output,const T1& d1,const T2& d2) 116 | {write(output,d1);write(output,d2);} 117 | 118 | template 119 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3) 120 | {write(output,d1);write(output,d2,d3);} 121 | 122 | template 123 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3,const T4& d4) 124 | {write(output,d1);write(output,d2,d3,d4);} 125 | 126 | template 127 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3,const T4& d4,const T5& d5) 128 | {write(output,d1);write(output,d2,d3,d4,d5);} 129 | 130 | template 131 | void write(std::ostream& output,const T1& d1,const T2& d2,const T3& d3,const T4& d4,const T5& d5,const T6& d6) 132 | {write(output,d1);write(output,d2,d3,d4,d5,d6);} 133 | 134 | } 135 | #endif 136 | -------------------------------------------------------------------------------- /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 | git clone https://github.com/wdas/partio.git 15 | cd partio 16 | make -j prefix=$prefix install 17 | 18 | Getting Started 19 | =============== 20 | 21 | CMake is used to build the project, but we provide a top-level Makefile 22 | for convenience that takes care of all the steps. 23 | 24 | See the Makefile for the user-tweakable variables and corresponding 25 | cmake options. 26 | 27 | The typical usage for an installation into `/usr/local` 28 | with a temporary staging directory of `/tmp/stage` is: 29 | 30 | make DESTDIR=/tmp/stage prefix=/usr/local install 31 | 32 | Source code overview 33 | ==================== 34 | 35 | src/ 36 | lib/ Library code (public API in root) 37 | lib/core Core library (KDtree traversal, data representations) 38 | lib/io Input/Output (Different file formats) 39 | py/ SWIG based python bindings 40 | doc/ Doxygen documentation and (the start of) a manual 41 | tests/ Start of regression tests (I need more) 42 | tools/ Useful tools 43 | partconvert 44 | partinfo 45 | partview 46 | 47 | Class Model 48 | ----------- 49 | 50 | The goal of the library is to abstract the particle interface from the data 51 | representation. That is why Partio represents particles using three classes that 52 | inherit and provide more functionality 53 | 54 | ParticlesInfo - Information about # of particles and attributes 55 | ParticlesData - Read only access to all particle data 56 | ParticlesDataMutable - Read/write access to all particle data 57 | 58 | The functions used to get particle access are these: 59 | 60 | readHeaders() 61 | returns ParticlesInfo 62 | reads only the minimum data necessary to get number of particles and 63 | attributes 64 | 65 | readCached() 66 | returns ParticlesData 67 | For multiple users in different threads using the same particle file 68 | ParticlesData 69 | 70 | create() and read() 71 | returns ParticlesDataMutable 72 | allows read/write access 73 | 74 | Behind the scenes you could implement these classes however you like. Headers 75 | only representation is called core/ParticleHeader.{h,cpp}. Simple 76 | non-interleaved attributes is core/ParticleSimple.{h,cpp}. 77 | 78 | Attribute Data Model 79 | -------------------- 80 | 81 | All particles have the same data attributes. They have the model that they are 82 | of three basic types with a count of how many scalar values they have. 83 | 84 | VECTOR[3] 85 | FLOAT[d] 86 | INT[d] 87 | 88 | VECTOR[3] and FLOAT[3] have the same data representations. 89 | VECTOR[4] is invalid however FLOAT[4] is valid as is FLOAT[1...infinity] 90 | 91 | This seems to encompass the most common file formats for particles 92 | 93 | 94 | Iterating 95 | --------- 96 | 97 | There are multiple ways to access data in the API. Here are 98 | some tips 99 | 100 | - Use SIMD functions when possible prefer dataAsFloat(),data(arrayOfIndices) as 101 | opposed to data(int singleIndex) which accesses multiple pieces of data at 102 | once 103 | 104 | - Cache ParticleAttributes for quick access instead of calling attributeInfo() 105 | over a loop of particles 106 | 107 | - Use iterators to do linear operations over all particles They are much more 108 | optimized than both data() and the dataAsFloat or 109 | 110 | 111 | Backends 112 | -------- 113 | 114 | Behind the scenes there are SimpleParticles, ParticleHeaders, and 115 | SimpleParticlesInterleaved. In the future I would like to write a disk-based 116 | cached back end that can dynamically only load the data that is necessary. 117 | create(), read() and readCached could be augmented to create different 118 | structures in these cases. 119 | 120 | Readers/Writers 121 | --------------- 122 | 123 | New readers and writers can be added in the io/ directory. You simply need to 124 | implement the interface ParticlesInfo, ParticlesData and ParticlesDataMutable 125 | (or as many as you need). Editing the io/readers.h to add prototypes and 126 | io/ParticleIO.cpp to add file extension bindings should be easy. 127 | 128 | 129 | - Andrew Selle, Walt Disney Animation Studios 130 | -------------------------------------------------------------------------------- /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 | virtual void release(); 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); return nullptr;} 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/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/tests/testkdtree.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 | #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/testmerge.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 | #include 40 | 41 | using namespace Partio; 42 | 43 | // TODD - Create test base class to read in base and delta files 44 | // and validate them, as well as release() on test completion. 45 | // Add test to merge two particle sets without an identifier 46 | // (should be fully additive) 47 | 48 | class PartioTest : public ::testing::Test { 49 | public: 50 | PartioTest() {} 51 | virtual ~PartioTest() {} 52 | 53 | void SetUp() { 54 | // Read in base and delta files 55 | std::string datadir(PARTIO_DATA_DIR); 56 | std::string base_geo = datadir + "/base.bgeo"; 57 | std::string delta_geo = datadir + "/delta.bgeo"; 58 | base = Partio::read(base_geo.c_str()); 59 | delta = Partio::read(delta_geo.c_str()); 60 | 61 | // Validate each before merging (don't allow test data to change) 62 | ASSERT_EQ(5, base->numParticles()); 63 | ASSERT_EQ(3, delta->numParticles()); 64 | ASSERT_TRUE(base->attributeInfo("life", base_life_attr)); 65 | ASSERT_TRUE(delta->attributeInfo("life", delta_life_attr)); 66 | ASSERT_TRUE(base->attributeInfo("position", base_pos_attr)); 67 | ASSERT_TRUE(delta->attributeInfo("position", delta_pos_attr)); 68 | ASSERT_FALSE(base->attributeInfo("new", base_new_attr)); 69 | ASSERT_TRUE(delta->attributeInfo("new", delta_new_attr)); 70 | for (int i=0; i<5; i++) { 71 | ASSERT_EQ(base_values_life[i], base->data(base_life_attr, i)[0]); 72 | ASSERT_EQ(base_values_posx[i], base->data(base_pos_attr, i)[0]); 73 | } 74 | for (int i=0; i<3; i++) { 75 | ASSERT_EQ(delta_values_life[i], delta->data(delta_life_attr, i)[0]); 76 | ASSERT_EQ(delta_values_posx[i], delta->data(delta_pos_attr, i)[0]); 77 | } 78 | } 79 | 80 | void TearDown() { 81 | base->release(); 82 | delta->release(); 83 | } 84 | 85 | Partio::ParticlesDataMutable* base; 86 | Partio::ParticlesDataMutable* delta; 87 | ParticleAttribute base_life_attr, base_pos_attr, base_new_attr; 88 | ParticleAttribute delta_life_attr, delta_pos_attr, delta_new_attr; 89 | std::vector base_values_life{ -1.2, -0.2, 0.8, 1.8, 2.8 }; 90 | std::vector base_values_posx{ 0.0, 0.1, 0.2, 0.3, 0.4 }; 91 | std::vector delta_values_life{ 1.0, 3.0, 5.0 }; 92 | std::vector delta_values_posx{ 0.1, 0.3, 0.5 }; 93 | }; 94 | 95 | TEST_F(PartioTest, merge) 96 | { 97 | std::cout << "\nBase particle set:\n"; 98 | Partio::print(base); 99 | std::cout << "\nDelta particle set:\n"; 100 | Partio::print(delta); 101 | 102 | // Do the merge 103 | Partio::merge(*base, *delta, "id"); 104 | std::cout << "\nMerged particle set:\n"; 105 | Partio::print(base); 106 | ASSERT_EQ(6, base->numParticles()); 107 | std::vector expected_life({-1.2, 1.0, 0.8, 3.0, 2.8, 5.0}); 108 | std::vector expected_posx({0.0, 0.1, 0.2, 0.3, 0.4, 0.5}); 109 | std::vector expected_new({0,1,0,2,0,3}); 110 | ASSERT_TRUE(base->attributeInfo("new", base_new_attr)); 111 | for (int i=0; i<6; i++) { 112 | ASSERT_EQ(expected_life[i], base->data(base_life_attr, i)[0]); 113 | ASSERT_EQ(expected_posx[i], base->data(base_pos_attr, i)[0]); 114 | ASSERT_EQ(expected_new[i], base->data(base_new_attr, i)[0]); 115 | } 116 | 117 | int numFixed = base->numFixedAttributes(); 118 | ASSERT_EQ(3, numFixed); 119 | } 120 | 121 | TEST_F(PartioTest, mergenoid) 122 | { 123 | } 124 | 125 | int main(int argc, char* argv[]) 126 | { 127 | testing::InitGoogleTest(&argc, argv); 128 | return RUN_ALL_TESTS(); 129 | } 130 | -------------------------------------------------------------------------------- /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/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/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 | virtual void release(); 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 | virtual void release(); 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 | { assert(false); return nullptr; } 88 | 89 | ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,const int count); 90 | FixedAttribute addFixedAttribute(const char* attribute,ParticleAttributeType type,const int count); 91 | ParticleIndex addParticle(); 92 | iterator addParticles(const int count); 93 | 94 | 95 | iterator setupIterator(const int index=0); 96 | const_iterator setupConstIterator(const int index=0) const; 97 | void setupIteratorNextBlock(Partio::ParticleIterator& iterator); 98 | void setupIteratorNextBlock(Partio::ParticleIterator& iterator) const; 99 | void setupAccessor(Partio::ParticleIterator& iterator,ParticleAccessor& accessor); 100 | void setupAccessor(Partio::ParticleIterator& iterator,ParticleAccessor& accessor) const; 101 | private: 102 | void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const; 103 | void* fixedDataInternal(const FixedAttribute& attribute) const; 104 | void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount, 105 | const ParticleIndex* particleIndices,const bool sorted,char* values) const; 106 | 107 | private: 108 | int particleCount; 109 | int allocatedCount; 110 | char* data; 111 | char* fixedData; 112 | int stride; 113 | struct IndexedStrTable{ 114 | std::map stringToIndex; // TODO: this should be a hash table unordered_map 115 | std::vector strings; 116 | }; 117 | std::vector attributeIndexedStrs; 118 | std::vector attributeOffsets; // Inside is data of appropriate type 119 | std::vector attributes; 120 | std::map nameToAttribute; 121 | std::vector fixedAttributeIndexedStrs; 122 | std::vector fixedAttributeOffsets; // Inside is data of appropriate type 123 | std::vector fixedAttributes; 124 | std::map nameToFixedAttribute; 125 | 126 | PartioMutex kdtree_mutex; 127 | KdTree<3>* kdtree; 128 | }; 129 | 130 | } 131 | #endif 132 | -------------------------------------------------------------------------------- /src/lib/io/PDC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright (c) 2011 Disney Enterprises, Inc. and Contributors, All rights reserved 4 | 5 | keypress events also added the PTS file format (all need cleanup) 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 | Format Contributed by github user: Jinkuen 37 | Modifications from: github user: redpawfx (redpawFX@gmail.com) and Luma Pictures 2011 38 | 39 | */ 40 | 41 | #include "../Partio.h" 42 | #include "../core/ParticleHeaders.h" 43 | #include "PartioEndian.h" 44 | #include "ZIP.h" 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | namespace Partio{ 52 | 53 | using namespace std; 54 | 55 | static const int PDC_MAGIC = (((((' '<<8)|'C')<<8)|'D')<<8)|'P'; // " CDP" 56 | 57 | typedef struct{ 58 | int magic; 59 | int version; 60 | int bitorder; 61 | int tmp1; 62 | int tmp2; 63 | int numParticles; 64 | int numAttrs; 65 | } PDC_HEADER; 66 | 67 | string readName(istream& input){ 68 | int nameLen = 0; 69 | read(input, nameLen); 70 | char* name = new char[nameLen]; 71 | input.read(name, nameLen); 72 | string result(name, name+nameLen); 73 | delete [] name; 74 | return result; 75 | } 76 | 77 | ParticlesDataMutable* readPDC(const char* filename, const bool headersOnly,std::ostream* errorStream){ 78 | 79 | unique_ptr input(Gzip_In(filename,std::ios::in|std::ios::binary)); 80 | if(!*input){ 81 | if(errorStream) *errorStream << "Partio: Unable to open file " << filename << std::endl; 82 | return 0; 83 | } 84 | 85 | PDC_HEADER header; 86 | input->read((char*)&header, sizeof(header)); 87 | if(PDC_MAGIC != header.magic){ 88 | if(errorStream) *errorStream << "Partio: Magic number '" << header.magic << "' of '" << filename << "' doesn't match pdc magic '" << PDC_MAGIC << "'" << std::endl; 89 | return 0; 90 | } 91 | 92 | BIGEND::swap(header.numParticles); 93 | BIGEND::swap(header.numAttrs); 94 | 95 | ParticlesDataMutable* simple = headersOnly ? new ParticleHeaders: create(); 96 | simple->addParticles(header.numParticles); 97 | 98 | for(int attrIndex = 0; attrIndex < header.numAttrs; attrIndex++){ 99 | // add attribute 100 | ParticleAttribute attr; 101 | string attrName = readName(*input); 102 | int type; 103 | read(*input, type); 104 | if(type == 3){ 105 | attr = simple->addAttribute(attrName.c_str(), FLOAT, 1); 106 | } 107 | else if(type == 5){ 108 | attr = simple->addAttribute(attrName.c_str(), VECTOR, 3); 109 | } 110 | 111 | // if headersOnly, skip 112 | if(headersOnly){ 113 | input->seekg((int)input->tellg() + header.numParticles*sizeof(double)*attr.count); 114 | continue; 115 | } 116 | else{ 117 | double tmp[3]; 118 | for(int partIndex = 0; partIndex < simple->numParticles(); partIndex++){ 119 | for(int dim = 0; dim < attr.count; dim++){ 120 | read(*input, tmp[dim]); 121 | simple->dataWrite(attr, partIndex)[dim] = (float)tmp[dim]; 122 | } 123 | } 124 | } 125 | } 126 | 127 | return simple; 128 | } 129 | 130 | bool writePDC(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream){ 131 | unique_ptr output( 132 | compressed ? 133 | Gzip_Out(filename,ios::out|ios::binary) 134 | :new std::ofstream(filename,ios::out|ios::binary)); 135 | 136 | if(!*output){ 137 | if(errorStream) *errorStream << "Partio Unable to open file " << filename << endl; 138 | return false; 139 | } 140 | 141 | // write .pdc header 142 | write(*output, PDC_MAGIC); 143 | write(*output, (int)1); // version 144 | write(*output, (int)1); // bitorder 145 | write(*output, (int)0); // tmp1 146 | write(*output, (int)0); // tmp2 147 | write(*output, (int)p.numParticles()); 148 | write(*output, (int)p.numAttributes()); 149 | 150 | for(int attrIndex = 0; attrIndex < p.numAttributes(); attrIndex++){ 151 | ParticleAttribute attr; 152 | p.attributeInfo(attrIndex,attr); 153 | 154 | // write attribute name 155 | write(*output, (int)attr.name.length()); 156 | output->write(attr.name.c_str(), (int)attr.name.length()); 157 | 158 | // write type 159 | int count = 1; // FLOAT 160 | if(attr.type == VECTOR){ 161 | count = 3; 162 | } 163 | write(*output, (int)(count+2)); 164 | 165 | // write data 166 | for(int partIndex = 0; partIndex < p.numParticles(); partIndex++){ 167 | const float* data = p.data(attr, partIndex); 168 | for(int dim = 0; dim < count; dim++){ 169 | write(*output, (double)data[dim]); 170 | } 171 | } 172 | } 173 | return true; 174 | } 175 | 176 | }// end of namespace Partio 177 | -------------------------------------------------------------------------------- /src/lib/io/ParticleIO.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 "../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/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/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 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 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< 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 | 54 | void ParticleHeaders:: 55 | release() 56 | { 57 | delete this; 58 | } 59 | 60 | int ParticleHeaders:: 61 | numParticles() const 62 | { 63 | return particleCount; 64 | } 65 | 66 | int ParticleHeaders:: 67 | numAttributes() const 68 | { 69 | return static_cast(attributes.size()); 70 | } 71 | 72 | int ParticleHeaders:: 73 | numFixedAttributes() const 74 | { 75 | return static_cast(fixedAttributes.size()); 76 | } 77 | 78 | bool ParticleHeaders:: 79 | attributeInfo(const int attributeIndex,ParticleAttribute& attribute) const 80 | { 81 | if(attributeIndex<0 || attributeIndex>=(int)attributes.size()) return false; 82 | attribute=attributes[attributeIndex]; 83 | return true; 84 | } 85 | 86 | bool ParticleHeaders:: 87 | fixedAttributeInfo(const int attributeIndex,FixedAttribute& attribute) const 88 | { 89 | if(attributeIndex<0 || attributeIndex>=(int)fixedAttributes.size()) return false; 90 | attribute=fixedAttributes[attributeIndex]; 91 | return true; 92 | } 93 | 94 | bool ParticleHeaders:: 95 | attributeInfo(const char* attributeName,ParticleAttribute& attribute) const 96 | { 97 | std::map::const_iterator it=nameToAttribute.find(attributeName); 98 | if(it!=nameToAttribute.end()){ 99 | attribute=attributes[it->second]; 100 | return true; 101 | } 102 | return false; 103 | } 104 | 105 | bool ParticleHeaders:: 106 | fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const 107 | { 108 | std::map::const_iterator it=nameToFixedAttribute.find(attributeName); 109 | if(it!=nameToFixedAttribute.end()){ 110 | attribute=fixedAttributes[it->second]; 111 | return true; 112 | } 113 | return false; 114 | } 115 | 116 | void ParticleHeaders:: 117 | sort() 118 | { 119 | assert(false); 120 | } 121 | 122 | 123 | int ParticleHeaders:: 124 | registerIndexedStr(const ParticleAttribute&, const char*) 125 | { 126 | assert(false); 127 | return -1; 128 | } 129 | 130 | int ParticleHeaders:: 131 | registerFixedIndexedStr(const FixedAttribute&, const char* str) 132 | { 133 | assert(false); 134 | return -1; 135 | } 136 | 137 | int ParticleHeaders:: 138 | lookupIndexedStr(const ParticleAttribute&, const char*) const 139 | { 140 | assert(false); 141 | return -1; 142 | } 143 | 144 | int ParticleHeaders:: 145 | lookupFixedIndexedStr(const FixedAttribute&, const char* str) const 146 | { 147 | assert(false); 148 | return -1; 149 | } 150 | 151 | const std::vector& ParticleHeaders:: 152 | indexedStrs(const ParticleAttribute&) const 153 | { 154 | static std::vector dummy; 155 | assert(false); 156 | return dummy; 157 | } 158 | 159 | const std::vector& ParticleHeaders:: 160 | fixedIndexedStrs(const FixedAttribute& attr) const 161 | { 162 | static std::vector dummy; 163 | assert(false); 164 | return dummy; 165 | } 166 | 167 | void ParticleHeaders:: 168 | findPoints(const float[3],const float[3],std::vector&) const 169 | { 170 | assert(false); 171 | } 172 | 173 | float ParticleHeaders:: 174 | findNPoints(const float[3],const int,const float,std::vector&,std::vector&) const 175 | { 176 | assert(false); 177 | return 0; 178 | } 179 | 180 | int ParticleHeaders:: 181 | findNPoints(const float[3],int,const float, ParticleIndex *, 182 | float *, float *) 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=static_cast(attributes.size()); // all arrays separate so we don't use this here! 196 | attr.count=count; 197 | attributes.push_back(attr); 198 | nameToAttribute[attribute]=static_cast(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&,const 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&,const int, 247 | const ParticleIndex*,const bool,char*) const 248 | { 249 | assert(false); 250 | } 251 | 252 | void ParticleHeaders:: 253 | dataAsFloat(const ParticleAttribute&,const int, 254 | const ParticleIndex*,const bool,float*) 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/tools/partjson.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Converts partio files to and from json. 5 | 6 | Usage: partjson [FLAGS] 7 | 8 | Supported FLAGS: 9 | -c/--compress: When converting to partio, compress the output 10 | -v/--verbose : Turn on verbosity for partio 11 | -h/--help : Print this help message 12 | """ 13 | 14 | # TODO: Unicode compliance 15 | 16 | __copyright__ = """ 17 | CONFIDENTIAL INFORMATION: This software is the confidential and 18 | proprietary information of Walt Disney Animation Studios ("WDAS"). 19 | This software may not be used, disclosed, reproduced or distributed 20 | for any purpose without prior written authorization and license 21 | from WDAS. Reproduction of any section of this software must 22 | include this legend and all copyright notices. 23 | Copyright Disney Enterprises, Inc. All rights reserved. 24 | """ 25 | 26 | import os, sys, json 27 | import partio 28 | 29 | def toJson(particleSet): 30 | """ Converts a particle set to json """ 31 | 32 | data = {} 33 | 34 | # Put types in json just for readability 35 | data['__types__'] = { i : partio.TypeName(i) for i in range(5) } 36 | 37 | # Convert fixed attributes 38 | fixedAttributes = {} 39 | fixedIndexedStrings = {} 40 | for i in range(particleSet.numFixedAttributes()): 41 | attr = particleSet.fixedAttributeInfo(i) 42 | fixedAttributes[attr.name] = {'type': attr.type, 43 | 'count': attr.count, 44 | 'value': particleSet.getFixed(attr), 45 | } 46 | 47 | # Convert indexed string attributse 48 | if attr.type == partio.INDEXEDSTR: 49 | fixedIndexedStrings[attr.name] = particleSet.fixedIndexedStrs(attr) 50 | 51 | if fixedAttributes: 52 | data['fixedAttributes'] = fixedAttributes 53 | if fixedIndexedStrings: 54 | data['fixedIndexedStrings'] = fixedIndexedStrings 55 | 56 | # Convert particle attributes 57 | attributes = {} 58 | attrs = [] 59 | indexedStrings = {} 60 | for i in range(particleSet.numAttributes()): 61 | attr = particleSet.attributeInfo(i) 62 | attrs.append(attr) 63 | attributes[attr.name] = {'type': attr.type, 'count': attr.count } 64 | 65 | # Convert indexed string attributse 66 | if attr.type == partio.INDEXEDSTR: 67 | indexedStrings[attr.name] = particleSet.indexedStrs(attr) 68 | 69 | if attributes: 70 | data['attributes'] = attributes 71 | if indexedStrings: 72 | data['indexedStrings'] = indexedStrings 73 | 74 | # Convert particles to an indexed dictionary 75 | particles = {} 76 | for i in range(particleSet.numParticles()): 77 | particle = {} 78 | for attr in attrs: 79 | particle[attr.name] = particleSet.get(attr, i) 80 | # Add an index purely for readability & debugging (not consumed converting back) 81 | particles[i] = particle 82 | 83 | if particles: 84 | data['particles'] = particles 85 | 86 | return data 87 | 88 | 89 | def fromJson(data): 90 | """ Converts a json dictionary to a particle set """ 91 | 92 | particleSet = partio.create() 93 | 94 | # Convert fixed attributes 95 | fixedAttributes = {} 96 | if 'fixedAttributes' in data: 97 | for attrName, attrInfo in data['fixedAttributes'].items(): 98 | attrName = str(attrName) 99 | attr = particleSet.addFixedAttribute(attrName, attrInfo['type'], attrInfo['count']) 100 | fixedAttributes[attrName] = attr 101 | if len(attrInfo['value']) == attrInfo['count']: 102 | particleSet.setFixed(attr, attrInfo['value']) 103 | else: 104 | sys.stderr.write('Mismatched count for fixed attribute {}. Skipping.\n'.format(attrName)) 105 | 106 | # Convert attributes 107 | attributes = {} 108 | if 'attributes' in data: 109 | for attrName, attrInfo in data['attributes'].items(): 110 | attrName = str(attrName) 111 | attr = particleSet.addAttribute(attrName, attrInfo['type'], attrInfo['count']) 112 | attributes[attrName] = attr 113 | 114 | # Convert fixed indexed strings 115 | if 'fixedIndexedStrings' in data: 116 | for attrName, strings in data['fixedIndexedStrings'].items(): 117 | if attrName not in fixedAttributes: 118 | sys.stderr.write('Could not match fixed indexed string {} with any defined fixed attribute. Skipping.\n'.format(attrName)) 119 | continue 120 | for string in strings: 121 | particleSet.registerFixedIndexedStr(fixedAttributes[attrName], string) 122 | 123 | # Convert indexed strings 124 | if 'indexedStrings' in data: 125 | for attrName, strings in data['indexedStrings'].items(): 126 | if attrName not in attributes: 127 | sys.stderr.write('Could not match indexed string {} with any defined attribute. Skipping.\n'.format(attrName)) 128 | continue 129 | for string in strings: 130 | particleSet.registerIndexedStr(attributes[attrName], str(string)) 131 | 132 | # Convert particles 133 | if 'particles' in data: 134 | particleSet.addParticles(len(data['particles'])) 135 | for pnum, particle in data['particles'].items(): 136 | pnum = int(pnum) 137 | for attrName, value in particle.items(): 138 | try: 139 | attr = attributes[attrName] 140 | except IndexError: 141 | sys.stderr.write('Could not match attribute "{}" for particle {} with any defined attributes. Skipping.\n'.format(attrName, pnum)) 142 | continue 143 | if len(value) != attr.count: 144 | sys.stderr.write('Mismatched count for attribute "{}" ({}) and particle {} ({}). Skipping.\n'.format(attrName, attr.count, pnum, len(value))) 145 | continue 146 | 147 | particleSet.set(attr, pnum, value) 148 | 149 | return particleSet 150 | 151 | def main(): 152 | """ Main """ 153 | 154 | # Process command-line arguments 155 | filenames = [] 156 | verbose = False 157 | compress = False 158 | for arg in sys.argv[1:]: 159 | if arg in ('-h', '--help'): 160 | print(__doc__) 161 | return 162 | 163 | if arg in ('-v', '--verbose'): 164 | verbose = True 165 | continue 166 | 167 | if arg in ('-c', '--compress'): 168 | compress = True 169 | continue 170 | 171 | filenames.append(arg) 172 | 173 | if len(filenames) != 2: 174 | print(__doc__) 175 | sys.stderr.write('Incorrect number of arguments.\n') 176 | sys.exit(1) 177 | 178 | file1, file2 = filenames[0:2] 179 | ext1 = os.path.splitext(file1)[1] 180 | ext2 = os.path.splitext(file2)[1] 181 | 182 | partio_extensions = ('.bgeo', '.geo', '.bhclassic', '.ptc', '.pdb') 183 | 184 | # Validate files 185 | if not os.path.exists(file1): 186 | sys.stderr.write('Invalid input file: {}\n'.format(file1)) 187 | sys.exit(1) 188 | 189 | # Convert from json to partio 190 | if ext1 == '.json': 191 | if ext2 not in partio_extensions: 192 | sys.stderr.write('Unknown partio extension for: {}\n'.format(file2)) 193 | sys.exit(1) 194 | 195 | with open(file1, 'r') as fp: 196 | data = json.load(fp) 197 | particleSet = fromJson(data) 198 | partio.write(file2, particleSet, compress) 199 | sys.exit(0) 200 | 201 | if ext1 not in partio_extensions: 202 | sys.stderr.write('Unknown partio extension for: {}\n'.format(file1)) 203 | sys.exit(1) 204 | 205 | # Convert from partio to json 206 | if ext1 in partio_extensions: 207 | particleSet = partio.read(file1, verbose) 208 | data = toJson(particleSet) 209 | with open(file2, 'w') as fp: 210 | json.dump(data, fp, indent=2, sort_keys=True) 211 | sys.exit(0) 212 | 213 | print(__doc__) 214 | sys.stderr.write('Unknown file extension(s)') 215 | sys.exit(1) 216 | 217 | 218 | if __name__ == '__main__': 219 | main() 220 | -------------------------------------------------------------------------------- /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 | #include 40 | 41 | void help() 42 | { 43 | std::cerr << "Usage: partinfo [FLAGS] { particle indices to print full info }\n"; 44 | std::cerr << "Supported FLAGS:\n"; 45 | std::cerr << " -a/--all : Print all particles\n"; 46 | std::cerr << " -s/--strings: Print all indexed string values (default=5)\n"; 47 | std::cerr << " -h/--help : Print this help message\n"; 48 | } 49 | 50 | void printParticle(int particleIndex, Partio::ParticlesDataMutable* p, size_t widest) 51 | { 52 | std::cout << "---------------------------" << std::endl; 53 | std::cout << "Particle " << particleIndex << ":" << std::endl; 54 | if (particleIndex >= p->numParticles() || particleIndex < 0) { 55 | std::cout << "OUT OF RANGE" << std::endl; 56 | } else { 57 | for (int i = 0; i < p->numAttributes(); i++) { 58 | Partio::ParticleAttribute attr; 59 | p->attributeInfo(i, attr); 60 | std::cout << std::setw(10) << Partio::TypeName(attr.type) << " " << std::setw(widest) << attr.name << " "; 61 | if (attr.count > 1) 62 | std::cout << "[ "; 63 | for (int ii = 0; ii < attr.count; ii++) { 64 | if (ii) 65 | std::cout << ", "; 66 | if (attr.type == Partio::INDEXEDSTR) { 67 | int val = p->data(attr, particleIndex)[ii]; 68 | std::cout << val << "='" << p->indexedStrs(attr)[val] << "'"; 69 | } else if (attr.type == Partio::INT) 70 | std::cout << p->data(attr, particleIndex)[ii]; 71 | else 72 | std::cout << p->data(attr, particleIndex)[ii]; 73 | } 74 | if (attr.count > 1) 75 | std::cout << " ]"; 76 | std::cout << std::endl; 77 | } 78 | } 79 | } 80 | 81 | #define FLAG(shortFlag, longFlag) strcmp(argv[i], shortFlag) == 0 || strcmp(argv[i], longFlag) == 0 82 | 83 | int main(int argc, char* argv[]) 84 | { 85 | const char* filename(nullptr); 86 | std::set particleIndices; 87 | bool printAllStrings(false); 88 | bool printAllParticles(false); 89 | if (argc < 2) { 90 | help(); 91 | return 1; 92 | } 93 | for (int i = 1; i < argc; ++i) { 94 | if (FLAG("-h", "--help")) { 95 | help(); 96 | return 0; 97 | } else if (FLAG("-a", "--all")) { 98 | printAllParticles = true; 99 | } else if (FLAG("-s", "--strings")) { 100 | printAllStrings = true; 101 | } else if (argv[i][0] == '-') { 102 | std::cerr << "Unknown flag: " << argv[i] << std::endl; 103 | } else if (!filename) { 104 | filename = argv[i]; 105 | } else { 106 | particleIndices.insert(atoi(argv[i])); 107 | } 108 | } 109 | Partio::ParticlesDataMutable* p = Partio::read(filename); 110 | if (!p) { 111 | std::cerr << "Unable to read \"" << filename << "\"\n"; 112 | return 1; 113 | } 114 | 115 | std::cout << std::setiosflags(std::ios::left) << "Number of particles: " << p->numParticles() << std::endl; 116 | int numAttr = p->numAttributes(); 117 | std::cout << std::setw(12) << "Type" << std::setw(10) << "Count" << std::setw(30) << "Name" << std::endl; 118 | std::cout << std::setw(12) << "----" << std::setw(10) << "-----" << std::setw(30) << "----" << std::endl; 119 | for (int i = 0; i < numAttr; i++) { 120 | Partio::ParticleAttribute attr; 121 | p->attributeInfo(i, attr); 122 | std::cout << std::setw(12) << Partio::TypeName(attr.type) << std::setw(10) << attr.count << std::setw(30) 123 | << attr.name << std::endl; 124 | ; 125 | } 126 | 127 | // Get widest attribute name for better formatting 128 | size_t widest(0); 129 | for (int i = 0; i < p->numAttributes(); ++i) { 130 | Partio::ParticleAttribute attr; 131 | p->attributeInfo(i, attr); 132 | widest = std::max(widest, attr.name.size()); 133 | } 134 | widest++; 135 | 136 | if (printAllParticles) { 137 | for (int i = 0; i < p->numParticles(); ++i) 138 | printParticle(i, p, widest); 139 | } else if (!particleIndices.empty()) { 140 | for (int i : particleIndices) 141 | printParticle(i, p, widest); 142 | } else { 143 | int numFixedAttr = p->numFixedAttributes(); 144 | if (numFixedAttr) { 145 | std::cout << "---------------------------" << std::endl; 146 | std::cout << "Fixed Attributes" << std::endl; 147 | std::cout << std::setw(12) << "Type" << std::setw(10) << "Count" << std::setw(widest) << "Name" 148 | << std::endl; 149 | std::cout << std::setw(12) << "----" << std::setw(10) << "-----" << std::setw(widest) << "----" 150 | << std::endl; 151 | for (int i = 0; i < numFixedAttr; i++) { 152 | Partio::FixedAttribute attr; 153 | p->fixedAttributeInfo(i, attr); 154 | std::cout << std::setw(12) << Partio::TypeName(attr.type) << std::setw(10) << attr.count 155 | << std::setw(widest) << attr.name << std::endl; 156 | ; 157 | } 158 | 159 | for (int i = 0; i < numFixedAttr; i++) { 160 | Partio::FixedAttribute attr; 161 | p->fixedAttributeInfo(i, attr); 162 | std::cout << std::setw(10) << Partio::TypeName(attr.type) << " " << std::setw(widest) << attr.name; 163 | for (int ii = 0; ii < attr.count; ii++) { 164 | if (attr.type == Partio::INDEXEDSTR) { 165 | int val = p->fixedData(attr)[ii]; 166 | std::cout << " " << val; 167 | for (size_t index = 0; index < p->fixedIndexedStrs(attr).size(); index++) { 168 | std::cout << std::endl << " " << index << " '" << p->fixedIndexedStrs(attr)[index] << "'"; 169 | } 170 | } else if (attr.type == Partio::INT) 171 | std::cout << " " << p->fixedData(attr)[ii]; 172 | else 173 | std::cout << " " << p->fixedData(attr)[ii]; 174 | } 175 | std::cout << std::endl; 176 | } 177 | } 178 | 179 | // Display indexed strings 180 | bool printedTitle(false); 181 | for (int i = 0; i < p->numAttributes(); ++i) { 182 | Partio::ParticleAttribute attr; 183 | p->attributeInfo(i, attr); 184 | if (attr.type == Partio::INDEXEDSTR) { 185 | if (!printedTitle) { 186 | std::cout << "\nINDEXED STRINGS:\n"; 187 | printedTitle = true; 188 | } 189 | const std::vector indexedStrs = p->indexedStrs(attr); 190 | std::cout << attr.name << " (" << indexedStrs.size() << ") = ["; 191 | if (!indexedStrs.empty()) 192 | std::cout << std::endl; 193 | size_t numStrings = printAllStrings ? indexedStrs.size() : std::min((size_t)5, indexedStrs.size()); 194 | for (size_t i = 0; i < numStrings; ++i) { 195 | std::cout << " " << indexedStrs[i] << std::endl; 196 | } 197 | if (indexedStrs.size() > 5) 198 | std::cout << " ...\n"; 199 | std::cout << "]\n"; 200 | } 201 | } 202 | } 203 | 204 | p->release(); 205 | return 0; 206 | } 207 | --------------------------------------------------------------------------------