Ejemplo n.º 1
0
        public void FormatGraph(object sender, FormatVertexEventArgs args)
        {
            MyVertex o = (MyVertex)args.Vertex;

            args.VertexFormatter.Label = o.Name;
            args.VertexFormatter.Shape = NGraphviz.Helpers.GraphvizVertexShape.Ellipse;
        }
Ejemplo n.º 2
0
        //Restituisce le equazioni cartesiane della retta passante per V1, V2
        public static MyLine LinePassingThrough(MyVertex V1, MyVertex V2)
        {
            //var whatToWrite = string.Format("LinePassingThrough:");
            //KLdebug.Print(whatToWrite, "LinePassingThrough.txt");

            //manca il controllo se V1==V2
            var tolerance = Math.Pow(10, -5);

            if (Math.Abs(V1.x - V2.x) < tolerance)
            {
                MyPlane FirstPlane = new MyPlane(1, 0, 0, -V1.x);
                if (V1.y == V2.y)
                {
                    MyPlane SecondPlane = new MyPlane(0, 1, 0, -V1.y);
                    MyLine  OutputLine  = new MyLine(FirstPlane, SecondPlane);
                    return(OutputLine);
                }
                else
                {
                    if (Math.Abs(V1.z - V2.z) < tolerance)
                    {
                        MyPlane SecondPlane = new MyPlane(0, 0, 1, -V1.z);
                        MyLine  OutputLine  = new MyLine(FirstPlane, SecondPlane);
                        return(OutputLine);
                    }
                    else
                    {
                        MyPlane SecondPlane = new MyPlane(0, -(V2.z - V1.z) / (V2.y - V1.y), 1, -V1.z + V1.y * (V2.z - V1.z) / (V2.y - V1.y));
                        MyLine  OutputLine  = new MyLine(FirstPlane, SecondPlane);
                        return(OutputLine);
                    }
                }
            }
            else
            {
                if (Math.Abs(V1.y - V2.y) < tolerance)
                {
                    MyPlane FirstPlane = new MyPlane(0, 1, 0, -V1.y);
                    if (Math.Abs(V1.z - V2.z) < tolerance)
                    {
                        MyPlane SecondPlane = new MyPlane(0, 0, 1, -V1.z);
                        MyLine  OutputLine  = new MyLine(FirstPlane, SecondPlane);
                        return(OutputLine);
                    }
                    else
                    {
                        MyPlane SecondPlane = new MyPlane(-(V2.z - V1.z) / (V2.x - V1.x), 0, 1, -V1.z + V1.x * (V2.z - V1.z) / (V2.x - V1.x));
                        MyLine  OutputLine  = new MyLine(FirstPlane, SecondPlane);
                        return(OutputLine);
                    }
                }
                else
                {
                    MyPlane FirstPlane  = new MyPlane(-(V2.y - V1.y) / (V2.x - V1.x), 1, 0, -V1.y + V1.x * (V2.y - V1.y) / (V2.x - V1.x));
                    MyPlane SecondPlane = new MyPlane(-(V2.z - V1.z) / (V2.x - V1.x), 0, 1, -V1.z + V1.x * (V2.z - V1.z) / (V2.x - V1.x));
                    MyLine  OutputLine  = new MyLine(FirstPlane, SecondPlane);
                    return(OutputLine);
                }
            }
        }
