Esempio n. 1
0
void example_convolution ()
{
  Kernel<pcl::PointXYZRGB> kernel;
  Convolution<pcl::PointXYZRGB> convolution;

  /*dummy clouds*/
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr input_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr kernel_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr output_cloud (new pcl::PointCloud<pcl::PointXYZRGB>);

  /*example 1 : Gaussian Smoothing*/
  kernel.sigma_ = 2.0;
  kernel.kernel_size_ = 3;
  kernel.gaussianKernel (*kernel_cloud);
  convolution.kernel_ = *kernel_cloud;
  convolution.convolve (*output_cloud, *input_cloud);

  /*example 2 : forward derivative in X direction*/
  kernel.kernel_type_ = Kernel<pcl::PointXYZRGB>::DERIVATIVE_FORWARD_X;
  kernel.fetchKernel (*kernel_cloud);
  convolution.kernel_ = *kernel_cloud;
  convolution.convolve (*output_cloud, *input_cloud);

  /*example 3*/
  kernel.kernel_type_ = Kernel<pcl::PointXYZRGB>::DERIVATIVE_FORWARD_X;
  kernel.fetchKernel (convolution.kernel_);
  convolution.convolve (*output_cloud, *input_cloud);
}
void WaterErosion::runErosion() 
{
	waterToAdd = menu.getFloatSlider("water")->getValue();
	maxSaturation = menu.getFloatSlider("max saturation")->getValue();
	addSoil = menu.getFloatSlider("Add Soil")->getValue();
	removeSoil = menu.getFloatSlider("Remove Soil")->getValue();

	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++){
			for (int c = 0; c < 3; c++)
			{
				flowMap.getPixels()[(y * width + x) * 4 + c] = 0;
			}
			flowMap.getPixels()[(y * width + x) * 4 + 3] = 255;
		}
	}

	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++)
		{
			waterFlowErosion(x, y, ofVec2f(ofRandom(-1.5, 1.5), ofRandom(-1.5, 1.5)) , waterToAdd);
		}
	}

	Kernel k;
	k.setSize(3);
	k.gaussianKernel(1.0f);

	ofPixels terrain;
	terrain.allocate(width, height, OF_IMAGE_GRAYSCALE);
	GreyProcessing::greyBlur(heightMap.getPixels(), terrain.getPixels(), width, height, k, CLAMP);

	heightMap.setFromPixels(terrain.getPixels(), width, height, OF_IMAGE_GRAYSCALE);
	
}