public void Render() { var halfWidth = _width / 2; var halfHeight = _height / 2; // cast a ray against each pixel on the canvas for (var y = -halfHeight; y < halfHeight; y++) { for (var x = -halfWidth; x < halfWidth; x++) { List <Hit> hits = CastRay(x, y); // Check if we did hit something if (hits.Count == 0) { continue; } Color lightColor = CalculateLight(hits[0]); _canvas.SetPixel(x + _width / 2, y + _height / 2, lightColor); } } // Save the result into a bitmap PPM.SaveCanvas(_canvas, "RtTest"); }
public static void WritePPM(this PPM image) { var complete = Path.Combine(projectPath, "Output\\"); Directory.CreateDirectory(complete); using (FileStream fileStream = File.OpenWrite(Path.Combine(complete, $"{image.FileName}"))) { var R = image.RGBMatrix.R; var G = image.RGBMatrix.G; var B = image.RGBMatrix.B; fileStream.Write(Encoding.ASCII.GetBytes("P3\n")); fileStream.Write(Encoding.ASCII.GetBytes("\n")); fileStream.Write(Encoding.ASCII.GetBytes($"{image.Width} {image.Height}\n")); fileStream.Write(Encoding.ASCII.GetBytes($"{image.MaxValue}\n")); for (int i = 0; i < image.Height; i++) { for (int j = 0; j < image.Width; j++) { fileStream.Write(Encoding.ASCII.GetBytes($"{R[i, j]}\n")); fileStream.Write(Encoding.ASCII.GetBytes($"{G[i, j]}\n")); fileStream.Write(Encoding.ASCII.GetBytes($"{B[i, j]}\n")); } } } }
public static void TestRender(int spp, int height) { var w = BuildWorld(); var aspectRatio = 3f / 2; var width = (int)(aspectRatio * height); // var height = 800; var canvas = new Canvas(width, height); var pps = new PerPixelSampler(spp); var camera = new ApertureCamera(MathF.PI / 3f, 3f / 2, 0.05f, new Point(0, 1.25f, -4f), new Point(0, 1, 0), Vectors.Up, 3.5f); var cws = new ComposableWorldSampler(2, 16, GGXNormalDistribution.Instance, GGXSmithGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps)); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); ctx.Render(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "scene"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
private void ME_ToggledOn() { if (GlobalResources.UserInputMonitoringChecked) { User_Input_Monitoring.InitialiseUserInputMonitoring(); } if (GlobalResources.ProcessMonitoring) { Process_Monitoring.InitialiseProcessMonitoring(); } if (GlobalResources.FileSystemMonitoring) { File_System_Monitoring.InitialiseFileSystemMonitoring(); } if (GlobalResources.ProcessPortMapper) { PPM.InitializePPM(); } if (GlobalResources.WindowsServices) { WindowsServices.InitializePPM(); } if (GlobalResources.ApplicationsMonitoring) { Applications_Monitoring.InitializeApplicationMonitoring(); } GlobalResources.ITurnedOnMonitoringEngine(); GlobalResources.IInitiatedSettingsUpdate(); }
public void EndsInNewLineChar() { var c = new Canvas(10, 2); c.SetAllPixels(new Color(1f, 0.8f, 0.6f)); var ppm = PPM.CanvasToPPM(c); ppm.Should().EndWith(Environment.NewLine); }
public void MustBePPMTypeThreeToImport() { var ppm = @"P32 1 1 255 0 0 0"; var action = new Action(() => PPM.Parse(ppm)); action.Should().Throw <FileLoadException>(); }
public void ProperHeader() { var c = new Canvas(5, 3); var ppm = PPM.CanvasToPPM(c); var lines = ppm.Split(new[] { Environment.NewLine }, StringSplitOptions.None); lines[0].Should().Be("P3"); lines[1].Should().Be("5 3"); lines[2].Should().Be("255"); }
public static void MappingTestRender() { Cube Cube(float rotY, float rotX, float tx, float ty) { var cube1 = new Cube { Material = { Texture = CreateTestCubeMap(), Roughness = 1f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) } }; cube1.SetTransform(Transform.RotateY(rotY).RotateX(rotX).Translate(tx, ty, 0)); return(cube1); } var g = new Group(); g.AddChild(Cube(0.7854f, 0.7854f, -6, 2)); g.AddChild(Cube(2.3562f, 0.7854f, -2, 2)); g.AddChild(Cube(3.927f, 0.7854f, 2, 2)); g.AddChild(Cube(5.4978f, 0.7854f, 6, 2)); g.AddChild(Cube(0.7854f, -0.7854f, -6, -2)); g.AddChild(Cube(2.3562f, -0.7854f, -2, -2)); g.AddChild(Cube(3.927f, -0.7854f, 2, -2)); g.AddChild(Cube(5.4978f, -0.7854f, 6, -2)); g.Divide(1); var w = new World(); w.SetLights(new PointLight(new Point(0, 2, -100), Colors.White)); w.SetObjects(g); var width = 800; var height = 400; var from = new Point(0, 0, -20f); var to = new Point(0, 0, 0); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(16); var fov = 0.8f; var aspectRatio = (float)width / height; var transform = Transform.LookAt(from, to, new Vector(0, 1, 0)); var camera = new PinholeCamera(transform, fov, aspectRatio); var cws = new PhongWorldShading(1, w); var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps)); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); ctx.Render(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "mapping"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
// We use it instead of direct PPM.DecodeChar call to be sure that // we reset PPM structures in case of corrupt data. It is important, // because these structures can be invalid after PPM.DecodeChar returned -1. int SafePPMDecodeChar() { int Ch = PPM.DecodeChar(); if (Ch == -1) // Corrupt PPM data found. { PPM.CleanUp(); // Reset possibly corrupt PPM data structures. UnpBlockType = BLOCK_LZ; // Set faster and more fail proof LZ mode. } return(Ch); }
private List <double> CreateSVMMatrices() { List <double> matrixes = new List <double>(); int Peptide = 0; if (PeptideSequence != null && PeptideSequence != "") { Peptide = 1; } int fuc = 1; int CoreYPeaks = CoreIDPeak.Count; float CoreYScore = CoreScore; if (!IUPACString.EndsWith("(DeHex-)HexNAc")) { CoreYPeaks = CoreIDPeak.Count - CoreIDPeak.Where(x => x.Item2.Contains("deHex")).ToList().Count; foreach (var core in CoreIDPeak.Where(x => x.Item2.EndsWith("(DeHex-)HexNAc"))) { CoreYScore -= core.Item1.Intensity; } fuc = 0; } matrixes.Add(Peptide); matrixes.Add(fuc); matrixes.Add(NoOfTotalGlycan); matrixes.Add(Convert.ToDouble(PPM.ToString("0.000"))); //matrixes.Add(CoreYPeaks); //matrixes.Add(Convert.ToDouble(CoreYScore.ToString("0.000"))); matrixes.Add(BranchIDPeak.Count); matrixes.Add(Convert.ToDouble(BranchScore.ToString("0.000"))); var CorePeaks = CoreIDPeak.Where(x => x.Item2 == "HexNAc").ToList(); matrixes.Add(Convert.ToDouble(CorePeaks.Count != 0 ? CorePeaks[0].Item1.Intensity.ToString("0.0000") : "0")); CorePeaks = CoreIDPeak.Where(x => x.Item2 == "HexNAc-HexNAc").ToList(); matrixes.Add(Convert.ToDouble(CorePeaks.Count != 0 ? CorePeaks[0].Item1.Intensity.ToString("0.0000") : "0")); CorePeaks = CoreIDPeak.Where(x => x.Item2 == "HexNAc-HexNAc-Hex").ToList(); matrixes.Add(Convert.ToDouble(CorePeaks.Count != 0 ? CorePeaks[0].Item1.Intensity.ToString("0.0000") : "0")); CorePeaks = CoreIDPeak.Where(x => x.Item2 == "HexNAc-HexNAc-Hex-Hex").ToList(); matrixes.Add(Convert.ToDouble(CorePeaks.Count != 0 ? CorePeaks[0].Item1.Intensity.ToString("0.0000") : "0")); CorePeaks = CoreIDPeak.Where(x => x.Item2 == "HexNAc-HexNAc-Hex-(Hex-)Hex").ToList(); matrixes.Add(Convert.ToDouble(CorePeaks.Count != 0 ? CorePeaks[0].Item1.Intensity.ToString("0.0000") : "0")); //if (MatchWithPrecursorMW) //{ // matrixes.Add(1); //} //else //{ // matrixes.Add(0); //} return(matrixes); }
public void HandlesColorDataOnDifferentLines() { var ppm = @"P3 1 1 255 51 153 204"; var canvas = PPM.Parse(ppm); canvas.PixelAt(0, 0).Should().Be(new Color(0.2f, 0.6f, 0.8f)); }
public void Load(string path, bool isPPM) { if (isPPM) { PPM ppm = PPM.LoadImage(path); LoadFromPPM(ppm); } else { Bitmap bitMap = new Bitmap(path); LoadFromBitmap(bitMap); } }
public void SplitsLongLines() { var c = new Canvas(10, 2); c.SetAllPixels(new Color(1f, 0.8f, 0.6f)); var ppm = PPM.CanvasToPPM(c); var lines = ppm.Split(new[] { Environment.NewLine }, StringSplitOptions.None); lines[3].Should().Be("255 204 153 255 204 153 255 204 153 255 204 153 255 204 153 255 204"); lines[4].Should().Be("153 255 204 153 255 204 153 255 204 153 255 204 153"); lines[5].Should().Be("255 204 153 255 204 153 255 204 153 255 204 153 255 204 153 255 204"); lines[6].Should().Be("153 255 204 153 255 204 153 255 204 153 255 204 153"); }
public void PPMPixelData() { var c = new Canvas(5, 3); c.WritePixel(new Color(1.5f, 0f, 0f), 0, 0); c.WritePixel(new Color(0f, 0.5f, 0f), 2, 1); c.WritePixel(new Color(-0.5f, 0f, 1f), 4, 2); var ppm = PPM.CanvasToPPM(c); var lines = ppm.Split(new[] { Environment.NewLine }, StringSplitOptions.None); lines[3].Should().Be("255 0 0 0 0 0 0 0 0 0 0 0 0 0 0"); lines[4].Should().Be("0 0 0 0 0 0 0 128 0 0 0 0 0 0 0"); lines[5].Should().Be("0 0 0 0 0 0 0 0 0 0 0 0 0 0 255"); }
public void CreatesCanvasWithProperDimensions() { var ppm = @"P3 10 2 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; var canvas = PPM.Parse(ppm); canvas.Width.Should().Be(10); canvas.Height.Should().Be(2); }
private void LoadFromPPM(PPM ppm) { hres = ppm.Width; vres = ppm.Height; for (int y = 0; y < vres; y++) { for (int x = 0; x < hres; x++) { Vec3 c = ppm.GetColorv(x, y); pixels.Add(c); } } }
public void ProperlyScalesPixelColor() { var ppm = @"P3 4 3 255 255 127 0 0 127 255 127 255 0 255 255 255 0 0 0 255 0 0 0 255 0 0 0 255 255 255 0 0 255 255 255 0 255 127 127 127"; var canvas = PPM.Parse(ppm); canvas.PixelAt(0, 0).Should().Be(new Color(1, 0.498f, 0)); canvas.PixelAt(3, 0).Should().Be(new Color(1, 1, 1)); canvas.PixelAt(2, 1).Should().Be(new Color(0, 1, 0)); canvas.PixelAt(0, 2).Should().Be(new Color(1, 1, 0)); canvas.PixelAt(3, 2).Should().Be(new Color(0.498f, 0.498f, 0.498f)); }
public void HandlesComments() { var ppm = @"P3 # this is a comment 2 1 # this, too 255 # another comment 255 255 255 # oh, no, comments in the pixel data! 255 0 255"; var canvas = PPM.Parse(ppm); canvas.PixelAt(0, 0).Should().Be(new Color(1, 1, 1)); canvas.PixelAt(1, 0).Should().Be(new Color(1, 0, 1)); }
public void RaycastTest() { const int canvasPixels = 100; var canvas = new Canvas(canvasPixels, canvasPixels); var s = new Sphere { Material = { Texture = new SolidColor(new Color(0.4f, 0.2f, 1)) } }; var light = new PointLight(new Point(-10, 10, -10), new Color(1f, 1f, 1f)); //var t = Transforms.Shear(0.1f, 0, 0, 0, 0, 0).Scale(0.9f, 1f, 1f); //s.SetTransform(t); var rayOrigin = new Point(0f, 0f, -5f); const float wallZ = 10f; const float wallSize = 7.0f; const float pixelSize = wallSize / canvasPixels; const float half = wallSize / 2; for (var y = 0; y < canvasPixels; y++) { var worldY = half - pixelSize * y; for (var x = 0; x < canvasPixels; x++) { var worldX = -half + pixelSize * x; var position = new Point(worldX, worldY, wallZ); var r = new Ray(rayOrigin, (position - rayOrigin).Normalize()); var xs = s.Intersects(r); var hit = xs.Hit(); if (!hit.HasValue) { continue; } var point = r.Position(hit.Value.T); var shape = hit.Value.Geometry; var normal = shape.NormalAt(point, hit.Value); var eye = -r.Direction; var color = PhongShading.Lighting(shape.Material, shape, light, point, eye, normal, 1); canvas.WritePixel(color, x, y); } } PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "raycast"); }
public static List <Block> SplitInBlocks(this PPM image, StorageType type, double[,] matrix) { List <Block> encoded = new List <Block>(); for (int i = 0; i < image.Height; i += 8) { for (int j = 0; j < image.Width; j += 8) { Block store = SubMatrix(type, i, j, matrix); if (type == StorageType.Y) { encoded.Add(store); } else { encoded.Add(store.BlockAverage420()); } } } return(encoded); }
public void ProjectileTest() { var start = new Point(0, 1, 0); var vel = new Vector(1f, 1.8f, 0f).Normalize() * 11.25f; var p = new Projectile(start, vel); var w = new SimWorld(new Vector(0f, -0.1f, 0f), new Vector(-0.01f, 0, 0)); var c = new Canvas(900, 550); var(x, y) = p.ToXY(); y = 550 - y; var red = new Color(1f, 0f, 0f); while (c.IsInBounds(x, y)) { c.WritePixel(red, x, y); p = p.Tick(w); (x, y) = p.ToXY(); y = 550 - y; } PPM.ToFile(c, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "projectile"); }
public Image(String [] args) //throws FileNotFoundException, IOException { : base(args, 200, 80) { about("0.1", "test image output of XBM, XPM, and PPM format", "Stephen Tse <*****@*****.**>", "http://escher.sourceforge.net/"); if (help_option) { return; } Console.Write("Loading images...."); xbm = new XBM(display, 32, 32, xbm_data); xpm = new XPM(display, xpm_data); StreamReader ppm_file = new StreamReader("etc/image.pnm"); ppm = new PPM(display, ppm_file); Console.WriteLine("done."); }
public void ReturnsColorByUV() { var ppm = @"P3 10 10 10 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 0 0 0 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 0 0 0 1 1 1 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 0 0 0 1 1 1 2 2 2 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 0 0 0 1 1 1 2 2 2 3 3 3 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 6 6 6 7 7 7 8 8 8 9 9 9 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 7 7 7 8 8 8 9 9 9 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 8 8 8 9 9 9 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 9 9 9 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 "; var canvas = PPM.Parse(ppm); var pattern = new UVImage(canvas); pattern.ColorAt(new UVPoint(0f, 0f)).Should().Be(new Color(0.9f, 0.9f, 0.9f)); pattern.ColorAt(new UVPoint(0.3f, 0f)).Should().Be(new Color(0.2f, 0.2f, 0.2f)); pattern.ColorAt(new UVPoint(0.6f, 0.3f)).Should().Be(new Color(0.1f, 0.1f, 0.1f)); pattern.ColorAt(new UVPoint(1f, 1f)).Should().Be(new Color(0.9f, 0.9f, 0.9f)); }
public static void SolidTestRender(int spp) { Console.WriteLine("Loading file..."); var filePath = Path.Combine(GetExecutionPath(), "neon_env.ppm"); //var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm"); Console.WriteLine("Parsing file..."); var textureCanvas = PPM.ParseFile(filePath); var image = new UVImage(textureCanvas); var map = new TextureMap(image, UVMapping.Spherical); var skySphere = new Sphere { Material = { Texture = map, Ambient = 1.0f, CastsShadows = false, Transparency = 0f, Roughness = 1f, SpecularColor = new Color(0.0f, 0.0f, 0.0f) } }; skySphere.SetTransform(Transform.RotateY(3.3f).Scale(1000f)); var radius = 0.25f; var red = new Material { Texture = new SolidColor(new Color(1, 0, 0)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var blue = new Material { Texture = new SolidColor(new Color(0, 0, 1)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var yellow = new Material { Texture = new SolidColor(new Color(1, 1, 0)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var white = new Material { Texture = new SolidColor(new Color(1, 1, 1)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var blackPip = new Material { Texture = new SolidColor(new Color(0.1f, 0.1f, 0.1f)), Ambient = 0.0f, Roughness = 0.8f, Metallic = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f) }; var whitePip = new Material { Texture = new SolidColor(new Color(0.95f, 0.95f, 0.95f)), Ambient = 0.0f, Roughness = 0.8f, Metallic = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f) }; var d1 = CutPips(RoundedCube(radius, blue), whitePip); var d2 = CutPips(RoundedCube(radius, red), whitePip); var d3 = CutPips(RoundedCube(radius, white), blackPip); var d4 = CutPips(RoundedCube(radius, yellow), blackPip); d1.SetTransform(Transform.RotateY(-2.2f).TranslateY(1f).Scale(0.5f)); d2.SetTransform(Transform.RotateZ(MathF.PI / 2f).TranslateY(1f).TranslateX(2f).TranslateZ(1f).Scale(0.5f)); d3.SetTransform(Transform.RotateY(0.5f).TranslateY(1f).TranslateX(-4f).TranslateZ(1f).Scale(0.5f)); d4.SetTransform(Transform.RotateY(-0.2f).TranslateY(3f).TranslateX(0.2f).TranslateZ(1.25f).Scale(0.5f)); var lightGray = new Color(0.48f, 0.48f, 0.48f); var darkGray = new Color(0.15f, 0.15f, 0.15f); //var s1 = new StripeTexture(lightGray, darkGray); //var s2 = new StripeTexture(lightGray, darkGray); //s2.SetTransform(Transforms.RotateY(MathF.PI / 2)); //var pattern = new BlendedCompositeTexture(s1, s2); //pattern.SetTransform(Transforms.Scale(1f / 20f)); var pattern = new CheckerTexture(lightGray, darkGray); pattern.SetTransform(Transform.Scale(1f / 20f)); var floor = new Cube { Material = { Texture = pattern, Roughness = 0.5f, Specular = 0.1f, Diffuse = 0.3f, Reflective = 0.15f, SpecularColor = new Color(0.3f, 0.3f, 0.3f), Ambient = 0f } }; floor.SetTransform(Transform.TranslateY(-1f).Scale(20f)); var g = new Group(d1, d2, d3, d4, floor, skySphere); g.Divide(1); var w = new World(); w.SetLights(new AreaLight(new Point(-8, 10, -10), new Vector(12f, 0, 0), 6, new Vector(0, 0f, -10f), 3, new Color(1.1f, 1.1f, 1.1f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new PointLight(new Point(-8, 10, -10), new Color(0.9f, 0.9f, 0.9f))); //w.SetLights(new AreaLight(new Point(-3, 6, -4), new Vector(1f, 0, 0), 3, new Vector(0, 1f, 0), 3, // new Color(1.4f, 1.4f, 1.4f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new AreaLight(new Point(-10, 10, -10), new Vector(1,0,0), 4, new Vector(0,1,0), 3, Colors.White)); w.SetObjects(g); //var width = 600; //var height = 400; //var transform = Transforms.View(new Point(0, 1.5f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0)); //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height); //var ws = new ComposableWorldShading(2, GGXNormalDistribution.Instance, SchlickBeckmanGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); ////var ws = new PhongWorldShading(2, w); //var scene = new Scene(c, ws); ////var aaa = new AdaptiveRenderer(2, 0.01f, scene); //var aaa = new SamplesPerPixelRenderer(24, scene); //var canvas = new Canvas(width, height); var width = 600; var height = 400; var from = new Point(0, 1.5f, -5f); var to = new Point(0, 1, -0.5f); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(spp); var fov = MathF.PI / 3f; var aspectRatio = (float)width / height; var camera = new ApertureCamera(fov, aspectRatio, 0.15f, from, to, Vectors.Up); //var transform = Transforms.View(from, to, new Vector(0, 1, 0)); //var camera = new PinholeCamera2(transform, fov, aspectRatio); //var cws = new PhongWorldShading2(4, w); var cws = new ComposableWorldSampler(2, 4, GGXNormalDistribution.Instance, SchlickBeckmanGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps)); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); ctx.Render(); // RenderContext.Render(canvas, aaa); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "solid"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
private static World BuildWorld() { Console.WriteLine("Loading file..."); var filePath = Path.Combine(GetExecutionPath(), "indoor_env.ppm"); //var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm"); Console.WriteLine("Parsing file..."); var textureCanvas = PPM.ParseFile(filePath); var image = new UVImage(textureCanvas); var map = new TextureMap(image, UVMapping.Spherical); var skySphere = new Sphere { Material = { Texture = map, Ambient = 1.5f, CastsShadows = false, Transparency = 0f, Roughness = 1f, SpecularColor = new Color(0.0f, 0.0f, 0.0f) } }; //skySphere.SetTransform(Transforms.RotateY(3.4f).Scale(1000f)); skySphere.SetTransform(Transform.RotateY(3.3f).Scale(10000f)); var s1 = new StripeTexture(Colors.White, Colors.Black); var s2 = new StripeTexture(Colors.White, Colors.Black); s2.SetTransform(Transform.RotateY(MathF.PI / 2)); var pattern = new BlendedCompositeTexture(s1, s2); pattern.SetTransform(Transform.Scale(1f / 20f)); var testPattern = new UVAlignTestPattern(Colors.White, Colors.Red, Colors.Yellow, Colors.Green, Colors.Blue); var testMap = new TextureMap(testPattern, UVMapping.Cylindrical); //var stripe = new StripePattern(new Color(0.9f, 0, 0), new Color(0.0f, 0.0f, 0.9f)); //stripe.SetTransform(Transforms.Scale(0.25f, 0.25f, 0.25f).RotateY(MathF.PI / 4)); //var perlin = new PerlinRippleCompositePattern(stripe, 0.8f); //perlin.SetTransform(Transforms.Scale(0.1f, 0.1f, 0.1f)); var worldFilePath = Path.Combine(GetExecutionPath(), "world.ppm"); var worldCanvas = PPM.ParseFile(worldFilePath); var worldTexture = new UVImage(worldCanvas); var worldPattern = new TextureMap(worldTexture, UVMapping.Spherical); var floor = new Cube { Material = { Texture = pattern, Specular = 0.1f, Reflective = 0.1f, Roughness = 0.22f, Ambient = 0f, SpecularColor = new Color(0.1f, 0.1f, 0.1f) } }; floor.SetTransform(Transform.TranslateY(-1).Scale(20f)); var middle = new Sphere { Material = { Texture = worldPattern, Diffuse = 0.7f, Specular = 1f, Reflective = 0.4f, Shininess = 600, Roughness = 0.2f, Metallic = 0.3f, SpecularColor = new Color(0.1f,0.2f, 0.5f), Ambient = 0f } }; middle.SetTransform(Transform.RotateY(1.5f).Translate(-0.5f, 1f, 0.1f)); var right = new Sphere { Material = { Texture = new TextureMap(new UVCheckers(20, 10, Colors.Black, Colors.White), UVMapping.Spherical), Roughness = 0.5f, Diffuse = 0.7f, Specular = 0.3f, Reflective = 0.2f, Ambient = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f) } }; right.SetTransform(Transform.Translate(0.25f, 0.25f, -1f) * Transform.Scale(0.25f)); var rightPlastic = new Sphere { Material = { Texture = new SolidColor(new Color(1f, 0.0f, 0.0f)), SpecularColor = new Color(0.2f, 0.2f, 0.2f), Roughness = 0.25f, Metallic = 0f, Ambient = 0.0f } }; rightPlastic.SetTransform(Transform.Translate(-0.15f, 0.15f, -0.91f) * Transform.Scale(0.15f)); var left = new Sphere { Material = { Texture = new SolidColor(new Color(0.85f, 0.85f, 0.90f)), SpecularColor = new Color(0.3f, 0.3f, 0.3f), Roughness = 0.10f, Metallic = 0.6f, Transparency = 0.95f, RefractiveIndex = 1.52f,Ambient = 0.0f } }; left.SetTransform(Transform.Translate(-1.3f, 0.30f, -0.75f) * Transform.Scale(0.30f)); // left.SetTransform(Transforms.Translate(-2.1f, 0.33f, 0.5f) * Transforms.Scale(0.33f, 0.33f, 0.33f)); var leftChrome = new Sphere { Material = { Texture = new SolidColor(new Color(0.9f, 0.9f, 0.95f)), Diffuse = 0.05f, Specular = 0.9f, SpecularColor = new Color(0.9f, 0.9f, 0.95f), Roughness = 0.55f, Metallic = 1f, Transparency = 0, RefractiveIndex = 1.52f,Reflective = 1.4f, Ambient = 0.0f, Shininess = 300 } }; leftChrome.SetTransform(Transform.Translate(-0.95f, 0.15f, -1.1f) * Transform.Scale(0.15f)); var cube = new Cube { Material = { Texture = new GradientTexture(new Color(1f, 0, 0), new Color(1f, 0.8f, 0f)), Roughness = 0.5f, Ambient = 0f, SpecularColor = new Color(0.2f,0.2f, 0.2f) } }; cube.Material.Texture.SetTransform(Transform.TranslateX(-0.5f).Scale(2f).RotateZ(MathF.PI / 2f)); cube.SetTransform(Transform.RotateY(MathF.PI / 4f).Translate(2.5f, 1f, 3.6f).Scale(1f, 1f, 1f)); var cone = new Cone { IsClosed = true, Minimum = -1f, Maximum = 0f, Material = { Texture = new SolidColor(new Color(0.4f, 0.8f, 0.1f)), Diffuse = 0.7f, Specular = 0.3f, Ambient = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f), Roughness = 0.6f, Reflective = 0.2f } }; cone.SetTransform(Transform.Scale(0.6f, 2f, 0.6f).Translate(1.5f, 2.0f, 0)); var cylinder = new Cylinder { Minimum = 0f, Maximum = 3f, IsClosed = true, Material = { Reflective = 0.33f, Specular = 0.9f, Diffuse = 0.1f, Ambient = 0.0f, Shininess = 100, Metallic = 0.76f, SpecularColor = new Color(0.9f, 0.8f, 0.7f), Roughness = 0.02f, Texture = testMap } }; cylinder.SetTransform(Transform.Translate(-3f, 0f, 3.5f)); //var t = new Triangle(new Point(0, 0, 0), new Point(1, 0.5f, 0), new Point(0.5f, 1f, 1f)) //{ // Material = {Texture = new GradientTexture(new Color(0f, 1, 0), new Color(0f, 0f, 1f))} //}; //t.SetTransform(Transforms.Translate(1f, 2f, 1f)); var ringMaterial = new Material { Texture = new SolidColor(new Color(1f, 0.8f, 0f)), Reflective = 0.4f, RefractiveIndex = 0.95f, Roughness = 0.12f, Metallic = 1f, SpecularColor = new Color(0.9f, 0.7f, 0f), //Transparency = 0.95f, Shininess = 300, Specular = 0.9f, Ambient = 0.0f, Diffuse = 0.3f }; var co = new Cylinder { Minimum = -0.01f, Maximum = 0.01f, IsClosed = true }; co.SetTransform(Transform.Scale(1.5f, 1f, 1.5f)); co.SetMaterial(ringMaterial); var ci = new Cylinder { Minimum = -0.1f, Maximum = 0.1f, IsClosed = true }; ci.SetTransform(Transform.Scale(1.2f, 1f, 1.2f)); ci.SetMaterial(ringMaterial); var s = new ConstructiveSolid(ConstructiveOp.Difference, co, ci); s.SetTransform(Transform.RotateZ(-0.2f).RotateX(-0.1f).Translate(-0.5f, 1f, 0.1f)); var gl = new Group(); gl.AddChild(middle); gl.AddChild(left); gl.AddChild(leftChrome); gl.AddChild(cylinder); gl.AddChild(s); gl.AddChild(right); gl.AddChild(rightPlastic); gl.AddChild(cube); gl.AddChild(cone); //gl.AddChild(t); gl.AddChild(floor); gl.AddChild(skySphere); gl.Divide(1); var w = new World(); w.SetLights(new AreaLight(new Point(-80f, 80, -60), new Vector(100f, 0, 0), 6, new Vector(0, 0f, -10f), 3, new Color(1.8f, 1.8f, 1.8f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new PointLight(new Point(-3.5f, 4f, -5f), new Color(0.9f, 0.9f, 0.9f))); w.SetObjects(gl); return(w); }
public static void TeapotTest() { Console.WriteLine("Loading file..."); var filePath = Path.Combine(GetExecutionPath(), "indoor_env.ppm"); //var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm"); Console.WriteLine("Parsing file..."); var textureCanvas = PPM.ParseFile(filePath); var image = new UVImage(textureCanvas); var map = new TextureMap(image, UVMapping.Spherical); var skySphere = new Sphere { Material = { Texture = map, Ambient = 2.5f, CastsShadows = false, Transparency = 0f, Roughness = 1f, SpecularColor = new Color(0.0f, 0.0f, 0.0f) } }; //skySphere.SetTransform(Transforms.RotateY(3.4f).Scale(1000f)); skySphere.SetTransform(Transform.RotateY(3.3f).Scale(10000f)); var path = Path.Combine(GetExecutionPath(), "teapot.obj"); Console.WriteLine("Loading file {0}...", path); var data = ObjFile.ParseFile(path); Console.WriteLine("File parsed..."); var triangulated = data.Groups[0]; triangulated.SetTransform(Transform.Scale(0.10f).RotateX(-MathF.PI / 2f).RotateY(MathF.PI / 8f)); var glass = new Material { Texture = new SolidColor(new Color(0.8f, 1f, 0.9f)), Reflective = 0.78f, Roughness = 0.35f, Metallic = 0.65f, SpecularColor = new Color(0.7f, 0.9f, 0.8f), RefractiveIndex = 1.52f, Transparency = 0.80f, Ambient = 0.0f, Diffuse = 0.2f, Shininess = 200f, Specular = 0.9f }; ApplyMaterialToChildren(triangulated, glass); var checkerboard = new Material { Texture = new CheckerTexture(new Color(0.95f, 0.95f, 0.95f), new Color(0.8f, 0.05f, 0.05f)), Metallic = 0.4f, SpecularColor = new Color(0.3f, 0.3f, 0.3f), Reflective = 0.5f, Roughness = 0.1f, Ambient = 0.0f, Diffuse = 0.3f }; checkerboard.Texture.SetTransform(Transform.Scale(0.125f)); var group = new Group(); var floor = new Cube(); floor.SetMaterial(checkerboard); floor.SetTransform(Transform.TranslateY(-1).Scale(5f)); group.AddChild(floor); group.AddChild(triangulated); group.AddChild(skySphere); group.Divide(1); var w = new World(); w.SetLights(new AreaLight(new Point(-80f, 80, -60), new Vector(100f, 0, 0), 6, new Vector(0, 0f, -10f), 3, new Color(1.8f, 1.8f, 1.8f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new PointLight(new Point(-30, 30, -30), new Color(1.4f, 1.4f, 1.4f))); w.SetObjects(group); //var width = 600; //var height = 400; //var transform = Transforms.View(new Point(0, 3.0f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0)); //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height); ////var ws = new ComposableWorldShading(3, GGXNormalDistribution.Instance, SchlickBeckmanGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); //var ws = new PhongWorldShading(5, w); //var scene = new Scene(c, ws); //var aaa = new AdaptiveRenderer(3, 0.05f, scene); //var canvas = new Canvas(width, height); var width = 600; var height = 400; var from = new Point(0, 2.5f, -2.5f); var to = new Point(0.25f, 0.5f, 0); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(10); var fov = MathF.PI / 3f; var aspectRatio = (float)width / height; var transform = Transform.LookAt(from, to, new Vector(0, 1, 0)); //var camera = new PinholeCamera(transform, fov, aspectRatio); var camera = new ApertureCamera(fov, aspectRatio, 0.08f, from, to, Vectors.Up); // var cws = new PhongWorldShading(5, w); var cws = new ComposableWorldSampler(2, 16, GGXNormalDistribution.Instance, GGXSmithGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps)); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); //RenderContext.Render(canvas, aaa); ctx.Render(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "teapot"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
public static void LowPolyTeapotTest() { var path = Path.Combine(GetExecutionPath(), "teapot-low.obj"); var data = ObjFile.ParseFile(path); var triangulated = data.Groups[0]; triangulated.SetTransform(Transform.Scale(0.1f).RotateX(-MathF.PI / 2f)); var material = new Material { Texture = new SolidColor(new Color(0.3f, 0.3f, 1f)), Reflective = 0.4f, Ambient = 0.2f, Diffuse = 0.3f }; var floor = new Cube(); floor.SetMaterial(material); var fg = new Group(); fg.AddChild(floor); fg.SetTransform(Transform.TranslateY(-1).Scale(1f)); var g = new Group(fg, triangulated); g.Divide(1); var w = new World(); w.SetLights(new PointLight(new Point(-10, 10, -10), Colors.White)); w.SetObjects(g); //var width = 300; //var height = 200; //var transform = Transforms.View(new Point(0, 1.5f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0)); //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height); //var scene = new Scene(c, new PhongWorldShading(1, w)); //var canvas = new Canvas(width, height); var width = 300; var height = 200; var from = new Point(0, 1.5f, -5f); var to = new Point(0, 1, 0); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(3); var fov = MathF.PI / 3f; var aspectRatio = (float)width / height; var transform = Transform.LookAt(from, to, new Vector(0, 1, 0)); var camera = new PinholeCamera(transform, fov, aspectRatio); var cws = new PhongWorldShading(1, w); var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps)); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); //RenderContext.Render(canvas, scene); ctx.Render(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "teapot"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
//public static List<BYCZIons> CalculateBYCZIon(string Sequence, MassSpectrometry.SuperSpectrum spectrum, List<ModificationList> AllValidationModifications = null, double MatchTolerance = 0.00, SortedList<char, double> aa = null, bool isauto = false, Dictionary<double, double> CurrentMonomasses = null) //{ // return CalculateBYCZIon(Sequence, spectrum) //} /// <summary> /// Calcaulate all the b and y ions using a given sequence. /// And compare it to the Monomasses already present. /// </summary> /// <param name="Sequence"></param> /// <param name="Monomasses"></param> /// <returns></returns> public static List <BYCZIons> CalculateBYCZIon(string Sequence, List <double> Monomasses, double ParentMass, string ActivationType, List <ModificationList> AllValidationModifications = null, double MatchTolerance = 0.00, SortedList <char, double> aa = null, bool isauto = false, Dictionary <double, double> CurrentMonomasses = null) { List <BYCZIons> AllIons = new List <BYCZIons>(); if (string.IsNullOrWhiteSpace(Sequence)) { return(AllIons); // some simple validation. If there is no valid sequence, there are no ions, so return the empty list. } AminoAcids = aa ?? AminoAcids; Monomasses = Monomasses.OrderBy(a => a).ToList(); if (AllValidationModifications == null) { AllValidationModifications = App.AllValidationModifications; } if (MatchTolerance == 0.00) { MatchTolerance = Properties.Settings.Default.MatchTolerancePPM; } double ion = new double(); double cion = new double(); cion = Molecules.Ammonia; //if (!isauto) { if (ParentMass == 0.0) { ParentMass = LocalParentMass; } Monomasses.Add(ParentMass); Monomasses = Monomasses.Where(a => a <= ParentMass).OrderBy(a => a).ToList(); } string[] splitstring = { "[", "]" }; List <string> sequences = Sequence.Replace("(", "").Replace(")", "").Trim().Split(splitstring, StringSplitOptions.RemoveEmptyEntries).ToList(); int count = 1; Regex regex = new Regex(@"^[0-9\.\+\-]+$"); Regex regexlwrcs = new Regex(@"[a-z]+$"); //bool number = false; string tempseq = string.Empty; if (regex.IsMatch(sequences[0])) { ion = Convert.ToDouble(sequences[0]); cion = cion + Convert.ToDouble(sequences[0]); } for (int i = 0; i < sequences.Count; i++) { string seq = sequences[i]; if (i < sequences.Count) { if ((regex.IsMatch(seq)) || AllValidationModifications.Any(a => (a.Abbreviation == sequences[i]) || ("+" + a.Abbreviation == sequences[i]) || ("-" + a.Abbreviation == sequences[i]))) { continue; } } { { bool breaksequence = false; for (int j = 0; j < seq.Length; j++) /// This is the individual AminoAcids { if (j == seq.Length - 1) { for (int ii = i + 1; ii < sequences.Count; ii++) { if ((regex.IsMatch(sequences[ii])) || AllValidationModifications.Any(a => (a.Abbreviation == sequences[ii]) || ("+" + a.Abbreviation == sequences[ii]) || ("-" + a.Abbreviation == sequences[ii]))) { breaksequence = true; break; } else { breaksequence = false; break; } } } if (breaksequence) { for (int ii = i + 1; ii < sequences.Count; ii++) { { if (AllValidationModifications.Any(a => a.Abbreviation == sequences[ii])) { tempseq = "+" + sequences[ii] + " " + tempseq; ion = ion + Convert.ToDouble(AllValidationModifications.First(a => a.Abbreviation == sequences[ii]).Mass); cion = cion + Convert.ToDouble(AllValidationModifications.First(a => a.Abbreviation == sequences[ii]).Mass); } else if (AllValidationModifications.Any(a => "+" + a.Abbreviation == sequences[ii])) { tempseq = sequences[ii] + " " + tempseq; ion = ion + Convert.ToDouble(AllValidationModifications.First(a => "+" + a.Abbreviation == sequences[ii]).Mass); cion = cion + Convert.ToDouble(AllValidationModifications.First(a => "+" + a.Abbreviation == sequences[ii]).Mass); } else if (AllValidationModifications.Any(a => "-" + a.Abbreviation == sequences[ii])) { tempseq = sequences[ii] + " " + tempseq; ion = ion - Math.Abs(Convert.ToDouble(AllValidationModifications.First(a => "-" + a.Abbreviation == sequences[ii]).Mass)); cion = cion - Math.Abs(Convert.ToDouble(AllValidationModifications.First(a => "-" + a.Abbreviation == sequences[ii]).Mass)); } else if (regex.IsMatch(sequences[ii])) { if (sequences[ii].StartsWith("+")) { ion = ion + Convert.ToDouble(sequences[ii]); cion = cion + Convert.ToDouble(sequences[ii]); tempseq += "+ " + sequences[ii].Remove(sequences[ii].IndexOf("+"), 1) + " "; } else if (sequences[ii].StartsWith("-")) { ion = ion - Math.Abs(Convert.ToDouble(sequences[ii])); cion = cion - Math.Abs(Convert.ToDouble(sequences[ii])); tempseq += "- " + sequences[ii].Remove(sequences[ii].IndexOf("-"), 1) + " "; } else { ion = ion + Convert.ToDouble(sequences[ii]); cion = cion + Convert.ToDouble(sequences[ii]); tempseq += "+ " + sequences[ii] + " "; } } else { break; } } } } if (j != seq.Length - 1) { if (regexlwrcs.IsMatch(Convert.ToString(seq[j + 1]))) { ion = ion + sequencelengthwithmods((Convert.ToString(seq[j]) + Convert.ToString(seq[j + 1]))); cion = cion + sequencelengthwithmods((Convert.ToString(seq[j]) + Convert.ToString(seq[j + 1]))); tempseq = Convert.ToString(seq[j]) + Convert.ToString(seq[j + 1]) + " " + tempseq; j = j + 1; } else { ion = ion + sequencelength(Convert.ToString(seq[j])); cion = cion + sequencelength(Convert.ToString(seq[j])); tempseq = seq[j] + " " + tempseq; } } else { ion = ion + sequencelength(Convert.ToString(seq[j])); cion = cion + sequencelength(Convert.ToString(seq[j])); tempseq = seq[j] + " " + tempseq; } //if (isauto) //{ // double bionerror = Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100; // AllIons.Add(new BYIons() // { // Bion = ion, // //Yion = 0, // //AminoAcid = tempseq.TrimEnd(), // //BionNumber = count, // //BorYIon = count, // bioncolor = bionerror == 100 ? false : (((PPM.CalculatePPM(ion, bionerror) <= Properties.Settings.Default.FragementIonTolerance) && (PPM.CalculatePPM(ion, bionerror) >= -(Properties.Settings.Default.FragementIonTolerance)))), /// Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)), // Intensity = CurrentMonomasses.Any(a => Math.Abs(a.Key - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? CurrentMonomasses.First(a => Math.Abs(a.Key - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Value : 0, // bnh3ioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Ammonia), MatchTolerance)), // bh2oioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Water), MatchTolerance)), // bionerror = bionerror,/// Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100, // //bh2oion = Math.Round(ion - Molecules.Water, 5), // //bh2oioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Water), MatchTolerance)), // //bionerror = Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100, // //BionDescription = "B" + Convert.ToString(count) + " " + PPM.CalculatePPM(ion, Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100), // //BionDaltonDescription = "B" + Convert.ToString(count) + " " + (Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100) // }); //} //else { double bionerror = Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100; double cionerror = Monomasses.Any(a => Math.Abs(a - cion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - cion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)).Select(a => a - cion).First() : 100; AllIons.Add(new BYCZIons() { Bion = ion, Yion = 0, Cion = cion, Zion = 0, AminoAcid = tempseq.TrimEnd(), BionNumber = count, ActivationType = ActivationType, BorYIon = count, CionNumber = count, CorZIon = count, Intensity = CurrentMonomasses != null ? (CurrentMonomasses.Any(a => Math.Abs(a.Key - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? CurrentMonomasses.First(a => Math.Abs(a.Key - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Value : 0) : 0, bioncolor = bionerror == 100 ? false : ((Math.Abs(PPM.CalculatePPM(ParentMass, bionerror)) < Properties.Settings.Default.FragementIonTolerance)), ///Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)), //bioncolor = bionerror == 100 ? false : (((PPM.CalculatePPM(ion, bionerror) < Properties.Settings.Default.FragementIonTolerance) && (PPM.CalculatePPM(ion, bionerror) > -(Properties.Settings.Default.FragementIonTolerance)))), ///Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)), bh2oion = Math.Round(ion - Molecules.Water, 5), bh2oioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Water), MatchTolerance)), bionerror = bionerror,/// Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100, BionDescription = "B" + Convert.ToString(count) + " " + PPM.CalculatePPM(ion, Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100), BionDaltonDescription = "B" + Convert.ToString(count) + " " + (Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100), bnh3ion = Math.Round(ion - Molecules.Ammonia, 5), bnh3ioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Ammonia), MatchTolerance)), cioncolor = cionerror == 100 ? false : ((Math.Abs(PPM.CalculatePPM(ParentMass, cionerror)) < Properties.Settings.Default.FragementIonTolerance)), //Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)), //bioncolor = bionerror == 100 ? false : (((PPM.CalculatePPM(ion, bionerror) < Properties.Settings.Default.FragementIonTolerance) && (PPM.CalculatePPM(ion, bionerror) > -(Properties.Settings.Default.FragementIonTolerance)))), ///Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)), ch2oion = Math.Round(cion - Molecules.Water, 5), ch2oioncolor = Monomasses.Any(a => Math.Abs(a - (cion - Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((cion - Molecules.Water), MatchTolerance)), cionerror = cionerror, // Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100, CionDescription = "C" + Convert.ToString(count) + " " + PPM.CalculatePPM(cion, Monomasses.Any(a => Math.Abs(a - cion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - cion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)).Select(a => a - cion).First() : 100), CionDaltonDescription = "C" + Convert.ToString(count) + " " + (Monomasses.Any(a => Math.Abs(a - cion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - cion) <= PPM.CurrentPPMbasedonMatchList(cion, MatchTolerance)).Select(a => a - cion).First() : 100), cnh3ion = Math.Round(cion - Molecules.Ammonia, 5), cnh3ioncolor = Monomasses.Any(a => Math.Abs(a - (cion - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((cion - Molecules.Ammonia), MatchTolerance)), }); } //{ // double cionerror = Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100; // AllIons.Add(new BYIons() // { // Cion = ion, // Zion = 0, // AminoAcid = tempseq.TrimEnd(), // CionNumber = count, // CorZIon = count, // Intensity = CurrentMonomasses != null ? (CurrentMonomasses.Any(a => Math.Abs(a.Key - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? CurrentMonomasses.First(a => Math.Abs(a.Key - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Value : 0) : 0, // cioncolor = cionerror == 100 ? false : ((Math.Abs(PPM.CalculatePPM(ion, cionerror)) < Properties.Settings.Default.FragementIonTolerance)), ///Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)), // //bioncolor = bionerror == 100 ? false : (((PPM.CalculatePPM(ion, bionerror) < Properties.Settings.Default.FragementIonTolerance) && (PPM.CalculatePPM(ion, bionerror) > -(Properties.Settings.Default.FragementIonTolerance)))), ///Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)), // ch2oion = Math.Round(ion - Molecules.Water, 5), // ch2oioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Water), MatchTolerance)), // cionerror = cionerror,/// Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100, // CionDescription = "B" + Convert.ToString(count) + " " + PPM.CalculatePPM(ion, Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100), // CionDaltonDescription = "B" + Convert.ToString(count) + " " + (Monomasses.Any(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - ion) <= PPM.CurrentPPMbasedonMatchList(ion, MatchTolerance)).Select(a => a - ion).First() : 100), // cnh3ion = Math.Round(ion - Molecules.Ammonia, 5), // cnh3ioncolor = Monomasses.Any(a => Math.Abs(a - (ion - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((ion - Molecules.Ammonia), MatchTolerance)), // }); //} count = count + 1; tempseq = string.Empty; } } } } count = AllIons.Count - 1; ion = 0; cion = 0; //if (regex.IsMatch(sequences[0])) //{ // ion = Convert.ToDouble(sequences[0]); //} int c = 1; List <BYCZIons> intensities = new List <BYCZIons>(); intensities = AllIons.Where(a => a.bioncolor == true).ToList(); tempseq = string.Empty; for (int i = sequences.Count - 1; i >= 0; i--) { string seq = sequences[i]; string sq = seq; if (regex.IsMatch(sq)) { if (sq.Contains("+")) { sq = sq.Remove(sq.IndexOf("+"), 1); ion = ion + Convert.ToDouble(sq); cion = cion + Convert.ToDouble(sq); } else if (sq.Contains("-")) { sq = sq.Remove(sq.IndexOf("-"), 1); ion = ion - Math.Abs(Convert.ToDouble(sq)); cion = cion - Math.Abs(Convert.ToDouble(sq)); } else { ion = ion + Convert.ToDouble(sq); cion = cion + Convert.ToDouble(sq); } } else { if (seq.Contains("-")) { if (AllValidationModifications.Any(a => ("-" + a.Abbreviation) == seq)) { ion = ion - Math.Abs(Convert.ToDouble(AllValidationModifications.Where(a => "-" + a.Abbreviation == seq).First().Mass)); cion = cion - Math.Abs(Convert.ToDouble(AllValidationModifications.Where(a => "-" + a.Abbreviation == seq).First().Mass)); } } else if (seq.Contains("+")) { if (AllValidationModifications.Any(a => ("+" + a.Abbreviation) == seq)) { ion = ion + Convert.ToDouble(AllValidationModifications.Where(a => "+" + a.Abbreviation == seq).First().Mass); cion = cion + Convert.ToDouble(AllValidationModifications.Where(a => "+" + a.Abbreviation == seq).First().Mass); } } else if (AllValidationModifications.Any(a => a.Abbreviation == seq)) { ion = ion + Convert.ToDouble(AllValidationModifications.Where(a => a.Abbreviation == seq).First().Mass); cion = cion + Convert.ToDouble(AllValidationModifications.Where(a => a.Abbreviation == seq).First().Mass); } else { string[] alltheaminoacids = seq.Select(a => a.ToString()).ToArray(); double modmass = 0.0; string tempaminoacids = string.Empty; bool hasaminoacidsmod = false; foreach (string AminoAcid in alltheaminoacids.Reverse()) { if (regexlwrcs.IsMatch(AminoAcid)) { tempaminoacids = AminoAcid; hasaminoacidsmod = true; continue; } tempaminoacids = AminoAcid + tempaminoacids; ion = ion + (hasaminoacidsmod ? sequencelengthwithmods(tempaminoacids) : sequencelength(AminoAcid)); cion = cion + (hasaminoacidsmod ? sequencelengthwithmods(tempaminoacids) : sequencelength(AminoAcid)); double Yion = Math.Round(ion + Molecules.Water, 4); double Zion = Math.Round(cion, 4); //AllIons[count].yioncolor = Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)); AllIons[count].Yion = Yion; AllIons[count].Zion = Zion; //AllIons[count].in double yionerror = Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)).Select(a => a - (ion + Molecules.Water)).First() : 100; double zionerror = Monomasses.Any(a => Math.Abs(a - (cion)) <= PPM.CurrentPPMbasedonMatchList((cion), MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - (cion)) <= PPM.CurrentPPMbasedonMatchList((cion), MatchTolerance)).Select(a => a - (cion)).First() : 100; //if (isauto) //{ // //if (AllIons[count].yioncolor) // { // AllIons[count].Intensity += CurrentMonomasses.Any(a => Math.Abs(a.Key - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)) ? // CurrentMonomasses.First(a => Math.Abs(a.Key - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)).Value : 0; // AllIons[count].yh2oioncolor = Monomasses.Any(a => Math.Abs(a - (ion)) <= PPM.CurrentPPMbasedonMatchList((ion), MatchTolerance)); // AllIons[count].ynh3ioncolor = Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water - Molecules.Ammonia), MatchTolerance)); // AllIons[count].yionerror = yionerror;/// Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)).Select(a => a - (ion + Molecules.Water)).First() : 100; // AllIons[count].yioncolor = yionerror == 100 ? false : (((PPM.CalculatePPM(Yion, yionerror) <= Properties.Settings.Default.FragementIonTolerance) && (PPM.CalculatePPM(Yion, yionerror) >= -(Properties.Settings.Default.FragementIonTolerance)))); //Checking if the PPM ion tolerance is between the limits // //CurrentMonomasses.ContainsKey(AllIons[count].Yion) ? CurrentMonomasses[AllIons[count].Yion] : 0; // //AllIons[count].Intensity += CurrentMonomasses.ContainsKey(AllIons[count].Yion) ? CurrentMonomasses[AllIons[count].Yion] : 0; // } //} //if (!isauto) { AllIons[count].Yion = Yion;/// Math.Round(ion + Molecules.Water, 4); AllIons[count].Zion = Zion; AllIons[count].YionNumber = -c; AllIons[count].ZionNumber = -c; AllIons[count].Intensity += CurrentMonomasses != null ? (CurrentMonomasses.Any(a => Math.Abs(a.Key - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)) ? CurrentMonomasses.First(a => Math.Abs(a.Key - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)).Value : 0) : 0; AllIons[count].ActivationType = ActivationType; AllIons[count].NewYIonNumber = c; AllIons[count].NewZIonNumber = c; AllIons[count].yh2oion = Math.Round(ion, 4); AllIons[count].zh2oion = Math.Round(Zion + Molecules.Water, 4); AllIons[count].ynh3ion = Math.Round(ion + Molecules.Water - Molecules.Ammonia, 4); AllIons[count].znh3ion = Math.Round(Zion - Molecules.Ammonia, 4); AllIons[count].yh2oioncolor = Monomasses.Any(a => Math.Abs(a - (ion)) <= PPM.CurrentPPMbasedonMatchList((ion), MatchTolerance)); //AllIons[count].zh2oioncolor = Monomasses.Any(a => Math.Abs(a - (Zion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion), MatchTolerance)); AllIons[count].ynh3ioncolor = Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water - Molecules.Ammonia), MatchTolerance)); AllIons[count].znh3ioncolor = Monomasses.Any(a => Math.Abs(a - (Zion - Molecules.Ammonia)) <= PPM.CurrentPPMbasedonMatchList((Zion - Molecules.Ammonia), MatchTolerance)); AllIons[count].yionerror = yionerror; /// Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)) ? Monomasses.Where(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance)).Select(a => a - (ion + Molecules.Water)).First() : 100; AllIons[count].zionerror = zionerror; AllIons[count].yioncolor = yionerror == 100 ? false : ((Math.Abs(PPM.CalculatePPM(ParentMass, yionerror)) <= Properties.Settings.Default.FragementIonTolerance)); AllIons[count].zioncolor = zionerror == 100 ? false : ((Math.Abs(PPM.CalculatePPM(ParentMass, zionerror)) <= Properties.Settings.Default.FragementIonTolerance)); //AllIons[count].yioncolor = yionerror == 100 ? false : (((PPM.CalculatePPM(Yion, yionerror) <= Properties.Settings.Default.FragementIonTolerance) && (PPM.CalculatePPM(Yion, yionerror) >= -(Properties.Settings.Default.FragementIonTolerance)))); if (Monomasses.Any(a => Math.Abs(a - (ion + Molecules.Water)) <= PPM.CurrentPPMbasedonMatchList((ion + Molecules.Water), MatchTolerance))) { AllIons[count].YionDescription = "Y" + Convert.ToString(c) + " " + Convert.ToString(AllIons[count].yionPPM); AllIons[count].YionDaltonDescription = "Y" + Convert.ToString(c) + " " + Convert.ToString(AllIons[count].yionerror); } if (Monomasses.Any(a => Math.Abs(a - (Zion)) <= PPM.CurrentPPMbasedonMatchList((Zion), MatchTolerance))) { AllIons[count].ZionDescription = "Y" + Convert.ToString(c) + " " + Convert.ToString(AllIons[count].zionPPM); AllIons[count].ZionDaltonDescription = "Y" + Convert.ToString(c) + " " + Convert.ToString(AllIons[count].zionerror); } } c = c + 1; count = count - 1; tempaminoacids = string.Empty; hasaminoacidsmod = false; } } } } return(AllIons); }
public Encoder(PPM image) { Image = image; EncodingBlocks = new EncodingBlocks(); }
public static void RowTestByDelegate(int spp, string fileSuffix, Func <int, Material> materialFunc) { Console.WriteLine("Loading file..."); var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm"); Console.WriteLine("Parsing file..."); var textureCanvas = PPM.ParseFile(filePath); var image = new UVImage(textureCanvas); var map = new TextureMap(image, UVMapping.Spherical); var skySphere = new Sphere { Material = { Texture = map, Ambient = 1.5f, CastsShadows = false, Transparency = 1f } }; skySphere.SetTransform(Transform.RotateY(3.4f).Scale(1000f)); var g = new Group(); var dx = 2.75f; var dz = 3.5f; var y = 1f; var nX = 10; var nZ = 1; int n = 0; for (var z = 0; z < nZ; z++) { for (var x = 0; x < nX; x++) { var s = new Sphere(); s.SetTransform(Transform.TranslateY(1f).Scale(1.2f).Translate(x * dx, 0, z * dz)); s.SetMaterial(materialFunc(x + 1)); g.AddChild(s); n++; } } var lightGray = new Color(0.9f, 0.9f, 0.9f); var darkGray = new Color(0.1f, 0.9f, 0.1f); var s1 = new StripeTexture(lightGray, darkGray); var s2 = new StripeTexture(lightGray, darkGray); s2.SetTransform(Transform.RotateY(MathF.PI / 2)); var pattern = new BlendedCompositeTexture(s1, s2); pattern.SetTransform(Transform.Scale(1f / 30f)); var text = new CheckerTexture(new Color(0.3f, 0.7f, 0.3f), new Color(0.13f, 0.13f, 0.13f)); text.SetTransform(Transform.Scale(1f / 16f)); var floor = new Cube { Material = { Texture = text, SpecularColor = new Color(0.3f, 0.3f, 0.3f), Metallic = 0f, Roughness = 0.45f, Ambient = 0.15f } }; floor.SetTransform(Transform.TranslateY(-1f).Scale(40f)); var min = g.LocalBounds().Min; var max = g.LocalBounds().Max; var dir = max - min; var mid = min + (dir * 0.5f); var g2 = new Group(g, floor, skySphere); g2.Divide(1); var w = new World(); w.SetLights(new PointLight(new Point(mid.X, 500, -500), new Color(1.7f, 1.7f, 1.7f))); w.SetObjects(g2); var width = 1200; var height = 140; var from = new Point(mid.X, 6f, -32f); var to = mid; var canvas = new Canvas(width, height); var pps = new PerPixelSampler(spp); var fov = MathF.PI / 4f; var aspectRatio = (float)width / height; var camera = new ApertureCamera(fov, aspectRatio, 0.2F, from, to, Vectors.Up); var cws = new ComposableWorldSampler(2, 16, GGXNormalDistribution.Instance, GGXSmithGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps)); Console.WriteLine("Rendering at {0}x{1}...", width, height); var stopwatch = new Stopwatch(); stopwatch.Start(); ctx.Render(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "col_row_" + fileSuffix); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }