示例#1
0
        public void EdgeConnectionTest5()
        {
            var ec = new EdgeConnection(
                Releases.Motions.Define(xNeg: 123.4),
                Releases.Rotations.RigidLine(),
                "My library connection"
                );

            Slab slab = CreateDummySlab();

            slab = Slab.EdgeConnection(slab, ec, 0);

            var model = new Model(Country.S, new List <GenericClasses.IStructureElement> {
                slab
            });

            string output = "Shells/EdgeConnection_Out.struxml";

            model.SerializeModel(output);

            var deserialized = Model.DeserializeFromFilePath(output);

            Assert.IsTrue(deserialized.Entities.Slabs.Count == 1);
            var actualEdgeConnections = deserialized.Entities.Slabs.First().SlabPart.GetEdgeConnections();

            Assert.IsTrue(actualEdgeConnections.Where(e => e != null).Count() == 1);
            var first = actualEdgeConnections.First();

            Assert.IsTrue(first.IsLibraryItem);
            Assert.IsFalse(first.IsCustomItem);
            Assert.AreEqual("My library connection", first.LibraryName);
            Assert.IsNull(first.Rigidity);
            Assert.IsNotNull(first.PredefRigidity);
            Assert.AreEqual(123.4, first.PredefRigidity.Rigidity.Motions.XNeg, delta: 1e-6);
        }
示例#2
0
        private static Slab CreateDummySlab()
        {
            string input    = "Shells/EdgeConnection-model.struxml";
            var    template = Model.DeserializeFromFilePath(input);

            var p1 = new Geometry.FdPoint3d(0, 0, 0);
            var p2 = new Geometry.FdPoint3d(1, 0, 0);
            var p3 = new Geometry.FdPoint3d(1, 1, 0);
            var p4 = new Geometry.FdPoint3d(0, 1, 0);

            var edges = new List <Geometry.Edge> {
                new Geometry.Edge(p1, p2, Geometry.FdCoordinateSystem.Global()),
                new Geometry.Edge(p2, p3, Geometry.FdCoordinateSystem.Global()),
                new Geometry.Edge(p3, p4, Geometry.FdCoordinateSystem.Global()),
                new Geometry.Edge(p4, p1, Geometry.FdCoordinateSystem.Global())
            };
            var contour = new Geometry.Contour(edges);
            var region  = new Geometry.Region(new List <Geometry.Contour> {
                contour
            }, Geometry.FdCoordinateSystem.Global());
            var slab = Slab.Plate("S", template.Materials.Material[0], region, EdgeConnection.GetDefault(), ShellEccentricity.GetDefault(), ShellOrthotropy.GetDefault(), new List <Thickness> {
                new Thickness(Geometry.FdPoint3d.Origin(), 0.2)
            });

            return(slab);
        }
示例#3
0
        public void EdgeConnectionTest2()
        {
            var ec = new EdgeConnection(Releases.Motions.RigidLine(), Releases.Rotations.RigidLine(), "My lib item");

            Assert.IsNotNull(ec);
            Assert.IsNotNull(ec.PredefRigidity);
            Assert.IsNull(ec.Rigidity);
        }
示例#4
0
        public override void AddEdgeConnection(EdgeConnection con)
        {
            var edge     = Mesh.Edges[con.Edge];
            var previous = (con.Previous != -1) ? Mesh.Edges[con.Previous] : null;
            var next     = (con.Next != -1) ? Mesh.Edges[con.Next] : null;

            edge.Previous = previous;
            edge.Next     = next;
        }
        /// <summary>
        /// Adapted https://github.com/MicrosoftEdge/MicrosoftEdge-Extensions-Demos/blob/master/SecureInput/NativeMessagingHostInProcess/App.xaml.cs
        /// </summary>
        /// <param name="args"></param>
        protected async override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);
            IBackgroundTaskInstance taskInstance = args.TaskInstance;

            if (taskInstance.TriggerDetails is AppServiceTriggerDetails)
            {
                AppServiceTriggerDetails appService = taskInstance.TriggerDetails as AppServiceTriggerDetails;
                this.connection = new EdgeConnection(taskInstance.GetDeferral(), appService);
            }
        }
