How to create helical curve using inventor api and c# or vb.net - helix

I have code in c# windows app creating a line in a 2D sketch. And then I created a 3D sketch. Eventually I want to add a helical curve around this line from the 3D sketch. Can anyone help me please to solve this issue? Thanks in advance.
public void MyMethod(Inventor.Application ThisApplication)
{
PartDocument oSheetMetalDoc = (PartDocument)m_oInventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, m_oInventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kMetricSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"), true);
// Set a reference to the component definition.
SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oSheetMetalDoc.ComponentDefinition;
// Set a reference to the sheet
// metal features collection.
SheetMetalFeatures oSheetMetalFeatures = (SheetMetalFeatures)oCompDef.Features;
// Create a new sketch on the X-Y work plane.
PlanarSketch oSketch = default(PlanarSketch);
oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);
TransientGeometry oTransGeom = (TransientGeometry)ThisApplication.TransientGeometry;
// Draw a 4cm x 3cm rectangle with the
// corner at (0,0)
SketchLine line = (SketchLine)oSketch.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(0, 500)); // 2. ihtimal
// skecth line turn to centerline
line.Centerline = true;
ThisApplication.ActiveView.GoHome();
// Create a 3D sketch.
Sketch3D sketch3 = (Sketch3D)oCompDef.Sketches3D.Add();
SketchEntity3D selectObj = m_oInventorApp.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Select 3d sketch entity");
if (selectObj == null)
{
}
// HelicalConstraint3D . want to add helical curve around the line above
}

This is iLogic/VB.net code for creating helix curve based on selected SketchLine.
Part document must be active, and at least one SketchLine must be visible for selection.
Sub Main()
Dim oSketchLine As SketchLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter,
"Select line")
CreateHelicalCurve(oSketchLine)
End Sub
Private Sub CreateHelicalCurve(oSketchLine As SketchLine)
Dim partDef As PartComponentDefinition = oSketchLine.Parent.Parent
Dim sketch3D As Sketch3D = partDef.Sketches3D.Add()
Dim axisStartPoint As Point = oSketchLine.StartSketchPoint.Geometry3d
Dim axisEndPoint As Point = oSketchLine.EndSketchPoint.Geometry3d
Dim curveStartPoint As Point = axisStartPoint.Copy()
curveStartPoint.TranslateBy(ThisApplication.TransientGeometry.CreateVector(0, 0, 1))
Dim diameter As Double = 5 ' [cm]
Dim pitch As Double = 1 ' [cm]
Dim revolution As Object = Nothing ' Optional argument
Dim height As Double = 5 ' [cm]
Dim helicalCurveDefinition As HelicalCurveConstantShapeDefinition = sketch3D.HelicalCurves.
CreateConstantShapeDefinition(
HelicalShapeDefinitionTypeEnum.kPitchAndHeightShapeType,
axisStartPoint,
axisEndPoint,
curveStartPoint,
diameter,
pitch,
revolution,
height
)
sketch3D.HelicalCurves.Add(helicalCurveDefinition)
End Sub

Related

Extracting motion detector blob