Ejemplo n.º 3
0
 public MyCircle(double[] CircleParameters)//Curve myCircle
 {
     //double[] circleParam = myCircle.CircleParams();
     //double[] centerCircleArray = { circleParam[0], circleParam[1], circleParam[2] };
     this.centerCircle = new MyVertex(CircleParameters[0], CircleParameters[1], CircleParameters[2]);
     this.radiusCircle = CircleParameters[6];
 }
        //Restituisce l'equazione cartesiana del piano passante per V1, V2, V3
        public static MyPlane PlanePassingThrough(MyVertex V1, MyVertex V2, MyVertex V3 /*, ref StringBuilder fileOutput*/)
        {
            //manca il controllo se i punti se i 3 punti sono coincidenti...

            MyPlane OutputPlane = new MyPlane();

            if (V1.Lieonline(LinePassingThrough(V2, V3)))
            {
                return(OutputPlane); // Plane does not exist
            }
            else
            {
                var aa   = (V2.y - V1.y) * (V3.z - V1.z) - (V3.y - V1.y) * (V2.z - V1.z);
                var bb   = -((V2.x - V1.x) * (V3.z - V1.z) - (V3.x - V1.x) * (V2.z - V1.z));
                var cc   = (V2.x - V1.x) * (V3.y - V1.y) - (V3.x - V1.x) * (V2.y - V1.y);
                var norm = Math.Sqrt(Math.Pow(aa, 2) + Math.Pow(bb, 2) + Math.Pow(cc, 2));
                OutputPlane.a = aa / norm;
                OutputPlane.b = bb / norm;
                OutputPlane.c = cc / norm;
                OutputPlane.d = -OutputPlane.a * V1.x - OutputPlane.b * V1.y - OutputPlane.c * V1.z;

                //VERSIONE VECCHIA CON CUI FUNZIONAVA: SE IN FUTURO SORGONO PROBLEMI TORNARE A QUESTA
                //OutputPlane.a = (V2.y - V1.y) * (V3.z - V1.z) - (V3.y - V1.y) * (V2.z - V1.z);
                //OutputPlane.b = -((V2.x - V1.x) * (V3.z - V1.z) - (V3.x - V1.x) * (V2.z - V1.z));
                //OutputPlane.c = (V2.x - V1.x) * (V3.y - V1.y) - (V3.x - V1.x) * (V2.y - V1.y);
                //OutputPlane.d = -OutputPlane.a * V1.x - OutputPlane.b * V1.y - OutputPlane.c * V1.z;
            }

            return(OutputPlane);
        }
Ejemplo n.º 5
0
        public static bool IsRotationTwoPatterns(MyPattern firstMyPattern, MyPattern secondMyPattern, double teta,
                                                 double[] axisDirection, MyVertex circumCenter, SldWorks SwApplication, ref StringBuilder fileOutput)
        {
            //check of the length correspondence:
            var firstPatternLength  = firstMyPattern.listOfMyREOfMyPattern.Count;
            var secondPatternLength = secondMyPattern.listOfMyREOfMyPattern.Count;

            if (firstPatternLength != secondPatternLength)
            {
                return(false);
            }

            //KLdebug.Print("La 0^ RE del 1° pattern è compatibile con la 0^ RE del 2° pattern? " +
            //    IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
            //    secondMyPattern.listOfMyREOfMyPattern[0], teta, axisDirection, circumCenter), nameFile);
            //KLdebug.Print("La 0^ RE del 1° pattern è compatibile con la (n-1)^ RE del 2° pattern? " +
            //    IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
            //    secondMyPattern.listOfMyREOfMyPattern[secondPatternLength - 1], teta, axisDirection, circumCenter), nameFile);

            if (PartUtilities.GeometryAnalysis.IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
                                                               secondMyPattern.listOfMyREOfMyPattern[0], teta, axisDirection, circumCenter) ||
                PartUtilities.GeometryAnalysis.IsRotationTwoRE(firstMyPattern.listOfMyREOfMyPattern[0],
                                                               secondMyPattern.listOfMyREOfMyPattern[secondPatternLength - 1], teta, axisDirection, circumCenter))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        //The rotation matrix is referred to a counterclockwise rotation, so we must establish
        //which of the two possible direction of the outer pointing normals is the correct one
        public static double[] establishAxisDirection(MyVertex first, MyVertex second, MyVertex center, double[] planeNormal)
        {
            //const string nameFile = "GetRotationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //var whatToWrite = string.Format("planenormal: ({0},{1},{2}) ", planeNormal[0], planeNormal[1], planeNormal[2]);
            //KLdebug.Print(whatToWrite, nameFile);
            var tolerance = Math.Pow(10, -6);

            double[] vectorV1               = { first.x - center.x, first.y - center.y, first.z - center.z };
            double[] vectorV2               = { second.x - center.x, second.y - center.y, second.z - center.z };
            double[] crossProduct           = FunctionsLC.CrossProduct(vectorV1, vectorV2);
            double[] crossProductNormalized = FunctionsLC.Normalize(crossProduct);
            //whatToWrite = string.Format("crossProduct normalized: ({0},{1},{2}) ", crossProductNormalized[0], crossProductNormalized[1], crossProductNormalized[2]);
            //KLdebug.Print(whatToWrite, nameFile);
            if (FunctionsLC.MyEqualsArray(crossProductNormalized, planeNormal))
            {
                //KLdebug.Print("OK: tengo il versore così e lo arrotondo", nameFile);
                for (var i = 0; i < 3; i++)
                {
                    if (Math.Abs(planeNormal[i]) < tolerance)
                    {
                        planeNormal.SetValue(0, i);
                    }
                }
                //whatToWrite = string.Format("Diventa: ({0},{1},{2}) ", planeNormal[0], planeNormal[1], planeNormal[2]);
                //KLdebug.Print(whatToWrite, nameFile);
                return(planeNormal);
            }
            else
            {
                //KLdebug.Print("Devo invertire il versore.", nameFile);
                double[] oppositePlaneNormal = { -planeNormal[0], -planeNormal[1], -planeNormal[2] };
                return(oppositePlaneNormal);
            }
        }