示例#6
0
        // Init method
        internal void Init()
        {
            // Create our edge connection
            StanOptions opts = StanOptions.GetDefaultOptions();

            opts.NatsURL = "192.168.0.8:4222";
            edge         = new EdgeConnection("test-cluster", "rfid", opts);
            // Open the connection
            edge.Open();
            // Register an observed route manager to automatically handle remote observers with constraints
            var resourceMgr = edge.RegisterObservedResourceManager("events", new RequestConstraints(RFIDDataType, "proto3"));

            // Setup a handler for receiving new resource observer events
            resourceMgr.OnResourceObserverCreated += ObserverCreated;
            // Setup a handler for receiving observer removed events
            resourceMgr.OnResourceObserverRemoved += ObserverRemoved;
        }
示例#7
0
        private static void CreateLine <MESH>(IMeshConstructor <MESH> constructor, MeshDescriptor des)
        {
            constructor.PushEdgeMesh(des.Vertices, des.Edges);

            for (int i = 0; i < des.Vertices; i++)
            {
                Vector2f v = CGAL_GetSkeletonPoint(i);
                constructor.AddVertex(v);
            }

            for (int i = 0; i < des.Edges; i++)
            {
                EdgeIndex edge = CGAL_GetSkeletonEdge(i);
                constructor.AddEdge(edge);
            }

            int numConnections = CGAL_NumEdgeConnection();

            for (int i = 0; i < numConnections; i++)
            {
                EdgeConnection con = CGAL_GetEdgeConnection(i);
                constructor.AddEdgeConnection(con);
            }
        }
	// todo - there's a lot of duplicate code between this and poke face.
	/**
	 *	Inserts a vertex at the center of each edge, then connects the new vertices to another new
	 *	vertex placed at the center of the face.
	 */
	// internal method - so it's allow to be messy, right?
	private static bool SubdivideFace_Internal(pb_Object pb, EdgeConnection edgeConnection, 
		out Vector3?[] appendedVertices,	
		out pb_Face[] splitFaces,
		out Vector3[][] splitVertices,
		out int[][] splitSharedIndices)
	{
		splitFaces = null;
		splitVertices = null;
		splitSharedIndices = null;
		appendedVertices = new Vector3?[edgeConnection.edges.Count];

		// cache all the things
		pb_Face face = edgeConnection.face;
		pb_IntArray[] sharedIndices = pb.sharedIndices;
		Vector3[] vertices = pb.vertices;

		List<Vector3> edgeCenters3d = new List<Vector3>();//pb.GetVertices(edgeConnection.face));
		
		// filter duplicate edges
		int u = 0;
		List<int> usedEdgeIndices = new List<int>();
		foreach(pb_Edge edge in edgeConnection.edges)
		{
			int ind = face.edges.IndexOf(edge, sharedIndices);
			if(!usedEdgeIndices.Contains(ind))
			{
				Vector3 cen = (vertices[edge.x] + vertices[edge.y]) / 2f;
				edgeCenters3d.Add(cen);
				usedEdgeIndices.Add(ind);
				appendedVertices[u] = cen;
			}
			else
				appendedVertices[u] = null;

			u++;
		}

		// now we have all the vertices of the old face, plus the new edge center vertices

		Vector3[] verts3d = pb.GetVertices(face.distinctIndices);
		Vector3 nrm = pb_Math.Normal(pb.GetVertices(face.indices));

		Vector2[] verts2d = pb_Math.VerticesTo2DPoints(verts3d, nrm);
		Vector2[] edgeCenters2d = pb_Math.VerticesTo2DPoints(edgeCenters3d.ToArray(), nrm);
		
		Vector3 cen3d = pb_Math.Average(verts3d);
		Vector2 cen2d = pb_Math.VerticesTo2DPoints( new Vector3[1] { cen3d }, nrm)[0];

		// Get the directions from which to segment this face
		Vector2[] dividers = new Vector2[edgeCenters2d.Length];
		for(int i = 0; i < edgeCenters2d.Length; i++)
			dividers[i] = (edgeCenters2d[i] - cen2d).normalized;

		List<Vector2>[] quadrants2d = new List<Vector2>[edgeCenters2d.Length];
		List<Vector3>[] quadrants3d = new List<Vector3>[edgeCenters2d.Length];
		List<int>[]		sharedIndex = new List<int>[edgeCenters2d.Length];

		for(int i = 0; i < quadrants2d.Length; i++)
		{
			quadrants2d[i] = new List<Vector2>(1) { cen2d };
			quadrants3d[i] = new List<Vector3>(1) { cen3d };
			sharedIndex[i] = new List<int>(1) { -2 };		// any negative value less than -1 will be treated as a new group
		}

		// add the divisors
		for(int i = 0; i < edgeCenters2d.Length; i++)
		{
			quadrants2d[i].Add(edgeCenters2d[i]);
			quadrants3d[i].Add(edgeCenters3d[i]);
			sharedIndex[i].Add(-1);	// -(i+2) to group new vertices in AppendFace

			// and add closest in the counterclockwise direction
			Vector2 dir = (edgeCenters2d[i]-cen2d).normalized;
			float largestClockwiseDistance = 0f;
			int quad = -1;
			for(int j = 0; j < dividers.Length; j++)
			{
				if(j == i) continue;	// this is a dividing vertex - ignore

				float dist = Vector2.Angle(dividers[j], dir);
				if( Vector2.Dot(pb_Math.Perpendicular(dividers[j]), dir) < 0f )
					dist = 360f - dist;

				if(dist > largestClockwiseDistance)
				{
					largestClockwiseDistance = dist;
					quad = j;
				}
			}

			quadrants2d[quad].Add(edgeCenters2d[i]);
			quadrants3d[quad].Add(edgeCenters3d[i]);
			sharedIndex[quad].Add(-1);
		}

		// distribute the existing vertices
		for(int i = 0; i < face.distinctIndices.Length; i++)
		{
			Vector2 dir = (verts2d[i]-cen2d).normalized;	// plane corresponds to distinctIndices
			float largestClockwiseDistance = 0f;
			int quad = -1;
			for(int j = 0; j < dividers.Length; j++)
			{
				float dist = Vector2.Angle(dividers[j], dir);
				if( Vector2.Dot(pb_Math.Perpendicular(dividers[j]), dir) < 0f )
					dist = 360f - dist;

				if(dist > largestClockwiseDistance)
				{
					largestClockwiseDistance = dist;
					quad = j;
				}
			}

			quadrants2d[quad].Add(verts2d[i]);
			quadrants3d[quad].Add(verts3d[i]);
			sharedIndex[quad].Add(pb.sharedIndices.IndexOf(face.distinctIndices[i]));
		}

		int len = quadrants2d.Length;

		// Triangulate
		int[][] tris = new int[len][];
		for(int i = 0; i < len; i++)
		{
			if(quadrants2d[i].Count < 3)
			{
				Debug.LogError("Insufficient points to triangulate - bailing on subdivide operation.  This is probably due to a concave face, or maybe the compiler just doesn't like you today.  50/50 odds really.");
				return false;
			}
		
			tris[i] = Delauney.Triangulate(quadrants2d[i]).ToIntArray();
			
			Vector3[] nrm_check = new Vector3[3]
			{
				quadrants3d[i][tris[i][0]],
				quadrants3d[i][tris[i][1]],
				quadrants3d[i][tris[i][2]]
			};

			if( Vector3.Dot(nrm, pb_Math.Normal(nrm_check)) < 0 )
				System.Array.Reverse(tris[i]);
		}

		splitFaces 		= new pb_Face[len];
		splitVertices 	= new Vector3[len][];
		splitSharedIndices 	= new int[len][];

		for(int i = 0; i < len; i++)
		{
			// triangles, material, pb_UV, smoothing group, shared index
			splitFaces[i] = new pb_Face(tris[i], face.material, new pb_UV(face.uv), face.smoothingGroup, face.textureGroup, face.elementGroup, face.color);
			splitVertices[i] = quadrants3d[i].ToArray();
			splitSharedIndices[i] = sharedIndex[i].ToArray();
		}

		return true;
	}
