MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SpineEntry.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) 2013 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 "header.h"
11 #include "Boundary.h"
12 #include "MeshEntry.h"
13 #include "VoxelJunction.h"
14 #include "ChemCompt.h"
15 #include "../utility/Vec.h"
16 #include "CylBase.h"
17 #include "SpineEntry.h"
18 
24 SpineEntry::SpineEntry( Id shaft, Id head, unsigned int parent )
25  :
26  parent_( parent ),
27  shaftId_( shaft ),
28  headId_( head )
29 {
30  double dia = Field< double >::get( shaft, "diameter" );
31  double length = Field< double >::get( shaft, "length" );
32  double x0 = Field< double >::get( shaft, "x0" );
33  double y0 = Field< double >::get( shaft, "y0" );
34  double z0 = Field< double >::get( shaft, "z0" );
35  double x1 = Field< double >::get( shaft, "x" );
36  double y1 = Field< double >::get( shaft, "y" );
37  double z1 = Field< double >::get( shaft, "z" );
38  double x2 = Field< double >::get( head, "x" );
39  double y2 = Field< double >::get( head, "y" );
40  double z2 = Field< double >::get( head, "z" );
41  double hdia = Field< double >::get( head, "diameter" );
42  double hlength = Field< double >::get( head, "length" );
43 
44  // cout << "SpineEntry: " << parent_ << " " << x0 << " " << x1 << " " << x2 << " : " << y0 << " " << y1<< " " << y2 << " : " << z0 << " " << z1 << " " << z2 << " " << hdia << endl;
45 
46  root_.setX( x0 );
47  root_.setY( y0 );
48  root_.setZ( z0 );
49  shaft_.setX( x1 );
50  shaft_.setY( y1 );
51  shaft_.setZ( z1 );
52  head_.setX( x2 );
53  head_.setY( y2 );
54  head_.setZ( z2 );
55 
56  root_.setDia( dia );
57  root_.setLength( length );
58  root_.setNumDivs( 0 );
59  root_.setIsCylinder( true );
60  shaft_.setDia( dia );
61  shaft_.setLength( length );
62  shaft_.setNumDivs( 1 );
63  shaft_.setIsCylinder( true );
64  head_.setDia( hdia );
65  head_.setLength( hlength );
66  head_.setNumDivs( 1 );
67  head_.setIsCylinder( true );
68 }
69 
70 
72  :
73  parent_( 0 ),
74  shaftId_( Id() ),
75  headId_( Id() )
76 {
77  const double defaultLength = 1e-6;
78  root_.setX( 0 );
79  root_.setY( 0 );
80  root_.setZ( 0 );
81  shaft_.setX( defaultLength );
82  shaft_.setY( 0 );
83  shaft_.setZ( 0 );
84  head_.setX( defaultLength * 2 );
85  head_.setY( 0 );
86  head_.setZ( 0 );
87 
88 
89 
90  root_.setDia( defaultLength );
91  root_.setLength( defaultLength );
92  root_.setNumDivs( 0 );
93  root_.setIsCylinder( true );
94  shaft_.setDia( defaultLength );
95  shaft_.setLength( defaultLength );
96  shaft_.setNumDivs( 1 );
97  shaft_.setIsCylinder( true );
98  head_.setDia( defaultLength );
99  head_.setLength( defaultLength );
100  head_.setNumDivs( 1 );
101  head_.setIsCylinder( true );
102 }
103 
104 unsigned int SpineEntry::parent() const
105 {
106  return parent_;
107 }
108 
110 {
111  return shaftId_;
112 }
113 
115 {
116  return headId_;
117 }
118 
119 void SpineEntry::setParent( unsigned int parent )
120 {
121  parent_ = parent;
122 }
123 
124 void SpineEntry::mid( double& x, double& y, double& z ) const
125 {
126  x = ( shaft_.getX() + head_.getX() ) / 2.0;
127  y = ( shaft_.getY() + head_.getY() ) / 2.0;
128  z = ( shaft_.getZ() + head_.getZ() ) / 2.0;
129 }
130 
132  unsigned int myIndex,
133  double granularity, vector< VoxelJunction >& ret )
134 {
135  // First flag is for curve, second is for cap of cylinder.
136  head_.matchCubeMeshEntries( compt, shaft_, myIndex,
137  granularity, ret, true, true );
138 }
139 
140 double SpineEntry::volume() const
141 {
142  return head_.volume( shaft_ );
143 }
144 
146  unsigned int myIndex,
147  double granularity, vector< VoxelJunction >& ret ) const
148 {
149  head_.matchCubeMeshEntries( compt, shaft_, myIndex,
150  granularity, ret, true, false );
151 }
152 
154  unsigned int myIndex,
155  double granularity, vector< VoxelJunction >& ret ) const
156 {
157  // First flag is for curve, second is for cap of cylinder.
158  head_.matchCubeMeshEntries( compt, shaft_, myIndex,
159  granularity, ret, false, true );
160 }
161 
168  const ChemCompt* compt, unsigned int myIndex,
169  double& area, double& length ) const
170 {
171  return 0;
172 }
173 
174 double SpineEntry::rootArea() const
175 {
176  return root_.getDia() * root_.getDia() * PI * 0.25;
177 }
178 
180 {
181  // I've simplified this because a) it doesn't make much sense to add
182  // a diffusion length with a different axial size and b) it makes the
183  // resizing hugely complicated.
184  // return shaft_.getLength() + 0.5 * head_.getLength();
185  return shaft_.getLength();
186 }
187 
188 vector< double > SpineEntry::psdCoords() const
189 {
190  vector< double > ret( 8, 0.0 );
191  double m0, m1, m2;
192  mid( m0, m1, m2 );
193  ret[0] = m0;
194  ret[1] = m1;
195  ret[2] = m2;
196  ret[3] = head_.getX() - m0;
197  ret[4] = head_.getY() - m1;
198  ret[5] = head_.getZ() - m2;
199  /*
200  ret[0] = head_.getX();
201  ret[1] = head_.getY();
202  ret[2] = head_.getZ();
203  double m0, m1, m2;
204  mid( m0, m1, m2 );
205  ret[3] = ret[0] - m0;
206  ret[4] = ret[1] - m1;
207  ret[5] = ret[2] - m2;
208  */
209  ret[6] = head_.getDia();
210  ret[7] = sqrt( ret[3] * ret[3] + ret[4] * ret[4] + ret[5] * ret[5] );
211 
212  return ret;
213 }
214 
215 
216 void SpineEntry::setVolume( double volume )
217 {
218  double volscale = volume / head_.volume( shaft_ );
219  double linscale = pow( volscale, 1.0 / 3.0 );
220  head_.setLength( head_.getLength() * linscale );
221  head_.setDia( head_.getDia() * linscale );
222  double dx = head_.getX() - shaft_.getX();
223  double dy = head_.getY() - shaft_.getY();
224  double dz = head_.getZ() - shaft_.getZ();
225  head_.setX( dx * linscale + shaft_.getX() );
226  head_.setY( dy * linscale + shaft_.getY() );
227  head_.setZ( dz * linscale + shaft_.getZ() );
228 }
229 
230 void SpineEntry::positionShaftBase( double x, double y, double z )
231 {
232  double dx = x - root_.getX();
233  double dy = y - root_.getY();
234  double dz = y - root_.getZ();
235  root_.setX( x );
236  root_.setY( y );
237  root_.setZ( z );
238  shaft_.setX( dx + shaft_.getX() );
239  shaft_.setY( dy + shaft_.getY() );
240  shaft_.setZ( dz + shaft_.getZ() );
241  head_.setX( dx + head_.getX() );
242  head_.setY( dy + head_.getY() );
243  head_.setZ( dz + head_.getZ() );
244 }
245 
unsigned int parent_
head cylinder.
Definition: SpineEntry.h:110
void matchCubeMeshEntriesToPSD(const ChemCompt *compt, unsigned int myIndex, double granularity, vector< VoxelJunction > &ret) const
Definition: SpineEntry.cpp:153
double getLength() const
Definition: CylBase.cpp:98
void setNumDivs(unsigned int v)
Definition: CylBase.cpp:103
CylBase head_
Shaft cylinder.
Definition: SpineEntry.h:106
Id shaftId_
Id of electrical compartment in which this diffusive compt lives.
Definition: SpineEntry.h:113
unsigned int parent() const
Returns index of parent entry located on NeuroMesh.
Definition: SpineEntry.cpp:104
double rootArea() const
Definition: SpineEntry.cpp:174
CylBase root_
Definition: SpineEntry.h:104
double volume() const
Return volume of spine. Ignores shaft volume. Virtual func.
Definition: SpineEntry.cpp:140
void setX(double v)
Definition: CylBase.cpp:53
double getX() const
Definition: CylBase.cpp:58
void matchCubeMeshEntries(const ChemCompt *other, unsigned int myIndex, double granularity, vector< VoxelJunction > &ret)
Definition: SpineEntry.cpp:131
double volume(const CylBase &parent) const
Returns vol of current node. Usually needs to refer to parent.
Definition: CylBase.cpp:135
void mid(double &x, double &y, double &z) const
Return coords of centre of spine head.
Definition: SpineEntry.cpp:124
void setLength(double v)
Definition: CylBase.cpp:93
double getY() const
Definition: CylBase.cpp:68
CylBase shaft_
Anchor point on dendrite.
Definition: SpineEntry.h:105
vector< double > psdCoords() const
Definition: SpineEntry.cpp:188
void positionShaftBase(double x, double y, double z)
Definition: SpineEntry.cpp:230
void matchCubeMeshEntries(const ChemCompt *other, const CylBase &parent, unsigned int startIndex, double granularity, vector< VoxelJunction > &ret, bool useCylinderCurve, bool useCylinderCap) const
Definition: CylBase.cpp:320
void setZ(double v)
Definition: CylBase.cpp:73
void setParent(unsigned int parent)
Assigns index of parent entry located on NeuroMesh.
Definition: SpineEntry.cpp:119
double diffusionLength() const
Definition: SpineEntry.cpp:179
void setVolume(double volume)
Definition: SpineEntry.cpp:216
unsigned int matchNeuroMeshEntriesToShaft(const ChemCompt *compt, unsigned int myIndex, double &area, double &length) const
Definition: SpineEntry.cpp:167
void setIsCylinder(bool v)
Definition: CylBase.cpp:113
void setY(double v)
Definition: CylBase.cpp:63
Id shaftId() const
Definition: SpineEntry.cpp:109
double getDia() const
Definition: CylBase.cpp:88
double getZ() const
Definition: CylBase.cpp:78
void setDia(double v)
Definition: CylBase.cpp:83
const double PI
Definition: consts.cpp:12
Definition: Id.h:17
void matchCubeMeshEntriesToHead(const ChemCompt *compt, unsigned int myIndex, double granularity, vector< VoxelJunction > &ret) const
Returns Id of head electrical compartment.
Definition: SpineEntry.cpp:145
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Id headId() const
Returns Id of shaft electrical compartment.
Definition: SpineEntry.cpp:114