-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSWC.C
157 lines (122 loc) · 2.84 KB
/
SWC.C
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
#include"SWC.h"
/*****************************************************************/
// Overloading SWCData for I/0
/*****************************************************************/
ostream & operator << (ostream & tmp, SWCData swcd)
{
tmp << swcd.pi << " " ;
tmp << swcd.tc << " " ;
tmp << swcd.x << " " ;
tmp << swcd.y << " " ;
tmp << swcd.z << " " ;
tmp << swcd.r << " " ;
tmp << swcd.ppi << endl ;
return tmp;
}
/*****************************************************************/
istream & operator >> (istream & tmp, SWCData & swcd)
{
tmp >> swcd.pi ;
tmp >> swcd.tc ;
tmp >> swcd.x ;
tmp >> swcd.y ;
tmp >> swcd.z ;
tmp >> swcd.r ;
tmp >> swcd.ppi;
return tmp;
}
/*****************************************************************/
// SWC Class Files
/*****************************************************************/
SWC :: SWC ()
{
ncomp=0;
}
/*****************************************************************/
void SWC :: ReadSWC(char * filename)
{
char * flname=new char [35];
if(!filename){
cout << "\nGive input SWC filename : ";
cin >> flname ;
}
else strcpy(flname,filename);
ifstream swcfile (flname);
if(!swcfile){
cerr << "\nFile " << flname << " does not exist.\n";
exit(1);
}
char c;
char * buffer=new char[80];
streampos crps;
int i;
swcfile.get(c);
if (c=='#'){
// Skip through header...
while (c == '#'){
swcfile.getline(buffer,80);
swcfile.get(c);
}
crps=swcfile.tellg();
}
else crps=0;
// Browse through the end of file to get the number of points....
ncomp=0;
while(!swcfile.eof()){
swcfile.getline(buffer,80);
ncomp ++;
}
ncomp --;
Comptmt=new SWCData[ncomp];
// Read all points...
swcfile.close();
ifstream swc1file;
swc1file.open(flname);
if(!swc1file){
cerr << "\nFile " << flname << " does not exist.\n";
exit(1);
}
swc1file.seekg(crps);
for(i=0; i<ncomp; i++){
swc1file >> Comptmt[i];
if(Comptmt[i].tc==-1)
cerr << "\nWarning: Undefined compartment type at "
<< Comptmt[i] ;
}
delete(buffer);
delete(flname);
}
/*****************************************************************/
void SWC :: isRead()
{
if(!ncomp){
cerr << "\nSWC file has been read.\n";
exit(1);
}
}
/*****************************************************************/
void SWC :: WriteSWC(char * filename)
{
isRead ();
char * flname=new char [35];
if(!filename){
cout << "\nGive output SWC filename : ";
cin >> flname ;
}
else strcpy(flname,filename);
ofstream outfile (flname);
int i;
for(i=0; i<ncomp; i++)
outfile << Comptmt[i] ;
delete(flname);
}
/*****************************************************************/
void SWC :: SetComptmt(SWCData * Cpts, int npts)
{
int i;
ncomp=npts;
Comptmt=new SWCData[ncomp];
for(i=0; i<ncomp; i++)
Comptmt[i]=Cpts[i];
}
/*****************************************************************/