Ejemplo n.º 7
0
        // It creates the MyPlane passing through a given MyVertex and parallel to a given MyPlane    ------------>>>>>>> AL MOMENTO NON SERVE!
        public static MyPlane PlaneParallelToAPlaneAndPassingThroughAPoint(MyVertex givenPoint, MyPlane givenPlane)
        {
            double[] outputNormal             = { givenPlane.a, givenPlane.b, givenPlane.c };
            double[] outputPointOfApplication = { givenPoint.x, givenPoint.y, givenPoint.z };
            var      outputPlane = new MyPlane(outputNormal, outputPointOfApplication);

            return(outputPlane);
        }
Ejemplo n.º 8
0
        //I create MyLine corresponding to the axis of the cylinder, using two points passing through this line:
        //(the origin of the cylinder) and (the origin of the cylinder + direction vector)

        public static MyLine ConvertPointPlusDirectionInMyLine(double[] appPoint, double[] direction)
        {
            MyVertex firstPoint  = new MyVertex(appPoint[0], appPoint[1], appPoint[2]);
            MyVertex secondPoint = new MyVertex(appPoint[0] + direction[0], appPoint[1] + direction[1], appPoint[2] + direction[2]);

            MyLine outputLine = LinePassingThrough(firstPoint, secondPoint);

            return(outputLine);
        }
Ejemplo n.º 9
0
        private static void SerializeNode(XmlWriter wr, MyVertex vr)
        {
            wr.WriteAttributeString("type", vr.Job.GetType().FullName);

            var serializer = new YAXLib.YAXSerializer(vr.Job.GetType(), YAXSerializationOptions.DontSerializeNullObjects);
            var result     = serializer.Serialize(vr);

            wr.WriteRaw(result);
        }
Ejemplo n.º 10
0
        public void DFS(T start)
        {
            MyVertex <T> my = Find(start);

            if (my != null)
            {
                InitVisited(true);
                DFS(my);
            }
        }
Ejemplo n.º 11
0
        //(THE FOLLOWING FUNCTION IS CREATED FOR COMPOSED PATTERN SEARCH)
        //This function is the analogous of IsReflectionTwoRE, but in this situation the candidate
        //reflectional plane is given as input.
        public static bool IsReflectionTwoREGivenCandidateReflPlane(MyRepeatedEntity firstMyRepeatedEntity,
                                                                    MyRepeatedEntity secondMyRepeatedEntity, MyPlane candidateReflMyPlane)
        {
            //Vertex analysis for Reflection:
            var firstListOfVertices  = firstMyRepeatedEntity.listOfVertices;
            var firstNumOfVerteces   = firstListOfVertices.Count;
            var secondListOfVertices = secondMyRepeatedEntity.listOfVertices;
            var secondNumOfVerteces  = secondListOfVertices.Count;

            if (firstNumOfVerteces == secondNumOfVerteces)
            {
                int i = 0;
                while (i < firstNumOfVerteces)
                {
                    if (secondListOfVertices.FindIndex(
                            vert => vert.IsReflectionOf(firstListOfVertices[i], candidateReflMyPlane)) != -1)
                    {
                        var found =
                            secondListOfVertices.Find(
                                vert => vert.IsReflectionOf(firstListOfVertices[i], candidateReflMyPlane));

                        var scarto =
                            new MyVertex(Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).x - found.x),
                                         Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).y - found.y),
                                         Math.Abs(firstListOfVertices[i].Reflect(candidateReflMyPlane).z - found.z));

                        i++;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            //Check of correct position of normals of all Planar face:
            if (!CheckOfPlanesForReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane))
            {
                return(false);
            }

            ////Check of correct position of cylinder faces:
            if (!CheckOfCylindersForReflection(firstMyRepeatedEntity, secondMyRepeatedEntity, candidateReflMyPlane))
            {
                return(false);
            }

            ////CONTINUARE CON GLI ALTRI TIPI DI SUPERFICI............
            //KLdebug.Print("   ====>>> TRASLAZIONE TRA QUESTE DUE re VERIFICATA!", nameFile);
            return(true);
        }
