Skip to content
Snippets Groups Projects
Unverified Commit 7aa8e7f5 authored by SebastianDirks's avatar SebastianDirks Committed by GitHub
Browse files

Merge pull request #11 from Digital-Production-Aachen/CLI_ASCII

Added ASCII support to CLI reader
parents 58415f17 cedd1072
No related branches found
No related tags found
No related merge requests found
......@@ -566,7 +566,7 @@ namespace OpenVectorFormat.ILTFileReaderAdapter
var yDif = Math.Abs(coords[3] - coords[5]);
if (xDif < minJumpLength && yDif < minJumpLength)
{
fakeHatches = true;
//fakeHatches = true;
}
}
......
......
......@@ -64,7 +64,19 @@ namespace OpenVectorFormat.ILTFileReader.Controller
{
sR = new StreamReader(filePath);
Header = ReadHeader();
Geometry = new Geometry(ReadBinaryContent());
IList<ILayer> layers;
switch (header.DataFormat)
{
case DataFormatType.binary:
layers = ReadBinaryContent();
break;
case DataFormatType.ASCII:
layers = ReadASCIIContent();
break;
default:
throw new FileLoadException("unknown format type");
}
Geometry = new Geometry(layers);
}
public enum BinaryWriteStyle
......@@ -150,7 +162,6 @@ namespace OpenVectorFormat.ILTFileReader.Controller
if (line.Equals("$$ASCII"))
{
this.header.DataFormat = DataFormatType.ASCII;
throw new FileLoadException("ASCII Format is not supported at the moment");
}
if ((match = Regex.Match(line, @"\$\$UNITS\/(.*)")).Success)
......@@ -315,6 +326,59 @@ namespace OpenVectorFormat.ILTFileReader.Controller
return layers;
}
private IList<ILayer> ReadASCIIContent()
{
String line;
IList<ILayer> layers = new List<ILayer>();
Layer currentLayer = null;
//read first line
if (this.sR.ReadLine() != "$$GEOMETRYSTART") throw new FileLoadException("no geometry found");
while ((line = this.sR.ReadLine()) != null)
{
//optimization: hatches are most common, polylines 2nd
if (line.StartsWith(@"$$HATCHES/"))
{
var numberStrings = line.Substring(10).Split(',');
if (numberStrings.Length < 4)
{
throw new FileLoadException("invalid hatches: " + line);
}
int id = int.Parse(numberStrings[0], NumberStyles.Any, CultureInfo.InvariantCulture);
int n = int.Parse(numberStrings[1], NumberStyles.Any, CultureInfo.InvariantCulture);
float[] coordinates = new float[numberStrings.Length-2];
for(int i=0; i< coordinates.Length; i++)
{
coordinates[i] = float.Parse(numberStrings[i+2], NumberStyles.Any, CultureInfo.InvariantCulture);
}
currentLayer.VectorBlocks.Add(new Hatches(id, n, coordinates));
}
if (line.StartsWith(@"$$POLYLINE/"))
{
var numberStrings = line.Substring(11).Split(',');
if (numberStrings.Length < 5)
{
throw new FileLoadException("invalid hatches: " + line);
}
int id = int.Parse(numberStrings[0], NumberStyles.Any, CultureInfo.InvariantCulture);
Direction dir = (Direction) int.Parse(numberStrings[1], NumberStyles.Any, CultureInfo.InvariantCulture);
int n = int.Parse(numberStrings[2], NumberStyles.Any, CultureInfo.InvariantCulture);
float[] coordinates = new float[numberStrings.Length - 3];
for (int i = 0; i < coordinates.Length; i++)
{
coordinates[i] = float.Parse(numberStrings[i + 3], NumberStyles.Any, CultureInfo.InvariantCulture);
}
currentLayer.VectorBlocks.Add(new Polyline(id, dir, n, coordinates));
}
if (line.StartsWith(@"$$LAYER/"))
{
float height = float.Parse(line.Substring(8), NumberStyles.Any, CultureInfo.InvariantCulture);
currentLayer = new Layer(height);
layers.Add(currentLayer);
}
}
return layers;
}
/// <summary>
/// write the given header
/// </summary>
......
......
......@@ -33,8 +33,8 @@ namespace OpenVectorFormat.ILTFileReader.Model
{
class Hatches : VectorBlock, ILTFileReader.IHatches
{
public float[] coordinates;
private bool isASCII = false;
private float[] coordinates;
public Hatches(long offsetInFile, int id, int n, bool isLong, BinaryReader reader)
{
......@@ -45,12 +45,22 @@ namespace OpenVectorFormat.ILTFileReader.Model
this.reader = reader;
}
public Hatches(int id, int n, float[] coordinates)
{
Id = id;
N = n;
isASCII = true;
this.coordinates = coordinates;
}
override public float[] Coordinates
{
get
{
if (IsLong)
if (isASCII)
return coordinates;
else if (IsLong)
return readHelper.readFloatArray(reader, OffsetInFile, N * 4 * 4);
else
return readHelper.readFloatArrayFromUshorts(reader, OffsetInFile, N * 4 * 2);
......
......
......@@ -39,6 +39,13 @@ namespace OpenVectorFormat.ILTFileReader.Model
this.isLong = isLong;
this.VectorBlocks = new List<IVectorBlock>();
}
public Layer(float height)
{
Height = height;
this.VectorBlocks = new List<IVectorBlock>();
}
public long OffsetInFile
{
get;
......
......
......@@ -33,6 +33,8 @@ namespace OpenVectorFormat.ILTFileReader.Model
{
class Polyline: VectorBlock,ILTFileReader.IPolyline
{
private bool isASCII = false;
private float[] coordinates;
public Polyline(long offsetInFile, int id, Direction dir, int n, bool isLong, BinaryReader reader)
{
OffsetInFile = offsetInFile;
......@@ -43,11 +45,23 @@ namespace OpenVectorFormat.ILTFileReader.Model
this.reader = reader;
}
public Polyline(int id, Direction dir, int n, float[] coordinates)
{
Id = id;
this.N = n;
this.Dir = dir;
isASCII = true;
this.coordinates = coordinates;
}
override public float[] Coordinates
{
get
{
if (IsLong)
if (isASCII)
return coordinates;
else if (IsLong)
return readHelper.readFloatArray(reader, OffsetInFile, N * 2 * 4);
else
return readHelper.readFloatArrayFromUshorts(reader, OffsetInFile, N * 2 * 2);
......
......
This diff is collapsed.
......@@ -74,7 +74,7 @@ namespace OpenVectorFormat.ReaderWriter.UnitTests
CheckerConfig config = new CheckerConfig
{
CheckLineSequencesClosed = CheckAction.CHECKERROR,
CheckLineSequencesClosed = CheckAction.DONTCHECK,
CheckMarkingParamsKeys = CheckAction.CHECKERROR,
CheckPartKeys = CheckAction.CHECKERROR,
CheckPatchKeys = CheckAction.DONTCHECK,
......
......
......@@ -46,6 +46,12 @@
<None Update="TestFiles\ASP_Simple_Test.asp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Elephant_ASCII.cli">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\frustrum_ASCII.cli">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\s_Cylinder_ex.cli">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment