-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunfold1.scad
107 lines (84 loc) · 11.3 KB
/
unfold1.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
$fn = 48;
polyhedron(points = [[8.0270463088, 22.2910190083, 4.3911295103], [5.7086083173, 17.8123176372, 4.3911296693], [9.0586216944, 18.4332435066, 4.3911295438], [8.0270463157, 22.2910190101, 4.3911295184], [9.0586216875, 18.4332435047, 4.3911295357], [12.1758003435, 22.0697927911, 4.3911294754], [12.1758003462, 22.0697927888, 4.3911295032], [9.0586216848, 18.4332435070, 4.3911295079], [12.5521639583, 19.4770531753, 4.3911295036], [12.1758003544, 22.0697927900, 4.3911295164], [12.5521639501, 19.4770531741, 4.3911294905], [15.8224963805, 21.3955573783, 4.3911293993], [15.8224963816, 21.3955573842, 4.3911294462], [14.3592315921, 24.9108401351, 4.3911294425], [12.1758003533, 22.0697927841, 4.3911294694], [14.3592315931, 24.9108401356, 4.3911294406], [15.8224963805, 21.3955573837, 4.3911294481], [17.7348757539, 24.6305473745, 4.3911295389], [14.1873467830, 30.2960576694, 4.3911294001], [14.3592315942, 24.9108401478, 4.3911295054], [17.7348757529, 24.6305473623, 4.3911294741], [17.7348757546, 24.6305473634, 4.3911293949], [16.1735972591, 31.6710706626, 4.3911294233], [14.1873467813, 30.2960576683, 4.3911294793], [16.1735972517, 31.6710706610, 4.3911293778], [17.7348757619, 24.6305473650, 4.3911294404], [19.6678539085, 26.8514572331, 4.3911294427], [17.7348757610, 24.6305473658, 4.3911294458], [21.3538045172, 24.0557064649, 4.3911294312], [19.6678539094, 26.8514572323, 4.3911294373], [19.6678539113, 26.8514572334, 4.3911294172], [21.3538045153, 24.0557064637, 4.3911294513], [21.8422824623, 29.0856974731, 4.3911294097], [21.3538045111, 24.0557064641, 4.3911294592], [25.5677651895, 27.2769943389, 4.3911292960], [21.8422824665, 29.0856974727, 4.3911294017], [21.8422824559, 29.0856974507, 4.3911293764], [25.5677652002, 27.2769943609, 4.3911293213], [26.0520936735, 30.2529972043, 4.3911292230], [27.7238814815, 26.4310576350, 4.3911292895], [26.0520936851, 30.2529972024, 4.3911292834], [25.5677651886, 27.2769943627, 4.3911292610], [27.7238814811, 26.4310576348, 4.3911293144], [30.1450110541, 28.7572917589, 4.3911293264], [26.0520936855, 30.2529972026, 4.3911292584], [32.0962237540, 25.0366758363, 4.3911295378], [30.1450110478, 28.7572917655, 4.3911293487], [27.7238814874, 26.4310576282, 4.3911292921], [30.1450110503, 28.7572917669, 4.3911294879], [32.0962237514, 25.0366758350, 4.3911293986], [32.9771732027, 27.8747011410, 4.3911293185], [30.1450110443, 28.7572917474, 4.3911294092], [32.9771732088, 27.8747011604, 4.3911293972], [33.9628555860, 31.2447719997, 4.3911293678], [33.9628555953, 31.2447719970, 4.3911293674], [32.9771731995, 27.8747011631, 4.3911293976], [37.4942805222, 26.4927159225, 4.3911293418], [36.9938115230, 25.3885880163, 4.3911293002], [32.9771732125, 27.8747011379, 4.3911293644], [32.0962237416, 25.0366758380, 4.3911293527], [32.0962237413, 25.0366758419, 4.3911293168], [36.1103054037, 19.7712426261, 4.3911293220], [36.9938115233, 25.3885880124, 4.3911293361], [36.1103054230, 19.7712426230, 4.3911292887], [41.1749769004, 24.5140558347, 4.3911292418], [36.9938115040, 25.3885880154, 4.3911293693], [41.1749769021, 24.5140558328, 4.3911292391], [36.1103054212, 19.7712426249, 4.3911292914], [41.4708945047, 19.3622538324, 4.3911291569], [44.0167811132, 20.0027965200, 4.3911290934], [41.1749768738, 24.5140558311, 4.3911293134], [41.4708945331, 19.3622538340, 4.3911290826], [24.1593112217, 33.3671758727, 4.3911292935], [21.8422824581, 29.0856974426, 4.3911292821], [26.0520936713, 30.2529972125, 4.3911293173], [24.1593112161, 33.3671758693, 4.3911293413], [26.0520936769, 30.2529972159, 4.3911292695], [28.2273461517, 34.6851018183, 4.3911293321], [24.1593112207, 33.3671758550, 4.3911294124], [28.2273461470, 34.6851018326, 4.3911292610], [23.8247077291, 36.2928969416, 4.3911293829], [24.1593112276, 33.3671758557, 4.3911294038], [23.8247077222, 36.2928969408, 4.3911293915], [20.1038112902, 35.5886264783, 4.3911294738], [24.3531707109, 40.7952568991, 4.3911296101], [20.1038112869, 35.5886264962, 4.3911293515], [23.8247077256, 36.2928969229, 4.3911295138], [20.1038113067, 35.5886264800, 4.3911294349], [24.3531706910, 40.7952569153, 4.3911295266], [19.7414920467, 41.8682424252, 4.3911294862], [19.7414920452, 41.8682424186, 4.3911295429], [24.3531706926, 40.7952569219, 4.3911294699], [22.3676815595, 44.2785284739, 4.3911294895], [19.7414920486, 41.8682424148, 4.3911295144], [22.3676815560, 44.2785284776, 4.3911295180], [19.1172764011, 46.3429218910, 4.3911293967], [28.7212005527, 37.3442449916, 4.3911293563], [23.8247077245, 36.2928969290, 4.3911293262], [28.2273461516, 34.6851018452, 4.3911293177], [26.4835018203, 39.9645903308, 4.3911293502], [23.8247077245, 36.2928969288, 4.3911293593], [28.7212005527, 37.3442449917, 4.3911293233], [21.8422824592, 29.0856974420, 4.3911292988], [24.1593112207, 33.3671758733, 4.3911292767], [19.6025812318, 34.1533911226, 4.3911293710], [19.6678539134, 26.8514572314, 4.3911294168], [21.8422824603, 29.0856974751, 4.3911294102], [17.3562393118, 32.3373428583, 4.3911294142], [16.1735972397, 31.6710706906, 4.3911294318], [12.2541631763, 32.4997480059, 4.3911293987], [14.1873468007, 30.2960576403, 4.3911294707], [9.6672180727, 30.6803536048, 4.3911293901], [14.1873468093, 30.2960576478, 4.3911294203], [12.2541631677, 32.4997479983, 4.3911294491], [9.8848472096, 35.1262815214, 4.3911293783], [9.6672180735, 30.6803536036, 4.3911294538], [12.2541631668, 32.4997479996, 4.3911293854], [9.8848472051, 35.1262815216, 4.3911293887], [7.6306372291, 32.3290431095, 4.3911293000], [9.6672180781, 30.6803536034, 4.3911294434], [7.6306372234, 32.3290431141, 4.3911292851], [9.8848472108, 35.1262815170, 4.3911294036], [5.4700410796, 34.1661313135, 4.3911292308], [16.1735972397, 31.6710706905, 4.3911293988], [11.5847743920, 35.9731116641, 4.3911296018], [12.2541631763, 32.4997480059, 4.3911294317], [11.2892800115, 26.8060066149, 4.3911295115], [14.3592316269, 24.9108401488, 4.3911295385], [14.1873467503, 30.2960576683, 4.3911293670], [11.2892800013, 26.8060065983, 4.3911294721], [11.2155380469, 23.1915052253, 4.3911295989], [14.3592316371, 24.9108401654, 4.3911295779], [9.2659080433, 25.1411328507, 4.3911295411], [11.2155380554, 23.1915052251, 4.3911295198], [11.2892799928, 26.8060065985, 4.3911295512], [9.0586216832, 18.4332435123, 4.3911295127], [13.3185810521, 17.5144728546, 4.3911294099], [12.5521639598, 19.4770531701, 4.3911294987], [5.7086083112, 17.8123176697, 4.3911295958], [9.1839142370, 13.7477959518, 4.3911297661], [9.0586217004, 18.4332434741, 4.3911296173], [11.8700856961, 15.1035192193, 4.3911296043], [9.0586217124, 18.4332434745, 4.3911297209], [9.1839142250, 13.7477959515, 4.3911296624], [9.1839142286, 13.7477959442, 4.3911295943], [13.2635212499, 12.8786213056, 4.3911295636], [11.8700856924, 15.1035192266, 4.3911296725]], triangles = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20], [21, 22, 23], [24, 25, 26], [27, 28, 29], [30, 31, 32], [33, 34, 35], [36, 37, 38], [39, 40, 41], [42, 43, 44], [45, 46, 47], [48, 49, 50], [51, 52, 53], [54, 55, 56], [57, 58, 59], [60, 61, 62], [63, 64, 65], [66, 67, 68], [69, 70, 71], [72, 73, 74], [75, 76, 77], [78, 79, 80], [81, 82, 83], [84, 85, 86], [87, 88, 89], [90, 91, 92], [93, 94, 95], [96, 97, 98], [99, 100, 101], [102, 103, 104], [105, 106, 107], [108, 109, 110], [111, 112, 113], [114, 115, 116], [117, 118, 119], [120, 121, 122], [123, 124, 125], [126, 127, 128], [129, 130, 131], [132, 133, 134], [135, 136, 137], [138, 139, 140], [141, 142, 143], [144, 145, 146]]);
/***********************************************
****** SolidPython code: *************
************************************************
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
from __future__ import division
import os
import sys
import re
import tree
import utilities
from numpy import array,cross
from tree import TriangleNode, parseArrayIntoTree, parseEdgeArrayIntoTree, cutTreeIntoPatches
from stl_reader import Reader
from graph2 import Graph,TreeNode,treeLength
from utilities import getMatrixArbitraryAxis
from dxf_writer import DXFWriter
from evolution import TreeWorld
# Assumes SolidPython is in site-packages or elsewhwere in sys.path
from solid import *
from solid.utils import *
SEGMENTS = 48
filename = "kitten-122.stl"
triangles = Reader.read("stl/" + filename)
# triangles = Reader.read("stl/icosahedron.stl")
g = Graph(triangles)
n = len(g.nodes)
print "There are a total of ", n, " nodes"
hFn = lambda e: g.defaultHeuristic(e)
msp = g.toMSPTree(hFn)
edge_rep = msp.makeEdgeRepresentation()
hFn = lambda e: -g.defaultHeuristic(e)
msp2 = g.toMSPTree(hFn)
edge_rep2 = msp2.makeEdgeRepresentation()
world = TreeWorld(g, [edge_rep, edge_rep2])
child1 = world.generateFittest()
print child1
tn = parseEdgeArrayIntoTree(g.nodes, child1)
print treeLength(msp,set()), "faces"
#tn = parseArrayIntoTree(g.nodes, array_rep)
tn.unfold()
v = tn.getAllChildVertices()
v2d = tn.getAllChildVertices2D()
tn.getAllChildTriangles()
kdtree = utilities.makeKDTree(tn.getAllChildTriangles())
intersects = tn.checkIntersection() # return nodes thats intersect
print len(intersects), "faces that intersects"
paths = world.paths_intersection(child1)
cutEdges = g.cutEdges(paths)
print "Edges to cut:", cutEdges
tns = cutTreeIntoPatches(tn,cutEdges)
ds = [tn.convertToDict() for tn in tns]
print "No of Patches:", len(ds)
#v_i = [ x.getTransformedVertices2D() for x in intersects ]
#v = reduce(lambda x,y: x+y, v_i)
#print [x.node for x in xs]
#print len(xs)
#array_rep = [19, 55, 115, 49, -1, 147, 55, 194, 230, 180, 14, 82, 8, 198, 157, 197, 196, 81, 254, 240, 148, 120, 26, 46, 181, 123, 210, 223, 125, 143, 52, 21, 107, 16, 212, 250, 125, 73, 196, 27, 75, 249, 167, 39, 57, 103, 166, 23, 207, 15, 3, 240, 178, 191, 33, 181, 111, 29, 184, 177, 7, 92, 118, 59, 15, 93, 129, 58, 199, 94, 97, 98, 40, 61, 143, 64, 234, 251, 75, 91, 32, 78, 186, 133, 76, 134, 90, 4, 187, 218, 51, 49, 218, 182, 106, 43, 176, 138, 121, 63, 216, 151, 36, 10, 149, 146, 47, 226, 198, 133, 66, 104, 103, 46, 162, 10, 113, 251, 25, 83, 114, 62, 11, 5, 114, 206, 120, 38, 245, 185, 159, 110, 238, 1, 189, 226, 87, 154, 142, 160, 96, 54, 44, 5, 233, 68, 74, 12, 242, 253, 54, 208, 222, 211, 33, 93, 124, 155, 127, 215, 137, 127, 168, 13, 50, 173, 19, 152, 2, 24, 230, 6, 248, 115, 195, 153, 222, 232, 170, 148, 51, 173, 52, 254, 34, 253, 171, 84, 203, 205, 153, 135, 8, 197, 128, 60, 246, 141, 4, 9, 108, 3, 140, 144, 79, 117, 221, 100, 45, 158, 214, 20, 32, 22, 175, 111, 76, 18, 182, 175, 119, 85, 190, 139, 163, 99, 151, 234, 22, 63, 8, 144, 177, 144, 76, 237, 113, 193, 239, 238, 19, 162, 26, 244, 174, 140, 235, 225, 172, 41, 249, 117, 84, 77, 18, 239]
#print array_rep
#tn = parseArrayIntoTree(g.nodes, array_rep)
#tn.unfold()
#v = tn.getAllChildVertices()
def assembly(v):
a = polyhedron(
points=v,
triangles=[[x for x in range(y,y+3)] for y in range(0,len(v),3)])
return a
def intersecting():
a = polygon(
points=v2d,
paths=[[x for x in range(y,y+3)] for y in range(0,len(v),3)])
return a
if __name__ == '__main__':
for i,tn in enumerate(tns):
v = tn.getAllChildVertices()
a = assembly(v)
scad_render_to_file(a,'unfold{0}.scad'.format(i), file_header='$fn = %s;' % SEGMENTS, include_orig_code=True)
#a = intersecting()
scad_render_to_file(a,'unfold.scad', file_header='$fn = %s;' % SEGMENTS, include_orig_code=True)
d_writer = DXFWriter(n, ds, filename)
d_writer.generate_file()
***********************************************/