public static bool KLGetPatternsFromLinearPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                                MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                                List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                                ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            // Se non uso listOfComponentsOnThePath probabilmente dovrò aggiornare listOfOrigins con il numero effettivo di elementi che appartengono al pattern selezionato.
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            //var numOfCompOnThisPath = listOfOrigins.Count;

            var noStop = true;

            //const string nameFile = "GetTranslationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("VERIFICA DELLE POSSIBILI TRASLAZIONI TRA " + numOfCompOnThisPath + " COMPONENTS:", nameFile);
            //KLdebug.Print(" ", nameFile);

            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var foundNewPattern = KLGetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref i, ref numOfCompOnThisPath,
                                                                       ref noStop, ref newPattern);

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        noStop = true;
                    }

                    var listREofRcomponents = new List <MyRepeatedEntity>(listOfComponentsOnThePath.Select(comp => comp.RepeatedEntity).ToList());
                    //var listGS = new List<Surface>();
                    var newPatternPoint = new MyPattern(listREofRcomponents, newPattern.pathOfMyPattern,
                                                        newPattern.typeOfMyPattern);

                    KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                              listOfOrigins, ref listOfMatrAdj,
                                              ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("FINE LISTA :) ", nameFile);

            if (noStop)
            {
                //KLdebug.Print("NESSUNA INTERRUZIONE: PATTERN DI LUNGHEZZA MASSIMA SU QUESTO PATH!", nameFile);
                return(true);
            }
            return(false);
        }
        public static bool  GetPatternsFromCircularPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                                 MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                                 List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                                 ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            var noStop = true;

            const string nameFile = "GetCircularPatterns.txt";

            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var j               = i;
                var foundNewPattern = GetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref j, ref numOfCompOnThisPath,
                                                                     ref noStop, ref newPattern);

                if (foundNewPattern == false)
                {
                    var pathCircumference = (MyCircumForPath)pathObject;
                    foundNewPattern = GetMaximumRotation_Assembly(listOfComponentsOnThePath, pathCircumference, ref i, ref numOfCompOnThisPath,
                                                                  ref noStop, ref newPattern);
                }
                else
                {
                    i = j;
                }

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        noStop = true;
                    }

                    CheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                            listOfOrigins, ref listOfMatrAdj,
                                            ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            if (noStop)
            {
                return(true);
            }
            return(false);
        }
        public static bool GetPatternsFromCircularPath(List <MyRepeatedEntity> listOfREOnThePath,
                                                       MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfCentroids,
                                                       List <MyRepeatedEntity> listOfREOnThisSurface, ref List <MyMatrAdj> listOfMatrAdj,
                                                       ref List <MyGroupingSurface> listOfMyGroupingSurface,
                                                       List <MyGroupingSurface> listOfInitialGroupingSurface, ref List <MyPattern> listOfOutputPattern,
                                                       ref List <MyPattern> listOfOutputPatternTwo)
        {
            var numOfRE = listOfREOnThePath.Count;
            var noStop  = true;


            var i = 0;

            while (i < (numOfRE - 1))
            {
                var newPattern      = new MyPattern();
                var j               = i;
                var foundNewPattern = GetMaximumTranslation(listOfREOnThePath, pathObject, ref j, ref numOfRE, ref noStop,
                                                            ref newPattern, listOfInitialGroupingSurface);

                if (foundNewPattern == false)
                {
                    var pathCircumference = (MyCircumForPath)pathObject;
                    foundNewPattern = GetMaximumRotation(listOfREOnThePath, pathCircumference, ref i, ref numOfRE, ref noStop,
                                                         ref newPattern, listOfInitialGroupingSurface);
                }
                else
                {
                    i = j;
                }

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyREOfMyPattern.Count == numOfRE || newPattern.listOfMyREOfMyPattern.Count == numOfRE - 1)
                    {
                        noStop = true;
                    }

                    CheckAndUpdate(newPattern, ref listOfPathOfCentroids,
                                   listOfREOnThisSurface, ref listOfMatrAdj, ref listOfMyGroupingSurface,
                                   ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            if (noStop)
            {
                return(true);
            }
            return(false);
        }
예제 #4
0
        public static bool GetMaximumTranslation_ComposedPatterns(List <MyPattern> listOfPatternOnThePath,
                                                                  MyPathGeometricObject pathObject, ref int i, ref int numOfPatterns, ref bool noStop,
                                                                  ref MyComposedPattern outputComposedPattern)
        {
            const string nameFile    = "ComposedPatterns_Linear.txt";
            var          whatToWrite = "";

            var listOfPatternsOfNew = new List <MyPattern> {
                listOfPatternOnThePath[i]
            };
            var lengthOfNew = 1;
            var exit        = false;

            while (i < (numOfPatterns - 1) && exit == false)
            {
                whatToWrite = string.Format("         Confronto {0}^ pattern e la {1}^ pattern: ", i, i + 1);

                if (IsTranslationTwoPatterns(listOfPatternOnThePath[i], listOfPatternOnThePath[i + 1]))
                {
                    listOfPatternsOfNew.Add(listOfPatternOnThePath[i + 1]);
                    lengthOfNew += 1;

                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    i++;
                }
            }

            if (lengthOfNew > 1)
            {
                outputComposedPattern.listOfMyPattern         = listOfPatternsOfNew;
                outputComposedPattern.pathOfMyComposedPattern = pathObject;

                outputComposedPattern.typeOfMyComposedPattern = "(linear) TRANSLATION";

                outputComposedPattern.constStepOfMyComposedPattern = listOfPatternsOfNew[0].patternCentroid.Distance(
                    listOfPatternsOfNew[1].patternCentroid);
                return(true);
            }

            return(false);
        }
예제 #5
0
        public static bool GetMaximumTranslation_Assembly_ComposedPatterns(List <MyPatternOfComponents> listOfPatternOnThePath,
                                                                           MyPathGeometricObject pathObject, ref int i, ref int numOfPatterns, ref bool noStop,
                                                                           ref MyComposedPatternOfComponents outputComposedPattern)
        {
            var listOfPatternsOfNew = new List <MyPatternOfComponents> {
                listOfPatternOnThePath[i]
            };
            var lengthOfNew = 1;
            var exit        = false;

            while (i < (numOfPatterns - 1) && exit == false)
            {
                if (IsTranslationTwoPatternsOfComponents(listOfPatternOnThePath[i], listOfPatternOnThePath[i + 1]))
                {
                    listOfPatternsOfNew.Add(listOfPatternOnThePath[i + 1]);
                    lengthOfNew += 1;

                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    i++;
                }
            }

            if (lengthOfNew > 1)
            {
                outputComposedPattern.ListOfMyPatternOfComponents         = listOfPatternsOfNew;
                outputComposedPattern.pathOfMyComposedPatternOfComponents = pathObject;

                outputComposedPattern.typeOfMyComposedPatternOfComponents = "(linear) TRANSLATION";

                outputComposedPattern.constStepOfMyComposedPatternOfComponents =
                    listOfPatternsOfNew[0].patternCentroid.Distance(
                        listOfPatternsOfNew[1].patternCentroid);
                return(true);
            }

            return(false);
        }
        //It detects all the TRANSLATIONAL relations in a set of MyRepeatedComponent
        //whose origins lie on a given line.
        //it saves patterns of length = 2 in a list;
        //it saves patterns of length > 2 in a list.
        //It returns TRUE if only one pattern has been detected and it has maximum length, FALSE otherwise.

        public static bool GetPatternsFromLinearPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                              MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                              List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                              ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            var noStop = true;


            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var foundNewPattern = GetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref i, ref numOfCompOnThisPath,
                                                                     ref noStop, ref newPattern);

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        noStop = true;
                    }

                    CheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                            listOfOrigins, ref listOfMatrAdj,
                                            ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            if (noStop)
            {
                return(true);
            }
            return(false);
        }
        public static bool KLGetPatternsFromCircularPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                                  MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                                  List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                                  ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo, ModelDoc2 SwModel, SldWorks SwApplication)
        {
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            var noStop = true;

            //const string nameFile = "GetCircularPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print(
            //    "VERIFICA DELLE POSSIBILI TRASLAZIONI SU CIRCONFERENZA O ROTAZIONI TRA " + numOfCompOnThisPath + " COMPONENTS:",
            //    nameFile);
            //KLdebug.Print(" ", nameFile);

            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var j               = i;
                var foundNewPattern = KLGetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref j, ref numOfCompOnThisPath,
                                                                       ref noStop, ref newPattern, SwApplication);
                if (foundNewPattern == false)
                {
                    var pathCircumference = (MyCircumForPath)pathObject;

                    foundNewPattern = KLGetMaximumRotation_Assembly(listOfComponentsOnThePath, pathCircumference,
                                                                    ref i, ref numOfCompOnThisPath,
                                                                    ref noStop, ref newPattern, SwModel, SwApplication);
                }
                else
                {
                    i = j;
                }

                if (foundNewPattern)
                {
                    //KLdebug.Print("foundNewPattern vero", nameFile);
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        //KLdebug.Print("foundNewPattern vero no stop", nameFile);
                        noStop = true;
                    }

                    KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                              listOfOrigins, ref listOfMatrAdj,
                                              ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("FINE LISTA :) ", nameFile);

            if (noStop)
            {
                // KLdebug.Print("NESSUNA INTERRUZIONE: PATTERN DI LUNGHEZZA MASSIMA SU QUESTO PATH!", nameFile);
                return(true);
            }
            return(false);
        }
