-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_to_brain.sh
90 lines (72 loc) · 3.05 KB
/
file_to_brain.sh
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
#!/bin/bash
# Define input and output file paths
input_file="/path/to/directory/coordinates_and_volume.txt"
output_file="/path/to/directory/cube_brain.obj"
# Check if the Python interpreter is available
if ! command -v python3 &>/dev/null; then
echo "Error: Python 3 is not installed. Please install Python 3 to run this script."
exit 1
fi
# Execute the Python script
python3 <<EOF
def create_cube_vertex(x, y, z, scale):
"""
Create vertices for a cube centered at (x, y, z)
"""
vertices = [
(x - scale / 2, y - scale / 2, z + scale / 2), # Front bottom left
(x + scale / 2, y - scale / 2, z + scale / 2), # Front bottom right
(x + scale / 2, y + scale / 2, z + scale / 2), # Front top right
(x - scale / 2, y + scale / 2, z + scale / 2), # Front top left
(x - scale / 2, y - scale / 2, z - scale / 2), # Back bottom left
(x + scale / 2, y - scale / 2, z - scale / 2), # Back bottom right
(x + scale / 2, y + scale / 2, z - scale / 2), # Back top right
(x - scale / 2, y + scale / 2, z - scale / 2) # Back top left
]
return vertices
def create_cube_faces(offset):
"""
Create faces for a cube with the given offset
"""
base_index = offset * 8 + 1 # Each cube has 8 vertices, starting from 1
return [
(base_index, base_index + 1, base_index + 2, base_index + 3), # Front face
(base_index + 4, base_index + 7, base_index + 6, base_index + 5), # Back face
(base_index, base_index + 4, base_index + 5, base_index + 1), # Bottom face
(base_index + 3, base_index + 2, base_index + 6, base_index + 7), # Top face
(base_index + 1, base_index + 5, base_index + 6, base_index + 2), # Left face
(base_index + 4, base_index, base_index + 3, base_index + 7) # Right face
]
with open('$input_file', 'r') as f:
lines = f.readlines()
with open('$output_file', 'w') as f:
# Write header
f.write("g Cubes\n")
# Initialize vertex offset
vertex_offset = 0
# Iterate through each line in the input file
for line in lines:
# Extract coordinates
parts = line.split(",")
# Define distance between points
distance = 10 # Adjust the distance as needed
# Calculate scaled coordinates
x = int(parts[1].split("(")[1]) / distance
y = int(parts[2]) / distance
z = int(parts[3].split(")")[0]) / distance
# Define scale factor
scale = 20 # Adjust the scale factor as needed
# Create vertices for the cube
vertices = create_cube_vertex(x, y, z, scale)
# Write vertices to file
for vertex in vertices:
f.write("v {} {} {}\n".format(vertex[0], vertex[1], vertex[2]))
# Create faces for the cube
faces = create_cube_faces(vertex_offset)
# Write faces to file
for face in faces:
f.write("f {} {} {} {}\n".format(face[0], face[1], face[2], face[3]))
# Update vertex offset for next cube
vertex_offset += 1
print("OBJ file created: $output_file")
EOF