Ejemplo n.º 12
0
        private void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            var pos      = Mouse.GetPosition(this);
            var menuitem = sender as MenuItem;

            if (menuitem != null)
            {
                var vertex = new MyVertex((menuitem.Tag as Type)?.FullName);
                myArea.AddJob(vertex, pos);
            }
        }
Ejemplo n.º 13
0
        public static double[] ReflectNormal(double[] normal, MyPlane candidateReflMyPlane)
        {
            double[] planeNormal = { candidateReflMyPlane.a, candidateReflMyPlane.b, candidateReflMyPlane.c };
            double[] origin      = { 0, 0, 0 };
            var      planeForReflectionOfNormals = new MyPlane(planeNormal, origin);
            var      normalMyVertex          = new MyVertex(normal[0], normal[1], normal[2]);
            var      reflectedNormalMyVertex = normalMyVertex.Reflect(planeForReflectionOfNormals);

            double[] reflectedNormal = { reflectedNormalMyVertex.x, reflectedNormalMyVertex.y, reflectedNormalMyVertex.z };
            return(reflectedNormal);
        }
Ejemplo n.º 14
0
        public void AddVertex(T item)
        {
            if (Contains(item))
            {
                throw new ArgumentException("添加了重复的顶点!");
            }

            MyVertex <T> newVertex = new MyVertex <T>(item);

            items.Add(newVertex);
        }
Ejemplo n.º 15
0
 private static void Vertex_OnFinished(MyVertex obj)
 {
     _nbVerticesStopped++;
     obj.OnFinished -= Vertex_OnFinished;
     m_launched      = _nbVerticesStopped != _nbVertices;
     if (!m_launched)
     {
         log4net.LogManager.GetLogger("Automation.Core").Info("Graph execution finished");
         OnFinished?.Invoke();
     }
 }
        public static List <MyVertex> translateListOfVertices(List <MyVertex> listOfVerticesToTranslate,
                                                              double[] translationalVector)
        {
            var outputList = new List <MyVertex>();

            foreach (MyVertex vert in listOfVerticesToTranslate)
            {
                var translatedVert = new MyVertex(vert.x + translationalVector[0], vert.y + translationalVector[1], vert.z + translationalVector[2]);
                outputList.Add(translatedVert);
            }
            return(outputList);
        }
        public static MyVertex CreateMidMyVertex(Entity ent)
        {
            var edgeCurve     = (Curve)((Edge)ent).GetCurve();
            var curveParaData = (CurveParamData)((Edge)ent).GetCurveParams3();
            var maxParameter  = curveParaData.UMaxValue;
            var minParameter  = curveParaData.UMinValue;
            var meanParameter = (maxParameter - minParameter) / 2;

            double[] arrayVertexMid = edgeCurve.Evaluate(meanParameter);
            var      midPoint       = new MyVertex((double)arrayVertexMid.GetValue(0),
                                                   (double)arrayVertexMid.GetValue(1), (double)arrayVertexMid.GetValue(2));

            return(midPoint);
        }
Ejemplo n.º 18
0
    public MyTriangle(Vector3[] points)
    {
        // For all the vertices in the triangle(3) create a MyVertex with the triangle(s) it is in
        for (int i = 0; i < Mathf.Min(points.Length, 3); i++)
        {
            MyVertex vertex = new MyVertex(points[i]);
            vertex.AddTriangle(this);
            vertices[i] = vertex;
        }

        for(int i = 0; i < vertices.Length; i++)
        {
            vertices[i].UpdateConnections();
        }
    }
Ejemplo n.º 19
0
 public void DFS(MyVertex <T> startVex)
 {
     startVex.isVisited = true;
     Console.Write(startVex.data.ToString() + ",");
     if (!startVex.nextVex.IsNullOrEmpty())
     {
         foreach (MyVertex <T> item in startVex.nextVex)
         {
             if (!item.isVisited)
             {
                 DFS(item);
             }
         }
     }
 }