예제 #8
0
        //Crea il massimo path LINEA a partire dai 3 punti dati
        public static List <int> ThreePointsGivenPathsLine(MyMatrAdj MatrAdjToSee, List <MyVertex> ListCentroid,
                                                           List <int> ListOfExtremePoints, int Point1, int Point2, int Point3, ref StringBuilder fileOutput,
                                                           ref bool ToleranceOk, out MyPathGeometricObject pathCurve)
        {
            #region VERSION 1: the original, it is ok
            //var nameFile = "ContaElementiPath.txt";

            //List<int> Path = new List<int>();

            //Path.Add(Point1);
            //Path.Add(Point2);
            //Path.Add(Point3);
            //KLdebug.Print("point1 = " + Point1, nameFile);
            //KLdebug.Print("point2 = " + Point2, nameFile);
            //KLdebug.Print("point1 = " + Point3, nameFile);


            //MyLine linePath = FunctionsLC.LinePassingThrough(ListCentroid[Point2], ListCentroid[Point3]);

            ////procedo nella direzione Point2-Point3

            //List<int> BranchesThird = MatrAdjToSee.matr.GetRow(Point3).Find(entry => entry == 1).ToList(); //cerco tra questi

            //BranchesThird.Remove(Point2);
            //KLdebug.Print("Num of elementi in BranchesThird (1^ volta) = " + BranchesThird.Count, nameFile);

            //foreach (int ind in BranchesThird)
            //{
            //    KLdebug.Print("- " + ind, nameFile);
            //}

            //int Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
            //while (Next != -1)
            //{
            //    // Check if the tolerance is too rough
            //    int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
            //    if (NumOfFound == 1)
            //    {
            //        int NextInd = BranchesThird[Next];
            //        BranchesThird.Clear();
            //        BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi
            //        KLdebug.Print("Num of elementi in BranchesThird = " + BranchesThird.Count, nameFile);

            //        foreach (int ind in BranchesThird)
            //        {
            //            KLdebug.Print("- " + ind, nameFile);
            //        }

            //        BranchesThird.Remove(Path[Path.Count - 1]); //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in coda), perché se no tornerei indietro
            //        KLdebug.Print("Path.count = " + Path.Count, nameFile);
            //        Path.Add(NextInd); //aggiungo in coda al path
            //        KLdebug.Print("Aggiunto al path: - " + NextInd, nameFile);
            //        KLdebug.Print("Path.count dopo aggiunta = " + Path.Count, nameFile);
            //        Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
            //        KLdebug.Print(" ", nameFile);

            //    }
            //    else
            //    {
            //        //End the execution in the higher levels
            //        ToleranceOk = false;
            //        pathCurve = null;
            //        return Path;
            //    }

            //}

            //#region Check if I can invert the direction of expansion on not
            ////se Point1 non era un Extreme point, inverto la direzione procedendo verso Point2-Point1
            //if (!(ListOfExtremePoints.Contains(Point1)))
            //{
            //    BranchesThird.Clear();
            //    BranchesThird = MatrAdjToSee.matr.GetRow(Point1).Find(entry => entry == 1).ToList(); //cerco tra questi
            //    BranchesThird.Remove(Point2);
            //    Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
            //    //uso FindIndex perché mi restituisce -1 se non trova
            //    while (Next != -1)
            //    {
            //        // Check if the tolerance is too rough
            //        int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
            //        if (NumOfFound == 1)
            //        {
            //            int NextInd = BranchesThird[Next];
            //            BranchesThird.Clear();
            //            BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi
            //            BranchesThird.Remove(Path[0]); //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in testa), perché se no tornerei indietro
            //            Path.Insert(0, NextInd);  //aggiungo in testa al path
            //            Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
            //        }
            //        else
            //        {
            //            //End the execution in the higher levels
            //            ToleranceOk = false;
            //            pathCurve = null;
            //            return Path;
            //        }

            //    }
            //}
            //#endregion

            //fileOutput.AppendLine("\n Nuovo path retta:");
            //foreach (int ind in Path)
            //{
            //    fileOutput.AppendLine(" - " + ind);
            //}
            //pathCurve = linePath;
            //return Path;
            #endregion

            #region VERSION 2: ok but not very compact

            /*   var nameFile = "ContaElementiPath.txt";
             *
             * List<int> Path = new List<int>();
             *
             * Path.Add(Point1);
             * Path.Add(Point2);
             * Path.Add(Point3);
             * KLdebug.Print("point1 = " + Point1, nameFile);
             * KLdebug.Print("point2 = " + Point2, nameFile);
             * KLdebug.Print("point1 = " + Point3, nameFile);
             *
             * KLdebug.Print("Matr distance = " + MatrAdjToSee.d, nameFile);
             * KLdebug.Print("Matrice dimension = " + MatrAdjToSee.matr.GetLength(0), nameFile);
             * var line = string.Format(
             *                "Matrice :\n" +
             *                "{0} {1} {2} {3}\n" +
             *                "{4} {5} {6} {7}\n" +
             *                "{8} {9} {10} {11}\n"+
             *                "{12} {13} {14} {15}\n\n",
             *
             *                MatrAdjToSee.matr[0, 0], MatrAdjToSee.matr[0, 1], MatrAdjToSee.matr[0, 2], MatrAdjToSee.matr[0, 3],
             *                MatrAdjToSee.matr[1, 0], MatrAdjToSee.matr[1, 1], MatrAdjToSee.matr[1, 2], MatrAdjToSee.matr[1, 3],
             *                MatrAdjToSee.matr[2, 0], MatrAdjToSee.matr[2, 1], MatrAdjToSee.matr[2, 2], MatrAdjToSee.matr[2, 3],
             *                MatrAdjToSee.matr[3, 0], MatrAdjToSee.matr[3, 1], MatrAdjToSee.matr[3, 2], MatrAdjToSee.matr[3, 3]
             *               );
             * KLdebug.Print(line, nameFile);
             *
             * MyLine linePath = FunctionsLC.LinePassingThrough(ListCentroid[Point2], ListCentroid[Point3]);
             * int NextInd;
             *
             * //procedo nella direzione Point2-Point3
             * List<int> BranchesThird = MatrAdjToSee.matr.GetRow(Point3).Find(entry => entry == 1).ToList(); //cerco tra questi
             * BranchesThird.Remove(Point2);
             *
             * KLdebug.Print("Branches di " + Point3  + " :", nameFile);
             * foreach (int ind in BranchesThird)
             * {
             *  KLdebug.Print("- " + ind, nameFile);
             * }
             *
             * int Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
             * int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
             *
             * if (NumOfFound == 1)
             * {
             *  NextInd = BranchesThird[Next];
             *  Path.Add(NextInd); //aggiungo in coda al path
             *  KLdebug.Print("Aggiunto al path (1^ volta) : - " + NextInd, nameFile);
             *  KLdebug.Print("Path dopo aggiunta: ", nameFile);
             *  foreach (int ind in Path)
             *  {
             *      KLdebug.Print("- " + ind, nameFile);
             *  }
             *
             *  BranchesThird.Clear();
             *  BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi
             *  BranchesThird.Remove(Path[Path.Count - 2]);
             *  KLdebug.Print("Rimosso dai branch (1^ volta) : - " + Path[Path.Count - 2], nameFile);
             *
             *  KLdebug.Print("Branches (1^ volta)" + NextInd + " :", nameFile);
             *  foreach (int ind in BranchesThird)
             *  {
             *      KLdebug.Print("- " + ind, nameFile);
             *  }
             *  Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
             *  KLdebug.Print(" ", nameFile);
             *
             *
             *  while (Next != -1)
             *  {
             *      KLdebug.Print("(Entro nel while)", nameFile);
             *      // Check if the tolerance is too rough
             *      NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
             *      if (NumOfFound == 1)
             *      {
             *          NextInd = BranchesThird[Next];
             *          BranchesThird.Clear();
             *          BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi
             *          BranchesThird.Remove(Path[Path.Count - 1]); //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in coda), perché se no tornerei indietro
             *          KLdebug.Print("Rimosso dai branch: - " + Path[Path.Count - 2], nameFile);
             *
             *          KLdebug.Print("Branches di " + NextInd + " :", nameFile);
             *          foreach (int ind in BranchesThird)
             *          {
             *              KLdebug.Print("- " + ind, nameFile);
             *          }
             *
             *          Path.Add(NextInd); //aggiungo in coda al path
             *          KLdebug.Print("Aggiunto al path: - " + NextInd, nameFile);
             *          KLdebug.Print("Path dopo aggiunta: " + Path.Count, nameFile);
             *          foreach (int ind in Path)
             *          {
             *              KLdebug.Print("- " + ind, nameFile);
             *          }
             *          Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
             *          KLdebug.Print(" ", nameFile);
             *
             *      }
             *      else
             *      {
             *          //End the execution in the higher levels
             *          ToleranceOk = false;
             *          pathCurve = null;
             *          return Path;
             *      }
             *
             *
             *  }
             * }
             *
             #region Check if I can invert the direction of expansion on not
             * //se Point1 non era un Extreme point, inverto la direzione procedendo verso Point2-Point1
             * if (!(ListOfExtremePoints.Contains(Point1)))
             * {
             *  BranchesThird.Clear();
             *  BranchesThird = MatrAdjToSee.matr.GetRow(Point1).Find(entry => entry == 1).ToList(); //cerco tra questi
             *  BranchesThird.Remove(Point2);
             *  Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
             *  //uso FindIndex perché mi restituisce -1 se non trova
             *  while (Next != -1)
             *  {
             *      // Check if the tolerance is too rough
             *      NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
             *      if (NumOfFound == 1)
             *      {
             *          NextInd = BranchesThird[Next];
             *          BranchesThird.Clear();
             *          BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi
             *          BranchesThird.Remove(Path[0]); //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in testa), perché se no tornerei indietro
             *          Path.Insert(0, NextInd);  //aggiungo in testa al path
             *          Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
             *      }
             *      else
             *      {
             *          //End the execution in the higher levels
             *          ToleranceOk = false;
             *          pathCurve = null;
             *          return Path;
             *      }
             *
             *  }
             * }
             #endregion
             *
             * fileOutput.AppendLine("\n Nuovo path retta:");
             * foreach (int ind in Path)
             * {
             *  fileOutput.AppendLine(" - " + ind);
             * }
             * pathCurve = linePath;
             * return Path;
             */
            #endregion

            //VERSION 3: Ok and more compact

            List <int> Path = new List <int>();

            Path.Add(Point1);
            Path.Add(Point2);
            Path.Add(Point3);

            MyLine linePath = FunctionsLC.LinePassingThrough(ListCentroid[Point2], ListCentroid[Point3]);

            //procedo nella direzione Point2-Point3
            List <int> BranchesThird = MatrAdjToSee.matr.GetRow(Point3).Find(entry => entry == 1).ToList(); //cerco tra questi
            BranchesThird.Remove(Point2);

            int Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
            while (Next != -1)
            {
                // Check if the tolerance is too rough
                int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
                if (NumOfFound == 1)
                {
                    int NextInd = BranchesThird[Next];
                    Path.Add(NextInd); //aggiungo in coda al path

                    BranchesThird.Clear();
                    BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi

                    BranchesThird.Remove(Path[Path.Count - 2]);                                           //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in coda), perché se no tornerei indietro
                    Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
                }
                else
                {
                    //End the execution in the higher levels
                    ToleranceOk = false;
                    pathCurve   = null;
                    return(Path);
                }
            }

            #region Check if I can invert the direction of expansion on not
            //se Point1 non era un Extreme point, inverto la direzione procedendo verso Point2-Point1
            if (!(ListOfExtremePoints.Contains(Point1)))
            {
                BranchesThird.Clear();
                BranchesThird = MatrAdjToSee.matr.GetRow(Point1).Find(entry => entry == 1).ToList(); //cerco tra questi
                BranchesThird.Remove(Point2);
                Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
                //uso FindIndex perché mi restituisce -1 se non trova
                while (Next != -1)
                {
                    // Check if the tolerance is too rough
                    int NumOfFound = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieonline(linePath)).Count;
                    if (NumOfFound == 1)
                    {
                        int NextInd = BranchesThird[Next];
                        BranchesThird.Clear();
                        BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList(); //cerco tra questi
                        BranchesThird.Remove(Path[0]);                                                        //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in testa), perché se no tornerei indietro
                        Path.Insert(0, NextInd);                                                              //aggiungo in testa al path
                        Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieonline(linePath));
                    }
                    else
                    {
                        //End the execution in the higher levels
                        ToleranceOk = false;
                        pathCurve   = null;
                        return(Path);
                    }
                }
            }
            #endregion

            fileOutput.AppendLine("\n Nuovo path retta:");
            foreach (int ind in Path)
            {
                fileOutput.AppendLine(" - " + ind);
            }
            pathCurve = linePath;
            return(Path);
        } //fine ThreePointsGivenPathsLine
