import java.io.Reader; import java.io.Writer; /** * Implementat ion of * interface for specifying per-agent information neccessary to * perform formation morphing to morph to a rectangle with a * "comb" topology. Rect width is specified at construction time. * @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class MorphSpecFourCombs implements IMorphSpec { int m_nWidth; double m_lfDist; /** * defaults for the first demo */ public MorphSpecFourCombs() { m_lfDist = 0.2; m_nWidth = 2; } public MorphSpecFourCombs(int nRectWidth, double lfSpacing) { m_lfDist = lfSpacing; m_nWidth = nRectWidth; } public double [] getFinalUv(int nAgentId) { int nGrp = nAgentId %4; nAgentId = (nAgentId +3)/ 4; double [] arrLfUv = new double[2]; if(nAgentId == 0) { arrLfUv[0] = arrLfUv[1] = 0.0; } else if(nAgentId == 1) { if(nGrp == 0) { arrLfUv[0] = 0.0; arrLfUv[1] = m_lfDist; } else if(nGrp == 1) { arrLfUv[0] = m_lfDist; arrLfUv[1] = 0.0; } else if(nGrp == 2) { arrLfUv[0] = 0.0; arrLfUv[1] = -m_lfDist; } else if(nGrp == 3) { arrLfUv[0] = -m_lfDist; arrLfUv[1] = 0.0; } } else if(nAgentId % m_nWidth == 1) { arrLfUv[0] = 0.0; arrLfUv[1] = m_lfDist; } else { arrLfUv[0] = -m_lfDist; arrLfUv[1] = 0.0; } return arrLfUv; } int getGrpOff(int nGrp) { return nGrp*( (m_nWidth+m_nWidth+1)*m_nWidth ); } public int getNumChildren(int nAgentId) { if(nAgentId == 0) { return 4; } nAgentId = (nAgentId +3)/ 4; if(nAgentId % m_nWidth == 0 && nAgentId/m_nWidth < m_nWidth-1) { return 2; } return 1; } public int getTopoLastVisit(int nAgentId) { int nGrp = nAgentId %4; nAgentId = (nAgentId +3)/ 4; if(nAgentId == 0) { return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ m_nWidth-1+2*m_nWidth*(m_nWidth-nAgentId/m_nWidth)+ getGrpOff(3); } if(nAgentId % m_nWidth == 0) { return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ m_nWidth-1+2*m_nWidth*(m_nWidth-nAgentId/m_nWidth)+ getGrpOff(nGrp); } else { return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ m_nWidth+m_nWidth-(nAgentId % m_nWidth)-1+ getGrpOff(nGrp); } } public int getTopoFirstVisit(int nAgentId) { int nGrp = nAgentId %4; nAgentId = (nAgentId+3) / 4; return (m_nWidth+m_nWidth-1)*(nAgentId/m_nWidth)+ (nAgentId % m_nWidth)+getGrpOff(nGrp); } public int getTopoDepth(int nAgentId) { // int nGrp = nAgentId %4; nAgentId = (nAgentId+3) / 4; return (nAgentId/m_nWidth) + (nAgentId%m_nWidth); } public int getMaxDepth() { return 2*m_nWidth; } /** * Make this more then a stub later */ public void dump(Writer writeTo) {} /** * Make this more then a stub later */ public void load(Reader readFrom) {} }