42 "Minimum Radius of Gyration Mantissa 0-255: ");
45 "Minimum Radius of Gyration Exponent 0-255: ");
48 "Maximum Radius of Gyration Mantissa 0-255: ");
51 "Maximum Radius of Gyration Exponent 0-255: ");
56 #define ATAN_TABLE_SIZE 64
75 static bool atan_table_init =
false;
76 atan_table_mutex.
Lock();
77 if (!atan_table_init) {
80 (
uinT8) (atan ((i / (
float) ATAN_TABLE_SIZE)) * 128.0 /
PI + 0.5);
83 cos_table[i] = cos(i * 2 *
PI / INT_CHAR_NORM_RANGE +
PI);
84 sin_table[i] = sin(i * 2 *
PI / INT_CHAR_NORM_RANGE +
PI);
86 atan_table_init =
true;
94 return FCOORD(cos_table[theta], sin_table[theta]);
105 int num_features = fx_info.
NumCN;
106 if (num_features > 0) {
107 sample = TrainingSample::CopyFromFeatures(fx_info, cnfeatures,
111 int num_features = fx_info.
NumBL;
112 if (num_features > 0) {
113 sample = TrainingSample::CopyFromFeatures(fx_info, blfeatures,
148 inT32 *FeatureOutlineArray) {
151 EDGEPT *Loop, *LoopStart, *Segment;
152 inT16 LastX, LastY, Xmean, Ymean;
153 inT32 NormX, NormY, DeltaX, DeltaY;
162 uinT16 NumBLFeatures, NumCNFeatures;
166 register inT32 pfX, pfY, dX, dY;
190 while (OutLine !=
NULL) {
191 LoopStart = OutLine->
loop;
206 DeltaX = NormX - LastX;
207 DeltaY = NormY - LastY;
208 Length =
MySqrt(DeltaX, DeltaY);
209 n = ((Length << 2) + Length + 32) >> 6;
211 Xsum += ((LastX << 1) + DeltaX) * (int) Length;
212 Ysum += ((LastY << 1) + DeltaY) * (int) Length;
221 while (Loop != LoopStart);
222 OutLine = OutLine->
next;
226 Xmean = (Xsum / (
inT32) LengthSum) >> 1;
227 Ymean = (Ysum / (
inT32) LengthSum) >> 1;
229 Results->
Length = LengthSum;
230 Results->
Xmean = Xmean;
231 Results->
Ymean = Ymean;
250 while (OutLine !=
NULL) {
251 LoopStart = OutLine->
loop;
253 LastX = Loop->
pos.
x - Xmean;
261 NormX = Loop->
pos.
x - Xmean;
263 if (NormY < Results->YBottom)
265 if (NormY > Results->
YTop)
271 DeltaX = NormX - LastX;
272 DeltaY = NormY - LastY;
273 Length =
MySqrt(DeltaX, DeltaY);
274 n = ((Length << 2) + Length + 32) >> 6;
277 dX = (DeltaX << 8) / n;
278 dY = (DeltaY << 8) / n;
279 pfX = (LastX << 8) + (dX >> 1);
280 pfY = (LastY << 8) + (dY >> 1);
281 Ix += ((pfY >> 8) - Ymean) * ((pfY >> 8) - Ymean);
285 Iy += (pfX >> 8) * (pfX >> 8);
289 (
inT16) ((pfY >> 8) - 128),
293 for (i = 1; i < n; i++) {
296 Ix += ((pfY >> 8) - Ymean) * ((pfY >> 8) - Ymean);
297 Iy += (pfX >> 8) * (pfX >> 8);
301 (
inT16) ((pfY >> 8) - 128),
313 while (Loop != LoopStart);
314 OutLine = OutLine->
next;
316 Results->
Width = max_x - min_x;
321 RxInv =
MySqrt2 (NumBLFeatures, Ix, &RxExp);
322 RyInv =
MySqrt2 (NumBLFeatures, Iy, &RyExp);
325 Results->
Rx = (
inT16) (51.2 / (
double) RxInv * pow (2.0, (
double) RxExp));
326 Results->
Ry = (
inT16) (51.2 / (
double) RyInv * pow (2.0, (
double) RyExp));
327 if (Results->
Ry == 0) {
334 Results->
NumBL = NumBLFeatures;
352 int OutLineIndex = -1;
353 while (OutLine !=
NULL) {
354 LoopStart = OutLine->
loop;
356 LastX = (Loop->
pos.
x - Xmean) * RyInv;
357 LastY = (Loop->
pos.
y - Ymean) * RxInv;
358 LastX >>= (
inT8) RyExp;
359 LastY >>= (
inT8) RxExp;
368 NormX = (Loop->
pos.
x - Xmean) * RyInv;
369 NormY = (Loop->
pos.
y - Ymean) * RxInv;
370 NormX >>= (
inT8) RyExp;
371 NormY >>= (
inT8) RxExp;
375 DeltaX = NormX - LastX;
376 DeltaY = NormY - LastY;
377 Length =
MySqrt(DeltaX, DeltaY);
378 n = ((Length << 2) + Length + 32) >> 6;
381 dX = (DeltaX << 8) / n;
382 dY = (DeltaY << 8) / n;
383 pfX = (LastX << 8) + (dX >> 1);
384 pfY = (LastY << 8) + (dY >> 1);
391 if (FeatureOutlineArray) {
392 FeatureOutlineArray[NumCNFeatures] = OutLineIndex;
395 for (i = 1; i < n; i++) {
404 if (FeatureOutlineArray) {
405 FeatureOutlineArray[NumCNFeatures] = OutLineIndex;
416 while (Loop != LoopStart);
417 OutLine = OutLine->
next;
420 Results->
NumCN = NumCNFeatures;
434 assert ((X != 0) || (Y != 0));
449 Atan = AtanTable[Ratio];
456 else if (AbsX > AbsY)
465 else if (AbsX > AbsY)
473 return (
uinT8) Angle;
488 Feature = &(FeatureArray[FeatureNum]);
493 Feature->
X = ClipToRange<inT16>(X, 0, 255);
494 Feature->
Y = ClipToRange<inT16>(Y, 0, 255);
495 Feature->
Theta = Theta;
508 register uinT16 BitLocation;
510 const uinT32 EvidenceMultMask =
518 if (X > EvidenceMultMask)
519 X = EvidenceMultMask;
520 if (Y > EvidenceMultMask)
521 Y = EvidenceMultMask;
525 BitLocation = (EvidenceMultMask + 1) << 1;
528 Square = (SqRoot | BitLocation) * (SqRoot | BitLocation);
530 SqRoot |= BitLocation;
545 register uinT8 SqRoot;
547 register uinT8 BitLocation;
553 while ((N2 & 0xc0000000) == 0) {
558 while ((I & 0xc0000000) == 0) {
563 if (((N2 & 0x80000000) == 0) && ((I & 0x80000000) == 0)) {
575 Square = (SqRoot | BitLocation) * (SqRoot | BitLocation);
577 SqRoot |= BitLocation;
595 register uinT8 AM, BM, AE, BE;
596 register uinT8 BitN, LastCarry;
597 int RxInvLarge, RyInvSmall;
604 while ((AM != 0) || (BM != 0)) {
606 BitN = LastCarry + (AM & 1) + 1;
611 BitN = LastCarry + (!(BM & 1));
616 BitN = LastCarry + (AM & 1) + (!(BM & 1));
622 LastCarry = (BitN & 2) > 1;
625 BitN = LastCarry + 1;
626 LastCarry = (BitN & 2) > 1;
639 while ((AM != 0) || (BM != 0)) {
641 BitN = LastCarry + (AM & 1) + 1;
646 BitN = LastCarry + (!(BM & 1));
651 BitN = LastCarry + (AM & 1) + (!(BM & 1));
657 LastCarry = (BitN & 2) > 1;
660 BitN = LastCarry + 1;
661 LastCarry = (BitN & 2) > 1;
674 while ((AM != 0) || (BM != 0)) {
676 BitN = LastCarry + (AM & 1) + 1;
681 BitN = LastCarry + (!(BM & 1));
686 BitN = LastCarry + (AM & 1) + (!(BM & 1));
692 LastCarry = (BitN & 2) > 1;
695 BitN = LastCarry + 1;
696 LastCarry = (BitN & 2) > 1;
709 while ((AM != 0) || (BM != 0)) {
711 BitN = LastCarry + (AM & 1) + 1;
716 BitN = LastCarry + (!(BM & 1));
721 BitN = LastCarry + (AM & 1) + (!(BM & 1));
727 LastCarry = (BitN & 2) > 1;
730 BitN = LastCarry + 1;
731 LastCarry = (BitN & 2) > 1;
739 if (RxInvLarge && RyInvSmall) {