-
Notifications
You must be signed in to change notification settings - Fork 2
/
unfold4.scad
107 lines (84 loc) · 7.57 KB
/
unfold4.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 = [[4.3062771141, 49.1156396182, 4.3911295692], [1.4023295368, 51.3504049016, 4.3911295545], [1.5468317669, 48.0888453190, 4.3911295607], [2.3122708861, 42.1852357328, 4.3911295011], [4.3062771137, 49.1156396194, 4.3911295638], [1.5468317673, 48.0888453178, 4.3911295661], [4.3062771209, 49.1156396173, 4.3911295183], [2.3122708789, 42.1852357348, 4.3911295466], [4.7141697483, 42.4435640455, 4.3911296027], [4.7141697463, 42.4435640454, 4.3911295235], [7.1373273037, 47.2558836103, 4.3911296288], [4.3062771229, 49.1156396174, 4.3911295975], [8.9279597055, 44.1238085379, 4.3911296348], [7.1373272744, 47.2558836250, 4.3911296619], [4.7141697755, 42.4435640306, 4.3911294904], [4.3062771129, 49.1156396165, 4.3911295633], [2.9042694944, 53.5830700038, 4.3911295478], [1.4023295380, 51.3504049032, 4.3911295605], [4.3062771133, 49.1156396167, 4.3911295415], [7.0921657177, 51.6377775573, 4.3911295335], [2.9042694940, 53.5830700037, 4.3911295696], [7.4468559076, 47.8466627371, 4.3911294846], [7.0921657229, 51.6377775515, 4.3911294921], [4.3062771080, 49.1156396224, 4.3911295829], [7.0921657218, 51.6377775514, 4.3911294902], [7.4468559087, 47.8466627372, 4.3911294865], [10.3747444182, 49.9121871020, 4.3911295134], [10.3747444154, 49.9121870966, 4.3911295604], [10.7843895959, 52.4998770120, 4.3911295345], [7.0921657246, 51.6377775567, 4.3911294433], [10.7123279336, 46.3127294487, 4.3911293837], [10.3747444160, 49.9121871051, 4.3911295105], [7.4468559109, 47.8466627340, 4.3911294895], [12.5333460586, 48.1968026066, 4.3911294527], [10.3747444075, 49.9121871043, 4.3911294314], [10.7123279421, 46.3127294495, 4.3911294628], [15.1220157974, 45.7058601219, 4.3911294747], [12.5333460715, 48.1968025942, 4.3911293860], [10.7123279292, 46.3127294620, 4.3911295294], [15.1220157968, 45.7058601174, 4.3911294643], [10.7123279298, 46.3127294665, 4.3911295398], [12.2977309494, 43.5761297243, 4.3911294714], [10.7123279311, 46.3127294673, 4.3911294761], [9.9329242302, 41.8437500481, 4.3911295063], [12.2977309481, 43.5761297235, 4.3911295351], [13.2786003037, 39.6919869398, 4.3911293500], [15.1220157650, 45.7058601595, 4.3911295529], [12.2977309812, 43.5761296821, 4.3911293828], [13.2786003038, 39.6919869398, 4.3911293830], [12.2977309812, 43.5761296821, 4.3911293498], [11.1697492389, 40.8703751955, 4.3911294219], [13.2786002799, 39.6919869471, 4.3911294258], [19.0730032516, 43.0965353561, 4.3911295175], [15.1220157888, 45.7058601522, 4.3911294771], [12.5333460562, 48.1968026036, 4.3911294278], [14.9058770392, 50.8526234981, 4.3911293508], [10.3747444099, 49.9121871073, 4.3911294564], [10.3747444097, 49.9121871084, 4.3911293415], [14.9058770394, 50.8526234970, 4.3911294656], [13.0670596243, 53.0764468651, 4.3911293405], [18.8160331456, 55.9659768660, 4.3911293847], [13.0670596435, 53.0764468809, 4.3911293923], [14.9058770202, 50.8526234812, 4.3911294138], [1.4023295368, 51.3504049040, 4.3911295718], [2.9042694956, 53.5830700030, 4.3911295365], [-3.1015879555, 52.3622030274, 4.3911295541], [-3.1015879611, 52.3622030023, 4.3911295407], [-2.8155365365, 48.1342323728, 4.3911295444], [1.4023295425, 51.3504049292, 4.3911295851], [-4.4181405723, 49.8419880660, 4.3911295499], [-2.8155365436, 48.1342323723, 4.3911295625], [-3.1015879540, 52.3622030027, 4.3911295226]], 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]]);
/***********************************************
****** 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()
***********************************************/