How to create Screw shape using Eyeshot's functions - c#

I need to create screw shape using Eyeshot's libraries in .NET application.
In SolidWorks this is easily accomplished with creating the shape/profile that needs to be swept/stretched, and helix curve which is used as a rail or direction.
In SolidWorks positioning helix start point to some point in profile's diameter and using "Sweep" command results that point to be driven/rotated around the helix and the wanted shape is created.
SolidWorks example
In Eyeshot I create my profile as a LinearPath entity and use
SweepAsSolid(ICurve rail, double tol, sweepMethodType sweepMethod = sweepMethodType.RotationMinimizingFrames)
function but the result is different. It seems that SweepAsSolid function position helix start point in the center of the profile and different shape is created.
Using helix as a rail:
Eyeshot example with helix as a rail
Using straight line as a rail:
Eyeshot example with straight line as a rail
Is there a way to get wanted shape with Eyeshot's libraries using the same procedure as in SolidWorks?

I think the method ExtrudeWithTwist() is what you are looking for:
Point3D moveText = new Point3D(0,3,0);
// new example
Line l1 = new Line(-3, 0, 3, 0);
Line l2 = new Line(3, 0, 3, 2);
Line l3 = new Line(3, 2, -3, 2);
Line l4 = new Line(-3, 2, -3, 0);
CompositeCurve cc1 = new CompositeCurve(l1, l2, l3, l4);
Surface[] loft1 = Surface.ExtrudeWithTwist(cc1, new Vector3D(0, 0, -10), new Point3D(0, 1, 0), Math.PI, 0.1);
foreach (Surface s in loft1)
{
s.Translate(10, 0, 0);
}
model.Entities.AddRange(loft1, 0, Color.Orange);

Related

How to add fillet between 2 curves in eyeshot

I found the method for Chamfer and fillet but could not really understand the implementation of it.
Basically I am not able to evoke Fillet property.
http://documentation.devdept.com/100/WPF/topic4434.html
If anybody can guide.
Code:
ICurve line1 = new Line(0, 0, 0, 57.06, 0, 0);
ICurve line2 = new Line(0, 0, 0, 0, 45, 0);
So how do I fillet between these 2 lines. I cant locate Fillet method to pass these ICurves.
Adding the image, for better understanding of problem. As you can see I am not able to invoke Curve class and subsequently fillet property. I am using Eyeshot version 12
enter image description here
Image of all the dll added, but still same error
enter image description here
Thanks.
Here you go bud. Hopefully this is a decent start. I set flip 1 to be true, so that line1's end point is at the start of line 2. (I didn't actually plot this, but I think that's what they're asking for)
I also made the assumption you want to trim lines 1 and 2.
Eyeshots documentation on their website is pretty decent. Reading those can definitely help you understand the constructors a little better.
The output of the fillet command is an arc, which makes sense. You will most likely need to add myFillet seperately from lines 1 and 2 to the viewport, as they are all separate entities.
ICurve line1 = new Line(0, 0, 0, 57.06, 0, 0);
ICurve line2 = new Line(0, 0, 0, 0, 45, 0);
double radius = 10.0;
bool flip1 = true;
bool flip2 = false;
bool trim1 = true;
bool trim2 = true;
Arc myFillet;
Curve.Fillet(line1, line2, radius, flip1, flip2, trim1, trim2, out myFillet);

Render a basic Quad to Screen?

