Exemple #1
0
        public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo)
        {
            TimeSeriesValues values = new TimeSeriesValues("length");

            foreach (ReadOnlyMotionFrame frame in frames)
            {
                IList <LineObject> lines = selected.Select(info => frame[info] as LineObject).ToList();
                if (lines.All(line => line != null) && lines.Count > 0)
                {
                    try {
                        values.SetValue(frame.Time, (decimal)lines.Sum(line => line.Length()));
                    } catch (ArithmeticException) {
                        values.SetValue(frame.Time, null);
                    }
                }
                else
                {
                    values.SetValue(frame.Time, null);
                }
            }
            string name = selected[0].Name;

            if (selected.Count > 1)
            {
                name += "-etc";
            }
            SequenceData data = new SequenceData(values, null, PathEx.GiveName("Length", name));

            return(new SequenceData[] { data });
        }
        public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env)
        {
            TimeSeriesValues values = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames);

            foreach (var pair in env.SelectedSequence.Values.Enumerate())
            {
                decimal?[] tmp = new decimal?[env.SelectedSequence.Values.ColumnCount];
                if (pair.Value.All(x => x.HasValue))
                {
                    try {
                        decimal sum = pair.Value.Sum(x => x.Value);
                        if (sum != 0)
                        {
                            for (int i = 0; i < tmp.Length; i++)
                            {
                                tmp[i] = pair.Value[i].Value / sum;
                            }
                        }
                    } catch (OverflowException) {
                        tmp = new decimal?[env.SelectedSequence.Values.ColumnCount];
                    }
                }
                values.SetValue(pair.Key, tmp);
            }
            SequenceData ret = new SequenceData(values, null, PathEx.GiveName("Normal", env.SelectedSequence.Title));

            ret.Type = SequenceType.Numeric;
            return(ret);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public IList <SequenceData> OutputSequence(IList <MotionObjectInfo> selected, IList <ProcParam <MotionProcEnv> > args, IEnumerable <ReadOnlyMotionFrame> frames, ProgressInformation progressInfo)
        {
            SingleSelectParameter unit = args[0] as SingleSelectParameter;
            bool degree = unit.Value == 0;

            MotionObjectInfo info1  = selected[0];
            MotionObjectInfo info2  = selected[1];
            TimeSeriesValues values = new TimeSeriesValues(degree ? "degree" : "radian");

            foreach (ReadOnlyMotionFrame frame in frames)
            {
                LineObject line1 = frame[info1] as LineObject;
                LineObject line2 = frame[info2] as LineObject;
                if (line1 != null && line2 != null)
                {
                    float  cos    = Vector3.Dot(line1.Direction(), line2.Direction());
                    double radian = 0;
                    if (cos <= -1)
                    {
                        radian = Math.PI;
                    }
                    else if (cos < 1)
                    {
                        radian = Math.Acos(cos);
                    }
                    if (degree)
                    {
                        values.SetValue(frame.Time, (decimal)(radian * 180 / Math.PI));
                    }
                    else
                    {
                        values.SetValue(frame.Time, (decimal)radian);
                    }
                }
                else
                {
                    values.SetValue(frame.Time, null);
                }
            }
            SequenceData data = new SequenceData(values, null, PathEx.GiveName("Angle", info1.Name, info2.Name));

            return(new SequenceData[] { data });
        }
        public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env)
        {
            SequenceSingleSelectParameter operand = args[0] as SequenceSingleSelectParameter;
            TimeSeriesValues ret = new TimeSeriesValues("InnerProduct");

            int count = Math.Min(env.SelectedSequence.Values.ColumnCount, operand.Value.Values.ColumnCount);

            using (IEnumerator <KeyValuePair <decimal, decimal?[]> > one = env.SelectedSequence.Values.Enumerate().GetEnumerator())
                using (IEnumerator <KeyValuePair <decimal, decimal?[]> > another = operand.Value.Values.Enumerate().GetEnumerator()) {
                    bool oneAlive     = one.MoveNext();
                    bool anotherAlive = another.MoveNext();
                    while (oneAlive && anotherAlive)
                    {
                        decimal?value = 0;
                        for (int i = 0; i < count; i++)
                        {
                            if (one.Current.Value[i].HasValue && another.Current.Value[i].HasValue)
                            {
                                value = value.Value + one.Current.Value[i].Value * another.Current.Value[i].Value;
                            }
                            else
                            {
                                value = null;
                                break;
                            }
                        }
                        // 後にある時刻のところに値を入れる
                        // 前にある方を進める
                        if (one.Current.Key < another.Current.Key)
                        {
                            ret.SetValue(another.Current.Key, value);
                            oneAlive = one.MoveNext();
                        }
                        else
                        {
                            ret.SetValue(one.Current.Key, value);
                            anotherAlive = another.MoveNext();
                        }
                    }
                }
            return(new SequenceData(ret, null, PathEx.GiveName("InnerProduct", env.SelectedSequence.Title, operand.Value.Title)));
        }
        public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env)
        {
            var row    = ((SequenceSingleSelectParameter)args[0]).Value;
            var labels = ((LabelSelectParameter)args[1]).Value;
            TimeSeriesValues newSeq = new TimeSeriesValues(env.SelectedSequence.Values.ColumnNames);

            foreach (var label in row.GetLabelSequence().EnumerateLabels())
            {
                newSeq.SetValue(label.BeginTime, new decimal?[env.SelectedSequence.Values.ColumnCount]);
                newSeq.SetValue(label.EndTime, new decimal?[env.SelectedSequence.Values.ColumnCount]);
            }
            foreach (var pair in env.SelectedSequence.Values.Enumerate())
            {
                if (labels.Contains(row.GetLabelAt(pair.Key)))
                {
                    newSeq.SetValue(pair.Key, pair.Value);
                }
            }
            SequenceData ret = new SequenceData(newSeq, new LabelingBorders(env.SelectedSequence.Borders), PathEx.GiveName("ClipBy", new string[] { env.SelectedSequence.Title }.Union(labels)));

            ret.Type = SequenceType.Numeric;
            return(ret);
        }
        public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env)
        {
            ICSLabelSequence labelSequence = env.SelectedSequence.GetLabelSequence();

            if (labelSequence == null)
            {
                MessageBox.Show("ラベルが空でした", this.GetType().ToString());
                return(null);
            }
            if (env.Controller.WholeEndTime > 0)
            {
                labelSequence.SetLabel(0, env.Controller.WholeEndTime, "", true);
            }
            TimeSeriesValues         sequence  = new TimeSeriesValues("value");
            Dictionary <string, int> indexInfo = new Dictionary <string, int>();
            var labelTexts = labelSequence.GetLabelTexts(true);
            int count      = 0;

            foreach (var labelText in labelTexts)
            {
                indexInfo[labelText] = count;
                count++;
            }
            sequence.SetValue(0, new decimal?[1]);
            sequence.SetValue(labelSequence.Duration, new decimal?[1]);
            foreach (var label in labelSequence.EnumerateLabels())
            {
                var value = new decimal?[1] {
                    indexInfo[label.LabelText]
                };
                sequence.SetValue(label.BeginTime, value);
            }
            SequenceData ret = new SequenceData(sequence, null, PathEx.GiveName("labelNum", env.SelectedSequence.Title));

            ret.Type = SequenceType.Numeric;
            return(ret);
        }
        public SequenceData Operate(IList <ProcParam <SequenceProcEnv> > args, SequenceProcEnv env)
        {
            SequenceColumnMultiSelectParameter si = args[0] as SequenceColumnMultiSelectParameter;
            List <int>       indices = si.Value.Where(i => 0 <= i && i < env.SelectedSequence.Values.ColumnNames.Length).ToList();
            TimeSeriesValues val     = new TimeSeriesValues(indices.Select(i => env.SelectedSequence.Values.ColumnNames[i]));

            foreach (var pair in env.SelectedSequence.Values.Enumerate())
            {
                val.SetValue(pair.Key, indices.Select(i => pair.Value[i]).ToArray());
            }
            SequenceData ret = new SequenceData(val, new LabelingBorders(env.SelectedSequence.Borders), PathEx.GiveName("Extracted", env.SelectedSequence.Title));

            ret.Type = SequenceType.Numeric;
            return(ret);
        }