コード例 #1
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);
        }
コード例 #2
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);
                        }
                    }
                }
            }
        }
コード例 #3
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);
        }
コード例 #4
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);
        }