1
2
3 package org.catacomb.numeric.difnet;
4
5 import org.catacomb.report.E;
6
7
8
9 public class CellPoint {
10 public int activeType;
11 public int geometricalType;
12
13 public double x;
14 public double y;
15 public double z;
16 public double r;
17
18 public CellPoint[] nbr;
19 public int nnbr;
20
21
22
23 public int index;
24 public int parentIndex;
25
26
27 public int iwork;
28 public boolean umark;
29 public boolean wmark;
30 public boolean dead;
31 public int wcount;
32
33
34
35 public double dgx;
36 public double dgy;
37
38
39 public String name;
40
41 public CellPoint() {
42 nbr = new CellPoint[6];
43 nnbr = 0;
44 dead = false;
45 umark = false;
46 wmark = false;
47 }
48
49
50 public CellPoint(double x, double y, double z, double r,
51 int gtype, int atype) {
52 this();
53 this.x = x;
54 this.y = y;
55 this.z = z;
56 this.r = r;
57 this.geometricalType = (gtype < 0 ? 0 : gtype);
58 this.activeType = (atype < 0 ? 0 : atype);
59 }
60
61
62 public CellPoint makeCopy() {
63 return new CellPoint(x, y, z, r, geometricalType, activeType);
64 }
65
66
67 public void setWork(int iw) {
68 iwork = iw;
69 }
70 public int getWork() {
71 return iwork;
72 }
73
74
75 public String toString() {
76 return ("zyzr: " + x + " " + y + " " + z + " " + r + " nnbr=" + nnbr);
77 }
78
79
80 public void setPosition(double[] a) {
81 x = a[0];
82 y = a[1];
83 z = a[2];
84 if (a.length >= 3) {
85 r = a[3];
86 }
87 }
88
89
90 public void locateBetween(CellPoint cpa, CellPoint cpb, double f) {
91 double wf = 1. - f;
92 x = f * cpb.x + wf * cpa.x;
93 y = f * cpb.y + wf * cpa.y;
94 z = f * cpb.z + wf * cpa.z;
95 r = f * cpb.r + wf * cpa.r;
96 }
97
98
99
100 public void addNeighbor(CellPoint cpn) {
101 if (nnbr >= nbr.length) {
102 CellPoint[] pn = new CellPoint[2*nnbr];
103 for (int i = 0; i < nnbr; i++) {
104 pn[i] = nbr[i];
105 }
106 nbr = pn;
107 }
108 nbr[nnbr++] = cpn;
109 }
110
111
112 public void removeNeighbor(CellPoint cp) {
113 int ii = -1;
114 for (int i = 0; i < nnbr; i++) {
115 if (nbr[i] == cp) {
116 ii = i;
117 }
118 }
119 if (ii >= 0) {
120 for (int i = ii; i < nnbr-1; i++) {
121 nbr[i] = nbr[i+1];
122 }
123 nnbr--;
124 }
125 }
126
127
128 public void replaceNeighbor(CellPoint cp, CellPoint cr) {
129
130 int ii = -1;
131 for (int i = 0; i < nnbr; i++) {
132 if (nbr[i] == cp) {
133 ii = i;
134 }
135 }
136 if (ii >= 0) {
137 nbr[ii] = cr;
138 } else {
139 E.error(" (replaceNeighbor) couldnt find nbr " + cp +
140 " in nbrs list of " + this);
141 }
142 }
143
144
145 public boolean hasNeighbor(CellPoint cp) {
146 boolean hn = false;
147 for (int i = 0; i < nnbr; i++) {
148 if (nbr[i] == cp) {
149 hn = true;
150 }
151 }
152 return hn;
153 }
154
155
156 public void removeDeadNeighbors() {
157 for (int i = nnbr-1; i >= 0; i--) {
158 if (nbr[i].dead) {
159 removeNeighbor(nbr[i]);
160 }
161 }
162 }
163
164
165 public double distanceTo(CellPoint cp) {
166 double dx = x - cp.x;
167 double dy = y - cp.y;
168 double dz = z - cp.z;
169 return Math.sqrt(dx*dx + dy*dy + dz*dz);
170 }
171
172
173 public void movePerp(CellPoint ca, CellPoint cb, double dperp) {
174 double dx = cb.x - ca.x;
175 double dy = cb.y - ca.y;
176 double f = Math.sqrt(dx*dx + dy*dy);
177 dx /= f;
178 dy /= f;
179 x += dperp * dy;
180 y -= dperp * dx;
181 }
182
183
184 }
185
186
187
188
189
190