Edit: Motion Detection I believe this may answer my question...
I want to not only detect motion, but read where the motion occurred in the frame. Nothing in MotionDetector seems to have anything about its location. I thought maybe I could run it through MotionDetector then extract the biggest blob, but that doesn't seem to work either. It only picks up one blob.
Video clip is a vehicle coming down a ramp. mainPBX is the original frame, main2PBX is the altered frame (with the biggest blob overlayed). My thought is to read when the blob goes from smaller to bigger (and vice versa), to determine entering or leaving.
Private Sub Processor()
Dim bc As New BlobCounter With {
.MinWidth = 5,
.MinHeight = 5,
.ObjectsOrder = ObjectsOrder.Size
}
Dim detector As New MotionDetector(New SimpleBackgroundModelingDetector, New MotionAreaHighlighting)
Using reader As New AForge.Video.FFMPEG.VideoFileReader()
reader.Open("C:\Videos\MyVideo.mp4")
For i As Integer = 0 To reader.FrameCount - 1
Dim frame = reader.ReadVideoFrame()
Dim frame2 As Bitmap = frame.Clone()
Dim frame3 As Bitmap = frame.Clone()
detector.ProcessFrame(frame2)
bc.ProcessImage(frame2)
Dim blobs = bc.GetObjectsInformation()
If blobs.Length > 0 Then
bc.ExtractBlobsImage(frame3, blobs(0), True)
PBX_Image(main2PBX, frame3.Clone())
End If
PBX_Image(mainPBX, frame.Clone())
Threading.Thread.Sleep(25)
frame.Dispose()
frame2.Dispose()
frame3.Dispose()
Next
End Using
End Sub
This is in no way finished, but I can actually interact with the blobs.
Private Sub Processor()
Dim Rectangles As New List(Of Rectangle)
Dim detector As New SimpleBackgroundModelingDetector With {
.SuppressNoise = True,
.DifferenceThreshold = 10,
.FramesPerBackgroundUpdate = 10,
.KeepObjectsEdges = True
}
Dim processor As New AForge.Vision.Motion.BlobCountingObjectsProcessing With {
.MinObjectsWidth = 40,
.MinObjectsHeight = 40,
.HighlightColor = Color.Red
}
Dim motionDetector As New MotionDetector(detector, processor)
Using reader As New AForge.Video.FFMPEG.VideoFileReader()
reader.Open("C:\Videos\MyVideo.mp4")
For i As Integer = 0 To reader.FrameCount - 1
Dim frame = reader.ReadVideoFrame()
motionDetector.ProcessFrame(frame)
Dim t As BlobCountingObjectsProcessing = motionDetector.MotionProcessingAlgorithm
Dim r As Rectangle = Rectangle.Empty
If t.ObjectRectangles.Length > 0 Then
If t.ObjectRectangles.Length > 2 Then
r = t.ObjectRectangles.Aggregate(Function(r1, r2) If((r1.Width * r1.Height) > (r2.Width * r2.Height), r1, r2))
Else
r = t.ObjectRectangles.First()
End If
End If
If r.IsEmpty = False Then Rectangles.Add(r)
PBX_Image(mainPBX, frame.Clone())
Threading.Thread.Sleep(25)
frame.Dispose()
Next
End Using
End Sub

In box2d for iOS, how to find the distance between two circular bodies?

I am using the following code to get the distance between two circular bodies of different radius:
distance = b2Distance(body1->GetPosition(), body2->GetPosition());
I have realized that variable distance is storing the distance between the two centers of the bodies, but not the distance between the borders. What I want is distance=0 when the two bodies are touching.
How can I do that? I've been trying this code but it fails:
b2DistanceInput *distanceInput;
distanceInput->transformA = body1->GetTransform();
distanceInput->transformB = body2->GetTransform();
b2DistanceProxy *proxyA;
proxyA->Set(fixtureBody1->GetShape(), 1);
b2DistanceProxy *proxyB;
proxyB->Set(fixtureBody2->GetShape(), 1);
distanceInput->proxyA = *proxyA;
distanceInput->proxyB = *proxyB;
b2DistanceOutput *theDistance;
b2SimplexCache *cache;
cache->count = 0;
b2Distance(theDistance, cache, distanceInput);
The getShape method is giving a bad access error within the b2box code.
Any ideas?
Thanks,
GA
Try use this code - it work for me:
b2DistanceInput *distanceInput = new b2DistanceInput();
b2DistanceProxy *proxyA = new b2DistanceProxy();
b2DistanceProxy *proxyB = new b2DistanceProxy();
b2SimplexCache *cache = new b2SimplexCache();
b2DistanceOutput *theDistance = new b2DistanceOutput();
proxyA->Set(fixtureBody1->GetShape(),1);
proxyB->Set(fixtureBody2->GetShape(),1);
distanceInput->transformA = body1->GetTransform();
distanceInput->transformB = body2->GetTransform();
distanceInput->proxyA = *proxyA;
distanceInput->proxyB = *proxyB;
distanceInput->useRadii = true;
cache->count = 0;
b2Distance(theDistance, cache, distanceInput);

AForge Imaging finding Rectagles in Image

