Exemple #1
0
        //private static void TestModelComparison()
        //{
        //    Obj ObjFile = new Obj();
        //    ObjFile.LoadObj("Content/Models/monkey.obj");

        //    SortedDictionary<int, SortedSet<int>> VertexFaceMap = new SortedDictionary<int, SortedSet<int>>();
        //    SortedDictionary<int, SortedSet<int>> FaceVertexMap = new SortedDictionary<int, SortedSet<int>>();
        //    SortedDictionary<int, SortedSet<int>> VertexVertexMap = new SortedDictionary<int, SortedSet<int>>();
        //    SortedDictionary<int, SortedSet<VertexDistance>> VertexVertexDistanceMap = new SortedDictionary<int, SortedSet<VertexDistance>>();

        //    for (int i = 0; i < ObjFile.FaceList.Count; ++i)
        //    {
        //        for (int fp = 0; fp < ObjFile.FaceList[i].VertexIndexList.Length; ++fp)
        //        {
        //            if (VertexFaceMap.ContainsKey(ObjFile.FaceList[i].VertexIndexList[fp]))
        //            {
        //                VertexFaceMap[ObjFile.FaceList[i].VertexIndexList[fp]].Add(ObjFile.FaceList[i].Index);
        //            }
        //            else
        //            {
        //                VertexFaceMap.Add(ObjFile.FaceList[i].VertexIndexList[fp], new SortedSet<int>() { ObjFile.FaceList[i].Index });
        //            }

        //            if (FaceVertexMap.ContainsKey(ObjFile.FaceList[i].Index))
        //            {
        //                FaceVertexMap[ObjFile.FaceList[i].Index].Add(ObjFile.FaceList[i].VertexIndexList[fp]);
        //            }
        //            else
        //            {
        //                FaceVertexMap.Add(ObjFile.FaceList[i].Index, new SortedSet<int>() { ObjFile.FaceList[i].VertexIndexList[fp] });
        //            }

        //            if (!VertexVertexMap.ContainsKey(ObjFile.FaceList[i].VertexIndexList[fp]))
        //            {
        //                VertexVertexMap.Add(ObjFile.FaceList[i].VertexIndexList[fp], new SortedSet<int>());
        //                VertexVertexDistanceMap.Add(ObjFile.FaceList[i].VertexIndexList[fp], new SortedSet<VertexDistance>());
        //            }

        //            for (int v = 0; v < ObjFile.FaceList[i].VertexIndexList.Length; ++v)
        //            {
        //                if (ObjFile.FaceList[i].VertexIndexList[fp] != ObjFile.FaceList[i].VertexIndexList[v])
        //                {
        //                    VertexVertexMap[ObjFile.FaceList[i].VertexIndexList[fp]].Add(ObjFile.FaceList[i].VertexIndexList[v]);

        //                    VertexVertexDistanceMap[ObjFile.FaceList[i].VertexIndexList[fp]].Add(new VertexDistance()
        //                    {
        //                        Source = ObjFile.FaceList[i].VertexIndexList[fp],
        //                        Destination = ObjFile.FaceList[i].VertexIndexList[v],
        //                        Distance = Vertex.CalcDistance(ObjFile.VertexList[ObjFile.FaceList[i].VertexIndexList[v] - 1], ObjFile.VertexList[ObjFile.FaceList[i].VertexIndexList[fp] - 1])
        //                    });
        //                }
        //            }
        //        }
        //    }

        //    SortedSet<VertexDistance> Shape = new SortedSet<VertexDistance>();

        //    foreach (int Key in VertexVertexDistanceMap.Keys)
        //    {
        //        foreach (VertexDistance DistObj in VertexVertexDistanceMap[Key])
        //        {
        //            Shape.Add(DistObj);
        //        }
        //    }

        //    List<VertexDistance> ListShape = Shape.ToList();

        //    for (int i = 0; i < ListShape.Count; ++i)
        //    {
        //        ulong CurrentId = ListShape[i].Id;
        //        ListShape[i].ConnectedSide1.AddRange(Shape.Where(x => x.Id != CurrentId && (x.Side1 == ListShape[i].Side1 || x.Side2 == ListShape[i].Side1)).OrderBy(x => x.Distance).ThenBy(x => x.Side1).ThenBy(x => x.Side2));
        //        ListShape[i].ConnectedSide2.AddRange(Shape.Where(x => x.Id != CurrentId && (x.Side1 == ListShape[i].Side2 || x.Side2 == ListShape[i].Side2)).OrderBy(x => x.Distance).ThenBy(x => x.Side1).ThenBy(x => x.Side2));
        //    }

        //    LoopingSequence<VertexDistance> LoopingSequence = new LoopingSequence<VertexDistance>(ListShape.ToArray());
        //}

        private static void TestLoopingSequence()
        {
            Random rnd = new Random();

            byte[] sequence1 = new byte[] { 1, 2, 3, 1, 2, 3, 1, 2, 3 };
            byte[] sequence2 = new byte[] { 10, 1, 2, 3, 1, 2, 3, 1, 2, 3, 10 };
            //byte[] sequence1 = new byte[] { 7, 7, 7, 7, 7, 7, 7, 7, 7 };
            //byte[] sequence2 = new byte[] { 7, 7, 7, 7, 7, 7, 7, 7, 7, 1 };

            //rnd.NextBytes(sequence1);
            //rnd.NextBytes(sequence2);

            Console.WriteLine("Starting");

            LoopingSequence <byte> seq1 = new LoopingSequence <byte>(sequence1);
            LoopingSequence <byte> seq2 = new LoopingSequence <byte>(sequence2);

            List <SequenceMatchScore> scores = seq1.CompareSequence(seq2, new ByteComparer(0), out int ThisBestStartIndex, out int BestMatchScore, out int BestOtherMatchIndex, 3, 3);

            Console.WriteLine($"ThisBestStartIndex : {ThisBestStartIndex}");
            Console.WriteLine($"BestMatchScore : {BestMatchScore}");
            Console.WriteLine($"BestOtherMatchIndex : {BestOtherMatchIndex}");
        }