예제 #9
0
        public static bool GetMaximumTranslation_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath, MyPathGeometricObject pathObject,
                                                          ref int i, ref int numOfCompOnThisPath, ref bool noStop, ref MyPatternOfComponents outputPattern)
        {
            const string nameFile = "GetTranslationalPatterns.txt";
            string       whatToWrite;

            var listOfComponentsOfNewMyPattern = new List <MyRepeatedComponent> {
                listOfComponentsOnThePath[i]
            };
            var lengthOfCurrentPath = listOfComponentsOfNewMyPattern.Count;
            var exit = false;

            while (i < (numOfCompOnThisPath - 1) && exit == false)
            {
                if (IsTranslationTwoRC(listOfComponentsOnThePath[i], listOfComponentsOnThePath[i + 1]))
                {
                    listOfComponentsOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]);
                    lengthOfCurrentPath += 1;
                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    i++;
                }
            }

            if (lengthOfCurrentPath > 1)
            {
                outputPattern.listOfMyRCOfMyPattern = listOfComponentsOfNewMyPattern;
                outputPattern.pathOfMyPattern       = pathObject;

                if (pathObject.GetType() == typeof(MyLine))
                {
                    outputPattern.typeOfMyPattern = "linear TRANSLATION";
                }
                else
                {
                    outputPattern.typeOfMyPattern = "circular TRANSLATION";
                }
                outputPattern.constStepOfMyPattern = listOfComponentsOfNewMyPattern[0].Origin.Distance(
                    listOfComponentsOfNewMyPattern[1].Origin);
                return(true);
            }

            return(false);
        }
