void BezierCurve::calculateCage(unsigned seg, Vector3F *p) const { if(seg == 0) p[0] = m_cvs[0]; else p[0] = (m_cvs[seg] * 2.f + m_cvs[seg - 1] + m_cvs[seg + 1]) * .25f; if(seg >= numSegments() - 1) p[3] = m_cvs[numSegments()]; else p[3] = (m_cvs[seg + 1] * 2.f + m_cvs[seg] + m_cvs[seg + 2]) * .25f; p[1] = (m_cvs[seg + 1] * 0.5f + m_cvs[seg] * 0.5f) * .5f + p[0] * .5f; p[2] = (m_cvs[seg] * 0.5f + m_cvs[seg + 1] * 0.5f) * .5f + p[3] * .5f; }
// Count signaling compts, also subdivide for long dend compts. void SigNeur::assignSignalingCompts() { numSoma_ = 0; numDend_ = 0; numSpine_ = 0; numNeck_ = 0; for ( vector< TreeNode >::iterator i = tree_.begin(); i != tree_.end(); ++i ) { if ( i->category == SOMA ) { unsigned int ns = numSegments( i->compt, lambda_ ); i->sigStart = numSoma_; i->sigEnd = numSoma_ = numSoma_ + ns; } else if ( i->category == DEND ) { unsigned int ns = numSegments( i->compt, lambda_ ); i->sigStart = numDend_; i->sigEnd = numDend_ = numDend_ + ns; // cout << " " << numSegments; } else if ( i->category == SPINE ) { i->sigStart = numSpine_; i->sigEnd = ++numSpine_; } else if ( i->category == SPINE_NECK ) { ++numNeck_; } } // cout << endl; // Now reposition the indices for the dends and spines, depending on // the numerical methods. // if ( dendMethod_ == "rk5" && somaMethod_ == dendMethod_ ) { for ( vector< TreeNode >::iterator i = tree_.begin(); i != tree_.end(); ++i ) { if ( i->category == DEND ) { i->sigStart += numSoma_; i->sigEnd += numSoma_; } } // } // if ( dendMethod_ == "rk5" && spineMethod_ == dendMethod_ ) { unsigned int offset = numSoma_ + numDend_; for ( vector< TreeNode >::iterator i = tree_.begin(); i != tree_.end(); ++i ) { if ( i->category == SPINE ) { i->sigStart += offset; i->sigEnd += offset; } } // } // reportTree(); }
/* ================ idCameraDef::getActiveSegmentInfo ================ */ void idCameraDef::getActiveSegmentInfo(int segment, idVec3 &origin, idVec3 &direction, float *fov) { #if 0 if (!cameraSpline.validTime()) { buildCamera(); } double d = (double)segment / numSegments(); getCameraInfo(d * totalTime * 1000, origin, direction, fov); #endif /* if (!cameraSpline.validTime()) { buildCamera(); } origin = *cameraSpline.getSegmentPoint(segment); idVec3 temp; int numTargets = getTargetSpline()->controlPoints.Num(); int count = cameraSpline.splineTime.Num(); if (numTargets == 0) { // follow the path if (cameraSpline.getActiveSegment() < count - 1) { temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1]; } } else if (numTargets == 1) { temp = *getTargetSpline()->controlPoints[0]; } else { temp = *getTargetSpline()->getSegmentPoint(segment); } temp -= origin; temp.Normalize(); direction = temp; */ }
const BoundingBox BezierCurve::calculateBBox() const { BoundingBox b; const unsigned ns = numSegments(); for(unsigned i=0; i < ns; i++) b.expandBy(calculateBBox(i)); return b; }
Vector3F BezierCurve::interpolate(float param) const { unsigned seg = segmentByParameter(param); Vector3F p[4]; calculateCage(seg, p); float t = param * numSegments() - seg; return calculateBezierPoint(t, p); }
void BezierCurve::getSegmentSpline(unsigned i, BezierSpline & spline) const { unsigned v[4]; v[0] = i-1; v[1] = i; v[2] = i+1; v[3] = i+2; if(i==0) v[0] = 0; if(i==numSegments()-1) v[3] = i+1; if(i==0) spline.cv[0] = m_cvs[v[0]]; else spline.cv[0] = m_cvs[v[0]] * .25f + m_cvs[v[1]] * .5f + m_cvs[v[2]] * .25f ; spline.cv[1] = spline.cv[0] * .5f + m_cvs[v[1]] * .25f + m_cvs[v[2]] * .25f; if(i==numSegments()-1) spline.cv[3] = m_cvs[v[3]]; else spline.cv[3] = m_cvs[v[1]] * .25f + m_cvs[v[2]] * .5f + m_cvs[v[3]] * .25f ; spline.cv[2] = spline.cv[3] * .5f + m_cvs[v[1]] * .25f + m_cvs[v[2]] * .25f; }
float BezierCurve::length() const { float sum = 0.f; const unsigned ns = numSegments(); BezierSpline sp; for(unsigned i=0; i < ns; i++) { getSegmentSpline(i, sp); sum += splineLength(sp); } return sum; }
float BezierCurve::distanceToPoint(const Vector3F & toP, Vector3F & closestP) const { float minD = 1e8; const unsigned ns = numSegments(); for(unsigned i=0; i < ns; i++) { BezierSpline sp; getSegmentSpline(i, sp); distanceToPoint(sp, toP, minD, closestP); } return minD; }
bool BezierCurve::intersectBox(const BoundingBox & box) { BoundingBox ab = calculateBBox(); if(!ab.intersect(box)) return false; const unsigned ns = numSegments(); for(unsigned i=0; i < ns; i++) { BezierSpline sp; getSegmentSpline(i, sp); if(intersectBox(sp, box)) return true; } return false; }
bool BezierCurve::intersectTetrahedron(const Vector3F * tet) { BoundingBox tbox; tbox.expandBy(tet[0]); tbox.expandBy(tet[1]); tbox.expandBy(tet[2]); tbox.expandBy(tet[3]); BoundingBox ab = calculateBBox(); if(!ab.intersect(tbox)) return false; const unsigned ns = numSegments(); for(unsigned i=0; i < ns; i++) { BezierSpline sp; getSegmentSpline(i, sp); if(intersectTetrahedron(sp, tet, tbox)) return true; } return false; }