-
Notifications
You must be signed in to change notification settings - Fork 2
/
Func.h
2884 lines (2245 loc) · 67.4 KB
/
Func.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef FUNC_H
#define FUNC_H
#include "Neuron.h"
#include "pca.h"
#include "Segment.h"
#include <math.h>
#include "stdlib.h"
#include "Limit.h"
#include <assert.h>
#define VOID 1000000000
#define TH_DIM 0.95
;
class Func{
protected:
double preMean;
Func * pre;
char* name;
Func *limit;
public:
double virtual computeStep(Segment *t){return VOID;};
Func(){name="<NoName>";limit=0;pre=this;};
Func(char* m){
name=m;limit=0;pre= this;
}
Func(char*m, Func* l){name=m;limit=l;}
Func(char*m, Func* preElaboration, Func* l){name=m;limit=l;pre=preElaboration;}
void virtual initialize(double preMean1) {preMean=preMean1;};
virtual Func * getPreFunc(){ return pre;}
//a value great than MAX is considered NULL
double compute(Segment *t){
//if no limit
if(limit==0)
return computeStep(t);
//otherwise check limit
if (limit->computeStep(t)!=0 )
return computeStep(t);
return VOID;
};
char * getName(){return name;}
char * getLimit(){if (limit==0) return "";return limit->getName();}
void setName(char* m){name=m;}
}
;
class Equal:public Func{
protected:
public:
Func * a;
double value;
Equal(Func * b, double d,Func* lim=0):Func("Lim",lim){
a=b;
value=d;
};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
if(a->computeStep(t)==value)
return 1;
return 0;
}
}
;
class Greater:public Func{
protected:
public:
Func * a;
double value;
Greater(Func * b, double d,Func* lim=0):Func("Lim",lim){
a=b;
value=d;
};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
if(a->computeStep(t)>value)
return 1;
return 0;
}
}
;
class Lesser:public Func{
protected:
public:
Func * a;
double value;
Lesser(Func * b, double d,Func* lim=0):Func("Lim",lim){
a=b;
value=d;
};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
if(a->computeStep(t)<value)
return 1;
return 0;
}
}
;
//And: if both function return a value different than zero then they return 1 otherwise 0
class And:public Func{
protected:
public:
Func * a;
Func *b;
And(Func * A,Func * B, Func* lim=0):Func("Lim",lim){
a=A;b=B;
};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
if(a->computeStep(t)!=0 && b->computeStep(t)!=0)
return 1;
return 0;
}
}
;
//Or: if one function return a value different than zero then return 1 otherwise 0
class Or:public Func{
protected:
public:
Func * a;
Func *b;
Or(Func * A,Func * B, Func* lim=0):Func("Lim",lim){
a=A;b=B;
};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
if(a->computeStep(t)!=0 || b->computeStep(t)!=0)
return 1;
return 0;
}
}
;
//store Class Info for Machine Learning Algorithm
class N_Class:public Func{
int c;
public:
N_Class(Func* lim=0):Func("N_Class",lim){c=-1;};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t->getClass()!=-1){
Segment * t1=t;
while(t1->getPrev()!=NULL)
t1=t1->getPrev();
c=t1->getClass();
}
return c;
}
}
;
class Diameter:public Func{
public:
Diameter(Func* lim=0):Func("Diameter",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//changed the if condition from (t->getPid()==-1) to keep in sync with Windows code.
//sri 12/15/2010
if(t==NULL)
{
return VOID;
}
double d=t->getDiam();
//cout<<"\n ------------------------------------------------Dia for: "<<t->getId();
return d;
}
}
;
class Diameter_pow:public Func{
public:
Diameter_pow(Func* lim=0):Func("Diameter_pow",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//changed the if condition from (t->getPid()==-1) to keep in sync with Windows code.
//sri 12/15/2010
if(t==NULL) return VOID;
double dp=t->getDiam();
return pow(dp,1.5);
}
}
;
class Type:public Func{
public:
Type(Func* lim=0):Func("Type",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//if(t->getType()== 3) cerr<<"found dendrite..";
return t->getType();}
}
;
class N_stems:public Func{
public:
N_stems(Func* lim=0):Func("N_stems",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t) {
Segment * p = t;
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//Return void for all the transitions from
if(t->getType() < 2) return VOID;
if (t->getPrev() != NULL) {
//SG Code fix, the code is fixed for the N_stems. N_stems doesn't care about specificity.
//
// if (t->getType() != t->getPrev()->getType() && t->getType() > 0
// && (t->getPrev()->getType() == -1
// || t->getPrev()->getType() == 1)) {
//
// return 1;
// }
if(t->getType() != t->getPrev()->getType() && (t->getPrev()->getType() == 1 || t->getPrev()->getType() == -1) && t->getType() != 1){
return 1;
}
}
return VOID;
}
}
;
class N_branch:public Func{
public:
N_branch(Func* lim=0):Func("N_branch",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//SG Code changes 18Nov2011
//Formula changed
//N_brnach = N_bifs+N_tips
if((t->isFather() || t->isTerminate()) && t->getType() > 0 && t->getId() > 1){
return 1;
}
return VOID;
// //SG Code changes 07/22/2011
// //The number of segments included are chnaged.
// if(t->isFather() || t->isTerminate() ||
// (t->getType() > 1 && t->getType() != t->getPrev()->getType() && t->getPrev()->getType() == 1 )
// ){
//
// return 1;
// }
// return VOID;
// //End of SG Code changes.
}
}
;
//changing the code for N_tips to TerminalSegment
class TerminalSegment:public Func{
public:
TerminalSegment(Func* lim=0):Func("TerminalSegment",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
if(t->getNrTip()==1)
return 1;
return VOID;
}
}
;
class Length:public Func{
public:
Length(Func* lim=0):Func("Length",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
double lenght=0;
if( t->getPid()!=-1)
lenght=t->getEnd()->distance(t->getPrev()->getEnd());
if(lenght>0) return lenght;
return VOID;
}
}
;
class Branch_Order:public Func{
public:
Branch_Order(Func* lim=0):Func("Branch_Order",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
return t->getOrder();
}
}
;
class Diam_threshold:public Func{
public:
Diam_threshold(Func* lim=0):Func("Diam_threshold",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t==NULL ||t->getPrev()==NULL) return VOID;
if(t->getPrev()->isFather() && t->getNrTip()==1) return t->getDiam();
return VOID ;
}
}
;
class Soma_Surface:public Func{
public:
Soma_Surface(Func* lim=0):Func("Soma_Surface",lim){};
int nrSomaSeg(Segment *t){
int tmp=0;
if(t->getNext1()!=NULL)
tmp+=nrSomaSeg(t->getNext1());
if(t->getNext2()!=NULL)
tmp+=nrSomaSeg(t->getNext2());
if (t->getType()==1 && t->getId()>0) tmp++;
return tmp;
}
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
static int notSingle=0;
if(t->getRadius()!=t->getRadius())return VOID;
if(t->getId()<0) return VOID;
if( t->getPid()==-1 ){
notSingle=nrSomaSeg(t);
cerr<<"#soma seg:"<<notSingle<<"\n";
if(notSingle ==1){
double diam = t->getDiam();
return (M_PI*diam*diam);
}
return VOID;
}
if(notSingle>0){
if (t->getPrev()!=NULL && t->getType()==1 &&t->getId()>0){
//cerr<<"id:"<<t->getId()<<" soma val:"<<(t->getEnd()->distance(t->getPrev()->getEnd()))*M_PI*t->getPrev()->getDiam()<<"\n";
cerr<<"id:"<<t->getId()<<" soma val:"<<M_PI*t->getPrev()->getDiam()*t->getPrev()->getDiam()<<"\n";
return (t->getEnd()->distance(t->getPrev()->getEnd()))*M_PI*t->getPrev()->getDiam()*t->getPrev()->getDiam();
}
}
return VOID;
}
}
;
class EucDistance:public Func{
public:
EucDistance(Func* lim=0):Func("EucDistance",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
return t->getSomaDistance();
}
}
;
class PathDistance:public Func{
public:
PathDistance(Func* lim=0):Func("PathDistance",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
return t->getPathDistance();
}
}
;
//Burke taper
//##ModelId=3F6DA246032A
class Taper_1:public Func{
Segment * tmp;
public:
Taper_1(Func* lim=0):Func("Taper_1",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//SG Code chnages
//Including terminal segments to calculate the taper_1
// if(t->getPrevFather()->getId() < 2 || ( t->isFather() == NULL && !t->isTerminate()))
// return VOID;
//End of SG Code chnages
//Conditions from taper 2
if(t->getId()<2)
return VOID;
if(!(t->isFather()||(t->isTerminate()&&t->getType()>0)))
return VOID;
tmp=t;
double length=tmp->getLength();
tmp=tmp->getPrev();
while(!tmp->isFather()){
length+=tmp->getLength();
tmp=tmp->getPrev();
}
//round off length value to two decimal points to avoid too large values sri 01/10/2012
//if(length < 0.01)
//cerr<< "Taper_1 length:"<<length<<"\n";
length = ((double) ((int) (length * 100))) / 100;
//SG Code chnages 07-July-2011
//If the difference of parent and child diameter is none then dont accept the segment.
if(length == 0)
return VOID;
//SG Code Change June-10-2011
//Swapped the ChildDiam - Father Diam to Father Diam - Child Diam in formulae.
double taper=(t->getPrevFather()->getDiam() - t->getDiam())/length;
return taper;
}
}
;
class Rall_Power:public Func{
double d,d1,d2,min,max;
double step(double m){
double a1=pow(d,m);
double a2=pow(d1,m)+pow(d2,m);
double a3=fabs( (a1-a2));
return a3;
}
public:
Rall_Power(Func* lim=0):Func("Rall_Power",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t==NULL) return VOID;
if(t->isFather() && t->getType() > 0) {
max=5;min=0;
d=t->getDiam();
if(t->getNext2()==NULL) return VOID;
d1=t->getNext1()->getDiam();
d2=t->getNext2()->getDiam();
if(d==d1 ||d==d2){
//cerr<<t->getId()<<"--barnch invalid for d==d1 ||d==d2 \n";
return VOID;
}
//skip biforcation than get bigger
if(d<d1 ||d<d2) {
//cerr<<t->getId()<<"--barnch invalid for d<d1 ||d<d2 \n";
return VOID;
}
//compute manually
double start=min;
double steps=1000;
double const delta=(max-min)/steps;
//look for a local minima
double t1,t2,t3,in=0;
double minima;
minima=0;
while (start<max){
t1=step(start);
in++;
if (in>1000){
Segment *s=t;
}
t2=step(start+delta);
t3=step(start+delta+delta);
start+=delta;
if(t1>t2 && t3>t2) {
minima=start;
}
}
if (minima==0 || minima==max){
//cerr<<t->getId()<<"--barnch invalid for minima 0 or max \n";
return VOID;
}
return minima;
}
return VOID;
}
}
;
class Rall1:public Func{
double d,d1,d2,f1,f2,f3,min,max,med;
double step(double m){
double a1=pow(d,m);
double a2=pow(d1,m)+pow(d2,m);
double a3=fabs( (a1-a2)/a1);
return a3;
}
public:
Rall1(Func* lim=0):Func("Rall1",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t->isFather() && t->getType() > 0) {
max=5;min=0.5;med=(min+max)/2;
d=t->getDiam();
if(t->getNext2()==NULL) return VOID;
d1=t->getNext1()->getDiam();
d2=t->getNext2()->getDiam();
if(d==d1 ||d==d2){
return VOID;
}
//skip biforcation than get bigger
if(d<d1 ||d<d2) return VOID;
for(int i=0;i<100;i++){
f1=step(min);
f2=step(med);
f3=step(max);
if(f1<f2) max=med;
if(f2>f3) min=med;
//if in a minima choose the less max)
if(f1>f2 && f2<f3){
if(f1<f3) {
max=med;
} else {
min=med;
}
}
med=(min+max)/2;
}
return med;
}
return VOID;
}
}
;
class Parent_Daughter_Ratio:public Func{
public:
Parent_Daughter_Ratio(Func* lim=0):Func("Parent_Daughter_Ratio",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//if prev is father return father/segment ratio else VOID
if(t->getPrev()!=NULL)
if(t->getPrev()->isFather()){
double a,b;
a=t->getPrev()->getDiam();
b=t->getDiam();
if(a>0)
return b/a;
}
return VOID;
}
}
;
class Last_parent_diam:public Func{
public:
Last_parent_diam(Func* lim=0):Func("Last_parent_diam",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if( t->isFather() && t->getNrTip()==2)
return t->getDiam();
return VOID;
}
}
;
class Partition_asymmetry:public Func{
public:
Partition_asymmetry(Func* lim=0):Func("Partition_asymmetry",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG Code changes 08/04/2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t->isFather()){
if(t->getNext2()==NULL) return VOID;
int n1=t->getNext1()->getNrTip();
int n2=t->getNext2()->getNrTip();
if(n1==1 && n2==1) return 0;
return abs(n1-n2)/(n1+n2-2.0);
}
return VOID;
}
}
;
class Daughter_Ratio:public Func{
public:
Daughter_Ratio(Func* lim=0):Func("Daughter_Ratio",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t->getType() < 1) return VOID;
if(!(t->isFather())) return VOID;
if(t->getNext2()==NULL) return VOID;
double d1=t->getNext1()->getDiam();
double d2=t->getNext2()->getDiam();
if(d2>d1){
/*
* Code fix to cater to the zero dia situation for the function.
*/
if(d1 <= 0){
//cerr<<"\n!!!!!Zero Diameter found for compartment id:"<<t->getId()<<" Type:"<<t->getType();
return VOID;
}
else
return d2/d1;
}
/*
* Code fix to cater to the zero dia situation for the function.
*/
if(d2 <= 0){
//cerr<<"\n!!!!!Zero Diameter found for compartment id:"<<t->getId()<<" Type:"<<t->getType();
return VOID;
}
else
return d1/d2;
}
}
;
class Taper_2:public Func{
public:
Taper_2(Func* lim=0):Func("Taper_2",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t->getId()<2)
return VOID;
if(t->isFather()||(t->isTerminate()&&t->getType()>0)){
if(t->getPrevFather()->getDiam()!=0)
return (t->getPrevFather()->getDiam()-t->getDiam())/t->getPrevFather()->getDiam();
}
return VOID;
}
}
;
class Branch_pathlength:public Func{
public:
Branch_pathlength(Func* lim=0):Func("Branch_pathlength",lim){};
Func * getPreFunc(){ return this;}
double computeStep(Segment *t){
//SG code added 26-08-2011
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
if(t->getId()<2)
return VOID;
if(t->isFather() ||(t->isTerminate() && t->getType()>0)){
//round off the length to two decimal points to avoid close to 0 values. sri 10/01/2012
double brnchlen = t->getPathDistance() - t->getPrevFather()->getPathDistance();
brnchlen = ((double) ((int) (brnchlen * 100))) / 100;
if(brnchlen == 0){//discard branches that were formed due to triforcation adjustment sri 10/01/2012
//cerr<<"stop here.."<<t->getEnd()->getX()<<","<<t->getEnd()->getY()<<","<<t->getEnd()->getZ()<<" "<<t->getType()<<" "<<brnchlen<<"\n";
return VOID;
}
else if(brnchlen <= 0.1){
cerr<<"branchlen<=0.1 "<<t->getEnd()->getX()<<","<<t->getEnd()->getY()<<","<<t->getEnd()->getZ()<<" "<<t->getType()<<" "<<brnchlen<<"\n";
}
return (brnchlen);
}
return VOID;
}
}
;
class Bif_ampl_local: public Func {
public:
Bif_ampl_local(Func* lim = 0) :
Func("Bif_ampl_local", lim) {
}
;
Func * getPreFunc() {
return this;
}
double computeStep(Segment *t) {
//To avoid the virtual compartments
if(t->getType() == -1) return -VOID;
//If soma return void
//if(t->getType() == 1) return VOID;
if(t->getType() == 1){
Segment * temp_soma = canComputeAtSoma(t);
if(temp_soma == NULL){
return VOID;
}else{
return (t->getEnd()->angle(temp_soma->getNext1()->getEnd(), temp_soma->getNext2()->getEnd()));
}
}
double toreturn;
if (t->getNext2() == NULL)
return VOID;
if (t->isFather()){
// return (t->getEnd()->angle(t->getNext1()->getEnd(),
// t->getNext2()->getEnd()));
//toreturn = (t->getEnd()->angle(t->getNonVirtualNext1()->getEnd(),t->getNonVirtualNext2()->getEnd()));
//cout<<"for Id:"<<t->getId()<<" --value:"<<toreturn<<" \n";
//If next1 and next2 both dont have virtual compartment
if(t->getNext1()->getType() != -1 && t->getNext2()->getType() != -1){
toreturn = (t->getEnd()->angle(t->getNext1()->getEnd(), t->getNext2()->getEnd()));
//cout<<"-Non-V \n";
}
else{
//If Next1 is not virtual compartment
if(t->getNext1()->getType() != -1)
toreturn = computeMaxAngle(t, t->getNext1(),t);
//If Next2 is virtual compartment
else
toreturn = computeMaxAngle(t,t->getNext1()->getNext1(),t);
//cout<<"-is-V \n";
}
//convert return value to two digits SP 10/09/12
//toreturn = ((double) ((int) (toreturn * 100))) / 100;
//Commented out two adjustment of decimal values to 2 digits, as it is causing -ve values when the angle is equal to zero.
if(toreturn<0)
cerr<<"negative.."<<toreturn<<" "<<t->getEnd()->getX()<<","<<t->getEnd()->getY()<<","<<t->getType()<<" next1 "<<t->getNext1()->getEnd()->getX()<<","<<t->getNext1()->getEnd()->getY()<<","<<t->getNext1()->getEnd()->getZ()<<" next2 "<<t->getNext2()->getEnd()->getX()<<","<<t->getNext2()->getEnd()->getY()<<","<<t->getNext2()->getEnd()->getZ()<<"\n";
return toreturn;
}
return VOID;
}
double computeMaxAngle( Segment *t_main, Segment * t1, Segment * t) {
//Maximum value of the angle
//Computed value, temp value to compare with
double maxValue = 0, computedValue = 0;
//Flag for marking Next1,2 as virtual
bool tn1_is_virt = false, tn2_is_virt = false;
//Finding if Next1 is virtual
if(t->getNext1() != NULL){
if (t->getNext1()->getType() == -1){
tn1_is_virt = true;
//cout <<"v1:t\n";
}
}
//Finding if Next2 is virtual
if(t->getNext2() != NULL){
if (t->getNext2()->getType() == -1){
tn2_is_virt = true;
//cout <<"v2:t\n";
}
}
//Computing value is one of the Next1,2 is virtual
//Going into the recursion
if (tn1_is_virt || tn2_is_virt) {
//Compute value if Next2 is virtual
if(t->getNext2() != NULL && tn2_is_virt)
computedValue = computeMaxAngle(t_main, t1, t->getNext2());
//Setting the max value
if (computedValue > maxValue && computedValue != VOID)
maxValue = computedValue;
//Compute value if Next2 is virtual
if(t->getNext1() != NULL && tn1_is_virt)
computedValue = computeMaxAngle(t_main, t1, t->getNext1());
//Setting the max value
if (computedValue > maxValue && computedValue != VOID)
maxValue = computedValue;
}
if(t->getNext1() != NULL)
//If next1 is not virtual comouting the value
if (t->getNext1()->getType() != -1) {
computedValue = t_main->getEnd()->angle(t1->getEnd(),
t->getNext1()->getEnd());
//Setting the max value
if (computedValue > maxValue && computedValue != VOID)
maxValue = computedValue;
//cout<<"P1->"<<maxValue<<",";
}
//If next2 is not virtual
if(t->getNext2() != NULL)
//If next2 is not virtual comouting the value
if (t->getNext2()->getType() != -1) {
computedValue = t_main->getEnd()->angle(t1->getEnd(),
t->getNext2()->getEnd());
//Setting the max value
if (computedValue > maxValue && computedValue != VOID)
maxValue = computedValue;
//cout<<"P1->"<<maxValue<<",";
}
return maxValue;
}
/*
* This method finds if the Bif_ampl_local can be computed at soma.
* It looks for a V from soma, having next1() & next2() as non-soma and non-virtual compartments
*/
Segment* canComputeAtSoma(Segment * t){
Segment * toReturn = NULL;
Segment * temp1 = t;
while(temp1->getNext2() != NULL){
if(temp1->getNext1()->getType() > 1 && temp1->getNext2()->getType() > 1){
toReturn = temp1;
break;
}else{
if(temp1->getNext1()->getType() != 1 || temp1->getNext2()->getType() != -1){
break;
}else{
temp1 = temp1->getNext2();
}
}