From dc21788389983c79055cbc928ad4360f2540d8d9 Mon Sep 17 00:00:00 2001 From: RepoErik <84872500+BiologyTools@users.noreply.github.com> Date: Thu, 1 Dec 2022 07:59:00 +0200 Subject: [PATCH] 2.7.5 DirectDraw BGR fix. --- Graphics/DBitmap.cs | 6 +- Graphics/Graphics/DColorShader.cs | 10 +- Graphics/Graphics/DDX11.cs | 6 +- Graphics/Graphics/DGraphics.cs | 8 +- Graphics/Graphics/DModel.cs | 4 +- Graphics/Shaders/color-gs.hlsl | 42 ++++--- Graphics/Shaders/color-vs.hlsl | 20 ++-- Graphics/System/DSystem.cs | 4 +- Graphics/System/DSystemConfiguration.cs | 5 +- Graphics/View3D.Designer.cs | 150 ++++++++++++++++++++++-- Graphics/View3D.cs | 24 +++- Graphics/View3D.resx | 3 + Properties/AssemblyInfo.cs | 4 +- Source/Bio.cs | 4 +- Source/ImageView.cs | 91 ++++++++------ 15 files changed, 274 insertions(+), 107 deletions(-) diff --git a/Graphics/DBitmap.cs b/Graphics/DBitmap.cs index ce753c3..c5b1741 100644 --- a/Graphics/DBitmap.cs +++ b/Graphics/DBitmap.cs @@ -105,14 +105,18 @@ public unsafe static Bitmap FromImage(RenderTarget renderTarget, System.Drawing. int w = image.Width; int h = image.Height; Bitmap b = null; - // Loads from file using System.Drawing.Image + //For RGB images we switch to BGR + if(image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed && image.PixelFormat != System.Drawing.Imaging.PixelFormat.Format16bppGrayScale) + image = BufferInfo.SwitchRedBlue(image); BitmapData d = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat); using (var bitmap = (System.Drawing.Bitmap)image) { + var bitmapProperties = new BitmapProperties(new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore)); var size = new Size2(bitmap.Width, bitmap.Height); if (image.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { + b = new Bitmap(renderTarget, size, new DataPointer(d.Scan0, bitmap.Width * 4 * bitmap.Height), bitmap.Width * 4, bitmapProperties); return b; } diff --git a/Graphics/Graphics/DColorShader.cs b/Graphics/Graphics/DColorShader.cs index 973d962..e5103f5 100644 --- a/Graphics/Graphics/DColorShader.cs +++ b/Graphics/Graphics/DColorShader.cs @@ -135,10 +135,10 @@ private void ShuddownShader() VertexShader?.Dispose(); VertexShader = null; } - public bool Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, IntRange r, IntRange g, IntRange b) + public bool Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, IntRange r, IntRange g, IntRange b, float interval, float alpha) { // Set the shader parameters that it will use for rendering. - if (!SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, r, g, b)) + if (!SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, r, g, b,interval, alpha)) return false; // Now render the prepared buffers with the shader. @@ -146,7 +146,7 @@ public bool Render(DeviceContext deviceContext, int indexCount, Matrix worldMatr return true; } - private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, IntRange r, IntRange g, IntRange b) + private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, IntRange r, IntRange g, IntRange b, float interval, float alpha) { try { @@ -164,14 +164,14 @@ private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix f = ushort.MaxValue; else f = byte.MaxValue; - + // Copy the matrices into the constant buffer. DMatrixBuffer matrixBuffer = new DMatrixBuffer() { world = worldMatrix, view = viewMatrix, projection = projectionMatrix, - rMinMax = new Vector4((float)r.Min / f, (float)r.Max / f, 0, 0), + rMinMax = new Vector4((float)r.Min / f, (float)r.Max / f, interval, alpha), gMinMax = new Vector4((float)g.Min / f, (float)g.Max / f, 0, 0), bMinMax = new Vector4((float)b.Min / f, (float)b.Max / f, 0, 0) }; diff --git a/Graphics/Graphics/DDX11.cs b/Graphics/Graphics/DDX11.cs index 533ecee..3f9c17f 100644 --- a/Graphics/Graphics/DDX11.cs +++ b/Graphics/Graphics/DDX11.cs @@ -188,14 +188,14 @@ public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) // Setup the raster description which will determine how and what polygon will be drawn. RasterizerStateDescription rasterDesc = new RasterizerStateDescription() { - IsAntialiasedLineEnabled = true, + IsAntialiasedLineEnabled = false, CullMode = CullMode.Back, DepthBias = 0, DepthBiasClamp = .0f, - IsDepthClipEnabled = true, + IsDepthClipEnabled = false, FillMode = FillMode.Solid, IsFrontCounterClockwise = false, - IsMultisampleEnabled = true, + IsMultisampleEnabled = false, IsScissorEnabled = false, SlopeScaledDepthBias = .0f }; diff --git a/Graphics/Graphics/DGraphics.cs b/Graphics/Graphics/DGraphics.cs index 0618de8..95c5619 100644 --- a/Graphics/Graphics/DGraphics.cs +++ b/Graphics/Graphics/DGraphics.cs @@ -79,12 +79,12 @@ public void ShutDown() D3D?.ShutDown(); D3D = null; } - public bool Frame(IntRange r, IntRange g, IntRange b) + public bool Frame(IntRange r, IntRange g, IntRange b, float interval, float alpha) { // Render the graphics scene. - return Render(r,g,b); + return Render(r,g,b,interval,alpha); } - private bool Render(IntRange r, IntRange g, IntRange b) + private bool Render(IntRange r, IntRange g, IntRange b, float interval, float alpha) { // Clear the buffer to begin the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1f); @@ -101,7 +101,7 @@ private bool Render(IntRange r, IntRange g, IntRange b) Model.Render(D3D.DeviceContext); // Render the model using the color shader. - if (!ColorShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, r, g, b)) + if (!ColorShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, r, g, b, interval, alpha)) return false; // Present the rendered scene to the screen. diff --git a/Graphics/Graphics/DModel.cs b/Graphics/Graphics/DModel.cs index 6d1992f..9a103ff 100644 --- a/Graphics/Graphics/DModel.cs +++ b/Graphics/Graphics/DModel.cs @@ -41,7 +41,7 @@ private bool InitializeBuffer(Device device, BioImage im) // Create the vertex array and load it with data. var vertices = new DColorShader.DVertex[VertexCount]; ColorS col; - for (int z = im.SizeZ - 1; z >= 0; z--) + for (int z = 0; z < im.SizeZ; z++) { for (int y = im.SizeY-1; y >= 0; y--) { @@ -54,7 +54,7 @@ private bool InitializeBuffer(Device device, BioImage im) vec.W = 0.5f; vertices[ind] = new DColorShader.DVertex() { - position = new Vector3((float)x / (float)im.SizeX, (float)y / (float)im.SizeY, ((float)z / im.SizeZ) * 0.1f), + position = new Vector3((float)x / (float)im.SizeX, (float)y / (float)im.SizeY, (z / (float)im.SizeZ)*(float)im.physicalSizeZ), color = vec }; } diff --git a/Graphics/Shaders/color-gs.hlsl b/Graphics/Shaders/color-gs.hlsl index c876e5d..ab49d37 100644 --- a/Graphics/Shaders/color-gs.hlsl +++ b/Graphics/Shaders/color-gs.hlsl @@ -46,31 +46,29 @@ float4 ToClipSpace(float2 screenPos, float originalClipPosW) [maxvertexcount(6)] void ColorGeometryShader(point v2g input[1], inout TriangleStream triStream) { - if(input[0].color.w != 0) - { - g2f v; - float2 screenPos = FromClipSpace(input[0].position); - float clipPosW = input[0].position.w; - v.color = input[0].color; - float s = 0.02; - v.position = ToClipSpace(screenPos + float2(-s, -s), clipPosW); - triStream.Append(v); + g2f v; + float2 screenPos = FromClipSpace(input[0].position); + float clipPosW = input[0].position.w; + v.color = input[0].color; + float s = 0.02; + v.position = ToClipSpace(screenPos + float2(-s, -s), clipPosW); + triStream.Append(v); - v.position = ToClipSpace(screenPos + float2(-s, s), clipPosW); - triStream.Append(v); + v.position = ToClipSpace(screenPos + float2(-s, s), clipPosW); + triStream.Append(v); - v.position = ToClipSpace(screenPos + float2(s, s), clipPosW); - triStream.Append(v); - triStream.RestartStrip(); + v.position = ToClipSpace(screenPos + float2(s, s), clipPosW); + triStream.Append(v); + triStream.RestartStrip(); - v.position = ToClipSpace(screenPos + float2(s, -s), clipPosW); - triStream.Append(v); + v.position = ToClipSpace(screenPos + float2(s, -s), clipPosW); + triStream.Append(v); - v.position = ToClipSpace(screenPos + float2(-s, -s), clipPosW); - triStream.Append(v); + v.position = ToClipSpace(screenPos + float2(-s, -s), clipPosW); + triStream.Append(v); - v.position = ToClipSpace(screenPos + float2(s, s), clipPosW); - triStream.Append(v); - triStream.RestartStrip(); - } + v.position = ToClipSpace(screenPos + float2(s, s), clipPosW); + triStream.Append(v); + triStream.RestartStrip(); + } \ No newline at end of file diff --git a/Graphics/Shaders/color-vs.hlsl b/Graphics/Shaders/color-vs.hlsl index 88beb2c..7b06d49 100644 --- a/Graphics/Shaders/color-vs.hlsl +++ b/Graphics/Shaders/color-vs.hlsl @@ -42,39 +42,41 @@ PixelInputType ColorVertexShader(VertexInputType input) output.color = float4(0, 0, 0, 0); // Change the position vector to be 4 units for proper matrix calculations. input.position.w = 1.0f; - if ((input.color.x > rMinMax.x)) + if ((input.color.x >= rMinMax.x)) { float r = 1 / (rMinMax.y - rMinMax.x); input.color.x *= r; - input.color.w = 0.8f; + input.color.w = (input.color.x * input.color.y * input.color.z) * (1 / rMinMax.w); } else { input.color.x = 0; } - if (input.color.y > gMinMax.x) + if (input.color.y >= gMinMax.x) { float g = 1 / (gMinMax.y - gMinMax.x); input.color.y *= g; - input.color.w = 0.8f; + input.color.w = (input.color.x * input.color.y * input.color.z) * (1 / rMinMax.w); } else { input.color.y = 0; } - if (input.color.z > bMinMax.x) + if (input.color.z >= bMinMax.x) { float b = 1 / (bMinMax.y - bMinMax.x); input.color.z *= b; - input.color.w = 0.8f; + input.color.w = (input.color.x * input.color.y * input.color.z) * (1 / rMinMax.w); } else { input.color.z = 0; } - if (!(input.color.x > rMinMax.x) && !(input.color.y > gMinMax.x) && !(input.color.z > bMinMax.x)) - input.color.w = 0.0f; - // Calculate the position of the vertex against the world, view, and projection matrices. + //if (!(input.color.x >= rMinMax.x) && !(input.color.y >= gMinMax.x) && !(input.color.z >= bMinMax.x)) + // input.color.w = 0.0f; + + input.position.z = input.position.z * rMinMax.z; + //Calculate the position of the vertex against the world, view, and projection matrices. output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); diff --git a/Graphics/System/DSystem.cs b/Graphics/System/DSystem.cs index 884574b..2155af1 100644 --- a/Graphics/System/DSystem.cs +++ b/Graphics/System/DSystem.cs @@ -34,13 +34,13 @@ public virtual bool Initialize(string title, int width, int height, bool vSync, } return result; } - public bool Frame(IntRange r, IntRange g, IntRange b) + public bool Frame(IntRange r, IntRange g, IntRange b, float interval, float alpha) { // Check if the user pressed escape and wants to exit the application. if (Input.IsKeyDown(Keys.Escape)) return false; // Do the frame processing for the graphics object. - return Graphics.Frame(r,g,b); + return Graphics.Frame(r,g,b,interval,alpha); } public void ShutDown() { diff --git a/Graphics/System/DSystemConfiguration.cs b/Graphics/System/DSystemConfiguration.cs index 2be486a..f4e04b3 100644 --- a/Graphics/System/DSystemConfiguration.cs +++ b/Graphics/System/DSystemConfiguration.cs @@ -42,11 +42,10 @@ public DSystemConfiguration(string title, int width, int height, bool fullScreen // Static Constructor static DSystemConfiguration() { - VerticalSyncEnabled = false; + VerticalSyncEnabled = true; ScreenDepth = 1000.0f; - ScreenNear = 0.1f; + ScreenNear = -0.1f; BorderStyle = FormBorderStyle.None; - ShaderFilePath = Application.StartupPath + @"\Graphics\Shaders\"; } } diff --git a/Graphics/View3D.Designer.cs b/Graphics/View3D.Designer.cs index 4693f5d..d7648b8 100644 --- a/Graphics/View3D.Designer.cs +++ b/Graphics/View3D.Designer.cs @@ -29,6 +29,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(View3D)); this.statusStrip = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); @@ -45,6 +46,12 @@ private void InitializeComponent() this.bMinBox = new System.Windows.Forms.NumericUpDown(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); + this.frameIntervalBox = new System.Windows.Forms.NumericUpDown(); + this.label7 = new System.Windows.Forms.Label(); + this.transparencyBox = new System.Windows.Forms.NumericUpDown(); + this.label8 = new System.Windows.Forms.Label(); + this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.resetCameraToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.rMinBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.rMaxBox)).BeginInit(); @@ -52,6 +59,9 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.gMinBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bMaxBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bMinBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.frameIntervalBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.transparencyBox)).BeginInit(); + this.contextMenuStrip.SuspendLayout(); this.SuspendLayout(); // // statusStrip @@ -75,7 +85,7 @@ private void InitializeComponent() // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(2, 430); + this.label1.Location = new System.Drawing.Point(2, 407); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(38, 13); this.label1.TabIndex = 2; @@ -85,7 +95,7 @@ private void InitializeComponent() // this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(113, 430); + this.label2.Location = new System.Drawing.Point(113, 407); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(41, 13); this.label2.TabIndex = 4; @@ -96,9 +106,10 @@ private void InitializeComponent() this.dxPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.dxPanel.ContextMenuStrip = this.contextMenuStrip; this.dxPanel.Location = new System.Drawing.Point(0, 0); this.dxPanel.Name = "dxPanel"; - this.dxPanel.Size = new System.Drawing.Size(678, 422); + this.dxPanel.Size = new System.Drawing.Size(678, 399); this.dxPanel.TabIndex = 14; this.dxPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dxPanel_MouseDown); this.dxPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dxPanel_MouseMove); @@ -115,7 +126,7 @@ private void InitializeComponent() 0, 0}); this.rMinBox.InterceptArrowKeys = false; - this.rMinBox.Location = new System.Drawing.Point(46, 428); + this.rMinBox.Location = new System.Drawing.Point(46, 405); this.rMinBox.Maximum = new decimal(new int[] { 65535, 0, @@ -138,7 +149,7 @@ private void InitializeComponent() 0, 0}); this.rMaxBox.InterceptArrowKeys = false; - this.rMaxBox.Location = new System.Drawing.Point(160, 428); + this.rMaxBox.Location = new System.Drawing.Point(160, 405); this.rMaxBox.Maximum = new decimal(new int[] { 65535, 0, @@ -161,7 +172,7 @@ private void InitializeComponent() 0, 0}); this.gMaxBox.InterceptArrowKeys = false; - this.gMaxBox.Location = new System.Drawing.Point(387, 428); + this.gMaxBox.Location = new System.Drawing.Point(387, 405); this.gMaxBox.Maximum = new decimal(new int[] { 65535, 0, @@ -183,7 +194,7 @@ private void InitializeComponent() 0, 0}); this.gMinBox.InterceptArrowKeys = false; - this.gMinBox.Location = new System.Drawing.Point(273, 428); + this.gMinBox.Location = new System.Drawing.Point(273, 405); this.gMinBox.Maximum = new decimal(new int[] { 65535, 0, @@ -198,7 +209,7 @@ private void InitializeComponent() // this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(340, 430); + this.label3.Location = new System.Drawing.Point(340, 407); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(41, 13); this.label3.TabIndex = 18; @@ -208,7 +219,7 @@ private void InitializeComponent() // this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(229, 430); + this.label4.Location = new System.Drawing.Point(229, 407); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(38, 13); this.label4.TabIndex = 17; @@ -226,7 +237,7 @@ private void InitializeComponent() 0, 0}); this.bMaxBox.InterceptArrowKeys = false; - this.bMaxBox.Location = new System.Drawing.Point(611, 428); + this.bMaxBox.Location = new System.Drawing.Point(611, 405); this.bMaxBox.Maximum = new decimal(new int[] { 65535, 0, @@ -248,7 +259,7 @@ private void InitializeComponent() 0, 0}); this.bMinBox.InterceptArrowKeys = false; - this.bMinBox.Location = new System.Drawing.Point(497, 428); + this.bMinBox.Location = new System.Drawing.Point(497, 405); this.bMinBox.Maximum = new decimal(new int[] { 65535, 0, @@ -263,7 +274,7 @@ private void InitializeComponent() // this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(564, 430); + this.label5.Location = new System.Drawing.Point(564, 407); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(40, 13); this.label5.TabIndex = 22; @@ -273,18 +284,122 @@ private void InitializeComponent() // this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(453, 430); + this.label6.Location = new System.Drawing.Point(453, 407); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(37, 13); this.label6.TabIndex = 21; this.label6.Text = "B Min:"; // + // frameIntervalBox + // + this.frameIntervalBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.frameIntervalBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(49)))), ((int)(((byte)(91)))), ((int)(((byte)(138))))); + this.frameIntervalBox.DecimalPlaces = 4; + this.frameIntervalBox.ForeColor = System.Drawing.Color.White; + this.frameIntervalBox.Increment = new decimal(new int[] { + 1, + 0, + 0, + 65536}); + this.frameIntervalBox.InterceptArrowKeys = false; + this.frameIntervalBox.Location = new System.Drawing.Point(82, 429); + this.frameIntervalBox.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.frameIntervalBox.Minimum = new decimal(new int[] { + 1000, + 0, + 0, + -2147483648}); + this.frameIntervalBox.Name = "frameIntervalBox"; + this.frameIntervalBox.Size = new System.Drawing.Size(61, 20); + this.frameIntervalBox.TabIndex = 26; + this.frameIntervalBox.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.frameIntervalBox.ValueChanged += new System.EventHandler(this.frameIntervalBox_ValueChanged); + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(2, 431); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(77, 13); + this.label7.TabIndex = 25; + this.label7.Text = "Frame Interval:"; + // + // transparencyBox + // + this.transparencyBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.transparencyBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(49)))), ((int)(((byte)(91)))), ((int)(((byte)(138))))); + this.transparencyBox.DecimalPlaces = 4; + this.transparencyBox.ForeColor = System.Drawing.Color.White; + this.transparencyBox.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.transparencyBox.InterceptArrowKeys = false; + this.transparencyBox.Location = new System.Drawing.Point(237, 429); + this.transparencyBox.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.transparencyBox.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 458752}); + this.transparencyBox.Name = "transparencyBox"; + this.transparencyBox.Size = new System.Drawing.Size(61, 20); + this.transparencyBox.TabIndex = 28; + this.transparencyBox.Value = new decimal(new int[] { + 1, + 0, + 0, + 262144}); + this.transparencyBox.ValueChanged += new System.EventHandler(this.transparencyBox_ValueChanged); + // + // label8 + // + this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(157, 431); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(72, 13); + this.label8.TabIndex = 27; + this.label8.Text = "Transparency"; + // + // contextMenuStrip + // + this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.resetCameraToolStripMenuItem}); + this.contextMenuStrip.Name = "contextMenuStrip"; + this.contextMenuStrip.Size = new System.Drawing.Size(147, 26); + // + // resetCameraToolStripMenuItem + // + this.resetCameraToolStripMenuItem.Name = "resetCameraToolStripMenuItem"; + this.resetCameraToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.resetCameraToolStripMenuItem.Text = "Reset Camera"; + this.resetCameraToolStripMenuItem.Click += new System.EventHandler(this.resetCameraToolStripMenuItem_Click); + // // View3D // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(95)))), ((int)(((byte)(122)))), ((int)(((byte)(156))))); this.ClientSize = new System.Drawing.Size(678, 474); + this.Controls.Add(this.transparencyBox); + this.Controls.Add(this.label8); + this.Controls.Add(this.frameIntervalBox); + this.Controls.Add(this.label7); this.Controls.Add(this.bMaxBox); this.Controls.Add(this.bMinBox); this.Controls.Add(this.label5); @@ -316,6 +431,9 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.gMinBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bMaxBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bMinBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.frameIntervalBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.transparencyBox)).EndInit(); + this.contextMenuStrip.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -337,5 +455,11 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown bMinBox; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label6; + private System.Windows.Forms.NumericUpDown frameIntervalBox; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.NumericUpDown transparencyBox; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip; + private System.Windows.Forms.ToolStripMenuItem resetCameraToolStripMenuItem; } } \ No newline at end of file diff --git a/Graphics/View3D.cs b/Graphics/View3D.cs index 479ae8b..77ace08 100644 --- a/Graphics/View3D.cs +++ b/Graphics/View3D.cs @@ -17,7 +17,8 @@ public partial class View3D : Form { DSystem sys = null; List Buffers = new List(); - Vector3 Origin = new Vector3(0.1f, -0.1f, -1); + private static Vector3 origin = new Vector3(0f, -1f, -2f); + Vector3 Origin = origin; Vector3 r = new Vector3(0, (float)Math.PI, (float)Math.PI); SizeF Scale = new SizeF(1f, 1f); Matrix rot = Matrix.Identity; @@ -64,11 +65,12 @@ private void Initialize() sys.Configuration.Title = "3D View"; sys.Configuration.Width = dxPanel.Width; sys.Configuration.Height = dxPanel.Height; + rot = Matrix.RotationX(r.X) * Matrix.RotationY(r.Y) * Matrix.RotationZ(r.Z); world = rot;// * Matrix.Scaling(Scale.Width, Scale.Height, 1); sys.Graphics.D3D.WorldMatrix = world; sys.Graphics.Initialize(sys.Configuration, dxPanel.Handle, ImageView.SelectedImage); - sys.Graphics.Frame(RRange,GRange,BRange); + sys.Graphics.Frame(RRange,GRange,BRange,(float)frameIntervalBox.Value,(float)transparencyBox.Value); } public void UpdateView() { @@ -78,7 +80,7 @@ public void UpdateView() world = rot * Matrix.Scaling(Scale.Width, Scale.Height, 1); sys.Graphics.D3D.WorldMatrix = world; sys.Graphics.Camera.SetPosition(Origin.X, Origin.Y, Origin.Z); - sys.Graphics.Frame(RRange, GRange, BRange); + sys.Graphics.Frame(RRange, GRange, BRange,(float)frameIntervalBox.Value,(float)transparencyBox.Value); } private void View3D_Resize(object sender, EventArgs e) @@ -196,5 +198,21 @@ private void View3D_FormClosing(object sender, FormClosingEventArgs e) { sys.ShutDown(); } + + private void frameIntervalBox_ValueChanged(object sender, EventArgs e) + { + UpdateView(); + } + + private void transparencyBox_ValueChanged(object sender, EventArgs e) + { + UpdateView(); + } + + private void resetCameraToolStripMenuItem_Click(object sender, EventArgs e) + { + Origin = origin; + UpdateView(); + } } } diff --git a/Graphics/View3D.resx b/Graphics/View3D.resx index 6d9f7ba..e6f59ee 100644 --- a/Graphics/View3D.resx +++ b/Graphics/View3D.resx @@ -120,6 +120,9 @@ 17, 17 + + 126, 17 + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index a3f3a39..5b7c390 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("2.7.4.0")] -[assembly: AssemblyFileVersion("2.7.4.0")] +[assembly: AssemblyVersion("2.7.5.0")] +[assembly: AssemblyFileVersion("2.7.5.0")] diff --git a/Source/Bio.cs b/Source/Bio.cs index 06d81a8..4258468 100644 --- a/Source/Bio.cs +++ b/Source/Bio.cs @@ -5133,7 +5133,7 @@ public void To24Bit() bs[0] = new BufferInfo(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane); bs[1] = new BufferInfo(ID, SizeX, SizeY, Buffers[i + 1].PixelFormat, Buffers[i + 1].Bytes, new ZCT(Buffers[i + 1].Coordinate.Z, 0, Buffers[i + 1].Coordinate.T), i + 1, Buffers[i + 1].Plane); if (Channels.Count > 2) - bs[2] = new BufferInfo(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane); + bs[2] = new BufferInfo(ID, SizeX, SizeY, Buffers[i + 2].PixelFormat, Buffers[i + 2].Bytes, new ZCT(Buffers[i + 2].Coordinate.Z, 0, Buffers[i + 2].Coordinate.T), i + 2, Buffers[i + 2].Plane); BufferInfo bbs = BufferInfo.RGB8To24(bs); for (int b = 0; b < 3; b++) { @@ -5220,7 +5220,7 @@ public void To48Bit() bs[0] = new BufferInfo(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane); bs[1] = new BufferInfo(ID, SizeX, SizeY, Buffers[i + 1].PixelFormat, Buffers[i + 1].Bytes, new ZCT(Buffers[i + 1].Coordinate.Z, 0, Buffers[i + 1].Coordinate.T), i + 1, Buffers[i + 1].Plane); if (Channels.Count > 2) - bs[2] = new BufferInfo(ID, SizeX, SizeY, Buffers[i].PixelFormat, Buffers[i].Bytes, new ZCT(Buffers[i].Coordinate.Z, 0, Buffers[i].Coordinate.T), i, Buffers[i].Plane); + bs[2] = new BufferInfo(ID, SizeX, SizeY, Buffers[i+2].PixelFormat, Buffers[i + 2].Bytes, new ZCT(Buffers[i + 2].Coordinate.Z, 0, Buffers[i + 2].Coordinate.T), i + 2, Buffers[i + 2].Plane); BufferInfo bbs = BufferInfo.RGB16To48(bs); for (int b = 0; b < 3; b++) { diff --git a/Source/ImageView.cs b/Source/ImageView.cs index 23f3b80..3578619 100644 --- a/Source/ImageView.cs +++ b/Source/ImageView.cs @@ -51,8 +51,8 @@ public ImageView(BioImage im) resolutions = im.Resolutions; if (im.isPyramidal) { - hScrollBar.Maximum = im.Resolutions[resolution].SizeX-1; - vScrollBar.Maximum = im.Resolutions[resolution].SizeY-1; + hScrollBar.Maximum = im.Resolutions[resolution].SizeX; + vScrollBar.Maximum = im.Resolutions[resolution].SizeY; hScrollBar.Visible = true; vScrollBar.Visible = true; } @@ -71,13 +71,16 @@ public ImageView(BioImage im) Mode = ViewMode.Filtered; Resolution = im.series; UpdateView(); - dx = new Direct2D(); - dx.Initialize(new Configuration("Bio", dxPanel.Width, dxPanel.Height), dxPanel.Handle); + if (HardwareAcceleration) + { + dx = new Direct2D(); + dx.Initialize(new Configuration("BioImager", dxPanel.Width, dxPanel.Height), dxPanel.Handle); + } } public ImageView() { InitializeComponent(); - tools = new Tools(); + tools = App.tools; Dock = DockStyle.Fill; App.viewer = this; SetCoordinate(0, 0, 0); @@ -102,8 +105,11 @@ public ImageView() UpdateImages(); GoToImage(); UpdateView(); - dx = new Direct2D(); - dx.Initialize(new Configuration("Bio", dxPanel.Width, dxPanel.Height), dxPanel.Handle); + if (HardwareAcceleration) + { + dx = new Direct2D(); + dx.Initialize(new Configuration("BioImager", dxPanel.Width, dxPanel.Height), dxPanel.Handle); + } } ~ImageView() { @@ -114,7 +120,6 @@ public ImageView() List resolutions = new List(); public static List selectedAnnotations = new List(); private static BioImage selectedImage = null; - private static int selectedIndex = 0; public Direct2D dx = null; public static BioImage SelectedImage @@ -208,8 +213,8 @@ public void AddImage(BioImage im) SelectedIndex = Images.Count - 1; if (im.isPyramidal) { - hScrollBar.Maximum = im.Resolutions[resolution].SizeX-1; - vScrollBar.Maximum = im.Resolutions[resolution].SizeY-1; + hScrollBar.Maximum = im.Resolutions[resolution].SizeX; + vScrollBar.Maximum = im.Resolutions[resolution].SizeY; hScrollBar.Visible = true; vScrollBar.Visible = true; } @@ -217,6 +222,10 @@ public void AddImage(BioImage im) { hScrollBar.Visible = false; vScrollBar.Visible = false; + pictureBox.Width += 18; + pictureBox.Height += 18; + overlayPictureBox.Width += 18; + overlayPictureBox.Height += 18; } InitGUI(); UpdateImages(); @@ -529,6 +538,7 @@ public bool HardwareAcceleration hardwareAcceleration = value; if (value) { + GoToImage(0); cBar.Value = 0; rgbBoxsPanel.SendToBack(); pictureBox.BringToFront(); @@ -539,6 +549,7 @@ public bool HardwareAcceleration } else { + GoToImage(0); rgbBoxsPanel.SendToBack(); cBar.BringToFront(); cLabel.BringToFront(); @@ -724,7 +735,7 @@ public void RenderFrame() if (HardwareAcceleration && dx != null) { dx.BeginDraw(); - dx.RenderTarget2D.Clear(new SharpDX.Mathematics.Interop.RawColor4(1.0f, 1.0f, 1.0f, 1.0f)); + dx.RenderTarget2D.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f)); RectangleF rg = ToScreenRectF(PointD.MinX, PointD.MinY, PointD.MaxX - PointD.MinX, PointD.MaxY - PointD.MinY); //dx.RenderTarget2D.Transform = SharpDX.Matrix3x2.Rotation((float)Math.PI); @@ -751,13 +762,12 @@ public void RenderFrame() RectangleF rge = new RectangleF((float)((-Origin.X) - (w / 2)), (float)((-Origin.Y) - (h / 2)), (float)(Math.Abs(w)), (float)(Math.Abs(h))); RectangleF rec = new RectangleF((float)Images[x].Volume.Location.X, (float)Images[x].Volume.Location.Y, (float)Images[x].Volume.Width, (float)Images[x].Volume.Height); //if (rge.IntersectsWith(rec)) - dx.RenderTarget2D.DrawBitmap(dBitmaps[x], ToRawRectF(r.X, r.Y, r.Width, r.Height), 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear); + dx.RenderTarget2D.DrawBitmap(dBitmaps[x], ToRawRectF(r.X, r.Y, r.Width, r.Height), 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear); if (Images[x].selected) { dx.RenderTarget2D.DrawRectangle(ToRawRectF(r.X, r.Y, r.Width, r.Height), blue); } } - SetCoordinate(zBar.Value, cBar.Value, tBar.Value); bool bounds = showBounds; @@ -888,13 +898,16 @@ public void RenderFrame() } if (labels) { - //Lets draw the text of this ROI in the middle of the RO - float fw = ((float)an.Rect.X + ((float)an.Rect.W / 2)) - ((float)an.TextSize.Width / 2); - float fh = ((float)an.Rect.Y + ((float)an.Rect.H / 2)) - ((float)an.TextSize.Height / 2); - RawRectangleF r = ToRawRectF(fw, fh, an.TextSize.Width, an.TextSize.Height); - SharpDX.DirectWrite.TextFormat tex = new SharpDX.DirectWrite.TextFormat(dx.FactoryDWrite, an.font.FontFamily.ToString(), an.font.Size); - dx.RenderTarget2D.DrawText(an.Text, tex, r, b); - tex.Dispose(); + if (an.Text != null) + { + //Lets draw the text of this ROI in the middle of the RO + float fw = ((float)an.Rect.X + ((float)an.Rect.W / 2)) - ((float)an.TextSize.Width / 2); + float fh = ((float)an.Rect.Y + ((float)an.Rect.H / 2)) - ((float)an.TextSize.Height / 2); + RawRectangleF r = ToRawRectF(fw, fh, an.TextSize.Width, an.TextSize.Height); + SharpDX.DirectWrite.TextFormat tex = new SharpDX.DirectWrite.TextFormat(dx.FactoryDWrite, an.font.FontFamily.ToString(), an.font.Size); + dx.RenderTarget2D.DrawText(an.Text, tex, r, b); + tex.Dispose(); + } } if (bounds) { @@ -1146,7 +1159,8 @@ public void UpdateImage() dBitmaps[SelectedIndex].Dispose(); dBitmaps[SelectedIndex] = null; } - dBitmaps[SelectedIndex] = DBitmap.FromImage(dx.RenderTarget2D, BufferInfo.To32Bit(bitmap)); + Clipboard.SetImage(bitmap); + dBitmaps[SelectedIndex] = DBitmap.FromImage(dx.RenderTarget2D, bitmap); } @@ -1811,11 +1825,17 @@ private void DrawView(System.Drawing.Graphics g) if (rg.IntersectsWith(rec)) if (SelectedImage.isPyramidal) { + //We check tto see if image is valid + if (Bitmaps[i].PixelFormat == PixelFormat.DontCare) + UpdateImages(); g.ResetTransform(); g.DrawImage(Bitmaps[i], 0, 0, Bitmaps[i].Width, Bitmaps[i].Height); } else { + //We check tto see if image is valid + if (Bitmaps[i].PixelFormat == PixelFormat.DontCare) + UpdateImages(); g.DrawImage(Bitmaps[i], r.X, r.Y, r.Width, r.Height); } if (i == SelectedIndex && !SelectedImage.isPyramidal) @@ -1851,12 +1871,8 @@ private void rgbPictureBox_MouseMove(object sender, MouseEventArgs e) { return; } - PointF ip; - if (HardwareAcceleration) - ip = SelectedImage.ToImageSpace(new PointD(SelectedImage.Volume.Width - p.X, SelectedImage.Volume.Height - p.Y)); - else - ip = SelectedImage.ToImageSpace(p); - mousePoint = "(" + p.X + ", " + p.Y + ")"; + PointF ip = SelectedImage.ToImageSpace(p); + mousePoint = "(" + (p.X) + ", " + (p.Y) + ")"; if (e.Button == MouseButtons.XButton1 && !x1State && !Ctrl && Mode != ViewMode.RGBImage) { @@ -1964,7 +1980,6 @@ private void rgbPictureBox_MouseMove(object sender, MouseEventArgs e) Graphics.Graphics g = Graphics.Graphics.FromImage(SelectedBuffer); Graphics.Pen pen = new Graphics.Pen(Tools.DrawColor, (int)Tools.StrokeWidth, ImageView.SelectedImage.bitsPerPixel); g.FillEllipse(new Rectangle((int)ip.X, (int)ip.Y, (int)Tools.StrokeWidth, (int)Tools.StrokeWidth), pen.color); - update = true; UpdateImage(); } @@ -2406,7 +2421,7 @@ public float ToScreenW(double x) { if (HardwareAcceleration) { - return (float)(-x * PxWmicron); + return (float)(x * PxWmicron); } return (float)(x * PxWmicron); } @@ -2414,7 +2429,7 @@ public float ToScreenH(double y) { if (HardwareAcceleration) { - return (float)(-y * PxHmicron); + return (float)(y * PxHmicron); } return (float)(y * PxHmicron); } @@ -2469,7 +2484,7 @@ public void GoToImage() return; double dx = SelectedImage.Volume.Width / 2; double dy = SelectedImage.Volume.Height / 2; - Origin = new PointD(-(Images[SelectedIndex].Volume.Location.X + dx), -(Images[SelectedIndex].Volume.Location.Y + dy)); + Origin = new PointD(-(SelectedImage.Volume.Location.X + dx), -(SelectedImage.Volume.Location.Y + dy)); double wx, wy; if (HardwareAcceleration) { @@ -2486,6 +2501,8 @@ public void GoToImage() } public void GoToImage(int i) { + if (Images.Count <= i) + return; double dx = Images[i].Volume.Width / 2; double dy = Images[i].Volume.Height / 2; Origin = new PointD(-(Images[i].Volume.Location.X + dx), -(Images[i].Volume.Location.Y + dy)); @@ -2649,12 +2666,14 @@ private void overlayPictureBox_Resize(object sender, EventArgs e) Configuration conf = new Configuration(); private void dxPanel_SizeChanged(object sender, EventArgs e) { - conf.Width = dxPanel.Width; - conf.Height = dxPanel.Height; - dx.Update(conf, dxPanel.Handle); - UpdateView(); + if (HardwareAcceleration) + { + conf.Width = dxPanel.Width; + conf.Height = dxPanel.Height; + dx.Update(conf, dxPanel.Handle); + UpdateView(); + } } - private void contextMenuStrip_Opening(object sender, CancelEventArgs e) { Function.Initialize();