I have been trying to accomplish this for quite some time with no success; I've looked at several relevant questions here on StackOverflow with no success; I've also followed 6 different tutorials that ALL followed pretty much the same process:
Build the vertices: -1, -1, 0, -1, 1, 0, 1, 1, 0, and 1, -1, 0.
Build the indices: 0, 1, 2, 0, 2, 3.
Create the Vertex and Index buffers.
Clear the RenderTargetView.
Set the current Vertex and Pixel shaders.
Update the constant buffers if you have any.
Render the quad (see below).
Rinse and repeat 4 - 8.
Now, the reason this is driving me up the wall is because I can render far more advanced objects such as:
Spheres
3D Lines
Fans
My code for creating the quad is pretty much the same as everyone else's:
public class Quad {
private void SetVertices() {
float width = Rescale(Size.Width, 0, Application.Width, -1, 1);
float height = Rescale(Size.Height, 0, Application.Height, -1, 1);
vertices = new Vertex[] {
new Vertex(new Vector3(-width, -height, 0), Vector3.ForwardLH, Color.White),
new Vertex(new Vector3(-width, height, 0), Vector3.ForwardLH, Color.White),
new Vertex(new Vector3(width, height, 0), Vector3.ForwardLH, Color.White),
new Vertex(new Vector3(width, -height, 0), Vector3.ForwardLH, Color.White)
}
indices = new int[] { 0, 1, 2, 0, 2, 3 };
vertexBuffer = Buffer.Create(Device3D, BindFlags.VertexBuffer, vertices);
vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SIzeOf<Vertex>(), 0);
indexBuffer = Buffer.Create(Device3D, BindFlags.IndexBuffer, indices);
indexCount = indices.Length;
}
public void Render() {
if (shaderResourceView != null)
context3D.PixelShader.SetShaderResource(0, shaderResourceView);
context3D.PixelShader.SetSampler(0, samplerState);
context3D.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
context3D.InputAssembler.SetVertexBuffers(0, vertexBinding);
context3D.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0);
context3D.DrawIndexed(totalIndexCount, 0, 0);
}
}
Notes
I am using a right handed coordinate system (for some reason the previous developer hardwired Vector3.ForwardLH into some places that I now cannot get rid of yet); if that helps any and I cannot currently convert to a left handed coordinate system.
Am I missing something here? Why am I unable to render a basic quad?
If you feel more information is needed feel free to let me know and I will add it on request.
When rendering with Direct3D 11, you need to know the all the state. You do not mention what your BlendState, DepthStencilState, or RasterState settings are here which is a likely reason you aren't getting the results you want.
If the DepthStencilState is such set use the Z-Buffer, then the fact that your vertices have a 0 for the Z means they are going to get culled. You can set a depth/stencil state without Z writes or Z tests, and you should definitely turn off Z writes when drawing 2D stuff anyhow. You can also pass something like 0.5 for the Z value for your vertices which is fairly common for 2D drawing with 3D APIs.
If you backface culling enabled in the RasterState, then the winding order of your vertices could result in them being skipped. You can play with different winding orders, or disable culling.
It also really matters what your Vertex Shader and Pixel Shader are here. You don't show the code for setting your shaders or shader constants, and you don't show the HLSL.
You should seriously consider using the SharpDX Toolkit SpriteBatch class for efficient quad rendering or looking at their source for it.
I know you are using SharpDX an C#, but you might find it useful to see the DirectX Tool Kit for DX11 tutorial on drawing 2D shapes.

VisuaBrush Scaling Incorrectly with Canvas as Visual element