예제 #10
0
        public static bool KLGetMaximumTranslation_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath, MyPathGeometricObject pathObject,
                                                            ref int i, ref int numOfCompOnThisPath, ref bool noStop, ref MyPatternOfComponents outputPattern)
        {
            //const string nameFile = "GetTranslationalPatterns.txt";

            var listOfREOnThePath = new List <MyRepeatedEntity>(listOfComponentsOnThePath.Select(comp => comp.RepeatedEntity));

            var listOfREOfNewMyPattern = new List <MyRepeatedEntity> {
                listOfREOnThePath[i]
            };
            var listOfComponetsOfNewMyPattern = new List <MyRepeatedComponent> {
                listOfComponentsOnThePath[i]
            };

            var lengthOfCurrentPath = listOfREOfNewMyPattern.Count;   // = number of couple possibly related by translation (= number of repetition of distance d)
            var exit = false;

            while (i < (numOfCompOnThisPath - 1) && exit == false) //fino alla penultima RE
            {
                if (true)
                //if (Part.PartUtilities.GeometryAnalysis.IsTranslationTwoRE(listOfREOnThePath[i], listOfREOnThePath[i + 1]))
                {
                    listOfREOfNewMyPattern.Add(listOfREOnThePath[i + 1]);
                    listOfComponetsOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]);
                    lengthOfCurrentPath += 1;
                    //KLdebug.Print("Aggiunta " + (i + 1) + "-esima COMP al MYPattern. lengthOfCurrentPath = " + listOfComponetsOfNewMyPattern.Count, nameFile);
                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    //KLdebug.Print(" ", nameFile);
                    //KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile);
                    //KLdebug.Print(" ", nameFile);

                    i++;
                }
            }

            if (lengthOfCurrentPath > 1)
            {
                outputPattern.listOfMyRCOfMyPattern = listOfComponetsOfNewMyPattern;
                outputPattern.pathOfMyPattern       = pathObject;

                if (pathObject.GetType() == typeof(MyLine))
                {
                    outputPattern.typeOfMyPattern = "linear TRANSLATION";
                    //KLdebug.Print("CREATO PATTERN TRANS lineare DI LUNGHEZZA = " + listOfREOfNewMyPattern.Count, nameFile);
                }
                else
                {
                    outputPattern.typeOfMyPattern = "circular TRANSLATION";
                    //KLdebug.Print("CREATO PATTERN TRANS circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile);
                    var teta = FunctionsLC.FindAngle(listOfREOfNewMyPattern[0].centroid,
                                                     listOfREOfNewMyPattern[1].centroid, ((MyCircumForPath)pathObject).circumcenter);
                    outputPattern.angle = teta;
                }
                outputPattern.constStepOfMyPattern = listOfREOfNewMyPattern[0].centroid.Distance(listOfREOfNewMyPattern[1].centroid);
                return(true);
            }

            return(false);
        }
