static void Main(string[] args) { // Execute all the classes containing type exploration code CollectionInterfaces.Execute(); Arrays.Execute(); DataStructures.Execute(); }
/// <summary> /// Writes a map to a stream in MAP format. /// </summary> /// <param name="stream">The stream to write to</param> /// <param name="map">The map to save</param> protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map) { using (var writer = new StreamWriter(stream)) { WriteWorld(writer, map.WorldSpawn); } }
public void ApplyAffliction (DataStructures.Affliction affliction) { // Name matching is ugly, consider switching to id this.affliction = affliction; if (affliction.name == "Frozen") { gameObject.GetComponent<Renderer> ().material.color = Color.blue; GameObject newFrozen = (GameObject)(Instantiate (frozenPrefab, new Vector3 (gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z), gameObject.transform.rotation)); newFrozen.transform.parent = gameObject.transform; } else if (affliction.name == "Possessed") { gameObject.GetComponent<Renderer> ().material.color = Color.magenta; GameObject newPossessed = (GameObject)(Instantiate (possessedPrefab, new Vector3 (gameObject.transform.position.x + 0.68f, gameObject.transform.position.y, gameObject.transform.position.z), gameObject.transform.rotation)); newPossessed.transform.parent = gameObject.transform; } else if (affliction.name == "Parasite") { gameObject.GetComponent<Renderer> ().material.color = Color.yellow; GameObject newParasite = (GameObject)(Instantiate (parasitePrefab, new Vector3 (gameObject.transform.position.x + 0.68f, gameObject.transform.position.y, gameObject.transform.position.z), gameObject.transform.rotation)); newParasite.transform.parent = gameObject.transform; } else if (affliction.name == "Zombified") { gameObject.GetComponent<Renderer> ().material.color = Color.grey; GameObject newZombie = (GameObject)(Instantiate (zombiePrefab, new Vector3 (gameObject.transform.position.x + 0.68f, gameObject.transform.position.y, gameObject.transform.position.z), gameObject.transform.rotation)); newZombie.transform.parent = gameObject.transform; } else if (affliction.name == "Poison") { gameObject.GetComponent<Renderer> ().material.color = Color.green; GameObject newPoison = (GameObject)(Instantiate (poisonPrefab, new Vector3 (gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z + 1.0f), gameObject.transform.rotation)); newPoison.GetComponent<Renderer>().sortingLayerName = "Particles"; newPoison.transform.parent = gameObject.transform; } else { gameObject.GetComponent<Renderer> ().material.color = Color.red; } }
static void TestAll(string[] args) { // data DataStructures.RunInstanceNull(args); SparseVector.RunInstanceNull(args); SparseMatrix.RunInstanceNull(args); Stateful.RunInstanceNull(args); Cloning.RunInstanceNull(args); Serialization.RunInstanceNull(args); // model Bow.RunInstanceNull(args); BinarySvm.RunInstanceNull(args); // clustering KMeans.RunInstanceNull(args); // validation NFold.RunInstanceNull(args); NFoldClass.RunInstanceNull(args); // other Searching.RunInstanceNull(args); TextProcessing.RunInstanceNull(args); }
protected virtual void SaveToFile(string filename, DataStructures.MapObjects.Map map) { using (var strm = new FileStream(filename, FileMode.Create, FileAccess.Write)) { SaveToStream(strm, map); } }
private static string GetIPv4PrecedenceText(int precedence) { string description = DataStructures.GetIPv4PrecedenceDescription(precedence); switch (precedence) { case 0: return(String.Format("000 . . . . . = Precedence: {0} (0)", description)); case 1: return(String.Format("001 . . . . . = Precedence: {0} (1)", description)); case 2: return(String.Format("010 . . . . . = Precedence: {0} (2)", description)); case 3: return(String.Format("011 . . . . . = Precedence: {0} (3)", description)); case 4: return(String.Format("100 . . . . . = Precedence: {0} (4)", description)); case 5: return(String.Format("101 . . . . . = Precedence: {0} (5)", description)); case 6: return(String.Format("110 . . . . . = Precedence: {0} (6)", description)); case 7: return(String.Format("111 . . . . . = Precedence: {0} (7)", description)); default: return(String.Empty); } }
public void UpdateFrom_v0_1() { var filename = "Broombridge/broombridge_v0.1.yaml"; var broombridge_v0_1 = Deserializers.Deserialize <V0_1.Data>(filename); var broombridge_v0_2 = DataStructures.Update(broombridge_v0_1); Broombridge.Serializers.SerializeBroombridgev0_2(broombridge_v0_2, System.Console.Out); }
protected internal override void CollectInvolvedEntities(DataStructures.RawList<Entity> outputInvolvedEntities) { //The default implementation for solver groups looks at every single subconstraint. //That's not necessary for these special constraints. if (entityA != null) outputInvolvedEntities.Add(entityA); if (entityB != null) outputInvolvedEntities.Add(entityB); }
public void ReadModel(string filename) { string contents = File.ReadAllText(filename); var data = (ModelSaver)DataStructures.Deserialization(contents, typeof(ModelSaver)); Ip2VecModel.SuDeserializer(data, this); //this.WordCount = this.Word2Index.Count(); //this.Ip2VecSettings.NeuronCount = data.Y; }
public void SetProperty(string originalName, string newName, string currentValue, DataStructures.GameData.Property property) { _setting = true; OriginalName = originalName; PropertyName = newName; PropertyValue = currentValue; Property = property; OnSetProperty(); _setting = false; }
public static void SaveMapToFile(string filename, DataStructures.MapObjects.Map map) { var provider = RegisteredProviders.FirstOrDefault(p => p.IsValidForFileName(filename)); if (provider != null) { provider.SaveToFile(filename, map); return; } throw new ProviderNotFoundException("No map provider was found for this file format."); }
public HardwareChannel(string serverName, string deviceName, string channelName, string channelDescription, HardwareChannel.HardwareConstants.ChannelTypes ct, DataStructures.Gpib.Address gpibAddress, HardwareChannel.HardwareConstants.GPIBDeviceType gpibDeviceType) : this(serverName, deviceName, channelName,channelDescription, ct) { if (this.ChannelType != HardwareConstants.ChannelTypes.gpib) { throw new Exception("Do not call gpib channel constructor for a non gpib device."); } this.gpibAddress = gpibAddress; this.gpibDeviceType = gpibDeviceType; }
public void SaveModel(string filename) { var data = PreSerializer(this); using (StreamWriter file = new StreamWriter(filename, false)) { file.WriteLine(DataStructures.Serialization(data, data.GetType())); } Console.WriteLine("Finish writing to {0}", filename); }
public void Summarize(DataStructures.Document doc, Configuration config) { TFIDF.Transform(doc, config, 0); DescriptionSummary(doc); MustHaveSummary(doc); GoodToHaveSummary(doc); //?? Future work //Imporrtant Words count //Nouns Count //Verbs Count }
//static void Main(string[] args) //{ // // TestGeneralClassMethods(); // // TestWayFairPrintTable(); // // TestWayFairStringIsBalanced(); // // TestWayFairSumOfMultiplesOf3And5LessThanN(); // // TestSepratePositiveNegativeInArray(); // // TestWayFairBST(); // Console.WriteLine(IHSMarkit.String.Reverse("123456789")); //} private static void TestWayFairBST() { BinarySearchTree binarySearchTree = new BinarySearchTree(); binarySearchTree.Insert("Rahul", 33); binarySearchTree.Insert("Arpita", 30); binarySearchTree.Insert("Amita", 55); binarySearchTree.Insert("Pooja", 26); binarySearchTree.Insert("Keshav", 60); binarySearchTree.Insert("Gopal", 58); Console.WriteLine(binarySearchTree.DrawTree()); DataStructures dataStructures = new DataStructures(); Console.WriteLine("Max Depth is {0}", dataStructures.MaxDepthViaLoop(binarySearchTree.RootNode())); binarySearchTree.RootNode(); }
//TODO: Having a specialized triangle-triangle pair test would be nice. Even if it didn't use an actual triangle-triangle test, certain assumptions could still make it speedier and more elegant. //"Closest points between triangles" + persistent manifolding would probably be the best approach (a lot faster than the triangle-convex general case anyway). public override bool GenerateContactCandidate(out DataStructures.TinyStructList<ContactData> contactList) { if (base.GenerateContactCandidate(out contactList)) { //The triangle-convex pair test has already rejected contacts whose normals would violate the first triangle's sidedness. //However, since it's a vanilla triangle-convex test, it doesn't know about the sidedness of the other triangle! var shape = ((TriangleShape)convex); Vector3 normal; //Lots of recalculating ab-bc! Vector3 ab, ac; Vector3.Subtract(ref shape.vB, ref shape.vA, out ab); Vector3.Subtract(ref shape.vC, ref shape.vA, out ac); Vector3.Cross(ref ab, ref ac, out normal); var sidedness = shape.sidedness; if (sidedness != TriangleSidedness.DoubleSided) { for (int i = contactList.count - 1; i >= 0; i--) { ContactData item; contactList.Get(i, out item); float dot; Vector3.Dot(ref item.Normal, ref normal, out dot); if (sidedness == TriangleSidedness.Clockwise) { if (dot < 0) { contactList.RemoveAt(i); } } else { if (dot > 0) { contactList.RemoveAt(i); } } } } return contactList.count > 0; } return false; }
internal static void UpdateArpNode(TreeView treeView, ARPPacket arpPacket) { TreeNode arpNode = treeView.Nodes["ARP"]; if (arpNode == null) { arpNode = AddArpNode(treeView); } arpNode.Text = String.Format("Address Resolution Protocol ({0})", DataStructures.GetARPOpDescription(arpPacket.ARPOperation)); arpNode.Nodes["HwType"].Text = String.Format("Hardware type: {0} (0x{1:X4})", DataStructures.GetARPHwTypeDescription(arpPacket.ARPHwType), arpPacket.ARPHwType); arpNode.Nodes["ProtocolType"].Text = String.Format("Protocol type: {0} (0x{1:X4})", DataStructures.GetEtherTypeDescription((EthernetPacketType)arpPacket.ARPProtocolType), arpPacket.ARPProtocolType); arpNode.Nodes["HwSize"].Text = String.Format("Hardware size: {0}", arpPacket.ARPHwLength); arpNode.Nodes["ProtocolSize"].Text = String.Format("Protocol size: {0}", arpPacket.ARPProtocolLength); arpNode.Nodes["Opcode"].Text = String.Format("Operation: {0} (0x{1:X4})", DataStructures.GetARPOpDescription(arpPacket.ARPOperation), arpPacket.ARPOperation); arpNode.Nodes["SenderHwAddress"].Text = String.Format("Sender MAC address: {0}", GetHyphenatedHwAddress(arpPacket.ARPSenderHwAddress)); arpNode.Nodes["SenderIPAddress"].Text = String.Format("Sender IP address: {0}", arpPacket.ARPSenderProtoAddress); arpNode.Nodes["TargetHwAddress"].Text = String.Format("Target MAC address: {0}", GetHyphenatedHwAddress(arpPacket.ARPTargetHwAddress)); arpNode.Nodes["TargetIPAddress"].Text = String.Format("Target IP address: {0}", arpPacket.ARPTargetProtoAddress); }
private IEnumerable<Solid> CreateSolids(DataStructures.MapObjects.Map map, List<Coordinate> points, IEnumerable<ObjFace> objFaces) { var faces = objFaces.Select(x => CreateFace(map, points, x)).ToList(); // See if the solid is valid var solid = new Solid(map.IDGenerator.GetNextObjectID()); solid.Colour = Colour.GetRandomBrushColour(); solid.Faces.AddRange(faces); faces.ForEach(x => x.Parent = solid); if (solid.IsValid()) { // Do an additional check to ensure that all edges are shared var edges = solid.Faces.SelectMany(x => x.GetEdges()).ToList(); if (edges.All(x => edges.Count(y => x.EquivalentTo(y)) == 2)) { // Valid! let's get out of here! yield return solid; yield break; } } // Not a valid solid, decompose into tetrahedrons/etc foreach (var face in faces) { var polygon = new Polygon(face.Vertices.Select(x => x.Location)); if (!polygon.IsValid() || !polygon.IsConvex()) { // tetrahedrons foreach (var triangle in face.GetTriangles()) { var tf = new Face(map.IDGenerator.GetNextFaceID()); tf.Plane = new Plane(triangle[0].Location, triangle[1].Location, triangle[2].Location); tf.Vertices.AddRange(triangle.Select(x => new Vertex(x.Location, tf))); tf.UpdateBoundingBox(); yield return SolidifyFace(map, tf); } } else { // cone/pyramid/whatever yield return SolidifyFace(map, face); } } }
private void ParseAt(DataStructures.GameData.GameData gd, IEnumerator<LexObject> iterator) { iterator.MoveNext(); var type = iterator.Current.Value; if (type.Equals("include", StringComparison.InvariantCultureIgnoreCase)) { Expect(iterator, LexType.String); if (CurrentFile != null) { var filename = iterator.Current.GetValue(); var path = Path.GetDirectoryName(CurrentFile) ?? ""; var incfile = Path.Combine(path, filename); var current = CurrentFile; var incgd = GetGameDataFromFile(incfile); CurrentFile = current; if (!gd.Includes.Any(x => String.Equals(x, filename, StringComparison.InvariantCultureIgnoreCase))) gd.Includes.Add(filename); // Merge the included gamedata into the current one gd.MapSizeHigh = Math.Max(incgd.MapSizeHigh, gd.MapSizeHigh); gd.MapSizeLow = Math.Min(incgd.MapSizeLow, gd.MapSizeLow); gd.Includes.AddRange(incgd.Includes.Where(x => !gd.Includes.Contains(x))); gd.Classes.AddRange(incgd.Classes.Where(x => !gd.Classes.Any(y => String.Equals(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase)))); gd.AutoVisgroups.AddRange(incgd.AutoVisgroups.Where(x => !gd.AutoVisgroups.Any(y => String.Equals(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase)))); gd.MaterialExclusions.AddRange(incgd.MaterialExclusions.Where(x => !gd.MaterialExclusions.Any(y => String.Equals(x, y, StringComparison.InvariantCultureIgnoreCase)))); } else { throw new ProviderException("Unable to include a file when not reading from a file."); } } else if (type.Equals("mapsize", StringComparison.InvariantCultureIgnoreCase)) { Expect(iterator, LexType.So); Expect(iterator, LexType.Value); gd.MapSizeLow = Int32.Parse(iterator.Current.Value); Expect(iterator, LexType.Comma); Expect(iterator, LexType.Value); gd.MapSizeHigh = Int32.Parse(iterator.Current.Value); Expect(iterator, LexType.Already); } else if (type.Equals("materialexclusion", StringComparison.InvariantCultureIgnoreCase)) { Expect(iterator, LexType.Open); iterator.MoveNext(); while (iterator.Current.Type != LexType.Close) { Assert(iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + "."); var exclusion = iterator.Current.GetValue(); gd.MaterialExclusions.Add(exclusion); iterator.MoveNext(); } } else if (type.Equals("autovisgroup", StringComparison.InvariantCultureIgnoreCase)) { Expect(iterator, LexType.Equals); iterator.MoveNext(); Assert(iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + "."); var sectionName = iterator.Current.GetValue(); var sect = new AutoVisgroupSection {Name = sectionName}; Expect(iterator, LexType.Open); iterator.MoveNext(); while (iterator.Current.Type != LexType.Close) { Assert(iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + "."); var groupName = iterator.Current.GetValue(); var grp = new AutoVisgroup {Name = groupName}; Expect(iterator, LexType.Open); iterator.MoveNext(); while (iterator.Current.Type != LexType.Close) { Assert(iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + "."); var entity = iterator.Current.GetValue(); grp.EntityNames.Add(entity); iterator.MoveNext(); } sect.Groups.Add(grp); } gd.AutoVisgroups.Add(sect); } else { // Parsing: // @TypeClass name(param, param) name() var ct = ParseClassType(type); var gdo = new GameDataObject("", "", ct); iterator.MoveNext(); while (iterator.Current.Type == LexType.Value) { // Parsing: // @TypeClass {name(param, param) name()} var name = iterator.Current.Value; var bh = new Behaviour(name); iterator.MoveNext(); if (iterator.Current.Type == LexType.Value) { // Allow for the following (first seen in hl2 base): // @PointClass {halfgridsnap} base(Targetname) continue; } Assert(iterator.Current.Type == LexType.So, "Unexpected " + iterator.Current.Type); iterator.MoveNext(); while (iterator.Current.Type != LexType.Already) { // Parsing: // name({param, param}) if (iterator.Current.Type != LexType.Comma) { Assert(iterator.Current.Type == LexType.Value || iterator.Current.Type == LexType.String, "Unexpected " + iterator.Current.Type + "."); var value = iterator.Current.Value; if (iterator.Current.Type == LexType.String) value = value.Trim('"'); bh.Values.Add(value); } iterator.MoveNext(); } Assert(iterator.Current.Type == LexType.Already, "Unexpected " + iterator.Current.Type); // Treat base behaviour as a special case if (bh.Name == "base") { gdo.BaseClasses.AddRange(bh.Values); } else { gdo.Behaviours.Add(bh); } iterator.MoveNext(); } // = class_name : "Descr" + "iption" [ Assert(iterator.Current.Type == LexType.Equals, "Expected equals, got " + iterator.Current.Type); Expect(iterator, LexType.Value); gdo.Name = iterator.Current.Value; iterator.MoveNext(); if (iterator.Current.Type == LexType.Colon) { // Parsing: // : {"Descr" + "iption"} [ iterator.MoveNext(); gdo.Description = ParsePlusString(iterator); } Assert(iterator.Current.Type == LexType.Open, "Unexpected " + iterator.Current.Type); // Parsing: // name(type) : "Desc" : "Default" : "Long Desc" = [ ... ] // input name(type) : "Description" // output name(type) : "Description" iterator.MoveNext(); while (iterator.Current.Type != LexType.Close) { Assert(iterator.Current.Type == LexType.Value, "Unexpected " + iterator.Current.Type); var pt = iterator.Current.Value; if (pt == "input" || pt == "output") // IO { // input name(type) : "Description" var io = new IO(); Expect(iterator, LexType.Value); io.IOType = (IOType) Enum.Parse(typeof (IOType), pt, true); io.Name = iterator.Current.Value; Expect(iterator, LexType.So); Expect(iterator, LexType.Value); io.VariableType = ParseVariableType(iterator.Current.Value); Expect(iterator, LexType.Already); iterator.MoveNext(); // if not colon, this will be the value of the next io/property, or close if (iterator.Current.Type == LexType.Colon) { iterator.MoveNext(); io.Description = ParsePlusString(iterator); } gdo.InOuts.Add(io); } else // Property { Expect(iterator, LexType.So); Expect(iterator, LexType.Value); var vartype = ParseVariableType(iterator.Current.Value); Expect(iterator, LexType.Already); var prop = new Property(pt, vartype); iterator.MoveNext(); // if not colon or equals, this will be the value of the next io/property, or close if (iterator.Current.Type == LexType.Value) { // Check for additional flags on the property // e.g.: name(type) readonly : "This is a read only value" // name(type) report : "This value will show in the entity report" switch (iterator.Current.Value) { case "readonly": prop.ReadOnly = true; iterator.MoveNext(); break; case "report": prop.ShowInEntityReport = true; iterator.MoveNext(); break; } } do // Using do/while(false) so I can break out - reduces nesting. { // Short description if (iterator.Current.Type != LexType.Colon) break; iterator.MoveNext(); prop.ShortDescription = ParsePlusString(iterator); // Default value if (iterator.Current.Type != LexType.Colon) break; iterator.MoveNext(); if (iterator.Current.Type != LexType.Colon) // Allow for ': :' structure (no default) { if (iterator.Current.Type == LexType.String) { prop.DefaultValue = iterator.Current.Value.Trim('"'); } else { Assert(iterator.Current.Type == LexType.Value, "Unexpected " + iterator.Current.Type); prop.DefaultValue = iterator.Current.Value; } iterator.MoveNext(); } // Long description if (iterator.Current.Type != LexType.Colon) break; iterator.MoveNext(); prop.Description = ParsePlusString(iterator); } while (false); if (iterator.Current.Type == LexType.Equals) { Expect(iterator, LexType.Open); // Parsing property options: // value : description // value : description : 0 iterator.MoveNext(); while (iterator.Current.IsValueOrString()) { var opt = new Option { Key = iterator.Current.GetValue() }; Expect(iterator, LexType.Colon); // Some FGDs use values for property descriptions instead of strings iterator.MoveNext(); Assert(iterator.Current.IsValueOrString(), "Choices value must be value or string type."); if (iterator.Current.Type == LexType.String) { opt.Description = ParsePlusString(iterator); } else { opt.Description = iterator.Current.GetValue(); iterator.MoveNext(); // ParsePlusString moves next once it's complete, need to do the same here } prop.Options.Add(opt); if (iterator.Current.Type != LexType.Colon) { continue; } Expect(iterator, LexType.Value); opt.On = iterator.Current.Value == "1"; iterator.MoveNext(); } Assert(iterator.Current.Type == LexType.Close, "Unexpected " + iterator.Current.Type); iterator.MoveNext(); } gdo.Properties.Add(prop); } } Assert(iterator.Current.Type == LexType.Close, "Unexpected " + iterator.Current.Type); gd.Classes.Add(gdo); } }
/// <summary> /// ����ǰ�tcp����תΪ�ֽ������õģ���Ϊ���Ҫ�õ�2�ξͲ��������α�ײ���һ���� /// </summary> /// <param name="tch"></param> /// <param name="buffer"></param> /// <param name="size"></param> /// <returns></returns> public Int32 tchto(DataStructures.tcpHeader tch, byte[] buffer, int size) { Int32 rtn; int index = 0; byte[] b_tch_sport = BitConverter.GetBytes(tch.th_sport); byte[] b_tch_dport = BitConverter.GetBytes(tch.th_dport); byte[] b_tch_seq = BitConverter.GetBytes(tch.th_seq); byte[] b_tch_ack = BitConverter.GetBytes(tch.th_ack); byte[] b_tch_lenres = new byte[1]; b_tch_lenres[0] = tch.th_lenres; byte[] b_tch_flag = new byte[1]; b_tch_flag[0] = tch.th_flag; byte[] b_tch_win = BitConverter.GetBytes(tch.th_win); byte[] b_tch_sum = BitConverter.GetBytes(tch.th_sum); byte[] b_tch_urp = BitConverter.GetBytes(tch.th_urp); Array.Copy(b_tch_sport, 0, buffer, index, b_tch_sport.Length); index += b_tch_sport.Length; Array.Copy(b_tch_dport, 0, buffer, index, b_tch_dport.Length); index += b_tch_dport.Length; Array.Copy(b_tch_seq, 0, buffer, index, b_tch_seq.Length); index += b_tch_seq.Length; Array.Copy(b_tch_ack, 0, buffer, index, b_tch_ack.Length); index += b_tch_ack.Length; Array.Copy(b_tch_lenres, 0, buffer, index, b_tch_lenres.Length); index += b_tch_lenres.Length; Array.Copy(b_tch_flag, 0, buffer, index, b_tch_flag.Length); index += b_tch_flag.Length; Array.Copy(b_tch_win, 0, buffer, index, b_tch_win.Length); index += b_tch_win.Length; Array.Copy(b_tch_sum, 0, buffer, index, b_tch_sum.Length); index += b_tch_sum.Length; Array.Copy(b_tch_urp, 0, buffer, index, b_tch_urp.Length); index += b_tch_urp.Length; if (index != size) { rtn = -1; return rtn; } else { rtn = index; return rtn; } }
private static GenericStructure WriteWorld(DataStructures.MapObjects.Map map, IEnumerable<Solid> solids, IEnumerable<Group> groups) { var world = map.WorldSpawn; var ret = new GenericStructure("world"); ret["id"] = world.ID.ToString(CultureInfo.InvariantCulture); ret["classname"] = "worldspawn"; WriteEntityData(ret, world.EntityData); //TODO these properties ret["mapversion"] = map.Version.ToString(CultureInfo.InvariantCulture); ret["detailmaterial"] = "detail/detailsprites"; ret["detailvbsp"] = "detail.vbsp"; ret["maxpropscreenwidth"] = "-1"; ret["skyname"] = "sky_day01_01"; foreach (var solid in solids.OrderBy(x => x.ID)) { ret.Children.Add(WriteSolid(solid)); } foreach (var group in groups.OrderBy(x => x.ID)) { ret.Children.Add(WriteGroup(group)); } return ret; }
protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map) { var groups = new List<Group>(); var solids = new List<Solid>(); var ents = new List<Entity>(); FlattenTree(map.WorldSpawn, solids, ents, groups); var fvi = FileVersionInfo.GetVersionInfo(typeof (VmfProvider).Assembly.Location); var versioninfo = new GenericStructure("versioninfo"); versioninfo.AddProperty("editorname", "Sledge"); versioninfo.AddProperty("editorversion", fvi.ProductMajorPart.ToString(CultureInfo.InvariantCulture) + "." + fvi.ProductMinorPart.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("editorbuild", fvi.ProductBuildPart.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("mapversion", map.Version.ToString(CultureInfo.InvariantCulture)); versioninfo.AddProperty("formatversion", "100"); versioninfo.AddProperty("prefab", "0"); var visgroups = new GenericStructure("visgroups"); foreach (var visgroup in map.Visgroups.OrderBy(x => x.ID).Where(x => !x.IsAutomatic)) { visgroups.Children.Add(WriteVisgroup(visgroup)); } var viewsettings = new GenericStructure("viewsettings"); viewsettings.AddProperty("bSnapToGrid", map.SnapToGrid ? "1" : "0"); viewsettings.AddProperty("bShowGrid", map.Show2DGrid ? "1" : "0"); viewsettings.AddProperty("bShow3DGrid", map.Show3DGrid ? "1" : "0"); viewsettings.AddProperty("nGridSpacing", map.GridSpacing.ToString(CultureInfo.InvariantCulture)); viewsettings.AddProperty("bIgnoreGrouping", map.IgnoreGrouping ? "1" : "0"); viewsettings.AddProperty("bHideFaceMask", map.HideFaceMask ? "1" : "0"); viewsettings.AddProperty("bHideNullTextures", map.HideNullTextures ? "1" : "0"); viewsettings.AddProperty("bTextureLock", map.TextureLock ? "1" : "0"); viewsettings.AddProperty("bTextureScalingLock", map.TextureScalingLock ? "1" : "0"); var world = WriteWorld(map, solids, groups); var entities = ents.OrderBy(x => x.ID).Select(WriteEntity).ToList(); var cameras = new GenericStructure("cameras"); cameras.AddProperty("activecamera", map.Cameras.IndexOf(map.ActiveCamera).ToString(CultureInfo.InvariantCulture)); foreach (var cam in map.Cameras) { var camera = new GenericStructure("camera"); camera.AddProperty("position", "[" + FormatCoordinate(cam.EyePosition) + "]"); camera.AddProperty("look", "[" + FormatCoordinate(cam.LookPosition) + "]"); cameras.Children.Add(camera); } var cordon = new GenericStructure("cordon"); cordon.AddProperty("mins", map.CordonBounds.Start.ToString()); cordon.AddProperty("maxs", map.CordonBounds.End.ToString()); cordon.AddProperty("active", map.Cordon ? "1" : "0"); using (var sw = new StreamWriter(stream)) { versioninfo.PrintToStream(sw); visgroups.PrintToStream(sw); viewsettings.PrintToStream(sw); world.PrintToStream(sw); entities.ForEach(e => e.PrintToStream(sw)); cameras.PrintToStream(sw); cordon.PrintToStream(sw); } }
protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map) { var bw = new BinaryWriter(stream, Encoding.UTF8); bw.Write(2.2f); // RMF version number bw.WriteFixedLengthString(Encoding.UTF8, 3, "RMF"); WriteVisgroups(bw, map.Visgroups); WriteMapObject(bw, map.WorldSpawn); bw.WriteFixedLengthString(Encoding.UTF8, 8, "DOCINFO"); bw.Write(0.2f); // Unused bw.Write(map.Cameras.IndexOf(map.ActiveCamera)); WriteCameras(bw, map.Cameras); }
public static int FindMinCutWithRandomizedContractions(DataStructures.Graph_AdjacencyList<Types.Vertex<int>, int> graph) { RandomizedContraction contraction = new RandomizedContraction(graph); int cut = contraction.FindMinCut_RandomizeContraction(); return cut; }
internal static void UpdateEthernetNode(TreeView treeView, EthernetPacket ethPacket) { TreeNode ethNode = treeView.Nodes["Ethernet"]; if (ethNode == null) { ethNode = AddEthernetNode(treeView); } ethNode.Text = String.Format("Ethernet II, Src: {0}, Dst: {1}", GetHyphenatedHwAddress(ethPacket.SourceHwAddress), GetHyphenatedHwAddress(ethPacket.DestinationHwAddress)); ethNode.Nodes["Destination"].Text = String.Format("Destination: {0}", GetHyphenatedHwAddress(ethPacket.DestinationHwAddress)); ethNode.Nodes["Source"].Text = String.Format("Source: {0}", GetHyphenatedHwAddress(ethPacket.SourceHwAddress)); ethNode.Nodes["Type"].Text = String.Format("Type: {0} (0x{1:X4})", DataStructures.GetEtherTypeDescription(ethPacket.EthernetProtocol), (int)ethPacket.EthernetProtocol); }
public ModelReference(string path, DataStructures.Models.Model model) { Path = path; Model = model; }
private void OnLoaded(object obj) { DataStructures.Add(new DataStructureAxViewModel()); DataStructures.Add(new DataStructureAyViewModel()); SelectedDataStructure = DataStructures.First(); }
private Solid SolidifyFace(DataStructures.MapObjects.Map map, Face face) { var solid = new Solid(map.IDGenerator.GetNextObjectID()); solid.Colour = Colour.GetRandomBrushColour(); solid.Faces.Add(face); face.Parent = solid; var center = face.Vertices.Aggregate(Coordinate.Zero, (sum, v) => sum + v.Location) / face.Vertices.Count; var offset = center - face.Plane.Normal * 5; for (var i = 0; i < face.Vertices.Count; i++) { var v1 = face.Vertices[i]; var v2 = face.Vertices[(i + 1) % face.Vertices.Count]; var f = new Face(map.IDGenerator.GetNextFaceID()); f.Parent = solid; f.Plane = new Plane(v1.Location, offset, v2.Location); f.Parent = solid; f.Vertices.Add(new Vertex(offset, f)); f.Vertices.Add(new Vertex(v2.Location, f)); f.Vertices.Add(new Vertex(v1.Location, f)); f.UpdateBoundingBox(); solid.Faces.Add(f); } return solid; }
private NationalInstruments.NI4882.Address niAddress(DataStructures.Gpib.Address address) { return new NationalInstruments.NI4882.Address(address.PrimaryAddress, address.SecondaryAddress); }
private void Read(DataStructures.MapObjects.Map map, StreamReader reader) { var points = new List<Coordinate>(); string line; while ((line = CleanLine(reader.ReadLine())) != null) { string keyword, values; SplitLine(line, out keyword, out values); switch (keyword.ToLower()) { // Vertex data case "v": // geometric vertices break; case "vt": // texture vertices break; case "vn": // vertex normals break; case "vp": // parameter space vertices case "cstype": // rational or non-rational forms of curve or surface type: basis matrix, Bezier, B-spline, Cardinal, Taylor case "degree": // degree case "bmat": // basis matrix case "step": // step size // not supported break; // Elements case "f": // face break; case "p": // point case "l": // line case "curv": // curve case "curv2": // 2D curve case "surf": // surface // not supported break; // Free-form curve/surface body statements case "parm": // parameter name case "trim": // outer trimming loop (trim) case "hole": // inner trimming loop (hole) case "scrv": // special curve (scrv) case "sp": // special point (sp) case "end": // end statement (end) // not supported break; // Connectivity between free-form surfaces case "con": // connect // not supported break; // Grouping case "g": // group name break; case "s": // smoothing group break; case "mg": // merging group break; case "o": // object name // not supported break; // Display/render attributes case "mtllib": // material library case "usemtl": // material name case "usemap": // texture map name case "bevel": // bevel interpolation case "c_interp": // color interpolation case "d_interp": // dissolve interpolation case "lod": // level of detail case "shadow_obj": // shadow casting case "trace_obj": // ray tracing case "ctech": // curve approximation technique case "stech": // surface approximation technique // not relevant break; } } }
private Face CreateFace(DataStructures.MapObjects.Map map, List<Coordinate> points, ObjFace objFace) { var verts = objFace.Vertices.Select(x => points[x]).ToList(); var f = new Face(map.IDGenerator.GetNextFaceID()); f.Plane = new Plane(verts[2], verts[1], verts[0]); f.Vertices.AddRange(verts.Select(x => new Vertex(x, f)).Reverse()); f.UpdateBoundingBox(); return f; }
/// <summary> /// ��IPHeaderʵ������Ϣת��Ϊbyte���� /// </summary> /// <param name="ipHeader"></param> /// <returns></returns> private byte[] GetBytesFromIPHeader(DataStructures.IP_HEADER ipHeader) { int count = 0; int len = sizeof(ushort) * 4 + sizeof(int) * 2 + 4; byte[] ByteBuf = new byte[len]; byte[] tmp; ByteBuf[count++] = ipHeader.ver_hlen; ByteBuf[count++] = ipHeader.TOS; tmp = BitConverter.GetBytes(ipHeader.totalLen); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(ipHeader.ident); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(ipHeader.frag_and_flags); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } ByteBuf[count++] = ipHeader.ttl; ByteBuf[count++] = ipHeader.proto; tmp = BitConverter.GetBytes(ipHeader.checksum); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(ipHeader.sourceIP); for (int i = 0; i < sizeof(int); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(ipHeader.destIP); for (int i = 0; i < sizeof(int); i++) { ByteBuf[count++] = tmp[i]; } return ByteBuf; }
private void Read(DataStructures.MapObjects.Map map, StreamReader reader) { var points = new List<Coordinate>(); var faces = new List<ObjFace>(); var currentGroup = "default"; var scale = 100m; string line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("# Scale: ")) { var num = line.Substring(9); decimal s; if (decimal.TryParse(num, NumberStyles.Float, CultureInfo.InvariantCulture, out s)) { scale = s; } } line = CleanLine(line); string keyword, values; SplitLine(line, out keyword, out values); if (String.IsNullOrWhiteSpace(keyword)) continue; var vals = (values ?? "").Split(' ').Where(x => !String.IsNullOrWhiteSpace(x)).ToArray(); switch (keyword.ToLower()) { // Things I care about case "v": // geometric vertices points.Add(Coordinate.Parse(vals[0], vals[1], vals[2]) * scale); break; case "f": // face faces.Add(new ObjFace(currentGroup, vals.Select(x => ParseFaceIndex(points, x)))); break; case "g": // group name currentGroup = (values ?? "").Trim(); break; // Things I don't care about #region Not Implemented // Vertex data // "v" case "vt": // texture vertices break; case "vn": // vertex normals break; case "vp": // parameter space vertices case "cstype": // rational or non-rational forms of curve or surface type: basis matrix, Bezier, B-spline, Cardinal, Taylor case "degree": // degree case "bmat": // basis matrix case "step": // step size // not supported break; // Elements // "f" case "p": // point case "l": // line case "curv": // curve case "curv2": // 2D curve case "surf": // surface // not supported break; // Free-form curve/surface body statements case "parm": // parameter name case "trim": // outer trimming loop (trim) case "hole": // inner trimming loop (hole) case "scrv": // special curve (scrv) case "sp": // special point (sp) case "end": // end statement (end) // not supported break; // Connectivity between free-form surfaces case "con": // connect // not supported break; // Grouping // "g" case "s": // smoothing group break; case "mg": // merging group break; case "o": // object name // not supported break; // Display/render attributes case "mtllib": // material library case "usemtl": // material name case "usemap": // texture map name case "bevel": // bevel interpolation case "c_interp": // color interpolation case "d_interp": // dissolve interpolation case "lod": // level of detail case "shadow_obj": // shadow casting case "trace_obj": // ray tracing case "ctech": // curve approximation technique case "stech": // surface approximation technique // not relevant break; #endregion } } var solids = new List<Solid>(); // Try and see if we have a valid solid per-group foreach (var g in faces.GroupBy(x => x.Group)) { solids.AddRange(CreateSolids(map, points, g)); } foreach (var solid in solids) { foreach (var face in solid.Faces) { face.Colour = solid.Colour; face.AlignTextureToFace(); } solid.SetParent(map.WorldSpawn); } }
/// <summary> /// ��psdHeaderʵ������Ϣת��Ϊbyte���� /// </summary> /// <param name="psdHeader"></param> /// <returns></returns> private byte[] GetBytesFromPsdHeader(DataStructures.psd_header psdHeader) { int count = 0; int len = sizeof(int) + sizeof(int) + 2 + sizeof(ushort); byte[] ByteBuf = new byte[len]; byte[] tmp; tmp = BitConverter.GetBytes(psdHeader.saddr); for (int j = 0; j < sizeof(int); j++) { ByteBuf[count++] = tmp[j]; } tmp = BitConverter.GetBytes(psdHeader.daddr); for (int j = 0; j < sizeof(int); j++) { ByteBuf[count++] = tmp[j]; } ByteBuf[count++] = psdHeader.mbz; ByteBuf[count++] = psdHeader.ptcl; for (int j = 0; j < sizeof(ushort); j++) { ByteBuf[count++] = tmp[j]; } return ByteBuf; }
protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map) { /* // Csg version var csg = new CsgSolid(); foreach (var mo in map.WorldSpawn.Find(x => x is Solid).OfType<Solid>()) { csg = csg.Union(new CsgSolid(mo.Faces.Select(x => new Polygon(x.Vertices.Select(v => v.Location))))); } using (var sw = new StreamWriter(stream)) { foreach (var polygon in csg.Polygons) { foreach (var v in polygon.Vertices) { sw.Write("v "); sw.Write(v.X.ToString("0.0000", CultureInfo.InvariantCulture)); sw.Write(' '); sw.Write(v.Y.ToString("0.0000", CultureInfo.InvariantCulture)); sw.Write(' '); sw.Write(v.Z.ToString("0.0000", CultureInfo.InvariantCulture)); sw.WriteLine(); } sw.Write("f "); for (int i = polygon.Vertices.Count; i > 0; i--) { sw.Write(-i); sw.Write(' '); } sw.WriteLine(); sw.WriteLine(); } } */ // Semi-recoverable version using (var sw = new StreamWriter(stream)) { sw.WriteLine("# Sledge Object Export"); sw.WriteLine("# Scale: 1"); sw.WriteLine(); foreach (var solid in map.WorldSpawn.Find(x => x is Solid).OfType<Solid>()) { sw.Write("g solid_"); sw.Write(solid.ID); sw.WriteLine(); foreach (var face in solid.Faces) { foreach (var v in face.Vertices) { sw.Write("v "); sw.Write(v.Location.X.ToString("0.0000", CultureInfo.InvariantCulture)); sw.Write(' '); sw.Write(v.Location.Y.ToString("0.0000", CultureInfo.InvariantCulture)); sw.Write(' '); sw.Write(v.Location.Z.ToString("0.0000", CultureInfo.InvariantCulture)); sw.WriteLine(); } sw.Write("f "); for (var i = 1; i <= face.Vertices.Count; i++) { sw.Write(-i); sw.Write(' '); } sw.WriteLine(); sw.WriteLine(); } } } }
/// <summary> /// ��TcpHeaderʵ������Ϣת��Ϊbyte���� /// </summary> /// <param name="tcpHeader"></param> /// <returns></returns> private byte[] GetBytesFromTcpHeader(DataStructures.TCP_HEADER tcpHeader) { int count = 0; int len = sizeof(ushort) * 2 + sizeof(int) * 2 + 2 + sizeof(ushort) * 3; byte[] ByteBuf = new byte[len]; byte[] tmp; tmp = BitConverter.GetBytes(tcpHeader.sourcePort); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(tcpHeader.destPort); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(tcpHeader.tcp_seq); for (int i = 0; i < sizeof(int); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(tcpHeader.tcp_ack); for (int i = 0; i < sizeof(int); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(tcpHeader.tcp_win); ByteBuf[count++] = tcpHeader.tcp_lenres; ByteBuf[count++] = tcpHeader.tcp_flags; for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(tcpHeader.tcp_checksum); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } tmp = BitConverter.GetBytes(tcpHeader.tcp_urp); for (int i = 0; i < sizeof(ushort); i++) { ByteBuf[count++] = tmp[i]; } return ByteBuf; }
private static void UnloadModel(DataStructures.Models.Model model) { model.Dispose(); foreach (var kv in Models.Where(x => x.Value == model)) Models.Remove(kv.Key); }
/// <summary> /// ����ǰ�ip����תΪ�ֽ������õ� /// </summary> /// <param name="iph"></param> /// <param name="Buffer"></param> /// <param name="size"></param> /// <returns></returns> public Int32 ipto(DataStructures.ipHeader iph, byte[] Buffer, int size) { Int32 rtn = 0; int index = 0; byte[] b_verlen = new byte[1]; b_verlen[0] = iph.ip_verlen; byte[] b_tos = new byte[1]; b_tos[0] = iph.ip_tos; byte[] b_totallen = BitConverter.GetBytes(iph.ip_totallength); byte[] b_id = BitConverter.GetBytes(iph.ip_id); byte[] b_offset = BitConverter.GetBytes(iph.ip_offset); byte[] b_ttl = new byte[1]; b_ttl[0] = iph.ip_ttl; byte[] b_protol = new byte[1]; b_protol[0] = iph.ip_protocol; byte[] b_checksum = BitConverter.GetBytes(iph.ip_checksum); byte[] b_srcaddr = BitConverter.GetBytes(iph.ip_srcaddr); byte[] b_destaddr = BitConverter.GetBytes(iph.ip_destaddr); Array.Copy(b_verlen, 0, Buffer, index, b_verlen.Length); index += b_verlen.Length; Array.Copy(b_tos, 0, Buffer, index, b_tos.Length); index += b_tos.Length; Array.Copy(b_totallen, 0, Buffer, index, b_totallen.Length); index += b_totallen.Length; Array.Copy(b_id, 0, Buffer, index, b_id.Length); index += b_id.Length; Array.Copy(b_offset, 0, Buffer, index, b_offset.Length); index += b_offset.Length; Array.Copy(b_ttl, 0, Buffer, index, b_ttl.Length); index += b_ttl.Length; Array.Copy(b_protol, 0, Buffer, index, b_protol.Length); index += b_protol.Length; Array.Copy(b_checksum, 0, Buffer, index, b_checksum.Length); index += b_checksum.Length; Array.Copy(b_srcaddr, 0, Buffer, index, b_srcaddr.Length); index += b_srcaddr.Length; Array.Copy(b_destaddr, 0, Buffer, index, b_destaddr.Length); index += b_destaddr.Length; if (index != size/* sizeof(IcmpPacket) */) { rtn = -1; return rtn; } rtn = index; return rtn; }
protected internal override void CollectInvolvedEntities(DataStructures.RawList<Entity> outputInvolvedEntities) { //This should never really have to be called. if (entityA != null) outputInvolvedEntities.Add(entityA); if (entityB != null) outputInvolvedEntities.Add(entityB); }
/// <summary> /// ����ǰ�tcpα�ײ�תΪ�ֽ������õ� /// </summary> /// <param name="psh"></param> /// <param name="buffer"></param> /// <param name="size"></param> /// <returns></returns> public Int32 pshto(DataStructures.psdHeader psh, byte[] buffer, int size) { Int32 rtn; int index = 0; byte[] b_psh_saddr = BitConverter.GetBytes(psh.saddr); byte[] b_psh_daddr = BitConverter.GetBytes(psh.daddr); byte[] b_psh_mbz = new byte[1]; b_psh_mbz[0] = psh.mbz; byte[] b_psh_ptcl = new byte[1]; b_psh_ptcl[0] = psh.ptcl; byte[] b_psh_tcpl = BitConverter.GetBytes(psh.tcpl); Array.Copy(b_psh_saddr, 0, buffer, index, b_psh_saddr.Length); index += b_psh_saddr.Length; Array.Copy(b_psh_daddr, 0, buffer, index, b_psh_daddr.Length); index += b_psh_daddr.Length; Array.Copy(b_psh_mbz, 0, buffer, index, b_psh_mbz.Length); index += b_psh_mbz.Length; Array.Copy(b_psh_ptcl, 0, buffer, index, b_psh_ptcl.Length); index += b_psh_ptcl.Length; Array.Copy(b_psh_tcpl, 0, buffer, index, b_psh_tcpl.Length); index += b_psh_tcpl.Length; if (index != size) { rtn = -1; return rtn; } else { rtn = index; return rtn; } }