I've been fighting with this problem for a few days now and have had zero luck getting it resolved or finding any support on the web. Basically, I am trying to create a VisualBrush with a canvas as the visual element. I want to be able to draw several lines on this canvas and will eventually be mapping it to a 3D surface (2 parallel triangles forming a rectangle). I've set up the texture coordinates and can confirm everything works by simply using an ImageBrush or something of that nature. The problem I am having is that the canvas refuses to maintain its size and is constantly scaled based on the content that is inside it. So for example, if the canvas is 100x100 and I have a single line inside it from (0, 0) to (50, 50), the canvas would be scaled such that only the 50x50 portion with content inside is mapped to the texture coordinates and onto the 3D surface. I have tried many combinations of Viewport/Viewbox/StretchMode/Alignment/etc and can't find anything that stops this from happening. I am setting the Width and Height properties of the canvas so I can't see why it would perform differently in the VisualBrush versus if I simply added it into a grid or some other layout container.
Here's some code to help illustrate the problem.
// create the canvas for the VisualBrush
Canvas drawCanvas = new Canvas();
drawCanvas.Background = Brushes.Transparent; // transparent canvas background so only content is rendered
drawCanvas.Width = 100;
drawCanvas.Height = 100;
// add a line to the canvas
Line l = new Line();
l.X1 = 0;
l.Y1 = 0;
l.X2 = 50;
l.Y2 = 50;
l.Stroke = Brushes.Red;
l.StrokeThickness = 2;
drawCanvas.Children.Add(l);
// create rectangular surface mesh
MeshGeometry3D TableMesh = new MeshGeometry3D();
CreateRectangleModel(
new Point3D(0, 0, 0),
new Point3D(0, 0, 100),
new Point3D(100, 0, 100),
TableMesh);
// need to include texture coordinates for our table mesh to map canvas to 3D model
TableMesh.TextureCoordinates = new PointCollection {
new Point(0, 0), new Point(0, 1), new Point(1, 1),
new Point(1, 1), new Point(0, 1), new Point(0, 0),
new Point(1, 1), new Point(1, 0), new Point(0, 0),
new Point(0, 0), new Point(1, 0), new Point(1, 1)
};
// finally make our visual brush with the canvas we have created
VisualBrush vb = new VisualBrush();
vb.Visual = drawCanvas;
Material TableMaterial = new DiffuseMaterial(vb);
// add our new model to the scene
GeometryModel3D geometry = new GeometryModel3D(TableMesh, TableMaterial);
Model3DGroup group = new Model3DGroup();
group.Children.Add(geometry);
ModelVisual3D previewTable = new ModelVisual3D();
previewTable.Content = group;
MainViewport.Children.Add(previewTable);
And the one function I referenced is
private void CreateRectangleModel(Point3D pStart, Point3D pCorner1, Point3D pEnd, MeshGeometry3D mesh)
{
// pCorner -> O--O <- pEnd
// | /|
// |/ |
// pStart -> O--O <- pCorner2
// find the remaining point for our rectangle
Point3D pCorner2 = new Point3D(
pStart.X + (pEnd.X - pCorner1.X),
pStart.Y + (pEnd.Y - pCorner1.Y),
pStart.Z + (pEnd.Z - pCorner1.Z));
// add necessary triangles to our group (we create 2 facing up, 2 facing down)
CreateTriangleModel(pStart, pCorner1, pEnd, mesh);
CreateTriangleModel(pEnd, pCorner1, pStart, mesh);
CreateTriangleModel(pEnd, pCorner2, pStart, mesh);
CreateTriangleModel(pStart, pCorner2, pEnd, mesh);
}
I can't get the canvas to maintain its set size of 100x100 unless the children content goes all the way to these extremes. For my purposes, the line coordinates could be anywhere within the canvas and I need to have it maintain its desired shape regardless of the content.
Any advice would be greatly appreciated!
Some things to try:
Create an image file of 100x100 pixels by hand and then put it into an ImageBrush, and use that brush in your DiffuseMaterial. This is to confirm that your texture coords, etc are being set up properly.
Instead of using a Transparent Background colour on your Canvas, try Green (this is to see if the texture is being cropped based on transparent pixels)
If the cropping is being done of your texture (due to transparency)...then try putting a rectangle on the Canvas at the dimensions you want the texture to be...maybe that will change something.
Or try using RenderTargetBitmap to create an image from your Canvas visual...then use that image within an ImageBrush. (you can then confirm that the image is of your expected area of 100x100).
Finally, instead of using a Canvas+VisualBrush to create your texture try creating the Brush by using a DrawingBrush+DrawingGroup+GeometryDrawing

C# DirectX Draw lines using DrawUserPrimitives works fine but DrawPrimitives don't work

