forked from TEXflip/log-carving-approximator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.py
72 lines (59 loc) · 2.4 KB
/
sandbox.py
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
from inspyred import ec, swarm
from planeProblem import PlaneCutProblem
from wedgeProblem import BlenderWedgeProblem, taglio
from wedgeProblem2 import BlenderWedgeProblem2
import matplotlib.pylab as plt
import numpy as np
import os
import sys
import plot_utils
from inspyred_utils import NumpyRandomWrapper
import time
### Choose the algorithm between EC and PSO
algorithms_list = {"ec" : 0, "pso" : 1, "es" : 2}
ALGORITHM = algorithms_list["ec"]
REGENERATION = False
args = {}
# --- Global Params
args["initial_pop_storage"] = {}
args["max_generations"] = 10
args["slice_application_generation"] = 10 # number of generations before appling the best slice, only if REGENERATION = False
args["pop_size"] = args["num_selected"] = 10 # population size
args["num_offspring"] = 10
args["num_evolutions"] = 5 # only if REGENERATION = True
args["fig_title"] = 'Model Sculpting Approximation'
# --- Evolutionary Computation params ---
args["num_elites"] = 1
args["gaussian_stdev"] = 0.25
args["crossover_rate"] = 0.2
args["mutation_rate"] = 0.8
args["tournament_size"] = 3
# --- Particle Swarm Optimization params ---
args["inertia"] = 1
args["cognitive_rate"] = 1.8
args["social_rate"] = 2.
# --- Evolutionary Strategies params ---
args["tau"] = None
args["tau_prime"] = None
args["epsilon"] = 0.00001
if __name__ == "__main__":
rng = NumpyRandomWrapper(42) # in sostanza, è una sorta di random.seed()
# problem = PlaneCutProblem('3D models/bulbasaur.stl', '3D models/cylinder.stl', rng)
# problem = BlenderWedgeProblem('3D models/diamond.stl', '3D models/cylinder.stl', rng)
problem = BlenderWedgeProblem2('3D models/bulbasaur.stl', '3D models/cylinder.stl', rng)
pop = []
for i in range(10):
pop.append(problem.generator(rng, args))
fit = problem.evaluator(pop, args)
print(fit)
cuts_string = '"' + ';'.join(','.join('%0.7f' %x for x in y) for y in pop) + '"'
if isinstance(problem, PlaneCutProblem):
problem.SaveCarvingMesh("finalModel.stl")
command = 'blender -P templates/stlImporter.py -- "finalModel.stl" "' + problem.targetMeshPath + '" plane ' + cuts_string
# print(command)
os.system(command)
else:
problem.SaveCarvingMesh("finalModel3.stl", problem.carvingMesh)
command = 'blender -P templates/stlImporter.py -- "finalModel3.stl" "' + problem.targetMeshPath + '" wedge ' + cuts_string
# print(command)
os.system(command)