public void TestFusionLowPETResolution()
		{
			string testName = MethodBase.GetCurrentMethod().Name;
			using (var data = new FusionTestDataContainer(TestDataFunction.Threed,
			                                              new Vector3D(0.7f, 0.7f, 0.7f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit,
			                                              new Vector3D(1.0f, 1.0f, 1.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit))
			{
				var results = DiffFusionImages(data, testName);

				for (int n = 0; n < results.Count; n++)
					Assert.Less(results[n], 0.025, "{0}:: slice {1} exceeds difference limit.", testName, n);
			}
		}
		public void ValidateImageDifferenceEngine()
		{
			string testName = MethodBase.GetCurrentMethod().Name;
			using (var data = new FusionTestDataContainer(TestDataFunction.Threed,
			                                              new Vector3D(1.0f, 1.0f, 1.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit,
			                                              new Vector3D(1.0f, 1.0f, 1.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit))
			{
				var results = DiffFusionImages(data, testName);

				for (int n = 0; n < results.Count; n++)
					Assert.AreEqual(0, results[n], 100*double.Epsilon, "{0}:: slice {1} exceeds difference limit.", testName, n);
			}
		}
		private static IList<double> DiffFusionOperatorResults(IColorMap colorMap, bool thresholding, string testName)
		{
			var outputPath = new DirectoryInfo(Path.Combine(typeof (FusionColorCompositingTest).FullName, testName));
			if (outputPath.Exists)
				outputPath.Delete(true);
			outputPath.Create();

			// this kind of test requires that the base and overlay slices be unsigned and precisely coincident
			using (var data = new FusionTestDataContainer(
				() => TestDataFunction.GradientX.CreateSops(false, Modality.CT, new Vector3D(1.0f, 1.0f, 15.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit),
				() => TestDataFunction.GradientY.CreateSops(false, Modality.PT, new Vector3D(1.0f, 1.0f, 15.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit)))
			{
				using (var log = File.CreateText(Path.Combine(outputPath.FullName, "data.csv")))
				{
					log.WriteLine("{0}, {1}, {2}, {3}", "n", "opacity", "alpha", "diff");
					using (var baseDisplaySet = data.CreateBaseDisplaySet())
					{
						using (var overlayDisplaySet = data.CreateOverlayDisplaySet())
						{
							using (var fusionDisplaySet = data.CreateFusionDisplaySet())
							{
								var list = new List<double>();

								var imageIndex = fusionDisplaySet.PresentationImages.Count/2;
								var fusionImage = fusionDisplaySet.PresentationImages[imageIndex];

								for (int n = 0; n <= 10; n++)
								{
									var opacity = n/10f;

									SetFusionDisplayParameters(fusionImage, colorMap, opacity, thresholding);
									using (IPresentationImage referenceImage =
										Fuse(baseDisplaySet.PresentationImages[imageIndex], overlayDisplaySet.PresentationImages[imageIndex], colorMap, opacity, thresholding))
									{
										using (var referenceBmp = DrawToBitmap(referenceImage))
										{
											referenceBmp.Save(Path.Combine(outputPath.FullName, string.Format("reference{0}.png", n)));
										}

										using (var fusionBmp = DrawToBitmap(fusionImage))
										{
											fusionBmp.Save(Path.Combine(outputPath.FullName, string.Format("test{0}.png", n)));
										}

										// because the fusion display set is generated from real base images and *reformatted* overlay images,
										// there will necessarily be higher differences at the edges of the useful image area

										Bitmap diff;
										double result = ImageDiff.Compare(ImageDiffAlgorithm.Euclidian, referenceImage, fusionImage, new Rectangle(18, 18, 98, 98), out diff);
										diff.Save(Path.Combine(outputPath.FullName, string.Format("diff{0}.png", n)));
										diff.Dispose();
										log.WriteLine("{0}, {1:f2}, {2}, {3:f6}", n, opacity, (int) (255*opacity), result);
										list.Add(result);
									}
								}

								return list;
							}
						}
					}
				}
			}
		}
		private static IList<double> DiffFusionImages(FusionTestDataContainer data, string testName)
		{
			var outputPath = new DirectoryInfo(Path.Combine(typeof (FusionLayerCoregistrationTests).FullName, testName));
			if (outputPath.Exists)
				outputPath.Delete(true);
			outputPath.Create();

			using (var log = File.CreateText(Path.Combine(outputPath.FullName, "data.csv")))
			{
				// if the overlay image is not rendered at all, this coregistration test would pass, but then the color compositing test would fail
				using (var referenceDisplaySet = data.CreateBaseDisplaySet())
				{
					using (var testDisplaySet = data.CreateFusionDisplaySet())
					{
						var list = new List<double>();
						int index = 0;
						foreach (var testImage in testDisplaySet.PresentationImages)
						{
							var referenceImage = referenceDisplaySet.PresentationImages[index];
							NormalizePresentationImageDisplay(testImage);
							NormalizePresentationImageDisplay(referenceImage);

							Bitmap diff;
							double result = ImageDiff.Compare(ImageDiffAlgorithm.Euclidian, referenceImage, testImage, out diff);
							diff.Save(Path.Combine(outputPath.FullName, string.Format("diff{0:000}.png", index)));
							diff.Dispose();
							log.WriteLine("{0}, {1:f6}", index, result);
							list.Add(result);

							++index;
						}

						return list;
					}
				}
			}
		}
		public void TestFusionAnisotropicSpecialCase4Test()
		{
			Assert.Ignore(_anisotropicPixelAspectRatioMPRSupport);

			string testName = MethodBase.GetCurrentMethod().Name;
			using (var data = new FusionTestDataContainer(TestDataFunction.Threed,
			                                              new Vector3D(0.8f, 0.9f, 1.0f), Vector3D.xUnit, Vector3D.yUnit, Vector3D.zUnit,
			                                              new Vector3D(0.9f, 1.0f, 0.8f), Vector3D.yUnit, Vector3D.zUnit, Vector3D.xUnit))
			{
				var results = DiffFusionImages(data, testName);

				for (int n = 0; n < results.Count; n++)
					Assert.Less(results[n], 0.025, "{0}:: slice {1} exceeds difference limit.", testName, n);
			}
		}