コード例 #1
0
ファイル: utils.c プロジェクト: aksharvarma/fire-spread
  int check_burning_wind(int** forest, int row_index, int col_index, int neighbourhood_type, int wind_speed, int wind_direction, long double pImmune,int rows, int cols)
  {
    int i=row_index;
    int j=col_index;
    int neighbour_status = -5;
    switch(wind_speed)
      {
      case 0:
	return TREE;
	break;
      case 2:
			
	switch(wind_direction)
	  {
	  case SOUTH:
	    neighbour_status = forest[Nr(Nr(i))%rows][Nc(Nc(j))%cols];
	    break;
	  case NORTH:
	    neighbour_status = forest[Sr(Sr(i))%rows][Sc(Sc(j))%cols];
	    break;
	  case EAST:
	    neighbour_status = forest[Wr(Wr(i))%rows][Wc(Wc(j))%cols];
	    break;
	  case WEST:
	    neighbour_status = forest[Er(Er(i))%rows][Ec(Ec(j))%cols];
	    break;
	  }
	if (pImmune<U && neighbour_status == BURNING)
	  return BURNING;
      case 1:
	neighbour_status = -5;
	switch(wind_direction)
	  {
	  case SOUTH:
	    neighbour_status = forest[Nr(i)][Nc(j)];
	    break;
	  case NORTH:
	    neighbour_status = forest[Sr(i)][Sc(j)];
	    break;
	  case EAST:
	    neighbour_status = forest[Wr(i)][Wc(j)];
	    break;
	  case WEST:
	    neighbour_status = forest[Er(i)][Ec(j)];
	    break;
	  }
	if (pImmune<U && neighbour_status == BURNING)
	  return BURNING;
	else
	  return TREE;	
      }
	
  }
