MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SwcSegment.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2015 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include <string>
11 #include <vector>
12 #include <iostream>
13 #include <sstream>
14 #include <cstdlib>
15 #include <math.h>
16 using namespace std;
17 #include "../utility/Vec.h"
18 #include "SwcSegment.h"
19 
20 const short SwcSegment::UNDEF = 0;
21 const short SwcSegment::SOMA = 1;
22 const short SwcSegment::AXON = 2;
23 const short SwcSegment::DEND = 3;
24 const short SwcSegment::APICAL = 4;
25 const short SwcSegment::FORK = 5; // Assumed to be on regular dend
26 const short SwcSegment::END = 6; // Assumed to be on regular dend
27 const short SwcSegment::CUSTOM = 7;
28  // Here are a few more
29 const short SwcSegment::BadSegment = 8;
30 const short SwcSegment::AXON_FORK = 10;
31 const short SwcSegment::AXON_END = 11;
32 const short SwcSegment::APICAL_FORK = 12;
33 const short SwcSegment::APICAL_END = 13;
34 
35 const string SwcSegment::typeName[] = {
36  "undef", "soma", "axon", "dend", "apical", "dend_f", "dend_e",
37  "custom", "bad", "undef",
38  "axon_f", "axon_e", "apical_f", "apical_e" };
39 
40 SwcSegment::SwcSegment( const string& line )
41  :
42  geometricalDistanceFromSoma_( 0.0 ),
43  electrotonicDistanceFromSoma_( 0.0 )
44 {
45  vector< string > args;
46  stringstream ss( line );
47  string temp;
48  while (ss >> temp ) {
49  args.push_back( temp );
50  }
51  if ( args.size() == 7 ) {
52  myIndex_ = atoi( args[0].c_str() );
53  type_ = atoi( args[1].c_str() );
54  double x = atof( args[2].c_str() );
55  double y = atof( args[3].c_str() );
56  double z = atof( args[4].c_str() );
57  v_ = Vec( x, y, z );
58  radius_ = atof( args[5].c_str() );
59  int pa = atoi( args[6].c_str() );
60  if ( pa > 0 )
61  parent_ = pa;
62  else
63  parent_ = ~0U;
64  } else {
65  type_ = BadSegment;
66  }
67 }
68 
69 SwcSegment::SwcSegment( int i, short type,
70  double x, double y, double z,
71  double r, int parent )
72  :
73  myIndex_( i ),
74  type_( type ),
75  v_( x, y, z ),
76  radius_( r ),
77  length_( 0.0 ),
78  L_( 0.0 ),
79  geometricalDistanceFromSoma_( 0.0 ),
80  electrotonicDistanceFromSoma_( 0.0 )
81 {
82  if ( parent >= 0 )
83  parent_ = parent;
84  else
85  parent_ = ~0U;
86 }
87 
89 {
90  if ( type_ == SOMA ) // already defined as soma
91  return;
92  if ( type_ == DEND ) {
93  if ( kids_.size() > 1 )
94  type_ = FORK; // Dend fork point
95  else if ( kids_.size() == 0 )
96  type_ = END; // end point
97  } else if ( type_ == APICAL ) {
98  if ( kids_.size() > 1 )
99  type_ = APICAL_FORK; // apical Dend fork point
100  else if ( kids_.size() == 0 )
101  type_ = APICAL_END; // apical end point
102  } else if ( type_ == AXON ) {
103  if ( kids_.size() > 1 )
104  type_ = AXON_FORK; // apical Dend fork point
105  else if ( kids_.size() == 0 )
106  type_ = AXON_END; // apical end point
107  }
108 }
109 
111 
112 SwcBranch::SwcBranch( int i, const SwcSegment& start, double len, double L,
113  const vector< int >& cable )
114  : SwcSegment( start ),
115  r0( start.radius() ),
116  r1( start.radius() ),
117  geomLength( len ),
118  electroLength( L )
119 {
120  myIndex_ = i;
121  parent_ = 0;
122  kids_.resize( 0 );
123  segs_.resize( cable.size() );
124  // Put the contents of cable into segs, in reverse order.
125  vector< int >::const_reverse_iterator j = cable.rbegin();
126  vector< int >::iterator k = segs_.begin();
127  for ( k = segs_.begin(); k != segs_.end(); ++k )
128  *k = *j++;
129 }
130 
132 {
133  cout << myIndex() << ": " << segs_[0] << " -> " << segs_.back() <<
134  " = " << segs_.size() <<
135  " : pa = " << parent() << " , length=( " <<
136  geomLength << ", " << electroLength << " )\n";
137 }
const Neuron * parent_
Definition: Spine.h:78
vector< int > segs_
Definition: SwcSegment.h:202
static const short BadSegment
Definition: SwcSegment.h:131
static const short FORK
Definition: SwcSegment.h:127
unsigned int parent() const
Definition: SwcSegment.h:44
double geomLength
Radius at end.
Definition: SwcSegment.h:184
unsigned int myIndex() const
Definition: SwcSegment.h:52
void printDiagnostics() const
Definition: SwcSegment.cpp:131
static const short CUSTOM
Definition: SwcSegment.h:129
Definition: Vec.h:13
void figureOutType()
Definition: SwcSegment.cpp:88
double electroLength
Definition: SwcSegment.h:195
SwcBranch(int i, const SwcSegment &start, double len, double L, const vector< int > &cable)
Definition: SwcSegment.cpp:112
static const short END
Definition: SwcSegment.h:128
static const short SOMA
Definition: SwcSegment.h:123
static const short AXON_END
Definition: SwcSegment.h:133
unsigned int myIndex_
Definition: SwcSegment.h:140
static const short DEND
Definition: SwcSegment.h:125
vector< int > kids_
Definition: SwcSegment.h:169
static const short APICAL_FORK
Definition: SwcSegment.h:134
static const short APICAL_END
Definition: SwcSegment.h:135
static const short UNDEF
Definition: SwcSegment.h:122
short type_
Index of self.
Definition: SwcSegment.h:153
unsigned int parent_
Number of length constants in segment.
Definition: SwcSegment.h:158
static const string typeName[]
Definition: SwcSegment.h:137
static const short APICAL
Definition: SwcSegment.h:126
static const short AXON
Definition: SwcSegment.h:124
static const short AXON_FORK
Definition: SwcSegment.h:132