-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunfold0.scad
107 lines (84 loc) · 9.02 KB
/
unfold0.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 = [[-0.5832276605, 6.9252141051, 4.3911296913], [-1.2751503567, 9.7606306212, 4.3911296728], [-5.5845348783, 7.0255133474, 4.3911297106], [-3.6573813226, 14.2220837752, 4.3911298152], [-5.5845348675, 7.0255133303, 4.3911297222], [-1.2751503676, 9.7606306383, 4.3911296612], [-3.6573813460, 14.2220837627, 4.3911297400], [-1.2751503442, 9.7606306508, 4.3911297364], [3.6567318487, 15.0696365426, 4.3911296409], [-2.2755621931, 20.8533087398, 4.3911297014], [-3.6573813429, 14.2220837354, 4.3911296949], [3.6567318455, 15.0696365699, 4.3911296860], [3.6567318454, 15.0696365699, 4.3911296789], [1.7996404459, 20.6725330344, 4.3911296887], [-2.2755621930, 20.8533087399, 4.3911297085], [1.7996404964, 20.6725330511, 4.3911295980], [3.6567317950, 15.0696365531, 4.3911297695], [5.7086083258, 17.8123176302, 4.3911294728], [8.0270462989, 22.2910190134, 4.3911295613], [1.7996404950, 20.6725330493, 4.3911294525], [5.7086083272, 17.8123176321, 4.3911296183], [1.7996404884, 20.6725330748, 4.3911295031], [8.0270463055, 22.2910189879, 4.3911295107], [6.6959582811, 24.8512620485, 4.3911295322], [11.3235479908, 24.8196901538, 4.3911294599], [6.6959582591, 24.8512620370, 4.3911295840], [8.0270463276, 22.2910189993, 4.3911294589], [9.5730807326, 26.9499411826, 4.3911295462], [6.6959582590, 24.8512620359, 4.3911294691], [11.3235479908, 24.8196901549, 4.3911295748], [10.7253196320, 15.9601036115, 4.3911295011], [5.7086084062, 17.8123175702, 4.3911296055], [3.6567317147, 15.0696366132, 4.3911296368], [-0.8966414779, 24.4519674622, 4.3911297164], [-2.2755621941, 20.8533087161, 4.3911297089], [1.7996404470, 20.6725330581, 4.3911296883], [-0.8966414784, 24.4519674618, 4.3911296864], [1.7996404475, 20.6725330585, 4.3911297183], [3.8567555031, 26.7720397116, 4.3911296010], [2.6836753044, 30.1345047015, 4.3911296238], [-0.8966414739, 24.4519674526, 4.3911296417], [3.8567554986, 26.7720397208, 4.3911296457], [-0.8966414541, 24.4519674401, 4.3911297061], [2.6836752845, 30.1345047140, 4.3911295594], [-0.1485880019, 29.9883765994, 4.3911296177], [-3.6573813439, 14.2220837356, 4.3911296996], [-2.2755621920, 20.8533087396, 4.3911296967], [-8.4879616071, 20.5475846024, 4.3911295443], [-2.2755621887, 20.8533086720, 4.3911296196], [-4.9950095999, 23.5839446584, 4.3911296143], [-8.4879616104, 20.5475846700, 4.3911296214], [-9.0038958762, 26.1310181786, 4.3911295563], [-8.4879616122, 20.5475846721, 4.3911295949], [-4.9950095981, 23.5839446563, 4.3911296408], [-4.9950095869, 23.5839446740, 4.3911296188], [-8.2823894533, 28.1010835871, 4.3911294290], [-9.0038958875, 26.1310181609, 4.3911295782], [0.7638346427, 7.6723576688, 4.3911296714], [3.6567318504, 15.0696365410, 4.3911297306], [-1.2751503459, 9.7606306524, 4.3911296466], [0.7638346706, 7.6723576579, 4.3911296075], [4.1432301669, 7.9618108661, 4.3911296644], [3.6567318225, 15.0696365519, 4.3911297945], [-5.5845348730, 7.0255133318, 4.3911297878], [-3.6573813171, 14.2220837737, 4.3911297495], [-7.0999917282, 9.8385375790, 4.3911297622], [-11.4161378176, 12.4477769122, 4.3911298544], [-7.0999916985, 9.8385375557, 4.3911298447], [-3.6573813468, 14.2220837971, 4.3911296670], [-11.4161378173, 12.4477769126, 4.3911298475], [-9.3698820289, 6.2335981530, 4.3911298428], [-7.0999916988, 9.8385375552, 4.3911298517], [-9.3698821383, 6.2335981170, 4.3911297535], [-11.4161377079, 12.4477769487, 4.3911299367], [-11.2706907398, 6.6760840547, 4.3911297873], [-11.2706907242, 6.6760840551, 4.3911298736], [-11.4161377235, 12.4477769483, 4.3911298504], [-15.8481951953, 9.0129866412, 4.3911297903], [-5.5845348713, 7.0255133327, 4.3911297766], [-7.0999917299, 9.8385375781, 4.3911297735], [-8.5754238796, 5.8421529400, 4.3911297701], [-8.5754238476, 5.8421528588, 4.3911297073], [-7.0868699153, 4.5799823729, 4.3911297230], [-5.5845349034, 7.0255134138, 4.3911298393], [-5.5845348949, 7.0255134086, 4.3911297680], [-7.0868699238, 4.5799823781, 4.3911297944], [-3.6773918351, 3.2860457095, 4.3911297161], [-3.6773918387, 3.2860457000, 4.3911297556], [-7.0868699202, 4.5799823877, 4.3911297549], [-5.9321802926, -0.4281462792, 4.3911297500], [-0.5832276604, 6.9252141117, 4.3911297357], [-5.5845348785, 7.0255133408, 4.3911296662], [-1.8947423572, 5.0239528311, 4.3911297582], [-1.8947423704, 5.0239528402, 4.3911297974], [1.2815623988, 4.0920788845, 4.3911297010], [-0.5832276472, 6.9252141027, 4.3911296965], [-1.8947423652, 5.0239528577, 4.3911297880], [-0.6277181725, 0.8677595603, 4.3911297885], [1.2815623937, 4.0920788670, 4.3911297104], [1.2815623604, 4.0920788867, 4.3911296780], [-0.6277181392, 0.8677595406, 4.3911298209], [1.2445836010, -0.0789270558, 4.3911299388]], 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]]);
/***********************************************
****** 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()
***********************************************/