├── LICENSE ├── README.md ├── addon └── BlenderPartioTools.py ├── extern ├── partio │ ├── CMakeLists.txt │ ├── LICENSE │ ├── Makefile │ ├── README.md │ └── src │ │ └── lib │ │ ├── CMakeLists.txt │ │ ├── Partio.h │ │ ├── PartioAttribute.h │ │ ├── PartioIterator.h │ │ ├── PartioVec3.h │ │ ├── core │ │ ├── KdTree.h │ │ ├── Mutex.h │ │ ├── Particle.cpp │ │ ├── ParticleCaching.cpp │ │ ├── ParticleCaching.h │ │ ├── ParticleHeaders.cpp │ │ ├── ParticleHeaders.h │ │ ├── ParticleSimple.cpp │ │ ├── ParticleSimple.h │ │ ├── ParticleSimpleInterleave.cpp │ │ └── ParticleSimpleInterleave.h │ │ └── io │ │ ├── BGEO.cpp │ │ ├── BIN.cpp │ │ ├── GEO.cpp │ │ ├── MC.cpp │ │ ├── PDA.cpp │ │ ├── PDB.cpp │ │ ├── PDC.cpp │ │ ├── PRT.cpp │ │ ├── PTC.cpp │ │ ├── PTS.cpp │ │ ├── ParticleIO.cpp │ │ ├── PartioEndian.h │ │ ├── RIB.cpp │ │ ├── ZIP.cpp │ │ ├── ZIP.h │ │ ├── half2float.h │ │ ├── pdb.h │ │ └── readers.h └── zlib │ ├── CMakeLists.txt │ └── src │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── gzio.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h ├── partio_extension ├── partio.py ├── partio_wrap.cxx ├── setup.cfg └── setup.py └── screenshots └── BlenderPartioTools.jpg /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jan Bender 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BlenderPartioTools is an open-source add-on to import particle data in Blender. The add-on can handle all file formats that are supported by the [Partio](https://www.disneyanimation.com/technology/partio.html) library. 2 | 3 | The add-on requires Blender 2.80 or newer. 4 | 5 | This add-on can be used to import and render the particle data generated with our fluid simulation library: 6 | - [https://github.com/InteractiveComputerGraphics/SPlisHSPlasH](https://github.com/InteractiveComputerGraphics/SPlisHSPlasH) 7 | 8 | **Author**: [Jan Bender](http://www.interactive-graphics.de), **License**: MIT 9 | 10 | ![](screenshots/BlenderPartioTools.jpg) 11 | 12 | ## Installation 13 | 14 | 1. This add-on requires the partio python module. This module can be built by the calling 15 | 16 | python setup.py build_ext 17 | 18 | in the directory partio_extension. Note that you have to use the same Python version as your Blender version uses (for Blender 2.80 this is Python 3.7). 19 | 20 | 2. Copy the generated file _partio.* (name depends on system) and the file partio.py to the Blender add-on folder. 21 | 22 | 3. Copy the file addon/BlenderPartioTools.py to the Blender add-on folder. 23 | 24 | 4. Start Blender and load add-on (Edit/Preferences/Add-ons) 25 | 26 | ## Usage 27 | 28 | After loading the add-on a new importer appears. To import partio data do the following steps: 29 | 30 | 1. Click on "File/Import/Partio Import". 31 | 2. Choose particle redius and maximum velocity (for coloring). 32 | 3. Choose partio file (the add-on assumes that the last number in the file name is the frame number). 33 | 34 | ## Remarks 35 | 36 | * Blender resets the particle system in frame 1. Therefore, the animation will start in frame 2 and all frame numbers are shifted by 1 (i.e. in frame 2 the file example_1.bgeo is loaded). 37 | * The add-on generates a hidden cube as emitter and renders the particles as spheres. If the radius should be adapted, edit the render settings of the cube's particle system. 38 | * By default the particle color is determined by the magnitude of the velocity of a particle. You can adapt this by modifying the shader. 39 | -------------------------------------------------------------------------------- /addon/BlenderPartioTools.py: -------------------------------------------------------------------------------- 1 | bl_info = { 2 | "name": "BlenderPartioTools", 3 | "description": "Importer for partio files.", 4 | "author": "Jan Bender", 5 | "version": (1, 0), 6 | "blender": (2, 80, 0), 7 | "warning": "", 8 | "wiki_url": "https://github.com/InteractiveComputerGraphics/BlenderPartioTools", 9 | "support": "COMMUNITY", 10 | "category": "Import-Export" 11 | } 12 | 13 | 14 | import bpy 15 | import sys 16 | import os 17 | import re 18 | import mathutils 19 | import partio 20 | from bpy_extras.io_utils import ImportHelper 21 | from bpy.app.handlers import persistent 22 | from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatProperty 23 | from bpy.types import Operator 24 | 25 | 26 | class PartioReader: 27 | def __init__( self, param ): 28 | self.param = param 29 | 30 | def __call__(self, scene, depsgraph=None): 31 | partioFile = self.param[0] 32 | emitterObject = self.param[1] 33 | 34 | try: 35 | dummy = emitterObject.name 36 | except: 37 | # emitter does not exist anymore 38 | #clear the post frame handler 39 | bpy.app.handlers.frame_change_post.remove(self) 40 | return 41 | 42 | indexlist = re.findall(r'\d+', partioFile) 43 | self.isSequence = True 44 | if len(indexlist) == 0: 45 | self.isSequence = False 46 | fileName = partioFile 47 | else: 48 | frameNumber = int(indexlist[-1]) 49 | idx = partioFile.rfind(str(frameNumber)) 50 | l = len(str(frameNumber)) 51 | fileName = str(partioFile[0:idx]) + str(scene.frame_current-1) + str(partioFile[idx+l:]) 52 | 53 | print("Read partio file: " + fileName) 54 | 55 | p=partio.read(fileName) 56 | 57 | if p != None: 58 | totalParticles = p.numParticles() 59 | print("# particles: " + str(totalParticles)) 60 | 61 | emitterObject.particle_systems[0].settings.count = totalParticles 62 | 63 | if totalParticles > 10000: 64 | emitterObject.particle_systems[0].settings.display_method = 'DOT' 65 | 66 | if depsgraph is None: 67 | depsgraph = bpy.context.evaluated_depsgraph_get() 68 | particle_systems = emitterObject.evaluated_get(depsgraph).particle_systems 69 | particles = particle_systems[0].particles 70 | 71 | posAttr = None 72 | velAttr = None 73 | for i in range(p.numAttributes()): 74 | attr=p.attributeInfo(i) 75 | typeStr="NONE" 76 | if attr.name=="position": posAttr = attr 77 | if attr.name=="velocity": velAttr = attr 78 | 79 | pos = [] 80 | for i in range(p.numParticles()): 81 | position = p.get(posAttr, i) 82 | x = mathutils.Vector((position[0], -position[2], position[1])) 83 | 84 | x = emitterObject.matrix_world @ x 85 | pos.append(x[0]) 86 | pos.append(x[1]) 87 | pos.append(x[2]) 88 | # Set the location of all particle locations to flatList 89 | particles.foreach_set("location", pos) 90 | 91 | 92 | if velAttr is not None: 93 | vel = [] 94 | for i in range(p.numParticles()): 95 | velocity = p.get(velAttr, i) 96 | v = mathutils.Vector((velocity[0], -velocity[2], velocity[1])) 97 | v = emitterObject.matrix_world @ v - emitterObject.location 98 | vel.append(v[0]) 99 | vel.append(v[1]) 100 | vel.append(v[2]) 101 | particles.foreach_set("velocity", vel) 102 | 103 | emitterObject.particle_systems[0].settings.frame_end = 0 104 | 105 | 106 | class PartioImporter(Operator, ImportHelper): 107 | bl_idname = "importer.partio" 108 | bl_label = "Import partio files" 109 | 110 | filter_glob: StringProperty( 111 | default="*.bgeo", 112 | options={'HIDDEN'}, 113 | maxlen=255, 114 | ) 115 | 116 | particleRadius: FloatProperty( 117 | name="Particle radius", 118 | description="Particle radius", 119 | default=0.025, 120 | ) 121 | 122 | maxVel: FloatProperty( 123 | name="Max. velocity", 124 | description="Max. velocity", 125 | default=5.0, 126 | ) 127 | 128 | def execute(self, context): 129 | self.emitterObject = None 130 | self.initParticleSystem() 131 | 132 | #run the function on each frame 133 | param = [self.filepath, self.emitterObject] 134 | 135 | self.emitterObject["partioFile"] = self.filepath 136 | 137 | bpy.app.handlers.frame_change_post.append(PartioReader(param)) 138 | 139 | scn = bpy.context.scene 140 | scn.render.engine = 'CYCLES' 141 | 142 | indexlist = re.findall(r'\d+', self.filepath) 143 | self.isSequence = True 144 | if len(indexlist) == 0: 145 | self.isSequence = False 146 | bpy.context.scene.frame_current = 2 147 | else: 148 | frameNumber = int(indexlist[-1]) 149 | bpy.context.scene.frame_current = frameNumber+1 150 | 151 | return {'FINISHED'} 152 | 153 | def initParticleSystem(self): 154 | # create emitter object 155 | bpy.ops.mesh.primitive_cube_add(enter_editmode=False, location=(0, 0, 0)) 156 | 157 | self.emitterObject = bpy.context.active_object 158 | self.emitterObject.hide_viewport = False 159 | self.emitterObject.hide_render = False 160 | self.emitterObject.hide_select = False 161 | 162 | # add particle system 163 | bpy.ops.object.modifier_add(type='PARTICLE_SYSTEM') 164 | bpy.context.object.show_instancer_for_render = False 165 | bpy.context.object.show_instancer_for_viewport = False 166 | 167 | self.emitterObject 168 | self.emitterObject.particle_systems[0].settings.frame_start = 0 169 | self.emitterObject.particle_systems[0].settings.frame_end = 0 170 | self.emitterObject.particle_systems[0].settings.lifetime = 1000 171 | self.emitterObject.particle_systems[0].settings.particle_size = self.particleRadius 172 | self.emitterObject.particle_systems[0].settings.display_size = 2.0 * self.particleRadius 173 | 174 | # add object for rendering particles 175 | bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=(0, 0, 0)) 176 | bpy.ops.object.shade_smooth() 177 | sphereObj = bpy.context.active_object 178 | sphereObj.hide_set(True) 179 | sphereObj.hide_viewport = False 180 | sphereObj.hide_render = True 181 | sphereObj.hide_select = True 182 | 183 | # add velocity-dependent color material 184 | found = True 185 | index = 1 186 | matNameBase = "ParticleMaterial" 187 | matName = matNameBase + str(index) 188 | materials = bpy.data.materials 189 | while (found): 190 | material = materials.get( matName ) 191 | if material: 192 | index += 1 193 | matName = matNameBase + str(index) 194 | else: 195 | found = False 196 | 197 | material = materials.new( matName ) 198 | 199 | 200 | material.use_nodes = True 201 | nodes = material.node_tree.nodes 202 | links = material.node_tree.links 203 | nodes.clear() 204 | links.clear() 205 | output = nodes.new( type = 'ShaderNodeOutputMaterial' ) 206 | diffuse = nodes.new( type = 'ShaderNodeBsdfDiffuse' ) 207 | link = links.new( diffuse.outputs['BSDF'], output.inputs['Surface'] ) 208 | 209 | particleInfo = nodes.new( type = 'ShaderNodeParticleInfo' ) 210 | 211 | vecMath = nodes.new( type = 'ShaderNodeVectorMath' ) 212 | vecMath.operation = 'DOT_PRODUCT' 213 | 214 | math1 = nodes.new( type = 'ShaderNodeMath' ) 215 | math1.operation = 'SQRT' 216 | math2 = nodes.new( type = 'ShaderNodeMath' ) 217 | math2.operation = 'MULTIPLY' 218 | math2.inputs[1].default_value = 1.0/self.maxVel 219 | math2.use_clamp = True 220 | 221 | 222 | ramp = nodes.new( type = 'ShaderNodeValToRGB' ) 223 | ramp.color_ramp.elements[0].color = (0, 0, 1, 1) 224 | 225 | link = links.new( particleInfo.outputs['Velocity'], vecMath.inputs[0] ) 226 | link = links.new( particleInfo.outputs['Velocity'], vecMath.inputs[1] ) 227 | 228 | link = links.new( vecMath.outputs['Value'], math1.inputs[0] ) 229 | link = links.new( math1.outputs['Value'], math2.inputs[0] ) 230 | link = links.new( math2.outputs['Value'], ramp.inputs['Fac'] ) 231 | link = links.new( ramp.outputs['Color'], diffuse.inputs['Color'] ) 232 | 233 | 234 | self.emitterObject.active_material = material 235 | sphereObj.active_material = material 236 | 237 | self.emitterObject.particle_systems[0].settings.render_type = 'OBJECT' 238 | self.emitterObject.particle_systems[0].settings.instance_object = bpy.data.objects[sphereObj.name] 239 | 240 | @persistent 241 | def loadPost(scene): 242 | for obj in bpy.data.objects: 243 | if "partioFile" in obj: 244 | param = [obj["partioFile"], obj] 245 | bpy.app.handlers.frame_change_post.append(PartioReader(param)) 246 | 247 | # Only needed if you want to add into a dynamic menu 248 | def menu_func_import(self, context): 249 | self.layout.operator(PartioImporter.bl_idname, text="Partio Import") 250 | 251 | 252 | def register(): 253 | bpy.utils.register_class(PartioImporter) 254 | bpy.types.TOPBAR_MT_file_import.append(menu_func_import) 255 | bpy.app.handlers.load_post.append(loadPost) 256 | print(bpy.app.handlers.load_post) 257 | 258 | 259 | def unregister(): 260 | bpy.utils.unregister_class(PartioImporter) 261 | bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) 262 | bpy.app.handlers.load_post.remove(loadPost) 263 | 264 | 265 | if __name__ == "__main__": 266 | print ("main") 267 | register() 268 | 269 | # test call 270 | bpy.ops.importer.partio('INVOKE_DEFAULT') 271 | unregister() -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/src/lib/PartioIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #ifndef _PartioParticleIterator_h_ 36 | #define _PartioParticleIterator_h_ 37 | 38 | #include 39 | #include 40 | #include 41 | #include "PartioAttribute.h" 42 | 43 | namespace Partio{ 44 | 45 | class ParticlesData; 46 | struct ParticleAccessor; 47 | 48 | //! Data 49 | /*! 50 | This class represents a piece of data stored in a particle attribute. 51 | The only allowed values are float and d 52 | */ 53 | template 54 | struct Data 55 | { 56 | T x[d]; 57 | 58 | const T& operator[](const int i) const {return x[i];} 59 | T& operator[](const int i) {return x[i];} 60 | }; 61 | typedef Data DataI; 62 | typedef Data DataF; 63 | typedef Data DataV; 64 | 65 | 66 | template class ParticleIterator; 67 | 68 | struct Provider 69 | { 70 | virtual void setupIteratorNextBlock(ParticleIterator& iterator) const=0; 71 | virtual void setupIteratorNextBlock(ParticleIterator& iterator)=0; 72 | virtual void setupAccessor(ParticleIterator& iterator,ParticleAccessor& accessor) const=0; 73 | virtual void setupAccessor(ParticleIterator& iterator,ParticleAccessor& accessor)=0; 74 | virtual ~Provider(){} 75 | }; 76 | 77 | template 78 | struct PROVIDER 79 | { 80 | typedef Provider TYPE; 81 | }; 82 | template<> 83 | struct PROVIDER 84 | { 85 | typedef const Provider TYPE; 86 | }; 87 | 88 | // TODO: non copyable 89 | struct ParticleAccessor 90 | { 91 | int stride; 92 | char* basePointer; 93 | int attributeIndex; // index of attribute opaque, do not touch 94 | int count; 95 | private: 96 | ParticleAttributeType type; 97 | 98 | ParticleAccessor* next; 99 | 100 | public: 101 | ParticleAccessor(const ParticleAttribute& attr) 102 | :stride(0),basePointer(0),attributeIndex(attr.attributeIndex), 103 | count(attr.count),type(attr.type),next(0) 104 | {} 105 | 106 | template TDATA* raw(const TITERATOR& it) 107 | {return reinterpret_cast(basePointer+it.index*stride);} 108 | 109 | template const TDATA* raw(const TITERATOR& it) const 110 | {return reinterpret_cast(basePointer+it.index*stride);} 111 | 112 | template TDATA& data(const TITERATOR& it) 113 | {return *reinterpret_cast(basePointer+it.index*stride);} 114 | 115 | template const TDATA& data(const TITERATOR& it) const 116 | {return *reinterpret_cast(basePointer+it.index*stride);} 117 | 118 | friend class ParticleIterator; 119 | friend class ParticleIterator; 120 | }; 121 | 122 | 123 | template 124 | class ParticleIterator 125 | { 126 | public: 127 | private: 128 | typedef typename PROVIDER::TYPE PROVIDER; 129 | 130 | //! Delegate, null if the iterator is false 131 | PROVIDER* particles; 132 | 133 | public: 134 | //! Start of non-interleaved index of contiguous block 135 | size_t index; 136 | private: 137 | 138 | //! End of non-interleaved index of contiguous block 139 | size_t indexEnd; 140 | 141 | //! This is used for both non-interleaved and interleaved particle attributes 142 | ParticleAccessor* accessors; 143 | 144 | public: 145 | //! Construct an invalid iterator 146 | ParticleIterator() 147 | :particles(0),index(0),indexEnd(0),accessors(0) 148 | {} 149 | 150 | //! Copy constructor. NOTE: Invalidates any accessors that have been registered with it 151 | ParticleIterator(const ParticleIterator& other) 152 | :particles(other.particles),index(other.index),indexEnd(other.indexEnd),accessors(0) 153 | {} 154 | 155 | //! Construct an iterator with iteration parameters. This is typically only 156 | //! called by implementations of Particle (not by users). For users, use 157 | //! begin() and end() on the particle type 158 | ParticleIterator(PROVIDER* particles,size_t index,size_t indexEnd) 159 | :particles(particles),index(index),indexEnd(indexEnd) 160 | {} 161 | 162 | //! Whether the iterator is valid 163 | bool valid() const 164 | {return particles;} 165 | 166 | //! Increment the iterator (postfix). Prefer the prefix form below to this one. 167 | ParticleIterator operator++(int) 168 | { 169 | ParticleIterator newIt(*this); 170 | index++; 171 | return newIt; 172 | } 173 | 174 | //! Increment the iterator (prefix). 175 | ParticleIterator& operator++() 176 | { 177 | index++; 178 | // TODO: make particles==0 check unnecessary by using indexEnd=0 to signify invalid iterator 179 | if((index>indexEnd) && particles) particles->setupIteratorNextBlock(*this); 180 | return *this; 181 | } 182 | 183 | //! Iterator comparison equals 184 | bool operator==(const ParticleIterator& other) 185 | { 186 | // TODO: this is really really expensive 187 | // TODO: this needs a block or somethingt o say which segment it is 188 | return particles==other.particles && index==other.index; 189 | } 190 | 191 | //! Iterator comparison not-equals 192 | bool operator!=(const ParticleIterator& other) 193 | { 194 | if(other.particles!=particles) return true; // if not same delegate 195 | else if(particles==0) return false; // if both are invalid iterators 196 | else return !(*this==other); 197 | } 198 | 199 | void addAccessor(ParticleAccessor& newAccessor) 200 | { 201 | newAccessor.next=accessors; 202 | accessors=&newAccessor; 203 | if(particles) particles->setupAccessor(*this,newAccessor); 204 | } 205 | 206 | 207 | // TODO: add copy constructor that wipes out accessor linked list 208 | 209 | }; 210 | 211 | template 212 | std::ostream& operator<<(std::ostream& output,const Data& v) 213 | { 214 | output< 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 | 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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/src/lib/core/ParticleHeaders.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2010 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include "ParticleHeaders.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | using namespace Partio; 42 | 43 | ParticleHeaders:: 44 | ParticleHeaders() 45 | :particleCount(0) 46 | { 47 | } 48 | 49 | ParticleHeaders:: 50 | ~ParticleHeaders() 51 | { 52 | } 53 | 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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/src/lib/io/MC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright (c) 2011 Disney Enterprises, Inc. and Contributors, All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | 35 | Format Contributed by github user: Jinkuen 36 | Modifications from: github user: redpawfx (redpawFX@gmail.com) and Luma Pictures 2011 37 | 38 | */ 39 | 40 | #include "../Partio.h" 41 | #include "../core/ParticleHeaders.h" 42 | #include "PartioEndian.h" // read/write big-endian file 43 | #include "ZIP.h" // for zip file 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | namespace Partio 52 | { 53 | //#define PartioBIG_ENDIAN 54 | 55 | using namespace std; 56 | 57 | // TODO: convert this to use iterators like the rest of the readers/writers 58 | 59 | std::string GetString(std::istream& input, unsigned int size){ 60 | char* tmp = new char [size]; 61 | input.read(tmp, size); 62 | std::string result(tmp); 63 | 64 | // fix read tag error (ex: DBLA --> DBLAi, why !!) 65 | if(result.size() > size){ 66 | result.resize(size); 67 | } 68 | 69 | delete [] tmp; 70 | return result; 71 | } 72 | 73 | typedef struct{ 74 | std::string name; 75 | std::string type; 76 | unsigned int numParticles; 77 | unsigned int blocksize; 78 | } Attribute_Header; 79 | 80 | 81 | bool ReadAttrHeader(std::istream& input, Attribute_Header& attribute){ 82 | char tag[4]; 83 | input.read(tag, 4); // CHNM 84 | 85 | int chnmSize; 86 | read(input, chnmSize); 87 | if(chnmSize%4 > 0){ 88 | chnmSize = chnmSize - chnmSize%4 + 4; 89 | } 90 | attribute.name = GetString(input, chnmSize); 91 | attribute.name = attribute.name.substr(attribute.name.find_first_of("_")+1); 92 | 93 | input.read(tag, 4); // SIZE 94 | int dummy; 95 | read(input, dummy); // 4 96 | 97 | read(input, attribute.numParticles); 98 | 99 | attribute.type = GetString(input, 4); 100 | 101 | read(input, attribute.blocksize); 102 | 103 | return true; 104 | } 105 | 106 | int CharArrayLen(char** charArray){ 107 | int i = 0; 108 | if(charArray != NULL){ 109 | while(charArray[i] != NULL){ 110 | i++; 111 | } 112 | } 113 | return i; 114 | } 115 | 116 | bool IsStringInCharArray(std::string target, char** list){ 117 | //std::cout << "Is " << target << " in "; 118 | for(int i = 0; i < CharArrayLen(list); i++){ 119 | //std::cout << std::string(list[i]) << " "; 120 | if(target == std::string(list[i])){ 121 | //std::cout << "? (YES)" << std::endl; 122 | return true; 123 | } 124 | } 125 | //std::cout << "? (NO)" << std::endl; 126 | return false; 127 | } 128 | 129 | static const int MC_MAGIC = ((((('F'<<8)|'O')<<8)|'R')<<8)|'4'; 130 | static const int HEADER_SIZE = 56; 131 | 132 | ParticlesDataMutable* readMC(const char* filename, const bool headersOnly,std::ostream* errorStream){ 133 | 134 | std::unique_ptr input(Gzip_In(filename,std::ios::in|std::ios::binary)); 135 | if(!*input){ 136 | if(errorStream) *errorStream << "Partio: Unable to open file " << filename << std::endl; 137 | return 0; 138 | } 139 | 140 | int magic; 141 | read(*input, magic); 142 | if(MC_MAGIC != magic){ 143 | if(errorStream) *errorStream << "Partio: Magic number '" << magic << "' of '" << filename << "' doesn't match mc magic '" << MC_MAGIC << "'" << std::endl; 144 | return 0; 145 | } 146 | 147 | int headerSize; 148 | read(*input, headerSize); 149 | 150 | int dummy; // tmp1, tmp2, num1, tmp3, tmp4, num2, num3, tmp5, num4, num5, blockTag 151 | for(int i = 0; i < 10; i++){ 152 | read(*input, dummy); 153 | //std::cout << dummy << std::endl; 154 | } 155 | 156 | char tag[4]; 157 | input->read(tag, 4); // FOR4 158 | 159 | int blockSize; 160 | read(*input, blockSize); 161 | 162 | // Allocate a simple particle with the appropriate number of points 163 | ParticlesDataMutable* simple=0; 164 | if(headersOnly){ 165 | simple = new ParticleHeaders; 166 | } 167 | else{ 168 | simple=create(); 169 | } 170 | 171 | int numParticles = 0; 172 | input->read(tag, 4); // MYCH 173 | while(((int)input->tellg()-HEADER_SIZE) < blockSize){ 174 | Attribute_Header attrHeader; 175 | ReadAttrHeader(*input, attrHeader); 176 | 177 | if(attrHeader.name == std::string("id")){ 178 | numParticles = attrHeader.numParticles; 179 | } 180 | 181 | if(attrHeader.blocksize/sizeof(double) == 1){ // for who ? 182 | input->seekg((int)input->tellg() + attrHeader.blocksize); 183 | continue; 184 | } 185 | #if 0 // TODO: if we ever put back attributes re-enable this 186 | if(attributes && (IsStringInCharArray(attrHeader.name, attributes)==false)){ 187 | input->seekg((int)input->tellg() + attrHeader.blocksize); 188 | continue; 189 | } 190 | #endif 191 | 192 | if(attrHeader.type == std::string("FVCA")){ 193 | input->seekg((int)input->tellg() + attrHeader.blocksize); 194 | simple->addAttribute(attrHeader.name.c_str(), VECTOR, 3); 195 | } 196 | else if(attrHeader.type == std::string("DBLA")){ 197 | input->seekg((int)input->tellg() + attrHeader.blocksize); 198 | if(attrHeader.name == "id"){ 199 | simple->addAttribute(attrHeader.name.c_str(), INT, 1); 200 | } 201 | else{ 202 | simple->addAttribute(attrHeader.name.c_str(), FLOAT, 1); 203 | } 204 | } 205 | else 206 | { 207 | input->seekg((int)input->tellg() + attrHeader.blocksize); 208 | if(errorStream) *errorStream << "Partio: Attribute '" << attrHeader.name << " " << attrHeader.type << "' cannot map type" << std::endl; 209 | } 210 | } 211 | simple->addParticles(numParticles); 212 | 213 | // If all we care about is headers, then return.-- 214 | if(headersOnly){ 215 | return simple; 216 | } 217 | //cout << "==============================================================" << endl; 218 | input->seekg(HEADER_SIZE); 219 | input->read(tag, 4); // MYCH 220 | while((int)input->tellg()-HEADER_SIZE < blockSize){ 221 | Attribute_Header attrHeader; 222 | ReadAttrHeader(*input, attrHeader); 223 | 224 | if(attrHeader.blocksize/sizeof(double) == 1){ // for who ? 225 | input->seekg((int)input->tellg() + attrHeader.blocksize); 226 | continue; 227 | } 228 | 229 | ParticleAttribute attrHandle; 230 | if(simple->attributeInfo(attrHeader.name.c_str(), attrHandle) == false){ 231 | input->seekg((int)input->tellg() + attrHeader.blocksize); 232 | continue; 233 | } 234 | 235 | Partio::ParticlesDataMutable::iterator it = simple->begin(); 236 | Partio::ParticleAccessor accessor(attrHandle); 237 | it.addAccessor(accessor); 238 | 239 | //std::cout << attrHeader.name << std::endl; 240 | if (attrHeader.type == std::string("DBLA")){ 241 | if (attrHeader.name == "id") 242 | { 243 | for (int i = 0; i < simple->numParticles(); i++) 244 | { 245 | double tmp; 246 | read(*input, tmp); 247 | int* data = simple->dataWrite(attrHandle, i); 248 | data[0] = (int)tmp; 249 | } 250 | } 251 | else{ 252 | for (int i = 0; i < simple->numParticles(); i++){ 253 | double tmp; 254 | read(*input, tmp); 255 | float* data = simple->dataWrite(attrHandle, i); 256 | data[0] = (float)tmp; 257 | } 258 | } 259 | } 260 | else if(attrHeader.type == std::string("FVCA")){ 261 | for(Partio::ParticlesDataMutable::iterator end = simple->end(); it != end; ++it){ 262 | input->read(accessor.raw(it), sizeof(float)*attrHandle.count); 263 | } 264 | it = simple->begin(); 265 | for(Partio::ParticlesDataMutable::iterator end = simple->end(); it != end; ++it){ 266 | float* data = accessor.raw(it); 267 | for(int i = 0; i < attrHandle.count; i++){ 268 | BIGEND::swap(data[i]); 269 | //data[k]=buffer[attrOffsets[attrIndex]+k]; 270 | //data[i] = endianSwap(data[i]); 271 | } 272 | } 273 | 274 | 275 | } 276 | /* 277 | if(0){ 278 | std::cout << typeName << std::endl; 279 | std::cerr << "Partio: " << filename << " had unknown attribute spec " << typeName << " " << name << std::endl; 280 | simple->release(); 281 | return 0; 282 | }*/ 283 | 284 | } 285 | return simple; 286 | 287 | } 288 | /* 289 | bool dgMc::open(string filePath){ 290 | timeval t1, t2; 291 | 292 | ReadStr(file, 4); // MYCH 293 | 294 | while(((int)file.tellg()-8-40-8) < header.blockSize){ 295 | ReadStr(file, 4); // CHNM 296 | 297 | int chnmSize = ReadInt(file); 298 | if(chnmSize%4 > 0){ 299 | chnmSize = chnmSize - chnmSize%4 + 4; 300 | } 301 | string attrname = ReadChar(file, chnmSize); 302 | attrname = attrname.substr(attrname.find_first_of("_")+1); 303 | //cout << attrname << endl; 304 | 305 | ReadStr(file, 4); // SIZE 306 | ReadInt(file); 307 | 308 | int arrayLength = ReadInt(file); 309 | string format = ReadStr(file, 4); // DBLA or FVCA 310 | int bufferLength = ReadInt(file); 311 | 312 | string DBLA("DBLA"); 313 | //cout << format << " " << arrayLength << " " << bufferLength << endl; 314 | if(format == string("DBLA")){ 315 | ReadDoubleArray(file, (int)file.tellg(), &_doubleArray[attrname], arrayLength); 316 | //file.seekg((int)file.tellg() + bufferLength); 317 | } 318 | else{ // FVCA 319 | ReadVectorArray(file, (int)file.tellg(), &_vectorArray[attrname], arrayLength); 320 | if(attrname == string("position")){ 321 | //ReadVectorArray(file, (int)file.tellg(), &_vectorArray[attrname], arrayLength); 322 | //file.seekg((int)file.tellg() + bufferLength); 323 | } 324 | else{ 325 | 326 | //file.seekg((int)file.tellg() + bufferLength); 327 | } 328 | //return true; 329 | } 330 | 331 | if(attrname == string("id")){ 332 | _numParticles = arrayLength; 333 | } 334 | } 335 | return true; 336 | } 337 | 338 | int main(){ 339 | cout << "go" << endl; 340 | 341 | timeval t1, t2; 342 | double elapsedTime; 343 | gettimeofday(&t1, NULL); 344 | 345 | for(int i = 0; i < 1; i++){ 346 | dgMc mc; 347 | mc.open(string("/dept/rdworks/jinkuen/testfile/mc/real_nParticleShape1Frame47.mc")); 348 | cout << mc.numParticles() << " "; 349 | for(int i = 0; i < mc.count(); i++){ 350 | cout << mc.list(dgParticle::All)[i] << " "; 351 | } 352 | mc.clear(); 353 | } 354 | cout << endl; 355 | 356 | gettimeofday(&t2, NULL); 357 | elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms 358 | elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms 359 | cout << elapsedTime << " ms.\n"; 360 | 361 | return 1; 362 | } 363 | 364 | */ 365 | 366 | } 367 | -------------------------------------------------------------------------------- /extern/partio/src/lib/io/PDA.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright 2011 Disney Enterprises, Inc. All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | */ 35 | #include "../Partio.h" 36 | #include "../core/ParticleHeaders.h" 37 | #include "ZIP.h" 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace Partio 46 | { 47 | 48 | using namespace std; 49 | 50 | // TODO: convert this to use iterators like the rest of the readers/writers 51 | 52 | ParticlesDataMutable* readPDA(const char* filename,const bool headersOnly,std::ostream* errorStream) 53 | { 54 | unique_ptr input(Gzip_In(filename,ios::in|ios::binary)); 55 | if(!*input){ 56 | if(errorStream) *errorStream <<"Partio: Can't open particle data file: "<good()){ 68 | *input>>word; 69 | if(word!="ATTRIBUTES"){simple->release();return 0;} 70 | } 71 | 72 | vector attrNames; 73 | vector attrs; 74 | 75 | while(input->good()){ 76 | *input>>word; 77 | if(word=="TYPES") break;; 78 | attrNames.push_back(word); 79 | } 80 | 81 | size_t index=0; 82 | while(input->good()){ 83 | *input>>word; 84 | if(word=="NUMBER_OF_PARTICLES:") break; 85 | 86 | if(index>=attrNames.size()) continue; 87 | 88 | if(word=="V"){ 89 | attrs.push_back(simple->addAttribute(attrNames[index].c_str(),Partio::VECTOR,3)); 90 | }else if(word=="R"){ 91 | attrs.push_back(simple->addAttribute(attrNames[index].c_str(),Partio::FLOAT,1)); 92 | }else if(word=="I"){ 93 | attrs.push_back(simple->addAttribute(attrNames[index].c_str(),Partio::INT,1)); 94 | } 95 | 96 | index++; 97 | } 98 | 99 | unsigned int num=0; 100 | if(input->good()){ 101 | *input>>num; 102 | simple->addParticles(num); 103 | if(headersOnly) return simple; // escape before we try to touch data 104 | }else{ 105 | simple->release(); 106 | return 0; 107 | } 108 | 109 | // look for beginning of header 110 | if(input->good()){ 111 | *input>>word; 112 | if(word != "BEGIN"){simple->release();return 0;} 113 | } 114 | if(input->good()){ 115 | *input>>word; 116 | if(word != "DATA"){simple->release();return 0;} 117 | } 118 | 119 | // Read actual particle data 120 | if(!input->good()){simple->release();return 0;} 121 | for(unsigned int particleIndex=0;input->good() && particleIndexdataWrite(attrs[attrIndex],particleIndex); 125 | for(int count=0;count>ival; 128 | data[count]=ival; 129 | } 130 | }else if(attrs[attrIndex].type==Partio::FLOAT || attrs[attrIndex].type==Partio::VECTOR){ 131 | float* data=simple->dataWrite(attrs[attrIndex],particleIndex); 132 | for(int count=0;count>fval; 135 | data[count]=fval; 136 | } 137 | } 138 | } 139 | } 140 | 141 | return simple; 142 | } 143 | 144 | bool writePDA(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) 145 | { 146 | unique_ptr output( 147 | compressed ? 148 | Gzip_Out(filename,ios::out|ios::binary) 149 | :new ofstream(filename,ios::out|ios::binary)); 150 | 151 | *output<<"ATTRIBUTES"< attrs; 154 | for (int aIndex=0;aIndex(attrs[attrIndex],particleIndex); 181 | for(int count=0;count(attrs[attrIndex],particleIndex); 185 | for(int count=0;count 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | namespace Partio 53 | { 54 | 55 | using namespace std; 56 | 57 | template struct PDB_POLICY; 58 | template<> struct PDB_POLICY<32> 59 | { 60 | typedef PDB::PDB_Header32 HEADER; 61 | typedef PDB::PDBdata32 DATA; 62 | typedef PDB::Channel32 CHANNEL; 63 | typedef PDB::Channel_Data32 CHANNEL_DATA; 64 | typedef PDB::Channel_io_Header CHANNEL_IO; 65 | }; 66 | template<> struct PDB_POLICY<64> 67 | { 68 | typedef PDB::PDB_Header HEADER; 69 | typedef PDB::PDBdata DATA; 70 | typedef PDB::Channel CHANNEL; 71 | typedef PDB::Channel_Data CHANNEL_DATA; 72 | typedef PDB::Channel_io_Header CHANNEL_IO; 73 | }; 74 | 75 | string GetString(istream& input,bool& error) 76 | { 77 | const char terminator='\0'; 78 | // TODO: make this check for FEOF condition! and also more efficient 79 | char c=' '; 80 | string s=""; 81 | error=true; 82 | while (input) 83 | { 84 | input.read(&c,sizeof(char)); 85 | if(c == terminator){error=false;break;} 86 | s += c; 87 | } 88 | return s; 89 | } 90 | 91 | 92 | template ParticlesDataMutable* readPDBHelper(const char* filename,const bool headersOnly,std::ostream* errorStream) 93 | { 94 | 95 | unique_ptr input(Gzip_In(filename,ios::in|ios::binary)); 96 | if(!*input){ 97 | if(errorStream) *errorStream<<"Partio: Unable to open file "<::HEADER header; 108 | 109 | input->read((char*)&header,sizeof(typename PDB_POLICY::HEADER)); 110 | if(header.magic != PDB_MAGIC){ 111 | if(errorStream) *errorStream<<"Partio: failed to get PDB magic"<addParticles(header.data_size); 116 | 117 | for(unsigned int i=0;i::CHANNEL_IO channelIOHeader; 119 | input->read((char*)&channelIOHeader,sizeof(channelIOHeader)); 120 | typename PDB_POLICY::CHANNEL channelHeader; 121 | input->read((char*)&channelHeader,sizeof(channelHeader)); 122 | bool error; 123 | string name=GetString(*input,error); 124 | if(error){ 125 | simple->release(); 126 | return 0; 127 | } 128 | 129 | typename PDB_POLICY::CHANNEL_DATA channelData; 130 | input->read((char*)&channelData,sizeof(channelData)); 131 | 132 | 133 | ParticleAttributeType type; 134 | switch(channelHeader.type){ 135 | case PDB_VECTOR: type=VECTOR;break; 136 | case PDB_REAL: type=FLOAT;break; 137 | case PDB_LONG: type=INT;break; 138 | default: type=NONE;break; 139 | } 140 | int size=header.data_size*channelData.datasize; 141 | 142 | // Read data or skip if we haven't found appropriate type handle 143 | if(type==NONE){ 144 | char buf[1024]; 145 | int toSkip=size; 146 | while(toSkip>0){ 147 | input->read(buf,min(toSkip,1024)); 148 | toSkip-=1024; 149 | } 150 | if(errorStream) *errorStream<<"Partio: Attribute '"<addAttribute(name.c_str(),type,count); 154 | if(headersOnly){ 155 | char buf[1024]; 156 | int toSkip=size; 157 | while(toSkip>0){ 158 | input->read(buf,min(toSkip,1024)); 159 | toSkip-=1024; 160 | } 161 | }else{ 162 | Partio::ParticlesDataMutable::iterator it=simple->begin(); 163 | Partio::ParticleAccessor accessor(attrHandle); 164 | it.addAccessor(accessor); 165 | 166 | for(Partio::ParticlesDataMutable::iterator end=simple->end();it!=end;++it){ 167 | input->read(accessor.raw(it),sizeof(float)*attrHandle.count); 168 | } 169 | } 170 | } 171 | } 172 | return simple; 173 | } 174 | 175 | template 176 | bool writePDBHelper(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) 177 | { 178 | unique_ptr output( 179 | compressed ? 180 | Gzip_Out(filename,ios::out|ios::binary) 181 | :new ofstream(filename,ios::out|ios::binary)); 182 | 183 | if(!*output){ 184 | if(errorStream) *errorStream<<"Partio Unable to open file "<::HEADER h32; 189 | memset(&h32,0,sizeof(typename PDB_POLICY::HEADER)); 190 | h32.magic=PDB_MAGIC; 191 | h32.swap=1; 192 | h32.version=1.0; 193 | h32.time=0.0; 194 | h32.data_size=p.numParticles(); 195 | h32.num_data=p.numAttributes(); 196 | for(int k=0;k<32;k++) h32.padding[k]=0; 197 | h32.data=0; 198 | output->write((char*)&h32,sizeof(typename PDB_POLICY::HEADER)); 199 | 200 | for(int attrIndex=0;attrIndex::CHANNEL_IO cio; 205 | typename PDB_POLICY::CHANNEL channel; 206 | typename PDB_POLICY::CHANNEL_DATA data_header; 207 | memset(&cio,0,sizeof(typename PDB_POLICY::CHANNEL_IO)); 208 | memset(&channel,0,sizeof(typename PDB_POLICY::CHANNEL)); 209 | memset(&data_header,0,sizeof(typename PDB_POLICY::CHANNEL_DATA)); 210 | 211 | cio.magic=0; 212 | cio.swap=1; 213 | cio.encoding=0; 214 | cio.type=0; 215 | output->write((char*)&cio,sizeof(typename PDB_POLICY::CHANNEL_IO)); 216 | 217 | // TODO: assert cproper count! 218 | channel.name=0; 219 | switch(attr.type){ 220 | case INDEXEDSTR:channel.type=PDB_LONG;break; 221 | case INT:channel.type=PDB_LONG;break; 222 | case FLOAT:channel.type=PDB_REAL;break; 223 | case VECTOR:channel.type=PDB_VECTOR;break; 224 | default: assert(false); 225 | } 226 | channel.size=0; 227 | channel.active_start=0; 228 | channel.active_end=h32.data_size-1; 229 | channel.hide=0; 230 | channel.disconnect=0; 231 | channel.data=0; 232 | channel.link=0; 233 | channel.next=0; 234 | output->write((char*)&channel,sizeof(channel)); 235 | output->write(attr.name.c_str(),attr.name.length()*sizeof(char)+1); 236 | data_header.type=channel.type; 237 | data_header.datasize=attr.count*sizeof(float); 238 | data_header.blocksize=p.numParticles(); 239 | data_header.num_blocks=1; 240 | data_header.block=0; 241 | output->write((char*)&data_header,sizeof(data_header)); 242 | 243 | Partio::ParticlesData::const_iterator it=p.begin(); 244 | Partio::ParticleAccessor accessor(attr); 245 | it.addAccessor(accessor); 246 | 247 | for(Partio::ParticlesData::const_iterator end=p.end();it!=end;++it){ 248 | output->write(accessor.raw(it),sizeof(float)*attr.count); 249 | } 250 | } 251 | return true; 252 | } 253 | 254 | ParticlesDataMutable* readPDB32(const char* filename,const bool headersOnly,std::ostream* errorStream) 255 | {return readPDBHelper<32>(filename,headersOnly,errorStream);} 256 | 257 | ParticlesDataMutable* readPDB64(const char* filename,const bool headersOnly,std::ostream* errorStream) 258 | {return readPDBHelper<64>(filename,headersOnly,errorStream);} 259 | 260 | bool writePDB32(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) 261 | {return writePDBHelper<32>(filename,p,compressed,errorStream);} 262 | 263 | bool writePDB64(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) 264 | {return writePDBHelper<64>(filename,p,compressed,errorStream);} 265 | 266 | ParticlesDataMutable* readPDB(const char* filename,const bool headersOnly,std::ostream* errorStream) 267 | { 268 | unique_ptr input(Gzip_In(filename,ios::in|ios::binary)); 269 | if(!*input){ 270 | if(errorStream) *errorStream <<"Partio: Unable to open file "<::HEADER header; 275 | input->read((char*)&header,sizeof(header)); 276 | if(header.magic != PDB_MAGIC){ 277 | if(errorStream) *errorStream <<"Partio: failed to get PDB magic"<::CHANNEL_IO channelIOHeader; 283 | input->read((char*)&channelIOHeader,sizeof(channelIOHeader)); 284 | //cout<<"we got channel io as "< 5 || channelIOHeader.type < 0 || (channelIOHeader.swap != 1 && channelIOHeader.swap != 0)){ 286 | return readPDBHelper<32>(filename,headersOnly,errorStream); 287 | }else{ 288 | return readPDBHelper<64>(filename,headersOnly,errorStream); 289 | } 290 | } 291 | 292 | bool writePDB(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream) 293 | {return writePDBHelper<32>(filename,p,compressed,errorStream);} 294 | 295 | } 296 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/src/lib/io/PTS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | PARTIO SOFTWARE 3 | Copyright (c) 2011 Disney Enterprises, Inc. and Contributors, All rights reserved 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation 18 | Studios" or the names of its contributors may NOT be used to 19 | endorse or promote products derived from this software without 20 | specific prior written permission from Walt Disney Pictures. 21 | 22 | Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 | FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED. 26 | IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 34 | 35 | Format Contributed by github user: redpawfx (redpawFX@gmail.com) and Luma Pictures 2011 36 | Some code for this format was helped along by referring to an implementation by 37 | */ 38 | #include "../Partio.h" 39 | #include "../core/ParticleHeaders.h" 40 | #include "ZIP.h" 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | namespace Partio 51 | { 52 | 53 | using namespace std; 54 | 55 | // TODO: convert this to use iterators like the rest of the readers/writers 56 | 57 | ParticlesDataMutable* readPTS(const char* filename,const bool headersOnly,std::ostream* errorStream) 58 | { 59 | unique_ptr input(Gzip_In(filename,ios::in|ios::binary)); 60 | if (!*input) 61 | { 62 | if(errorStream) *errorStream<<"Partio: Can't open particle data file: "< attrNames; 74 | vector attrs; 75 | 76 | /// we're going to fake the ID attribute since there's no such thing in PTS Files 77 | attrNames.push_back((string)"id"); 78 | attrs.push_back(simple->addAttribute(attrNames[0].c_str(),Partio::INT,1)); 79 | 80 | /// FORMAT is up to 8 elements space delimited { posX posY posZ remission quality red green blue } 81 | // since there's no header data to parse we're just going to hard code this 82 | 83 | /* Start from the beginning */ 84 | input->seekg(0,ios::beg); 85 | 86 | /* Determine amount of values per line */ 87 | char line[1024]; 88 | /* Jump over first line. */ 89 | input->getline(line,1024); 90 | input->getline(line,1024); 91 | int valcount = 0; 92 | #ifdef PARTIO_WIN32 93 | char * nextLine = NULL; 94 | char * pch = strtok_s( line, "\t ", &nextLine ); 95 | #else 96 | char * pch = strtok( line, "\t " ); 97 | #endif 98 | while ( pch ) 99 | { 100 | if ( *pch != 0 && *pch != '\n' ) 101 | { 102 | valcount++; 103 | } 104 | #ifdef PARTIO_WIN32 105 | pch = strtok_s( NULL, "\t ", &nextLine ); 106 | #else 107 | pch = strtok( NULL, "\t " ); 108 | #endif 109 | } 110 | 111 | 112 | switch ( valcount ) 113 | { 114 | case 3: // position only 115 | { 116 | attrNames.push_back((string)"position"); 117 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 118 | } 119 | break; 120 | case 4: // position and remission 121 | { 122 | attrNames.push_back((string)"position"); 123 | attrNames.push_back((string)"remission"); 124 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 125 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::FLOAT,1)); 126 | } 127 | break; 128 | case 6: // position and RGB 129 | { 130 | attrNames.push_back((string)"position"); 131 | attrNames.push_back((string)"pointColor"); 132 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 133 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::VECTOR,3)); 134 | } 135 | break; 136 | case 7: // position remission and RGB 137 | { 138 | attrNames.push_back((string)"position"); 139 | attrNames.push_back((string)"remission"); 140 | attrNames.push_back((string)"pointColor"); 141 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 142 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::FLOAT,1)); 143 | attrs.push_back(simple->addAttribute(attrNames[3].c_str(),Partio::VECTOR,3)); 144 | } 145 | break; 146 | case 8: // everything 147 | { 148 | attrNames.push_back((string)"position"); 149 | attrNames.push_back((string)"remission"); 150 | attrNames.push_back((string)"quality"); 151 | attrNames.push_back((string)"pointColor"); 152 | attrs.push_back(simple->addAttribute(attrNames[1].c_str(),Partio::VECTOR,3)); 153 | attrs.push_back(simple->addAttribute(attrNames[2].c_str(),Partio::FLOAT,1)); 154 | attrs.push_back(simple->addAttribute(attrNames[3].c_str(),Partio::INT,1)); 155 | attrs.push_back(simple->addAttribute(attrNames[4].c_str(),Partio::VECTOR,3)); 156 | } 157 | break; 158 | default: 159 | { 160 | return 0; 161 | } 162 | break; 163 | 164 | } 165 | 166 | input->seekg(0,ios::beg); 167 | 168 | unsigned int num=0; 169 | simple->addParticles(num); 170 | if (headersOnly) return simple; // escape before we try to touch data 171 | 172 | if (input->good()) 173 | { // garbage count at top of file 174 | char junk[1024]; 175 | input->getline(junk,1024); 176 | } 177 | 178 | // Read actual particle data 179 | if (!input->good()) { 180 | simple->release(); 181 | return 0; 182 | } 183 | 184 | // we have to read line by line, because data is not clean and consistent so we skip any lines that dont' conform 185 | 186 | for (unsigned int particleIndex=0;input->good();) 187 | { 188 | string token = ""; 189 | char line[1024]; 190 | input->getline(line, 1024); 191 | 192 | stringstream ss(line); 193 | 194 | float lineData[8]; 195 | int i = 0; 196 | 197 | while (ss >> token) 198 | { 199 | stringstream foo(token); 200 | float x; 201 | foo >> x; 202 | lineData[i] = x; 203 | i++; 204 | } 205 | 206 | if (i == valcount) 207 | { 208 | simple->addParticle(); 209 | for (unsigned int attrIndex=0;attrIndexdataWrite(attrs[attrIndex],particleIndex); 214 | if (attrs[attrIndex].name == "id") 215 | { 216 | data[0]=particleIndex; 217 | } 218 | else 219 | { 220 | data[0] = (int)lineData[4]; 221 | } 222 | 223 | 224 | } 225 | else if (attrs[attrIndex].type==Partio::FLOAT || attrs[attrIndex].type==Partio::VECTOR) 226 | { 227 | float* data=simple->dataWrite(attrs[attrIndex],particleIndex); 228 | 229 | if (attrs[attrIndex].name == "pointColor") 230 | { 231 | // 8 bit color conversion 232 | data[0]=lineData[4]/255; 233 | data[1]=lineData[5]/255; 234 | data[2]=lineData[6]/255; 235 | } 236 | else if (attrs[attrIndex].name == "position") 237 | { 238 | // position, we flip y/z 239 | data[0]=lineData[0]; 240 | data[1]=lineData[2]; 241 | data[2]=lineData[1]; 242 | } 243 | else if (attrs[attrIndex].name == "remission") 244 | { 245 | data[0] = lineData[3]; 246 | } 247 | 248 | } 249 | } 250 | particleIndex++; 251 | } 252 | } 253 | return simple; 254 | } 255 | 256 | /// THIS DOESENT WORK YET>> 257 | /* 258 | bool writePTS(const char* filename,const ParticlesData& p,const bool compressed) 259 | { 260 | unique_ptr output( 261 | compressed ? 262 | Gzip_Out(filename,ios::out|ios::binary) 263 | :new ofstream(filename,ios::out|ios::binary)); 264 | 265 | *output<<"ATTRIBUTES"< attrs; 268 | for (int aIndex=0;aIndex(attrs[attrIndex],particleIndex); 295 | for(int count=0;count(attrs[attrIndex],particleIndex); 299 | for(int count=0;count 37 | #include "../core/Mutex.h" 38 | #include "../Partio.h" 39 | #include "readers.h" 40 | 41 | namespace Partio{ 42 | using namespace std; 43 | 44 | // reader and writer code 45 | typedef ParticlesDataMutable* (*READER_FUNCTION)(const char*,const bool,std::ostream*); 46 | typedef bool (*WRITER_FUNCTION)(const char*,const ParticlesData&,const bool,std::ostream*); 47 | 48 | PartioMutex initializationMutex; 49 | 50 | map& 51 | readers() 52 | { 53 | static map data; 54 | static bool initialized=false; 55 | if(!initialized){ 56 | initializationMutex.lock(); 57 | data["bgeo"]=readBGEO; 58 | data["bhclassic"]=readBGEO; 59 | data["geo"]=readGEO; 60 | data["hclassic"]=readGEO; 61 | data["pdb"]=readPDB; 62 | data["pdb32"]=readPDB32; 63 | data["pdb64"]=readPDB64; 64 | data["pda"]=readPDA; 65 | data["mc"]=readMC; 66 | data["ptc"]=readPTC; 67 | data["pdc"]=readPDC; 68 | data["prt"]=readPRT; 69 | data["bin"]=readBIN; 70 | data["pts"]=readPTS; 71 | data["ptf"]=readPTC; 72 | data["itbl"]=readBGEO; 73 | data["atbl"]=readBGEO; 74 | initialized=true; 75 | initializationMutex.unlock(); 76 | } 77 | return data; 78 | } 79 | 80 | map& 81 | writers() 82 | { 83 | static map data; 84 | static bool initialized=false; 85 | if(!initialized){ 86 | initializationMutex.lock(); 87 | data["bgeo"]=writeBGEO; 88 | data["bhclassic"]=writeBGEO; 89 | data["geo"]=writeGEO; 90 | data["hclassic"]=writeGEO; 91 | data["pdb"]=writePDB; 92 | data["pdb32"]=writePDB32; 93 | data["pdb64"]=writePDB64; 94 | data["pda"]=writePDA; 95 | data["ptc"]=writePTC; 96 | data["rib"]=writeRIB; 97 | data["pdc"]=writePDC; 98 | data["prt"]=writePRT; 99 | data["bin"]=writeBIN; 100 | data["ptf"]=writePTC; 101 | data["itbl"]=writeBGEO; 102 | data["atbl"]=writeBGEO; 103 | initialized=true; 104 | initializationMutex.unlock(); 105 | } 106 | return data; 107 | } 108 | 109 | //! Gives extension of a file ignoring any trailing .gz 110 | //! i.e. for 'foo.pdb.gz' it gives 'pdb', for 'foo.pdb' it gives 'pdb' 111 | bool extensionIgnoringGz(const string& filename,string& ret,bool &endsWithGz,std::ostream& errorStream) 112 | { 113 | size_t period=filename.rfind('.'); 114 | endsWithGz=false; 115 | if(period==string::npos){ 116 | errorStream<<"Partio: No extension detected in filename"<::iterator i=readers().find(extension); 143 | if(i==readers().end()){ 144 | errorStream<<"Partio: No reader defined for extension "<second)(c_filename,false,verbose ? &errorStream : 0); 148 | } 149 | 150 | ParticlesInfo* 151 | readHeaders(const char* c_filename,bool verbose,std::ostream& errorStream) 152 | { 153 | string filename(c_filename); 154 | string extension; 155 | bool endsWithGz; 156 | if(!extensionIgnoringGz(filename,extension,endsWithGz,errorStream)) return 0; 157 | map::iterator i=readers().find(extension); 158 | if(i==readers().end()){ 159 | errorStream<<"Partio: No reader defined for extension "<second)(c_filename,true,verbose ? &errorStream : 0); 163 | } 164 | 165 | void 166 | write(const char* c_filename,const ParticlesData& particles,const bool forceCompressed,bool verbose,std::ostream& errorStream) 167 | { 168 | string filename(c_filename); 169 | string extension; 170 | bool endsWithGz; 171 | if(!extensionIgnoringGz(filename,extension,endsWithGz,errorStream)) return; 172 | map::iterator i=writers().find(extension); 173 | if(i==writers().end()){ 174 | errorStream<<"Partio: No writer defined for extension "<second)(c_filename,particles,forceCompressed || endsWithGz,verbose ? &errorStream : 0); 178 | } 179 | 180 | } // namespace Partio 181 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/partio/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 | -------------------------------------------------------------------------------- /extern/zlib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(zlib STATIC 2 | src/adler32.c 3 | src/compress.c 4 | src/crc32.c 5 | src/crc32.h 6 | src/deflate.c 7 | src/deflate.h 8 | src/gzio.c 9 | src/infback.c 10 | src/inffast.c 11 | src/inffast.h 12 | src/inffixed.h 13 | src/inflate.c 14 | src/inflate.h 15 | src/inftrees.c 16 | src/inftrees.h 17 | src/trees.c 18 | src/trees.h 19 | src/uncompr.c 20 | src/zconf.h 21 | src/zlib.h 22 | src/zutil.c 23 | src/zutil.h 24 | ) 25 | 26 | set_target_properties(zlib PROPERTIES FOLDER "External Dependencies") 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /extern/zlib/src/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | #define BASE 65521UL /* largest prime smaller than 65536 */ 12 | #define NMAX 5552 13 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 14 | 15 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 16 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 17 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 18 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 19 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 20 | 21 | /* use NO_DIVIDE if your processor does not do division in hardware */ 22 | #ifdef NO_DIVIDE 23 | # define MOD(a) \ 24 | do { \ 25 | if (a >= (BASE << 16)) a -= (BASE << 16); \ 26 | if (a >= (BASE << 15)) a -= (BASE << 15); \ 27 | if (a >= (BASE << 14)) a -= (BASE << 14); \ 28 | if (a >= (BASE << 13)) a -= (BASE << 13); \ 29 | if (a >= (BASE << 12)) a -= (BASE << 12); \ 30 | if (a >= (BASE << 11)) a -= (BASE << 11); \ 31 | if (a >= (BASE << 10)) a -= (BASE << 10); \ 32 | if (a >= (BASE << 9)) a -= (BASE << 9); \ 33 | if (a >= (BASE << 8)) a -= (BASE << 8); \ 34 | if (a >= (BASE << 7)) a -= (BASE << 7); \ 35 | if (a >= (BASE << 6)) a -= (BASE << 6); \ 36 | if (a >= (BASE << 5)) a -= (BASE << 5); \ 37 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 38 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 39 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 40 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 41 | if (a >= BASE) a -= BASE; \ 42 | } while (0) 43 | # define MOD4(a) \ 44 | do { \ 45 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 46 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 47 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 48 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 49 | if (a >= BASE) a -= BASE; \ 50 | } while (0) 51 | #else 52 | # define MOD(a) a %= BASE 53 | # define MOD4(a) a %= BASE 54 | #endif 55 | 56 | /* ========================================================================= */ 57 | uLong ZEXPORT adler32(adler, buf, len) 58 | uLong adler; 59 | const Bytef *buf; 60 | uInt len; 61 | { 62 | unsigned long sum2; 63 | unsigned n; 64 | 65 | /* split Adler-32 into component sums */ 66 | sum2 = (adler >> 16) & 0xffff; 67 | adler &= 0xffff; 68 | 69 | /* in case user likes doing a byte at a time, keep it fast */ 70 | if (len == 1) { 71 | adler += buf[0]; 72 | if (adler >= BASE) 73 | adler -= BASE; 74 | sum2 += adler; 75 | if (sum2 >= BASE) 76 | sum2 -= BASE; 77 | return adler | (sum2 << 16); 78 | } 79 | 80 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 81 | if (buf == Z_NULL) 82 | return 1L; 83 | 84 | /* in case short lengths are provided, keep it somewhat fast */ 85 | if (len < 16) { 86 | while (len--) { 87 | adler += *buf++; 88 | sum2 += adler; 89 | } 90 | if (adler >= BASE) 91 | adler -= BASE; 92 | MOD4(sum2); /* only added so many BASE's */ 93 | return adler | (sum2 << 16); 94 | } 95 | 96 | /* do length NMAX blocks -- requires just one modulo operation */ 97 | while (len >= NMAX) { 98 | len -= NMAX; 99 | n = NMAX / 16; /* NMAX is divisible by 16 */ 100 | do { 101 | DO16(buf); /* 16 sums unrolled */ 102 | buf += 16; 103 | } while (--n); 104 | MOD(adler); 105 | MOD(sum2); 106 | } 107 | 108 | /* do remaining bytes (less than NMAX, still just one modulo) */ 109 | if (len) { /* avoid modulos if none remaining */ 110 | while (len >= 16) { 111 | len -= 16; 112 | DO16(buf); 113 | buf += 16; 114 | } 115 | while (len--) { 116 | adler += *buf++; 117 | sum2 += adler; 118 | } 119 | MOD(adler); 120 | MOD(sum2); 121 | } 122 | 123 | /* return recombined sums */ 124 | return adler | (sum2 << 16); 125 | } 126 | 127 | /* ========================================================================= */ 128 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 129 | uLong adler1; 130 | uLong adler2; 131 | z_off_t len2; 132 | { 133 | unsigned long sum1; 134 | unsigned long sum2; 135 | unsigned rem; 136 | 137 | /* the derivation of this formula is left as an exercise for the reader */ 138 | rem = (unsigned)(len2 % BASE); 139 | sum1 = adler1 & 0xffff; 140 | sum2 = rem * sum1; 141 | MOD(sum2); 142 | sum1 += (adler2 & 0xffff) + BASE - 1; 143 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 144 | if (sum1 > BASE) sum1 -= BASE; 145 | if (sum1 > BASE) sum1 -= BASE; 146 | if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); 147 | if (sum2 > BASE) sum2 -= BASE; 148 | return sum1 | (sum2 << 16); 149 | } 150 | -------------------------------------------------------------------------------- /extern/zlib/src/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; 79 | } 80 | -------------------------------------------------------------------------------- /extern/zlib/src/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /extern/zlib/src/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. It 6 | is part of the implementation of the compression library and 7 | is subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /extern/zlib/src/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY, /* i/o: waiting for input or output to copy stored block */ 36 | TABLE, /* i: waiting for dynamic block table lengths */ 37 | LENLENS, /* i: waiting for code length code lengths */ 38 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 39 | LEN, /* i: waiting for length/lit code */ 40 | LENEXT, /* i: waiting for length extra bits */ 41 | DIST, /* i: waiting for distance code */ 42 | DISTEXT, /* i: waiting for distance extra bits */ 43 | MATCH, /* o: waiting for output space to copy string */ 44 | LIT, /* o: waiting for output space to write literal */ 45 | CHECK, /* i: waiting for 32-bit check value */ 46 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 47 | DONE, /* finished check, done -- remain here until reset */ 48 | BAD, /* got a data error -- remain here until reset */ 49 | MEM, /* got an inflate() memory error -- remain here until reset */ 50 | SYNC /* looking for synchronization bytes to restart inflate() */ 51 | } inflate_mode; 52 | 53 | /* 54 | State transitions between above modes - 55 | 56 | (most modes can go to the BAD or MEM mode -- not shown for clarity) 57 | 58 | Process header: 59 | HEAD -> (gzip) or (zlib) 60 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 61 | NAME -> COMMENT -> HCRC -> TYPE 62 | (zlib) -> DICTID or TYPE 63 | DICTID -> DICT -> TYPE 64 | Read deflate blocks: 65 | TYPE -> STORED or TABLE or LEN or CHECK 66 | STORED -> COPY -> TYPE 67 | TABLE -> LENLENS -> CODELENS -> LEN 68 | Read deflate codes: 69 | LEN -> LENEXT or LIT or TYPE 70 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 71 | LIT -> LEN 72 | Process trailer: 73 | CHECK -> LENGTH -> DONE 74 | */ 75 | 76 | /* state maintained between inflate() calls. Approximately 7K bytes. */ 77 | struct inflate_state { 78 | inflate_mode mode; /* current inflate mode */ 79 | int last; /* true if processing last block */ 80 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 81 | int havedict; /* true if dictionary provided */ 82 | int flags; /* gzip header method and flags (0 if zlib) */ 83 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 84 | unsigned long check; /* protected copy of check value */ 85 | unsigned long total; /* protected copy of output count */ 86 | gz_headerp head; /* where to save gzip header information */ 87 | /* sliding window */ 88 | unsigned wbits; /* log base 2 of requested window size */ 89 | unsigned wsize; /* window size or zero if not using window */ 90 | unsigned whave; /* valid bytes in the window */ 91 | unsigned write; /* window write index */ 92 | unsigned char FAR *window; /* allocated sliding window, if needed */ 93 | /* bit accumulator */ 94 | unsigned long hold; /* input bit accumulator */ 95 | unsigned bits; /* number of bits in "in" */ 96 | /* for string and stored block copying */ 97 | unsigned length; /* literal or length of data to copy */ 98 | unsigned offset; /* distance back to copy string from */ 99 | /* for table and code decoding */ 100 | unsigned extra; /* extra bits needed */ 101 | /* fixed and dynamic code tables */ 102 | code const FAR *lencode; /* starting table for length/literal codes */ 103 | code const FAR *distcode; /* starting table for distance codes */ 104 | unsigned lenbits; /* index bits for lencode */ 105 | unsigned distbits; /* index bits for distcode */ 106 | /* dynamic table building */ 107 | unsigned ncode; /* number of code length code lengths */ 108 | unsigned nlen; /* number of length code lengths */ 109 | unsigned ndist; /* number of distance code lengths */ 110 | unsigned have; /* number of code lengths in lens[] */ 111 | code FAR *next; /* next available space in codes[] */ 112 | unsigned short lens[320]; /* temporary storage for code lengths */ 113 | unsigned short work[288]; /* work area for code table building */ 114 | code codes[ENOUGH]; /* space for code tables */ 115 | }; 116 | -------------------------------------------------------------------------------- /extern/zlib/src/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- 39 | exhaustive search was 1444 code structures (852 for length/literals 40 | and 592 for distances, the latter actually the result of an 41 | exhaustive search). The true maximum is not known, but the value 42 | below is more than safe. */ 43 | #define ENOUGH 2048 44 | #define MAXD 592 45 | 46 | /* Type of code to build for inftable() */ 47 | typedef enum { 48 | CODES, 49 | LENS, 50 | DISTS 51 | } codetype; 52 | 53 | extern int inflate_table OF((codetype type, unsigned short FAR *lens, 54 | unsigned codes, code FAR * FAR *table, 55 | unsigned FAR *bits, unsigned short FAR *work)); 56 | -------------------------------------------------------------------------------- /extern/zlib/src/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /extern/zlib/src/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | This function can be used to decompress a whole file at once if the 20 | input file is mmap'ed. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 23 | enough memory, Z_BUF_ERROR if there was not enough room in the output 24 | buffer, or Z_DATA_ERROR if the input data was corrupted. 25 | */ 26 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 27 | Bytef *dest; 28 | uLongf *destLen; 29 | const Bytef *source; 30 | uLong sourceLen; 31 | { 32 | z_stream stream; 33 | int err; 34 | 35 | stream.next_in = (Bytef*)source; 36 | stream.avail_in = (uInt)sourceLen; 37 | /* Check for source > 64K on 16-bit machine: */ 38 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 39 | 40 | stream.next_out = dest; 41 | stream.avail_out = (uInt)*destLen; 42 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 43 | 44 | stream.zalloc = (alloc_func)0; 45 | stream.zfree = (free_func)0; 46 | 47 | err = inflateInit(&stream); 48 | if (err != Z_OK) return err; 49 | 50 | err = inflate(&stream, Z_FINISH); 51 | if (err != Z_STREAM_END) { 52 | inflateEnd(&stream); 53 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 54 | return Z_DATA_ERROR; 55 | return err; 56 | } 57 | *destLen = stream.total_out; 58 | 59 | err = inflateEnd(&stream); 60 | return err; 61 | } 62 | -------------------------------------------------------------------------------- /extern/zlib/src/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* 12 | * If you *really* need a unique prefix for all types and library functions, 13 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 14 | */ 15 | #ifdef Z_PREFIX 16 | # define deflateInit_ z_deflateInit_ 17 | # define deflate z_deflate 18 | # define deflateEnd z_deflateEnd 19 | # define inflateInit_ z_inflateInit_ 20 | # define inflate z_inflate 21 | # define inflateEnd z_inflateEnd 22 | # define deflateInit2_ z_deflateInit2_ 23 | # define deflateSetDictionary z_deflateSetDictionary 24 | # define deflateCopy z_deflateCopy 25 | # define deflateReset z_deflateReset 26 | # define deflateParams z_deflateParams 27 | # define deflateBound z_deflateBound 28 | # define deflatePrime z_deflatePrime 29 | # define inflateInit2_ z_inflateInit2_ 30 | # define inflateSetDictionary z_inflateSetDictionary 31 | # define inflateSync z_inflateSync 32 | # define inflateSyncPoint z_inflateSyncPoint 33 | # define inflateCopy z_inflateCopy 34 | # define inflateReset z_inflateReset 35 | # define inflateBack z_inflateBack 36 | # define inflateBackEnd z_inflateBackEnd 37 | # define compress z_compress 38 | # define compress2 z_compress2 39 | # define compressBound z_compressBound 40 | # define uncompress z_uncompress 41 | # define adler32 z_adler32 42 | # define crc32 z_crc32 43 | # define get_crc_table z_get_crc_table 44 | # define zError z_zError 45 | 46 | # define alloc_func z_alloc_func 47 | # define free_func z_free_func 48 | # define in_func z_in_func 49 | # define out_func z_out_func 50 | # define Byte z_Byte 51 | # define uInt z_uInt 52 | # define uLong z_uLong 53 | # define Bytef z_Bytef 54 | # define charf z_charf 55 | # define intf z_intf 56 | # define uIntf z_uIntf 57 | # define uLongf z_uLongf 58 | # define voidpf z_voidpf 59 | # define voidp z_voidp 60 | #endif 61 | 62 | #if defined(__MSDOS__) && !defined(MSDOS) 63 | # define MSDOS 64 | #endif 65 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 66 | # define OS2 67 | #endif 68 | #if defined(_WINDOWS) && !defined(WINDOWS) 69 | # define WINDOWS 70 | #endif 71 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 72 | # ifndef WIN32 73 | # define WIN32 74 | # endif 75 | #endif 76 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 77 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 78 | # ifndef SYS16BIT 79 | # define SYS16BIT 80 | # endif 81 | # endif 82 | #endif 83 | 84 | /* 85 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 86 | * than 64k bytes at a time (needed on systems with 16-bit int). 87 | */ 88 | #ifdef SYS16BIT 89 | # define MAXSEG_64K 90 | #endif 91 | #ifdef MSDOS 92 | # define UNALIGNED_OK 93 | #endif 94 | 95 | #ifdef __STDC_VERSION__ 96 | # ifndef STDC 97 | # define STDC 98 | # endif 99 | # if __STDC_VERSION__ >= 199901L 100 | # ifndef STDC99 101 | # define STDC99 102 | # endif 103 | # endif 104 | #endif 105 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 106 | # define STDC 107 | #endif 108 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 109 | # define STDC 110 | #endif 111 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 112 | # define STDC 113 | #endif 114 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 115 | # define STDC 116 | #endif 117 | 118 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 119 | # define STDC 120 | #endif 121 | 122 | #ifndef STDC 123 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 124 | # define const /* note: need a more gentle solution here */ 125 | # endif 126 | #endif 127 | 128 | /* Some Mac compilers merge all .h files incorrectly: */ 129 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 130 | # define NO_DUMMY_DECL 131 | #endif 132 | 133 | /* Maximum value for memLevel in deflateInit2 */ 134 | #ifndef MAX_MEM_LEVEL 135 | # ifdef MAXSEG_64K 136 | # define MAX_MEM_LEVEL 8 137 | # else 138 | # define MAX_MEM_LEVEL 9 139 | # endif 140 | #endif 141 | 142 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 143 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 144 | * created by gzip. (Files created by minigzip can still be extracted by 145 | * gzip.) 146 | */ 147 | #ifndef MAX_WBITS 148 | # define MAX_WBITS 15 /* 32K LZ77 window */ 149 | #endif 150 | 151 | /* The memory requirements for deflate are (in bytes): 152 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 153 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 154 | plus a few kilobytes for small objects. For example, if you want to reduce 155 | the default memory requirements from 256K to 128K, compile with 156 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 157 | Of course this will generally degrade compression (there's no free lunch). 158 | 159 | The memory requirements for inflate are (in bytes) 1 << windowBits 160 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 161 | for small objects. 162 | */ 163 | 164 | /* Type declarations */ 165 | 166 | #ifndef OF /* function prototypes */ 167 | # ifdef STDC 168 | # define OF(args) args 169 | # else 170 | # define OF(args) () 171 | # endif 172 | #endif 173 | 174 | /* The following definitions for FAR are needed only for MSDOS mixed 175 | * model programming (small or medium model with some far allocations). 176 | * This was tested only with MSC; for other MSDOS compilers you may have 177 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 178 | * just define FAR to be empty. 179 | */ 180 | #ifdef SYS16BIT 181 | # if defined(M_I86SM) || defined(M_I86MM) 182 | /* MSC small or medium model */ 183 | # define SMALL_MEDIUM 184 | # ifdef _MSC_VER 185 | # define FAR _far 186 | # else 187 | # define FAR far 188 | # endif 189 | # endif 190 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 191 | /* Turbo C small or medium model */ 192 | # define SMALL_MEDIUM 193 | # ifdef __BORLANDC__ 194 | # define FAR _far 195 | # else 196 | # define FAR far 197 | # endif 198 | # endif 199 | #endif 200 | 201 | #if defined(WINDOWS) || defined(WIN32) 202 | /* If building or using zlib as a DLL, define ZLIB_DLL. 203 | * This is not mandatory, but it offers a little performance increase. 204 | */ 205 | # ifdef ZLIB_DLL 206 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 207 | # ifdef ZLIB_INTERNAL 208 | # define ZEXTERN extern __declspec(dllexport) 209 | # else 210 | # define ZEXTERN extern __declspec(dllimport) 211 | # endif 212 | # endif 213 | # endif /* ZLIB_DLL */ 214 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 215 | * define ZLIB_WINAPI. 216 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 217 | */ 218 | # ifdef ZLIB_WINAPI 219 | # ifdef FAR 220 | # undef FAR 221 | # endif 222 | # include 223 | /* No need for _export, use ZLIB.DEF instead. */ 224 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 225 | # define ZEXPORT WINAPI 226 | # ifdef WIN32 227 | # define ZEXPORTVA WINAPIV 228 | # else 229 | # define ZEXPORTVA FAR CDECL 230 | # endif 231 | # endif 232 | #endif 233 | 234 | #if defined (__BEOS__) 235 | # ifdef ZLIB_DLL 236 | # ifdef ZLIB_INTERNAL 237 | # define ZEXPORT __declspec(dllexport) 238 | # define ZEXPORTVA __declspec(dllexport) 239 | # else 240 | # define ZEXPORT __declspec(dllimport) 241 | # define ZEXPORTVA __declspec(dllimport) 242 | # endif 243 | # endif 244 | #endif 245 | 246 | #ifndef ZEXTERN 247 | # define ZEXTERN extern 248 | #endif 249 | #ifndef ZEXPORT 250 | # define ZEXPORT 251 | #endif 252 | #ifndef ZEXPORTVA 253 | # define ZEXPORTVA 254 | #endif 255 | 256 | #ifndef FAR 257 | # define FAR 258 | #endif 259 | 260 | #if !defined(__MACTYPES__) 261 | typedef unsigned char Byte; /* 8 bits */ 262 | #endif 263 | typedef unsigned int uInt; /* 16 bits or more */ 264 | typedef unsigned long uLong; /* 32 bits or more */ 265 | 266 | #ifdef SMALL_MEDIUM 267 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 268 | # define Bytef Byte FAR 269 | #else 270 | typedef Byte FAR Bytef; 271 | #endif 272 | typedef char FAR charf; 273 | typedef int FAR intf; 274 | typedef uInt FAR uIntf; 275 | typedef uLong FAR uLongf; 276 | 277 | #ifdef STDC 278 | typedef void const *voidpc; 279 | typedef void FAR *voidpf; 280 | typedef void *voidp; 281 | #else 282 | typedef Byte const *voidpc; 283 | typedef Byte FAR *voidpf; 284 | typedef Byte *voidp; 285 | #endif 286 | 287 | #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ 288 | # include /* for off_t */ 289 | # include /* for SEEK_* and off_t */ 290 | # ifdef VMS 291 | # include /* for off_t */ 292 | # endif 293 | # define z_off_t off_t 294 | #endif 295 | #ifndef SEEK_SET 296 | # define SEEK_SET 0 /* Seek from beginning of file. */ 297 | # define SEEK_CUR 1 /* Seek from current position. */ 298 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 299 | #endif 300 | #ifndef z_off_t 301 | # define z_off_t long 302 | #endif 303 | 304 | #if defined(__OS400__) 305 | # define NO_vsnprintf 306 | #endif 307 | 308 | #if defined(__MVS__) 309 | # define NO_vsnprintf 310 | # ifdef FAR 311 | # undef FAR 312 | # endif 313 | #endif 314 | 315 | /* MVS linker does not support external names larger than 8 bytes */ 316 | #if defined(__MVS__) 317 | # pragma map(deflateInit_,"DEIN") 318 | # pragma map(deflateInit2_,"DEIN2") 319 | # pragma map(deflateEnd,"DEEND") 320 | # pragma map(deflateBound,"DEBND") 321 | # pragma map(inflateInit_,"ININ") 322 | # pragma map(inflateInit2_,"ININ2") 323 | # pragma map(inflateEnd,"INEND") 324 | # pragma map(inflateSync,"INSY") 325 | # pragma map(inflateSetDictionary,"INSEDI") 326 | # pragma map(compressBound,"CMBND") 327 | # pragma map(inflate_table,"INTABL") 328 | # pragma map(inflate_fast,"INFA") 329 | # pragma map(inflate_copyright,"INCOPY") 330 | #endif 331 | 332 | #endif /* ZCONF_H */ 333 | -------------------------------------------------------------------------------- /extern/zlib/src/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #ifndef NO_DUMMY_DECL 11 | struct internal_state {int dummy;}; /* for buggy compilers */ 12 | #endif 13 | 14 | const char * const z_errmsg[10] = { 15 | "need dictionary", /* Z_NEED_DICT 2 */ 16 | "stream end", /* Z_STREAM_END 1 */ 17 | "", /* Z_OK 0 */ 18 | "file error", /* Z_ERRNO (-1) */ 19 | "stream error", /* Z_STREAM_ERROR (-2) */ 20 | "data error", /* Z_DATA_ERROR (-3) */ 21 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 22 | "buffer error", /* Z_BUF_ERROR (-5) */ 23 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 24 | ""}; 25 | 26 | 27 | const char * ZEXPORT zlibVersion() 28 | { 29 | return ZLIB_VERSION; 30 | } 31 | 32 | uLong ZEXPORT zlibCompileFlags() 33 | { 34 | uLong flags; 35 | 36 | flags = 0; 37 | switch (sizeof(uInt)) { 38 | case 2: break; 39 | case 4: flags += 1; break; 40 | case 8: flags += 2; break; 41 | default: flags += 3; 42 | } 43 | switch (sizeof(uLong)) { 44 | case 2: break; 45 | case 4: flags += 1 << 2; break; 46 | case 8: flags += 2 << 2; break; 47 | default: flags += 3 << 2; 48 | } 49 | switch (sizeof(voidpf)) { 50 | case 2: break; 51 | case 4: flags += 1 << 4; break; 52 | case 8: flags += 2 << 4; break; 53 | default: flags += 3 << 4; 54 | } 55 | switch (sizeof(z_off_t)) { 56 | case 2: break; 57 | case 4: flags += 1 << 6; break; 58 | case 8: flags += 2 << 6; break; 59 | default: flags += 3 << 6; 60 | } 61 | #ifdef DEBUG 62 | flags += 1 << 8; 63 | #endif 64 | #if defined(ASMV) || defined(ASMINF) 65 | flags += 1 << 9; 66 | #endif 67 | #ifdef ZLIB_WINAPI 68 | flags += 1 << 10; 69 | #endif 70 | #ifdef BUILDFIXED 71 | flags += 1 << 12; 72 | #endif 73 | #ifdef DYNAMIC_CRC_TABLE 74 | flags += 1 << 13; 75 | #endif 76 | #ifdef NO_GZCOMPRESS 77 | flags += 1L << 16; 78 | #endif 79 | #ifdef NO_GZIP 80 | flags += 1L << 17; 81 | #endif 82 | #ifdef PKZIP_BUG_WORKAROUND 83 | flags += 1L << 20; 84 | #endif 85 | #ifdef FASTEST 86 | flags += 1L << 21; 87 | #endif 88 | #ifdef STDC 89 | # ifdef NO_vsnprintf 90 | flags += 1L << 25; 91 | # ifdef HAS_vsprintf_void 92 | flags += 1L << 26; 93 | # endif 94 | # else 95 | # ifdef HAS_vsnprintf_void 96 | flags += 1L << 26; 97 | # endif 98 | # endif 99 | #else 100 | flags += 1L << 24; 101 | # ifdef NO_snprintf 102 | flags += 1L << 25; 103 | # ifdef HAS_sprintf_void 104 | flags += 1L << 26; 105 | # endif 106 | # else 107 | # ifdef HAS_snprintf_void 108 | flags += 1L << 26; 109 | # endif 110 | # endif 111 | #endif 112 | return flags; 113 | } 114 | 115 | #ifdef DEBUG 116 | 117 | # ifndef verbose 118 | # define verbose 0 119 | # endif 120 | int z_verbose = verbose; 121 | 122 | void z_error (m) 123 | char *m; 124 | { 125 | fprintf(stderr, "%s\n", m); 126 | exit(1); 127 | } 128 | #endif 129 | 130 | /* exported to allow conversion of error code to string for compress() and 131 | * uncompress() 132 | */ 133 | const char * ZEXPORT zError(err) 134 | int err; 135 | { 136 | return ERR_MSG(err); 137 | } 138 | 139 | #if defined(_WIN32_WCE) 140 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 141 | * errno. We define it as a global variable to simplify porting. 142 | * Its value is always 0 and should not be used. 143 | */ 144 | int errno = 0; 145 | #endif 146 | 147 | #ifndef HAVE_MEMCPY 148 | 149 | void zmemcpy(dest, source, len) 150 | Bytef* dest; 151 | const Bytef* source; 152 | uInt len; 153 | { 154 | if (len == 0) return; 155 | do { 156 | *dest++ = *source++; /* ??? to be unrolled */ 157 | } while (--len != 0); 158 | } 159 | 160 | int zmemcmp(s1, s2, len) 161 | const Bytef* s1; 162 | const Bytef* s2; 163 | uInt len; 164 | { 165 | uInt j; 166 | 167 | for (j = 0; j < len; j++) { 168 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 169 | } 170 | return 0; 171 | } 172 | 173 | void zmemzero(dest, len) 174 | Bytef* dest; 175 | uInt len; 176 | { 177 | if (len == 0) return; 178 | do { 179 | *dest++ = 0; /* ??? to be unrolled */ 180 | } while (--len != 0); 181 | } 182 | #endif 183 | 184 | 185 | #ifdef SYS16BIT 186 | 187 | #ifdef __TURBOC__ 188 | /* Turbo C in 16-bit mode */ 189 | 190 | # define MY_ZCALLOC 191 | 192 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 193 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 194 | * must fix the pointer. Warning: the pointer must be put back to its 195 | * original form in order to free it, use zcfree(). 196 | */ 197 | 198 | #define MAX_PTR 10 199 | /* 10*64K = 640K */ 200 | 201 | local int next_ptr = 0; 202 | 203 | typedef struct ptr_table_s { 204 | voidpf org_ptr; 205 | voidpf new_ptr; 206 | } ptr_table; 207 | 208 | local ptr_table table[MAX_PTR]; 209 | /* This table is used to remember the original form of pointers 210 | * to large buffers (64K). Such pointers are normalized with a zero offset. 211 | * Since MSDOS is not a preemptive multitasking OS, this table is not 212 | * protected from concurrent access. This hack doesn't work anyway on 213 | * a protected system like OS/2. Use Microsoft C instead. 214 | */ 215 | 216 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 217 | { 218 | voidpf buf = opaque; /* just to make some compilers happy */ 219 | ulg bsize = (ulg)items*size; 220 | 221 | /* If we allocate less than 65520 bytes, we assume that farmalloc 222 | * will return a usable pointer which doesn't have to be normalized. 223 | */ 224 | if (bsize < 65520L) { 225 | buf = farmalloc(bsize); 226 | if (*(ush*)&buf != 0) return buf; 227 | } else { 228 | buf = farmalloc(bsize + 16L); 229 | } 230 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 231 | table[next_ptr].org_ptr = buf; 232 | 233 | /* Normalize the pointer to seg:0 */ 234 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 235 | *(ush*)&buf = 0; 236 | table[next_ptr++].new_ptr = buf; 237 | return buf; 238 | } 239 | 240 | void zcfree (voidpf opaque, voidpf ptr) 241 | { 242 | int n; 243 | if (*(ush*)&ptr != 0) { /* object < 64K */ 244 | farfree(ptr); 245 | return; 246 | } 247 | /* Find the original pointer */ 248 | for (n = 0; n < next_ptr; n++) { 249 | if (ptr != table[n].new_ptr) continue; 250 | 251 | farfree(table[n].org_ptr); 252 | while (++n < next_ptr) { 253 | table[n-1] = table[n]; 254 | } 255 | next_ptr--; 256 | return; 257 | } 258 | ptr = opaque; /* just to make some compilers happy */ 259 | Assert(0, "zcfree: ptr not found"); 260 | } 261 | 262 | #endif /* __TURBOC__ */ 263 | 264 | 265 | #ifdef M_I86 266 | /* Microsoft C in 16-bit mode */ 267 | 268 | # define MY_ZCALLOC 269 | 270 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 271 | # define _halloc halloc 272 | # define _hfree hfree 273 | #endif 274 | 275 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 276 | { 277 | if (opaque) opaque = 0; /* to make compiler happy */ 278 | return _halloc((long)items, size); 279 | } 280 | 281 | void zcfree (voidpf opaque, voidpf ptr) 282 | { 283 | if (opaque) opaque = 0; /* to make compiler happy */ 284 | _hfree(ptr); 285 | } 286 | 287 | #endif /* M_I86 */ 288 | 289 | #endif /* SYS16BIT */ 290 | 291 | 292 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 293 | 294 | #ifndef STDC 295 | extern voidp malloc OF((uInt size)); 296 | extern voidp calloc OF((uInt items, uInt size)); 297 | extern void free OF((voidpf ptr)); 298 | #endif 299 | 300 | voidpf zcalloc (opaque, items, size) 301 | voidpf opaque; 302 | unsigned items; 303 | unsigned size; 304 | { 305 | if (opaque) items += size - size; /* make compiler happy */ 306 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 307 | (voidpf)calloc(items, size); 308 | } 309 | 310 | void zcfree (opaque, ptr) 311 | voidpf opaque; 312 | voidpf ptr; 313 | { 314 | free(ptr); 315 | if (opaque) return; /* make compiler happy */ 316 | } 317 | 318 | #endif /* MY_ZCALLOC */ 319 | -------------------------------------------------------------------------------- /extern/zlib/src/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #define ZLIB_INTERNAL 17 | #include "zlib.h" 18 | 19 | #ifdef STDC 20 | # ifndef _WIN32_WCE 21 | # include 22 | # endif 23 | # include 24 | # include 25 | #endif 26 | #ifdef NO_ERRNO_H 27 | # ifdef _WIN32_WCE 28 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 29 | * errno. We define it as a global variable to simplify porting. 30 | * Its value is always 0 and should not be used. We rename it to 31 | * avoid conflict with other libraries that use the same workaround. 32 | */ 33 | # define errno z_errno 34 | # endif 35 | extern int errno; 36 | #else 37 | # ifndef _WIN32_WCE 38 | # include 39 | # endif 40 | #endif 41 | 42 | #ifndef local 43 | # define local static 44 | #endif 45 | /* compile with -Dlocal if your debugger can't find static symbols */ 46 | 47 | typedef unsigned char uch; 48 | typedef uch FAR uchf; 49 | typedef unsigned short ush; 50 | typedef ush FAR ushf; 51 | typedef unsigned long ulg; 52 | 53 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 54 | /* (size given to avoid silly warnings with Visual C++) */ 55 | 56 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 57 | 58 | #define ERR_RETURN(strm,err) \ 59 | return (strm->msg = (char*)ERR_MSG(err), (err)) 60 | /* To be used only when the state is known to be valid */ 61 | 62 | /* common constants */ 63 | 64 | #ifndef DEF_WBITS 65 | # define DEF_WBITS MAX_WBITS 66 | #endif 67 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 68 | 69 | #if MAX_MEM_LEVEL >= 8 70 | # define DEF_MEM_LEVEL 8 71 | #else 72 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 73 | #endif 74 | /* default memLevel */ 75 | 76 | #define STORED_BLOCK 0 77 | #define STATIC_TREES 1 78 | #define DYN_TREES 2 79 | /* The three kinds of block type */ 80 | 81 | #define MIN_MATCH 3 82 | #define MAX_MATCH 258 83 | /* The minimum and maximum match lengths */ 84 | 85 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 86 | 87 | /* target dependencies */ 88 | 89 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 90 | # define OS_CODE 0x00 91 | # if defined(__TURBOC__) || defined(__BORLANDC__) 92 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 93 | /* Allow compilation with ANSI keywords only enabled */ 94 | void _Cdecl farfree( void *block ); 95 | void *_Cdecl farmalloc( unsigned long nbytes ); 96 | # else 97 | # include 98 | # endif 99 | # else /* MSC or DJGPP */ 100 | # include 101 | # endif 102 | #endif 103 | 104 | #ifdef AMIGA 105 | # define OS_CODE 0x01 106 | #endif 107 | 108 | #if defined(VAXC) || defined(VMS) 109 | # define OS_CODE 0x02 110 | # define F_OPEN(name, mode) \ 111 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 112 | #endif 113 | 114 | #if defined(ATARI) || defined(atarist) 115 | # define OS_CODE 0x05 116 | #endif 117 | 118 | #ifdef OS2 119 | # define OS_CODE 0x06 120 | # ifdef M_I86 121 | #include 122 | # endif 123 | #endif 124 | 125 | #if defined(MACOS) || defined(TARGET_OS_MAC) 126 | # define OS_CODE 0x07 127 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 128 | # include /* for fdopen */ 129 | # else 130 | # ifndef fdopen 131 | # define fdopen(fd,mode) NULL /* No fdopen() */ 132 | # endif 133 | # endif 134 | #endif 135 | 136 | #ifdef TOPS20 137 | # define OS_CODE 0x0a 138 | #endif 139 | 140 | #ifdef WIN32 141 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 142 | # define OS_CODE 0x0b 143 | # endif 144 | #endif 145 | 146 | #ifdef __50SERIES /* Prime/PRIMOS */ 147 | # define OS_CODE 0x0f 148 | #endif 149 | 150 | #if defined(_BEOS_) || defined(RISCOS) 151 | # define fdopen(fd,mode) NULL /* No fdopen() */ 152 | #endif 153 | 154 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 155 | # if defined(_WIN32_WCE) 156 | # define fdopen(fd,mode) NULL /* No fdopen() */ 157 | # ifndef _PTRDIFF_T_DEFINED 158 | typedef int ptrdiff_t; 159 | # define _PTRDIFF_T_DEFINED 160 | # endif 161 | # else 162 | # define fdopen(fd,type) _fdopen(fd,type) 163 | # endif 164 | #endif 165 | 166 | /* common defaults */ 167 | 168 | #ifndef OS_CODE 169 | # define OS_CODE 0x03 /* assume Unix */ 170 | #endif 171 | 172 | #ifndef F_OPEN 173 | # define F_OPEN(name, mode) fopen((name), (mode)) 174 | #endif 175 | 176 | /* functions */ 177 | 178 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 179 | # ifndef HAVE_VSNPRINTF 180 | # define HAVE_VSNPRINTF 181 | # endif 182 | #endif 183 | #if defined(__CYGWIN__) 184 | # ifndef HAVE_VSNPRINTF 185 | # define HAVE_VSNPRINTF 186 | # endif 187 | #endif 188 | #ifndef HAVE_VSNPRINTF 189 | # ifdef MSDOS 190 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 191 | but for now we just assume it doesn't. */ 192 | # define NO_vsnprintf 193 | # endif 194 | # ifdef __TURBOC__ 195 | # define NO_vsnprintf 196 | # endif 197 | # ifdef WIN32 198 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 199 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 200 | # define vsnprintf _vsnprintf 201 | # endif 202 | # endif 203 | # ifdef __SASC 204 | # define NO_vsnprintf 205 | # endif 206 | #endif 207 | #ifdef VMS 208 | # define NO_vsnprintf 209 | #endif 210 | 211 | #if defined(pyr) 212 | # define NO_MEMCPY 213 | #endif 214 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 215 | /* Use our own functions for small and medium model with MSC <= 5.0. 216 | * You may have to use the same strategy for Borland C (untested). 217 | * The __SC__ check is for Symantec. 218 | */ 219 | # define NO_MEMCPY 220 | #endif 221 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 222 | # define HAVE_MEMCPY 223 | #endif 224 | #ifdef HAVE_MEMCPY 225 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 226 | # define zmemcpy _fmemcpy 227 | # define zmemcmp _fmemcmp 228 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 229 | # else 230 | # define zmemcpy memcpy 231 | # define zmemcmp memcmp 232 | # define zmemzero(dest, len) memset(dest, 0, len) 233 | # endif 234 | #else 235 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 236 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 237 | extern void zmemzero OF((Bytef* dest, uInt len)); 238 | #endif 239 | 240 | /* Diagnostic functions */ 241 | #ifdef DEBUG 242 | # include 243 | extern int z_verbose; 244 | extern void z_error OF((char *m)); 245 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 246 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 247 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 248 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 249 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 250 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 251 | #else 252 | # define Assert(cond,msg) 253 | # define Trace(x) 254 | # define Tracev(x) 255 | # define Tracevv(x) 256 | # define Tracec(c,x) 257 | # define Tracecv(c,x) 258 | #endif 259 | 260 | 261 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 262 | void zcfree OF((voidpf opaque, voidpf ptr)); 263 | 264 | #define ZALLOC(strm, items, size) \ 265 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 266 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 267 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 268 | 269 | #endif /* ZUTIL_H */ 270 | -------------------------------------------------------------------------------- /partio_extension/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | inplace=1 -------------------------------------------------------------------------------- /partio_extension/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup, Extension 2 | import platform 3 | 4 | defs = [] 5 | cxx_args = [] 6 | 7 | defs.append(('PARTIO_USE_ZLIB', None)) 8 | 9 | if platform.system() == 'Windows': 10 | defs.append(('PARTIO_WIN32', None)) 11 | defs.append(('_USE_MATH_DEFINES', None)) 12 | elif platform.system() == 'Linux': 13 | cxx_args = ["-fPIC", "-w"] 14 | 15 | module1 = Extension('_partio', 16 | include_dirs = ['../extern/partio/src/lib', '../extern/zlib/src'], 17 | define_macros = defs, 18 | extra_compile_args = cxx_args, 19 | sources = [ 20 | '../extern/partio/src/lib/core/Particle.cpp', 21 | '../extern/partio/src/lib/core/ParticleCaching.cpp', 22 | '../extern/partio/src/lib/core/ParticleHeaders.cpp', 23 | '../extern/partio/src/lib/core/ParticleSimple.cpp', 24 | '../extern/partio/src/lib/core/ParticleSimpleInterleave.cpp', 25 | '../extern/partio/src/lib/io/BGEO.cpp', 26 | '../extern/partio/src/lib/io/BIN.cpp', 27 | '../extern/partio/src/lib/io/GEO.cpp', 28 | '../extern/partio/src/lib/io/MC.cpp', 29 | '../extern/partio/src/lib/io/ParticleIO.cpp', 30 | '../extern/partio/src/lib/io/PDA.cpp', 31 | '../extern/partio/src/lib/io/PDB.cpp', 32 | '../extern/partio/src/lib/io/PDC.cpp', 33 | '../extern/partio/src/lib/io/PRT.cpp', 34 | '../extern/partio/src/lib/io/PTC.cpp', 35 | '../extern/partio/src/lib/io/PTS.cpp', 36 | '../extern/partio/src/lib/io/RIB.cpp', 37 | '../extern/partio/src/lib/io/ZIP.cpp', 38 | '../extern/zlib/src/adler32.c', 39 | '../extern/zlib/src/compress.c', 40 | '../extern/zlib/src/crc32.c', 41 | '../extern/zlib/src/deflate.c', 42 | '../extern/zlib/src/gzio.c', 43 | '../extern/zlib/src/infback.c', 44 | '../extern/zlib/src/inffast.c', 45 | '../extern/zlib/src/inflate.c', 46 | '../extern/zlib/src/inftrees.c', 47 | '../extern/zlib/src/trees.c', 48 | '../extern/zlib/src/uncompr.c', 49 | '../extern/zlib/src/zutil.c', 50 | 'partio_wrap.cxx']) 51 | 52 | tst = setup (name = '_partio', 53 | version = '1.0', 54 | description = 'partio package', 55 | ext_modules = [module1]) 56 | -------------------------------------------------------------------------------- /screenshots/BlenderPartioTools.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/InteractiveComputerGraphics/BlenderPartioTools/bdc3b993b4fb1306f32636be08771cbd7189967a/screenshots/BlenderPartioTools.jpg --------------------------------------------------------------------------------