예제 #11
0
        // This function updates the list of paths adding the paths raising from the given 1st and 2nd seed set points.
        public static void TwoPointsGivenPaths(MyMatrAdj matrAdjToSee, int n, int startPointInd,
                                               int secondPointInd, List <MyRepeatedEntity> listOfREOnThisSurface, List <MyVertex> listCentroid,
                                               List <int> listOfExtremePoints, ref List <int> listOfSimplePoints_Copy, List <int> listOfMBPoints,
                                               ref bool longestPattern, ref List <MyPathOfPoints> listOfPaths, ref List <int> listOfPenultimate,
                                               ref List <int> listOfLast, ref StringBuilder fileOutput, ref bool toleranceOk,
                                               ref List <MyMatrAdj> listOfMatrAdj, ref List <MyGroupingSurface> listOfMyGroupingSurface,
                                               List <MyGroupingSurface> listOfInitialGroupingSurface,
                                               ref List <MyPattern> listOfOutputPattern, ref List <MyPattern> listOfOutputPatternTwo,
                                               ref List <int> listOfIndicesOfLongestPath)
        {
            if (listOfExtremePoints.Contains(secondPointInd))
            //If the branch is an ExtremePoint, I treat it in a special way as I have not
            //the path equation yet. So I guide the 3rd point search.
            {
                //I come back, so I look what are the branches of the StartPoint
                List <int> BranchesSecond = matrAdjToSee.matr.GetRow(startPointInd).Find(entry => entry == 1).ToList();
                BranchesSecond.Remove(secondPointInd);
                foreach (int branch2 in BranchesSecond)
                {
                    var newMyPathOfCentroids = new MyPathOfPoints();

                    //if (SecondPointInd(extreme), StartPointInd(MB), branch2 don't belong to an existing path in ListOfPaths)
                    if (listOfPaths.FindIndex(pathObject => (pathObject.path.Contains(secondPointInd) &&
                                                             pathObject.path.Contains(startPointInd) && pathObject.path.Contains(branch2))) == -1)
                    {
                        List <int> Path      = new List <int>();
                        var        pathCurve = new MyPathGeometricObject();

                        if (listCentroid[branch2].Lieonline(FunctionsLC.LinePassingThrough(
                                                                listCentroid[startPointInd], listCentroid[secondPointInd])))
                        {
                            Path = ThreePointsGivenPathsLine(matrAdjToSee, listCentroid,
                                                             listOfExtremePoints, secondPointInd, startPointInd, branch2,
                                                             ref fileOutput, ref toleranceOk, out pathCurve);
                            // Notice that expansion will procede only in one direction
                        }
                        else
                        {
                            Path = ThreePointsGivenPathsCircum(matrAdjToSee, listCentroid,
                                                               listOfExtremePoints, secondPointInd, startPointInd, branch2,
                                                               ref fileOutput, ref toleranceOk, out pathCurve);
                            // Notice that expansion will procede only in one direction
                        }

                        if (toleranceOk == false)
                        {
                            return;
                        }

                        //If I have found a complete circumference I delete the repeated centroid index:
                        if (Path[0] == Path[Path.Count - 1])
                        {
                            Path.RemoveAt(Path.Count - 1);
                        }

                        newMyPathOfCentroids.path = Path;
                        newMyPathOfCentroids.pathGeometricObject = pathCurve;

                        listOfPaths.Add(newMyPathOfCentroids);

                        fileOutput.AppendLine("Aggiunto alla lista nuovo path: ");
                        fileOutput.AppendLine("  -numero di baricentri:" + newMyPathOfCentroids.path.Count);
                        if (pathCurve.GetType() == typeof(MyLine))
                        {
                            fileOutput.AppendLine("  -tipo di path: retta");
                            fileOutput.AppendLine("");
                        }
                        else
                        {
                            fileOutput.AppendLine("  -tipo di path: criconferenza");
                            fileOutput.AppendLine("");
                        }

                        //If a path of length n or n-1 is found, I move up the geometrical verify to see
                        //if the process can be stopped at this point (sufficiently satisfying result on this GS)
                        int m = Path.Count;
                        if (m == n || m == n - 1)
                        {
                            fileOutput.AppendLine("\n Trovato path che potrebbe dare un Longest Pattern: VERIFICO");

                            // Removing of the path from the list:
                            //this is done because if the pattern is verified the updating phase (in particular
                            //referred to the part of list of paths updating) will consider all the paths existing
                            //in the list of paths (so also the current long one) and the updating would be
                            //long and useless (we would try to compare the current path to itself).
                            listOfPaths.RemoveAt(listOfPaths.Count - 1);

                            if (PartUtilities.GeometryAnalysis.GetPatternsFromPath(newMyPathOfCentroids, listOfREOnThisSurface,
                                                                                   ref listOfPaths, ref listOfMatrAdj, ref listOfMyGroupingSurface, listOfInitialGroupingSurface,
                                                                                   ref listOfOutputPattern, ref listOfOutputPatternTwo))
                            {
                                longestPattern = true;
                                return;
                            }
                            else
                            {
                                listOfPaths.Add(newMyPathOfCentroids);
                                // Updating of the list of Simple points not yet passed through:
                                var ListOfPaths_copy = new List <MyPathOfPoints>(listOfPaths);
                                listOfSimplePoints_Copy.RemoveAll(point => ListOfPaths_copy[ListOfPaths_copy.Count - 1].path.Contains(point));

                                UpdateListsOfPenultimateAndLast(listOfExtremePoints,
                                                                listOfMBPoints, ref listOfPenultimate, ref listOfLast, Path);

                                listOfIndicesOfLongestPath.Add(listOfPaths.IndexOf(newMyPathOfCentroids));
                            }
                        }
                        else
                        {
                            UpdateListsOfPenultimateAndLast(listOfExtremePoints,
                                                            listOfMBPoints, ref listOfPenultimate, ref listOfLast, Path);
                        }
                    }
                }
            }


            else  // cioè listOfMBPoints.Contains(SecondPointInd) || ListOfSimplePoints.Contains(SecondPointInd)
            {
                //trasforma in lista la selezione sull'array (SecondPointInd,:)
                List <int> BranchesSecond = matrAdjToSee.matr.GetRow(secondPointInd).Find(entry => entry == 1).ToList();

                //levo il punto di partenza (che è sicuramente un branch) per non tornare indietro
                BranchesSecond.Remove(startPointInd);
                foreach (int branch2 in BranchesSecond)
                {
                    var newMyPathOfCentroids = new MyPathOfPoints();

                    // if (StartPointInd, SecondPointInd, branch2 don't belong to an existing path in ListOfPaths )
                    if (listOfPaths.FindIndex(pathObject => (pathObject.path.Contains(startPointInd) &&
                                                             pathObject.path.Contains(secondPointInd) && pathObject.path.Contains(branch2))) == -1)
                    {
                        List <int> Path      = new List <int>();
                        var        pathCurve = new MyPathGeometricObject();

                        if (listCentroid[branch2].Lieonline(FunctionsLC.LinePassingThrough(
                                                                listCentroid[startPointInd], listCentroid[secondPointInd])))
                        {
                            Path = ThreePointsGivenPathsLine(matrAdjToSee, listCentroid,
                                                             listOfExtremePoints, startPointInd, secondPointInd, branch2,
                                                             ref fileOutput, ref toleranceOk, out pathCurve);
                        }
                        else
                        {
                            Path = ThreePointsGivenPathsCircum(matrAdjToSee, listCentroid,
                                                               listOfExtremePoints, startPointInd, secondPointInd, branch2,
                                                               ref fileOutput, ref toleranceOk, out pathCurve);
                        }

                        if (toleranceOk == false)
                        {
                            return;
                        }


                        //If I have found a complete circumference I delete the repeated centroid index:
                        if (Path[0] == Path[Path.Count - 1])
                        {
                            Path.RemoveAt(Path.Count - 1);
                        }
                        newMyPathOfCentroids.path = Path;
                        newMyPathOfCentroids.pathGeometricObject = pathCurve;

                        listOfPaths.Add(newMyPathOfCentroids);

                        fileOutput.AppendLine("Aggiunto alla lista nuovo path: ");
                        fileOutput.AppendLine("  -numero di baricentri:" + newMyPathOfCentroids.path.Count);
                        if (pathCurve.GetType() == typeof(MyLine))
                        {
                            fileOutput.AppendLine("  -tipo di path: retta");
                        }
                        else
                        {
                            fileOutput.AppendLine("  -tipo di path: circonferenza");
                        }

                        //If a path of length n or n-1 is found, I move up the geometrical verify to see
                        //if the process can be stopped at this point (sufficiently satisfying result on this GS)
                        int m = Path.Count;
                        if (m == n || m == n - 1)
                        {
                            fileOutput.AppendLine("\n Trovato path che potrebbe dare un Longest Pattern: VERIFICO");

                            // Removing of the path from the list:
                            listOfPaths.RemoveAt(listOfPaths.Count - 1);

                            if (PartUtilities.GeometryAnalysis.GetPatternsFromPath(newMyPathOfCentroids, listOfREOnThisSurface,
                                                                                   ref listOfPaths, ref listOfMatrAdj, ref listOfMyGroupingSurface, listOfInitialGroupingSurface,
                                                                                   ref listOfOutputPattern, ref listOfOutputPatternTwo))
                            {
                                longestPattern = true;
                                return;
                            }
                            else
                            {
                                listOfPaths.Add(newMyPathOfCentroids);

                                // Updating of the list of Simple points not yet passed through:
                                var ListOfPaths_copy = new List <MyPathOfPoints>(listOfPaths);
                                listOfSimplePoints_Copy.RemoveAll(point => ListOfPaths_copy[ListOfPaths_copy.Count - 1].path.Contains(point));

                                UpdateListsOfPenultimateAndLast(listOfExtremePoints,
                                                                listOfMBPoints, ref listOfPenultimate, ref listOfLast, Path);

                                listOfIndicesOfLongestPath.Add(listOfPaths.IndexOf(newMyPathOfCentroids));
                            }
                        }
                        else
                        {
                            UpdateListsOfPenultimateAndLast(listOfExtremePoints,
                                                            listOfMBPoints, ref listOfPenultimate, ref listOfLast, Path);
                        }
                    }
                }
            }
        }
