Exemple #1
0
        // Алгоритм Рутисхаузера
        public static string Rutishauser(string str)
        {
            double n = -1;

            if (Double.TryParse(str, out n))
            {
                return(n.ToString(CultureInfo.InvariantCulture));
            }

            if (!IsBalanced(str))
            {
                return("Скобочная структура неверна!");
            }

            if (!CheckCorrectStr(str))
            {
                return("Ошибка в составлении выражения! (Расположите каждое действие в отдельных скобках)");
            }

            else
            {
                StructureList <MyStruct> list = ScanArithmeticExpression(str);

                list = DeterminateExpression(list);

                str = "";
                foreach (var element in list)
                {
                    str += element.PartOfString;
                }

                str = str.Replace('.', ',');
                return(Rutishauser(str));
            }
        }
Exemple #2
0
        private void generateLakeHouse(int HouseID)
        {
            int Radius = 32;

            int PX = (int)CenterPosition.X;
            int PY = (int)CenterPosition.Y;

            for (int countX = -Radius; countX <= Radius; countX += 2)
            {
                for (int countY = -Radius; countY <= Radius; countY += 2)
                {
                    if (MapUtil.HasSurrounding(PX + countX, PY + countY, IslandMap.lk, 8) && !IslandMap.lk[PX + countX, PY + countY] && !MapUtil.HasSurrounding(PX + countX, PY + countY, IslandMap.m, 1))
                    {
                        Point LakePoint = MapUtil.getClosest(PX + countX, PY + countY, IslandMap.lk, Radius);
                        int   angle     = MapUtil.GetDirectionAngle(PX + countX, PY + countY, IslandMap.lk) + 90;

                        if (angle >= 0)
                        {
                            Point3D Dimensions = VoxelModels.VoxelModels.ModelDimensionLibrary["House_" + HouseID + "_Dimensions"];

                            //Debug.WriteLine(Dimensions);

                            Structure Structure         = new Structure(new Point3D(PX + countX, IslandMap.h[PX + countX, PY + countY], PY + countY), angle, (int)Dimensions.X, (int)Dimensions.Y, (int)Dimensions.Z);
                            Boolean   HasNearbyBuilding = MapUtil.HasStructureSurroundingStructure(Structure, this, 3);

                            if (!HasNearbyBuilding)
                            {
                                Boolean HasLake = MapUtil.HasStructureSurrounding(Structure, IslandMap.lk, 6);

                                if (!HasLake)
                                {
                                    //add system for random houses
                                    IslandMap.StructureNames.Add("House_" + HouseID + "_");

                                    //IslandMap.StructurePoints.Add(new Point3D(PX + countX, IslandMap.h[PX + countX, PY + countY], PX + countX));
                                    IslandMap.StructurePoints.Add(new Point3D(PX + countX, IslandMap.h[PX + countX, PY + countY], PY + countY));
                                    //IslandMap.StructurePoints.Add(new Point3D(512, 2, 512));
                                    //IslandMap.StructureRotations.Add(new Vector3D(dir.X, 1, dir.Y));
                                    IslandMap.StructureRotations.Add(angle);

                                    StructureList.Add(Structure);

                                    //Debug.WriteLine("House added");

                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        // Найдем максимальный уровень
        static int GetMaxLvl(StructureList <MyStruct> list)
        {
            int max = 0;

            foreach (var element in list.Data)
            {
                if (element.Lvl > max)
                {
                    max = element.Lvl;
                }
            }

            return(max);
        }
Exemple #4
0
        // Constructor
        public MainViewModel(ScriptContext context)
        {
            Log.Initialize(context);

            var excludedDicomTypes = new List <string> {
                "BODY", "EXTERNAL", "SUPPORT", "MARKER"
            };

            _patient             = context.Patient;
            _plan                = context.PlanSetup;
            StructureList        = Plan.StructureSet.Structures.Where(x => !x.IsEmpty && !excludedDicomTypes.Contains(x.DicomType)).ToList();
            DefaultParameterSets = new List <ParameterSet>()
            {
                new ParameterSet()
                {
                    Name      = "Lung",
                    Type      = ParameterSetType.Lung,
                    AlphaBeta = new DoseValue(2.5, DoseUnit.Gy),
                    TD50      = new DoseValue(3080, DoseUnit.cGy),
                    n         = 0.99,
                    m         = 0.37
                },
                new ParameterSet()
                {
                    Name      = "Liver Primary",
                    Type      = ParameterSetType.LiverPrimary,
                    AlphaBeta = new DoseValue(2.5, DoseUnit.Gy),
                    TD50      = new DoseValue(3540, DoseUnit.cGy),
                    n         = 0.97,
                    m         = 0.12
                },
                new ParameterSet()
                {
                    Name      = "Liver Mets",
                    Type      = ParameterSetType.LiverMet,
                    AlphaBeta = new DoseValue(2.5, DoseUnit.Gy),
                    TD50      = new DoseValue(4070, DoseUnit.cGy),
                    n         = 0.97,
                    m         = 0.12
                }
            };

            _initialLoad                = false;
            SelectedStructure           = StructureList.First();
            SelectedDefaultParameterSet = DefaultParameterSets.First();

            log.Info("");
            LogManager.Shutdown();
        }
Exemple #5
0
        // Строим список [partOfString -- Lvl]
        static StructureList <MyStruct> ScanArithmeticExpression(string str)
        {
            char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            str = str.Replace('.', ',');
            str = str.Replace(" ", string.Empty);

            MyStruct[] data = {};
            StructureList <MyStruct> list = new StructureList <MyStruct>(data);
            int lvl = 0;

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '(')
                {
                    lvl++;
                    list.Add(new MyStruct {
                        PartOfString = str[i].ToString(), Lvl = lvl
                    });
                }

                if (digits.Contains(str[i]))
                {
                    string number = "";
                    while (digits.Contains(str[i]) || str[i] == ',')
                    {
                        number += str[i];
                        i++;
                    }

                    i--;

                    lvl++;
                    list.Add(new MyStruct {
                        PartOfString = number, Lvl = lvl
                    });
                }

                if (str[i] == '+' || str[i] == '-' || str[i] == '*' ||
                    str[i] == '/' || str[i] == ')')
                {
                    lvl--;
                    list.Add(new MyStruct {
                        PartOfString = str[i].ToString(), Lvl = lvl
                    });
                }
            }

            return(list);
        }
        public bool StructureDeletionPerformUpdates()
        {
            // Warn user if there are contoured structures to be deleted
            var contouredStructures = StructureList.Where(x => x.ToDelete && x.HasContours).Select(x => x.Structure);

            if (contouredStructures.Count() > 0)
            {
                var result = MessageBox.Show($"The following structures have contours, are you sure you want to delete them?\n\n{String.Join("\n", contouredStructures.Select(x => x.Id))}", "Confirm Structure Deletion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.No)
                {
                    return(false);
                }
            }

            Log.Initialize(_context);
            _context.Patient.BeginModifications();

            try
            {
                var ss       = _context.StructureSet;
                var failures = new List <Structure>();

                foreach (var struc in StructureList.Where(x => x.ToDelete).Select(x => x.Structure))
                {
                    if (ss.CanRemoveStructure(struc))
                    {
                        ss.RemoveStructure(struc);
                    }
                    else
                    {
                        failures.Add(struc);
                    }
                }

                if (failures.Count > 0)
                {
                    MessageBox.Show($"Could not delete structures:\n\n{String.Join("\n", failures.Select(x => x.Id))}\n\nPlease delete manually", "Error Deleting Structures", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch
            {
                MessageBox.Show($"Something failed when deleting structures, please delete them manually");
            }

            log.Info("Structure Deletion");
            LogManager.Shutdown();
            return(true);
        }
Exemple #7
0
        // Проверка, что ровно 2 элемента с макс уровнем
        static bool CheckCorrectStr(string str)
        {
            StructureList <MyStruct> list = ScanArithmeticExpression(str);
            int max   = GetMaxLvl(list);
            int count = 0;

            foreach (var element in list.Data)
            {
                if (element.Lvl == max)
                {
                    count++;
                }
            }

            return(count == 2);
        }
Exemple #8
0
        public void Parse(Stream s)
        {
            BinaryReader r = new BinaryReader(s);

            uint magic = r.ReadUInt32();

            if (checking)
            {
                if (magic != FOURCC("DATA"))
                {
                    throw new InvalidDataException(String.Format("Expected magic tag 0x{0:X8}; read 0x{1:X8}; position 0x{2:X8}",
                                                                 FOURCC("DATA"), magic, s.Position));
                }
            }

            version = r.ReadUInt32();

            //dataTablePosition = r.ReadUInt32() + (uint)r.BaseStream.Position - 4;
            if (!Util.GetOffset(r, out dataTablePosition))
            {
                throw new InvalidDataException(String.Concat("Invalid Data Table Position: 0x", dataTablePosition.ToString("X8")));
            }

            int dataCount = r.ReadInt32();

            //structureTablePosition = r.ReadUInt32() + (uint)r.BaseStream.Position - 4;
            if (!Util.GetOffset(r, out structureTablePosition))
            {
                throw new InvalidDataException(String.Concat("Invalid Structure Table Position: 0x", structureTablePosition.ToString("X8")));
            }

            int structureCount = r.ReadInt32();

            // Structure table

            this.structureList = new StructureList(OnResourceChanged, structureTablePosition, structureCount, r);

            this.dataList = new DataList(OnResourceChanged, this, dataCount, r);

            s.Position   = 0;
            this.rawData = r.ReadBytes((int)s.Length);
        }
Exemple #9
0
 void Awake()
 {
     this.factionID = this.GetInstanceID();
     structureList = GameObject.Find("_Lists").GetComponent<StructureList>();
     factionPlanetOwnershipMaterial = new Material(baseFactionPlanetOwnershipMaterial);
     factionPlanetOwnershipMaterial.color = factionColor;
 }
Exemple #10
0
 public void InitStructureListTest()
 {
     StructureList structList = new StructureList();
 }
Exemple #11
0
        protected override Stream UnParse()
        {
            Stream       s = new MemoryStream();
            BinaryWriter w = new BinaryWriter(s);

            if (this.structureList == null)
            {
                this.structureList = new StructureList(OnResourceChanged);
            }
            if (this.dataList == null)
            {
                this.dataList = new DataList(OnResourceChanged, this);
            }

            // Write Header with blank offsets
            w.Write((uint)FOURCC("DATA"));
            w.Write(this.version);
            w.Write(blank); // data table offset
            w.Write(this.dataList.Count);
            w.Write(blank); // structure table offset
            w.Write(this.structureList.Count);

            // Padding between header and data table?
            // Need more information
            // Debug.WriteLine(w.BaseStream.Position.ToString("X16"));
            //Util.Padding(w);
            w.Write(blank);
            w.Write(blank);


            // Write Data Table with blank Name and Structure offsets
            this.dataTablePosition = (uint)s.Position;
            this.dataList.UnParse(w);

            // Write Structure Table blank Name offsets
            this.structureTablePosition = (uint)s.Position;
            this.structureList.UnParse(w);



            // Write Names and set Name positions in data
            foreach (Structure structure in this.structureList)
            {
                foreach (Field field in structure.FieldTable)
                {
                    if (string.IsNullOrEmpty(field.Name))
                    {
                        field.NamePosition = Util.NullOffset;
                    }
                    else
                    {
                        field.NamePosition = (uint)s.Position;
                        Util.WriteString(w, field.Name);
                    }
                }
                if (string.IsNullOrEmpty(structure.Name))
                {
                    structure.NamePosition = Util.NullOffset;
                }
                else
                {
                    structure.NamePosition = (uint)s.Position;
                    Util.WriteString(w, structure.Name);
                }
            }
            foreach (Data data in this.dataList)
            {
                if (string.IsNullOrEmpty(data.Name))
                {
                    data.NamePosition = Util.NullOffset;
                }
                else
                {
                    data.NamePosition = (uint)s.Position;
                    Util.WriteString(w, data.Name);
                }
            }

            // Go back, calculate and write offsets

            this.structureList.WriteOffsets(w);
            this.dataList.WriteOffsets(w);

            // write the data table offset
            w.BaseStream.Position = 0x08;
            w.Write(dataTablePosition - w.BaseStream.Position);
            w.BaseStream.Position = 16;
            w.Write(structureTablePosition - w.BaseStream.Position); // dirty hack

            return(s);
        }
Exemple #12
0
        // Вычислить значение к скобках
        static StructureList <MyStruct> DeterminateExpression(StructureList <MyStruct> list)
        {
            // Найдем 2 элемента с максимальным уровнем
            int max = GetMaxLvl(list);

            MyStruct element1 = new MyStruct();

            element1.Lvl          = -1;
            element1.PartOfString = "";

            MyStruct element2 = new MyStruct();

            element1.Lvl          = -1;
            element1.PartOfString = "";

            int num = 0;

            foreach (var element in list)
            {
                if (element.Lvl == max)
                {
                    if (element1.Lvl == -1)
                    {
                        element1 = element;
                    }
                    else
                    {
                        element2 = element;
                        break;
                    }
                }

                num++;
            }

            // Номер операции (между двумя элементами)
            num--;
            string operation = list.Data[num].PartOfString;

            // Результат операции
            double res    = 0;
            double value1 = Double.Parse(element1.PartOfString);
            double value2 = Double.Parse(element2.PartOfString);

            if (operation == "+")
            {
                res = value1 + value2;
            }

            if (operation == "-")
            {
                res = value1 - value2;
            }

            if (operation == "*")
            {
                res = value1 * value2;
            }

            if (operation == "/")
            {
                res = Math.Round(value1 / value2, 3);
            }

            list.Remove(num - 2);
            list.Remove(num - 2);
            list.Remove(num - 2);
            list.Remove(num - 2);
            list.Remove(num - 2);

            MyStruct newRes = new MyStruct {
                PartOfString = res.ToString(CultureInfo.InvariantCulture), Lvl = max - 1
            };

            list.Add(newRes, num - 2);

            return(list);
        }
 /// <summary>
 /// Intializes a new <see cref="SuperflatGenerator"/>
 /// </summary>
 /// <param name="biome">The biome to use</param>
 /// <param name="layers">The layers to generate</param>
 /// <param name="structures">The structures which can spawn</param>
 public SuperflatGenerator(Layer[] layers, ID.Biome biome, StructureList structures) : base("flat")
 {
     Layers     = layers;
     Biome      = biome;
     Structures = structures;
 }