/* * Parallel.For(0, ny, j => * { * }); */ public void Apply(Grid grid, int index) { ModifiersGroup mgroup = this.Groups[index]; int dz = mgroup.Modifiers.Count(); mgroup.Applied = !mgroup.Applied; for (int k = 0; k < dz; ++k) { if (mgroup.Modifiers[k].Use) { this.Apply(grid, mgroup.Modifiers[k], mgroup.Applied); } } }
public static Prop Read(BinaryReader reader) { byte version = reader.ReadByte(); switch (version) { case Version0: { string title = reader.ReadString(); int nx = reader.ReadInt32(); int ny = reader.ReadInt32(); int nz = reader.ReadInt32(); double[,,] values = new double[nx, ny, nz]; for (int i = 0; i < nx; ++i) { for (int j = 0; j < ny; ++j) { for (int k = 0; k < nz; ++k) { values[i, j, k] = reader.ReadDouble(); } } } int nm = reader.ReadInt32(); List <ModifiersGroup> mg = new List <ModifiersGroup>(); for (int m = 0; m < nm; ++m) { mg.Add(ModifiersGroup.Read(reader)); } PropScale scale = PropScale.Read(reader); return(new Prop(title, values, mg, scale)); } default: return(new Prop()); } }
/* * public void Apply(Grid grid, int index) * { * Modifier modifier = this.Modifiers[index]; * float c = (modifier.Value - 1) / modifier.Radius; * int NX = grid.NX(), NY = grid.NY(), NZ = grid.NZ(); * if (!modifier.Applied) * { * for (int i = 0; i < NX; ++i) * for (int j = 0; j < NY; ++j) * { * Point3D center = grid.LocalCell(i, j, 0).MiddleTopFace().Center(); * double x = modifier.Location.X - center.X; * double y = modifier.Location.Y - center.Y; * float d = (float)Math.Pow(x * x + y * y, 0.5); * if (d <= modifier.Radius) * foreach (int k in modifier.Layers) * this.Values[i, j, k] *= (c * (modifier.Radius - d) + 1); * } * } * else * { * for (int i = 0; i < NX; ++i) * for (int j = 0; j < NY; ++j) * { * Point3D center = grid.LocalCell(i, j, 0).MiddleTopFace().Center(); * double x = modifier.Location.X - center.X; * double y = modifier.Location.Y - center.Y; * float d = (float)Math.Pow(x * x + y * y, 0.5); * if (d <= modifier.Radius) * foreach (int k in modifier.Layers) * this.Values[i, j, k] /= (c * (modifier.Radius - d) + 1); * } * } * modifier.Applied = !modifier.Applied; * } */ public void AddAndApply(Grid grid, ModifiersGroup m) { this.Groups.Add(m); Apply(grid, Groups.Count - 1); }