float CInfiniteAmortizedNoise3D::generate(int x, int y, int z, const int m0, const int m1, int n, float*** cell){
  int r = 1; // Side length of cell divided by side length of subcell.

  //skip over unwanted octaves
  for(int i=1; i<m0; i++){
    n /= 2; r *= 2;
  } //for
  
  if(n < 2)return 1.0f; //fail and bail - should not happen
    
  //Generate first octave directly into cell.
  //  We could add all octaves into the cell directly if we zero out the cell
  //  before we begin. However, that is a nontrivial overhead that Perlin noise
  //  does not have, and we can avoid it too by putting in the first octave and
  //  adding in the rest.

  initSplineTable(n); //initialize the spline table to cells of size n
  for(int i0=0; i0<r; i0++)
    for(int j0=0; j0<r; j0++)
      for(int k0=0; k0<r; k0++){ //for each subcell
        initEdgeTables(x + i0, y + j0, z + k0, n); //initialize the amortized noise tables
        getNoise(n, i0*n, j0*n, k0*n, cell); //generate noise directly into cell
      } //for

  float scale = 1.0f; //scale factor
  
  //Generate the other octaves and add them into cell. See previous comment.
  for(int k=m0; k<m1 && n>=2; k++){ //for each octave after the first
    n /= 2; r += r;  x += x; y += y; z += z; scale *= 0.5f; //rescale for next octave
    initSplineTable(n); //initialize the spline table to cells of size n
    for(int i0=0; i0<r; i0++)
      for(int j0=0; j0<r; j0++)
        for(int k0=0; k0<r; k0++){ //for each subcell
          initEdgeTables(x + i0, y + j0, z + k0, n); //initialize the edge tables
          addNoise(n, i0*n, j0*n, k0*n, scale, cell); //generate directly into cell
        } //for
  } //for each octave

  //Compute 1/magnitude and return it. 
  //  A single octave of Perlin noise returns a value of magnitude at most 
  //  1/sqrt(3). Adding magnitudes over all scaled octaves gives a total
  //  magnitude of (1 + 0.5 + 0.25 +...+ scale)/sqrt(3). This is equal to
  //  (2 - scale)/sqrt(3) (using the standard formula for the sum of a geometric
  //  progression). 1/magnitude is therefore sqrt(3)/(2-scale).

  return 1.732f/(2.0f - scale); //scale factor
} //generate
예제 #2
0
Real32 interpolatedNoise(const Pnt2f& t, UInt32 & octave, UInt32 UInt32, bool Smoothing)
{
	Real32 intX(osgFloor(t[0])), intY(osgFloor(t[1]));
	Real32 fractionX = t[0] - intX;
	Real32 fractionY = t[1] - intY;

	Real32 i1(0.0f), i2(0.0f), returnValue(0.0f);
	if(Smoothing)
	{
		if(UInt32 == PERLIN_INTERPOLATE_COSINE)
		{
			i1 = interpolateCosine(smoothNoise(intX, intY, octave),smoothNoise(intX + 1.0f, intY, octave), fractionX);
			intY += 1.0f;
			i2 = interpolateCosine(smoothNoise(intX, intY, octave),smoothNoise(intX + 1.0f, intY, octave), fractionX);
			returnValue = interpolateCosine(i1 , i2 , fractionY);
		}
		else if (UInt32 == PERLIN_INTERPOLATE_LINEAR)
		{
			i1 = interpolateLinear(smoothNoise(intX, intY, octave),smoothNoise(intX + 1.0f, intY, octave), fractionX);
			intY += 1.0f;
			i2 = interpolateLinear(smoothNoise(intX, intY, octave),smoothNoise(intX + 1.0f, intY, octave), fractionX);
			returnValue = interpolateLinear(i1 , i2 , fractionY);
		}
	} else
	{
		if(UInt32 == PERLIN_INTERPOLATE_COSINE)
		{
			i1 = interpolateCosine(getNoise(intX, intY, octave),getNoise(intX + 1.0f, intY, octave), fractionX);
			intY += 1.0f;
			i2 = interpolateCosine(getNoise(intX, intY, octave),getNoise(intX + 1.0f, intY, octave), fractionX);
			returnValue = interpolateCosine(i1 , i2 , fractionY);
		}
		else if (UInt32 == PERLIN_INTERPOLATE_LINEAR)
		{
			i1 = interpolateLinear(getNoise(intX, intY, octave),getNoise(intX + 1.0f, intY, octave), fractionX);
			intY += 1.0f;
			i2 = interpolateLinear(getNoise(intX, intY, octave),getNoise(intX + 1.0f, intY, octave), fractionX);
			returnValue = interpolateLinear(i1 , i2 , fractionY);
		}
	}

	return returnValue;
}
void ChunkGenerator::generateLayer(Chunk* chunk, TerrainLayer terrainLayer, int x, int z, int& currentHeight)
{
	int maxHeight;
	int baseNoise;
	D3DXVECTOR3 blockLocal;
	Block* currentTarget;

	// generate noise using layer settings
	baseNoise = getNoise(x, 0, z, terrainLayer.frequency, terrainLayer.amplitude, terrainLayer.exponent);

	//=============================
	// Define Maximum Layer Height
	//=============================

	if (terrainLayer.layerType == LayerType::Absolute)
	{
		// Calculate highest point we generate up to
		maxHeight = terrainLayer.baseHeight + baseNoise;
	}
	else if (terrainLayer.layerType == LayerType::Additive)
	{
		// Calculate highest point we generate up to
		maxHeight = currentHeight + terrainLayer.baseHeight + baseNoise;
	}

	//======================
	// create Terrain Layer
	//======================

	for (float y = currentHeight; y < maxHeight; y++)
	{
		// Calculate its local position in the chunk
		blockLocal = D3DXVECTOR3(x, y, z) - chunk->getPosition();

		// update the block
		currentTarget = chunk->getBlock(blockLocal.x, blockLocal.y, blockLocal.z);
		if (currentTarget)
		{
			currentTarget->clone(World::Blocks[terrainLayer.blockName]);
		}
	}

	// update returned value
	currentHeight = maxHeight;
}
예제 #4
0
void NoiseGen::createMapImage(int nx, int ny)
{

    mapTexture->clear();

    for(int i = 0; i < IMAGE_SIZE; i++)
    {
        for(int n = 0; n < IMAGE_SIZE; n++)
        {

            //note , the scale factor for simplex differs from perlin, perlin > value zooms in, simplex < value zooms in
            if(N_MODE == SIMPLEX && !terrainmode) drawPixel(mapTexture, n, i, scaled_octave_noise_2d(octaves,persistence,scale,0,255,n+nx,i + ny) , IMAGE_SCALE);
            else if(N_MODE == SIMPLEX && terrainmode) drawPixelTerrain(mapTexture, n, i, scaled_octave_noise_2d(octaves,persistence,scale,0,255,(n + nx),(i + ny)), IMAGE_SCALE);
            else if(N_MODE == PERLIN && !terrainmode) drawPixel(mapTexture, n, i, getNoise(octaves, persistence, scale, n + nx, i + ny), IMAGE_SCALE);
            else if(N_MODE == PERLIN && terrainmode) drawPixelTerrain(mapTexture, n, i, getNoise(octaves, persistence, scale, n + nx, i + ny), IMAGE_SCALE);
        }
    }
    std::cout << nx << "," << ny << std::endl;
}
예제 #5
0
Real32 interpolatedNoise(Real32 t, UInt32 octave, UInt32 UInt32, bool Smoothing)
{
	Real32 intT(osgFloor(t));
	Real32 fractionT = t - intT;
	Real32 v1,v2;
	if(Smoothing)
	{
		v1 = getNoise(intT,octave)/2.0f + getNoise(intT - 1.0f, octave)/4.0f + getNoise(intT + 1.0f, octave)/4.0f;
		intT += 1.0f;
		v2 = getNoise(intT,octave)/2.0f + getNoise(intT - 1.0f, octave)/4.0f + getNoise(intT + 1.0f, octave)/4.0f;
	} else
	{
		v1 = getNoise(intT,octave);
		v2 = getNoise(intT + 1.0f,octave);
	}

	Real32 returnValue(0.0);
	if(UInt32 == PERLIN_INTERPOLATE_COSINE) returnValue = interpolateCosine(v1 , v2 , fractionT);
	else if(UInt32 == PERLIN_INTERPOLATE_LINEAR) returnValue = interpolateLinear(v1 , v2 , fractionT);
	
	return returnValue;
}
예제 #6
0
void sendMeasureUART (uint8_t port) {
	double reCalc = 0.0;
	switch (portModeMeasure[port]) {
	case Vol :
		reCalc = measurement;
		dtostrf(reCalc ,7,3, voltageValueBuffer);
		break;
	case Light :
		reCalc = getLightIntensity();
		dtostrf(reCalc ,7,1, voltageValueBuffer);
		break;
	case Temp :
		reCalc = getTemp();
		dtostrf(reCalc ,7,1, voltageValueBuffer);
		break;
	case Noise :
		reCalc = getNoise();
		dtostrf(reCalc ,7,3, voltageValueBuffer);
		break;
	case Distance :
		reCalc = getDistance();
		dtostrf(reCalc ,7,1, voltageValueBuffer);
		break;
	}
	uart_puts("P:");

	uart_putc((char) port +48);
	uart_putc(';');
	// +1 wegen leerzeichen ... -- vorzeichen platzhalter
	uart_puts(voltageValueBuffer+1);

	switch (portModeMeasure[port]) {
	case Vol : uart_puts(" V"); break;
	case Light : uart_puts(" L"); break;
	case Temp : uart_puts(" C"); break;
	case Noise : uart_puts(" S"); break;
	case Distance : uart_puts(" cm"); break;
	}

	uart_putc('\n');
}
예제 #7
0
int ej_active_wireless_if(webs_t wp, int argc, char_t ** argv, char *iface, char *visible, int cnt)
{
	int rssi = 0, noise = 0;
	FILE *fp2;
	char *mode;
	char mac[30];
	char line[80];
	int macmask;
	macmask = atoi(argv[0]);
	if (!ifexists(iface))
		return cnt;
	unlink(RSSI_TMP);
	char wlmode[32];

	sprintf(wlmode, "%s_mode", visible);
	mode = nvram_safe_get(wlmode);
	unsigned char buf[WLC_IOCTL_MAXLEN];

	memset(buf, 0, WLC_IOCTL_MAXLEN);	// get_wdev
	int r = getassoclist(iface, buf);

	if (r < 0)
		return cnt;
	struct maclist *maclist = (struct maclist *)buf;
	int i;

	for (i = 0; i < maclist->count; i++) {
		ether_etoa((uint8 *) & maclist->ea[i], mac);

		rssi = 0;
		noise = 0;
		// get rssi value
		if (strcmp(mode, "ap") && strcmp(mode, "apsta")
		    && strcmp(mode, "apstawet"))
			sysprintf("wl -i %s rssi > %s", iface, RSSI_TMP);
		else
			sysprintf("wl -i %s rssi \"%s\" > %s", iface, mac, RSSI_TMP);

		// get noise value if not ap mode
		// if (strcmp (mode, "ap"))
		// snprintf (cmd, sizeof (cmd), "wl -i %s noise >> %s", iface,
		// RSSI_TMP);
		// system2 (cmd); // get RSSI value for mac

		fp2 = fopen(RSSI_TMP, "r");
		if (fgets(line, sizeof(line), fp2) != NULL) {

			// get rssi
			if (sscanf(line, "%d", &rssi) != 1)
				continue;
			noise = getNoise(iface, NULL);
			/*
			 * if (strcmp (mode, "ap") && fgets (line, sizeof (line), fp2) != 
			 * NULL && sscanf (line, "%d", &noise) != 1) continue;
			 */
			// get noise for client/wet mode

			fclose(fp2);
		}
		if (nvram_match("maskmac", "1") && macmask) {
			mac[0] = 'x';
			mac[1] = 'x';
			mac[3] = 'x';
			mac[4] = 'x';
			mac[6] = 'x';
			mac[7] = 'x';
			mac[9] = 'x';
			mac[10] = 'x';
		}
		if (cnt)
			websWrite(wp, ",");
		cnt++;
		int rxrate[32];
		int txrate[32];
		int time[32];
		strcpy(rxrate, "N/A");
		strcpy(txrate, "N/A");
		strcpy(time, "N/A");
#ifndef WL_STA_SCBSTATS
#define WL_STA_SCBSTATS		0x4000	/* Per STA debug stats */
#endif
		sta_info_compat_t *sta;
		sta_info_compat_old_t *staold;
		char *param;
		int buflen;
		char buf[WLC_IOCTL_MEDLEN];
		strcpy(buf, "sta_info");
		buflen = strlen(buf) + 1;
		param = (char *)(buf + buflen);
		memcpy(param, (char *)&maclist->ea[i], ETHER_ADDR_LEN);
		if (!wl_ioctl(iface, WLC_GET_VAR, &buf[0], WLC_IOCTL_MEDLEN)) {
			/* display the sta info */
			sta = (sta_info_compat_t *) buf;
			if (sta->ver == 2) {
				staold = (sta_info_compat_old_t *) buf;
				if (staold->flags & WL_STA_SCBSTATS) {
					int tx = staold->tx_rate;
					int rx = staold->rx_rate;
					if (tx > 0)
						sprintf(txrate, "%dM", tx / 1000);

					if (rx > 0)
						sprintf(rxrate, "%dM", rx / 1000);
					strcpy(time, UPTIME(staold->in));
				}
			} else {	// sta->ver == 3
				if (sta->flags & WL_STA_SCBSTATS) {
					int tx = sta->tx_rate;
					int rx = sta->rx_rate;
					if (tx > 0)
						sprintf(txrate, "%dM", tx / 1000);

					if (rx > 0)
						sprintf(rxrate, "%dM", rx / 1000);
					strcpy(time, UPTIME(sta->in));
				}
			}
		}

		/*
		 * if (!strcmp (mode, "ap")) { noise = getNoise(iface,NULL); // null
		 * only for broadcom }
		 */
		int qual = rssi * 124 + 11600;
		qual /= 10;
		websWrite(wp, "'%s','%s','%s','%s','%s','%d','%d','%d','%d'", mac, iface, time, txrate, rxrate, rssi, noise, rssi - noise, qual);
	}
	unlink(RSSI_TMP);

	return cnt;
}
예제 #8
0
Real32 smoothNoise(Real32 x, Real32 y, Real32 z, UInt32 octave)
{	// averages out the values from the corners, center of the sides, and the center of a 1x1 cube, centered @ (x,y,z)
	// where each side weighs 1/24, each corner weighs 1/16, and the center weighs 1/4.
	Real32 center = getNoise(x,y,z,octave)/4;
	
	Real32 corners = (getNoise(x+1,y-1,z-1,octave) + getNoise(x-1,y-1,z-1,octave) + getNoise(x+1,y+1,z-1,octave) + getNoise(x-1,y+1,z-1,octave) 
					+ getNoise(x+1,y-1,z+1,octave) + getNoise(x-1,y-1,z+1,octave) + getNoise(x+1,y+1,z+1,octave) + getNoise(x-1,y+1,z+1,octave))/16;
	
	Real32 sides = (getNoise(x+1,y,z,octave) + getNoise(x-1,y,z,octave) + getNoise(x,y+1,z,octave) 
					+ getNoise(x,y-1,z,octave) + getNoise(x,y,z+1,octave) + getNoise(x,y,z-1,octave))/24;
		
	return center + corners + sides;
}
예제 #9
0
Real32 interpolatedNoise(const Pnt3f& t, UInt32 & octave, UInt32 UInt32, bool Smoothing)
{
	Real32 intX(osgFloor(t[0])), intY(osgFloor(t[1])), intZ(osgFloor(t[2]));
	Real32 fractionX = t[0] - intX;
	Real32 fractionY = t[1] - intY;
	Real32 fractionZ = t[2] - intZ;

	Real32 v1,v2,v3,v4,v5,v6,v7,v8,i1,i2,i3,i4, returnValue(0.0f);
	
	if(Smoothing)
	{
		v1 = smoothNoise(intX,intY,intZ,octave);
		v2 = smoothNoise(intX + 1.0f,intY,intZ,octave);
		v3 = smoothNoise(intX,intY + 1.0f,intZ,octave);
		v4 = smoothNoise(intX + 1.0f,intY + 1.0f,intZ,octave);
		v5 = smoothNoise(intX,intY,intZ + 1.0f,octave);
		v6 = smoothNoise(intX + 1.0f,intY,intZ + 1.0f,octave);
		v7 = smoothNoise(intX,intY + 1.0f,intZ + 1.0f,octave);
		v8 = smoothNoise(intX + 1.0f,intY + 1.0f,intZ + 1.0f,octave);

		if(UInt32 == PERLIN_INTERPOLATE_COSINE)
		{
			i1 = interpolateCosine(v1,v2,fractionX);
			i2 = interpolateCosine(v3,v4,fractionX);
			i3 = interpolateCosine(v5,v6,fractionX);
			i4 = interpolateCosine(v7,v8,fractionX);

			i1 = interpolateCosine(i1,i2,fractionY);
			i2 = interpolateCosine(i3,i4,fractionY);

			returnValue = interpolateCosine(i1,i2,fractionZ);

		} else if (UInt32 == PERLIN_INTERPOLATE_LINEAR)
		{
			i1 = interpolateLinear(v1,v2,fractionX);
			i2 = interpolateLinear(v3,v4,fractionX);
			i3 = interpolateLinear(v5,v6,fractionX);
			i4 = interpolateLinear(v7,v8,fractionX);

			i1 = interpolateLinear(i1,i2,fractionY);
			i2 = interpolateLinear(i3,i4,fractionY);

			returnValue = interpolateLinear(i1,i2,fractionZ);

		}
	} else
	{
		v1 = getNoise(intX,intY,intZ,octave);
		v2 = getNoise(intX + 1.0f,intY,intZ,octave);
		v3 = getNoise(intX,intY + 1.0f,intZ,octave);
		v4 = getNoise(intX + 1.0f,intY + 1.0f,intZ,octave);
		v5 = getNoise(intX,intY,intZ + 1.0f,octave);
		v6 = getNoise(intX + 1.0f,intY,intZ + 1.0f,octave);
		v7 = getNoise(intX,intY + 1.0f,intZ + 1.0f,octave);
		v8 = getNoise(intX + 1.0f,intY + 1.0f,intZ + 1.0f,octave);

		if(UInt32 == PERLIN_INTERPOLATE_COSINE)
		{
			i1 = interpolateCosine(v1,v2,fractionX);
			i2 = interpolateCosine(v3,v4,fractionX);
			i3 = interpolateCosine(v5,v6,fractionX);
			i4 = interpolateCosine(v7,v8,fractionX);

			i1 = interpolateCosine(i1,i2,fractionY);
			i2 = interpolateCosine(i3,i4,fractionY);

			returnValue = interpolateCosine(i1,i2,fractionZ);

		} else if (UInt32 == PERLIN_INTERPOLATE_LINEAR)
		{
			i1 = interpolateLinear(v1,v2,fractionX);
			i2 = interpolateLinear(v3,v4,fractionX);
			i3 = interpolateLinear(v5,v6,fractionX);
			i4 = interpolateLinear(v7,v8,fractionX);

			i1 = interpolateLinear(i1,i2,fractionY);
			i2 = interpolateLinear(i3,i4,fractionY);

			returnValue = interpolateLinear(i1,i2,fractionZ);
		}
	}

	return returnValue;
}
예제 #10
0
void generateCANMsg(tExtendedCAN *M, uint8_t port) {
	// 0x00, priority, sender, receiver
	uint8_t id[4] = {0x00, PRIORITY_NORM, REKICK_ID, COMPASS_ID};
	char buff[5];
	double reCalc = 0.0;
	if (port == 11 || port == 12) { // relais (triggerd by sys) ACK 11,12 .. -> 1,2,...
		/*		M->id[1] = 0x90;
		M->id[2] = M_BOARD_ID2;*/
		M->id[0] = 0x00;
		M->id[1] = PRIORITY_NORM;
		M->id[2] = 0x50;
		M->id[3] = 0x00;
		M->header.rtr = 0;
		M->header.length = 5;
		M->data[0] = (uint8_t) 'o';
		M->data[1] = (uint8_t) 'k';
		M->data[2] = (uint8_t) ':';
		M->data[3] = (port -10);
		M->data[4] = (uint8_t) ' ';
	}
	if (port == NOMEASUREBOARD) {
		M->id[0] = 0x00;
		M->id[1] = PRIORITY_NORM;
		M->id[2] = 0x50;
		M->id[3] = 0x00;
		M->header.rtr = 0;
		M->header.length = 6;
		M->data[0] = (uint8_t) 'n';
		M->data[1] = (uint8_t) 'o';
		M->data[2] = (uint8_t) 'b';
		M->data[3] = (uint8_t) 'o';
		M->data[4] = (uint8_t) 'a';
		M->data[5] = (uint8_t) 'r';
	}
	if (port == LED_ALERT) {
		M->id[0] = 0x00;
		M->id[1] = PRIORITY_NORM;
		M->id[2] = 0x50;
		M->id[3] = 0x00;
		M->header.rtr = 0;
		M->header.length = 3;
		M->data[0] = (uint8_t) 'l';
		M->data[1] = (uint8_t) 'e';
		M->data[2] = (uint8_t) 'd';
	}
	if (port == ACK_CAN) { // ACK
		M->id[0] = 0x00;
		M->id[1] = PRIORITY_NORM;
		M->id[2] = 0x50;
		M->id[3] = 0x00;
		M->header.rtr = 0;
		M->header.length = 7;
		M->data[0] = (uint8_t) 'a';
		M->data[1] = (uint8_t) 'c';
		M->data[2] = (uint8_t) !(PINC & (1<< lastPin1)) ? 'R' : 'r';
		M->data[3] = (uint8_t) ' ';
		M->data[4] = (uint8_t) ':';
		M->data[5] = (uint8_t) !(PINC & (1<< lastPin2)) ? 'R' : 'r';
		M->data[6] = (uint8_t) ' ';
	} else {
		M->id[0] = 0x00;
		M->id[1] = PRIORITY_NORM;
		M->id[2] = 0x50; // sender
		M->id[3] = 0x00; // receiver
		M->header.rtr = 0;
		M->header.length = 8;
		switch (portModeMeasure[port]) {
		case Vol : reCalc = measurement; break;
		case Light : reCalc = getLightIntensity(); break;
		case Temp : reCalc = getTemp(); break;
		case Noise : reCalc = getNoise(); break;
		case Distance :	reCalc = getDistance(); break;
		}
		switch (portModeMeasure[port]) {
		case Vol :
			dtostrf(reCalc ,5,1, buff);
			M->data[6] = 'V';
			break;
		case Light :
			dtostrf(reCalc, 5,2, buff);
			M->data[4] = ' ';
			M->data[5] = ' ';
			M->data[6] = 'L';
			break;
		case Temp :
			dtostrf(reCalc ,5,2, buff);
			M->data[5] = ' ';
			M->data[6] = 'C';
			break;
		case Noise :
			dtostrf(reCalc ,5,1, buff);
			M->data[6] = 'S';
			break;
		case Distance :
			dtostrf(reCalc ,5,1, buff);
			M->data[4] = ' ';
			M->data[5] = ' ';
			M->data[6] = 'D';
			break;
		}
		memcpy((void *)M->data, (const void *)buff, 5);
		M->data[7] = port ;
	}
}
예제 #11
0
int ledtracking_main(int argc, char **argv)
{
	int toggle = 0;
	int testsnr = 0;
	int rssi, noise, snr_min, snr_max, polarity, delay, snr, gpio;
	unsigned char assoclist[1024];

	if (argc <= 4) {
		fprintf(stderr, "%s <interfacex> <gpio> <polarity> <snr-max>\n", argv[0]);
		exit(1);
	}
	gpio = atoi(argv[2]);
	polarity = atoi(argv[3]);
	snr_max = atoi(argv[4]);
	snr_min = snr_max / 6;
	if (argc == 6) {
		testsnr = atoi(argv[5]);
		fprintf(stderr, "use testsnr %d\n", testsnr);
	}

	while (1) {
		if (testsnr) {
			snr = testsnr;
		} else {
			int cnt = getassoclist(argv[1], assoclist);

			if (cnt == -1) {
				cnt = 0;
			}
			if (!cnt) {
				fprintf(stderr, "not associated, wait 5 seconds\n");
				sleep(5);
				continue;
			}
			unsigned char *pos = assoclist;

			pos += 4;
			rssi = getRssi(argv[1], pos);
			noise = getNoise(argv[1], pos);
			snr = rssi - noise;
		}

		if (snr < 0) {
			fprintf(stderr, "snr is %d, invalid\n", snr);
			continue;
		}

		snr -= snr_min;
		if (snr < 0)
			snr = 0;

		if (snr >= snr_max - snr_min) {
			fprintf(stderr, "snr >= snr_max - snr_min\n", gpio, toggle);
			toggle = polarity;
			delay = 100;
		} else {
			fprintf(stderr, "else\n", gpio, toggle);
			toggle = !toggle;
			delay = 1000 - snr * (1000 - 125) / (snr_max - snr_min);
		}

		usleep(1000 * delay / 2);
		set_gpio(gpio, 0 + toggle);
		fprintf(stderr, "%d,%d\n", gpio, toggle);
	}
}
예제 #12
0
 void SCKAmbient::updateSensors(byte mode) 
  {   
     boolean ok_read = false; 
     byte    retry   = 0;
     
     #if F_CPU == 8000000 
       getSHT21();
       ok_read = true;
     #else
       base_.timer1Stop();
       while ((!ok_read)&&(retry<5))
       {
         ok_read = getDHT22();
         retry++; 
         if (!ok_read)delay(3000);
       }
       base_.timer1Initialize(); 
     #endif
       if (((millis()-timeMICS)<=6*minute)||(mode!=ECONOMIC))  //6 minutes
       {  
         #if F_CPU == 8000000 
           getVcc();
         #endif
         getMICS();
         value[5] = getCO(); //ppm
         value[6] = getNO2(); //ppm
       }
       else if((millis()-timeMICS)>=60*minute) 
             {
               GasSensor(true);
               timeMICS = millis();
             }
       else
       {
         GasSensor(false);
       }
       
       if (ok_read )  
       {
         #if ((decouplerComp)&&(F_CPU > 8000000 ))
           uint16_t battery = base_.getBattery(Vcc);
           decoupler.update(battery);
           value[0] = getTemperature() - (int) decoupler.getCompensation();
         #else
           value[0] = getTemperature();
         #endif
          value[1] = getHumidity();
       }
       else 
       {
         value[0] = 0; // ºC
         value[1] = 0; // %
       }  
       value[2] = getLight(); //mV
       value[3] = base_.getBattery(Vcc); //%
       value[4] = base_.getPanel(Vcc);  // %
       value[7] = getNoise(); //mV     
       if (mode == NOWIFI)
            {
              value[8] = 0;  //Wifi Nets
              base_.RTCtime(time);
            } 
       else if (mode == OFFLINE)
         {
           value[8] = base_.scan();  //Wifi Nets
           base_.RTCtime(time);
         }
  }