Ejemplo n.º 20
0
        private static MyVertex DeserializeNode(XmlReader rd)
        {
            var typestring = rd.GetAttribute("type");
            var type       = NodeFactory.GetType(typestring);
            var serializer = new YAXLib.YAXSerializer(type, YAXSerializationOptions.DontSerializeNullObjects);
            var id         = long.Parse(rd.GetAttribute("id"));
            var job        = serializer.Deserialize(rd.ReadInnerXml()) as INode;
            var vertex     = new MyVertex(job)
            {
                ID = id
            };

            vertices.Add(vertex);

            return(vertex);
        }
        public static bool CorrespondenceOfCirclesInCylinderRot(double teta, double[] axisDirection, double[] translationalVector,
                                                                List <MyCircle> listOfCircleFirst, List <MyCircle> listOfCircleSecond)
        {
            const string nameFile = "GetRotationalPatterns.txt";

            var numOfCircleFirst  = listOfCircleFirst.Count;
            var numOfCircleSecond = listOfCircleSecond.Count;

            // OBSERVATION: int i, j are such that 0<=i,j<=2
            if (numOfCircleFirst > 0)
            {
                int i = 0;
                // for every circle of first cylinder
                while (i < numOfCircleFirst)
                {
                    var firstCenter           = listOfCircleFirst[i].centerCircle;
                    var firstCenterTranslated = new MyVertex(firstCenter.x + translationalVector[0],
                                                             firstCenter.y + translationalVector[1], firstCenter.z + translationalVector[2]);

                    int j = 0;
                    var thisCircleIsOk = false;

                    while (thisCircleIsOk == false && j < numOfCircleSecond)
                    {
                        var secondCenter           = listOfCircleSecond[j].centerCircle;
                        var secondCenterTranslated = new MyVertex(secondCenter.x + translationalVector[0],
                                                                  secondCenter.y + translationalVector[1], secondCenter.z + translationalVector[2]);

                        thisCircleIsOk = secondCenterTranslated.IsRotationOf(firstCenterTranslated, teta, axisDirection);

                        if (thisCircleIsOk)
                        {
                            listOfCircleSecond.RemoveAt(j);
                        }
                        j++;
                    }
                    if (!thisCircleIsOk)
                    {
                        return(false);
                    }
                    numOfCircleSecond = listOfCircleSecond.Count;
                    i++;
                }
            }

            return(true);
        }
        //Restituisce le equazioni cartesiane della circonferenza passante per V1, V2, V3
        public static MyCircumForPath CircumPassingThrough(MyVertex V1, MyVertex V2, MyVertex V3, ref StringBuilder fileOutput, ModelDoc2 SwModel, SldWorks swApplication)
        {
            //The circumference does not exist if the 3 points lie on the same line or if 2 of them are coincident.
            if (V1.Lieonline(LinePassingThrough(V2, V3)) || V1.Equals(V2) || V1.Equals(V3) || V2.Equals(V3))
            {
                MyCircumForPath OutputCircum = new MyCircumForPath();
                return(OutputCircum);
            }
            else
            {
                MyPlane CircumPlane = PlanePassingThrough(V1, V2, V3);

                //There is a unique sphere passing through 4 points: we must arbitrarily choose a fourth point not lying on the V1-V2-V3 plane
                //So we choose the point resulting from adding the normal direction to a point lying on the V1-V2-V3 plane, for example V1

                MyVertex V4 = new MyVertex(V1.x + CircumPlane.a * 10, V1.y + CircumPlane.b * 10, V1.z + CircumPlane.c * 10);
                //Vertex V4 = new Vertex(0, 0, 0);
                //if (SwModel != null)
                //{
                //    SwModel = swApplication.ActiveDoc;
                //    SwModel.ClearSelection2(true);
                //    SwModel.Insert3DSketch();
                //    SwModel.CreatePoint2(V1.x, V1.y, V1.z);
                //    SwModel.InsertSketch();
                //    SwModel.CreatePoint2(V2.x, V2.y, V2.z);
                //    SwModel.InsertSketch();
                //    SwModel.CreatePoint2(V3.x, V3.y, V3.z);
                //    SwModel.InsertSketch();
                //    SwModel.CreatePoint2(V4.x, V4.y, V4.z);
                //    SwModel.InsertSketch();
                //}

                MySphere CircumSphere = SpherePassingThrough(V1, V2, V3, V4, ref fileOutput, SwModel);

                if (CircumSphere.centerSphere == null)
                {
                }
                else if (CircumSphere.centerSphere != null)
                {
                    MyCircumForPath OutputCircum = new MyCircumForPath(CircumPlane, CircumSphere);
                    return(OutputCircum);
                }
            }
            MyCircumForPath OutputCircumNull = new MyCircumForPath();

            return(OutputCircumNull);
        }
