Ejemplo n.º 1
0
 void apply( void )
 {
     const kvs::RendererBase* base = static_cast<kvs::glut::Screen*>(screen())->scene()->rendererManager()->renderer();
     kvs::RayCastingRenderer* renderer = (kvs::RayCastingRenderer*)base;
     renderer->setTransferFunction( transferFunction() );
     screen()->redraw();
 }
Ejemplo n.º 2
0
double Neuron::count(double* input) {
    static double result;
    result = this->_activationFunction(
                transferFunction(input)
        );
    return result;
}
Ejemplo n.º 3
0
bool transferValue(lua_State* toL, lua_State* fromL)
{
    bool result = false;
    int type = lua_type(fromL, -1);
    
    switch (type)
    {
    case LUA_TNIL:
        lua_pushnil(toL);
        result = true;
        break;
    case LUA_TNUMBER:
        lua_pushnumber(toL, lua_tonumber(fromL, -1));
        result = true;
        break;
    case LUA_TBOOLEAN:
        lua_pushboolean(toL, lua_toboolean(fromL, -1));
        result = true;
        break;
    case LUA_TSTRING:
    {
        size_t len;
        const char* str = lua_tolstring(fromL, -1, &len);
        lua_pushlstring(toL, str, len);
        result = true;
        break;
    }
    case LUA_TTABLE:
        result = transferTable(toL, fromL);
        break;
    case LUA_TFUNCTION:
        result = transferFunction(toL, fromL);
        break;
    case LUA_TUSERDATA:
    {
        Userdata* ud = getPrivateUserdata(fromL, -1);
        if (ud)
            result = ud->copyToState(toL);
        break;
    }
    case LUA_TTHREAD:
        // copying coroutines is not supported.
        break;
    case LUA_TLIGHTUSERDATA:
        lua_pushlightuserdata(toL, lua_touserdata(fromL, -1));
        result = true;
        break;
    default:
        break;
    }
    
    return result;
}
  void ProjectionFilterer_fftw<TProjection>::Initialize()
    {
    athabasca_assert(!this->m_ForwardPlan);
    athabasca_assert(!this->m_BackwardPlan);

    // Add one to next power of two in order to pad.
    this->m_FFTLength = bonelab::FFT_util::NextNumberWithFactors2And3(2*this->m_Dimensions[1]);
    // Buffer length is slightly longer due to FFTW storage scheme.
    unsigned int bufferLength = 2*(this->m_FFTLength/2 + 1);
    this->m_Buffer.construct(bufferLength);

    m_ForwardPlan = fftw_mt<TValue>::plan_dft_r2c_1d(
                 this->m_FFTLength,
                 this->m_Buffer.ptr(),
                 reinterpret_cast<typename fftw_mt<TValue>::complex*>(this->m_Buffer.ptr()),
                 FFTW_MEASURE);
    m_BackwardPlan = fftw_mt<TValue>::plan_dft_c2r_1d(
                 this->m_FFTLength,
                 reinterpret_cast<typename fftw_mt<TValue>::complex*>(this->m_Buffer.ptr()),
                 this->m_Buffer.ptr(),
                 FFTW_MEASURE);

    this->m_RampFilter.construct(bufferLength);
    // Create another array that is just a reference to the same data,
    // but with length just FFTLength, instead of length Buffer.
    TFunction1D rampFilterRef;
    rampFilterRef.construct_reference(this->m_RampFilter.ptr(), this->m_FFTLength);

    // Create Ramp Filter by transforming real space version
    RampFilterRealSpace<TFunction1D> rampFilterGenerator;
    rampFilterGenerator.SetLength(this->m_FFTLength);
    rampFilterGenerator.SetSpacing(this->m_PixelSpacing);
    // Calculate the factor.  This consists of:
    // 1.  In the FFTW library, the inverse FFT should be
    //     multiplied by the 1/FFTLength.
    double factor = this->m_Weight/(this->m_FFTLength);
    rampFilterGenerator.SetWeight(factor);
    rampFilterGenerator.ConstructRealSpaceFilter(rampFilterRef);

    // performance check
    athabasca_assert(size_t(m_RampFilter.ptr()) % 16 == 0);

    /* to the frequency domain */
    typename fftw_mt<TValue>::plan rampForwardPlan = fftw_mt<TValue>::plan_dft_r2c_1d(
                   this->m_FFTLength,
                   this->m_RampFilter.ptr(),
                   reinterpret_cast<typename fftw_mt<TValue>::complex*>(this->m_RampFilter.ptr()),
                   FFTW_ESTIMATE);
    fftw_mt<TValue>::execute(rampForwardPlan);
    fftw_mt<TValue>::destroy_plan(rampForwardPlan);

    if (this->m_SmoothingFilter)
      {
      // Note: We will construct transferFunction out to this->m_FFTLength,
      //       which is in fact more than we really need.  However, as the
      //       length also indicates the Nyquist frequency, this is necessary
      //       for correctness.
      TFunction1D transferFunction(this->m_FFTLength);
      this->m_SmoothingFilter->SetLength(this->m_FFTLength);
      this->m_SmoothingFilter->ConstructTransferFunction(transferFunction);
      // Multiply RampFilter by transferFunction 
      for (unsigned int i=0, j=0; j<bufferLength; ++i, j+=2)
        {
        // Note that these are only the real components.
        // Just assume that m_RampFilter has no imaginary part - actually even
        // if it does, it is ignored below.
        this->m_RampFilter[j] *= transferFunction[i];
        }
      }

    }
  void ProjectionFilterer_vDSP<TProjection>::Initialize()
    {
    athabasca_assert(!this->m_FFTsetup);
    athabasca_assert(!this->m_Scratch);
    athabasca_assert(!this->m_RampFilter);
    athabasca_assert(this->m_Weight > 0);

    // Add one to next power of two in order to pad.
    this->m_PowerOfTwo = bonelab::FFT_util::NextPowerOfTwo(this->m_Dimensions[1]) + 1;

// #define EXTRA_FFT_PADDING
#ifdef EXTRA_FFT_PADDING
    std::cout << "**** WARNING: Adding extra FFT padding!\n";
    this->m_PowerOfTwo++;
#endif

    this->m_FFTLength = 1 << this->m_PowerOfTwo;

    this->m_FFTsetup = bonelab::vDSP<TValue>::create_fftsetup(this->m_PowerOfTwo, 0);
    this->m_Scratch = new TSplitComplex;
    this->m_Scratch->realp = (TValue*)malloc(this->m_FFTLength * sizeof(TValue));
    this->m_Scratch->imagp = this->m_Scratch->realp + this->m_FFTLength/2;
    this->m_RampFilter = new TSplitComplex;
    this->m_RampFilter->realp = (TValue*)malloc(this->m_FFTLength * sizeof(TValue));
    this->m_RampFilter->imagp = this->m_RampFilter->realp + this->m_FFTLength/2;

    // Create Ramp Filter by transforming real space version
    TFunction1D rampFilterRealSpace(this->m_FFTLength);
    RampFilterRealSpace<TFunction1D> rampFilterGenerator;
    rampFilterGenerator.SetLength(this->m_FFTLength);
    rampFilterGenerator.SetSpacing(this->m_PixelSpacing);
    // Calculate the factor.  This consists of:
    // 1.  In the vDSP library, the inverse FFT should be
    //     multiplied by the 1/(2*FFTLength).  Actually, experimentation
    //     seems to indicate that 1/(4*FFTLength) is required.  For the
    //     moment I am baffled by this, although I guess has something do
    //     to with multiplying in transformed space.
    double factor = this->m_Weight/(4*this->m_FFTLength);
    rampFilterGenerator.SetWeight(factor);
    rampFilterGenerator.ConstructRealSpaceFilter(rampFilterRealSpace);

    // performance check
    athabasca_assert(size_t(rampFilterRealSpace.ptr()) % 16 == 0);
    athabasca_assert(size_t(m_RampFilter->realp) % 16 == 0);
    bonelab::vDSP<TValue>::ctoz(
        reinterpret_cast<const TComplex*>(rampFilterRealSpace.ptr()),
        2,
        this->m_RampFilter,
        1,
        this->m_FFTLength/2);    
    /* to the frequency domain */
    bonelab::vDSP<TValue>::fft_zrip(
        this->m_FFTsetup,
        this->m_RampFilter,
        1,
        this->m_PowerOfTwo,
        FFT_FORWARD);

    if (this->m_SmoothingFilter)
      {
      // Note: We will construct transferFunction out to this->m_FFTLength,
      //       which is in fact more than we really need (for the storage
      //       scheme used for symmetric real data).  However, as the
      //       length also indicates the Nyquist frequency, this is necessary
      //       for correctness.
      TFunction1D transferFunction(this->m_FFTLength);
      this->m_SmoothingFilter->SetLength(this->m_FFTLength);
      this->m_SmoothingFilter->ConstructTransferFunction(transferFunction);
      // Multiply RampFilter by transferFunction, taking special care to deal with the
      // Nyquist component stored in imagp[0] in this storage scheme.
      TValue Nyquist_component = this->m_RampFilter->imagp[0] * transferFunction[this->m_FFTLength/2];
      bonelab::vDSP<TValue>::vmul(
          this->m_RampFilter->realp,
          1,
          transferFunction.ptr(),
          1,
          this->m_RampFilter->realp,
          1,
          this->m_FFTLength/2);
      this->m_RampFilter->imagp[0] = Nyquist_component;
      // Just assume that m_RampFilter has no imaginary part - actually even
      // if it does, it is ignored below.
      }

    }
Ejemplo n.º 6
0
Archivo: main.cpp Proyecto: koron21/kvs
 void apply( void )
 {        
     m_ref_volume_renderer->setTransferFunction( transferFunction() );
     m_ref_renderer->clearEnsembleBuffer();
     screen()->redraw();
 }