示例#9
0
 public virtual void AddEdgeConnection(EdgeConnection connection)
 {
 }
示例#10
0
        private void FindLongestPath()
        {
            //Dugum baglanti listesi alinir.
            List <GraphConnection> graphConnections = new List <GraphConnection>();

            foreach (var item in graphPoints)
            {
                foreach (var itemConnection in item.Connections)
                {
                    itemConnection.PrevGraphPointId = item.Id;
                    graphConnections.Add(itemConnection);
                }
            }

            nodeConnections = new NodeConnection[graphPoints.Count];
            graphEdges      = new EdgeConnection[graphConnections.Count]; //Graf kenarlari listesi

            for (int j = 0; j < graphPoints.Count; j++)
            {
                nodeConnections[j] = new NodeConnection(j);
            }
            int i = 0;

            foreach (var item in graphConnections)
            {
                EdgeConnection edgeConnection = new EdgeConnection(i);
                edgeConnection.BeginConnectionId = item.PrevGraphPointId;
                edgeConnection.EndConnectionId   = item.NextGraphPointId;
                edgeConnection.Cost     = item.Cost;
                edgeConnection.PrevFlow = 0;
                graphEdges[i]           = edgeConnection;

                nodeConnections[edgeConnection.BeginConnectionId].GraphNextNodes.Add(i);
                nodeConnections[edgeConnection.EndConnectionId].GraphPrevNodes.Add(i);
                i++;
            }

            graphVisits        = new int[nodeConnections.Length];
            graphCurrentVisits = new int[nodeConnections.Length];
            graphLongestPath   = new int[nodeConnections.Length];

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

            bool hasLongestPath = false;

            graphEndConnection   = comboBoxEnd.SelectedIndex;
            graphLongestCapacity = int.MinValue;
            graphMinimumCapacity = 1;
            GetLongestPathWithBacktrack(comboBoxBegin.SelectedIndex);
            if (graphLongestCapacity == int.MinValue)
            {
                hasLongestPath = false;
            }
            else
            {
                hasLongestPath = true;
            }

            if (hasLongestPath)
            {
                String output = "A" + graphLongestPath[0];
                pathLongest.Add(graphLongestPath[0]);
                for (int j = 1; j < graphCurrentTotalCost; j++)
                {
                    pathLongest.Add(graphLongestPath[j]);
                    output = output + " -> A" + graphLongestPath[j];
                }
                output     += "                  Max Flow : " + graphLongestCapacity;
                label4.Text = "Yol : " + output;
            }
            else
            {
                MessageBox.Show("A0 noktasindan A" + (graphPoints.Count - 1) + " noktasina yol bulunamadi.");
            }
            //En uzun yol bulundu ise gidilen yollar cizim alani bolgesinde gosterilir.
            if (pathLongest.Count > 0)
            {
                for (int k = 0; k < pathLongest.Count; k++)
                {
                    if (k + 1 < pathLongest.Count)
                    {
                        Pen   pen2   = new Pen(Color.Green, 3);
                        Brush brush2 = new SolidBrush(Color.Green);
                        graphic.FillRectangle(brush2, graphPoints[pathLongest[k]].PointX - 6, graphPoints[pathLongest[k]].PointY - 6, 12, 12);                                                          //Yol baslangic dugumune kare eklenir.
                        graphic.FillRectangle(brush2, graphPoints[pathLongest[k + 1]].PointX - 6, graphPoints[pathLongest[k + 1]].PointY - 6, 12, 12);                                                  //Yol bitis dugumune kare eklenir.
                        graphic.DrawLine(pen2, graphPoints[pathLongest[k]].PointX, graphPoints[pathLongest[k]].PointY, graphPoints[pathLongest[k + 1]].PointX, graphPoints[pathLongest[k + 1]].PointY); //Iki dugum arasinda yol cizilir
                        brush2.Dispose();                                                                                                                                                               //brush2 degiskeni bellekten silinir.
                        pen2.Dispose();                                                                                                                                                                 //pen2 degiskeni bellekten silinir.
                    }
                }
            }
        }