Ejemplo n.º 23
0
        public static MyPlane GetCandidateReflectionalMyPlane(MyVertex firstReferencePoint,
                                                              MyVertex secondReferencePoint, SldWorks swapplication)
        {
            //const string nameFile = "GetReflectionalPattern.txt";
            //KLdebug.Print(" ", nameFile);
            //var whatToWrite = "";

            double[] candidateReflectionalNormal =
            {
                secondReferencePoint.x - firstReferencePoint.x,
                secondReferencePoint.y - firstReferencePoint.y,
                secondReferencePoint.z - firstReferencePoint.z,
            };
            //whatToWrite = string.Format("Candidate reflectional normal: ({0}, {1}, {2})", candidateReflectionalNormal[0],
            //    candidateReflectionalNormal[1], candidateReflectionalNormal[2]);
            //KLdebug.Print(whatToWrite, nameFile);

            double[] candidateReflectionalAppPoint =
            {
                (firstReferencePoint.x + secondReferencePoint.x) / 2,
                (firstReferencePoint.y + secondReferencePoint.y) / 2,
                (firstReferencePoint.z + secondReferencePoint.z) / 2
            };
            //whatToWrite = string.Format("Candidate reflectional App Point: ({0}, {1}, {2})", candidateReflectionalAppPoint[0],
            //    candidateReflectionalAppPoint[1], candidateReflectionalAppPoint[2]);
            //KLdebug.Print(whatToWrite, nameFile);

            //if (swapplication != null)
            //{
            //    var SwModel = swapplication.ActiveDoc;
            //    SwModel.ClearSelection2(true);
            //    SwModel.Insert3DSketch();
            //    SwModel.CreatePoint2(candidateReflectionalAppPoint[0], candidateReflectionalAppPoint[1],
            //        candidateReflectionalAppPoint[2]);
            //    SwModel.InsertSketch();
            //}

            var candidateReflMyPlane = new MyPlane(candidateReflectionalNormal, candidateReflectionalAppPoint);

            //whatToWrite = string.Format("Candidate reflectional MyPlane: {0}x +{1}y +{2}z + {3} = 0", candidateReflMyPlane.a,
            //    candidateReflMyPlane.b, candidateReflMyPlane.c, candidateReflMyPlane.d);
            //KLdebug.Print(whatToWrite, nameFile);

            //KLdebug.Print(" ", nameFile);
            return(candidateReflMyPlane);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// entry point for the application.
        /// </summary>
        public void Test(string outputImageFolder)
        {
            AdjacencyGraph g = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);

            MyVertex[] v = new MyVertex[12];
            for (int i = 0; i < 12; i++)
            {
                v[i]       = (MyVertex)g.AddVertex();
                v[i].Name  = "Vertex " + i;
                v[i].Value = i;
            }
            g.AddEdge(v[0], v[1]);
            g.AddEdge(v[1], v[2]);
            g.AddEdge(v[2], v[3]);
            g.AddEdge(v[3], v[0]);
            g.AddEdge(v[2], v[0]);
            g.AddEdge(v[4], v[5]);
            g.AddEdge(v[5], v[6]);
            g.AddEdge(v[6], v[7]);
            g.AddEdge(v[7], v[4]);
            g.AddEdge(v[2], v[5]);
            g.AddEdge(v[8], v[9]);
            g.AddEdge(v[9], v[8]);
            g.AddEdge(v[10], v[11]);
            g.AddEdge(v[11], v[10]);
            g.AddEdge(v[2], v[9]);
            g.AddEdge(v[9], v[10]);

            GraphvizAlgorithm renderer = new GraphvizAlgorithm(g, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);

            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("Original_Graph.jpeg");

            CondensationGraphAlgorithm cgalgo = new CondensationGraphAlgorithm(g);

            cgalgo.InitCondensationGraphVertex += new CondensationGraphVertexEventHandler(CGVertexHandler);

            AdjacencyGraph cg = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);

            cgalgo.Create(cg);

            //	Render the Condensation Graph
            renderer = new GraphvizAlgorithm(cg, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("CG.jpeg");
        }
