private void CreateGeometry() { Window activeWindow = Window.ActiveWindow; Part mainPart = activeWindow.Scene as Part; if (mainPart == null) { return; } List <Body> bodies = new List <Body>(); foreach (int[,] patchData in patchIndices) { ControlPoint[,] controlPoints = new ControlPoint[4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { controlPoints[i, j] = new ControlPoint(vertices[patchData[i, j] - 1], 1); } } IDictionary <string, Face> idToFace; IDictionary <string, Edge> idToEdge; bodies.Add(Body.Import(new BezierPatchForeignBody(controlPoints), out idToFace, out idToEdge)); if (bodies[bodies.Count - 1].Faces.Count == 0) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { DesignCurve.Create(mainPart, CurveSegment.Create(PointCurve.Create(vertices[patchData[i, j] - 1]))); } } } } foreach (Body body in bodies) { if (body.Faces.Count > 0) { DesignBody.Create(mainPart, "Bezier", body); } } activeWindow.InteractionMode = InteractionMode.Solid; activeWindow.ZoomExtents(); }
private PointCurve.SegmentationResult SynchronizeRoutePointCurve() { if (RoutePointCurveUpToDate && m_routePointCurve.LastSuccessfulResult.Successful) { return(m_routePointCurve.LastSuccessfulResult); } if (m_routePointCurve == null) { m_routePointCurve = new PointCurve(); } m_routePointCurve.LastSuccessfulResult = new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }; if (m_routePointCurve.NumPoints == Route.NumNodes) { for (int i = 0; i < Route.NumNodes; ++i) { m_routePointCurve[i] = Route[i].Position; } } else { m_routePointCurve.Clear(); foreach (var node in Route) { m_routePointCurve.Add(node.Position); } } if (m_routePointCurve.Finalize()) { var numSegments = Mathf.Max(Mathf.CeilToInt(ResolutionPerUnitLength * Route.TotalLength), 1); var result = m_routePointCurve.FindSegmentLength(numSegments, PointCurve.DefaultErrorFunc, 5.0E-3f, 1.0E-3f); if (result.Successful) { return(result); } } return(new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }); }
/// <summary> /// Checks if this route is synchronized with the given point curve. /// </summary> /// <param name="pointCurve">Point curve.</param> /// <param name="tolerance">Max position change tolerance.</param> /// <returns>True if synchronized, otherwise false.</returns> public bool IsSynchronized(PointCurve pointCurve, float tolerance) { if (pointCurve == null || pointCurve.NumPoints != NumNodes) { return(false); } for (int i = 0; i < NumNodes; ++i) { if (Vector3.Distance(this[i].Position, pointCurve[i]) > tolerance) { return(false); } } return(true); }
protected override void OnExecute(Command command, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, buttonRect); foreach (Point point in controlForm.CalibrationPoints) { DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; } foreach (VideoForm videoForm in controlForm.VideoForms) { Point point = videoForm.TrackingCamera.GetLine(PointUV.Origin).Evaluate(0.2).Point; DesignBody desBody = ShapeHelper.CreateSphere(point, 0.1, part); desBody.Layer = referenceLayer; foreach (PointUV pointUV in videoForm.TrackingCamera.CalibrationPoints) { point = videoForm.TrackingCamera.GetLine(pointUV).Evaluate(0.2).Point; //desBody = ShapeHelper.CreateSphere(point, 0.1, part); //desBody.Layer = referenceLayer; var desCurve = DesignCurve.Create(part, CurveSegment.Create(PointCurve.Create(point))); desCurve.Layer = referenceLayer; } for (int i = 0; i < videoForm.Size.Width; i += videoForm.Size.Width / 12) { for (int j = 0; j < videoForm.Size.Height; j += videoForm.Size.Height / 12) { Line line = videoForm.TrackingCamera.GetLine(PointUV.Create(i, j)); var curveSegment = CurveSegment.Create(line, Interval.Create(-3, 6)); var desCurve = DesignCurve.Create(part, curveSegment); desCurve.Layer = referenceLayer; } } } }
public static ITrimmedCurve AsITrimmedCurve(this Point point) { return(CurveSegment.Create(PointCurve.Create(point))); }
public static CurveSegment AsCurveSegment(this Point point) { return(CurveSegment.Create(PointCurve.Create(point))); }
public override void WriteXml(Matrix documentTrans) { Debug.Assert(iTrimmedCurves != null); Debug.Assert(iTrimmedCurves.Count > 0); string pathData = MoveTo(documentTrans * iTrimmedCurves[0].StartPoint); foreach (ITrimmedCurve curve in iTrimmedCurves) { ITrimmedCurve iTrimmedCurve = curve; Line line = iTrimmedCurve.Geometry as Line; if (line != null) { pathData += LineTo(documentTrans * iTrimmedCurve.EndPoint); continue; } if (iTrimmedCurve.Geometry is Circle || iTrimmedCurve.Geometry is Ellipse) { ITrimmedCurve iTrimmedEllipse = iTrimmedCurve.ProjectToPlane(Plane.PlaneXY); Ellipse ellipse = iTrimmedEllipse.Geometry as Ellipse; if (ellipse == null) { ellipse = ((Circle)iTrimmedEllipse.Geometry).AsEllipse(); } Debug.Assert(ellipse != null); Debug.Assert(iTrimmedEllipse.Bounds.Span > 0); // interval should always be positive for SC ellipses Debug.Assert(!iTrimmedEllipse.IsReversed); double majorRadius = documentTrans.Scale * Math.Max(ellipse.MajorRadius, ellipse.MinorRadius); double minorRadius = documentTrans.Scale * Math.Min(ellipse.MajorRadius, ellipse.MinorRadius); double x = Vector.Dot(ellipse.Frame.DirX.UnitVector, Direction.DirX.UnitVector); double y = Vector.Dot(ellipse.Frame.DirX.UnitVector, Direction.DirY.UnitVector); pathData += ArcTo( majorRadius, minorRadius, Math.Atan2(y, x) * 180 / Math.PI, iTrimmedEllipse.Bounds.Span > Math.PI, Direction.Equals(Direction.DirZ, ellipse.Frame.DirZ), documentTrans * iTrimmedEllipse.EndPoint ); continue; } NurbsCurve nurbsCurve = iTrimmedCurve.Geometry as NurbsCurve; if (nurbsCurve == null) { ProceduralCurve proceduralCurve = iTrimmedCurve.Geometry as ProceduralCurve; if (proceduralCurve != null) { nurbsCurve = proceduralCurve.AsSpline(iTrimmedCurve.Bounds); } } if (nurbsCurve != null) { Debug.Assert(nurbsCurve.Data.Degree == 3); SelectFragmentResult result = null; CurveSegment fullNurbsCurve = CurveSegment.Create(nurbsCurve); List <ITrimmedCurve> pointCurves = nurbsCurve.Data.Knots .Where(k => iTrimmedCurve.Bounds.Contains(k.Parameter)) .Select(k => ((ITrimmedCurve)(nurbsCurve.Evaluate(k.Parameter).Point.AsCurveSegment()))) .ToList <ITrimmedCurve>(); pointCurves.Insert(0, nurbsCurve.Evaluate(iTrimmedCurve.Bounds.Start).Point.AsCurveSegment()); pointCurves.Add(nurbsCurve.Evaluate(iTrimmedCurve.Bounds.End).Point.AsCurveSegment()); for (int i = 0; i < pointCurves.Count - 1; i++) { //try { result = fullNurbsCurve.SelectFragment(( nurbsCurve.ProjectPoint(pointCurves[i].StartPoint).Param + nurbsCurve.ProjectPoint(pointCurves[i + 1].StartPoint).Param ) / 2, pointCurves); //} //catch { // Debug.Assert(false, "Attempted to trim curve out of bounds."); // WriteBlock.ExecuteTask("SVG Exception Curves", () => DesignCurve.Create(Window.ActiveWindow.Scene as Part, iTrimmedCurve)); // break; //} if (result != null) { NurbsCurve fragment = result.SelectedFragment.Geometry as NurbsCurve; WriteBlock.ExecuteTask("curve", delegate { fragment.Print(); }); pathData += CubicBézierTo(documentTrans * fragment.ControlPoints[1].Position, documentTrans * fragment.ControlPoints[2].Position, documentTrans * fragment.ControlPoints[3].Position); } } continue; } PointCurve pointCurve = iTrimmedCurve.Geometry as PointCurve; if (pointCurve != null) { continue; } // Handle Polygons, which are not in the API foreach (Point point in iTrimmedCurve.Geometry.GetPolyline(iTrimmedCurve.Bounds).Skip(1)) { pathData += LineTo(documentTrans * point); } continue; // throw new NotSupportedException("Unhandled iTrimmedCurve"); } if (isClosed) { pathData += ClosePath(); } xmlWriter.WriteStartElement("path"); xmlWriter.WriteAttributeString("d", pathData); StyleAttributes(strokeColor, fillColor, strokeWidth); xmlWriter.WriteEndElement(); }
public PointCurve.SegmentationResult SynchronizeRoutePointCurve() { if (RoutePointCurveUpToDate && m_routePointCurve.LastSuccessfulResult.Successful) { return(m_routePointCurve.LastSuccessfulResult); } if (m_routePointCurve == null) { m_routePointCurve = new PointCurve(); } m_routePointCurve.LastSuccessfulResult = new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }; m_routePointsCache = new Vector3[] { }; if (m_routePointCurve.NumPoints == Route.NumNodes) { for (int i = 0; i < Route.NumNodes; ++i) { m_routePointCurve[i] = Route[i].Position; } } else { m_routePointCurve.Clear(); foreach (var node in Route) { m_routePointCurve.Add(node.Position); } } if (m_routePointCurve.Finalize()) { var numSegments = Mathf.Max(Mathf.CeilToInt(ResolutionPerUnitLength * Route.TotalLength), 1); var result = m_routePointCurve.FindSegmentLength(numSegments, PointCurve.DefaultErrorFunc, 5.0E-3f, 1.0E-3f); if (result.Successful) { m_routePointResulutionPerUnitLength = ResolutionPerUnitLength; var routePoints = new List <Vector3>(); m_routePointCurve.Traverse((curr, next, type) => { routePoints.Add(curr.Point); if (type == PointCurve.SegmentType.Last && Mathf.Abs(next.Time - 1.0f) < Mathf.Abs(curr.Time - 1)) { routePoints.Add(next.Point); } }, result.SegmentLength); m_routePointsCache = routePoints.ToArray(); return(result); } } return(new PointCurve.SegmentationResult() { Error = float.PositiveInfinity, Successful = false }); }
protected override void OnExecute(Command command, ExecutionContext context, Rectangle buttonRect) { /* * Lost Particle Location Highlighter * Prompt user to select the MCNP output file which contains lost particle locations * Read in file and store locations * Highlight the point/plane which the particle loss occurs */ // Instance common functions class InstanceClasses.CommonSpaceClaimFunctions FunctionsClass = new InstanceClasses.CommonSpaceClaimFunctions(); // Variables Window window = Window.ActiveWindow; window.SetTool(new ToolClass()); Document doc = window.Document; Part rootPart = doc.MainPart; Part lostPart = Part.Create(doc, "Lost Particles"); Part vectorPart = Part.Create(doc, "Vector Lines"); Part curvePart = Part.Create(doc, "Lost Particle Curves"); Component lp2c = Component.Create(rootPart, curvePart); string filepath; bool showVectors; bool fileLocated = false; bool maxParticlesBool; double maxParicles; int particleCounter = 0; int particleLineCounter = 0; bool stopParticles = false; bool stopLines = false; string[] lines = null; string lostParticleIndicator = "x,y,z coordinates:"; string vectorIndicator = "u,v,w direction cosines:"; char[] delimeterChars = { ' ', '\t' }; char[] secondDelimChars = { '+', '-' }; int pointCounter = 1; int lineCounter = 1; string pointName; string vectorName; string chosenColour; Point currentPoint = Point.Create(0, 0, 0); Point vectorPoint = Point.Create(0, 0, 0); List <double> xValues = new List <double>(); List <double> yValues = new List <double>(); List <double> zValues = new List <double>(); List <Point> vectorPointList = new List <Point>(); List <Point> pointList = new List <Point>(); List <Line> lineList = new List <Line>(); // Bring up windows form using (var dialogue = new UI.LostParticlesForm()) { if (dialogue.ShowDialog() != DialogResult.OK) { return; } var nameAndRendering = new List <KeyValuePair <string, Graphic> >(); var partToGraphic = new Dictionary <Part, Graphic>(); var style = new GraphicStyle { EnableDepthBuffer = true }; filepath = dialogue.FileName; showVectors = dialogue.ShowVectors; maxParticlesBool = dialogue.MaxParticleBool; maxParicles = dialogue.MaxParticle; chosenColour = dialogue.ColourSelection; } if (window == null) { return; } //Debug.WriteLine(filepath); try { lines = File.ReadAllLines(filepath); fileLocated = true; } catch { MessageBox.Show("File Could Not Be Located"); //SpaceClaim.Api.V18.Application.Exit(); } // Get x,y,z coordinates of lost particle points //------------------------------------------------------------- if (fileLocated) { // Check if MCNP output or text file if (lines[0].Contains("Code Name & Version") || lines[0].Contains(lostParticleIndicator) || lines[0].Contains(vectorIndicator)) { //Debug.WriteLine("MCNP File"); // MCNP File foreach (string line in lines) { if (line.Contains(lostParticleIndicator)) { //Debug.WriteLine(line); if (!stopParticles) { string[] tempWords = line.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries); // Convert API values in metres to cm for SpaceClaim currentPoint = Point.Create(Convert.ToDouble(tempWords[2]) / 100, Convert.ToDouble(tempWords[3]) / 100, Convert.ToDouble(tempWords[4]) / 100); pointList.Add(currentPoint); particleCounter++; if (particleCounter >= maxParicles && maxParticlesBool) { stopParticles = true; } } } else if (line.Contains(vectorIndicator)) { string[] tempWords = line.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries); //Debug.WriteLine(tempWords[3] + " " + tempWords[4] + " " + tempWords[5]); Point origin = Point.Create(0, 0, 0); Direction direction = Direction.Create(Convert.ToDouble(tempWords[3]), Convert.ToDouble(tempWords[4]), Convert.ToDouble(tempWords[5])); vectorPoint = Point.Create(currentPoint.X + Convert.ToDouble(tempWords[3]) / 1, currentPoint.Y + Convert.ToDouble(tempWords[4]) / 1, currentPoint.Z + Convert.ToDouble(tempWords[5]) / 1); if (showVectors && !stopLines) { vectorName = "Lost Particle " + lineCounter.ToString() + " Vector"; LineSegment lineSeg = new LineSegment(currentPoint, vectorPoint); ITrimmedCurve shape = CurveSegment.Create(lineSeg); DesignCurve desCurve = DesignCurve.Create(vectorPart, shape); desCurve.Name = vectorName; desCurve.SetColor(null, Color.Blue); lineCounter++; particleLineCounter++; if (particleLineCounter >= maxParicles && maxParticlesBool) { stopLines = true; } } //Line vectorLine = Line.CreateThroughPoints(currentPoint, origin); Line vectorLine = Line.CreateThroughPoints(currentPoint, vectorPoint); //Line vectorLine = Line.Create(currentPoint, direction); lineList.Add(vectorLine); } #region Old Code /* * else if (lostParticleBool) * { * * if (line.Contains(endLostParticleIndicator)) * { * //string patternOne = @"(\-|\d)\d*\.\d+"; * string patternOne = @"(?<=\d)(\+|\-)"; * string[] tempWords = prevLine.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries); * string[] xWords = Regex.Split(tempWords[2], patternOne); * string[] yWords = Regex.Split(tempWords[3], patternOne); * string[] zWords = Regex.Split(tempWords[4], patternOne); * //Debug.WriteLine(xWords[0]); * //Debug.WriteLine(yWords[0]); * * string xFinal = xWords[0] + "E" + xWords[1] + xWords[2]; * string yFinal = yWords[0] + "E" + yWords[1] + yWords[2]; * string zFinal = zWords[0] + "E" + zWords[1] + zWords[2]; * * Debug.WriteLine(xFinal); * Debug.WriteLine(yFinal); * Debug.WriteLine(zFinal); * * /* * foreach (string word in xWords) * { * Debug.WriteLine(word); * } * * Debug.WriteLine(" "); * * foreach (string word in yWords) * { * Debug.WriteLine(word); * } * * * xValues.Add(Convert.ToDouble(xFinal)); * yValues.Add(Convert.ToDouble(yFinal)); * zValues.Add(Convert.ToDouble(zFinal)); * * } * * //prevLine = line; * } */ #endregion } //Debug.WriteLine(pointList.Count); // Use values and highlight the positions in SpaceClaim //--------------------------------------------------------------- foreach (Point point in pointList) { pointName = "Lost Particle " + pointCounter.ToString(); window.ActiveTool.CreateIndicator(point); //DatumPoint.Create(lostPart, pointName, point); var pc = PointCurve.Create(point); ITrimmedCurve shapey = CurveSegment.Create(pc); DesignCurve dcurve = DesignCurve.Create(curvePart, shapey); if (chosenColour == "Blue") { dcurve.SetColor(null, Color.Blue); } else if (chosenColour == "Red") { dcurve.SetColor(null, Color.Red); } else if (chosenColour == "Green") { dcurve.SetColor(null, Color.Green); } else if (chosenColour == "Orange") { dcurve.SetColor(null, Color.Orange); } else if (chosenColour == "Black") { dcurve.SetColor(null, Color.Black); } else if (chosenColour == "Yellow") { dcurve.SetColor(null, Color.Yellow); } else if (chosenColour == "Salmon Pink") { dcurve.SetColor(null, Color.Salmon); } pointCounter++; } if (showVectors) { /* * foreach (Line line in lineList) * { * vectorName = "Lost Particle " + lineCounter + " Vector"; * DatumLine dLine = DatumLine.Create(vectorPart, vectorName, line); * lineCounter++; * } */ Component vectorComponent = Component.Create(rootPart, vectorPart); } //Component lostParticleComponent = Component.Create(rootPart, lostPart); } else { // Text file /* * foreach (string line in lines) * { * Debug.Write(String.Format("{0}\n",line)); * } */ bool firstLine = true; int length = 0; foreach (string line in lines) { if (line.Length != 0) { string[] tempWords = line.Split(delimeterChars, StringSplitOptions.RemoveEmptyEntries); if (firstLine) { firstLine = false; length = tempWords.Length; } if (length > 3) { currentPoint = Point.Create(Convert.ToDouble(tempWords[0]) / 100, Convert.ToDouble(tempWords[1]) / 100, Convert.ToDouble(tempWords[2]) / 100); pointList.Add(currentPoint); particleCounter++; Point origin = Point.Create(0, 0, 0); Direction direction = Direction.Create(Convert.ToDouble(tempWords[3]), Convert.ToDouble(tempWords[4]), Convert.ToDouble(tempWords[5])); vectorPoint = Point.Create(currentPoint.X + Convert.ToDouble(tempWords[3]) / 1, currentPoint.Y + Convert.ToDouble(tempWords[4]) / 1, currentPoint.Z + Convert.ToDouble(tempWords[5]) / 1); if (showVectors) { vectorName = "Lost Particle " + lineCounter.ToString() + " Vector"; LineSegment lineSeg = new LineSegment(currentPoint, vectorPoint); ITrimmedCurve shape = CurveSegment.Create(lineSeg); DesignCurve desCurve = DesignCurve.Create(vectorPart, shape); desCurve.Name = vectorName; desCurve.SetColor(null, Color.Blue); lineCounter++; particleLineCounter++; } //Line vectorLine = Line.CreateThroughPoints(currentPoint, origin); Line vectorLine = Line.CreateThroughPoints(currentPoint, vectorPoint); //Line vectorLine = Line.Create(currentPoint, direction); lineList.Add(vectorLine); } else if (length <= 3) { try { currentPoint = Point.Create(Convert.ToDouble(tempWords[0]) / 100, Convert.ToDouble(tempWords[1]) / 100, Convert.ToDouble(tempWords[2]) / 100); pointList.Add(currentPoint); particleCounter++; } catch { } } } } foreach (Point point in pointList) { pointName = "Lost Particle " + pointCounter.ToString(); window.ActiveTool.CreateIndicator(point); //DatumPoint.Create(lostPart, pointName, point); var pc = PointCurve.Create(point); ITrimmedCurve shapey = CurveSegment.Create(pc); DesignCurve dcurve = DesignCurve.Create(curvePart, shapey); if (chosenColour == "Blue") { dcurve.SetColor(null, Color.Blue); } else if (chosenColour == "Red") { dcurve.SetColor(null, Color.Red); } else if (chosenColour == "Green") { dcurve.SetColor(null, Color.Green); } else if (chosenColour == "Orange") { dcurve.SetColor(null, Color.Orange); } else if (chosenColour == "Black") { dcurve.SetColor(null, Color.Black); } else if (chosenColour == "Yellow") { dcurve.SetColor(null, Color.Yellow); } else if (chosenColour == "Salmon Pink") { dcurve.SetColor(null, Color.Salmon); } pointCounter++; } if (showVectors) { Component vectorComponent = Component.Create(rootPart, vectorPart); } //Component lostParticleComponent = Component.Create(rootPart, lostPart); } } }