/* Authors Martin Schlather, martin.schlather@math.uni-goettingen.de Definition of correlation functions and derivatives (spectral measures, tbm operators) Note: * Never use the below functions directly, but only by the functions indicated in RFsimu.h, since there is no error check (e.g. initialization of RANDOM) * VARIANCE, SCALE are not used here * definitions for the random coin method can be found in MPPFcts.cc * definitions for genuinely anisotropic or nonstationary models are in SophisticatedModel.cc; hyper models also in Hypermodel.cc Copyright (C) 2001 -- 2003 Martin Schlather Copyright (C) 2004 -- 2004 Yindeng Jiang & Martin Schlather Copyright (C) 2005 -- 2011 Martin Schlather This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "RF.h" #ifdef DoublePrecision #define boolean int #define uchar int #define uword int #else #define boolean bool #define uchar unsigned char #define uword short unsigned int #endif //#define gz unsigned short int void threshold(int n, res_type *in, double percent, boolean* out) { int i; double threshold; threshold = qnorm(percent, 0.0, 1.0, 1, 0); for (i=0; i 15 && sizeof(uchar)==1) error("max coarse is 15"); int threshold = (res * res) / 2, ncDres = nc / res, nrres = nr * res, nrDres = nr / res; boolean *pin, *pc, *pinbase, *lastres, *lastin = in + ncDres * nrres; uchar *proutende, *pr, *pout = out, *lastout = out + nrDres * ncDres; for(pinbase = in; pinbase threshold; } } void reference_area(int nr, int nc, uchar *in, int edge, uword *out) { int i, j, old, laststart, n = nc * nr, edgeM1 = edge - 1, edgeM1nr = nr * edgeM1, last = n - edge, edgenr = edge * nr, nrMedge1 = nr - edge +1; uword dummy; out[0] = 0.0; for(i=0; i nrdecr) nettoedge = nrdecr; if (nettoedge > ncdecr) nettoedge = ncdecr; if (debug) PRINTF(" netto.referenz=%d\n", nettoedge); for (iperc=0; iperc<*nperc; iperc++) { areathreshold = (int) ceil(nettoedge * nettoedge * percent[iperc]); if (debug) PRINTF(" min=%2.0f%(=%dpx) ", percent[iperc] * 100, areathreshold ); reference_area(nrdecr, ncdecr, decreased, nettoedge, refarea); lastnc = (ncdecr - nettoedge +1) * nrdecr; forest = 0; land = (nrdecr - nettoedge + 1) * (ncdecr - nettoedge + 1); for (j=0; j= areathreshold); } } percent_covered = (double) forest / (double) land; if (debug) PRINTF("-> forest=%d land=(%d-%d+1)^2=%d coverd=%2.2f%\n", forest, nrdecr, nettoedge, land, percent_covered); result[k++] = percent_covered; } } } } *Nrdecr = nrdecr; *Ncdecr = ncdecr; *Areathreshold = areathreshold; } void analyseForst(int* keynr, double *gausspercent, int *ngaussp, int *coarse, int *ncrs, int *edges, int *nedg, double *percent, int *nperc, double *result) { int nrdecr, ncdecr, areathreshold, n = KEY[*keynr].loc.totalpoints; res_type *image; boolean *binary; uchar *decreased; uword *refarea; PRINTF("memory needed %e + %e + %e + %e\n", (double) n * sizeof(res_type), (double) n * sizeof(boolean), (double) n * sizeof(uchar), (double) n * sizeof(uword) ); if ((image = (res_type*) malloc(n * sizeof(res_type))) == NULL) error("mem err 1"); if ((binary = (boolean*) malloc(n * sizeof(boolean))) == NULL) error("mem err 2"); if ((decreased = (uchar*) calloc(n, sizeof(uchar))) == NULL) error("mem err 3"); if ((refarea = (uword*) malloc(n * sizeof(uword))) == NULL) error("mem err 4"); analyse_internal(keynr, gausspercent, ngaussp, coarse, ncrs, edges, nedg, percent, nperc, image, binary, decreased, &nrdecr, &ncdecr, refarea, &areathreshold, result); free(refarea); free(decreased); free(binary); free(image); } void analyseForstImages(int* keynr, double *gausspercent, int *ngaussp, int *coarse, int *ncrs, int *edges, int *nedg, double *percent, int *nperc, // double *image, int *binary, int *decreased, int *nrdecr, int *ncdecr, int *refarea, // int *areathreshold, double *result ) { if (sizeof(res_type) != sizeof(double)) { error("images cannot be returned (res_type)\n"); } if (sizeof(boolean) != sizeof(int)) { error("images cannot be returned (bool)\n"); } if (sizeof(uchar) != sizeof(int)) { error("images cannot be returned (uchar)\n"); } if (sizeof(uword) != sizeof(int)) { error("images cannot be returned (uword)\n"); } analyse_internal(keynr, gausspercent, ngaussp, coarse, ncrs, edges, nedg, percent, nperc, (res_type *)image, (boolean*) binary, (uchar*) decreased, nrdecr, ncdecr, (uword*) refarea, areathreshold, result); // assert(*areathreshold < 10); }