protected void VoxelizeData(BodyDataDTO data) { Vector3 minX = data.BodyVertices.MinBy(t => t.X); Vector3 minY = data.BodyVertices.MinBy(t => t.Y); Vector3 minZ = data.BodyVertices.MinBy(t => t.Z); float min = Math.Abs(Math.Min(minX.X, Math.Min(minY.Y, minZ.Z))); for (int i = 0; i < data.BodyVertices.Count; i++) { data.BodyVertices[i] += new Vector3(min, min, min); data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * _scale), (float)Math.Truncate(data.BodyVertices[i].Y * _scale), (float)Math.Truncate(data.BodyVertices[i].Z * _scale)); } HashSet <Vector3> set = new HashSet <Vector3>(); List <Vector3> vertices = new List <Vector3>(); List <Color> colors = new List <Color>(); Console.WriteLine("[LOG] Started to voxelize data..."); using (ProgressBar progressbar = new ProgressBar()) { for (int i = 0; i < data.BodyVertices.Count; i++) { if (!set.Contains(data.BodyVertices[i])) { set.Add(data.BodyVertices[i]); vertices.Add(data.BodyVertices[i]); colors.Add(data.BodyColors[i]); } progressbar.Report(i / (float)data.BodyVertices.Count); } } Console.WriteLine("[LOG] Done."); minX = vertices.MinBy(t => t.X); minY = vertices.MinBy(t => t.Y); minZ = vertices.MinBy(t => t.Z); min = Math.Min(minX.X, Math.Min(minY.Y, minZ.Z)); for (int i = 0; i < vertices.Count; i++) { float max = Math.Max(vertices[i].X, Math.Max(vertices[i].Y, vertices[i].Z)); if (/*max - min < 8000 && */ max - min >= 0) { vertices[i] -= new Vector3(min, min, min); _blocks.Add(new Voxel((ushort)vertices[i].X, (ushort)vertices[i].Y, (ushort)vertices[i].Z, colors[i].ColorToUInt())); } } }
protected sealed override BodyDataDTO ReadContentFile() { BodyDataDTO dataFile = new BodyDataDTO(); List <Vector3> bodyVertices = new List <Vector3>(); List <Color> bodyColors = new List <Color>(); using (StreamReader reader = new StreamReader(_path)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); line = line.Replace(" ", ""); string[] data = line.Split(','); if (data.Length > 14) { try { float[] values = new float[data.Length]; for (int i = 0; i < data.Length; i++) { string s = data[i]; values[i] = float.Parse(s, CultureInfo.InvariantCulture); } Vector3 vertice = new Vector3(values[11], values[12], values[13]); bodyVertices.Add(vertice); bodyColors.Add(Color.FromArgb((byte)Math.Round(values[7] * 255), (byte)Math.Round(values[8] * 255), (byte)Math.Round(values[9] * 255))); } catch (Exception e) { } } } } dataFile.BodyColors = bodyColors; dataFile.BodyVertices = bodyVertices; return(dataFile); }
protected sealed override BodyDataDTO ReadContentFile() { BodyDataDTO dataFile = new BodyDataDTO(); StreamReader file = new StreamReader(PathFile); string line; List <Vector3> bodyVertices = new List <Vector3>(); List <Color> bodyColors = new List <Color>(); while ((line = file.ReadLine()) != null) { string[] data = line.Split(' '); if (data.Length < 6) { Console.WriteLine("[ERROR] Line not well formated : " + line); } else { try { float x = float.Parse(data[0], CultureInfo.InvariantCulture); float y = float.Parse(data[1], CultureInfo.InvariantCulture); float z = float.Parse(data[2], CultureInfo.InvariantCulture); int r = int.Parse(data[3], CultureInfo.InvariantCulture); int g = int.Parse(data[4], CultureInfo.InvariantCulture); int b = int.Parse(data[5], CultureInfo.InvariantCulture); bodyVertices.Add(new Vector3(x, y, z)); bodyColors.Add(Color.FromArgb(r, g, b)); } catch (Exception e) { Console.WriteLine("[ERROR] Line not well formated : " + line + " " + e.Message); } } } dataFile.BodyVertices = bodyVertices; dataFile.BodyColors = bodyColors; return(dataFile); }
public XYZToSchematic(string path, float scale, int colorLimit) : base(path, scale, colorLimit) { BodyDataDTO data = ReadContentFile(); VoxelizeData(data); }
protected void VoxelizeData(BodyDataDTO data) { mSchematic = new Schematic(); if (data.BodyVertices.Count == 0) { return; } Vector3 minX = data.BodyVertices.MinBy(t => t.X); Vector3 minY = data.BodyVertices.MinBy(t => t.Y); Vector3 minZ = data.BodyVertices.MinBy(t => t.Z); float min = Math.Abs(Math.Min(minX.X, Math.Min(minY.Y, minZ.Z))); for (int i = 0; i < data.BodyVertices.Count; i++) { data.BodyVertices[i] += new Vector3(min, min, min); //data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * Scale), (float)Math.Truncate(data.BodyVertices[i].Y * Scale), (float)Math.Truncate(data.BodyVertices[i].Z * Scale)); } Vector3 maxX = data.BodyVertices.MaxBy(t => t.X); Vector3 maxY = data.BodyVertices.MaxBy(t => t.Y); Vector3 maxZ = data.BodyVertices.MaxBy(t => t.Z); Console.WriteLine("[INFO] Max X: " + maxX.X + ", Y: " + maxY.Y + ", " + maxZ.Z); minX = data.BodyVertices.MinBy(t => t.X); minY = data.BodyVertices.MinBy(t => t.Y); minZ = data.BodyVertices.MinBy(t => t.Z); Console.WriteLine("[INFO] Min X: " + minX.X + ", Y: " + minY.Y + ", " + minZ.Z); Vector3 size = new Vector3(maxX.X - minX.X, maxY.Y - minY.Y, maxZ.Z - minZ.Z); Console.WriteLine("[INFO] Size X: " + size.X + ", Y: " + size.Y + ", " + size.Z); float max = Math.Max(size.X, Math.Max(size.Y, size.Z)); float factor = Scale / max; for (int i = 0; i < data.BodyVertices.Count; i++) { data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * factor), (float)Math.Truncate(data.BodyVertices[i].Y * factor), (float)Math.Truncate(data.BodyVertices[i].Z * factor)); } minX = data.BodyVertices.MinBy(t => t.X); minY = data.BodyVertices.MinBy(t => t.Y); minZ = data.BodyVertices.MinBy(t => t.Z); //HashSet<Vector3> set = new HashSet<Vector3>(); min = Math.Min(minX.X, Math.Min(minY.Y, minZ.Z)); Console.WriteLine("[INFO] Started to voxelize data..."); using (ProgressBar progressbar = new ProgressBar()) { for (int i = 0; i < data.BodyVertices.Count; i++) { float maxV = Math.Max(data.BodyVertices[i].X, Math.Max(data.BodyVertices[i].Y, data.BodyVertices[i].Z)); if (maxV - min >= 0) { data.BodyVertices[i] -= new Vector3(min, min, min); mSchematic.AddVoxel((int)(data.BodyVertices[i].X - minX.X), (int)(data.BodyVertices[i].Y - minY.Y), (int)(data.BodyVertices[i].Z - minZ.Z), data.BodyColors[i].ColorToUInt()); } //if (!set.Contains(data.BodyVertices[i])) //{ // set.Add(data.BodyVertices[i]); // //vertices.Add(data.BodyVertices[i]); // //colors.Add(data.BodyColors[i]); //} progressbar.Report(i / (float)data.BodyVertices.Count); } } Console.WriteLine("[INFO] Done."); //minX = vertices.MinBy(t => t.X); //minY = vertices.MinBy(t => t.Y); //minZ = vertices.MinBy(t => t.Z); //for (int i = 0; i < vertices.Count; i++) //{ // float max = Math.Max(vertices[i].X, Math.Max(vertices[i].Y, vertices[i].Z)); // if (/*max - min < 8000 && */max - min >= 0) // { // vertices[i] -= new Vector3(min, min, min); // _blocks.Add(new Voxel((ushort)vertices[i].X, (ushort)vertices[i].Y, (ushort)vertices[i].Z, colors[i].ColorToUInt())); // } //} }
public CSVToSchematic(string path, float scale, int colorLimit, bool holes, bool flood, bool lonely) : base(path, scale, colorLimit, holes, flood, lonely) { BodyDataDTO data = ReadContentFile(); VoxelizeData(data); }