本文整理汇总了C++中Interpolator::interpolate方法的典型用法代码示例。如果您正苦于以下问题:C++ Interpolator::interpolate方法的具体用法?C++ Interpolator::interpolate怎么用?C++ Interpolator::interpolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpolator
的用法示例。
在下文中一共展示了Interpolator::interpolate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SmileSection
InterpolatedSmileSection<Interpolator>::InterpolatedSmileSection(
const Date& d,
const std::vector<Rate>& strikes,
const std::vector<Real>& stdDevs,
Real atmLevel,
const DayCounter& dc,
const Interpolator& interpolator,
const Date& referenceDate,
const Real shift)
: SmileSection(d, dc, referenceDate, ShiftedLognormal, shift),
exerciseTimeSquareRoot_(std::sqrt(exerciseTime())), strikes_(strikes),
stdDevHandles_(stdDevs.size()), vols_(stdDevs.size())
{
//fill dummy handles to allow generic handle-based
// computations later on
for (Size i=0; i<stdDevs.size(); ++i)
stdDevHandles_[i] = Handle<Quote>(boost::shared_ptr<Quote>(new
SimpleQuote(stdDevs[i])));
atmLevel_ = Handle<Quote>
(boost::shared_ptr<Quote>(new SimpleQuote(atmLevel)));
// check strikes!!!!!!!!!!!!!!!!!!!!
interpolation_ = interpolator.interpolate(strikes_.begin(),
strikes_.end(),
vols_.begin());
}
示例2: setInterpolation
void setInterpolation(const Interpolator& i = Interpolator()) {
varianceSurface_ =
i.interpolate(times_.begin(), times_.end(),
strikes_.begin(), strikes_.end(),
variances_);
notifyObservers();
}
示例3: setInterpolation
void setInterpolation(const Interpolator& i = Interpolator()) {
for (Size j=0; j < times_.size(); ++j) {
localVolInterpol_[j] = i.interpolate(
strikes_[j]->begin(), strikes_[j]->end(),
localVolMatrix_->column_begin(j));
}
notifyObservers();
}
示例4: LogInterpolationImpl
LogInterpolationImpl(const I1& xBegin, const I1& xEnd,
const I2& yBegin,
const Interpolator& factory = Interpolator())
: Interpolation::templateImpl<I1,I2>(xBegin, xEnd, yBegin),
logY_(xEnd-xBegin) {
interpolation_ = factory.interpolate(this->xBegin_,
this->xEnd_,
logY_.begin());
}
示例5: initialize
virtual bool initialize() {
if(!qseq){
string filename = getNativePathString(
boost::filesystem::path(shareDirectory())
/ "motion" / "SR1" / "SR1WalkPattern3.yaml");
BodyMotion motion;
if(!motion.loadStandardYAMLformat(filename)){
os() << motion.seqMessage() << endl;
return false;
}
qseq = motion.jointPosSeq();
if(qseq->numFrames() == 0){
os() << "Empty motion data." << endl;
return false;
}
timeStep_ = qseq->getTimeStep();
}
if(fabs(timeStep() - timeStep_) > 1.0e-6){
os() << "Time step must be " << timeStep_ << "." << endl;;
return false;
}
body = ioBody();
numJoints = body->numJoints();
if(numJoints != qseq->numParts()){
os() << "The number of joints must be " << qseq->numParts() << endl;
return false;
}
qold.resize(numJoints);
VectorXd q0(numJoints);
VectorXd q1(numJoints);
for(int i=0; i < numJoints; ++i){
qold[i] = q0[i] = body->joint(i)->q();
}
MultiValueSeq::Frame frame = qseq->frame(0);
for(int i=0; i < numJoints; ++i){
q1[i] = frame[i];
}
interpolator.clear();
interpolator.appendSample(0.0, q0);
interpolator.appendSample(2.0, q1);
interpolator.update();
qref_old = interpolator.interpolate(0.0);
currentFrame = 0;
phase = 0;
time = 0.0;
return true;
}
示例6: control
virtual bool control() {
switch(phase){
case 0 :
qref = interpolator.interpolate(time);
if(time > interpolator.domainUpper()){
phase = 1;
}
break;
case 1:
if(currentFrame < qseq->numFrames()){
MultiValueSeq::Frame frame = qseq->frame(currentFrame++);
for(int i=0; i < numJoints; ++i){
qref[i] = frame[i];
}
}else{
phase = 2;
}
break;
case 2 :
qref = interpolator.interpolate(time);
}
for(int i=0; i < body->numJoints(); ++i){
Link* joint = body->joint(i);
double q = joint->q();
double dq_ref = (qref[i] - qref_old[i]) / timeStep_;
double dq = (q - qold[i]) / timeStep_;
joint->u() = (qref[i] - q) * pgain[i] + (dq_ref - dq) * dgain[i];
qold[i] = q;
}
qref_old = qref;
time += timeStep_;
return true;
}
示例7: main
int main ()
{
Region reg;
Constants con;
Exodus_file exo;
Driver drv;
Model_file mod;
Utilities utl;
Discontinuity dis;
std::cout << "Begin model building." << std::endl;
// Read parameter file.
drv.initialize ( mod, dis, utl, exo, reg );
drv.checkUsage ( mod, "INTERPOLATE" );
std::cout << "\n----- Interpolating -----\n";
std::cout << "\n";
dis.createKDTreePacked ( );
for ( std::vector < Exodus_file > ::
iterator exoFile=reg.regionsExo.begin();
exoFile!=reg.regionsExo.end(); ++exoFile )
{
std::cout << "\n";
Mesh msh;
Interpolator ipl;
exoFile -> openFile ( exoFile -> fname );
msh.getInfo ( exoFile -> idexo );
mod.createKDTreeUnpacked ( msh );
ipl.interpolate ( msh, mod, dis );
exoFile -> writeParams ( msh );
exoFile -> closeFile ( );
msh.deallocateMesh ( mod );
mod.deallocate ( );
}
drv.report ( mod );
return 0;
}
示例8: interpolate
float TimeInterpolator::interpolate(const Time& time, int variable, const float& c0, const float& c1, const float& c2)
{
int index = Utils<Time>::binary_search(this->timesteps, 0, this->timesteps.size(), time);
Interpolator * a;
if (index > -1)
{
if (time == this->timesteps[index])
{
//check that interpolator is loaded
if (current_kameleon_interpolators.find(this->timesteps[index]) != this->current_kameleon_interpolators.end())
{
a = this->current_kameleon_interpolators[time];
} else //set the interpolator
{
a = this->current_kameleon_files[time]->createNewInterpolator();
this-> current_kameleon_interpolators[time] = a;
}
float value = a->interpolate(variable, c0, c1, c2);
return value;
} else
{
Interpolator * b;
Time atime = this->timesteps[index];
Time btime = this->timesteps[index+1];
//Need to check if interpolators for atime and btime are loaded
if (current_kameleon_interpolators.find(atime) != this->current_kameleon_interpolators.end())
{
a = this->current_kameleon_interpolators[atime];
} else //store the interpolator
{
a = this->current_kameleon_files[atime]->createNewInterpolator();
this-> current_kameleon_interpolators[atime] = a;
}
if (current_kameleon_interpolators.find(btime) != this->current_kameleon_interpolators.end())
{
b = this->current_kameleon_interpolators[btime];
} else //store the interpolator
{
b = this->current_kameleon_files[btime]->createNewInterpolator();
this-> current_kameleon_interpolators[btime] = b;
}
// Interpolator * a = this->current_kameleon_files[atime]->createNewInterpolator(); //wasn't deallocated!
// Interpolator * b = this->current_kameleon_files[btime]->createNewInterpolator();
double duration = btime-atime;
double deltatime = (time - atime);
double r = deltatime / duration;
float avalue = a->interpolate(variable, c0, c1, c2);
float bvalue = b->interpolate(variable, c0, c1, c2);
float deltaValue = bvalue - avalue;
float value = avalue + deltaValue * r;
// std::cout << "inside. interpolated value: " << value << std::endl;
return value;
}
} else
return
-1.f;
}
示例9: control
virtual bool control() {
switch(phase){
case 0 :
qref = interpolator.interpolate(time);
if(time > interpolator.domainUpper()){
phase = 1;
}
break;
case 1:
if(currentFrame < qseq->numFrames()){
MultiValueSeq::Frame frame = qseq->frame(currentFrame++);
for(int i=0; i < numJoints; ++i){
qref[i] = frame[i];
}
}else{
interpolator.clear();
interpolator.appendSample(time, qref);
VectorXd q1(numJoints);
q1 = qref;
q1[rarm_shoulder_r] = -0.4;
q1[rarm_shoulder_p] = 0.75;
q1[rarm_elbow] = -2.0;
interpolator.appendSample(time + 3.0, q1);
q1[rarm_elbow] = -1.57;
q1[rarm_shoulder_p] = -0.2;
q1[rarm_wrist_r] = 1.5;
interpolator.appendSample(time + 5.0, q1);
q1[rarm_elbow] = -1.3;
q1[rarm_wrist_y] = -0.24;
interpolator.appendSample(time + 6.0, q1);
interpolator.update();
qref = interpolator.interpolate(time);
phase = 2;
}
break;
case 2 :
qref = interpolator.interpolate(time);
if(time > interpolator.domainUpper()){
interpolator.clear();
interpolator.appendSample(time, qref);
VectorXd q1(numJoints);
q1 = qref;
q1[rarm_wrist_y] = 0.0;
q1[rarm_shoulder_r] = 0.1;
interpolator.appendSample(time + 5.0, q1);
interpolator.update();
qref = interpolator.interpolate(time);
phase = 3;
}
break;
case 3:
qref = interpolator.interpolate(time);
if( rhsensor->F()[1] < -2 ) {
interpolator.clear();
interpolator.appendSample(time, qref);
VectorXd q1(numJoints);
q1 = qref;
q1[rarm_wrist_r] = -0.3;;
interpolator.appendSample(time + 2.0, q1);
interpolator.appendSample(time + 2.5, q1);
q1[rarm_shoulder_p] = -0.13;
q1[rarm_elbow] = -1.8;
interpolator.appendSample(time + 3.5, q1);
interpolator.update();
qref = interpolator.interpolate(time);
phase = 4;
}
break;
case 4 :
qref = interpolator.interpolate(time);
}
for(int i=0; i < body->numJoints(); ++i){
Link* joint = body->joint(i);
double q = joint->q();
double dq_ref = (qref[i] - qref_old[i]) / timeStep_;
double dq = (q - qold[i]) / timeStep_;
joint->u() = (qref[i] - q) * pgain[i] + (dq_ref - dq) * dgain[i];
qold[i] = q;
}
qref_old = qref;
time += timeStep_;
return true;
}
示例10: setInterpolation
void setInterpolation(const Interpolator& i = Interpolator()) {
varianceCurve_ = i.interpolate(times_.begin(), times_.end(),
variances_.begin());
varianceCurve_.update();
notifyObservers();
}
示例11: main
int main (int argc, char * argv[])
{
std::string filename;
std::string variable;
float c0;
float c1;
float c2;
int iterations = 10;
if (argc != 6)
{
cout << "integrator <filename> <variable> c0 c1 c2" << endl;
exit(1);
}
filename = argv[1];
variable = argv[2];
c0 = boost::lexical_cast<float>(argv[3]);
c1 = boost::lexical_cast<float>(argv[4]);
c2 = boost::lexical_cast<float>(argv[5]);
cout << "This program will compute the integral for a fieldline of the specified variable" << std::endl;
Kameleon kameleon; //creates a kameleon object capable of working with any of the ccmc-supported models
kameleon.open(filename);
kameleon.loadVectorVariable("b"); //see the namespace ccmc::strings::variables for possible inputs
kameleon.loadVectorVariable("e");
Tracer tracer(&kameleon); // Sets the interpolator (based on the kameleon object) to be used for tracing
tracer.setMaxIterations(20000); //Maximum number of points in the fieldline
tracer.setInnerBoundary(2.5f); //radius where fieldlines should stop (usually larger than the model's inner boundary)
tracer.setDn(.2f); //step size relative to the cell size
clock_t start, finish;
cout << "Initializing field line\n";
Fieldline fieldline;
/*
* Supported tracers: input position is cartesian (x,y,z) unless the model is Enlil (r,theta,phi)
* bidirectionalTrace(string variable, float p0, float p1, float p2)
* bidirectionalTraceWithDipole(string variable, float p0, float p1, float p2)
* unidirectionalTrace(string variable, float p0, float p1, float p2, Direction) where Direction must be keyword FORWARD or REVERSE
* unidirectionalTraceWithDipole(string variable, float p0, float p1, float p2, Direction)
*/
cout << "Bidirectional trace beginning at ("<< c0 << ","<<c1<<","<<c2<<")"<<endl;
start = clock();
fieldline = tracer.bidirectionalTrace("b",c0,c1,c2);
finish = clock();
float elapsed_time = ((double) finish - (double) start) / CLOCKS_PER_SEC;
cout << "Fieldline trace took "<< elapsed_time << " seconds\n"<<endl;
cout << "After bidrectional trace\n";
cout << "Points in fieldline:"<<fieldline.size()<<endl;
//You can retrieve the kameleon object's interpolator from the tracer, thusly:
Interpolator * interpolator = tracer.interpolator; //interpolator will be deleted via the Tracer's destructor
//Or you can make a new one, which is useful for doing interpolations in parallel:
//Interpolator * interpolator = kameleon.createNewInterpolator(); //but make sure you delete it when done
Fieldline fieldlineWithVariable;
Point3f p, eField;
float datum, pEx, pEy, pEz;
for (int i = 0; i < fieldline.size(); i++)
{
p = fieldline.getPosition(i);
datum = interpolator->interpolate(variable,p.component1,p.component2,p.component3);
fieldlineWithVariable.insertPointData(p,datum);
eField.component1 = interpolator->interpolate("ex",p.component1,p.component2,p.component3);
eField.component2 = interpolator->interpolate("ey",p.component1,p.component2,p.component3);
eField.component3 = interpolator->interpolate("ez",p.component1,p.component2,p.component3);
fieldlineWithVariable.insertVectorData(eField); // eField in [mV/m]
}
vector<float> segmentLengths = fieldlineWithVariable.getDs(); //computes line segments of fieldline [Re]
vector<float> integral = fieldlineWithVariable.integrate(); //sum of individual segmentLengths * variable
vector<float> fieldlinePotential = fieldlineWithVariable.integrateVector(); // integral(E dot dl)
std::cout<<"integral result:"<< integral.back()<< "[" << variable << "* Re]"<<endl;
std::cout<<"Fieldline potential:"<< fieldlinePotential.back()*(6.3781e3)<<"[V]\n"; //[V] = [Re*mV/m]*[1V/1000mV]*[6.3781e6 m/Re]
kameleon.close();
//delete interpolator; //required if you used kameleon.createNewInterpolator above
std::cout << "finished" << std::endl;
return 0;
}