/********************************************************** * Version $Id$ *********************************************************/ // diverses.cc //#include "../stdafx.h" #include #include #include #include #include #include #include "grid_bsl.h" #include "diverses.h" #include #include using namespace std; #define false 0 #define true 1 #ifdef _DEBUG #define new DEBUG_NEW #endif using namespace std; /*int Rand(const I_Vec& I, const GridWerte& G, int abstand) { IVecWerte W((GridWerte &) G); return Rand(I, W, abstand); } */ /* int Rand(const I_Vec& I, const IVecWerte& W, int abstand) { return Rand(I.X(), I.Y(), W(), abstand); } */ bool Rand(int x, int y, const GridWerte& W, int abstand ) { return (x == abstand || x == W.xanz-1-abstand || y == abstand || y == W.yanz-1-abstand); } /* int innerhalb(const I_Vec& I, const GridWerte& W) { int x = I.X(); int y = I.Y(); return (x >= 0 && x < W.xanz && y >= 0 && y < W.yanz); } int innerhalb(const I_Vec& I, const IVecWerte& W) { int x = I.X(); int y = I.Y(); return (x >= 0 && x < W().xanz && y >= 0 && y < W().yanz); } */ int innerhalb(int x, int y, const GridWerte& W) { return (x >= 0 && x < W.xanz && y >= 0 && y < W.yanz); } ostream& operator << (ostream& o, const C_Vec2& V) { o << "(" << V.X() << ", " << V.Y() << ")"; return o; } void normieren(C_Vec2& G) // Normiert einen Vektor { double r = G.Length(); G /= r; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // min3 max3 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ double max3(double x, double y, double z) { return( x > y ? (x > z ? x : z) : (y > z ? y : z) ); } double min3(double x, double y, double z) { return( x < y ? (x < z ? x : z) : (y < z ? y : z) ); } static int NachbarBesetzt(int y0, int y1, int x0, int x1, int y, int x, GridWerte& G) { for (int i=y0; i<=y1; i++) for (int j=x0; j<=x1; j++) if (i == -1 || i == 1 || j == -1 || j == 1) { if (innerhalb(x+j, y+i, G)) if (G(x+j,y+i) != 0.0) return true; } return false; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // DeleteNotKonvex //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // LinRand //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void LinRand( GridWerte& G, GridWerte& Erg) { Erg = G; Erg.xanz += 2; Erg.yanz += 2; Erg.xll -= Erg.dxy; Erg.yll -= Erg.dxy; Erg.getMem(); int i; int j; long yyy = G.yanz; long xxx = G.xanz; // for (i=0; i M_PI) winkel = 2*M_PI-winkel; Erg.Add_Value(j,i, winkel/M_PI); zaehler++; } } } if (zaehler != 0) Erg.Mul_Value(j,i, 1.0 / zaehler); } } } static double calcMittelwert( GridWerte& H, int x, int y) { if (x != H.xanz-1 && y != H.yanz-1) return (H(x,y) + H(x,y+1) + H(x+1,y) + H(x+1,y+1))/4.0f; else if (x == H.xanz-1) { return (H(x,y) + H(x,y+1))/2.0f; } else { return (H(x,y) + H(x+1,y))/2.0f; } }