-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fixed_viewer.py
More file actions
178 lines (142 loc) · 6.05 KB
/
Copy pathtest_fixed_viewer.py
File metadata and controls
178 lines (142 loc) · 6.05 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
"""
Test script for the fixed 3D TIFF Viewer
This script tests the OpenGL canvas and basic functionality.
"""
import tkinter as tk
import numpy as np
import sys
import traceback
def test_opengl_canvas_basic():
"""Test basic OpenGL canvas functionality"""
print("=== Testing Basic OpenGL Canvas ===")
try:
from opengl_canvas import VoxelOpenGLCanvas
root = tk.Tk()
root.title("OpenGL Canvas Test")
root.geometry("600x500")
# Create canvas
canvas = VoxelOpenGLCanvas(root, width=500, height=400)
canvas.pack(padx=10, pady=10, expand=True, fill='both')
# Create test data - a simple 3D cube of points
print("Creating test data...")
n = 10 # Points per dimension
x, y, z = np.meshgrid(np.linspace(-1, 1, n),
np.linspace(-1, 1, n),
np.linspace(-1, 1, n))
points = np.column_stack((x.flatten(), y.flatten(), z.flatten())).astype(np.float32)
# Create rainbow colors
colors = np.zeros((len(points), 3), dtype=np.float32)
colors[:, 0] = (points[:, 0] + 1) / 2 # Red based on X
colors[:, 1] = (points[:, 1] + 1) / 2 # Green based on Y
colors[:, 2] = (points[:, 2] + 1) / 2 # Blue based on Z
print(f"Test data: {len(points)} points")
print(f"Points range: {points.min(axis=0)} to {points.max(axis=0)}")
print(f"Colors range: {colors.min(axis=0)} to {colors.max(axis=0)}")
# Set the data
canvas.set_points(points, colors)
# Add instructions
instructions = tk.Label(root,
text="OpenGL Canvas Test\n\n" +
"Controls:\n" +
"• Left Mouse: Rotate\n" +
"• Middle Mouse: Pan\n" +
"• Right Mouse/Wheel: Zoom\n" +
"• Double-click: Reset view\n" +
"• R: Reset, A: Toggle Axes, G: Toggle Grid",
justify=tk.LEFT,
bg="lightgray",
font=("Arial", 9))
instructions.pack(side=tk.BOTTOM, fill=tk.X, padx=5, pady=5)
print("✓ OpenGL canvas test setup complete")
print("If you see a colorful 3D cube, the canvas is working!")
# Auto-close after 10 seconds for automated testing
root.after(10000, root.destroy)
root.mainloop()
return True
except Exception as e:
print(f"✗ OpenGL canvas test failed: {e}")
traceback.print_exc()
return False
def test_tiff_viewer_startup():
"""Test TIFF viewer startup without loading a file"""
print("\n=== Testing TIFF Viewer Startup ===")
try:
from tiff_viewer_3d import TIFFViewer3D
print("Creating TIFFViewer3D instance...")
# This will create the UI but we'll close it quickly
def close_after_delay():
print("✓ TIFF Viewer started successfully")
# Find the root window and close it
for widget in tk._default_root.winfo_children():
if isinstance(widget, tk.Toplevel):
widget.destroy()
break
else:
tk._default_root.destroy()
# Schedule close after 3 seconds
tk._default_root.after(3000, close_after_delay)
# This will start the viewer
viewer = TIFFViewer3D()
return True
except Exception as e:
print(f"✗ TIFF Viewer startup test failed: {e}")
traceback.print_exc()
return False
def test_imports():
"""Test all required imports"""
print("=== Testing Imports ===")
imports_to_test = [
("tkinter", "tkinter"),
("numpy", "numpy"),
("OpenGL.GL", "PyOpenGL"),
("pyopengltk", "pyopengltk"),
("opengl_canvas", "opengl_canvas.py"),
("tiff_viewer_3d", "tiff_viewer_3d.py"),
("tiff_viewer_ui", "tiff_viewer_ui.py"),
("data_in_image", "data_in_image.py"),
("estimator", "estimator.py"),
]
all_passed = True
for module, description in imports_to_test:
try:
__import__(module)
print(f"✓ {description}")
except ImportError as e:
print(f"✗ {description}: {e}")
all_passed = False
except Exception as e:
print(f"⚠ {description}: {e}")
return all_passed
def main():
"""Run all tests"""
print("3D TIFF Viewer - Comprehensive Test Suite")
print("=" * 50)
# Test 1: Imports
imports_ok = test_imports()
if not imports_ok:
print("\n❌ Import tests failed. Please install missing dependencies:")
print("pip install -r requirements.txt")
return 1
# Test 2: Basic OpenGL Canvas
canvas_ok = test_opengl_canvas_basic()
if not canvas_ok:
print("\n❌ OpenGL canvas test failed.")
print("This might be due to:")
print("1. Missing OpenGL drivers")
print("2. Graphics card compatibility issues")
print("3. PyOpenGL installation problems")
return 1
# Test 3: TIFF Viewer Startup (commented out to avoid GUI conflicts)
# viewer_ok = test_tiff_viewer_startup()
print("\n" + "=" * 50)
print("✅ All tests completed successfully!")
print("\nYour 3D TIFF Viewer should now work properly.")
print("\nTo use the application:")
print("1. Run: python main.py")
print("2. Upload a TIFF file")
print("3. Select colors and apply")
print("4. Use mouse to interact with 3D view")
return 0
if __name__ == "__main__":
exit(main())