void CInfiniteAmortizedNoise3D::addNoise(const int n, const int i0, const int j0, const int k0, float scale, float*** cell){  
  for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
      for(int k=0; k<n; k++) 
        cell[i0 + i][j0 + j][k0 + k] += scale * getNoise(i, j, k); //this is the only line that differs from getNoise
} //addNoise
예제 #14
0
int main(int argc, char ** argv)
{
	if(argc < 6)
	{
		printf("Incorrect number of input arguments: \n\tRandomField <OutputFieldName> <ReferenceFileName> <Distance> <Exponent> <flat> <seed(optional)>\n");
		return 1;
	}

	double d = atof(argv[3]);
	double e = atof(argv[4]);
	double f = atof(argv[5]);

	bool withSeed = false;

	unsigned seed;

	if(argc > 6)
	{
		seed = atoi(argv[6]);
		withSeed = true;
	}

	double xMin, xMax, yMin, yMax, cellSize;
	int nCol, nRow, bound;

	
	getRasterInfo(argv[2], &nRow, &nCol, &xMin, &yMax, &cellSize);

	xMax = xMin + nCol * cellSize;
	yMin = yMax - nRow * cellSize;

	bound = d / cellSize;

	printf("Generating spatial random field of %d(col) X %d(row)\n", nCol, nRow);
	printf("Cell Size: %lf\n", cellSize);
	printf("xRange: %lf ~ %lf\n", xMin, xMax);
	printf("yRange: %lf ~ %lf\n", yMin, yMax);
	printf("D=%lf\tE=%lf\tF=%lf\n", d, e, f);

	double * noise;
	double * mask;
	double * normal;
	float * uniform;

	if(NULL == (noise = (double *) malloc ((nCol + 2 * bound) * (nRow + 2 * bound) * sizeof(double))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (mask = (double *) malloc ((1 + 2 * bound) * (1 + 2 * bound) * sizeof(double))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (normal = (double *) malloc (nCol * nRow * sizeof(double))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (uniform = (float *) malloc (nCol * nRow * sizeof(float))))
	{
		printf("ERROR: Out of memory in line %d of file %s!\n", __LINE__, __FILE__);
		exit(1);
	}

	if(withSeed)
	{
		getNoise(noise, (nCol + 2 * bound) * (nRow + 2 * bound), seed);
	}
	else
	{
		getNoise(noise, (nCol + 2 * bound) * (nRow + 2 * bound));
	}

	getMask(mask, bound, cellSize, d, e, f);
	
	generateRandomField(noise, normal, mask, nCol, nRow, bound);

	free(noise);
	free(mask);

	normalToUniform(normal, uniform, nRow * nCol);

	free(normal);

	writeGeoTiffF(argv[1], uniform, nRow, nCol, xMin, yMax, cellSize);

	free(uniform);

	
	return 0;
}