Ejemplo n.º 25
0
        //This function returns the centroid of a set of given MyVertex
        public static MyVertex computeCentroidsOfVertices(List <MyVertex> listPointVertex)
        {
            double sumOfx        = 0;
            double sumOfy        = 0;
            double sumOfz        = 0;
            int    numOfVerteces = listPointVertex.Count;

            foreach (MyVertex vertex in listPointVertex)
            {
                sumOfx += vertex.x;
                sumOfy += vertex.y;
                sumOfz += vertex.z;
            }
            MyVertex centroid = new MyVertex(sumOfx / numOfVerteces, sumOfy / numOfVerteces, sumOfz / numOfVerteces);

            return(centroid);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 添加一条有向边
        /// </summary>
        /// <param name="from">头结点data</param>
        /// <param name="to">尾节点data</param>
        public void AddDirectedEdge(T from, T to)
        {
            MyVertex <T> fromVertex = Find(from);

            if (fromVertex == null)
            {
                throw new ArgumentException("头顶点不存在!");
            }

            MyVertex <T> toVertex = Find(to);

            if (toVertex == null)
            {
                throw new ArgumentException("尾顶点不存在!");
            }

            AddDirectedEdge(fromVertex, toVertex);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Entry point for the application.
        /// </summary>
        public static void Test(string outputImageFolder)
        {
            AdjacencyGraph g = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);

            MyVertex[] v = new MyVertex[12];
            for (int i = 0; i < 12; i++)
            {
                v[i]       = (MyVertex)g.AddVertex();
                v[i].Name  = "Vertex " + i;
                v[i].Value = i;
            }
            g.AddEdge(v[0], v[1]);
            g.AddEdge(v[1], v[2]);
            g.AddEdge(v[2], v[3]);
            g.AddEdge(v[3], v[0]);
            g.AddEdge(v[2], v[0]);
            g.AddEdge(v[4], v[5]);
            g.AddEdge(v[5], v[6]);
            g.AddEdge(v[6], v[7]);
            g.AddEdge(v[7], v[4]);
            g.AddEdge(v[2], v[5]);
            g.AddEdge(v[8], v[9]);
            g.AddEdge(v[9], v[8]);
            g.AddEdge(v[10], v[11]);
            g.AddEdge(v[11], v[10]);
            g.AddEdge(v[2], v[9]);
            g.AddEdge(v[9], v[10]);

            GraphvizAlgorithm renderer = new GraphvizAlgorithm(g, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);

            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("Original_Graph.jpeg");

            TransitiveClosureAlgorithm tcalgo = new TransitiveClosureAlgorithm(g);
            AdjacencyGraph             tc     = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);

            tcalgo.InitTransitiveClosureVertex += new TransitiveClosureVertexEventHandler(MapTCVertex);
            tcalgo.ExamineEdge += new EdgeEventHandler(InitEdge);
            tcalgo.Create(tc);

            renderer = new GraphvizAlgorithm(tc, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("TC.jpeg");
        }
        /// <summary>
        /// entry point for the application.
        /// </summary>		
        public void Test(string outputImageFolder)
        {
            AdjacencyGraph g = new AdjacencyGraph( new MyVertexProvider(), new EdgeProvider(), true);

            MyVertex[] v = new MyVertex[12];
            for( int i=0; i<12;i++)	{
                v[i] = (MyVertex) g.AddVertex();
                v[i].Name = "Vertex " + i;
                v[i].Value = i;
            }
            g.AddEdge(v[0], v[1]);
            g.AddEdge(v[1], v[2]);
            g.AddEdge(v[2], v[3]);
            g.AddEdge(v[3], v[0]);
            g.AddEdge(v[2], v[0]);
            g.AddEdge(v[4], v[5]);
            g.AddEdge(v[5], v[6]);
            g.AddEdge(v[6], v[7]);
            g.AddEdge(v[7], v[4]);
            g.AddEdge(v[2], v[5]);
            g.AddEdge(v[8], v[9]);
            g.AddEdge(v[9], v[8]);
            g.AddEdge(v[10], v[11]);
            g.AddEdge(v[11], v[10]);
            g.AddEdge(v[2], v[9]);
            g.AddEdge(v[9], v[10]);

            GraphvizAlgorithm renderer = new GraphvizAlgorithm(g,outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("Original_Graph.jpeg");

            CondensationGraphAlgorithm cgalgo = new CondensationGraphAlgorithm( g );
            cgalgo.InitCondensationGraphVertex += new CondensationGraphVertexEventHandler(CGVertexHandler);

            AdjacencyGraph cg = new AdjacencyGraph( new MyVertexProvider(), new EdgeProvider(), true);
            cgalgo.Create(cg);

            //	Render the Condensation Graph
            renderer = new GraphvizAlgorithm(cg, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("CG.jpeg");
        }
Ejemplo n.º 29
0
        private void addEdgesRecursive(MyVertex parent, Queue <MyVertex> verts, List <MyEdge> outEdges, int maxDepth)
        {
            if (maxDepth == 0)
            {
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                if (verts.Count == 0)
                {
                    return;
                }
                var c = verts.Dequeue();
                outEdges.Add(new MyEdge {
                    Source = parent, Target = c
                });
                addEdgesRecursive(c, verts, outEdges, maxDepth - 1);
            }
        }
Ejemplo n.º 30
0
        public static void PropagateNodeProperty(this MyGraph graph, MyVertex node)
        {
            propagateInProgress++;
            foreach (var edge in graph.OutEdges(node))
            {
                var source = node.Job;
                var target = edge.Target.Job;
                foreach (var property in source.GetType().GetProperties())
                {
                    var readOnlyAttr = (ReadOnlyAttribute)Attribute.GetCustomAttribute(property, typeof(ReadOnlyAttribute));
                    if (readOnlyAttr != null && readOnlyAttr.IsReadOnly)
                    {
                        continue;
                    }

                    if (property.GetValue(source) == null)
                    {
                        continue;
                    }
                    try
                    {
                        var targetproperty = target.GetType().GetProperty(property.Name);
                        //if (targetproperty.GetValue(target) == null)
                        {
                            targetproperty.SetValue(target, property.GetValue(source));
                            target.RaisePropertyChanged(targetproperty.Name);
                        }
                    }
                    catch
                    {
                    }
                }

                graph.PropagateNodeProperty(edge.Target);
            }
            propagateInProgress--;
            if (propagateInProgress == 0)
            {
                MessageBox.Show("Propagate Finished");
            }
        }
        /// <summary>
        /// Entry point for the application.
        /// </summary>		
        public static void Test(string outputImageFolder)
        {
            AdjacencyGraph g = new AdjacencyGraph( new MyVertexProvider(), new EdgeProvider(), true);

            MyVertex[] v = new MyVertex[12];
            for( int i=0; i<12;i++)	{
                v[i] = (MyVertex) g.AddVertex();
                v[i].Name = "Vertex " + i;
                v[i].Value = i;
            }
            g.AddEdge(v[0], v[1]);
            g.AddEdge(v[1], v[2]);
            g.AddEdge(v[2], v[3]);
            g.AddEdge(v[3], v[0]);
            g.AddEdge(v[2], v[0]);
            g.AddEdge(v[4], v[5]);
            g.AddEdge(v[5], v[6]);
            g.AddEdge(v[6], v[7]);
            g.AddEdge(v[7], v[4]);
            g.AddEdge(v[2], v[5]);
            g.AddEdge(v[8], v[9]);
            g.AddEdge(v[9], v[8]);
            g.AddEdge(v[10], v[11]);
            g.AddEdge(v[11], v[10]);
            g.AddEdge(v[2], v[9]);
            g.AddEdge(v[9], v[10]);

            GraphvizAlgorithm renderer = new GraphvizAlgorithm(g,outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("Original_Graph.jpeg");

            TransitiveClosureAlgorithm tcalgo = new TransitiveClosureAlgorithm(g);
            AdjacencyGraph tc = new AdjacencyGraph(new MyVertexProvider(), new EdgeProvider(), true);
            tcalgo.InitTransitiveClosureVertex += new TransitiveClosureVertexEventHandler(MapTCVertex);
            tcalgo.ExamineEdge += new EdgeEventHandler(InitEdge);
            tcalgo.Create(tc);

            renderer = new GraphvizAlgorithm(tc, outputImageFolder, NGraphviz.Helpers.GraphvizImageType.Jpeg);
            renderer.FormatVertex += new FormatVertexEventHandler(FormatGraph);
            renderer.Write("TC.jpeg");
        }
Ejemplo n.º 32
0
        //It returns the array correspondig to a point resulting from the intersection of a given MyPlane a given MyLine
        public static MyVertex PointIntersectionOfPlaneAndLine(MyPlane plane, MyLine line)
        {
            //... missing a check: not valid if the line lies on the plane!!!

            double[,] coefficientsMatrix =
            {
                { plane.a,       plane.b,       plane.c       },
                { line.plane1.a, line.plane1.b, line.plane1.c },
                { line.plane2.a, line.plane2.b, line.plane2.c }
            };


            double[,] knownTerms = { { -plane.d }, { -line.plane1.d }, { -line.plane2.d } };

            double[,] outputPointColumn = Matrix.Solve(coefficientsMatrix, knownTerms, leastSquares: true);

            //I transform it in MyVertex:
            MyVertex outputPoint = new MyVertex(outputPointColumn[0, 0], outputPointColumn[1, 0], outputPointColumn[2, 0]);

            return(outputPoint);
        }