void CBathymetryRasterizer::RasterizeImage()
{
	CStopWatch sw;
	sw.Start();

	int LowPixel = 255;
	int HighPixel = 0;

	byte * ImageData = new byte[ImageSize * ImageSize * 3];
	for (int i = 0; i < ImageSize; ++ i)
	{
		for (int j = 0; j < ImageSize; ++ j)
		{
			int const Index = ImageSize * i + j;

			if (Buckets[Index].Count > 0)
			{
				double const Value = Buckets[Index].Sum / Buckets[Index].Count;
				double const Intensity = 2.5f;
				double const Bottom = 0;
				int const Pixel = 255 - Clamp<int>((int) (Value * Intensity - Bottom), 0, 255);

				LowPixel = Min(LowPixel, Pixel);
				HighPixel = Max(HighPixel, Pixel);

				ImageData[Index * 3 + 0] = Pixel;
				ImageData[Index * 3 + 1] = 0;
				ImageData[Index * 3 + 2] = 0;
			}
			else
			{
				ImageData[Index * 3 + 0] = 0;
				ImageData[Index * 3 + 1] = 0;
				ImageData[Index * 3 + 2] = 255;
			}

			if (Buckets[Index].Tag == -1)
			{
				ImageData[Index * 3 + 1] = 255;
			}
			//else if (Buckets[Index].Tag > 0)
			//{
			//	if (TagGroups[Buckets[Index].Tag].IsBridge)
			//	{
			//		ImageData[Index * 3 + 1] = ImageData[Index * 3 + 0];
			//		ImageData[Index * 3 + 0] = 0;
			//		ImageData[Index * 3 + 2] = 128;
			//	}
			//}
		}
	}

	Log::Info("Low value: %d High Value: %d", LowPixel, HighPixel);

	CImage * Image = new CImage(ImageData, vec2u(ImageSize), 3);
	Image->FlipY();
	Image->Write(OutputName);

	Log::Info("Rasterize to image took %.3f", sw.Stop());
}
void CTopographyRasterizer::RasterizeImage()
{
	CStopWatch sw;
	sw.Start();

	int LowPixel = 255;
	int HighPixel = 0;

	byte * ImageData = new byte[ImageSize * ImageSize * 3];
	for (int i = 0; i < ImageSize; ++ i)
	{
		for (int j = 0; j < ImageSize; ++ j)
		{
			int const Index = ImageSize * i + j;

			double const Value = Buckets[Index].Value;
			double const Intensity = 1.0f;
			int const Pixel = Clamp<int>((int) (Value * Intensity), 0, 255);

			LowPixel = Min(LowPixel, Pixel);
			HighPixel = Max(HighPixel, Pixel);

			ImageData[Index * 3 + 0] = Pixel;
			ImageData[Index * 3 + 1] = Pixel;
			ImageData[Index * 3 + 2] = Pixel;
			
		}
	}

	Log::Info("Low value: %d High Value: %d", LowPixel, HighPixel);

	CImage * Image = new CImage(ImageData, vec2u(ImageSize), 3);
	Image->FlipY();
	Image->Write(OutputName);

	Log::Info("Rasterize to image took %.3f", sw.Stop());
}