示例#1
0
文件: FFT.cpp 项目: alexabate/GalSim
    // Fourier transform from (complex) k to x:
    // This version takes XTable reference as argument 
    void KTable::transform(XTable& xt) const 
    {
        check_array();

        // check proper dimensions for xt
        assert(_N==xt.getN());

        // We'll need a new k array because FFTW kills the k array in this
        // operation.  Also, to put x=0 in center of array, we need to flop
        // every other sign of k array, and need to scale.
        dbg<<"Before make t_array"<<std::endl;
        FFTW_Array<std::complex<double> > t_array(_N);
        dbg<<"After make t_array"<<std::endl;
        double fac = _dk * _dk / (4*M_PI*M_PI);
        long int ind=0;
        dbg<<"t_array.size = "<<t_array.size()<<std::endl;
        for (int iy=0; iy<_N; iy++) {
            dbg<<"ind = "<<ind<<std::endl;
            for (int ix=0; ix<=_N/2; ix++) {
                if ( (ix+iy)%2==0) t_array[ind]=fac * _array[ind];
                else t_array[ind] = -fac* _array[ind];
                ind++;
            }
        }
        dbg<<"After fill t_array"<<std::endl;

        fftw_plan plan = fftw_plan_dft_c2r_2d(
            _N, _N, t_array.get_fftw(), xt._array.get_fftw(), FFTW_ESTIMATE);
        dbg<<"After make plan"<<std::endl;
#ifdef FFT_DEBUG
        if (plan==NULL) throw FFTInvalid();
#endif

        // Run the transform:
        fftw_execute(plan);
        dbg<<"After exec plan"<<std::endl;
        fftw_destroy_plan(plan);
        dbg<<"After destroy plan"<<std::endl;

        xt._dx = 2*M_PI/(_N*_dk);
        dbg<<"Done transform"<<std::endl;
    }
CRhinoCommand::result CCommandTestAnimator::RunCommand( const CRhinoCommandContext& context )
{
    // Select objects to animate
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select objects to animate" );
    go.GetObjects( 1, 0 );
    if( go.CommandResult() != success )
        return go.CommandResult();

    // Select path curve
    CRhinoGetObject gc;
    gc.SetCommandPrompt( L"Select path curve" );
    gc.SetGeometryFilter( CRhinoGetObject::curve_object );
    gc.SetGeometryAttributeFilter( CRhinoGetObject::open_curve );
    gc.GetObjects( 1, 1 );
    if( gc.CommandResult() != success )
        return gc.CommandResult();

    const ON_Curve* crv = gc.Object(0).Curve();
    if( 0 == crv )
        return failure;

    // Create an array of normalized curve parameters
    ON_SimpleArray<double> t_array( m_max_steps );
    t_array.SetCount( m_max_steps );
    int i = 0;
    for( i = 0; i < m_max_steps; i++ )
    {
        double t = (double)i / ( (double)m_max_steps - 1 );
        t_array[i] = t;
    }

    // Get the real parameters along the curve
    if( !crv->GetNormalizedArcLengthPoints(m_max_steps, t_array.Array(), t_array.Array()) )
        return failure;

    // Create our dialog box with animatin slider...
    CTestAnimatorDlg dlg( CWnd::FromHandle(RhinoApp().MainWnd()) );
    dlg.m_max_steps = m_max_steps;
    dlg.m_start = crv->PointAtStart();

    // Get points along curve
    for( i = 0; i < m_max_steps; i++ )
    {
        ON_3dPoint pt = crv->PointAt( t_array[i] );
        dlg.m_points.Append( pt );
    }

    // Hide objects and add them to callback's object array
    for( i = 0; i < go.ObjectCount(); i++ )
    {
        CRhinoObjRef ref = go.Object(i);
        context.m_doc.HideObject( ref );
        dlg.m_conduit.m_objects.Append( ref.Object() );
    }

    // Do the dialog
    INT_PTR rc = dlg.DoModal();

    // If OK was pressed, transform the objects.
    // Otherwise, just unhide them.
    for( i = 0; i < go.ObjectCount(); i++ )
    {
        CRhinoObjRef ref = go.Object(i);
        context.m_doc.ShowObject( ref );
        if( rc == IDOK )
        {
            ON_Xform xform = dlg.m_conduit.m_xform;
            context.m_doc.TransformObject( ref, xform );
        }
    }

    context.m_doc.Redraw( CRhinoView::regenerate_display_hint );

    return CRhinoCommand::success;
}