import java.awt.Graphics; import java.util.Iterator; public class DrawVoronoi implements IDrawAgent { double m_lfMaxLen; int m_nColor=12; { m_lfMaxLen = 15.0; } IStateAccessor m_stateAccess; { m_stateAccess = new StateAccessors.PassThrough(); } public DrawVoronoi() { } public DrawVoronoi(double lfMaxLen) { m_lfMaxLen = lfMaxLen; } public DrawVoronoi(double lfMaxLen, IStateAccessor access) { m_lfMaxLen = lfMaxLen; m_stateAccess = access; } public void setColor(int nColor) { m_nColor=nColor; } public void draw(java.awt.Graphics g, IProjection p, double[] arrLfPoints, StateBundle[] arrAgentStates, CommGraph graph) { g.setColor(globalsUI.getColorMap().getColor(9)); if(arrAgentStates == null) { return; } for(int nId = 0; nId < arrAgentStates.length; ++nId) { try { g.setColor(globalsUI.getColorMap().getColor(m_nColor)); ILogicVarBundle bundle = arrAgentStates[nId].getVars(); bundle = m_stateAccess.access(bundle); IVoronoiHolder voronoi = (IVoronoiHolder)bundle; DistributedDelaunayClip clipData = voronoi.getClipAgent(); Iterator edgeIter = clipData.iterator(); double [] arrLfFirstPt = null; double [] arrLfLastPt = null; int nRad = 0; try { nRad = p.scaleRadius(m_lfMaxLen); } catch(Exception e) { nRad = 0; } double lfLastAng = 0.0; while(edgeIter.hasNext()) { DistributedDelaunayClip.Edge edge = edgeIter.next(); double [] arrLfEnd = clipData.getEdgeEnd(edge,m_lfMaxLen); double [] arrLfStart = clipData.getEdgeStart(edge,m_lfMaxLen); if(arrLfFirstPt == null) { arrLfFirstPt = arrLfStart; } g.drawLine(p.getScreenComp(0, arrLfStart, 0), p.getScreenComp(1, arrLfStart, 0), p.getScreenComp(0, arrLfEnd, 0), p.getScreenComp(1, arrLfEnd, 0)); /* if(arrLfLastPt != null) { lfLastAng = Math.atan2(arrLfLastPt[1], arrLfLastPt[0]); double lfNextAng = Math.atan2(arrLfStart[1], arrLfStart[0]); int nSweepStart = (int)(180.0*lfLastAng/Math.PI); int nSweepEnd = (int)(180.0*lfNextAng/Math.PI); g.drawArc(p.getScreenComp(0, arrLfPoints, 2*nId)-nRad, p.getScreenComp(1, arrLfPoints, 2*nId)-nRad, 2*nRad, 2*nRad, nSweepStart, nSweepEnd-nSweepStart); }*/ arrLfLastPt = arrLfEnd; } } catch(java.lang.ClassCastException e) { } } } }