22 #include "../utility/Vec.h"
24 extern const double PI;
27 double dia,
double length,
unsigned int numDivs )
139 double r0 = parent.
dia_/2.0;
140 double r1 =
dia_/2.0;
141 return length_ * ( r0*r0 + r0 *r1 + r1 * r1 ) *
PI / 3.0;
158 double frac0 = (
static_cast< double >( fid ) ) /
160 double frac1 = (
static_cast< double >( fid + 1 ) ) /
162 double r0 = 0.5 * ( parent.
dia_ * ( 1.0 - frac0 ) +
dia_ * frac0 );
163 double r1 = 0.5 * ( parent.
dia_ * ( 1.0 - frac1 ) +
dia_ * frac1 );
167 return (s1 - s0) * ( r0*r0 + r0 *r1 + r1 * r1 ) *
PI / 3.0;
173 const CylBase& parent,
unsigned int fid )
const
176 double frac0 = (
static_cast< double >( fid ) ) /
178 double frac1 = (
static_cast< double >( fid + 1 ) ) /
181 double r0 = 0.5 * ( parent.
dia_ * ( 1.0 - frac0 ) +
dia_ * frac0 );
183 double r1 = 0.5 * ( parent.
dia_ * ( 1.0 - frac1 ) +
dia_ * frac1 );
185 vector< double > ret( 10, 0.0 );
186 ret[0] = parent.
x_ + frac0 * (
x_ - parent.
x_ );
187 ret[1] = parent.
y_ + frac0 * (
y_ - parent.
y_ );
188 ret[2] = parent.
z_ + frac0 * (
z_ - parent.
z_ );
189 ret[3] = parent.
x_ + frac1 * (
x_ - parent.
x_ );
190 ret[4] = parent.
y_ + frac1 * (
y_ - parent.
y_ );
191 ret[5] = parent.
z_ + frac1 * (
z_ - parent.
z_ );
211 const CylBase& parent,
unsigned int fid )
const
216 double frac0 = (
static_cast< double >( fid ) ) /
218 double r0 = 0.5 * ( parent.
dia_ * ( 1.0 - frac0 ) +
dia_ * frac0 );
224 const CylBase& parent,
unsigned int fid )
const
229 double frac0 = ( 0.5 +
static_cast< double >( fid ) ) /
231 double r0 = 0.5 * ( parent.
dia_ * ( 1.0 - frac0 ) +
dia_ * frac0 );
243 double granularity )
const
246 return granularity *
dia_ / 2.0;
252 if ( h >
dia_ / 2.0 )
257 unsigned int num = ceil( lambda / h );
264 const Vec& u,
const Vec& v,
const Vec& q,
265 double h,
double r, vector< double >& area,
273 unsigned int numAngle = floor( 2.0 *
PI * r / h + 0.5 );
274 assert( numAngle > 0 );
275 double dtheta = 2.0 *
PI / numAngle;
276 double dArea = h * dtheta * r;
278 for (
unsigned int j = 0; j < numAngle; ++j ) {
279 double theta = j * dtheta;
280 double c = cos( theta );
281 double s = sin( theta );
282 double p0 = q.
a0() + r * ( u.
a0() * c + v.
a0() * s );
283 double p1 = q.
a1() + r * ( u.
a1() * c + v.
a1() * s );
284 double p2 = q.
a2() + r * ( u.
a2() * c + v.
a2() * s );
287 area[index] += dArea;
292 const Vec& u,
const Vec& v,
const Vec& q,
293 double h,
double r, vector< double >& area,
297 unsigned int numRadial = floor( r / h + 0.5 );
298 double dRadial = r / numRadial;
299 for (
unsigned int i = 0; i < numRadial; ++i ) {
300 double a = ( i + 0.5 ) * dRadial;
301 unsigned int numAngle = floor( 2.0 *
PI * a / h + 0.5 );
304 double dtheta = 2.0 *
PI / numAngle;
305 double dArea = dRadial * dtheta * a;
306 for (
unsigned int j = 0; j < numAngle; ++j ) {
307 double theta = j * dtheta;
308 double c = cos( theta );
309 double s = sin( theta );
310 double p0 = q.
a0() + a * ( u.
a0() * c + v.
a0() * s );
311 double p1 = q.
a1() + a * ( u.
a1() * c + v.
a1() * s );
312 double p2 = q.
a2() + a * ( u.
a2() * c + v.
a2() * s );
315 area[index] += dArea;
322 unsigned int startIndex,
324 vector< VoxelJunction >& ret,
325 bool useCylinderCurve,
bool useCylinderCap )
const
338 unsigned int num = floor( 0.1 + lambda / h );
342 for (
unsigned int i = 0; i <
numDivs_; ++i ) {
344 if ( useCylinderCurve ) {
345 for (
unsigned int j = 0; j < num; ++j ) {
346 unsigned int m = i * num + j;
347 double frac = ( m * h + h/2.0 ) /
length_;
348 double q0 =
x_ + a.
a0() * frac;
349 double q1 =
y_ + a.
a1() * frac;
350 double q2 =
z_ + a.
a2() * frac;
354 r = parent.
dia_/2.0 + frac * rSlope;
359 if ( useCylinderCap && i == numDivs_ - 1 ) {
361 h,
dia_/2.0, area, other );
366 for (
unsigned int k = 0; k < area.size(); ++k ) {
367 if ( area[k] > EPSILON ) {
380 double& linePos,
double& r )
const
394 Vec a( parent.
x_, parent.
y_, parent.
z_ );
399 assert( dist > EPSILON );
400 double k = ( b - a ).dotProduct( c - a );
416 unsigned int& index )
const
420 double ret =
nearest( x, y, z, parent, k, r );
424 }
else if ( k > 1.0 ) {
429 if ( index >= numDivs_ )
430 index = numDivs_ - 1;
432 if ( ret > r * 1.01 )
double x_
end of the node. The start is given by parent coords.
static void fillPointsOnDisc(const Vec &u, const Vec &v, const Vec &q, double h, double r, vector< double > &area, const CubeMesh *other)
static void fillPointsOnCircle(const Vec &u, const Vec &v, const Vec &q, double h, double r, vector< double > &area, const CubeMesh *other)
void setNumDivs(unsigned int v)
double length_
Diameter of node end.
unsigned int spaceToIndex(double x, double y, double z) const
Converts the 3-D coords to an index. EMPTY if out of range.
double voxelVolume(const CylBase &parent, unsigned int fid) const
bool isCylinder_
Number of subdivisions of cylinder.
double getDiffusionArea(const CylBase &parent, unsigned int index) const
double volume(const CylBase &parent) const
Returns vol of current node. Usually needs to refer to parent.
vector< double > getCoordinates(const CylBase &parent, unsigned int entry) const
double nearest(double x, double y, double z, const CylBase &parent, double &linePos, double &r) const
unsigned int getNumEntries() const
unsigned int numDivs_
Length of compartment.
static SrcFinfo0 s0("s0","")
void matchCubeMeshEntries(const ChemCompt *other, const CylBase &parent, unsigned int startIndex, double granularity, vector< VoxelJunction > &ret, bool useCylinderCurve, bool useCylinderCap) const
double getMiddleArea(const CylBase &parent, unsigned int index) const
Return cross-section area of middle of specified voxel.
double distance(const Vec &other) const
bool getIsCylinder() const
void setIsCylinder(bool v)
static const unsigned int EMPTY
void orthogonalAxes(Vec &u, Vec &v) const
Generates vectors u and v to form a mutually orthogonal system.
unsigned int getNumDivs() const
double selectGridSize(double h, double dia1, double granularity) const
double getVoxelLength() const
Return length of voxel. All are equal.
Vec pointOnLine(const Vec &end, double k)