Commit 776c1579 authored by Christoph Pflaum's avatar Christoph Pflaum
Browse files

interpolation operator , doku hinzu und was fuer Vektoren visualisierung

parent 7e315a51
......@@ -336,14 +336,84 @@ if(boxWSD.z < 0 && boxENT.z > 0.0 && boxWSD.y < 0.5 && boxENT.y > 0.5 && boxWSD.
}
}
}
///////////////////////////////////////////////////////////////////////////////////
// ColorMap
///////////////////////////////////////////////////////////////////////////////////
uint QImageMaker::colormap[ColormapSize];
uint ColorMap::colormap[ColormapSize];
void QImageMaker::makeColorMap() {
void ColorMap::makeColorMap() {
for(int i = 0; i < ColormapSize; ++i) {
colormap[i] = rgbFromWaveLength(380.0 + (i * 400.0 / ColormapSize));
}
}
QImage ColorMap::getImageColorMap(QSize resultSize) {
makeColorMap();
int widthI = resultSize.width();
int heightI = resultSize.height();
QImage image(resultSize, QImage::Format_RGB32);
for(int y = 0; y < heightI; ++y) {
uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y));
for(int x = 0; x < widthI; ++x) {
double coord_y = ((double)(heightI-1-y))/(heightI-1);
int valueIntU = coord_y * ColormapSize;
*scanLine++ = colormap[valueIntU % ColormapSize];
}
}
return image;
}
uint ColorMap::rgbFromWaveLength(double wave) {
double r = 0.0;
double g = 0.0;
double b = 0.0;qRgb(int(r * 255), int(g * 255), int(b * 255));
if (wave >= 380.0 && wave <= 440.0) {
r = -1.0 * (wave - 440.0) / (440.0 - 380.0);
b = 1.0;
} else if (wave >= 440.0 && wave <= 490.0) {
g = (wave - 440.0) / (490.0 - 440.0);
b = 1.0;
} else if (wave >= 490.0 && wave <= 510.0) {
g = 1.0;
b = -1.0 * (wave - 510.0) / (510.0 - 490.0);
} else if (wave >= 510.0 && wave <= 580.0) {
r = (wave - 510.0) / (580.0 - 510.0);
g = 1.0;
} else if (wave >= 580.0 && wave <= 645.0) {
r = 1.0;
g = -1.0 * (wave - 645.0) / (645.0 - 580.0);
} else if (wave >= 645.0 && wave <= 780.0) {
r = 1.0;
}
double s = 1.0;
if (wave > 700.0)
s = 0.3 + 0.7 * (780.0 - wave) / (780.0 - 700.0);
else if (wave < 420.0)
s = 0.3 + 0.7 * (wave - 380.0) / (420.0 - 380.0);
r = std::pow(r * s, 0.8);
g = std::pow(g * s, 0.8);
b = std::pow(b * s, 0.8);
return qRgb(int(r * 255), int(g * 255), int(b * 255));
}
///////////////////////////////////////////////////////////////////////////////////
// QImageMaker
///////////////////////////////////////////////////////////////////////////////////
QImageMaker::QImageMaker(Variable2D<double>& u_, int thicknessContourLines_) : Interpolate_on_structured_2Dgrid(u_.Give_blockgrid()) {
thicknessContourLines = thicknessContourLines_;
......@@ -498,11 +568,175 @@ QImage QImageMaker::makeImage(QSize resultSize, unsigned int numberContours, boo
}
///////////////////////////////////////////////////////////////////////////////////
// VectorOfArrowsCreator
///////////////////////////////////////////////////////////////////////////////////
VectorOfArrowsCreator::VectorOfArrowsCreator(Variable2D<double>& ux_, Variable2D<double>& uy_)
: Interpolate_on_structured_2Dgrid(ux_.Give_blockgrid()) {
ux = &ux_;
uy = &uy_;
//ug = u->Give_Ug();
bg = ux->Give_blockgrid();
maxU = Maximum(*ux);
minU = Minimum(*uy);
valueBackground = qRgb(255, 255, 255);
contourColor = qRgb(0, 0, 0 );
valueEmpty = qRgb(248, 248, 255);
makeColorMap();
dataX = new double[nx*ny];
dataY = new double[nx*ny];
interpolate(ux_,dataX,0.0);
interpolate(uy_,dataY,0.0);
}
VectorOfArrowsCreator::~VectorOfArrowsCreator() {
delete[] dataX;
delete[] dataY;
}
void VectorOfArrowsCreator::createVectorList(QVector<QPointF>& startP, QVector<QPointF>& endP,
QSize resultSize, unsigned int numberArrowX, unsigned int numberArrowY,
bool origionalSize) {
startP.resize(0);
endP.resize(0);
int widthI = resultSize.width();
int heightI = resultSize.height();
if(origionalSize) {
double ratioGiven = (double)widthI / (double)heightI;
double ratioHere = (pEN.x - pWS.x) / (pEN.y - pWS.y);
if(ratioHere >= ratioGiven) { //Das Bild ist zu breit
resultSize.setHeight(widthI / ratioHere);
heightI = resultSize.height();
}
else {
resultSize.setWidth(heightI * ratioHere);
widthI = resultSize.width();
}
}
double Phx = widthI / numberArrowX;
double Phy = heightI / numberArrowY;
double Ph = MIN(Phx,Phy) * 0.5;
double Ihx = (pEN.x - pWS.x) / numberArrowX;
double Ihy = (pEN.y - pWS.y) / numberArrowY;
for(int y = 0; y < numberArrowX; ++y) {
for(int x = 0; x < numberArrowY; ++x) {
double coord_x = (x+0.5)*Ihx;
double coord_y = (y+0.5)*Ihy;
if(bg->inStrechedDomain(pWS + D2vector(coord_x,coord_y))) {
int i = coord_x / hx;
int j = coord_y / hy;
if(i>=nx-1) i=nx-2;
if(j>=ny-1) j=ny-2;
double uWSx = dataX[i +nx*(j)];
double uESx = dataX[(i+1)+nx*(j)];
double uWNx = dataX[i +nx*(j+1)];
double uENx = dataX[(i+1)+nx*(j+1)];
double uWSy = dataY[i +nx*(j)];
double uESy = dataY[(i+1)+nx*(j)];
double uWNy = dataY[i +nx*(j+1)];
double uENy = dataY[(i+1)+nx*(j+1)];
bool WSin = bg->inStrechedDomain(pWS + D2vector(i*hx,j*hy));
bool ESin = bg->inStrechedDomain(pWS + D2vector((i+1)*hx,j*hy));
bool WNin = bg->inStrechedDomain(pWS + D2vector(i*hx,(j+1)*hy));
bool ENin = bg->inStrechedDomain(pWS + D2vector((i+1)*hx,(j+1)*hy));
if(WSin==false || ESin==false || WNin==false || ENin==false) {
double valueOkX, valueOkY;
if(WSin) { valueOkX=uWSx; valueOkY=uWSy; }
if(WNin) { valueOkX=uWNx; valueOkY=uWNy; }
if(ESin) { valueOkX=uESx; valueOkY=uESy; }
if(ENin) { valueOkX=uENx; valueOkY=uENy; }
if(WSin==false) { uWSx = valueOkX; uWSy = valueOkY; }
if(WNin==false) { uWNx = valueOkX; uWNy = valueOkY; }
if(ESin==false) { uESx = valueOkX; uESy = valueOkY; }
if(ENin==false) { uENx = valueOkX; uENy = valueOkY; }
}
double locX = coord_x / hx - i;
double locY = coord_y / hy - j;
double valueUx = uWSx * (1.0 - locX) * (1.0 - locY) +
uESx * locX * (1.0 - locY) +
uWNx * (1.0 - locX) * locY +
uENx * locX * locY;
//int valueIntUx = (valueUx - minU) / (maxU - minU) * ColormapSize;
double valueUy = uWSy * (1.0 - locX) * (1.0 - locY) +
uESy * locX * (1.0 - locY) +
uWNy * (1.0 - locX) * locY +
uENy * locX * locY;
//int valueIntUx = (valueUx - minU) / (maxU - minU) * ColormapSize;
double norm = sqrt(valueUx*valueUx + valueUy*valueUy);
if(norm>1.0e-10) {
valueUx = valueUx / norm * Ph;
valueUy = valueUy / norm * Ph;
QPointF A((x+0.5)*Phx, (y+0.5)*Phy);
QPointF B((x+0.5)*Phx + valueUx, (y+0.5)*Phy + valueUy);
startP.append(A);
endP.append(B);
}
}
}
}
}
/*
QImage VectorOfArrowsCreator::makeImage(QSize resultSize, unsigned int numberContours, bool showData, bool origionalSize) {
//double scaleFactor = this->scaleFactor;
//double centerX = this->centerX;
//double centerY = this->centerY;
std::vector<int> contourVals;
contourVals.resize(numberContours);
for(int i=0;i<numberContours;++i) {
contourVals.at(i) = ColormapSize * (i+1)/(numberContours+2) ;
}
QImage QImageMaker::getImageColorMap(QSize resultSize) {
makeColorMap();
int widthI = resultSize.width();
int heightI = resultSize.height();
if(origionalSize) {
double ratioGiven = (double)widthI / (double)heightI;
double ratioHere = (pEN.x - pWS.x) / (pEN.y - pWS.y);
if(ratioHere >= ratioGiven) { //Das Bild ist zu breit
resultSize.setHeight(widthI / ratioHere);
heightI = resultSize.height();
}
else {
resultSize.setWidth(heightI * ratioHere);
widthI = resultSize.width();
}
}
double Ihx = (pEN.x - pWS.x) / (widthI-1);
double Ihy = (pEN.y - pWS.y) / (heightI-1);
QImage image(resultSize, QImage::Format_RGB32);
......@@ -510,49 +744,78 @@ QImage QImageMaker::getImageColorMap(QSize resultSize) {
uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y));
for(int x = 0; x < widthI; ++x) {
double coord_y = ((double)(heightI-1-y))/(heightI-1);
int valueIntU = coord_y * ColormapSize;
*scanLine++ = colormap[valueIntU % ColormapSize];
double coord_x = x*Ihx;
double coord_y = y*Ihy;
if(bg->inStrechedDomain(pWS + D2vector(coord_x,coord_y))==false) {
// *scanLine++ = colormap[valueBackground % ColormapSize];
*scanLine++ = valueBackground;
}
else {
int i = coord_x / hx;
int j = coord_y / hy;
if(i>=nx-1) i=nx-2;
if(j>=ny-1) j=ny-2;
//cout << "i: " << i << " j: " << j << endl;
double uWS = data[i +nx*(j)];
double uES = data[(i+1)+nx*(j)];
double uWN = data[i +nx*(j+1)];
double uEN = data[(i+1)+nx*(j+1)];
bool WSin = bg->inStrechedDomain(pWS + D2vector(i*hx,j*hy));
bool ESin = bg->inStrechedDomain(pWS + D2vector((i+1)*hx,j*hy));
bool WNin = bg->inStrechedDomain(pWS + D2vector(i*hx,(j+1)*hy));
bool ENin = bg->inStrechedDomain(pWS + D2vector((i+1)*hx,(j+1)*hy));
if(WSin==false || ESin==false || WNin==false || ENin==false) {
double valueOk;
if(WSin) valueOk=uWS;
if(WNin) valueOk=uWN;
if(ESin) valueOk=uES;
if(ENin) valueOk=uEN;
if(WSin==false) uWS = valueOk;
if(WNin==false) uWN = valueOk;
if(ESin==false) uES = valueOk;
if(ENin==false) uEN = valueOk;
}
// assert( (i+1)+nx*(j+1) < nx*ny);
double locX = coord_x / hx - i;
double locY = coord_y / hy - j;
double valueU = uWS * (1.0 - locX) * (1.0 - locY) +
uES * locX * (1.0 - locY) +
uWN * (1.0 - locX) * locY +
uEN * locX * locY;
int valueIntU = (valueU - minU) / (maxU - minU) * ColormapSize;
bool notFoundContour = true;
if(numberContours>0) {
for(int i=0;i<numberContours && notFoundContour;++i) {
// if(valueIntU == contourVals.at(i)) {
if(ABS(valueIntU-contourVals.at(i)) <= thicknessContourLines) {
// *scanLine++ = colormap[contourColor % ColormapSize];
*scanLine++ = contourColor;
notFoundContour = false;
}
}
}
if(notFoundContour) {
if(showData) *scanLine++ = colormap[valueIntU % ColormapSize];
else *scanLine++ = valueEmpty;
}
}
//*scanLine++ = colormap[rgbFromU(valueU) % ColormapSize];
}
}
return image;
}
uint QImageMaker::rgbFromWaveLength(double wave) {
double r = 0.0;
double g = 0.0;
double b = 0.0;qRgb(int(r * 255), int(g * 255), int(b * 255));
if (wave >= 380.0 && wave <= 440.0) {
r = -1.0 * (wave - 440.0) / (440.0 - 380.0);
b = 1.0;
} else if (wave >= 440.0 && wave <= 490.0) {
g = (wave - 440.0) / (490.0 - 440.0);
b = 1.0;
} else if (wave >= 490.0 && wave <= 510.0) {
g = 1.0;
b = -1.0 * (wave - 510.0) / (510.0 - 490.0);
} else if (wave >= 510.0 && wave <= 580.0) {
r = (wave - 510.0) / (580.0 - 510.0);
g = 1.0;
} else if (wave >= 580.0 && wave <= 645.0) {
r = 1.0;
g = -1.0 * (wave - 645.0) / (645.0 - 580.0);
} else if (wave >= 645.0 && wave <= 780.0) {
r = 1.0;
}
double s = 1.0;
if (wave > 700.0)
s = 0.3 + 0.7 * (780.0 - wave) / (780.0 - 700.0);
else if (wave < 420.0)
s = 0.3 + 0.7 * (wave - 380.0) / (420.0 - 380.0);
r = std::pow(r * s, 0.8);
g = std::pow(g * s, 0.8);
b = std::pow(b * s, 0.8);
return qRgb(int(r * 255), int(g * 255), int(b * 255));
}
*/
\ No newline at end of file
......@@ -26,6 +26,7 @@
#ifndef INTERPOLTwoD_H
#define INTERPOLTwoD_H
#include <vector>
/////////////////////////////////////////////////////////////
// 1. Interpolate from blockgrid to rectangular blockgrid
......@@ -36,9 +37,12 @@
// 1. Interpolate from blockgrid to rectangular blockgrid
/////////////////////////////////////////////////////////////
/*
/** \defgroup InterpolationOperators ''Interpolation operators ''
**/
/* @{ */
/**
data structure on structured grid
\verbatim
ny-1 * * * * * *
* + + + + *
3 * + + + + *
......@@ -46,18 +50,14 @@ ny-1 * * * * * *
1 * + + + + *
0 * * * * * *
0 1 2 3 nx-1
*/
/***
\endverbatim
* interpolates data from blockgrid_ to rectangular block [pWSD, pENT]
***/
**/
class Interpolate_on_structured_2Dgrid {
public:
~Interpolate_on_structured_2Dgrid();
/***
/**
* preparation for interpolation
@param nx_ number of structured grid points x-direction
@param ny_ number of structured grid points y-direction
......@@ -65,26 +65,23 @@ class Interpolate_on_structured_2Dgrid {
@param pWSD Corner WSD of structured grid
@param pENT Corner WSD of structured grid
@param blockgrid_ of unstructured grid
***/
**/
Interpolate_on_structured_2Dgrid(int nx_, int ny_,
D2vector pWS, D2vector pEN,
Blockgrid2D& blockgrid_);
/***
/**
* preparation for interpolation
@param blockgrid_ of unstructured grid
***/
**/
Interpolate_on_structured_2Dgrid(Blockgrid2D* blockgrid_);
/***
/**
* interpolates from Variable u(of unstructured blockgrid) to structured data
@param u: Variable on unstructured blockgrid
@param data: pointer to structured grid data i+nx*j
***/
**/
template <class DTyp>
void interpolate(Variable2D<DTyp>& u, DTyp* data, DTyp defaultInterpolation);
......@@ -108,9 +105,10 @@ private:
Unstructured2DGrid* ug;
};
/***
/**
* interpolates data from blockgrid_ to rectangular block [pWSD, pENT] with own data
***/
**/
template <class DTyp>
class Interpolate_on_structured_2Dgrid_with_data : protected Interpolate_on_structured_2Dgrid {
public:
......@@ -126,23 +124,36 @@ class Interpolate_on_structured_2Dgrid_with_data : protected Interpolate_on_stru
private:
DTyp* data;
};
/* @} */
class QImageMaker : public Interpolate_on_structured_2Dgrid {
class ColorMap {
public:
QImageMaker(Variable2D<double>& u_, int thicknessContourLines_ = 4);
~QImageMaker();
QImage makeImage(QSize resultSize, unsigned int numberContours, bool showData, bool origionalSize = true);
static QImage getImageColorMap(QSize resultSize);
static void makeColorMap();
private:
/**
@wave Wellenlaenge in nm von 380nm bis 780nm
**/
static uint rgbFromWaveLength(double wave);
enum { ColormapSize = 512 };
static uint colormap[ColormapSize];
static uint colormap[ColormapSize];
};
/** \addtogroup InterpolationOperators **/
/* @{ */
/**
* this class is used für visualization using Qt
**/
class QImageMaker : public ColorMap, public Interpolate_on_structured_2Dgrid {
public:
QImageMaker(Variable2D<double>& u_, int thicknessContourLines_ = 4);
~QImageMaker();
QImage makeImage(QSize resultSize, unsigned int numberContours, bool showData, bool origionalSize = true);
private:
double* data;
Variable2D<double>* u;
//Unstructured2DGrid* ug;
......@@ -155,6 +166,32 @@ class QImageMaker : public Interpolate_on_structured_2Dgrid {
int thicknessContourLines;
};
/**
* this class is used für visualization using Qt. It creates vector of arrows of a vector field
**/
class VectorOfArrowsCreator : public ColorMap, public Interpolate_on_structured_2Dgrid {
public:
VectorOfArrowsCreator(Variable2D<double>& ux_, Variable2D<double>& uy_);
~VectorOfArrowsCreator();
void createVectorList(QVector<QPointF>& startP, QVector<QPointF>& endP,
QSize resultSize, unsigned int numberArrowX_, unsigned int numberArrowY_,
bool origionalSize = true);
private:
double* dataX;
double* dataY;
Variable2D<double>* ux;
Variable2D<double>* uy;
//Unstructured2DGrid* ug;
Blockgrid2D* bg;
double maxU, minU;
int valueBackground;
int contourColor;
int valueEmpty;
};
/* @} */
/////////////////////////////////////////////////////////////////
// Implementierung von Methoden
/////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment