protected void CreateSmoothNormales()
{
normalesSmooth1 = new Vec3[pData.Width, pData.Height];
normalesSmooth2 = new Vec3[pData.Width, pData.Height];
// Normieren
for (int i = 0; i < pData.Width; i++)
{
for (int j = 0; j < pData.Height; j++)
{
PixelInfo pInfo = pData.Points[i, j];
if (pInfo != null)
{
// pInfo.Normal.Normalize();
normalesSmooth1[i, j] = pInfo.Normal;
normalesSmooth1[i, j].Normalize();
}
}
}
Vec3[,] currentSmooth = normalesSmooth1;
Vec3[,] nextSmooth = normalesSmooth2;
Vec3[,] tempSmooth;
int smoothLevel = 0; // (int)ParameterDict.Exemplar.GetDouble("Renderer.SmoothNormalLevel");
for (int currentSmoothLevel = 0; currentSmoothLevel < smoothLevel; currentSmoothLevel++)
{
// create nextSmooth
for (int i = 0; i < pData.Width; i++)
{
for (int j = 0; j < pData.Height; j++)
{
Vec3 center = null;
center = currentSmooth[i, j];
PixelInfo pInfo = pData.Points[i, j];
// Test ohne smooth-Factor
// Nachbarelemente zusammenrechnen
Vec3 neighbors = new Vec3();
int neighborFound = 0;
for (int k = -1; k <= 1; k++)
{
for (int l = -1; l <= 1; l++)
{
int posX = i + k;
int posY = j + l;
if (posX >= 0 && posX < pData.Width && posY >= 0 && posY < pData.Height)
{
Vec3 currentNormal = null;
currentNormal = currentSmooth[i + k, j + l];
PixelInfo pInfo2 = pData.Points[i + k, j + l];
if (currentNormal != null)
{
double amount = 1;
if (pInfo != null && pInfo2 != null)
{
double dist = pInfo.Coord.Dist(pInfo2.Coord);
double dGlobal = _maxPoint.Dist(_minPoint);
dGlobal /= 1500;
if (dist < dGlobal)
amount = 1.0;
else if (dist > dGlobal && dist < 5.0 * dGlobal)
amount = 1.0 - (dGlobal / dist / 5.0);
else
amount = 0;
}
neighbors.Add(currentNormal.Mult(amount));
neighborFound++;
}
}
}
}
neighbors.Normalize();
if (center != null)
{
nextSmooth[i, j] = center;
if (center != null || neighborFound > 1)
{
Vec3 center2 = center;
center2.Mult(200);
neighbors.Add(center2.Mult(4));
neighbors.Normalize();
nextSmooth[i, j] = neighbors;
}
}
else
{
if (neighborFound > 4)
{
nextSmooth[i, j] = neighbors;
}
}
}
}
tempSmooth = currentSmooth;
currentSmooth = nextSmooth;
nextSmooth = tempSmooth;
}
}