I'm able to find the rectangles if the image is created in paint..
I'm not able to find the rectangles in Sanp shot or Screen Shot taken
It's not recognizing Rectangle in Snapshot imagees...
Pls help me
string path = "D:\\testc.png";
Bitmap image = (Bitmap)Bitmap.FromFile(path);
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinHeight = 1;
blobCounter.MinWidth = 1;
blobCounter.ProcessImage(image);
Blob[] blobs = blobCounter.GetObjectsInformation();
var retcs = blobCounter.GetObjects(image,true);
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
foreach (var blob in blobs)
{
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);
List<IntPoint> cornerPoints;
// use the shape checker to extract the corner points
if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
{
// only do things if the corners form a rectangle
if (shapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
{
// here i use the graphics class to draw an overlay, but you
// could also just use the cornerPoints list to calculate your
// x, y, width, height values.
List<Point> Points = new List<Point>();
foreach (var point in cornerPoints)
{
Points.Add(new Point(point.X, point.Y));
}
Graphics g = Graphics.FromImage(image);
g.DrawPolygon(new Pen(Color.Red, 5.0f), Points.ToArray());
image.Save("D:\\result.png");
}
}
}

Standard Hough Lines in EMGU CV

I am in need of using the standard Hough Transformation (instead of the using the HoughLinesBinary method which implements Probabilistic Hough Transform) and have attempted doing so by creating a custom version of the HoughLinesBinary method:
using (MemStorage stor = new MemStorage())
{
IntPtr lines = CvInvoke.cvHoughLines2(canny.Ptr, stor.Ptr, Emgu.CV.CvEnum.HOUGH_TYPE.CV_HOUGH_STANDARD, rhoResolution, (thetaResolution*Math.PI)/180, threshold, 0, 0);
Seq<MCvMat> segments = new Seq<MCvMat>(lines, stor);
List<MCvMat> lineslist = segments.ToList();
foreach(MCvMat line in lineslist)
{
//Process lines: (rho, theta)
}
}
My problem is that I am unsure of what type is the sequence returned. I believe it should be MCvMat, due to reading the documentation that CvMat* is used in OpenCV, which also states that for STANDARD "the matrix must be (the created sequence will be) of CV_32FC2 type"
I am unclear as to what I would need to do to return and process that correct output data from the STANDARD hough lines (i.e. the 2x1 vector for each line giving the rho and theta information).
Any help would be greatly appreciated. Thank you
-Sal
I had the same problem myself a couple of days ago. This is how I solved it using marshalling. Please let me know if you find a simpler solution.
using (MemStorage stor = new MemStorage())
{
IntPtr lines = CvInvoke.cvHoughLines2(canny.Ptr, stor.Ptr, Emgu.CV.CvEnum.HOUGH_TYPE.CV_HOUGH_STANDARD, rhoResolution, (thetaResolution*Math.PI)/180, threshold, 0, 0);
int maxLines = 100;
for(int i = 0; i < maxLines; i++)
{
IntPtr line = CvInvoke.cvGetSeqElem(lines, i);
if (line == IntPtr.Zero)
{
// No more lines
break;
}
PolarCoordinates coords = (PolarCoordinates)System.Runtime.InteropServices.Marshal.PtrToStructure(line, typeof(PolarCoordinates));
// Do something with your Hough lines
}
}
with a struct defined as follows:
public struct PolarCoordinates
{
public float Rho;
public float Theta;
}

XNA Vertex Buffer is drawing very wrongly

