本文整理汇总了C++中cinderfx::Fluid2D::dbgCurl方法的典型用法代码示例。如果您正苦于以下问题:C++ Fluid2D::dbgCurl方法的具体用法?C++ Fluid2D::dbgCurl怎么用?C++ Fluid2D::dbgCurl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cinderfx::Fluid2D
的用法示例。
在下文中一共展示了Fluid2D::dbgCurl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toOcv
//.........这里部分代码省略.........
mPrvCvData = mCurCvData;
mCurCvData = cv::Mat( toOcv( Channel( mCurScaled ) ) );
if( mPrvCvData.data && mCurCvData.data ) {
int pyrLvels = 3;
int winSize = 3;
int iters = 5;
int poly_n = 7;
double poly_sigma = 1.5;
cv::calcOpticalFlowFarneback( mPrvCvData, mCurCvData, mFlow, 0.5, pyrLvels, 2*winSize + 1, iters, poly_n, poly_sigma, cv::OPTFLOW_FARNEBACK_GAUSSIAN );
if( mFlow.data ) {
if( mFlowVectors.empty() ) {
mFlowVectors.resize( mCurScaled.getWidth()*mCurScaled.getHeight() );
}
//memset( &mFlowVectors[0], 0, mCurScaled.getWidth()*mCurScaled.getHeight()*sizeof( Vec2f ) );
mNumActiveFlowVectors = 0;
for( int j = 0; j < mCurScaled.getHeight(); ++j ) {
for( int i = 0; i < mCurScaled.getWidth(); ++i ) {
const float* fptr = reinterpret_cast<float*>(mFlow.data + j*mFlow.step + i*sizeof(float)*2);
//
Vec2f v = Vec2f( fptr[0], fptr[1] );
if( v.lengthSquared() >= mVelThreshold ) {
if( mNumActiveFlowVectors >= (int)mFlowVectors.size() ) {
mFlowVectors.push_back( std::make_pair( Vec2i( i, j ), v ) );
}
else {
mFlowVectors[mNumActiveFlowVectors] = std::make_pair( Vec2i( i, j ), v );
}
++mNumActiveFlowVectors;
}
}
}
}
}
}
// Update texture
mTexCam.update( mFlipped );
// Save previous frame
if( ! mPrvScaled ) {
mPrvScaled = Surface8u( mCurScaled.getWidth(), mCurScaled.getHeight(), mCurScaled.hasAlpha(), mCurScaled.getChannelOrder() );
}
memcpy( mPrvScaled.getData(), mCurScaled.getData(), mCurScaled.getHeight()*mCurScaled.getRowBytes() );
}
// Update fluid
float dx = (mFluid2DResX - 2)/(float)(640/kFlowScale);
float dy = (mFluid2DResY - 2)/(float)(480/kFlowScale);
for( int i = 0; i < mNumActiveFlowVectors; ++i ) {
Vec2f P = mFlowVectors[i].first;
const Vec2f& v = mFlowVectors[i].second;
mFluid2D.splatDensity( P.x*dx + 1, P.y*dy + 1, mDenScale*v.lengthSquared() );
mFluid2D.splatVelocity( P.x*dx + 1, P.y*dy + 1, v*mVelScale );
}
mFluid2D.step();
// Update velocity
const Vec2f* srcVel0 = mFluid2D.dbgVel0().data();
const Vec2f* srcVel1 = mFluid2D.dbgVel1().data();
Colorf* dstVel0 = (Colorf*)mSurfVel0.getData();
Colorf* dstVel1 = (Colorf*)mSurfVel1.getData();
for( int j = 0; j < mFluid2DResY; ++j ) {
for( int i = 0; i < mFluid2DResX; ++i ) {
*dstVel0 = Colorf( srcVel0->x, srcVel0->y, 0.0f );
*dstVel1 = Colorf( srcVel1->x, srcVel1->y, 0.0f );
++srcVel0;
++srcVel1;
++dstVel0;
++dstVel1;
}
}
// Update Density
mChanDen0 = Channel32f( mFluid2DResX, mFluid2DResY, mFluid2DResX*sizeof(float), 1, mFluid2D.dbgDen0().data() );
mChanDen1 = Channel32f( mFluid2DResX, mFluid2DResY, mFluid2DResX*sizeof(float), 1, mFluid2D.dbgDen1().data() );
mTexDen0.update( mChanDen0 );
mTexDen1.update( mChanDen1 );
// Update velocity textures
mTexVel0.update( mSurfVel0 );
mTexVel1.update( mSurfVel1 );
// Update Divergence
mChanDiv = Channel32f( mFluid2DResX, mFluid2DResY, mFluid2DResX*sizeof(float), 1, mFluid2D.dbgDivergence().data() );
mTexDiv.update( mChanDiv );
// Update Divergence
mChanPrs = Channel32f( mFluid2DResX, mFluid2DResY, mFluid2DResX*sizeof(float), 1, mFluid2D.dbgPressure().data() );
mTexPrs.update( mChanPrs );
// Update Curl, Curl Length
mChanCurl = Channel32f( mFluid2DResX, mFluid2DResY, mFluid2DResX*sizeof(float), 1, mFluid2D.dbgCurl().data() );
mTexCurl.update( mChanCurl );
mChanCurlLen = Channel32f( mFluid2DResX, mFluid2DResY, mFluid2DResX*sizeof(float), 1, mFluid2D.dbgCurlLength().data() );
mTexCurlLen.update( mChanCurlLen );
}