public IList <ProcParam <MotionProcEnv> > GetParameters() { MotionObjectSingleSelectParameter main = new MotionObjectSingleSelectParameter("Main Line", info => info.IsTypeOf <LineObject>(), true); NumberParameter enlarge = new NumberParameter("Enlarge targets", -10000, 10000, 3); return(new ProcParam <MotionProcEnv>[] { main, enlarge }); }
public bool ValidateArguments(IList <ProcParam <MotionProcEnv> > args, ref string errorMessage) { MotionObjectSingleSelectParameter main = args[0] as MotionObjectSingleSelectParameter; SingleSelectParameter unit = args[1] as SingleSelectParameter; return(true); }
public IList <ProcParam <MotionProcEnv> > GetParameters() { MotionObjectSingleSelectParameter main = new MotionObjectSingleSelectParameter("First Axis", new Predicate <MotionObjectInfo>(info => info.IsTypeOf(typeof(LineObject))), true); SingleSelectParameter unit = new SingleSelectParameter("Unit", new string[] { "線分の長さに対する比", "単位長さ" }); return(new ProcParam <MotionProcEnv>[] { main, unit }); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { MotionObjectSingleSelectParameter main = args[0] as MotionObjectSingleSelectParameter; SingleSelectParameter unit = args[1] as SingleSelectParameter; bool useRatio = unit.Value == 0; MotionObjectInfo firstAxis = main.Value; MotionObjectInfo secondAxis = selected.Where(info => info.IsTypeOf(typeof(LineObject)) && info != firstAxis).First(); IList <MotionObjectInfo> pointInfoList = selected.Where(info => info.IsTypeOf(typeof(PointObject))).ToList(); List <SequenceData> ret = new List <SequenceData>(); foreach (MotionObjectInfo pointInfo in pointInfoList) { TimeSeriesValues values = new TimeSeriesValues("axis1", "axis2", "axis3"); foreach (var frame in frames) { PointObject point = frame[pointInfo] as PointObject; LineObject line1 = frame[firstAxis] as LineObject; LineObject line2 = frame[secondAxis] as LineObject; decimal?[] relValues = null; if (point != null && line1 != null && line2 != null) { Vector3 anchor = line1.Position; Vector3 pointRelPos = point.Position - anchor; Vector3 axis1 = line1.Edge; Vector3 axis2 = line2.Edge; Vector3 axis1norm = Vector3.Normalize(axis1); Vector3 axis2norm = Vector3.Normalize(axis2); Vector3 axis3 = Vector3.Cross(axis1norm, axis2norm) * (float)Math.Sqrt(axis1.Length() * axis2.Length()); if (!useRatio) { axis1 = Vector3.Normalize(axis1); axis2 = Vector3.Normalize(axis2); axis3 = Vector3.Normalize(axis3); } float[,] mat = new float[, ] { { axis1.X, axis2.X, axis3.X }, { axis1.Y, axis2.Y, axis3.Y }, { axis1.Z, axis2.Z, axis3.Z } }; float[] vec = new float[] { pointRelPos.X, pointRelPos.Y, pointRelPos.Z }; SimultaneousEquations solve = SimultaneousEquations.Solve(mat, vec); if (solve.Answers.Length == 3) { relValues = new decimal?[3]; try { relValues[0] = (decimal)solve.Answers[0]; relValues[1] = (decimal)solve.Answers[1]; relValues[2] = (decimal)solve.Answers[2]; } catch (OverflowException) { relValues = null; } } } values.SetValue(frame.Time, relValues); } SequenceData data = new SequenceData(values, null, PathEx.GiveName("RelPos", pointInfo.Name)); ret.Add(data); } return(ret); }
public bool ValidateArguments(IList <ProcParam <MotionProcEnv> > args, ref string errorMessage) { MotionObjectSingleSelectParameter main = args[0] as MotionObjectSingleSelectParameter; if (main.Value == null) { errorMessage = global::MotionDataHandler.Properties.Settings.Default.Msg_CannotSpecifyNull + ": " + args[0].ParamName; return(false); } NumberParameter enlarge = args[1] as NumberParameter; return(true); }
public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo) { MotionObjectSingleSelectParameter main = args[0] as MotionObjectSingleSelectParameter; NumberParameter enlarge = args[1] as NumberParameter; float enlargement = 0; try { enlargement = (float)enlarge.Value; } catch (ArithmeticException) { } IList <MotionObjectInfo> targetInfoList = selected.Where(info => info != main.Value).ToList(); ICSLabelSequence labelSequence = new ICSLabelSequence(TimeController.Singleton.EndTime); string prevLabelText = null; decimal prevTime = decimal.MinValue; decimal wholeEndTime = decimal.MinValue; foreach (var frame in frames) { wholeEndTime = frame.Time; LineObject line = frame[main.Value] as LineObject; string labelText = ""; if (line == null || targetInfoList.Any(info => frame[info] == null)) { labelText = "no data"; } else { float minDistance = float.MaxValue; MotionObjectInfo nearest = null; foreach (var targetInfo in targetInfoList) { float distance; if (frame[targetInfo].DetectLineCollision(line.Position, line.AnotherEnd, enlargement, out distance)) { if (distance < minDistance) { nearest = targetInfo; minDistance = distance; } } } if (nearest != null) { labelText = nearest.Name; } else { labelText = "else"; } } if (prevLabelText != labelText) { decimal endTime = frame.Time; if (prevTime < endTime && prevLabelText != null) { labelSequence.SetLabel(prevTime, endTime, prevLabelText); } prevTime = endTime; prevLabelText = labelText; } } if (prevTime < wholeEndTime && prevLabelText != null) { labelSequence.SetLabel(prevTime, wholeEndTime, prevLabelText); } SequenceData data = SequenceData.FromLabelSequence(labelSequence, PathEx.GiveName("Collision", main.Value.Name)); return(new SequenceData[] { data }); }