Skip to content

Commit

Permalink
Fixed quantization on linux/max
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarbuz committed Nov 24, 2019
1 parent 62935e8 commit 4ed20ee
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
10 changes: 6 additions & 4 deletions SchematicToVoxCore/Converter/PointCloud/CSVToSchematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public CSVToSchematic(string path, int scale) : base(path, scale)
string s = data[i];
values[i] = float.Parse(s, CultureInfo.InvariantCulture);
}
bodyVertices.Add(new Vector3(values[2], values[3], values[4]));
bodyColors.Add(Color.FromArgb((byte)Math.Round(values[6] * 255),
(byte)Math.Round(values[7] * 255),
(byte)Math.Round(values[8] * 255)));

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)
{
Expand Down
2 changes: 1 addition & 1 deletion SchematicToVoxCore/Converter/PointCloud/PLYToSchematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public override Schematic WriteSchematic()
List<Block> list = Quantization.ApplyQuantization(_blocks);
list.ApplyOffset(new Vector3(minX, minY, minZ));
HashSet<Block> hashSet = list.ToHashSet();
RemoveHoles(ref hashSet, schematic);
//RemoveHoles(ref hashSet, schematic);
schematic.Blocks = hashSet;

return schematic;
Expand Down
2 changes: 1 addition & 1 deletion SchematicToVoxCore/Converter/PointCloud/XYZToSchematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override Schematic WriteSchematic()
List<Block> list = Quantization.ApplyQuantization(_blocks);
list.ApplyOffset(new Vector3(minX, minY, minZ));
HashSet<Block> hashSet = list.ToHashSet();
RemoveHoles(ref hashSet, schematic);
//RemoveHoles(ref hashSet, schematic);
schematic.Blocks = hashSet;

return schematic;
Expand Down
26 changes: 18 additions & 8 deletions SchematicToVoxCore/Extensions/Quantization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ public static class Quantization
public static List<Block> ApplyQuantization(List<Block> blocks)
{
WuQuantizer quantizer = new WuQuantizer();
using (Bitmap bitmap = CreateBitmapFromColors(blocks))
try
{
using (Image quantized = quantizer.QuantizeImage(bitmap))
using (Bitmap bitmap = CreateBitmapFromColors(blocks))
{
Bitmap reducedBitmap = new Bitmap(quantized);
int width = reducedBitmap.Size.Width;
for (int i = 0; i < blocks.Count; i++)
using (Image quantized = quantizer.QuantizeImage(bitmap))
{
int x = i % width;
int y = i / width;
blocks[i] = new Block(blocks[i].X, blocks[i].Y, blocks[i].Z, reducedBitmap.GetPixel(x, y).ColorToUInt());
Bitmap reducedBitmap = (Bitmap) quantized;
//Console.WriteLine(quantized.PixelFormat);
//Bitmap reducedBitmap = new Bitmap(quantized);
int width = reducedBitmap.Size.Width;
for (int i = 0; i < blocks.Count; i++)
{
int x = i % width;
int y = i / width;
blocks[i] = new Block(blocks[i].X, blocks[i].Y, blocks[i].Z,
reducedBitmap.GetPixel(x, y).ColorToUInt());
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}

return blocks;
}
Expand Down

0 comments on commit 4ed20ee

Please sign in to comment.