예제 #12
0
        //Crea il massimo path CIRCONFERENZA a partire dai 3 punti dati
        public static List <int> ThreePointsGivenPathsCircum(MyMatrAdj MatrAdjToSee,
                                                             List <MyVertex> ListCentroid, List <int> ListOfExtremePoints, int Point1,
                                                             int Point2, int Point3, ref StringBuilder fileOutput, ref bool ToleranceOk,
                                                             out MyPathGeometricObject pathCurve, ModelDoc2 swModel = null, SldWorks swApplication = null)
        {
            List <int> Path = new List <int>();

            Path.Add(Point1);
            Path.Add(Point2);
            Path.Add(Point3);

            MyCircumForPath CircumPath = FunctionsLC.CircumPassingThrough(
                ListCentroid[Point1], ListCentroid[Point2], ListCentroid[Point3], ref fileOutput, swModel, swApplication);

            //procedo nella direzione Point2-Point3
            fileOutput.AppendLine("Point3: " + Point3);
            List <int> BranchesThird = MatrAdjToSee.matr.GetRow(Point3).Find(entry => entry == 1).ToList();

            //cerco tra questi
            BranchesThird.Remove(Point2);
            //foreach (int ind in BranchesThird)
            //{
            //    fileOutput.AppendLine("\n branch del 3° punto " + Point3 + ": " + ind);
            //}

            int Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath));

            while (Next != -1 && BranchesThird[Next] != Point1)
            // mi devo fermare anche quando completo la circonferenza, se non va all'infinito
            {
                // Check if the tolerance is too rough
                int NumOfFound =
                    BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath)).Count;
                if (NumOfFound == 1)
                {
                    //List<int> listafind = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath));
                    //foreach (int ind in listafind)
                    //{
                    //    fileOutput.AppendLine("Branch candidato a proseguire il path (dovrebbe essere solo uno!): " + ind);
                    //}
                    //fileOutput.AppendLine("Next: " + Next);

                    int NextInd = BranchesThird[Next];
                    //fileOutput.AppendLine("Nextind: " + NextInd);
                    BranchesThird.Clear();
                    BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList();
                    //cerco tra questi
                    BranchesThird.Remove(Path.Last());
                    //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in coda), perché se no tornerei indietro
                    Path.Add(NextInd);     //aggiungo in coda al path
                    Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath));
                }
                else
                {
                    fileOutput.AppendLine("NumOfFound > 1  !!!!");
                    //End the execution in the higher levels
                    ToleranceOk = false;
                    pathCurve   = null;
                    return(Path);
                }
            }

            #region Check if I can invert the direction of expansion on not

            //se non ho ancora completato il giro (Next=-1) e Point1 non era un Extreme point, inverto la direzione procedendo verso Point2-Point1
            if (Next == -1)
            {
                if (!(ListOfExtremePoints.Contains(Point1)))
                {
                    fileOutput.AppendLine("non ho ancora completato il giro");

                    BranchesThird.Clear();
                    BranchesThird = MatrAdjToSee.matr.GetRow(Point1).Find(entry => entry == 1).ToList();
                    //cerco tra questi
                    BranchesThird.Remove(Point2);
                    Next = BranchesThird.FindIndex(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath));
                    while (Next != -1)
                    // qui sono sicura che che non completerò mai la crf, se no l'avrebbe già completata nell'altro while
                    {
                        // Check if the tolerance is too rough
                        int NumOfFound =
                            BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath))
                            .Count;
                        if (NumOfFound == 1)
                        {
                            //List<int> listafind = BranchesThird.FindAll(ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath));
                            //foreach (int ind in listafind)
                            //{
                            //    fileOutput.AppendLine("Branch candidato a proseguire il path (dovrebbe essere solo uno!): " + ind);
                            //}
                            //fileOutput.AppendLine("Next: " + Next);
                            int NextInd = BranchesThird[Next];
                            //fileOutput.AppendLine("Nextind: " + NextInd);
                            Console.ReadLine();

                            BranchesThird.Clear();
                            BranchesThird = MatrAdjToSee.matr.GetRow(NextInd).Find(entry => entry == 1).ToList();
                            //cerco tra questi
                            BranchesThird.Remove(Path[0]);
                            //rimuovo dai branch trovati l'ultimo elemento che avevo aggiunto al path (in testa), perché se no tornerei indietro
                            Path.Insert(0, NextInd);     //aggiungo in testa al path
                            Next =
                                BranchesThird.FindIndex(
                                    ind_branch => ListCentroid[ind_branch].Lieoncircum(CircumPath));
                        }
                        else
                        {
                            fileOutput.AppendLine("NumOfFound > 1  !!!!  ERRORE. ");
                            //End the execution in the higher levels
                            ToleranceOk = false;
                            pathCurve   = null;
                            return(Path);
                        }
                    }
                }
            }
            else                               //si è usciti dal 1° while perché BranchesThird[Next] == Point1, cioè ho completato il giro
            {
                Path.Add(BranchesThird[Next]); //aggiungo Point1 al Path (faccio un ciclo chiuso)
            }

            #endregion


            fileOutput.AppendLine("\n Nuovo path circonferenza:");
            foreach (int ind in Path)
            {
                fileOutput.AppendLine(" - " + ind);
            }
            pathCurve = CircumPath;


            if (CircumPath != null)
            {
                return(Path);
            }
            Path.Clear();
            return(Path);
        } //fine ThreePointsGivenPathsCircum
