been trying to change a renderer I wrote from SlimDX to SharpDX and ran into a problem. I want to render to multiple render targets (in this case color and object ID for picking)
This is the initialization of the rendertargets (all with same dimension and multisample setting)
//Swapchain, Device, Primary Rendertarget
var description = new SwapChainDescription()
{
BufferCount = 1,
Usage = Usage.RenderTargetOutput,
OutputHandle = Form.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard
};
this.Device = new Device(adapter);
this.SwapChain = new SwapChain(factory, Device, description);
this.backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(SwapChain, 0);
this.RenderTargetView = new RenderTargetView(Device, backBuffer);
//Depthbuffer
Texture2DDescription descDepth = new Texture2DDescription();
descDepth.Width = (int)Viewport.Width;
descDepth.Height = (int)Viewport.Height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = Format.D32_Float;
descDepth.Usage = ResourceUsage.Default;
descDepth.SampleDescription = new SampleDescription(1, 0);
descDepth.BindFlags = BindFlags.DepthStencil;
descDepth.CpuAccessFlags = 0;
descDepth.OptionFlags = 0;
using (Texture2D depthStencil = new Texture2D(Device, descDepth))
{
depthView = new DepthStencilView(Device, depthStencil);
}
//Rendertargetview for the ID
Texture2DDescription IdMapDesc = new Texture2DDescription();
IdMapDesc.Width = (int)Viewport.Width;
IdMapDesc.Height = (int)Viewport.Height;
IdMapDesc.ArraySize = 1;
IdMapDesc.MipLevels = 1;
IdMapDesc.Format = Format.R16_UInt;
IdMapDesc.Usage = ResourceUsage.Default;
IdMapDesc.SampleDescription = new SampleDescription(1, 0);
IdMapDesc.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget;
IdMapDesc.CpuAccessFlags = 0;
IdMapDesc.OptionFlags = 0;
using (Texture2D idMap = new Texture2D(Device, IdMapDesc))
{
idView = new RenderTargetView(Device, idMap);
}
This is how I do the Rendering
public override void Render()
{
Context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1f, 0);
Context.OutputMerger.SetTargets(depthView, RenderTargetView);
staticMeshRenderer.UpdateCameraConstants();
foreach(TerrainSegment segment in terrain.SegmentMap)
{
terrainRenderer.Draw(segment, null);
}
objectManager.DrawContent(Device);
}
producing this output (can't post images, it's a scene with working depthstencil)
However when using multiple rendertargets like this
Context.OutputMerger.SetTargets(depthView, RenderTargetView, idView);
the Depthstencil stops doing its job.
HLSL code used for both attempts:
struct PS_Output
{
float4 Color : SV_TARGET0;
uint ID : SV_TARGET1;
};
PS_Output PShader(VS_OutputStatic input)
{
PS_Output output;
output.ID = 3; //test
output.Color = Diffuse.Sample(StateLinear, input.TexCoords).rgba;
return output;
}
What am I doing wrong here?
Thanks in advance!
Debugging with RenderDoc showed that my Buffer Dimensions were NOT the same. Fixing that solved the problem.
Related
i am using C# EmguCv library to detect diamonds from the image capture by a live camera and saved into the folder. i have done other task of the project and only remaining the detection part and almost got it but just missing something that i don't know where is the problem . so here is the Image and it should be detected as Image2 perfect as this image so now i am trying something but it not giving me the result i want. here's i what i am getting is image3 and image4.
here is my code:
imgInput = new Image<Bgr, byte>(img_path);
if (imgInput == null)
{
return;
}
try
{
// Convert image to grayscale
Mat grayImage = new Mat();
CvInvoke.CvtColor(imgInput, grayImage, ColorConversion.Bgr2Gray);
// Apply Gaussian blur to reduce noise
CvInvoke.GaussianBlur(grayImage, grayImage, new Size(7, 7), 4);
// Apply Canny edge detection
Mat edges = new Mat();
CvInvoke.Canny(grayImage, edges, 75, 200);
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
CvInvoke.FindContours(edges, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
int jk = 0;
dataGridView1.Columns.Add("stone_id", "Stone ID");
for (int i = 0; i < contours.Size; i++)
{
double perimeter = CvInvoke.ArcLength(contours[i], true);
VectorOfPoint approx = new VectorOfPoint();
CvInvoke.ApproxPolyDP(contours[i], approx, 0.04 * perimeter, true);
var bbox = CvInvoke.BoundingRectangle(contours[i]);
process_img = new Image<Bgr, byte>(img_path);
process_img.ROI = bbox;
var img = process_img.Copy();
if (jk == sel_row_id)
{
CvInvoke.DrawContours(imgInput, contours, i, new MCvScalar(0, 255, 17), 2);
if (contours.Size > 0)
{
byte maxRed, maxBlue, maxGreen;
maxRed = maxBlue = maxGreen = 0;
float meanRed, meanBlue, meanGreen;
meanRed = meanBlue = meanGreen = 0;
double medRed,medBlue,medGreen;
medRed = medBlue = medGreen = 0;
FindMax(img.Bitmap, ref maxRed, ref maxBlue, ref maxGreen, ref meanRed, ref meanBlue, ref meanGreen, ref medRed, ref medBlue, ref medGreen);
R_txtbox.Text = maxRed.ToString();
B_txtbox.Text = maxBlue.ToString();
G_txtbox.Text = maxGreen.ToString();
R_mean.Text = meanRed.ToString();
B_mean.Text = meanBlue.ToString();
G_mean.Text = meanGreen.ToString();
R_med.Text = medRed.ToString();
B_med.Text = medBlue.ToString();
G_med.Text = medGreen.ToString();
pictureBox5.Image = img.ToBitmap();
//colorCode.Text = myRgbColor.ToString();
}
}
else
{
CvInvoke.DrawContours(imgInput, contours, i, new MCvScalar(0, 0, 255), 2);
}
dataGridView1.Rows.Add(jk.ToString());
jk++;
pictureBox4.Image = imgInput.Bitmap;
img.Save("F:\\Objects" + "\\" + (i + 1) + ".jpg");
}
RefreshGridView();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I am a beginner in xamarin ios, I want to create a table with 3 columns and multiple rows, and the no of row is depends on the data coming from the API .How can I do this...
Please help me...
I want to create the table like this...
You can simulate drawing the chart by following steps.
Custom TableHeaderView with three black rectangle ,just need add three label with its black border.
Do the same work as step1 with TableViewCell, and then place a textfield in first rectangle, place a button and a label in second rectangle,place two button in third rectangle.
Sample Code
TableHeaderView
public class headerView : UIView
{
public headerView()
{
this.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 50);
nfloat width = UIScreen.MainScreen.Bounds.Width / 3;
UILabel title = new UILabel();
title.Text = "Title";
title.TextColor = UIColor.Black;
title.TextAlignment = UITextAlignment.Center;
title.Font = UIFont.SystemFontOfSize(20);
title.Layer.BorderColor = UIColor.Black.CGColor;
title.Layer.BorderWidth = 1;
title.Frame = new CGRect(0, 0, width, 50);
this.Add(title);
UILabel File = new UILabel();
File.Text = "File";
File.TextColor = UIColor.Black;
File.TextAlignment = UITextAlignment.Center;
File.Font = UIFont.SystemFontOfSize(20);
File.Layer.BorderColor = UIColor.Black.CGColor;
File.Layer.BorderWidth = 1;
File.Frame = new CGRect(width, 0, UIScreen.MainScreen.Bounds.Width / 3, 50);
this.Add(File);
UILabel Option = new UILabel();
Option.Text = "Option";
Option.TextColor = UIColor.Black;
Option.TextAlignment = UITextAlignment.Center;
Option.Font = UIFont.SystemFontOfSize(20);
Option.Layer.BorderColor = UIColor.Black.CGColor;
Option.Layer.BorderWidth = 1;
Option.Frame = new CGRect(width * 2, 0, UIScreen.MainScreen.Bounds.Width / 3, 50);
this.Add(Option);
}
}
table.TableHeaderView = new headerView();
TableViewCell
public CustomVegeCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
{
SelectionStyle = UITableViewCellSelectionStyle.Gray;
nfloat width = UIScreen.MainScreen.Bounds.Width / 3;
UIView headingLabel = new UIView();
headingLabel.Layer.BorderColor = UIColor.Black.CGColor;
headingLabel.Layer.BorderWidth = 1;
headingLabel.Frame = new CGRect(0, 0, width, 100);
UIView subheadingLabel = new UIView();
subheadingLabel.Layer.BorderColor = UIColor.Black.CGColor;
subheadingLabel.Layer.BorderWidth = 1;
subheadingLabel.Frame = new CGRect(width, 0, width, 100);
UIView imageView = new UIView();
imageView.Layer.BorderColor = UIColor.Black.CGColor;
imageView.Layer.BorderWidth = 1;
imageView.Frame = new CGRect(width *2, 0, width, 100);
ContentView.Add (headingLabel);
ContentView.Add (subheadingLabel);
ContentView.Add (imageView);
///add additional control here
}
I have a couple of problems with a MSChart plotted in a Winform.
I can't get axis Y2 values displayed on the right hand side of the chart, which should be the default - similar to this question
the stripline won't plot, and
is it possible to line up the zero values of axes Y1 and Y2?
Thanks for any help.
ChartArea TestChartArea = new ChartArea();
public void CreateChartArea()
{
TestChartArea.Name = "TestChartArea";
TestChartArea.BackColor = Color.LightGreen;
TestChartArea.Position = new ElementPosition { Height = 100, Width = 80, X = 2, Y = 5 };
//TestChartArea.Position = new ElementPosition { Auto = true };
TestChartArea.AxisY = new Axis
{
Enabled = AxisEnabled.True,
IsLabelAutoFit = true,
IsMarginVisible = true,
LabelStyle = new LabelStyle { Format = "P2", ForeColor = Color.DarkBlue, Font = new Font("Arial", 10, FontStyle.Regular) },
LineColor = Color.Black,
MajorGrid = new Grid { LineColor = Color.White, LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.Black }
};
TestChartArea.AxisY2 = new Axis
{
Enabled = AxisEnabled.True,
IsLabelAutoFit = true,
IsMarginVisible = true,
LabelStyle = new LabelStyle { Format = "P2", ForeColor = Color.DarkBlue, Font = new Font("Arial", 10, FontStyle.Regular) },
LineColor = Color.Transparent,
MajorGrid = new Grid { LineColor = Color.Yellow, LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.Blue }
};
TestChartArea.AxisX = new Axis
{
Enabled = AxisEnabled.True,
Crossing = 0,
LineWidth = 1,
IsLabelAutoFit = true,
IsMarginVisible = false,
LabelStyle = new LabelStyle { Angle=-45,Format = "N0", ForeColor = Color.Black, Font = new Font("Arial", 8, FontStyle.Regular) },
LineColor = Color.Black,
MajorGrid = new Grid { LineColor = Color.White, LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.LightGray, Size = 4.0f },
Name="Spot"
};
}
public void PlotChart()
{
int[] Xseries = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double[] AXJO = { 0.0025, 0.0015, -0.001, 0.002, 0.0045, -0.002, -0.003, 0.0001, -0.004, -0.0075 };
double[] ES = { 0.0020, 0.0010, -0.0005, 0.003, 0.0025, -0.001, -0.0015, 0.0005, -0.0032, -0.006 };
double[] Diff = new double[10];
// pair return
for (int i = 0; i < 10; i++)
{
Diff[i] = AXJO[i] - ES[i];
}
TestChart.BackColor = Color.LightGoldenrodYellow;
TestChart.BackSecondaryColor = Color.LightBlue;
if (TestChart.Series.IsUniqueName("AXJO"))
{
TestChart.Series.Add("AXJO");
TestChart.Series["AXJO"].YAxisType = AxisType.Primary;
TestChart.Series["AXJO"].Color = Color.Green;
TestChart.Series["AXJO"].ChartType = SeriesChartType.Line;
TestChart.Series["AXJO"].Points.DataBindXY(Xseries, AXJO);
TestChart.Series["AXJO"].ChartArea = "TestChartArea";
}
if (TestChart.Series.IsUniqueName("ES"))
{
TestChart.Series.Add("ES");
TestChart.Series["ES"].YAxisType = AxisType.Primary;
TestChart.Series["ES"].Color = Color.Red;
TestChart.Series["ES"].ChartType = SeriesChartType.Line;
TestChart.Series["ES"].Points.DataBindXY(Xseries, ES);
TestChart.Series["ES"].ChartArea = "TestChartArea";
}
if (TestChart.Series.IsUniqueName("Diff"))
{
TestChart.Series.Add("Diff");
TestChart.Series["Diff"].YAxisType = AxisType.Secondary;
TestChart.Series["Diff"].Color = Color.Blue;
TestChart.Series["Diff"].ChartType = SeriesChartType.Line;
TestChart.Series["Diff"].Points.DataBindXY(Xseries, Diff);
TestChart.Series["Diff"].ChartArea = "TestChartArea";
}
}
public void AddStripLine()
{
// add stripline at Diff=zero
StripLine ZeroDiff = new StripLine();
ZeroDiff.ForeColor = Color.Black;
ZeroDiff.BackColor = Color.Black;
ZeroDiff.StripWidth = 1;
ZeroDiff.BorderWidth = 2;
ZeroDiff.Interval = 0;
ZeroDiff.IntervalOffset = 10;
TestChart.ChartAreas["TestChartArea"].AxisY2.StripLines.Add(ZeroDiff);
}
private void button1_Click(object sender, EventArgs e)
{
PlotChart();
AddStripLine();
}
}
You asked about the unwanted placement of the AxisY2 by setting its Crossing property to 0
Simply not setting it, thus leaving it at the default double.NaN for automatically placing it at the right will resolve the issue..:
Crossing = double.NaN
To make a stripline show, it needs to start within the visible range of its axis. Offsetting it by 10 is way overboard for your data.. Also making it black is probably not what you want, unless you only want a thin line, not a colored area..
The basic rules for StripLines are:
When Interval = 0 only one stripline is shown at IntervalOffset with a width/height of StripWidth
When Interval > 0 many striplines are shown, going over the whole axis; unless you have a semi-tranparent color you need to make sure that StripWidth < Interval or else there is no space between them!
All measures are in axis-values; the types can be set with StripWidthType and IntervalType; useful especially when using one of the DateTime units.
To make the 0 values of both y-axes align, you need to tweak the Minimum and/or Maximum values of one or both axes. This may be a bit tricky and you will probably need to look into your data and take full control of spacing and placing the axis labels..
I am using System.Web.UI.DataVisualization.Charting library to generate column chart in c#. But I want to remove x and y axis. want only the bars. I remover grid lines using following code
chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
How can I remove axis lines and its values ?
var chart = new Chart
{
Width = 80,
Height = 125,
RenderType = RenderType.ImageTag,
AntiAliasing = AntiAliasingStyles.All,
TextAntiAliasingQuality = TextAntiAliasingQuality.High
};
chart.Titles.Add("50");
chart.Titles.Add("Strongly Disagree");
chart.Titles[0].Font = new Font("Arial", 8f,FontStyle.Bold);
chart.Titles[0].ForeColor = Color.DarkGray;
chart.Titles[1].Font = new Font("Arial", 7f);
chart.Titles[1].ForeColor = Color.DarkGray;
chart.Titles[0].Position.X = 50;
chart.Titles[0].Position.Y = 50;
chart.Titles[1].Position.X = 50;
chart.Titles[1].Position.Y = 90;
chart.ChartAreas.Add("");
chart.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 12f);
chart.ChartAreas[0].AxisY.TitleFont = new Font("Arial", 12f);
chart.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 10f);
chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
chart.ChartAreas[0].BackColor = Color.White;
chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart.Series.Add("");
chart.Series[0].ChartType = SeriesChartType.Column;
int i = 0;
foreach (var q in myOrderList)
{
if (i == 0)
{
chart.Series[0].Points.AddXY("", Convert.ToDouble(q.NumberOfOrders));
chart.Series[0].Points[0].Color = Color.Orchid;
}
else
{
chart.Series[0].Points.AddXY("", Convert.ToDouble(q.NumberOfOrders));
chart.Series[0].Points[1].Color = Color.DarkViolet;
}
i++;
}
using (var chartimage = new MemoryStream())
{
chart.SaveImage(chartimage, ChartImageFormat.Png);
return chartimage.GetBuffer();
}
I found the solution..
chart.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
chart.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
chart.ChartAreas[0].AxisX.MinorTickMark.Enabled = false;
chart.ChartAreas[0].AxisX.Interval = 0;
chart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
chart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
chart.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
chart.ChartAreas[0].AxisY.MinorTickMark.Enabled = false;
chart.ChartAreas[0].AxisX.LineWidth = 0;
chart.ChartAreas[0].AxisY.LineWidth = 0;
I am getting an issue with SlimDX March SDK (For DXSDK11 June 2010 I believe). The problem is that whenever I turn the attach the depth view to the output merger state I don't get any output on the screen. I have compared my code with DX11 samples and it does seem to be correct. I have tried all sorts of flags and formats for the depth test (including always passing etc.) but nothing seems to work. I'd appreciate if anyone can spot a mistake. Here is the code. Here are the steps:
Initialize the back buffer:
D3DDevice device;
SwapChain swapChain;
/// Create the swap chain
SwapChainDescription desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription
{
Width = ContextSettings.Width,
Height = ContextSettings.Height,
RefreshRate = new SlimDX.Rational(ContextSettings.RefreshRate, 1),
Format = ContextSettings.BufferFormat,
},
IsWindowed = !ContextSettings.FullScreen,
OutputHandle = WindowHandle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
};
FeatureLevel[] featureLevels = new FeatureLevel[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1 };
DriverType driverType = DriverType.Hardware;
D3DDevice.CreateWithSwapChain(driverType, DeviceCreationFlags.Debug, featureLevels, desc, out device, out swapChain);
Device = device;
SwapChain = swapChain;
/// Setup window association
Factory factory = swapChain.GetParent<Factory>();
factory.SetWindowAssociation(WindowHandle, WindowAssociationFlags.IgnoreAll);
/// Setup back buffers and render target views
RenderBuffer = DXTexture2D.FromSwapChain<DXTexture2D>(swapChain, 0);
RenderView = new RenderTargetView(Device, RenderBuffer);
Then initialize the depth buffer:
Format depthFormat = Format.D32_Float;
Texture2DDescription depthBufferDesc = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
Format = depthFormat,
Height = width,
Width = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription( 1, 0 ),
Usage = ResourceUsage.Default
};
DepthBuffer = new DXTexture2D(Device, depthBufferDesc);
DepthStencilViewDescription dsViewDesc = new DepthStencilViewDescription
{
ArraySize = 0,
Format = depthFormat,
Dimension = DepthStencilViewDimension.Texture2D,
MipSlice = 0,
Flags = 0,
FirstArraySlice = 0
};
DepthView = new DepthStencilView(Device, DepthBuffer, dsViewDesc);
DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
{
IsDepthEnabled = true,
IsStencilEnabled = false,
DepthWriteMask = DepthWriteMask.All,
DepthComparison = Comparison.Less,
};
DepthState = DepthStencilState.FromDescription(Device, dsStateDesc);
Setup the render targets:
DeviceContext.OutputMerger.DepthStencilState = DepthState;
DeviceContext.OutputMerger.SetTargets(DepthView, RenderView);
DeviceContext.Rasterizer.SetViewports(new Viewport(0, 0, ContextSettings.Width, ContextSettings.Height, 0.0f, 1.0f));
Clear();
As soon as I remove DepthView from OutputMerger.SetTargets I start seeing images on the screen (without the depth test of course) and vice-versa otherwise.
It turned out that in the depthBufferDesc, I was passing width to the Height variable and height to the Width. This was creating the two render targets with different dimensions which was breaking it down.