コード例 #2
0
ファイル: bssrdf.cpp プロジェクト: AndreaLoforte/pbrt-v3
Spectrum TabulatedBSSRDF::Sr(Float r) const {
    Spectrum Sr(0.f);
    for (int ch = 0; ch < Spectrum::nSamples; ++ch) {
        // Convert $r$ into unitless optical radius $r_{\roman{optical}}$
        Float rOptical = r * sigma_t[ch];

        // Compute spline weights to interpolate BSSRDF on channel _ch_
        int rhoOffset, radiusOffset;
        Float rhoWeights[4], radiusWeights[4];
        if (!CatmullRomWeights(table.nRhoSamples, table.rhoSamples.get(),
                               rho[ch], &rhoOffset, rhoWeights) ||
            !CatmullRomWeights(table.nRadiusSamples, table.radiusSamples.get(),
                               rOptical, &radiusOffset, radiusWeights))
            continue;

        // Set BSSRDF value _Sr[ch]_ using tensor spline interpolation
        Float sr = 0;
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                Float weight = rhoWeights[i] * radiusWeights[j];
                if (weight != 0)
                    sr += weight *
                          table.EvalProfile(rhoOffset + i, radiusOffset + j);
            }
        }

        // Cancel marginal PDF factor from tabulated BSSRDF profile
        if (rOptical != 0) sr /= 2 * Pi * rOptical;
        Sr[ch] = sr;
    }
    // Transform BSSRDF value into world space units
    Sr *= sigma_t * sigma_t;
    return Sr.Clamp();
}
コード例 #3
0
Foam::tmp<Foam::volScalarField> Foam::liftModels::LegendreMagnaudet::Cl() const
{
    volScalarField Re(max(pair_.Re(), residualRe_));

    volScalarField Sr
    (
        sqr(pair_.dispersed().d())
       /(
            Re
           *pair_.continuous().nu()
        )
       *mag(fvc::grad(pair_.continuous().U()))
    );

    volScalarField ClLowSqr
    (
        sqr(6.0*2.255)
       *sqr(Sr)
       /(
            pow4(constant::mathematical::pi)
           *Re
           *pow3(Sr + 0.2*Re)
        )
    );

    volScalarField ClHighSqr
    (
        sqr(0.5*(Re + 16.0)/(Re + 29.0))
    );

    return sqrt(ClLowSqr + ClHighSqr);
}
コード例 #4
0
int do_neighbours_burn(int** forest,int row_index,int col_index)
{
	return (forest[Nr(row_index)][Nc(col_index)]==BURNING ||
	    forest[Er(row_index)][Ec(col_index)]==BURNING ||
	    forest[Wr(row_index)][Wc(col_index)]==BURNING ||
	    forest[Sr(row_index)][Sc(col_index)]==BURNING
	    );
}
コード例 #5
0
ファイル: utils.c プロジェクト: aksharvarma/fire-spread
  /* This counts the number of burning neighbours */
  int count_burning_neighbours(int** forest, int row_index, int col_index, int neighbourhood_type){
    int neighbors_on_fire=0;
    int i=row_index;
    int j=col_index;

    switch(neighbourhood_type){
    case VON_NEUMANN:
      if(forest[Nr(i)][Nc(j)]>=BURNING && forest[Nr(i)][Nc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Er(i)][Ec(j)]>=BURNING && forest[Er(i)][Ec(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Wr(i)][Wc(j)]>=BURNING && forest[Wr(i)][Wc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Sr(i)][Sc(j)]>=BURNING && forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      break;
    case MOORE:
      if(forest[Nr(i)][Nc(j)]>=BURNING && forest[Nr(i)][Nc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Er(i)][Ec(j)]>=BURNING && forest[Er(i)][Ec(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Wr(i)][Wc(j)]>=BURNING && forest[Wr(i)][Wc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[Sr(i)][Sc(j)]>=BURNING && forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      /* Diagonals */
      if(forest[NEr(i)][NEc(j)]>=BURNING && forest[NEr(i)][NEc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[SEr(i)][SEc(j)]>=BURNING && forest[SEr(i)][SEc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[NWr(i)][NWc(j)]>=BURNING && forest[NWr(i)][NWc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      if(forest[SWr(i)][SWc(j)]>=BURNING && forest[SWr(i)][SWc(j)]<=OLD_BURNING)
	neighbors_on_fire++;
      break;
    default:
      break;
    }
    return neighbors_on_fire;
  }
コード例 #6
0
ファイル: utils.c プロジェクト: aksharvarma/fire-spread
  /* This returns 1 if any neighbours burn, 0 otherwise */
  int do_neighbours_burn(int** forest, int row_index, int col_index, int neighbourhood_type){

    int i=row_index;
    int j=col_index;
  
    switch(neighbourhood_type){
    case VON_NEUMANN:
      return ((forest[Nr(i)][Nc(j)]>=BURNING &&
	       forest[Nr(i)][Nc(j)]<=OLD_BURNING) ||
	      (forest[Er(i)][Ec(j)]>=BURNING &&
	       forest[Er(i)][Ec(j)]<=OLD_BURNING) ||
	      (forest[Wr(i)][Wc(j)]>=BURNING &&
	       forest[Wr(i)][Wc(j)]<=OLD_BURNING) ||
	      (forest[Sr(i)][Sc(j)]>=BURNING &&
	       forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	      );
    case MOORE:
      return ((forest[Nr(i)][Nc(j)]>=BURNING &&
	       forest[Nr(i)][Nc(j)]<=OLD_BURNING) ||
	      (forest[Er(i)][Ec(j)]>=BURNING &&
	       forest[Er(i)][Ec(j)]<=OLD_BURNING) ||
	      (forest[Wr(i)][Wc(j)]>=BURNING &&
	       forest[Wr(i)][Wc(j)]<=OLD_BURNING) ||
	      (forest[Sr(i)][Sc(j)]>=BURNING &&
	       forest[Sr(i)][Sc(j)]<=OLD_BURNING)
	      ||
	      //Diagonals
	      (forest[NEr(i)][NEc(j)]>=BURNING &&
	       forest[NEr(i)][NEc(j)]<=OLD_BURNING) ||
	      (forest[SEr(i)][SEc(j)]>=BURNING &&
	       forest[SEr(i)][SEc(j)]<=OLD_BURNING) ||
	      (forest[NWr(i)][NWc(j)]>=BURNING &&
	       forest[NWr(i)][NWc(j)]<=OLD_BURNING) ||
	      (forest[SWr(i)][SWc(j)]>=BURNING &&
	       forest[SWr(i)][SWc(j)]<=OLD_BURNING)
	      );
    default:
      return 0;
    }
  }
コード例 #7
0
 double K (const double h) const
 { return K_sat * pow (Sr (h), (2 + 3.0 / b) * b); }
コード例 #8
0
 double Theta (const double h) const
 { return Sr (h) * Theta_sat; }
コード例 #9
0
ファイル: tldDetector.cpp プロジェクト: 2php/opencv_contrib
		bool TLDDetector::detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
		{
			patches.clear();
			Mat_<uchar> standardPatch(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
			Mat tmp;
			int dx = initSize.width / 10, dy = initSize.height / 10;
			Size2d size = img.size();
			double scale = 1.0;
			int npos = 0, nneg = 0;
			double maxSc = -5.0;
			Rect2d maxScRect;
			int scaleID;
			std::vector <Mat> resized_imgs, blurred_imgs;
			std::vector <Point> varBuffer, ensBuffer;
			std::vector <int> varScaleIDs, ensScaleIDs;

			//Detection part
			//Generate windows and filter by variance
			scaleID = 0;
			resized_imgs.push_back(img);
			blurred_imgs.push_back(imgBlurred);
			do
			{
				Mat_<double> intImgP, intImgP2;
				computeIntegralImages(resized_imgs[scaleID], intImgP, intImgP2);
				for (int i = 0, imax = cvFloor((0.0 + resized_imgs[scaleID].cols - initSize.width) / dx); i < imax; i++)
				{
					for (int j = 0, jmax = cvFloor((0.0 + resized_imgs[scaleID].rows - initSize.height) / dy); j < jmax; j++)
					{
						if (!patchVariance(intImgP, intImgP2, originalVariancePtr, Point(dx * i, dy * j), initSize))
							continue;
						varBuffer.push_back(Point(dx * i, dy * j));
						varScaleIDs.push_back(scaleID);
					}
				}
				scaleID++;
				size.width /= SCALE_STEP;
				size.height /= SCALE_STEP;
				scale *= SCALE_STEP;
				resize(img, tmp, size, 0, 0, DOWNSCALE_MODE);
				resized_imgs.push_back(tmp);
				GaussianBlur(resized_imgs[scaleID], tmp, GaussBlurKernelSize, 0.0f);
				blurred_imgs.push_back(tmp);
			} while (size.width >= initSize.width && size.height >= initSize.height);

			//Encsemble classification
			for (int i = 0; i < (int)varBuffer.size(); i++)
			{
				prepareClassifiers(static_cast<int> (blurred_imgs[varScaleIDs[i]].step[0]));
				if (ensembleClassifierNum(&blurred_imgs[varScaleIDs[i]].at<uchar>(varBuffer[i].y, varBuffer[i].x)) <= ENSEMBLE_THRESHOLD)
					continue;
				ensBuffer.push_back(varBuffer[i]);
				ensScaleIDs.push_back(varScaleIDs[i]);
			}

			//NN classification
			for (int i = 0; i < (int)ensBuffer.size(); i++)
			{
				LabeledPatch labPatch;
				double curScale = pow(SCALE_STEP, ensScaleIDs[i]);
				labPatch.rect = Rect2d(ensBuffer[i].x*curScale, ensBuffer[i].y*curScale, initSize.width * curScale, initSize.height * curScale);
				resample(resized_imgs[ensScaleIDs[i]], Rect2d(ensBuffer[i], initSize), standardPatch);

				double srValue, scValue;
				srValue = Sr(standardPatch);

				////To fix: Check the paper, probably this cause wrong learning
				//
				labPatch.isObject = srValue > THETA_NN;
				labPatch.shouldBeIntegrated = abs(srValue - THETA_NN) < 0.1;
				patches.push_back(labPatch);
				//

				if (!labPatch.isObject)
				{
					nneg++;
					continue;
				}
				else
				{
					npos++;
				}
				scValue = Sc(standardPatch);
				if (scValue > maxSc)
				{
					maxSc = scValue;
					maxScRect = labPatch.rect;
				}
			}

			if (maxSc < 0)
				return false;
			else
			{
				res = maxScRect;
				return true;
			}
		}