├── LICENSE ├── README.md ├── docs └── images │ └── result-eps-converted-to.jpg ├── install.sh ├── machinability.cpp ├── src ├── a.out ├── contour_tracing.h ├── heightmapGenerator ├── heightmapGenerator.cpp ├── install.sh ├── koko │ ├── __init__.pyc │ ├── c │ │ ├── __init__.py │ │ ├── __init__.pyc │ │ ├── asdf.py │ │ ├── asdf.pyc │ │ ├── interval.py │ │ ├── interval.pyc │ │ ├── libfab.py │ │ ├── libfab.pyc │ │ ├── mesh.py │ │ ├── mesh.pyc │ │ ├── multithread.py │ │ ├── multithread.pyc │ │ ├── path.py │ │ ├── path.pyc │ │ ├── region.py │ │ ├── region.pyc │ │ ├── vec3f.py │ │ └── vec3f.pyc │ └── fab │ │ ├── __init__.py │ │ ├── __init__.pyc │ │ ├── asdf.py │ │ ├── asdf.pyc │ │ ├── fabvars.py │ │ ├── fabvars.pyc │ │ ├── image (Tanay Gahlot's conflicted copy 2016-03-05).pyc │ │ ├── image.py │ │ ├── image.pyc │ │ ├── mesh.py │ │ ├── mesh.pyc │ │ ├── path.py │ │ ├── path.pyc │ │ ├── tree.py │ │ └── tree.pyc ├── lib │ ├── cvmlcpp │ │ ├── array │ │ │ └── ArrayIO │ │ ├── base │ │ │ ├── Allocators │ │ │ ├── CyclicBuffer │ │ │ ├── Enums │ │ │ ├── Functors │ │ │ ├── Functors.hpp │ │ │ ├── IDGenerators │ │ │ ├── Matrix │ │ │ ├── Matrix.hpp │ │ │ ├── Meta │ │ │ ├── StringTools │ │ │ ├── stl_cmath.h │ │ │ ├── stl_compat.h │ │ │ ├── stl_cstdint.h │ │ │ └── use_omp.h │ │ ├── math │ │ │ ├── ContainerOps.h │ │ │ ├── Euclid │ │ │ ├── Math │ │ │ ├── Math.hpp │ │ │ ├── Vectors │ │ │ └── Vectors.hpp │ │ └── volume │ │ │ ├── DTree │ │ │ ├── Facet │ │ │ ├── Geometry │ │ │ ├── Geometry.hpp │ │ │ ├── VolumeIO │ │ │ ├── VolumeIO.hpp │ │ │ └── Voxelizer │ └── omptl │ │ ├── License.txt │ │ ├── omptl │ │ ├── omptl_algorithm │ │ ├── omptl_algorithm_par.h │ │ ├── omptl_algorithm_ser.h │ │ ├── omptl_numeric │ │ ├── omptl_numeric_extensions.h │ │ ├── omptl_numeric_extensions_par.h │ │ ├── omptl_numeric_extensions_ser.h │ │ ├── omptl_numeric_par.h │ │ ├── omptl_numeric_ser.h │ │ └── omptl_tools.h ├── libfab │ ├── CMakeLists.txt │ ├── asdf │ │ ├── asdf.c │ │ ├── asdf.h │ │ ├── cache.c │ │ ├── cache.h │ │ ├── cms.c │ │ ├── cms.h │ │ ├── contour.c │ │ ├── contour.h │ │ ├── distance.c │ │ ├── distance.h │ │ ├── file_io.c │ │ ├── file_io.h │ │ ├── import.c │ │ ├── import.h │ │ ├── neighbors.c │ │ ├── neighbors.h │ │ ├── render.c │ │ ├── render.h │ │ ├── triangulate.c │ │ └── triangulate.h │ ├── cam │ │ ├── distance.c │ │ ├── distance.h │ │ ├── slices.c │ │ ├── slices.h │ │ ├── toolpath.c │ │ └── toolpath.h │ ├── formats │ │ ├── mesh.c │ │ ├── mesh.h │ │ ├── png_image.c │ │ ├── png_image.h │ │ ├── stl.c │ │ └── stl.h │ ├── libfab.so │ ├── tree │ │ ├── eval.c │ │ ├── eval.h │ │ ├── math │ │ │ ├── math_f.c │ │ │ ├── math_f.h │ │ │ ├── math_i.c │ │ │ ├── math_i.h │ │ │ ├── math_r.c │ │ │ └── math_r.h │ │ ├── node │ │ │ ├── node.c │ │ │ ├── node.h │ │ │ ├── opcodes.c │ │ │ ├── opcodes.h │ │ │ ├── printers.c │ │ │ ├── printers.h │ │ │ ├── results.c │ │ │ └── results.h │ │ ├── packed.c │ │ ├── packed.h │ │ ├── parser.c │ │ ├── parser.h │ │ ├── render.c │ │ ├── render.h │ │ ├── tree.c │ │ └── tree.h │ └── util │ │ ├── constants.h │ │ ├── interval.h │ │ ├── macros.h │ │ ├── path.c │ │ ├── path.h │ │ ├── region.c │ │ ├── region.h │ │ ├── squares.h │ │ ├── switches.h │ │ ├── vec3f.c │ │ └── vec3f.h ├── main.py ├── model │ ├── ToolConfig.h │ ├── VolumetricModel.h │ ├── structures.h │ └── utility.h ├── operationPlaner ├── operationPlanner.cpp ├── run_with_voxelizer.cpp ├── run_without_voxelizer.cpp ├── sequenceGenerator.h ├── sequenceGenerator_v1.cpp~ ├── standalone_voxelizer.cpp ├── test.txt ├── toolpathGenerator.h ├── voxelizer.cpp~ └── voxelizer.h ├── test ├── .DS_Store ├── test.py ├── testcases │ ├── .DS_Store │ ├── stl │ │ ├── .DS_Store │ │ ├── case_1.stl │ │ ├── case_2.stl │ │ ├── case_3.stl │ │ ├── case_4.stl │ │ ├── case_5.stl │ │ ├── case_6.stl │ │ └── case_7.stl │ └── voxel │ │ ├── .DS_Store │ │ ├── case_1.txt │ │ ├── case_2.txt │ │ ├── case_3.txt │ │ ├── case_4.txt │ │ ├── case_5.txt │ │ ├── case_6.txt │ │ └── case_7.txt ├── timeEstimator.py └── toBinaryTest.py └── utility ├── test.py ├── timeEstimator.py └── toBinaryTest.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2016] [Tanay Gahlot And Amey Kamat] 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 | 2 | ![Sample toolpaths generated by toolpath generator](docs/images/result-eps-converted-to.jpg) 3 | 4 | # ToolpathGenerator v1.0(Beta) 5 | Automating Toolpath Generation of 3D objects for 3-Axis CNC 6 | 7 | ToolpathGenerator automates toolpath planing process involved in toolpath generation of 3D objects for 3-Axis CNC. This work seeks to reduce the barrier faced by the entry level makers and designers involved in CNC machining. 8 | 9 | ## Usage 10 | ### Dependancies 11 | The voxelizer built into the system requires [boost library for c+](www.boost.org) to compile. Please note that, the [cvmlcpp library](https://github.com/fpbeekhof/cvmlcpp) has been modified and integrated into the source code. 12 | 13 | The voxelizer currently is known not to work on Mac, windows remains to be tested. 14 | 15 | ### Compiling 16 | #### Stand-alone Voxelizer 17 | If you wish to only voxelize the stl file without generating toolpaths, you need to compile as: 18 | ``` 19 | >g++ -std=c++11 ./src/standalone_voxelizer.cpp -o standalone_voxelizer 20 | ``` 21 | #### ToolpathGenerator without Voxelizer 22 | To run ToolpathGenerator without voxelizing, compile: 23 | ``` 24 | >g++ -std=c++11 ./src/run_without_voxelizer.cpp -o run_without_voxelizer 25 | ``` 26 | #### ToolpathGenerator with Voxelizer 27 | To run ToolpathGenerator with voxelizer, compile: 28 | ``` 29 | >g++ -std=c++11 ./src/run_with_voxelizer.cpp -o run_with_voxelizer 30 | ``` 31 | 32 | ### Executing 33 | #### Stand-alone Voxelizer 34 | Standalone voxelizer gives choice of input and output through parameters: 35 | 36 | ##### Input 37 | 38 | ``` 39 | "File" : Input as a file address 40 | 41 | "String" : Input as ASCII STL string through stdin 42 | ``` 43 | 44 | ##### Output 45 | ``` 46 | "JSON" : Output as JSON 47 | 48 | "String" : Output as string of 0s and 1s 49 | ``` 50 | 51 | Execute Standalone Voxelizer as: 52 | ``` 53 | >./standalone_voxelizer [input parameter] [output parameter] {input file address if file} [output file address] {< input string if string} 54 | ``` 55 | 56 | #### ToolpathGenerator without Voxelizer 57 | ToolpathGenerator without Voxelizer is run as: 58 | ``` 59 | >./run_without_voxelizer [output location] < [input voxel file] 60 | ``` 61 | 62 | #### ToolpathGenerator without Voxelizer 63 | ToolpathGenerator without Voxelizer is run as: 64 | ``` 65 | >./run_with_voxelizer [input voxel file] [output location] 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/images/result-eps-converted-to.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/docs/images/result-eps-converted-to.jpg -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Updating Repositories..." 4 | apt-get update 5 | 6 | echo "Installing..." 7 | apt-get install git g++ python 8 | 9 | echo "Removing Previous Boost Installation..." 10 | rm /usr/local/lib/libboost* 11 | rm -r /usr/local/include/boost 12 | 13 | cd .. 14 | echo "Downloading Boost..." 15 | wget -c 'http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.bz2/download' 16 | echo "Extracting and Installing Boost..." 17 | tar xf download 18 | cd boost_1_60_0 19 | ./bootstrap.sh 20 | ./b2 install 21 | 22 | cd ../ToolpathGenerator/src 23 | echo "Compiling Binaries..." 24 | g++ ./heightmapGenerator.cpp -o heightmapGenerator -std=c++11 25 | g++ ./operationPlanner.cpp -o operationPlaner -std=c++11 26 | 27 | cd .. 28 | 29 | echo "Done." 30 | -------------------------------------------------------------------------------- /machinability.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | void dist_transform(vector> heightMap, int xMax, int yMax){ 7 | 8 | vector> g = vector(xMax, vector(yMax, int)); 9 | for(int x = 0; x=0; y--){ 26 | if(g[x][y=1] < g[x][y]){ 27 | g[x][y] = g[x][y+1]; 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/a.out -------------------------------------------------------------------------------- /src/heightmapGenerator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/heightmapGenerator -------------------------------------------------------------------------------- /src/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update 4 | 5 | apt-get install git g++ 6 | 7 | wget -c 'http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.bz2/download' 8 | tar xf download 9 | cd boost_1_50_0 10 | ./bootstrap.sh 11 | ./b2 install 12 | 13 | g++ ./heightmapGenerator.cpp -o heightmapGenerator -std=c++11 14 | g++ ./operationPlanner.cpp -o operationPlaner -std=c++11 15 | 16 | sudo npm install 17 | -------------------------------------------------------------------------------- /src/koko/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/__init__.pyc -------------------------------------------------------------------------------- /src/koko/c/__init__.py: -------------------------------------------------------------------------------- 1 | """ Module defining C data structures from the libfab library. """ 2 | -------------------------------------------------------------------------------- /src/koko/c/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/__init__.pyc -------------------------------------------------------------------------------- /src/koko/c/asdf.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | from koko.c.interval import Interval 4 | 5 | class ASDF(ctypes.Structure): 6 | """ @class ASDF 7 | @brief C data structure describing an ASDF. 8 | """ 9 | pass 10 | ASDF._fields_ = [('state', ctypes.c_int), 11 | ('X', Interval), ('Y', Interval), ('Z', Interval), 12 | ('branches', ctypes.POINTER(ASDF)*8), 13 | ('d', ctypes.c_float*8), 14 | ('data', ctypes.c_void_p)] 15 | -------------------------------------------------------------------------------- /src/koko/c/asdf.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/asdf.pyc -------------------------------------------------------------------------------- /src/koko/c/interval.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | class Interval(ctypes.Structure): 4 | """ @class Interval 5 | @brief Interval containing upper and lower bounds with overloaded arithmetic operators 6 | """ 7 | _fields_ = [('lower', ctypes.c_float), 8 | ('upper', ctypes.c_float)] 9 | 10 | def __init__(self, lower=0, upper=None): 11 | """ @brief Constructor for Interval 12 | @param lower Lower bound 13 | @param upper Upper bound (if None, lower is used) 14 | """ 15 | if upper is None: upper = lower 16 | if isinstance(lower, Interval): 17 | lower, upper = lower.lower, lower.upper 18 | ctypes.Structure.__init__(self, lower, upper) 19 | 20 | def __str__(self): 21 | return "[%g, %g]" % (self.lower, self.upper) 22 | def __repr__(self): 23 | return "Interval(%g, %g)" % (self.lower, self.upper) 24 | def __add__(self, rhs): return libfab.add_i(self, Interval(rhs)) 25 | def __radd__(self, lhs): return libfab.add_i(Interval(lhs), self) 26 | def __sub__(self, rhs): return libfab.sub_i(self, Interval(rhs)) 27 | def __rsub__(self, lhs): return libfab.sub_i(Interval(lhs), self) 28 | def __mul__(self, rhs): return libfab.mul_i(self, Interval(rhs)) 29 | def __rmul__(self, lhs): return libfab.mul_i(Interval(lhs), self) 30 | def __div__(self, rhs): return libfab.div_i(self, Interval(rhs)) 31 | def __rdiv__(self, lhs): return libfab.div_i(Interval(lhs), self) 32 | def __neg__(self): return libfab.neg_i(self) 33 | 34 | @staticmethod 35 | def sqrt(i): return libfab.sqrt_i(i) 36 | @staticmethod 37 | def pow(i, e): return libfab.pow_i(i, e) 38 | @staticmethod 39 | def sin(i): return libfab.sin_i(i) 40 | @staticmethod 41 | def cos(i): return libfab.cos_i(i) 42 | @staticmethod 43 | def tan(i): return libfab.tan_i(i) 44 | 45 | def copy(self): 46 | return Interval(self.lower, self.upper) 47 | 48 | from koko.c.libfab import libfab 49 | -------------------------------------------------------------------------------- /src/koko/c/interval.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/interval.pyc -------------------------------------------------------------------------------- /src/koko/c/libfab.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/libfab.pyc -------------------------------------------------------------------------------- /src/koko/c/mesh.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | from koko.c.interval import Interval 4 | 5 | class Mesh(ctypes.Structure): 6 | """ @class Mesh 7 | @brief C data structure describing a Mesh 8 | """ 9 | _fields_ = [ 10 | ('vdata', ctypes.POINTER(ctypes.c_float)), 11 | ('vcount', ctypes.c_uint32), 12 | ('valloc', ctypes.c_uint32), 13 | ('tdata', ctypes.POINTER(ctypes.c_uint32)), 14 | ('tcount', ctypes.c_uint32), 15 | ('talloc', ctypes.c_uint32), 16 | ('X', Interval), ('Y', Interval), ('Z', Interval) 17 | ] 18 | 19 | -------------------------------------------------------------------------------- /src/koko/c/mesh.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/mesh.pyc -------------------------------------------------------------------------------- /src/koko/c/multithread.py: -------------------------------------------------------------------------------- 1 | import threading 2 | from thread import LockType 3 | 4 | def __monitor(interrupt, halt): 5 | """ @brief Waits for interrupt, then sets halt to 1 6 | @param interrupt threading.Event on which we wait 7 | @param halt ctypes.c_int used as a flag elsewhere 8 | """ 9 | interrupt.wait() 10 | halt.value = 1 11 | 12 | 13 | def multithread(target, args, interrupt=None, halt=None): 14 | """ @brief Runs a process on multiple threads. 15 | @details Must be called with both interrupt and halt or neither. Interrupt is cleared before returning. 16 | @param target Callable function 17 | @param args List of argument tuples (one tuple per thread) 18 | @param interrupt threading.Event to halt thread or None 19 | @param halt ctypes.c_int used as an interrupt flag by target 20 | """ 21 | 22 | if (halt is None) ^ (interrupt is None): 23 | raise ValueError('multithread must be invoked with both halt and interrupt (or neither)') 24 | 25 | threads = [threading.Thread(target=target, args=a) for a in args] 26 | 27 | if interrupt: 28 | m = threading.Thread(target=__monitor, args=(interrupt, halt)) 29 | m.daemon = True 30 | m.start() 31 | 32 | for t in threads: t.daemon = True 33 | for t in threads: t.start() 34 | for t in threads: t.join() 35 | 36 | if interrupt: 37 | interrupt.set() 38 | m.join() 39 | interrupt.clear() 40 | 41 | 42 | def monothread(target, args, interrupt=None, halt=None): 43 | """ @brief Runs a process on a single thread 44 | @details Must be called with both interrupt and halt or neither. Interrupt is cleared before returning. 45 | @param target Callable function 46 | @param args Argument tuples 47 | @param interrupt threading.Event to halt thread or None 48 | @param halt ctypes.c_int used as an interrupt flag by target 49 | """ 50 | if (halt is None) ^ (interrupt is None): 51 | raise ValueError('monothread must be invoked with both halt and interrupt (or neither)') 52 | 53 | if interrupt: 54 | m = threading.Thread(target=__monitor, args=(interrupt, halt)) 55 | m.daemon = True 56 | m.start() 57 | 58 | result = target(*args) 59 | 60 | if interrupt: 61 | interrupt.set() 62 | m.join() 63 | interrupt.clear() 64 | 65 | return result 66 | 67 | def threadsafe(f): 68 | ''' A decorator that locks the arguments to a function, 69 | invokes the function, then unlocks the arguments and 70 | returns.''' 71 | def wrapped(*args, **kwargs): 72 | for a in set(list(args) + kwargs.values()): 73 | if hasattr(a, 'lock') and LockType and isinstance(a.lock, LockType): 74 | a.lock.acquire() 75 | result = f(*args, **kwargs) 76 | for a in set(list(args) + kwargs.values()): 77 | if hasattr(a, 'lock') and LockType and isinstance(a.lock, LockType): 78 | a.lock.release() 79 | return result 80 | return wrapped 81 | -------------------------------------------------------------------------------- /src/koko/c/multithread.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/multithread.pyc -------------------------------------------------------------------------------- /src/koko/c/path.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | class Path(ctypes.Structure): 4 | """ @class Path 5 | @brief C data structure containing a doubly linked list. 6 | """ 7 | def __repr__(self): 8 | return 'pt(%g, %g) at %s' % \ 9 | (self.x, self.y, hex(ctypes.addressof(self))) 10 | def __eq__(self, other): 11 | if other is None: return False 12 | return ctypes.addressof(self) == ctypes.addressof(other) 13 | def __ne__(self, other): 14 | if other is None: return False 15 | return not (self == other) 16 | 17 | def p(t): return ctypes.POINTER(t) 18 | def pp(t): return p(p(t)) 19 | 20 | Path._fields_ = [ 21 | ('prev', p(Path)), ('next', p(Path)), 22 | ('x', ctypes.c_float), ('y', ctypes.c_float), ('z', ctypes.c_float), 23 | ('ptr', pp(Path*2)) 24 | ] 25 | 26 | del p, pp 27 | -------------------------------------------------------------------------------- /src/koko/c/path.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/path.pyc -------------------------------------------------------------------------------- /src/koko/c/region.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | 3 | class Region(ctypes.Structure): 4 | ''' @class Region 5 | @brief Class containing lattice bounds and ticks. 6 | @details Replicates C Region class. 7 | ''' 8 | _fields_ = [('imin', ctypes.c_uint32), 9 | ('jmin', ctypes.c_uint32), 10 | ('kmin', ctypes.c_uint32), 11 | ('ni', ctypes.c_uint32), 12 | ('nj', ctypes.c_uint32), 13 | ('nk', ctypes.c_uint32), 14 | ('voxels', ctypes.c_uint64), 15 | ('X', ctypes.POINTER(ctypes.c_float)), 16 | ('Y', ctypes.POINTER(ctypes.c_float)), 17 | ('Z', ctypes.POINTER(ctypes.c_float)), 18 | ('L', ctypes.POINTER(ctypes.c_uint16))] 19 | 20 | def __init__(self, (xmin, ymin, zmin)=(0.,0.,0.), 21 | (xmax, ymax, zmax)=(0.,0.,0.), 22 | scale=100., dummy=False, depth=None): 23 | """ @brief Creates an array. 24 | """ 25 | 26 | dx = float(xmax - xmin) 27 | dy = float(ymax - ymin) 28 | dz = float(zmax - zmin) 29 | 30 | if depth is not None: 31 | scale = 3*(2**6)* 2**(depth/3.) / (dx+dy+dz) 32 | 33 | ni = max(int(round(dx*scale)), 1) 34 | nj = max(int(round(dy*scale)), 1) 35 | nk = max(int(round(dz*scale)), 1) 36 | 37 | # Dummy assignments so that Doxygen recognizes these instance variables 38 | self.ni = self.nj = self.nk = 0 39 | self.imin = self.jmin = self.kmin = 0 40 | self.voxels = 0 41 | self.X = self.Y = self.Z = self.L = None 42 | 43 | ## @var ni 44 | # Number of ticks along x axis 45 | ## @var nj 46 | #Number of points along y axis 47 | ## @var nk 48 | # Number of points along z axis 49 | 50 | ## @var imin 51 | # Minimum i coordinate in global lattice space 52 | ## @var jmin 53 | # Minimum j coordinate in global lattice space 54 | ## @var kmin 55 | # Minimum k coordinate in global lattice space 56 | 57 | ## @var voxels 58 | # Voxel count in this section of the lattice 59 | 60 | ## @var X 61 | # Array of ni+1 X coordinates as floating-point values 62 | ## @var Y 63 | # Array of nj+1 Y coordinates as floating-point values 64 | ## @var Z 65 | # Array of nk+1 Z coordinates as floating-point values 66 | ## @var L 67 | # Array of nk+1 luminosity values as 16-bit integers 68 | 69 | ## @var free_arrays 70 | # Boolean indicating whether this region dynamically allocated 71 | # the X, Y, Z, and L arrays. 72 | # 73 | # Determines whether these arrays are 74 | # freed when the structure is deleted. 75 | 76 | ctypes.Structure.__init__(self, 77 | 0, 0, 0, 78 | ni, nj, nk, 79 | ni*nj*nk, 80 | None, None, None, None) 81 | 82 | if dummy is False: 83 | libfab.build_arrays(ctypes.byref(self), 84 | xmin, ymin, zmin, 85 | xmax, ymax, zmax) 86 | self.free_arrays = True 87 | else: 88 | self.free_arrays = False 89 | 90 | def __del__(self): 91 | """ @brief Destructor for Region 92 | @details Frees allocated arrays if free_arrays is True 93 | """ 94 | if hasattr(self, 'free_arrays') and self.free_arrays and libfab is not None: 95 | libfab.free_arrays(self) 96 | 97 | def __repr__(self): 98 | return ('[(%g, %g), (%g, %g), (%g, %g)]' % 99 | (self.imin, self.imin + self.ni, 100 | self.jmin, self.jmin + self.nj, 101 | self.kmin, self.kmin + self.nk)) 102 | 103 | def split(self, count=2): 104 | """ @brief Repeatedly splits the region along its longest axis 105 | @param count Number of subregions to generate 106 | @returns List of regions (could be fewer than requested if the region is indivisible) 107 | """ 108 | L = (Region*count)() 109 | count = libfab.split(self, L, count) 110 | 111 | return L[:count] 112 | 113 | def split_xy(self, count=2): 114 | """ @brief Repeatedly splits the region on the X and Y axes 115 | @param count Number of subregions to generate 116 | @returns List of regions (could be fewer than requested if the region is indivisible) 117 | """ 118 | L = (Region*count)() 119 | count = libfab.split_xy(self, L, count) 120 | 121 | return L[:count] 122 | 123 | def octsect(self, all=False, overlap=False): 124 | """ @brief Splits the region into eight subregions 125 | @param all If true, returns an 8-item array with None in the place of missing subregions. Otherwise, the output array is culled to only include valid subregions. 126 | @returns An array of containing regions (and Nones if all is True and the region was indivisible along some axis) 127 | """ 128 | L = (Region*8)() 129 | if overlap: 130 | bits = libfab.octsect_overlap(self, L) 131 | else: 132 | bits = libfab.octsect(self, L) 133 | 134 | if all: 135 | return [L[i] if (bits & (1 << i)) else None for i in range(8)] 136 | else: 137 | return [L[i] for i in range(8) if (bits & (1 << i))] 138 | 139 | 140 | from koko.c.libfab import libfab 141 | from koko.c.vec3f import Vec3f 142 | -------------------------------------------------------------------------------- /src/koko/c/region.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/region.pyc -------------------------------------------------------------------------------- /src/koko/c/vec3f.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | from math import sin, cos, radians, sqrt 3 | 4 | class Vec3f(ctypes.Structure): 5 | """ @class Vec3f 6 | @brief Three-element vector with overloaded arithmetic operators. 7 | """ 8 | _fields_ = [('x', ctypes.c_float), 9 | ('y', ctypes.c_float), 10 | ('z', ctypes.c_float)] 11 | def __init__(self, x=0., y=0., z=0.): 12 | try: x = list(x) 13 | except TypeError: ctypes.Structure.__init__(self, x, y, z) 14 | else: ctypes.Structure.__init__(self, x[0], x[1], x[2]) 15 | 16 | def __str__(self): 17 | return "(%g, %g, %g)" % (self.x, self.y, self.z) 18 | def __repr__(self): 19 | return "Vec3f(%g, %g, %g)" % (self.x, self.y, self.z) 20 | def __add__(self, rhs): 21 | return Vec3f(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z) 22 | def __sub__(self, rhs): 23 | return Vec3f(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z) 24 | def __div__(self, rhs): 25 | return Vec3f(self.x/rhs, self.y/rhs, self.z/rhs) 26 | def __neg__(self): 27 | return Vec3f(-self.x, -self.y, -self.z) 28 | def length(self): 29 | return sqrt(self.x**2 + self.y**2 + self.z**2) 30 | def copy(self): 31 | return Vec3f(self.x, self.y, self.z) 32 | 33 | @staticmethod 34 | def M(alpha, beta): 35 | """ @brief Generates M matrix for libfab's project and deproject functions. 36 | @param alpha Rotation about z axis 37 | @param beta Rotation about x axis. 38 | @returns (cos(a), sin(a), cos(b), sin(b)) as float array 39 | """ 40 | return (ctypes.c_float*4)( 41 | cos(radians(alpha)), sin(radians(alpha)), 42 | cos(radians(beta)), sin(radians(beta)) 43 | ) 44 | 45 | def project(self, alpha, beta): 46 | """ @brief Transforms from cell frame to view frame. 47 | @param alpha Rotation about z axis 48 | @param beta Rotation about x axis. 49 | @returns Projected Vec3f object 50 | """ 51 | return libfab.project(self, self.M(alpha, beta)) 52 | 53 | def deproject(self, alpha, beta): 54 | """ @brief Transforms from view frame to cell frame. 55 | @param alpha Rotation about z axis 56 | @param beta Rotation about x axis. 57 | @returns Deprojected Vec3f object 58 | """ 59 | return libfab.deproject(self, self.M(alpha, beta)) 60 | 61 | def __iter__(self): 62 | """ @brief Iterates over (x, y, z) list 63 | """ 64 | return [self.x, self.y, self.z].__iter__() 65 | 66 | from koko.c.libfab import libfab 67 | -------------------------------------------------------------------------------- /src/koko/c/vec3f.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/c/vec3f.pyc -------------------------------------------------------------------------------- /src/koko/fab/__init__.py: -------------------------------------------------------------------------------- 1 | """ Module defining classes used in design and fabrication workflow. """ 2 | -------------------------------------------------------------------------------- /src/koko/fab/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/__init__.pyc -------------------------------------------------------------------------------- /src/koko/fab/asdf.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/asdf.pyc -------------------------------------------------------------------------------- /src/koko/fab/fabvars.py: -------------------------------------------------------------------------------- 1 | """ Module defining a container class for CAD state and settings """ 2 | 3 | import operator 4 | 5 | from koko.lib.shapes2d import color 6 | from koko.fab.tree import MathTree 7 | 8 | class FabVars(object): 9 | ''' Container class to hold CAD state and settings.''' 10 | def __init__(self): 11 | self._shapes = [] 12 | self._shape = None 13 | self.render_mode = None 14 | self.mm_per_unit = 25.4 15 | self.border = 0.05 16 | 17 | @property 18 | def shapes(self): return self._shapes 19 | @shapes.setter 20 | def shapes(self, value): 21 | if type(value) not in (list, tuple): 22 | raise TypeError('cad.shapes must be a list or tuple of MathTree objects') 23 | value = map(MathTree.wrap, value) 24 | self._shapes = list(value) 25 | self._shape = reduce(operator.add, 26 | [color(s, None) for s in self.shapes] 27 | ) 28 | 29 | @property 30 | def shape(self): return self._shape 31 | @shape.setter 32 | def shape(self, value): self.shapes = [MathTree.wrap(value)] 33 | @property 34 | def function(self): return self.shape 35 | @function.setter 36 | def function(self, value): self.shape = value 37 | 38 | @property 39 | def render_mode(self): 40 | return self._render_mode 41 | @render_mode.setter 42 | def render_mode(self, value): 43 | if value not in ['2D','3D',None]: 44 | raise TypeError("render_mode must be '2D' or '3D'") 45 | self._render_mode = value 46 | 47 | @property 48 | def mm_per_unit(self): 49 | return self._mm_per_unit 50 | @mm_per_unit.setter 51 | def mm_per_unit(self, value): 52 | try: 53 | self._mm_per_unit = float(value) 54 | except TypeError: 55 | raise TypeError("mm_per_unit should be a number.") 56 | 57 | 58 | 59 | @property 60 | def xmin(self): 61 | try: 62 | dx = (max(s.xmax for s in self.shapes) - 63 | min(s.xmin for s in self.shapes)) 64 | return min(s.xmin for s in self.shapes) - dx*self.border/2. 65 | except (TypeError, ValueError, AttributeError): return None 66 | @property 67 | def xmax(self): 68 | try: 69 | dx = (max(s.xmax for s in self.shapes) - 70 | min(s.xmin for s in self.shapes)) 71 | return max(s.xmax for s in self.shapes) + dx*self.border/2. 72 | except (TypeError, ValueError, AttributeError): return None 73 | @property 74 | def dx(self): 75 | try: return self.xmax - self.xmin 76 | except TypeError: return None 77 | 78 | @property 79 | def ymin(self): 80 | try: 81 | dy = (max(s.ymax for s in self.shapes) - 82 | min(s.ymin for s in self.shapes)) 83 | return min(s.ymin for s in self.shapes) - dy*self.border/2. 84 | except (TypeError, ValueError, AttributeError): return None 85 | @property 86 | def ymax(self): 87 | try: 88 | dy = (max(s.ymax for s in self.shapes) - 89 | min(s.ymin for s in self.shapes)) 90 | return max(s.ymax for s in self.shapes) + dy*self.border/2. 91 | except (TypeError, ValueError, AttributeError): return None 92 | @property 93 | def dy(self): 94 | try: return self.ymax - self.ymin 95 | except TypeError: return None 96 | 97 | @property 98 | def zmin(self): 99 | try: 100 | dz = (max(s.zmax for s in self.shapes) - 101 | min(s.zmin for s in self.shapes)) 102 | return min(s.zmin for s in self.shapes) - dz*self.border/2. 103 | except (TypeError, ValueError, AttributeError): return None 104 | @property 105 | def zmax(self): 106 | try: 107 | dz = (max(s.zmax for s in self.shapes) - 108 | min(s.zmin for s in self.shapes)) 109 | return max(s.zmax for s in self.shapes) + dz*self.border/2. 110 | except (TypeError, ValueError, AttributeError): return None 111 | @property 112 | def dz(self): 113 | try: return self.zmax - self.zmin 114 | except TypeError: return None 115 | 116 | @property 117 | def bounded(self): 118 | return all(getattr(self, b) is not None for b in 119 | ['xmin','xmax','ymin','ymax','zmin','zmax']) 120 | 121 | -------------------------------------------------------------------------------- /src/koko/fab/fabvars.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/fabvars.pyc -------------------------------------------------------------------------------- /src/koko/fab/image (Tanay Gahlot's conflicted copy 2016-03-05).pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/image (Tanay Gahlot's conflicted copy 2016-03-05).pyc -------------------------------------------------------------------------------- /src/koko/fab/image.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/image.pyc -------------------------------------------------------------------------------- /src/koko/fab/mesh.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/mesh.pyc -------------------------------------------------------------------------------- /src/koko/fab/path.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/path.pyc -------------------------------------------------------------------------------- /src/koko/fab/tree.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TanayGahlot/ToolpathGenerator/a10aabfc704dd88d348c20b95072fe9cdd4bb383/src/koko/fab/tree.pyc -------------------------------------------------------------------------------- /src/lib/cvmlcpp/array/ArrayIO: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2007 by BEEKHOF, Fokko * 3 | * fpbeekhof@gmail.com * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef CVMLCPP_ARRAYIO 22 | #define CVMLCPP_ARRAYIO 1 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "../base/stl_cstdint.h" 29 | 30 | #include "../base/Meta" 31 | 32 | namespace cvmlcpp 33 | { 34 | 35 | template