I've got problem with DirectX in C#. I want to draw some lines. Firstly I've done it with DrawUserPrimitives and all is fine. But then I switched to vertexBuffer because I want to make rotations and other camera action. And I can't see nothing in the window.
There is part of code that fills vertexBuffer and draw verts on a plane.
vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored),
8 * (CurrentPanel.ElementsCount() + 1), m_device, Usage.None,
CustomVertex.PositionColored.Format, Pool.Default);
CustomVertex.PositionColored[] verts =
(CustomVertex.PositionColored[])vertexBuffer.Lock(0, 0);
//this function returns array of verts based on given points.
verts = CurrentPanel.GetLines();
vertexBuffer.Unlock();
m_device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(255, 255, 255).ToArgb(), 1.0f, 0);
m_device.BeginScene(); //m_device is my DirectX.Device
SetupViewport(); //Set all of matrixes...
m_device.SetStreamSource(0, vertexBuffer, 0);
m_device.VertexFormat = CustomVertex.PositionColored.Format;
//m_device.DrawUserPrimitives(PrimitiveType.LineList, CurrentPanel.ElementsCount() * 4, verts); // <- WHEN I USE THIS ALL IS OK
m_device.DrawPrimitives(PrimitiveType.LineList, 0, 4*(CurrentPanel.ElementsCount()+1)); //<-DO NOT WORK
m_device.EndScene();
m_device.Present();
I would like to add that this code is based on Microsoft DirectX samples.
You did not write the vertices to the VertexBuffer.
You created a variable named verts and used it to reference the Array that is returned from the Lock method, then you replaced the array referenced by verts to be the return value from CurrentPanel.GetLines().
But you didn't actually write anything to the VertexBuffer.

Object detection using emgu cv CvInvoke.cvHoughCircles

I want to detect objects using cvHoughCircles method in visual c#.If anyone knows how to do this please help me.
Edit Details:
I searched in the Internet there is examples using gray.HoughCircles method.
this is my code.
Image<Bgr, Byte> image = capture.QueryFrame();
MCvScalar hsv_min = new MCvScalar(150, 84, 130, 0);
MCvScalar hsv_max = new MCvScalar(358, 256, 255, 0);
IntPtr hsv_frame = CvInvoke.cvCreateImage(new System.Drawing.Size(640, 480),IPL_DEPTH.IPL_DEPTH_8U, 3);
IntPtr thresholded = CvInvoke.cvCreateImage(new System.Drawing.Size(640, 480), IPL_DEPTH.IPL_DEPTH_8U, 1);
CvInvoke.cvCvtColor(image, hsv_frame, COLOR_CONVERSION.CV_BGR2HSV);
CvInvoke.cvInRangeS(hsv_frame, hsv_min, hsv_max, thresholded);
IntPtr storage = CvInvoke.cvCreateMemStorage(0);
CvInvoke.cvSmooth(thresholded, thresholded, SMOOTH_TYPE.CV_GAUSSIAN, 9, 9, 0, 0);
IntPtr circles= CvInvoke.cvHoughCircles(thresholded, storage,HOUGH_TYPE.CV_HOUGH_GRADIENT , 2, 4, 100, 50, 10, 400);
In the following link there is code.But it is in pythen.So what I'm doing is trying to convert it into visual c#.
http://www.lirtex.com/robotics/fast-object-tracking-robot-computer-vision/#comment-847
I want to take all detected circles in to for loop and then draw circle to corresponding objects as in pythen code.
I tried to use foreach loop but there is error,
foreach statement cannot operate on variables of type 'System.IntPtr' because 'System.IntPtr' does not contain a public definition for 'GetEnumerator'.
Is there any method to avoid this error.
Did you try this tutorial?
Shape (Triangle, Rectangle, Circle, Line) Detection in CSharp
This contains good tutorial which may be help you.

Categories

Resources