11 #include "../shell/Shell.h"
12 #include "../utility/Vec.h"
26 ifstream fin( fname.c_str() );
28 cerr <<
"ReadSwc:: could not open file " << fname << endl;
34 while( getline( fin, temp ) ) {
35 if ( temp.length() == 0 )
37 string::size_type pos = temp.find_first_not_of(
"\t " );
38 if ( pos == string::npos )
40 if ( temp[pos] ==
'#' )
55 cout <<
"ReadSwc: " << fname <<
" : NumSegs = " <<
segs_.size() <<
56 ", bad = " << badSegs <<
57 ", Validated = " << valid <<
69 for (
unsigned int i = 0; i <
segs_.size(); ++i ) {
84 bool valid = ( numStart == 1 && numOrphans == 0 && badRadius == 0 );
86 cout <<
"ReadSwc::validate() failed: \nNumSegs = " <<
88 ", numStart = " << numStart <<
89 ", orphans = " << numOrphans <<
90 ", badIndex = " << badIndex <<
91 ", badRadius = " << badRadius <<
100 for (
unsigned int i = 0; i <
segs_.size(); ++i ) {
103 if ( s.
parent() != ~0U ) {
107 for (
unsigned int i = 0; i <
segs_.size(); ++i ) {
108 segs_[i].figureOutType();
115 for (
unsigned int i = 1; i <
segs_.size(); ++i ) {
121 for (
unsigned int j = 0; j < pa.
kids().size(); ++j ) {
122 if ( static_cast< unsigned int >( pa.
kids()[j] ) != s.
myIndex() )
123 temp.push_back( pa.
kids()[j] );
126 for (
unsigned int j = 0; j < s.
kids().size(); ++j ) {
129 temp.push_back( kid.
myIndex() );
133 cout <<
"ReadSwc:: Cleaned zero length " << s.
myIndex() << endl;
139 double& len,
double& L, vector< int >& cable )
const
142 cable.resize( 1, s.
myIndex() );
145 if ( s.
parent() == ~0U ) {
156 cable.push_back( pa.
myIndex() );
158 }
while ( (prev->
parent() != ~0U) && (prev->
kids().size() == 1) );
165 for (
unsigned int i = 0; i <
segs_.size(); ++i ) {
167 if ( s.
OK() && s.
kids().size() != 1 ) {
184 vector< int > reverseSeg (
segs_.size() + 1, 0 );
185 for (
unsigned int i = 0; i <
branches_.size(); ++i )
187 for (
unsigned int i = 0; i <
branches_.size(); ++i ) {
189 assert( parentSeg != 0 );
190 branches_[i].setParent( reverseSeg[ parentSeg ] );
196 vector< int > diag( 14 );
197 for (
unsigned int i = 0; i <
segs_.size(); ++i ) {
202 for (
int i = 0; i < 14; ++i )
213 double RM,
double RA,
double CM,
214 unsigned int i,
unsigned int j )
217 double len = seg.
radius() * 2.0;
218 string name =
"soma";
221 if ( seg.
parent() != ~0U ) {
230 x0 = seg.
vec().
a0() - len;
235 compt = shell->
doCreate(
"Compartment", parent, name, 1 );
241 double dia = seg.
radius() * 2.0e-6;
242 cptr->
setRm( er, RM / ( len * dia *
PI ) );
243 cptr->
setRa( er, RA * len / xa );
244 cptr->
setCm( er, CM * ( len * dia * PI ) );
247 cptr->
setX0( x0 * 1e-6 );
248 cptr->
setY0( y0 * 1e-6 );
249 cptr->
setZ0( z0 * 1e-6 );
257 double lambda,
double RM,
double RA,
double CM )
260 vector< Id > compts(
segs_.size() );
261 for (
unsigned int i = 0; i <
branches_.size(); ++i ) {
263 for (
unsigned int j = 0; j < br.
segs_.size(); ++j ) {
266 unsigned int paIndex = seg.
parent();
267 if ( paIndex == ~0U ) {
268 compt =
makeCompt( parent, seg, seg, RM, RA, CM, i, j );
271 compt =
makeCompt( parent, seg, pa, RM, RA, CM, i, j );
272 assert( compt !=
Id() );
273 assert( compts[ paIndex -1 ] !=
Id() );
275 compts[paIndex-1],
"axial", compt,
"raxial" );
277 assert( compt !=
Id() );
278 compts[ seg.
myIndex() -1 ] = compt;
void traverseBranch(const SwcSegment &s, double &len, double &L, vector< int > &cable) const
void replaceKids(const vector< int > &kids)
unsigned short type() const
void setLength(double length)
unsigned int parent() const
static const double MinRadius
const vector< int > & kids() const
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
unsigned int myIndex() const
void setCm(const Eref &e, double Cm)
double distance(const SwcSegment &other) const
vector< SwcSegment > segs_
vector< SwcBranch > branches_
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
void setDiameter(double diameter)
void setRa(const Eref &e, double Ra)
void setParent(unsigned int pa)
ReadSwc(const string &fname)
static const string typeName[]
static Id makeCompt(Id parent, const SwcSegment &seg, const SwcSegment &pa, double RM, double RA, double CM, unsigned int i, unsigned int j)
void setRm(const Eref &e, double Rm)
bool build(Id parent, double lambda, double RM, double RA, double CM)