-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnomalyVisualizer.cpp
More file actions
143 lines (115 loc) · 4.31 KB
/
AnomalyVisualizer.cpp
File metadata and controls
143 lines (115 loc) · 4.31 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
#include "AnomalyVisualizer.h"
#include <fstream>
#include <sstream>
#include <math.h>
AnomalyVisualizer::AnomalyVisualizer(const std::string& csvFilename) : currentAnomaly(0) {
loadAnomalies(csvFilename);
}
void AnomalyVisualizer::loadAnomalies(const std::string& csvFilename) {
std::ifstream file(csvFilename);
std::string line;
// Skip header
std::getline(file, line);
while (std::getline(file, line)) {
std::istringstream iss(line);
Anomaly anomaly;
std::string waveDataStr;
if (std::getline(iss, anomaly.particle1, ',') &&
std::getline(iss, anomaly.particle2, ',') &&
std::getline(iss, anomaly.interactionInfo, ',') &&
std::getline(iss, waveDataStr)) {
// Parse wave data
std::istringstream waveStream(waveDataStr);
float value;
while (waveStream >> value) {
anomaly.waveData.push_back(value);
if (waveStream.peek() == ',')
waveStream.ignore();
}
anomalies.push_back(anomaly);
}
}
}
void AnomalyVisualizer::render(sf::RenderWindow& window)
{
// Clear the window with a white background
window.clear(sf::Color::White);
// Render the coil
renderCoil(window);
// Render the wave graphs
renderWaveGraphs(window);
// Render the text information
renderText(window);
// No need to call window.display() here, it will be called in the main loop
}
void AnomalyVisualizer::renderCoil(sf::RenderWindow& window) {
// OpenGL rendering code for the coil
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(5, 5, 5, 0, 0, 0, 0, 1, 0);
// Render coil rings
glColor3f(0.5f, 0.5f, 0.5f);
for (int i = 0; i < 10; ++i) {
glPushMatrix();
glTranslatef(0, i * 0.5f, 0);
glutSolidTorus(0.1, 1.0, 20, 20);
glPopMatrix();
}
}
void AnomalyVisualizer::renderWaveGraphs(sf::RenderWindow& window) {
if (currentAnomaly >= anomalies.size()) return;
const auto& anomaly = anomalies[currentAnomaly];
// Render normal wave
sf::VertexArray normalWave(sf::LineStrip, 360);
for (int i = 0; i < 360; ++i) {
float x = i * 2.0f;
float y = 200 + std::sin(i * 0.1f) * 50;
normalWave[i].position = sf::Vector2f(x, y);
normalWave[i].color = sf::Color::Blue;
}
window.draw(normalWave);
// Render anomalous wave
sf::VertexArray anomalousWave(sf::LineStrip, anomaly.waveData.size());
for (size_t i = 0; i < anomaly.waveData.size(); ++i) {
float x = i * (720.0f / anomaly.waveData.size());
float y = 400 + anomaly.waveData[i] * 50;
anomalousWave[i].position = sf::Vector2f(x, y);
anomalousWave[i].color = sf::Color::Red;
}
window.draw(anomalousWave);
// Highlight breach points
sf::CircleShape breachPoint(5);
breachPoint.setFillColor(sf::Color::Yellow);
for (const auto& point : anomaly.breachPoints) {
float x = point.first * (720.0f / anomaly.waveData.size());
float y = 400 + point.second * 50;
breachPoint.setPosition(x - 5, y - 5);
window.draw(breachPoint);
}
}
void AnomalyVisualizer::renderText(sf::RenderWindow& window) {
if (currentAnomaly >= anomalies.size()) return;
const auto& anomaly = anomalies[currentAnomaly];
sf::Font font;
font.loadFromFile("/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf");
sf::Text text;
text.setFont(font);
text.setCharacterSize(20);
text.setFillColor(sf::Color::Black);
std::stringstream ss;
ss << "Anomaly " << (currentAnomaly + 1) << " of " << anomalies.size() << "\n";
ss << "Particles: " << anomaly.particle1 << " - " << anomaly.particle2 << "\n";
ss << "Interaction: " << anomaly.interactionInfo;
text.setString(ss.str());
text.setPosition(10, 10);
window.draw(text);
}
void AnomalyVisualizer::next() {
if (currentAnomaly < anomalies.size() - 1)
++currentAnomaly;
}
void AnomalyVisualizer::previous() {
if (currentAnomaly > 0)
--currentAnomaly;
}