|
|
/home/brennan/Software/sensix/source/C^4/Node.javaGo to the documentation of this file.00001 00010 /* 00011 * Copyright 2008. Los Alamos National Security, LLC. This material 00012 * was produced under U.S. Government contract DE-AC52-06NA25396 for 00013 * Los Alamos National Laboratory (LANL), which is operated by Los 00014 * Alamos National Security, LLC, for the Department of Energy. The 00015 * U.S. Government has rights to use, reproduce, and distribute this 00016 * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, 00017 * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL 00018 * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to 00019 * produce derivative works, such modified software should be clearly 00020 * marked, so as not to confuse it with the version available from LANL. 00021 * 00022 * Additionally, this program is free software; you can redistribute 00023 * it and/or modify it under the terms of the GNU General Public 00024 * License as published by the Free Software Foundation; version 2 of 00025 * the License. Accordingly, this program is distributed in the hope 00026 * it will be useful, but WITHOUT ANY WARRANTY; without even the 00027 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00028 * PURPOSE. See the GNU General Public License for more details. 00029 * 00030 * You should have received a copy of the GNU General Public License 00031 * along with this program; if not, write to the Free Software 00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00033 */ 00034 00035 00036 public class Node implements java.io.Serializable 00037 { 00038 transient protected int seq_num; 00039 protected int id; 00040 protected boolean rand_loc; 00041 protected double x; 00042 protected double y; 00043 protected double z; 00044 protected NodeGroup mygroup; 00045 00046 public Node() { 00047 seq_num = Network.TOTAL_NODES; 00048 Network.TOTAL_NODES++; 00049 rand_loc = false; 00050 x = y = z = 0.0; 00051 } 00052 00053 public Node(Node n) { 00054 seq_num = n.getSeq_num(); 00055 id = n.getId(); 00056 rand_loc = n.getRand_loc(); 00057 x = n.getX(); 00058 y = n.getY(); 00059 z = n.getZ(); 00060 mygroup = n.getMygroup(); 00061 } 00062 00063 public int getId() { 00064 return id; 00065 } 00066 00067 public int getSeq_num() { 00068 return seq_num; 00069 } 00070 00071 public boolean getRand_loc() { 00072 return rand_loc; 00073 } 00074 00075 public double getX() { 00076 return x; 00077 } 00078 00079 public double getY() { 00080 return y; 00081 } 00082 00083 public double getZ() { 00084 return z; 00085 } 00086 00087 public NodeGroup getMygroup() { 00088 return mygroup; 00089 } 00090 00091 public void setSeq_num(int i) { 00092 seq_num = i; 00093 } 00094 00095 public void setId(int i) { 00096 id = i; 00097 } 00098 00099 public void setRand_loc(boolean b) { 00100 if (b == true) { 00101 java.util.Random s = SenseGui.global_rand; 00102 java.util.Random r = new java.util.Random(s.nextLong()); 00103 r.nextDouble(); 00104 x = r.nextDouble() * SenseGui.FIELD_WIDTH; 00105 r.nextDouble(); 00106 y = r.nextDouble() * SenseGui.FIELD_WIDTH; 00107 r.nextDouble(); 00108 z = r.nextDouble() * SenseGui.FIELD_WIDTH; 00109 } 00110 rand_loc = b; 00111 } 00112 00113 public void setX(double xin) { 00114 x = xin; 00115 rand_loc = false; 00116 } 00117 00118 public void setY(double yin) { 00119 y = yin; 00120 rand_loc = false; 00121 } 00122 00123 public void setZ(double zin) { 00124 z = zin; 00125 rand_loc = false; 00126 } 00127 00128 public void setMygroup(NodeGroup g) { 00129 mygroup = g; 00130 } 00131 00132 static public double distance(Node n1, Node n2) { 00133 return Math.sqrt(Math.pow(n1.getX() - n2.getX(), 2) + 00134 Math.pow(n1.getY() - n2.getY(), 2) + 00135 Math.pow(n1.getZ() - n2.getZ(), 2)); 00136 } 00137 00138 public String toString() { 00139 if (mygroup == null) 00140 return "Node " + id + " at " + Math.round(x) + 00141 ":" + Math.round(y) + ":" + Math.round(z) + "\n"; 00142 else 00143 return "Node " + id + " at " + Math.round(x) + 00144 ":" + Math.round(y) + ":" + Math.round(z) + 00145 "\n at Level " + mygroup.getLevel() + "\n"; 00146 } 00147 } |