示例#11
0
        // todo - there's a lot of duplicate code between this and poke face.

        /**
         *	Inserts a vertex at the center of each edge, then connects the new vertices to another new
         *	vertex placed at the center of the face.
         */
        // internal method - so it's allow to be messy, right?
        private static bool SubdivideFace_Internal(pb_Object pb, EdgeConnection edgeConnection,
                                                   out Vector3?[] appendedVertices,
                                                   out pb_Face[] splitFaces,
                                                   out Vector3[][] splitVertices,
                                                   out int[][] splitSharedIndices)
        {
            splitFaces         = null;
            splitVertices      = null;
            splitSharedIndices = null;
            appendedVertices   = new Vector3?[edgeConnection.edges.Count];

            // cache all the things
            pb_Face face = edgeConnection.face;

            pb_IntArray[] sharedIndices = pb.sharedIndices;
            Vector3[]     vertices      = pb.vertices;

            List <Vector3> edgeCenters3d = new List <Vector3>();  //pb.GetVertices(edgeConnection.face));

            // filter duplicate edges
            int        u = 0;
            List <int> usedEdgeIndices = new List <int>();

            foreach (pb_Edge edge in edgeConnection.edges)
            {
                int ind = face.edges.IndexOf(edge, sharedIndices);
                if (!usedEdgeIndices.Contains(ind))
                {
                    Vector3 cen = (vertices[edge.x] + vertices[edge.y]) / 2f;
                    edgeCenters3d.Add(cen);
                    usedEdgeIndices.Add(ind);
                    appendedVertices[u] = cen;
                }
                else
                {
                    appendedVertices[u] = null;
                }

                u++;
            }

            // now we have all the vertices of the old face, plus the new edge center vertices

            Vector3[] verts3d = pb.GetVertices(face.distinctIndices);
            Vector3   nrm     = pb_Math.Normal(pb.GetVertices(face.indices));

            Vector2[] verts2d       = pb_Math.VerticesTo2DPoints(verts3d, nrm);
            Vector2[] edgeCenters2d = pb_Math.VerticesTo2DPoints(edgeCenters3d.ToArray(), nrm);

            Vector3 cen3d = pb_Math.Average(verts3d);
            Vector2 cen2d = pb_Math.VerticesTo2DPoints(new Vector3[1] {
                cen3d
            }, nrm)[0];

            // Get the directions from which to segment this face
            Vector2[] dividers = new Vector2[edgeCenters2d.Length];
            for (int i = 0; i < edgeCenters2d.Length; i++)
            {
                dividers[i] = (edgeCenters2d[i] - cen2d).normalized;
            }

            List <Vector2>[] quadrants2d = new List <Vector2> [edgeCenters2d.Length];
            List <Vector3>[] quadrants3d = new List <Vector3> [edgeCenters2d.Length];
            List <int>[]     sharedIndex = new List <int> [edgeCenters2d.Length];

            for (int i = 0; i < quadrants2d.Length; i++)
            {
                quadrants2d[i] = new List <Vector2>(1)
                {
                    cen2d
                };
                quadrants3d[i] = new List <Vector3>(1)
                {
                    cen3d
                };
                sharedIndex[i] = new List <int>(1)
                {
                    -2
                };                                                              // any negative value less than -1 will be treated as a new group
            }

            // add the divisors
            for (int i = 0; i < edgeCenters2d.Length; i++)
            {
                quadrants2d[i].Add(edgeCenters2d[i]);
                quadrants3d[i].Add(edgeCenters3d[i]);
                sharedIndex[i].Add(-1);         // -(i+2) to group new vertices in AppendFace

                // and add closest in the counterclockwise direction
                Vector2 dir = (edgeCenters2d[i] - cen2d).normalized;
                float   largestClockwiseDistance = 0f;
                int     quad = -1;
                for (int j = 0; j < dividers.Length; j++)
                {
                    if (j == i)
                    {
                        continue;                       // this is a dividing vertex - ignore
                    }
                    float dist = Vector2.Angle(dividers[j], dir);
                    if (Vector2.Dot(pb_Math.Perpendicular(dividers[j]), dir) < 0f)
                    {
                        dist = 360f - dist;
                    }

                    if (dist > largestClockwiseDistance)
                    {
                        largestClockwiseDistance = dist;
                        quad = j;
                    }
                }

                quadrants2d[quad].Add(edgeCenters2d[i]);
                quadrants3d[quad].Add(edgeCenters3d[i]);
                sharedIndex[quad].Add(-1);
            }

            // distribute the existing vertices
            for (int i = 0; i < face.distinctIndices.Length; i++)
            {
                Vector2 dir = (verts2d[i] - cen2d).normalized;          // plane corresponds to distinctIndices
                float   largestClockwiseDistance = 0f;
                int     quad = -1;
                for (int j = 0; j < dividers.Length; j++)
                {
                    float dist = Vector2.Angle(dividers[j], dir);
                    if (Vector2.Dot(pb_Math.Perpendicular(dividers[j]), dir) < 0f)
                    {
                        dist = 360f - dist;
                    }

                    if (dist > largestClockwiseDistance)
                    {
                        largestClockwiseDistance = dist;
                        quad = j;
                    }
                }

                quadrants2d[quad].Add(verts2d[i]);
                quadrants3d[quad].Add(verts3d[i]);
                sharedIndex[quad].Add(pb.sharedIndices.IndexOf(face.distinctIndices[i]));
            }

            int len = quadrants2d.Length;

            // Triangulate
            int[][] tris = new int[len][];
            for (int i = 0; i < len; i++)
            {
                if (quadrants2d[i].Count < 3)
                {
                    Debug.LogError("Insufficient points to triangulate - bailing on subdivide operation.  This is probably due to a concave face, or maybe the compiler just doesn't like you today.  50/50 odds really.");
                    return(false);
                }

                tris[i] = Delauney.Triangulate(quadrants2d[i]).ToIntArray();

                Vector3[] nrm_check = new Vector3[3]
                {
                    quadrants3d[i][tris[i][0]],
                    quadrants3d[i][tris[i][1]],
                    quadrants3d[i][tris[i][2]]
                };

                if (Vector3.Dot(nrm, pb_Math.Normal(nrm_check)) < 0)
                {
                    System.Array.Reverse(tris[i]);
                }
            }

            splitFaces         = new pb_Face[len];
            splitVertices      = new Vector3[len][];
            splitSharedIndices = new int[len][];

            for (int i = 0; i < len; i++)
            {
                // triangles, material, pb_UV, smoothing group, shared index
                splitFaces[i]         = new pb_Face(tris[i], face.material, new pb_UV(face.uv), face.smoothingGroup, face.textureGroup, face.elementGroup, face.color);
                splitVertices[i]      = quadrants3d[i].ToArray();
                splitSharedIndices[i] = sharedIndex[i].ToArray();
            }

            return(true);
        }