void keyOperations(void) { if (keyStates['a']) { camera->RotateX(-DownlookDist); camera->RotateY(0.75); camera->RotateX(DownlookDist); } if (keyStates['d']) { camera->RotateX(-DownlookDist); camera->RotateY(-0.75); camera->RotateX(DownlookDist); } if (keyStates['w']) camera->MoveForward((GLfloat)(-0.1* speed)); if (keyStates['s']) camera->MoveForward((GLfloat)(0.1* speed )); if (keyStates['q']) { DownlookDist += 0.75; camera->RotateX(0.75); } if (keyStates['e']) { DownlookDist -= 0.75; camera->RotateX(-0.75); } if (keyStates[' ']) glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); else glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); if (camera->GetX()<0) camera->SetX(0); if (camera->GetZ()<0) camera->SetZ(0); if (camera->GetX()>WORLD_SIZE-1) camera->SetX(WORLD_SIZE-1); if (camera->GetZ()>WORLD_SIZE-1) camera->SetZ(WORLD_SIZE-1); if (fp) { float newY = linearInterpolate( linearInterpolate( Island->getSAt((int)camera->GetZ(),(int)camera->GetX())->elevation, Island->getSAt((int)camera->GetZ()+1,(int)camera->GetX())->elevation, camera->GetZ()-int(camera->GetZ())), linearInterpolate( Island->getSAt((int)camera->GetZ(),(int)camera->GetX()+1)->elevation, Island->getSAt((int)camera->GetZ()+1,(int)camera->GetX()+1)->elevation, camera->GetZ()-int(camera->GetZ())), camera->GetX()-int(camera->GetX())); camera->SetY(newY+2); } }
//Computes the updated state of the system. Is called from the process function. //This performs state space interpolation to calculate the state of the //channel. //When a value of Vm_ and ligandConc_ is provided, we find the 4 matrix //exponentials that are closest to these values, and then calculate the //states at each of these 4 points. We then interpolate between these //states to calculate the final one. //In case all rates are 1D, then, the above-mentioned interpolation is //only one-dimensional in nature. void MarkovSolverBase::computeState( ) { Vector* newState; bool useBilinear = false, useLinear = false; if ( rateTable_->areAnyRates2d() || ( rateTable_->areAllRates1d() && rateTable_->areAnyRatesVoltageDep() && rateTable_->areAnyRatesLigandDep() ) ) { useBilinear = true; } else if ( rateTable_->areAllRatesVoltageDep() || rateTable_->areAllRatesLigandDep() ) { useLinear = true; } //Heavily borrows from the Interpol2D::interpolate function. if ( useBilinear ) newState = bilinearInterpolate(); else newState = linearInterpolate(); state_ = *newState; delete newState; }
int makeBlurPat(int n,int ang,int **x,int **y,int **val,int *sum) { int *tmpx, *tmpy, *tmpv; int *mat; int msum,tsum; int xx,yy,i; int vv; int hf; double rad; double fx,fy,tx,ty; double sinT,cosT; hf=n/2; tmpx=malloc(sizeof(int)*n*n); tmpy=malloc(sizeof(int)*n*n); tmpv=malloc(sizeof(int)*n*n); mat=malloc(sizeof(int)*n*n); for(yy=0;yy<n;yy++){ for(xx=0;xx<n;xx++){ mat[xx+yy*n]=0; } } msum=0; for(xx=0;xx<n;xx++){ vv=xx+1; if(vv>hf+1) vv=0; mat[xx+hf*n]=vv; msum+=vv; } rad=(double)ang*(3.14159265)/180.0; sinT=sin(rad); cosT=cos(rad); i=0; tsum=0; for(yy=0;yy<n;yy++){ for(xx=0;xx<n;xx++){ tx=(double)(xx-hf); ty=(double)(yy-hf); fx= cosT*tx+sinT*ty ; (double)hf; fy= -sinT*tx+cosT*ty + (double)hf; vv=linearInterpolate(mat,n,fx,fy); if(vv){ tmpx[i]=xx-hf; tmpy[i]=yy-hf; tmpv[i]=vv; tsum+=tmpv[i]; i++; } } } free(mat); *x=tmpx; *y=tmpy; *val=tmpv; *sum=tsum; return i; }
const tmp<surfaceScalarField> interpolWeights(GeometricField<type, fvPatchField, volMesh>& vf, const word& name){ //vf.boundaryField().updateCoeffs(); const objectRegistry& db = vf.db(); //const volVectorField& u = db.lookupObject<volVectorField>("vc"); const volVectorField& u = db.lookupObject<volVectorField>("u"); //const volVectorField& u = db.lookupObject<volVectorField>("s"); surfaceScalarField phi ( IOobject ( "phi", vf.time().timeName(), vf.mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), linearInterpolate(u) & vf.mesh().Sf() ); tmp<surfaceInterpolationScheme<type> > tinterpScheme; tinterpScheme = fvc::scheme<type>(phi, vf.mesh().schemesDict().interpolationScheme(name)); const surfaceInterpolationScheme<type>& interpolationScheme = tinterpScheme(); tmp<surfaceScalarField> tweights = interpolationScheme.weights(vf); //Info << "weights[15]:" << tweights()[15] << endl; return tweights; }
Vector3r PsdAxialBias::unitPos(const Real& d){ if(psdPts.empty()) throw std::runtime_error("AxialBias.psdPts: must not be empty."); Vector3r p3=Mathr::UnitRandom3(); Real& p(p3[axis]); size_t pos=0; // contains fraction number in the PSD if(!discrete){ p=linearInterpolate(d,psdPts,pos); } else { Real f0,f1,t; std::tie(f0,f1,t)=linearInterpolateRel(d,psdPts,pos); LOG_TRACE("PSD interp for "<<d<<": "<<f0<<".."<<f1<<", pos="<<pos<<", t="<<t); if(t==0.){ // we want the interval to the left of our point if(pos==0){ LOG_WARN("PsdAxiaBias.unitPos: discrete PSD interpolation returned point at the beginning for d="<<d<<", which should be zero. No interpolation done, setting 0."); p=0; return p3; } f1=f0; f0=psdPts[pos-1].y(); } // pick randomly in our interval p=f0+Mathr::UnitRandom()*(f1-f0); //cerr<<"Picked from "<<d0<<".."<<d1<<": "<<p<<endl; } // reorder fractions if desired if(!reorder.empty()){ Real a=0, dp=p-psdPts[pos].y(); for(size_t i=0; i<reorder.size(); i++){ if(reorder[i]==(int)pos){ p=a+dp; break; } // cumulate bin sizes of other fractions, except for the very last one which is zero by definition if(i<psdPts.size()-1) a+=psdPts[reorder[i]+1].y()-psdPts[reorder[i]].y(); } } // apply fuzz p=CompUtils::clamped(p+fuzz*(Mathr::UnitRandom()-.5),0,1); if(invert) p=1-p; return p3; }
tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fourthSnGrad<Type>::correction ( const GeometricField<Type, fvPatchField, volMesh>& vf ) const { const fvMesh& mesh = this->mesh(); tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tcorr ( (1.0/15.0) *( correctedSnGrad<Type>(mesh).snGrad(vf) - (linearInterpolate(gaussGrad<Type>(mesh).grad(vf)) & mesh.Sf()) /mesh.magSf() ) ); if (correctedSnGrad<Type>(mesh).corrected()) { tcorr() += correctedSnGrad<Type>(mesh).correction(vf); } return tcorr; }
//============================================================================== Error SceneAmbientColorEvent::update(F32 /*prevUpdateTime*/, F32 crntTime) { getSceneGraph().setAmbientColor( linearInterpolate(m_originalColor, m_finalColor, getDelta(crntTime))); return ErrorCode::NONE; }
bool Contour::findNextTriangle( double z, int t1, int e1, int& t2, int& e2, DT_Point& p ) { // 已达到边界 if( t1 == -1 ) return false; // 对第i个三角形的另外2条边进行检查并插值 e2 = getNextEdge( t1, e1 ); if( isNextTriangleUsed( t1, e2 ) || !hasContourPoint( z, e2 ) ) { e2 = getNextEdge( t1, e2 ); if( isNextTriangleUsed( t1, e2 ) || !hasContourPoint( z, e2 ) ) { return false; } } // 将当前的三角形的标记为已使用 getTriangleObject( t1 )->used = true; // 将三角形的编号进行转换 t2 = getNextTriangle( e2, t1 ); // 对边e2线性插值 linearInterpolate( z, e2, p ); return true; }
p2d bezierInterpolation(p2d* arr, unsigned int pnum, float f) { unsigned int linecnt = pnum-1; p2d* tmparr; p2d tmpp; int i; tmparr = copyp2darr(arr, pnum); while(linecnt > 0) { for(i=1;i<linecnt+1;i++) { tmpp = linearInterpolate(tmparr[i-1], tmparr[i], f); releasp2d(tmparr[i-1]); tmparr[i-1]=tmpp; } --linecnt; } tmpp = copyp(tmparr[0]); releasep2darr(tmparr, pnum); return tmpp; }
inline float bilinearInterpolate(const float *src, float u, float v, int w_x, int w_y) { int x_l = floor(u); int x_r = ceil(u); int y_l = floor(v); int y_r = ceil(v); float ret; float p[2][2] = {{0, 0}, {0, 0}}; // ll, lr, rl, rr bool avail[2][2] = {{False, False}, {False, False}}; if (x_l < w_x && y_l < w_y && x_l >= 0 && y_l >= 0) { p[0][0] = src[x_l * w_y + y_l]; avail[0][0] = True; } if (x_l < w_x && y_r < w_y && x_l >= 0 && y_r >= 0) { p[0][1] = src[x_l * w_y + y_r]; avail[0][1] = True; } if (x_r < w_x && y_l < w_y && x_r >= 0 && y_l >= 0) { p[1][0] = src[x_r * w_y + y_l]; avail[1][0] = True; } if (x_r < w_x && y_r < w_y && x_r >= 0 && y_r >= 0) { p[1][1] = src[x_r * w_y + y_r]; avail[1][1] = True; } if (!(avail[0][0] || avail[0][1] || avail[1][0] || avail[1][1])) ret = 0; else { float x = u - x_l; float y = v - y_l; // ret=bilinearInterpolate(p, avail, dx, dy); float tmp[2]; tmp[0] = linearInterpolate(p[0], avail[0], y); tmp[1] = linearInterpolate(p[1], avail[1], y); bool avail_tmp[2] = {False, False}; if (avail[0][0] || avail[0][1]) avail_tmp[0] = True; if (avail[1][0] || avail[1][1]) avail_tmp[1] = True; ret = linearInterpolate(tmp, avail_tmp, x); } return ret; }
tmp<GeometricField<Type, fvPatchField, volMesh> > average ( const GeometricField<Type, fvPatchField, volMesh>& vtf ) { return fvc::average(linearInterpolate(vtf)); }
void DistortionComponent::resetPoints() { const int w = getWidth(); const int h = getHeight(); const int bufferSize = buffer.getSize(); const float* bufferData = buffer.getData(); float x1 = w * 0.25f; float y1 = h * linearInterpolate (bufferData, bufferSize, bufferSize * 0.75f); float x2 = w * 0.75f; float y2 = h * linearInterpolate (bufferData, bufferSize, bufferSize * 0.25f); curvePoints[0]->setBounds ((int) (x1 - 5), (int) (y1 - 5), 10, 10); curvePoints[1]->setBounds ((int) (x2 - 5), (int) (y2 - 5), 10, 10); }
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh) { Info<< "Reading velocity field U\n" << endl; volVectorField U ( IOobject ( "U", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ), mesh ); Info<< "Reading/calculating face flux field phi\n" << endl; surfaceScalarField phi ( IOobject ( "phi", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), linearInterpolate(U) & mesh.Sf() ); Info<< "Creating LES filter width field LESdelta\n" << endl; volScalarField LESdelta ( IOobject ( "LESdelta", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("LESdelta", dimLength, SMALL) ); singlePhaseTransportModel laminarTransport(U, phi); autoPtr<incompressible::LESModel> sgsModel ( incompressible::LESModel::New(U, phi, laminarTransport) ); LESdelta.internalField() = sgsModel->delta(); LESdelta.write(); Info<< "End" << endl; }
interpolationCellPointFace<Type>::interpolationCellPointFace ( const GeometricField<Type, fvPatchField, volMesh>& psi ) : interpolation<Type>(psi), psip_(volPointInterpolation::New(psi.mesh()).interpolate(psi)), psis_(linearInterpolate(psi)) {}
void AffectorRoad::_legacyAffect (const float worldX, const float worldZ, const int x, const int z, const float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const { if (!isEnabled ()) return; if (amount > 0.f) { if (m_extent.isWithin (worldX, worldZ)) { const float width_2 = m_width * 0.5f; const float originalHeight = generatorChunkData.heightMap->getData (x, z); FindData result; if (find (Vector2d (worldX, worldZ), width_2, result)) { const float distanceToCenter = fabsf (result.distanceToCenter); const float desiredHeight = result.height; if (WithinRangeInclusiveInclusive (0.f, distanceToCenter, width_2 * (1.f - getFeatherDistance ()))) { generatorChunkData.heightMap->setData (x, z, desiredHeight); //-- clear the flora generatorChunkData.floraStaticCollidableMap->setData (x, z, generatorChunkData.floraGroup->getDefaultFlora ()); generatorChunkData.floraStaticNonCollidableMap->setData (x, z, generatorChunkData.floraGroup->getDefaultFlora ()); generatorChunkData.floraDynamicNearMap->setData (x, z, generatorChunkData.radialGroup->getDefaultRadial ()); generatorChunkData.floraDynamicFarMap->setData (x, z, generatorChunkData.radialGroup->getDefaultRadial ()); } else { //-- height const float t = distanceToCenter / width_2; DEBUG_FATAL (t < 0.f || t > 1.f, ("t is out of range")); generatorChunkData.heightMap->setData (x, z, linearInterpolate (desiredHeight, originalHeight, t)); } if (WithinRangeInclusiveInclusive (0.f, distanceToCenter, width_2 * (1.f - getFeatherDistanceShader ()))) { //-- set the shader if (m_cachedFamilyId != m_familyId) { m_cachedFamilyId = m_familyId; m_cachedSgi = generatorChunkData.shaderGroup->chooseShader (m_familyId); } ShaderGroup::Info sgi = m_cachedSgi; sgi.setChildChoice (generatorChunkData.m_legacyRandomGenerator->randomReal (0.0f, 1.0f)); generatorChunkData.shaderMap->setData (x, z, sgi); } } } } }
void Transition3Dto2D::render(QCAR::Matrix44F projectionMatrix, QCAR::Matrix34F targetPose, GLuint texture1) { float t = stepTransition(); QCAR::Matrix44F modelViewProjectionTracked; QCAR::Matrix44F modelViewProjectionCurrent; QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix( targetPose); QCAR::Matrix44F finalPositionMatrix = getFinalPositionMatrix(); SampleUtils::scalePoseMatrix(430.f * scaleFactor, 430.f * scaleFactor, 1.0f, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjectionTracked.data[0]); float elapsedTransformationCurrent = 0.8f + 0.2f * t; elapsedTransformationCurrent = deccelerate(elapsedTransformationCurrent); linearInterpolate(&modelViewProjectionTracked, &finalPositionMatrix, &modelViewProjectionCurrent, elapsedTransformationCurrent); glUseProgram(shaderProgramID); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeVertices[0]); glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeNormals[0]); glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &planeTexcoords[0]); glEnableVertexAttribArray(vertexHandle); glEnableVertexAttribArray(normalHandle); glEnableVertexAttribArray(textureCoordHandle); glEnable (GL_BLEND); // Drawing Textured Plane glActiveTexture (GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture1); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*) &modelViewProjectionCurrent.data[0]); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (const GLvoid*) &planeIndices[0]); glDisableVertexAttribArray(vertexHandle); glDisableVertexAttribArray(normalHandle); glDisableVertexAttribArray(textureCoordHandle); glDisable(GL_BLEND); SampleUtils::checkGlError("Transition3Dto2D::render"); }
void MonoDelay::tick( sample_t* sample ) { m_buffer[m_index] = *sample; int readIndex = m_index - ( int )m_length - 1; if(readIndex < 0) { readIndex += m_maxLength; } float fract = 1.0f - fraction( m_length ); if(readIndex != m_maxLength-1 ) { *sample = linearInterpolate(m_buffer[readIndex] , m_buffer[readIndex+1], fract ); } else { *sample = linearInterpolate(m_buffer[readIndex] , m_buffer[0], fract ); } m_buffer[m_index] += *sample * m_feedback; m_index = ( m_index +1 ) % m_maxLength; }
void StereoDelay::tick( sampleFrame frame ) { m_buffer[m_index][0] = frame[0]; m_buffer[m_index][1] = frame[1]; int readIndex = m_index - ( int )m_length - 1; if( readIndex < 0 ) { readIndex += m_maxLength; } float fract = 1.0f - fraction( m_length ); frame[0] = linearInterpolate( m_buffer[readIndex][0] , m_buffer[( readIndex+1) % m_maxLength][0], fract ); frame[1] = linearInterpolate( m_buffer[readIndex][1] , m_buffer[( readIndex+1) % m_maxLength][1], fract ); m_buffer[m_index][0] += frame[0] * m_feedback; m_buffer[m_index][1] += frame[1] * m_feedback; m_index = ( m_index + 1) % m_maxLength; }
Color ColorPalette::getColorOn1Scale(double val) { if(isUsingMaxIterMethod()){ std::cerr << "Error getColorOn1Scale called when method is iterMax!\n"; return Color(0,0,0); } if(val > 1 || val < 0){ std::cerr << "Error in getColorOn1Scale: value: " << val << " not on [0,1]!\n"; Color c; c.b = c.g = c.r = 0; return c; } if(type == "discrete"){ unsigned int index = (float)(val * (colorCount()-1)+0.5f); // on [0, colorCount()-1] if(index < 0 || index >= C.size()){ std::cerr << "Error in getColorOn1Scale: value: " << val << " gave color out of range!\n"; std::cerr << " There are " << colorCount() << " colors in palette.\n"; Color c; c.b = c.g = c.r = 0; return c; } return C[index]; }else{ // find 2 closest colors, then interpolate // get segement # (there are colorCount()-1 segements) unsigned int segNum = (float)(val * (colorCount()-2)+0.5f); // on [0, colorCount()-2] unsigned int indexLow = segNum; unsigned int indexHigh = segNum + 1; double posAtHigh = indexHigh / (colorCount() - 1); // now interpolate Color c; c.r = linearInterpolate(C[indexHigh].r, C[indexLow].r, posAtHigh - val); c.g = linearInterpolate(C[indexHigh].g, C[indexLow].g, posAtHigh - val); c.b = linearInterpolate(C[indexHigh].b, C[indexLow].b, posAtHigh - val); return c; } }
float FractionalDelayBuffer::getSample(float sampleIndex) { float localIndex = (float)index - sampleIndex; if (localIndex >= bufferSize) { localIndex -= bufferSize; } if (localIndex < 0) { localIndex += bufferSize; } return linearInterpolate(buffer, bufferSize, localIndex); }
//--------------------------------------------------------------------------- surfaceScalarFieldHolder compressibleCreatePhi( const TimeHolder& runTime, const fvMeshHolder& mesh, const volVectorFieldHolder& U, const volScalarFieldHolder& rho ) { Info<< "Reading/calculating face flux field phi\n" << endl; return surfaceScalarFieldHolder( IOobjectHolder( "phi", runTime->timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ), linearInterpolate( rho * U ) & surfaceVectorFieldHolder( mesh->Sf(), &mesh ) ); }
Foam::interpolationCellPointFace<Type>::interpolationCellPointFace ( const GeometricField<Type, fvPatchField, volMesh>& psi ) : interpolation<Type>(psi), psip_ ( volPointInterpolation::New(psi.mesh()).interpolate ( psi, "volPointInterpolate(" + psi.name() + ')', true // use cache ) ), psis_(linearInterpolate(psi)) {}
Error JitterMoveEvent::update(F32 prevUpdateTime, F32 crntTime) { SceneNode* node = getSceneNode(); ANKI_ASSERT(node); MoveComponent& move = node->getComponent<MoveComponent>(); Transform trf = move.getLocalTransform(); F32 factor = sin(getDelta(crntTime) * PI); trf.getOrigin() = linearInterpolate(m_originalPos, m_newPos, factor); move.setLocalTransform(trf); return ErrorCode::NONE; }
//============================================================================== void Animation::interpolate( U channelIndex, F32 time, Vec3& pos, Quat& rot, F32& scale) const { // Audjust time if(m_repeat && time > m_startTime + m_duration) { time = mod(time - m_startTime, m_duration) + m_startTime; } ANKI_ASSERT(time >= m_startTime && time <= m_startTime + m_duration); ANKI_ASSERT(channelIndex < m_channels.getSize()); const AnimationChannel& channel = m_channels[channelIndex]; // Position if(channel.m_positions.getSize() > 1) { auto next = channel.m_positions.begin(); do { } while((next->m_time < time) && (++next != channel.m_positions.end())); ANKI_ASSERT(next != channel.m_positions.end()); auto prev = next - 1; F32 u = (time - prev->m_time) / (next->m_time - prev->m_time); pos = linearInterpolate(prev->m_value, next->m_value, u); } // Rotation if(channel.m_rotations.getSize() > 1) { auto next = channel.m_rotations.begin(); do { } while((next->m_time < time) && (++next != channel.m_rotations.end())); ANKI_ASSERT(next != channel.m_rotations.end()); auto prev = next - 1; F32 u = (time - prev->m_time) / (next->m_time - prev->m_time); rot = prev->m_value.slerp(next->m_value, u); } }
bool Contour::findStartTrianlge( double z, int& t0, int& e0, DT_Point& p, bool useBoundary ) { bool ret = false; for( int i = 0; i < ( int )taa.size(); i++ ) { TriangleAttrib* pTriangle = taa[i]; if( pTriangle->used ) continue; int n = findEdgeCanUse( i, z, useBoundary ); if( n != -1 ) { t0 = i; e0 = pTriangle->getEdge( n ); linearInterpolate( z, e0, p ); ret = true; break; } } return ret; }
sample_t bSynth::nextStringSample() { float sample_step = static_cast<float>( sample_length / ( sample_rate / nph->frequency() ) ); // check overflow while (sample_realindex >= sample_length) { sample_realindex -= sample_length; } sample_t sample; if (interpolation) { // find position in shape int a = static_cast<int>(sample_realindex); int b; if (a < (sample_length-1)) { b = static_cast<int>(sample_realindex+1); } else { b = 0; } // Nachkommaanteil const float frac = fraction( sample_realindex ); sample = linearInterpolate( sample_shape[a], sample_shape[b], frac ); } else { // No interpolation sample_index = static_cast<int>(sample_realindex); sample = sample_shape[sample_index]; } // progress in shape sample_realindex += sample_step; return sample; }
double AnimationGraph::valueAt( double time ) { int i; for ( i = keys.count() - 1; i > -1; --i ) { if ( keys[i].x <= time ) { AnimationKey k1 = keys[i]; if ( i == keys.count() - 1 ) return k1.y; AnimationKey k2 = keys[i+1]; switch ( k1.keyType ) { case AnimationKey::LINEAR: return linearInterpolate( k1.y, k2.y, ( time - k1.x ) / ( k2.x - k1.x ) ); case AnimationKey::CURVE: return cosineInterpolate( k1.y, k2.y, ( time - k1.x ) / ( k2.x - k1.x ) ); default: return k1.y; } } } return keys[0].y; }
/* Procedural texture function */ int ptex_fun(float u, float v, GzColor color) { //Complex cC(-0.1011, 0.9563), cX(u, v); //Complex cC(-0.123, 0.745), cX(2*(u-0.5), 2*(v-0.5)); Complex cC(-0.72375, 0.26805), cX(2*(u-0.5), 2*(v-0.5)); int N = 10; float len; for (int i = 0; i < N; i++) { Complex cTemp1 = (cX * cX); Complex cTemp2 = (cTemp1 + cC); len = cTemp2.length(); cX = cTemp2; if ((len < lowerLim) || (len > upperLim)) break; //cX = cTemp2; } len = cX.length(); linearInterpolate(len, color); return GZ_SUCCESS; }
bool Foam::rawTopoChangerFvMesh::update() { // Do mesh changes (use inflation - put new points in topoChangeMap) Info<< "rawTopoChangerFvMesh : Checking for topology changes..." << endl; // Mesh not moved/changed yet moving(false); topoChanging(false); // Do any topology changes. Sets topoChanging (through polyTopoChange) autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true); bool hasChanged = topoChangeMap.valid(); if (hasChanged) { Info<< "rawTopoChangerFvMesh : Done topology changes..." << endl; // Temporary: fix fields on patch faces created out of nothing // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Two situations: // - internal faces inflated out of nothing // - patch faces created out of previously internal faces // Is face mapped in any way? PackedBoolList mappedFace(nFaces()); const label nOldInternal = topoChangeMap().oldPatchStarts()[0]; const labelList& faceMap = topoChangeMap().faceMap(); for (label facei = 0; facei < nInternalFaces(); facei++) { if (faceMap[facei] >= 0) { mappedFace[facei] = 1; } } for (label facei = nInternalFaces(); facei < nFaces(); facei++) { if (faceMap[facei] >= 0 && faceMap[facei] >= nOldInternal) { mappedFace[facei] = 1; } } const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap(); forAll(fromFaces, i) { mappedFace[fromFaces[i].index()] = 1; } const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap(); forAll(fromEdges, i) { mappedFace[fromEdges[i].index()] = 1; } const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap(); forAll(fromPts, i) { mappedFace[fromPts[i].index()] = 1; } // Set unmapped faces to zero Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values." << endl; zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace); zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace); // Special handling for phi: set unmapped faces to recreated phi Info<< "rawTopoChangerFvMesh :" << " recreating phi for unmapped boundary values." << endl; const volVectorField& U = lookupObject<volVectorField>("U"); surfaceScalarField& phi = const_cast<surfaceScalarField&> ( lookupObject<surfaceScalarField>("phi") ); setUnmappedValues ( phi, mappedFace, (linearInterpolate(U) & Sf())() ); if (topoChangeMap().hasMotionPoints()) { pointField newPoints = topoChangeMap().preMotionPoints(); // Give the meshModifiers opportunity to modify points Info<< "rawTopoChangerFvMesh :" << " calling modifyMotionPoints." << endl; topoChanger_.modifyMotionPoints(newPoints); // Actually move points Info<< "rawTopoChangerFvMesh :" << " calling movePoints." << endl; movePoints(newPoints); } } else { //Pout<< "rawTopoChangerFvMesh :" // << " no topology changes..." << endl; } return hasChanged;
int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" Info << "Reading T_init" << endl; volScalarField T_init ( IOobject("T_init", runTime.constant(), mesh, IOobject::MUST_READ), mesh ); Info << "Reading P_init" << endl; volScalarField P_init ( IOobject("P_init", runTime.constant(), mesh, IOobject::MUST_READ), mesh ); Info << "Reading rt_init" << endl; volScalarField rt_init ( IOobject("rt_init", runTime.constant(), mesh, IOobject::MUST_READ), mesh ); Info << "Reading r_init" << endl; volScalarField r_init ( IOobject("r_init", runTime.constant(), mesh, IOobject::MUST_READ), mesh ); Info << "Reading or creating tracer field rhof_init" << endl; surfaceScalarField rhof_init ( IOobject("rhof_init", runTime.constant(), mesh, IOobject::READ_IF_PRESENT), linearInterpolate(rt_init) ); Info << "Creating T" << endl; volScalarField T ( IOobject("T", runTime.timeName(), mesh, IOobject::NO_READ), T_init ); Info << "Creating P" << endl; volScalarField P ( IOobject("P", runTime.timeName(), mesh, IOobject::NO_READ), P_init ); Info << "Creating rt" << endl; volScalarField rt ( IOobject("rt", runTime.timeName(), mesh, IOobject::NO_READ), rt_init ); Info << "Creating rl" << endl; volScalarField rl ( IOobject("rl", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rv" << endl; volScalarField rv ( IOobject("rv", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rl_diag" << endl; volScalarField rl_diag ( IOobject("rl_diag", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rv_diag" << endl; volScalarField rv_diag ( IOobject("rv_diag", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rl_analytic" << endl; volScalarField rl_analytic ( IOobject("rl_analytic", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rv_analytic" << endl; volScalarField rv_analytic ( IOobject("rv_analytic", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rt_analytic" << endl; volScalarField rt_analytic ( IOobject("rt_analytic", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating S" << endl; volScalarField S ( IOobject("S", runTime.timeName(), mesh, IOobject::NO_READ), r_init ); Info << "Creating rhof" << endl; surfaceScalarField rhof ( IOobject("rhof", runTime.timeName(), mesh, IOobject::NO_READ), rhof_init ); IOdictionary rtDict ( IOobject ( "totalMoistureDict", mesh.time().system(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ); IOdictionary rlDict ( IOobject ( "liquidWaterDict", mesh.time().system(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ); IOdictionary rvDict ( IOobject ( "waterVapourDict", mesh.time().system(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ); IOdictionary tempDict ( IOobject ( "tempDict", mesh.time().system(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ); IOdictionary PDict ( IOobject ( "pressureDict", mesh.time().system(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ); const noAdvection velocityField; autoPtr<tracerField> rtVal(tracerField::New(rtDict, velocityField)); autoPtr<tracerField> rlVal(tracerField::New(rlDict, velocityField)); autoPtr<tracerField> rvVal(tracerField::New(rvDict, velocityField)); autoPtr<tracerField> tempVal(tracerField::New(tempDict, velocityField)); autoPtr<tracerField> PVal(tracerField::New(PDict, velocityField)); Info << "writing rt for time " << runTime.timeName() << endl; rtVal->applyTo(rt); rt.write(); Info << "writing rl for time " << runTime.timeName() << endl; rlVal->applyTo(rl); rl.write(); Info << "writing rv for time " << runTime.timeName() << endl; rvVal->applyTo(rv); rv.write(); Info << "writing rl_diag for time " << runTime.timeName() << endl; rlVal->applyTo(rl_diag); rl_diag.write(); Info << "writing rv_diag for time " << runTime.timeName() << endl; rvVal->applyTo(rv_diag); rv_diag.write(); Info << "writing rl_analytic for time " << runTime.timeName() << endl; rlVal->applyTo(rl_analytic); rl_analytic.write(); Info << "writing rv_analytic for time " << runTime.timeName() << endl; rvVal->applyTo(rv_analytic); rv_analytic.write(); Info << "writing rt_analytic for time " << runTime.timeName() << endl; rtVal->applyTo(rt_analytic); rt_analytic.write(); Info << "writing S for time " << runTime.timeName() << endl; S.write(); Info << "writing qf for time " << runTime.timeName() << endl; rtVal->applyTo(rhof); rhof.write(); Info << "writing T" << endl; tempVal->applyTo(T); T.write(); Info << "writing P" << endl; PVal->applyTo(P); P.write(); return EXIT_SUCCESS; }