10
C++ (Fach) / bv1 (Lektion)
-
Diese Lektion wurde von Missunderstand erstellt.
Diese Lektion ist leider nicht zum lernen freigegeben.
- Schreiben Sie ein Programm, das für ein Grauwertbild f • den Mittelwert von f, • die Standardabweichung von f und • die Varianz von f #include <iostream>#include <cmath> // für sqrt()#include <cstdlib> // für random()/srandom()#include "SimpleImage/SimpleGrayImage.h" using namespace std;void statistik (const SimpleGrayImage &img){ int N = img.width() * img.height(); double sum = 0.0; double sumsq = 0.0; for(int i = 0; i < img.height(); i++) for(int j = 0; j < img.width(); j++){ int val = img[i][j]; sum += val; sumsq += val * val;} double mu = sum / N;double var = sumsq / N - mu*mu;double std_dev = sqrt(var);cout << mu << " | " << std_dev << " | " << var << endl;}
- Schreiben Sie zunächst eine C++-Funktion wuerzen die als (Referenz-)Parameter ein Eingabe- bild, ein Ausgabebild und eine Häufigkeit h (als float-Wert zwischen 0 und 1) übergeben bekommt. void wuerzen (const SimpleGrayImage &in, SimpleGrayImage &out, float ant) { if(ant<0 || ant>1.0) throw "wuerzen: Salz- und Pfeffer-Anteil muss zwischen 0.0 und 1.0 liegen"; int limit = int(ant * RAND_MAX); out.resize(in.width(), in.height()); for (int i = 0; i < in.height(); i++) { for (int j = 0; j < in.width(); j++) { int rnd = random(); if(rnd > limit) out[i][j] = in[i][j]; else out[i][j] = (rnd &0x01) * 255; //nehme kleinstes bit für SW Entscheidung } }}
- Schreiben Sie nun eine Funktion float ssd(const SimpleGrayImage &in1, const SimpleGrayImage &in2) die zwei Bilder im1 und im2 miteinander entsprechend der Formel für die Sum of Squared Differences vergleicht und das Ergebnis zurückgibt. float ssd(const SimpleGrayImage &in1, const SimpleGrayImage &in2){if(in1.height() != in2.height() || in1.width() != in2.width) throw:"ssd Bilder müssen die gleiche größe haben";float sum = 0.0;for(int i = 0; i <in1.height; i++) for(int j = 0; j < in1.width; j++) float dif = im1[i][j] - in2 [i][j]; sum += dif * dif; } } return sum;}
- shader Initialisieren //load, compile and link Shaderconst char *shadernames[2] = {SHADERS_PATH "Phong.vert", SHADERS_PATH "Phong.frag"}; CVK::ShaderPhong phongShader( VERTEX_SHADER_BIT|FRAGMENT_SHADER_BIT, shadernames); CVK::State::getInstance()->setShader( &phongShader);
- Phong Shader in vec3 passPosition;in vec3 passNormal; //Weitere in Variable zum durchreichenin vec2 passTcoord;//Uniform Variable für Texturuniform sampler2D colortexture;//Zugriff auf die Textur diffuse_color = texture( colortexture, passTcoord ).rgb; //Verwendung der Beleuchtungsgleichung fragmentColor.rgb = diffuse_color * light_ambient;fragmentColor.rgb += spot * diffuse_color * cos_phi * light.col;fragmentColor.rgb += spot * mat.specular * cos_psi_n * light.col;
- Textur //Uniform Location suchenm_c_textureID = glGetUniformLocation( m_ProgramID, "colortexture"); //Statt der Textur eine Textur Unit übergebenglUniform1i( m_c_textureID, 0); //mehrere Texturen auf einen Shader übergeben -> eine von den Texture Units aktivieren und Textur gebunden werdenglActiveTexture( GL_TEXTURE0); glBindTexture( GL_TEXTURE_2D, m_textureID);
- Shader bekommen die üblichen Matrizen /Matrices ProjmatrixID = glGetUniformLocation( Shaders.getProgramID(), "ProjectionMatrix");ViewmatrixID = glGetUniformLocation( Shaders.getProgramID(), "ViewMatrix");ModelmatrixID = glGetUniformLocation( Shaders.getProgramID(), "ModelMatrix");
- Vertex Shader #version 330 //Vertex Shader layout (location = 0) in vec4 Position; uniform mat4 Projmatrix; uniform mat4 Viewmatrix; uniform mat4 Modelmatrix; void main(){ gl_position = Projectionmatrix * Viewmatrix * Modelmatrix * Position; }
- Pseudocode Sutherland Polygon SutherlandHodgman(Polygon poly, Edge clipedge) { A ist letzter Punkt des Polygons; Schleife über alle Ecken B des Polygons { if B innerhalb von clipedge If A innerhalb von clipedge Output (B); else{ S = Schnittpunkt (A,B,edge); Output(S), Output(B); } else if A innerhalb von clipedge { S = Schnittpunkt (A,B,edge); Output(S); } A = B; } Ergebnis von Output zurückgeben. }
- Sutherland Pseudocode Polygon SutherlandHodgman(Polygon poly, Edge clipedge){ A ist letzter Punkt des Polygons;Schleife über alle Ecken B des Polygons{if B innerhalb von clipedge If A innerhalb von clipedge Output (B); else{ S = Schnittpunkt (A,B,edge); Output(S), Output(B); } else if A innerhalb von clipedge{ S = Schnittpunkt (A,B,edge);Output(S);}A = B;} Ergebnis von Output zurückgeben.}
Anzeige