View Javadoc
1   package com.github.celldynamics.quimp;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   import com.github.celldynamics.quimp.geom.ExtendedVector2d;
7   
8   /**
9    * Represents a node in the snake - its basic component In fact this class stands for bidirectional
10   * list containing Nodes. Every node has assigned 2D position and several additional properties such
11   * as:
12   * <ul>
13   * <li>velocity of Node</li>
14   * <li>total force of Node</li>
15   * <li>normal vector</li>
16   * </ul>
17   * 
18   * @author rtyson
19   * @author p.baniukiewicz
20   *
21   */
22  public class Node extends PointsList<Node> {
23  
24    /**
25     * The Constant LOGGER.
26     */
27    static final Logger LOGGER = LoggerFactory.getLogger(Node.class.getName());
28    /**
29     * Velocity of the nodes, initialised in
30     * {@link Constrictor#constrict(Snake, ij.process.ImageProcessor)}.
31     */
32    private ExtendedVector2d vel;
33    /**
34     * Total force at node, initialized in
35     * {@link Constrictor#constrict(Snake, ij.process.ImageProcessor)}.
36     */
37    private ExtendedVector2d F_total;
38    /**
39     * Point to move node to after all new node positions have been calc initialized in
40     * {@link Constrictor#constrict(Snake, ij.process.ImageProcessor)}.
41     */
42    private ExtendedVector2d prelimPoint;
43  
44    /**
45     * Default constructor. Create empty Node with default parameters, not linked to other Nodes
46     */
47    public Node() {
48      super();
49      F_total = new ExtendedVector2d();
50      vel = new ExtendedVector2d();
51      prelimPoint = new ExtendedVector2d();
52    }
53  
54    /**
55     * Create Node with given id.
56     * 
57     * @param t id of Node
58     * @see com.github.celldynamics.quimp.PointsList
59     */
60    public Node(int t) {
61      super(t);
62      F_total = new ExtendedVector2d();
63      vel = new ExtendedVector2d();
64      prelimPoint = new ExtendedVector2d();
65    }
66  
67    /**
68     * Copy constructor. Copy properties of Node
69     * 
70     * <p>Previous or next points are not copied
71     * 
72     * @param src Source Node
73     */
74    public Nodemics/quimp/Node.html#Node">Node(final Node src) {
75      super(src);
76      this.vel = new ExtendedVector2d(src.vel);
77      this.F_total = new ExtendedVector2d(src.F_total);
78      this.prelimPoint = new ExtendedVector2d(src.prelimPoint);
79    }
80  
81    /**
82     * Create Node from coordinates.
83     * 
84     * @param xx x-axis coordinate
85     * @param yy y-axis coordinate
86     * @param t id of Node
87     */
88    public Node(double xx, double yy, int t) {
89      super(xx, yy, t);
90      F_total = new ExtendedVector2d();
91      vel = new ExtendedVector2d();
92      prelimPoint = new ExtendedVector2d();
93    }
94  
95    /**
96     * (non-Javadoc) Compare only current Node, no neighbours.
97     * 
98     * @see java.lang.Object#hashCode()
99     */
100   @Override
101   public int hashCode() {
102     final int prime = 31;
103     int result = super.hashCode();
104     result = prime * result + ((F_total == null) ? 0 : F_total.hashCode());
105     result = prime * result + ((prelimPoint == null) ? 0 : prelimPoint.hashCode());
106     result = prime * result + ((vel == null) ? 0 : vel.hashCode());
107     return result;
108   }
109 
110   /*
111    * (non-Javadoc)
112    * 
113    * @see java.lang.Object#equals(java.lang.Object)
114    */
115   @Override
116   public boolean equals(Object obj) {
117     if (this == obj) {
118       return true;
119     }
120     if (!super.equals(obj)) {
121       return false;
122     }
123     if (!(obj instanceof Node)) {
124       return false;
125     }
126     Nodef="../../../../com/github/celldynamics/quimp/Node.html#Node">Node other = (Node) obj;
127     if (F_total == null) {
128       if (other.F_total != null) {
129         return false;
130       }
131     } else if (!F_total.equals(other.F_total)) {
132       return false;
133     }
134     if (prelimPoint == null) {
135       if (other.prelimPoint != null) {
136         return false;
137       }
138     } else if (!prelimPoint.equals(other.prelimPoint)) {
139       return false;
140     }
141     if (vel == null) {
142       if (other.vel != null) {
143         return false;
144       }
145     } else if (!vel.equals(other.vel)) {
146       return false;
147     }
148     return true;
149   }
150 
151   /**
152    * Update point and force with preliminary values, and reset.
153    */
154   public void update() {
155     setX(getX() + prelimPoint.getX());
156     setY(getY() + prelimPoint.getY());
157     prelimPoint.setX(0);
158     prelimPoint.setY(0);
159   }
160 
161   /*
162    * (non-Javadoc)
163    * 
164    * @see java.lang.Object#toString()
165    */
166   @Override
167   public String toString() {
168     return "Node [vel=" + vel + ", F_total=" + F_total + ", prelimPoint=" + prelimPoint + ", point="
169             + point + ", normal=" + normal + ", tan=" + tan + ", head=" + head + ", tracknumber="
170             + tracknumber + ", position=" + position + ", frozen=" + isFrozen() + "]";
171   }
172 
173   /**
174    * Setter to F_total field.
175    * 
176    * @return F_total
177    */
178   public ExtendedVector2d getF_total() {
179     return F_total;
180   }
181 
182   /**
183    * Setter to vel field.
184    * 
185    * @return vel
186    */
187   public ExtendedVector2d getVel() {
188     return vel;
189   }
190 
191   /**
192    * Set total force for Node.
193    * 
194    * @param f vector of force to assign to Node force
195    */
196   public void setF_total(ExtendedVector2d f) {
197     F_total.setX(f.getX());
198     F_total.setY(f.getY());
199   }
200 
201   /**
202    * Set velocity for Node.
203    * 
204    * @param v vector of velocity to assign to Node force
205    */
206   public void setVel(ExtendedVector2d v) {
207     vel.setX(v.getX());
208     vel.setY(v.getY());
209   }
210 
211   /**
212    * Update total force for Node.
213    * 
214    * @param f vector of force to add to Node force
215    */
216   public void addF_total(ExtendedVector2d f) {
217     // add the xy values in f to xy F_total i.e updates total Force
218     F_total.setX(F_total.getX() + f.getX());
219     F_total.setY(F_total.getY() + f.getY());
220   }
221 
222   /**
223    * Update velocity for Node.
224    * 
225    * @param v vector of velocity to add to Node force
226    */
227   public void addVel(ExtendedVector2d v) {
228     // adds the xy values in v to Vel i.e. updates velocity
229     vel.setX(vel.getX() + v.getX());
230     vel.setY(vel.getY() + v.getY());
231   }
232 
233   /**
234    * Set preliminary point for Node.
235    * 
236    * @param v vector of preliminary point to assign to Node force
237    */
238   public void setPrelim(ExtendedVector2d v) {
239     prelimPoint.setX(v.getX());
240     prelimPoint.setY(v.getY());
241   }
242 }