예제 #13
0
        //It detect the maximum translational relation in a set of MyRepeatedEntity, starting from index i of the list of MyRE
        //(INITIAL PATH TYPE: line or circumference)
        public static bool GetMaximumTranslation(List <MyRepeatedEntity> listOfREOnThePath, MyPathGeometricObject pathObject,
                                                 ref int i, ref int numOfRE, ref bool noStop, ref MyPattern outputPattern, List <MyGroupingSurface> listOfInitialGroupingSurface)
        {
            #region Old version: computation of the candidate translational array computed as the MEAN VECTOR of all the connection arrays of the centroids
            //To compute the candidateTranslationArray I compute the mean vector
            //of all the difference vector between the centroids:
            //double sumOfx = 0;
            //double sumOfy = 0;
            //double sumOfz = 0;
            //for (int i = 0; i < (numOfRE - 1); i++)
            //{
            //    sumOfx += listOfREOnThePath[i + 1].centroid.x - listOfREOnThePath[i].centroid.x;
            //    sumOfy += listOfREOnThePath[i + 1].centroid.y - listOfREOnThePath[i].centroid.y;
            //    sumOfz += listOfREOnThePath[i + 1].centroid.z - listOfREOnThePath[i].centroid.z;
            //}
            //double[] candidateTranslationArray =
            //{
            //    sumOfx/(numOfRE-1),
            //    sumOfy/(numOfRE-1),
            //    sumOfz/(numOfRE-1)
            //};
            //var whatToWrite = string.Format("Candidate translational array: ({0}, {1}, {2})",
            //    candidateTranslationArray[0], candidateTranslationArray[1], candidateTranslationArray[2]);
            //KLdebug.Print(whatToWrite, nameFile);
            #endregion

            var listOfREOfNewMyPattern = new List <MyRepeatedEntity> {
                listOfREOnThePath[i]
            };
            var lengthOfCurrentPath = listOfREOfNewMyPattern.Count; // = number of couple possibly related by translation (= number of repetition of distance d)
            var exit = false;
            while (i < (numOfRE - 1) && exit == false)              //fino alla penultima RE
            {
                if (IsTranslationTwoRE(listOfREOnThePath[i], listOfREOnThePath[i + 1]))
                {
                    listOfREOfNewMyPattern.Add(listOfREOnThePath[i + 1]);
                    lengthOfCurrentPath += 1;
                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    i++;
                }
            }

            if (lengthOfCurrentPath > 1)
            {
                outputPattern.listOfMyREOfMyPattern = listOfREOfNewMyPattern;
                outputPattern.pathOfMyPattern       = pathObject;

                var listOfGroupingSurfaceForThisPattern = findGroupingSurfacesForThisPattern(listOfInitialGroupingSurface,
                                                                                             listOfREOfNewMyPattern, lengthOfCurrentPath);

                outputPattern.listOfGroupingSurfaces = listOfGroupingSurfaceForThisPattern;
                if (pathObject.GetType() == typeof(MyLine))
                {
                    outputPattern.typeOfMyPattern = "linear TRANSLATION";
                }
                else
                {
                    outputPattern.typeOfMyPattern = "circular TRANSLATION";

                    var teta = FunctionsLC.FindAngle(listOfREOfNewMyPattern[0].centroid,
                                                     listOfREOfNewMyPattern[1].centroid, ((MyCircumForPath)pathObject).circumcenter);
                    outputPattern.angle = teta;
                }
                outputPattern.constStepOfMyPattern = listOfREOfNewMyPattern[0].centroid.Distance(listOfREOfNewMyPattern[1].centroid);
                return(true);
            }

            return(false);
        }