I'm new to using the vertex buffer in XNA. In my project I construct one using a very large amount of vertices. I have been drawing the primitives heretofore with DrawUserIndexedPrimitives(), but I have grown out of that and need more efficiency, so I am trying to figure out the basics of buffers.
I think I've successfully implemented a buffer (and have been very satisfied with the performance improvements), except that all the faces look wrong. Here's how the primitives looked without the buffer: http://i.imgur.com/ygsnB.jpg (the intended look), and here's how they look without: http://i.imgur.com/rQN1p.jpg
Here's my code for loading a vertex buffer and index buffer:
private void RefreshVertexBuffer()
{
List<VertexPositionNormalTexture> vertices = new List<VertexPositionNormalTexture>();
List<int> indices = new List<int>();
//rebuild the vertex list and index list
foreach(var entry in blocks)
{
Block block = entry.Value;
for (int q = 0; q < block.Quads.Count; q++)
{
vertices.AddRange(block.Quads[q].Corners);
int offset = vertices.Count;
foreach (Triangle tri in block.Quads[q].Triangles)
{
indices.Add(tri.Indices[0] + offset);
indices.Add(tri.Indices[1] + offset);
indices.Add(tri.Indices[2] + offset);
}
}
}
vertexBuffer = new DynamicVertexBuffer(graphics, typeof(VertexPositionNormalTexture), vertices.Count, BufferUsage.None);
indexBuffer = new DynamicIndexBuffer(graphics, IndexElementSize.ThirtyTwoBits, indices.Count, BufferUsage.None);
vertexBuffer.SetData<VertexPositionNormalTexture>(vertices.ToArray(), 0, vertices.Count);
indexBuffer.SetData<int>(indices.ToArray(), 0, indices.Count);
}
and here is the draw call for plain rendering:
public void Render(Planet planet, Camera camera)
{
effect.View = camera.View;
effect.Projection = camera.Projection;
effect.World = planet.World;
foreach (KeyValuePair<Vector3, Block> entry in planet.Geometry.Blocks)
{
int blockID = planet.BlockMap.Blocks[entry.Value.U][entry.Value.V][entry.Value.W];
if (blockID == 1)
effect.Texture = dirt;
else if (blockID == 2)
effect.Texture = rock;
effect.CurrentTechnique.Passes[0].Apply();
foreach (Quad quad in entry.Value.Quads)
{
foreach (Triangle tri in quad.Triangles)
{
graphics.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
quad.Corners, 0, quad.Corners.Length, tri.Indices, 0, 1);
}
}
}
}
...and for the vertex buffer rendering:
public void RenderFromBuffer(Planet planet, Camera camera)
{
effect.View = camera.View;
effect.Projection = camera.Projection;
effect.World = planet.World;
graphics.SetVertexBuffer(planet.Geometry.VertexBuffer);
graphics.Indices = planet.Geometry.IndexBuffer;
effect.CurrentTechnique.Passes[0].Apply();
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, planet.Geometry.VertexBuffer.VertexCount, 0, planet.Geometry.IndexBuffer.IndexCount / 6);
}
My indices may be off? Or is this due to some quirks with how the graphics device acts with a buffer vs. user indexed?
Edit: It may also have something to do with the way I stitch triangle indices. When I built this project with DrawUserIndexedPrimitives, I ran into some issues similar to this where triangles facing a certain direction would draw on the wrong 'side' (or, the wrong face would be culled). So I came up with this solution:
Triangle[] tris;
if (faceDirection == ADJACENT_FACE_NAMES.BOTTOM | faceDirection == ADJACENT_FACE_NAMES.OUTER | faceDirection == ADJACENT_FACE_NAMES.LEFT)
{
//create the triangles for the quad
tris = new Triangle[2]{
new Triangle( //the bottom triangle
new int[3] {
0, //the bottom left corner
1, //the bottom right corner
2 //the top left corner
}),
new Triangle( //the top triangle
new int[3] {
1, //the bottom right corner
3, //the top right corner
2 //the top left corner
})};
}
else
{
tris = new Triangle[2]{
new Triangle(
new int[3] {
2, //the top left corner
1,
0
}),
new Triangle(
new int[3] {
2,
3,
1
})
};
}
The problem is that the triangles are being culled. So you have two options to fix this:
You can change the order of the triangle indices.
foreach (Triangle tri in block.Quads[q].Triangles)
{
indices.Add(tri.Indices[1] + offset);
indices.Add(tri.Indices[0] + offset);
indices.Add(tri.Indices[2] + offset);
}
You can change your RasterizerState...
Default rasterizer state is RasterizerState.CullClockwise...
You can change it to RasterizerState.CullCounterClockwise
EDIT:
this line has a bug:
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, planet.Geometry.VertexBuffer.VertexCount, 0, planet.Geometry.IndexBuffer.IndexCount / 6)
should be:
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, planet.Geometry.VertexBuffer.VertexCount, 0, planet.Geometry.IndexBuffer.IndexCount / 3)

Resources