Skip to content

Commit f414bf7

Browse files
author
BuildTools
committed
Added comments to visualization code
1 parent 5e7c3f6 commit f414bf7

12 files changed

+57
-26
lines changed

SphWaterfall/SphWaterfall/src/data/ParticleIO.h

+5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
using namespace std;
1414
class ParticleIO {
1515
public:
16+
//Exportiert die Partikel als Datei
1617
static void exportParticles(unordered_map<int, vector<SphParticle>>& frames, string fileName);
18+
19+
//Exportiert die Partikel im VTK-Format
1720
static void exportParticlesToVTK(vector<SphParticle>& particles, string fileName, int timestep, vector<int> proc_boundaries = {});
21+
22+
//Importiert die Partikel aus Datei
1823
static vector<vector<SphParticle>> importParticles(string fileName);
1924
};

SphWaterfall/SphWaterfall/src/visualization/Camera.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void Camera::debugRenderFrame(std::vector<DebugObject> particles) {
4242
Vector3 vec_u = findSkalarVectorWithYZero(this->direction).normalize();
4343
Vector3 vec_v = findUpVector(this->direction, vec_u).normalize();
4444

45+
//Cast a ray for every pixel in the frame
4546
for (int x = 0; x < this->width; x++) {
4647
for (int y = 0; y < this->height; y++) {
4748
double u = l + (r - l) * (x + 0.5f) / this->width;
@@ -167,7 +168,7 @@ Frame Camera::renderFrame(std::vector<ParticleObject> particles, int frameID) {
167168
}
168169
}
169170

170-
return frame;// Shader::applyGaussianSmoothing(frame, 5, 8);
171+
return Shader::applyGaussianSmoothing(frame, 5, 8);
171172
}
172173

173174
void Camera::renderGeometryFrames(Terrain terrain, Terrain gate) {
@@ -221,6 +222,7 @@ Pixel Camera::castTerrainRay(Ray& ray, Terrain& terrain) {
221222

222223
Pixel initColor = Pixel(200, 200, 200); //Make the background gray
223224

225+
//Iterate over all faces and find best hit
224226
for (int i = 0; i < terrain.getFaceCount(); i++) {
225227
double currDist = bestDistance;
226228

@@ -271,6 +273,7 @@ Pixel Camera::castTerrainGateRay(Ray& ray, Terrain& terrain, Terrain& gate) {
271273

272274
Pixel initColor = Pixel(200, 200, 200); //Make the background gray
273275

276+
//Iterate over all faces and find best hit
274277
for (int i = 0; i <= terrain.getFaceCount() + gate.getFaceCount(); i++) {
275278
double currDist = bestDistance;
276279

@@ -355,7 +358,6 @@ void Camera::shareBaseFrame(int rank)
355358
else {
356359
this->baseFrameOpen = Frame::MpiReceiveFrame(0);
357360
this->baseFrameClosed = Frame::MpiReceiveFrame(0);
358-
cout << this->baseFrameOpen.getPixel(400, 300).getBaseDepth() << endl;
359361
std::cout << "Base Frames passed to processor " << rank << std::endl;
360362
}
361363
}

SphWaterfall/SphWaterfall/src/visualization/Camera.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,39 @@ class Camera {
1717
Camera();
1818
Camera(Vector3 location, Vector3 direction, unsigned int width, unsigned int height, int switch_frame);
1919

20-
//Renders a frame based on debug object # Green on Black
20+
//Rendert einen Frame basierend auf DebugObject
2121
void debugRenderFrame(std::vector<DebugObject> particles);
2222

23-
//Renders a frame based on Particle Objects # Uses Geometry Frames as base # Color, Shader, Gate Switch included
23+
//Rendert einen Frame basierend auf ParticleObject
2424
Frame renderFrame(std::vector<ParticleObject> particles, int frameID);
2525

26-
//Renders
26+
//Rendert die Geometrie als Basis Frames für weitere Operationen
2727
void renderGeometryFrames(Terrain terrain, Terrain gate);
2828

29+
//Schreibt einen Frame als bmp Datei
2930
void outputDebugFrame(Frame f, const char* fileName);
31+
32+
//Definiert den Frame ab wann das offene Terrain als Basis Frame genommen wird
3033
void setGateSwitchFrame(unsigned int frameID);
34+
35+
//Verteilt die Basis Frames auf alle Prozessoren
3136
void shareBaseFrame(int);
3237

3338
Vector3 getLocation();
3439
Vector3 getDirection();
3540

3641
private:
3742

43+
//Rendert einen Pixel basierend auf DebugObject
3844
Pixel castDebugRay(Ray& ray, std::vector<DebugObject> particles);
45+
//Rendert ein einzelnes Terrain
3946
Pixel castTerrainRay(Ray& ray, Terrain& terrain);
47+
//Rendert zwei Terrain Modelle in einen Frame; wird für das Gatter genutzt
4048
Pixel castTerrainGateRay(Ray& ray, Terrain& terrain, Terrain& gate);
41-
49+
//Rendert ParticleObjects; arbeitet mit Wassertiefe
4250
Pixel castVolumeRay(Ray& ray, std::vector<ParticleObject> particles, Pixel basePixel);
4351

52+
//Gibt einen Verweiß auf den aktuell genutzten Basis Frame zurueck
4453
Frame& getCurrentlyUsedBaseFrame(unsigned int frameID);
4554

4655
Frame baseFrameOpen;

SphWaterfall/SphWaterfall/src/visualization/DebugObject.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DebugObject {
1212
Vector3 getLocation();
1313
double getRadius();
1414

15+
//Berechnet einen Schnittpunkt zwischen dem DebugObject und einem Ray
1516
bool intersects(Ray &ray, double &distance, double &highestDistance);
1617

1718
private:

SphWaterfall/SphWaterfall/src/visualization/Frame.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Pixel.h"
44
#include <vector>
55

6+
//Frame Klasse; enthält einen Array von Pixel um ein Bild der Größe N x M zu halten
67
class Frame {
78
public:
89
Frame(); //To genereate placeholder
@@ -14,6 +15,7 @@ class Frame {
1415
unsigned int getWidth();
1516
unsigned int getHeight();
1617

18+
//MPI Funktionalitaet zum Verteilen auf Prozessoren
1719
static void MpiSendFrame(Frame frame, int dest);
1820
static Frame MpiReceiveFrame(int source);
1921

SphWaterfall/SphWaterfall/src/visualization/ParticleObject.h

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Pixel.h"
77
#include "../data/Vector3.h"
88

9+
//Simple Klasse welche Daten für eine Kugel im Raum beinhaltet
910
class ParticleObject {
1011
public:
1112
ParticleObject(Vector3 location, double radius);
@@ -14,8 +15,10 @@ class ParticleObject {
1415
Vector3 getLocation();
1516
double getRadius();
1617

18+
//Berechnet einen Schnittpunkt zwischen dem ParticleObject und einem Ray
1719
bool intersects(Ray &ray, double &distance, double &waterDepth, double maxDepth);
1820

21+
//MPI Funktionalitaet zum Verteilen über Prozessoren
1922
static void MpiSendPObject(ParticleObject pObj, int dest);
2023
static ParticleObject MpiReceivePObject(int source);
2124

SphWaterfall/SphWaterfall/src/visualization/Pixel.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <limits>
44

5+
//Pixel Klasse; enthält RGB-Farbwerte
56
class Pixel {
67
public:
78
Pixel();
@@ -16,9 +17,11 @@ class Pixel {
1617
void setGreen(unsigned short green);
1718
void setBlue(unsigned short blue);
1819

20+
//Shader Funktionalitaet; Kontrolliert ob der Pixel im Shader miteinbezogen wird
1921
bool usesShader();
2022
void setShaderUsage(bool shaderUsage);
2123

24+
//Setzt die Geometrie Tiefe für den Pixel; Wird bentuzt um das zu unterscheiden ob WasserPartikel hinter oder vor dem Terrain liegen
2225
void setBaseDepth(double baseDepth);
2326
double getBaseDepth();
2427

SphWaterfall/SphWaterfall/src/visualization/Ray.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include "../data/Vector3.h"
33

4+
//Ray Klasse; enthält einen Ursprung und eine Richtung
45
class Ray {
56
public:
67
Ray(Vector3 direction, Vector3 origin);

SphWaterfall/SphWaterfall/src/visualization/Shader.h

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include <iostream>
33
#include "Frame.h"
44

5+
//Shader Klasse
56
class Shader {
67
public:
8+
//Führt einen Gausschen Weichzeichner angegeben oft durch, mit angegebener Matrix Größe
79
static Frame applyGaussianSmoothing(Frame f, int shaderDepth, int matrixSize);
810
};

SphWaterfall/SphWaterfall/src/visualization/VisualizationManager.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void VisualizationManager::renderFramesDistributed(string inputFileName, int ran
5656
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
5757

5858
if (rank == 0) {
59+
//Send frame count
5960
vector<vector<SphParticle>> frameParticles = ParticleIO::importParticles(inputFileName);
6061
for (int i = 1; i < world_size; i++) {
6162
unsigned int buf[1] =
@@ -65,6 +66,7 @@ void VisualizationManager::renderFramesDistributed(string inputFileName, int ran
6566
MPI_Send(buf, 1, MPI_UNSIGNED, i, 0, MPI_COMM_WORLD);
6667
}
6768

69+
//Send Frames distributed to all other processors
6870
for (int g = 0; g < frameParticles.size(); g++) {
6971
int target = (g % (world_size - 1)) + 1;
7072
vector<ParticleObject> frame = convertFluidParticles(frameParticles.at(g));
@@ -82,13 +84,14 @@ void VisualizationManager::renderFramesDistributed(string inputFileName, int ran
8284
}
8385
}
8486
else {
87+
//Receive Frame count
8588
unsigned int buf[1];
8689
MPI_Recv(buf, 1, MPI_UNSIGNED, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
8790
int frameCount = buf[0];
8891

8992
vector<vector<ParticleObject>> frameParticles;
9093

91-
94+
//Receive Frames from master
9295
for (int g = 0; g < frameCount; g++) {
9396
if ((g % (world_size - 1)) + 1 == rank) {
9497
unsigned int frameSize[1];
@@ -103,6 +106,7 @@ void VisualizationManager::renderFramesDistributed(string inputFileName, int ran
103106

104107
int counter = 0;
105108

109+
//Render frames and save to disk
106110
for (int i = 0; i < frameCount; i++) {
107111
if ((i % (world_size - 1)) + 1 == rank) {
108112
if (counter >= frameParticles.size()) continue;
@@ -146,19 +150,6 @@ vector<SphParticle> VisualizationManager::generateDebugParticles(int count) {
146150
return particles;
147151
}
148152

149-
void VisualizationManager::debug() {
150-
unordered_map<int, vector<SphParticle>> frames;
151-
152-
vector<SphParticle> part;
153-
part.emplace_back(SphParticle(Vector3(3, 0, 0)));
154-
155-
for (int i = 1; i <= 1; i++) {
156-
frames.insert_or_assign(i, part);
157-
}
158-
159-
ParticleIO::exportParticles(frames, "test.particles");
160-
}
161-
162153
bool VisualizationManager::initilaized = false;
163154
Camera VisualizationManager::camera = Camera();
164155
Terrain VisualizationManager::terrain = Terrain();

SphWaterfall/SphWaterfall/src/visualization/VisualizationManager.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@
99

1010
class VisualizationManager {
1111
public:
12+
//Initialisiert den VisualizationManager; erstellt eine Kamera
1213
static void init(Vector3 cameraLocation, unsigned int frameWidth, unsigned int frameHeight, int rank);
1314

15+
//Importiert das Terrain unf lässt es auf der Kamera rendern
1416
static void importTerrain(Terrain t, bool isGate);
1517

18+
//Setzt den Frame ab welchem die offene Geometrie verwendet werden soll
1619
static void setSwitchFrame(int switch_frame);
1720

21+
//Rendert Frames als Debug
1822
static void debugRenderFrame(std::vector<SphParticle> particles, string fileName);
1923

24+
//Rendert Frames
2025
static void renderFrames(string inputFileName);
2126

27+
//Rendert Frames mit MPI
2228
static void renderFramesDistributed(string inputFileName, int rank);
2329

30+
//Generiert Test Frames mit zufaelligen Partikeln
2431
static void generateFrames(int frameCount, int particleCount);
2532

26-
static void debug();
27-
2833
private:
2934
static vector<SphParticle> generateDebugParticles(int count);
3035

SphWaterfall/SphWaterfall/src/visualization/util.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const int bytesPerPixel = 3; /// red, green, blue
1717
const int fileHeaderSize = 14;
1818
const int infoHeaderSize = 40;
1919

20-
20+
//Entscheidet ob der berechnete Skalar Vektor tatsächlich nach rechts von der Kamera ViewDirection geht
2121
static Vector3 findRightSkalar(Vector3 vec, Vector3 right) {
2222
Vector3 left = right * -1;
2323

@@ -31,6 +31,7 @@ static Vector3 findRightSkalar(Vector3 vec, Vector3 right) {
3131
return right;
3232
}
3333

34+
//Findet den entsprechenden Vektor um die Vektoren nach Rechts und oben finden zu können
3435
static Vector3 findSkalarVectorWithYZero(Vector3 vector) {
3536
double x = 1;
3637
double y = 0;
@@ -39,6 +40,7 @@ static Vector3 findSkalarVectorWithYZero(Vector3 vector) {
3940
return findRightSkalar(vector, Vector3(x, y, z));
4041
}
4142

43+
//Berechnet den Vektor der für die Kamera nach oben zeigt
4244
static Vector3 findUpVector(Vector3 first, Vector3 second) {
4345
Vector3 up = Vector3(first.y * second.z - first.z * second.y,
4446
first.z * second.x - first.x * second.z,
@@ -48,6 +50,7 @@ static Vector3 findUpVector(Vector3 first, Vector3 second) {
4850
return up*-1;
4951
}
5052

53+
//Konvertiert SphParticle zu DebugObject
5154
static std::vector<DebugObject> convertSphParticles(std::vector<SphParticle> &particles) {
5255
std::vector<DebugObject> output;
5356
for (unsigned int i = 0; i < particles.size(); i++) {
@@ -57,6 +60,7 @@ static std::vector<DebugObject> convertSphParticles(std::vector<SphParticle> &pa
5760
return output;
5861
}
5962

63+
//Konvertiert SphParticle zu ParticleObject
6064
static std::vector<ParticleObject> convertFluidParticles(std::vector<SphParticle> &particles) {
6165
std::vector<ParticleObject> output;
6266
for (unsigned int i = 0; i < particles.size(); i++) {
@@ -66,6 +70,7 @@ static std::vector<ParticleObject> convertFluidParticles(std::vector<SphParticle
6670
return output;
6771
}
6872

73+
//Schreibt einen Frame als bmp
6974
static void writeFrameToBitmap(Frame f, const char* fileName, unsigned int w, unsigned int h) {
7075
FILE *file;
7176
unsigned char *img = NULL;
@@ -122,6 +127,7 @@ static void writeFrameToBitmap(Frame f, const char* fileName, unsigned int w, un
122127
fclose(file);
123128
}
124129

130+
//String Operationen welche nicht in std enthalten sind; Heutige Ausgabe: Split
125131
static vector<string> split(const string &s, const char &c)
126132
{
127133
string buff{ "" };
@@ -137,6 +143,7 @@ static vector<string> split(const string &s, const char &c)
137143
return v;
138144
}
139145

146+
//String Operationen welche nicht in std enthalten sind; Heutige Ausgabe: StartsWith
140147
static bool startsWith(const string &s, const string &sequence) {
141148
if (s.size() < sequence.size()) return false;
142149

@@ -147,6 +154,7 @@ static bool startsWith(const string &s, const string &sequence) {
147154
return true;
148155
}
149156

157+
//Berechnet Schnittpunkt zwischen Ray und Face
150158
static bool intersectsWithFace(Ray &ray, const Face& face, double &distance) {
151159
Vector3 vertex0 = face.a;
152160
Vector3 vertex1 = face.b;
@@ -168,13 +176,12 @@ static bool intersectsWithFace(Ray &ray, const Face& face, double &distance) {
168176
v = f * ray.direction.dot(q);
169177
if (v < 0.0 || u + v > 1.0)
170178
return false;
171-
// At this stage we can compute t to find out where the intersection point is on the line.
172179
float t = f * edge2.dot(q);
173-
if (t > EPSILON) // ray intersection
180+
if (t > EPSILON)
174181
{
175182
distance = t;
176183
return true;
177184
}
178-
else // This means that there is a line intersection but not a ray intersection.
185+
else
179186
return false;
180187
}

0 commit comments

Comments
 (0)