Skip to content

Commit

Permalink
Merge pull request #30 from usdot-fhwa-stol/hotfix/reduce_processing
Browse files Browse the repository at this point in the history
Multiple changes to increase performance of responding to TCRs
  • Loading branch information
snallamothu authored Jul 29, 2022
2 parents 99c20d2 + 7b4cdad commit e886a47
Show file tree
Hide file tree
Showing 19 changed files with 672 additions and 428 deletions.
73 changes: 8 additions & 65 deletions src/cc/ctrl/CtrlGeo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import cc.geosrv.Mercator;
import cc.util.Arrays;
import cc.util.Geo;
import cc.util.MathUtil;
import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.io.DataInputStream;
Expand All @@ -22,9 +21,8 @@
*
* @author aaron.cherney
*/
public class CtrlGeo implements Comparable<CtrlGeo>
public class CtrlGeo
{
public byte[] m_yId;
/**
* negative tangent path
*/
Expand All @@ -41,51 +39,16 @@ public class CtrlGeo implements Comparable<CtrlGeo>
public double[] m_dBB = new double[] {Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE};
public ArrayList<int[]> m_oTiles = new ArrayList();
int m_nZoom;
public int m_nCtrlType;
public byte[] m_yCtrlValue;
public double m_dLength;
public double m_dAverageWidth = 0.0;
public double[] m_dDebugNT;
public double[] m_dDebugPT;
public boolean[] m_bDow = new boolean[7];


public CtrlGeo(DataInputStream oIn, int nZoom)
throws IOException
{
this(oIn, false, nZoom);
}


public CtrlGeo(DataInputStream oIn, boolean bUpdateTiles, int nZoom)
CtrlGeo(DataInputStream oIn, boolean bUpdateTiles, int nZoom)
throws IOException
{
m_nZoom = nZoom;
oIn.readUTF(); // read version, discard it
m_yId = new byte[16];
oIn.read(m_yId);
oIn.skip(8); // skip updated, long

int nCount = oIn.readInt();
oIn.skip(nCount * 4); // skip vehicle types, they are ints
oIn.skip(20); // skip start, end, DoW (long, long ,int)
nCount = oIn.readInt();
oIn.skip(nCount * 8); // skip between which is pairs of ints
oIn.skip(13); // skip offset, period, span, regulatory (int, int, int, bool)

m_nCtrlType = oIn.readInt();
m_yCtrlValue = new byte[oIn.readInt()];
oIn.read(m_yCtrlValue);

oIn.readUTF(); // read proj, discard it
oIn.readUTF(); // read datum, discard it

oIn.skip(28); // skip time, lon, lat, alt, width, heading (long, int, int, int, int, int)
oIn.readUTF(); // read label, discard it

nCount = oIn.readInt();
oIn.skip(nCount * 16); // skip all the points (each are 4 ints)

m_nZoom = nZoom;
for (int nIndex = 0; nIndex < m_dBB.length; nIndex++)
m_dBB[nIndex] = oIn.readInt() / 100.0; // convert mercator cm to mercator meters

Expand All @@ -106,15 +69,10 @@ public CtrlGeo(DataInputStream oIn, boolean bUpdateTiles, int nZoom)
}


public CtrlGeo(TrafCtrl oCtrl, double dMaxStep, int nZoom)
CtrlGeo(TrafCtrl oCtrl, double dMaxStep, int nZoom)
throws Exception
{
m_nZoom = nZoom;
m_yId = new byte[oCtrl.m_yId.length];
m_nCtrlType = oCtrl.m_nControlType;
m_yCtrlValue = new byte[oCtrl.m_yControlValue.length];
System.arraycopy(oCtrl.m_yControlValue, 0, m_yCtrlValue, 0, m_yCtrlValue.length);
System.arraycopy(oCtrl.m_yId, 0, m_yId, 0, m_yId.length);
int nNumPts = oCtrl.size();
double dTotalLength = 0.0;
double[] dPts = Arrays.newDoubleArray(nNumPts * 3);
Expand Down Expand Up @@ -382,8 +340,8 @@ public static void writePts(DataOutputStream oOut, double[] dPts)
throws IOException
{
oOut.writeInt(Arrays.size(dPts) - 1);
int nPrevX = (int)(MathUtil.round(dPts[1] * 100.0, 0)); // convert mercator meters to mercator cms, rounding to nearest cm
int nPrevY = (int)(MathUtil.round(dPts[2] * 100.0, 0));
int nPrevX = (int)(dPts[1] * 100.0 + 0.5); // convert mercator meters to mercator cms, rounding to nearest cm
int nPrevY = (int)(dPts[2] * 100.0 + 0.5);
oOut.writeInt(nPrevX);
oOut.writeInt(nPrevY);
Iterator<double[]> oIt = Arrays.iterator(dPts, new double[2], 3, 2);
Expand All @@ -392,8 +350,8 @@ public static void writePts(DataOutputStream oOut, double[] dPts)
while (oIt.hasNext())
{
double[] dPt = oIt.next();
nCurX = (int)(MathUtil.round(dPt[0] * 100.0, 0)); // convert mercator meters to mercator cms, rounding to nearest cm
nCurY = (int)(MathUtil.round(dPt[1] * 100.0, 0));
nCurX = (int)(dPt[0] * 100.0 + 0.5); // convert mercator meters to mercator cms, rounding to nearest cm
nCurY = (int)(dPt[1] * 100.0 + 0.5);
oOut.writeByte(nCurX - nPrevX); // write the deltas in the file
oOut.writeByte(nCurY - nPrevY);
nPrevX = nCurX;
Expand Down Expand Up @@ -471,21 +429,6 @@ public static int[] readPtsLonLats(DataInputStream oIn, int[] nPts)

return nPts;
}


@Override
public int compareTo(CtrlGeo o)
{
int nRet = 0;
for (int nIndex = 0; nIndex < m_yId.length; nIndex++)
{
nRet = m_yId[nIndex] - o.m_yId[nIndex];
if (nRet != 0)
return nRet;
}

return nRet;
}


public Area createPolygon()
Expand Down
33 changes: 33 additions & 0 deletions src/cc/ctrl/CtrlIndex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cc.ctrl;

import java.io.DataInputStream;
import java.io.IOException;

/**
*
* @author aaron.cherney
*/
public class CtrlIndex
{
public byte[] m_yId;
public int m_nType;
public long m_lStart;
public long m_lEnd;
public double[] m_dBB;

public CtrlIndex(DataInputStream oIn)
throws IOException
{
m_nType = oIn.readInt();
m_yId = new byte[16];
oIn.read(m_yId);
m_lStart = oIn.readLong();
m_lEnd = oIn.readLong();
m_dBB = new double[]{oIn.readInt() / 100.0, oIn.readInt() / 100.0, oIn.readInt() / 100.0, oIn.readInt() / 100.0};
}
}
9 changes: 2 additions & 7 deletions src/cc/ctrl/RenderCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ public static void main(String[] sArgs)
TrafCtrl oCtrl = null;
try (DataInputStream oIn = new DataInputStream(new BufferedInputStream(Files.newInputStream(Paths.get(sFile)))))
{
oCtrl = new TrafCtrl(oIn, false);
}

try (DataInputStream oIn = new DataInputStream(new BufferedInputStream(Files.newInputStream(Paths.get(sFile)))))
{
oCtrl.m_oFullGeo = new CtrlGeo(oIn, true, nZoom);
oCtrl = new TrafCtrl(oIn, true, true);
}

ArrayList<int[]> nTiles = new ArrayList();
Expand All @@ -54,7 +49,7 @@ public static void main(String[] sArgs)
for (int[] nTile : nTiles)
{
String sIndex = String.format(sTdFF, nTile[0], nZoom, nTile[0], nTile[1]) + ".ndx";
ProcCtrl.updateIndex(sIndex, oCtrl.m_yId, lNow);
ProcCtrl.updateIndex(sIndex, oCtrl, lNow);
}

oCtrl.m_yId = null;
Expand Down
Loading

0 comments on commit e886a47

Please sign in to comment.