示例#1
0
//----------------------------------------------------------------------------
int SimplePendulum::Main (int, char**)
{
	msImage = new0 ImageRGB82D(SIZE, SIZE);

	SolveMethod(ExplicitEuler, "Data/explicit.im", "Data/explicit.txt");
	SolveMethod(ImplicitEuler, "Data/implicit.im", "Data/implicit.txt");
	SolveMethod(RungeKutta, "Data/runge.im", "Data/runge.txt");
	SolveMethod(LeapFrog, "Data/leapfrog.im", "Data/leapfrog.txt");
	Stiff1();
	Stiff2True();
	Stiff2Approximate();

	delete0(msImage);
	return 0;
}
示例#2
0
//----------------------------------------------------------------------------
RayTrace::RayTrace (ImageUChar3D* image, float gamma)
    :
    mGamma(gamma)
{
    // Get the maximum bound.
    int maxBound = image->GetBound(0);
    if (image->GetBound(1) > maxBound)
    {
        maxBound = image->GetBound(1);
    }
    if (image->GetBound(2) > maxBound)
    {
        maxBound = image->GetBound(2);
    }

    // Construct density in range [0,1/maxBound].  The accumulator values
    // must not exceed 1.
    mDensity = new0 ImageFloat3D(image->GetBound(0), image->GetBound(1),
        image->GetBound(2));
    unsigned char minValue = (*image)[0], maxValue = minValue;
    int i;
    for (i = 1; i < image->GetQuantity(); ++i)
    {
        if ((*image)[i] < minValue)
        {
            minValue = (*image)[i];
        }
        else if ((*image)[i] > maxValue)
        {
            maxValue = (*image)[i];
        }
    }
    float fMinValue = (float)minValue;
    float fMaxValue = (float)maxValue;
    float invRange = 1.0f/((fMaxValue - fMinValue)*maxBound);
    for (i = 1; i < image->GetQuantity(); ++i)
    {
        (*mDensity)[i] = ((*image)[i]- fMinValue)*invRange;
    }

    // Center point of 3D image.
    mXCenter = (float)((mDensity->GetBound(0) - 1)/2);
    mYCenter = (float)((mDensity->GetBound(1) - 1)/2);
    mZCenter = (float)((mDensity->GetBound(2) - 1)/2);

    // Determine image bounds and allocate images.
    mBound = (int)Mathf::Ceil(2.0f*maxBound);
    if (mBound % 2)
    {
        mBound++;
    }
    mBoundM1 = mBound - 1;
    mHBound = mBound/2;
    mAccum = new0 ImageFloat2D(mBound, mBound);
    mRender = new0 ImageRGB82D(mBound, mBound);

    // Initialize eyepoint frame field.
    for (int row = 0; row < 3; row++)
    {
        for (int col = 0; col < 3; col++)
        {
            mFrame[row][col] = (row == col ? 1.0f : 0.0f);
        }
    }
}