Beispiel #1
0
void Texture::setSubImage1D( GLsizei width, const GLvoid* data, GLint xoffset )
{
    KVS_ASSERT( m_target == GL_TEXTURE_1D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    KVS_GL_CALL( glTexSubImage1D( m_target, level, xoffset, width, m_external_format, m_external_type, data ) );
}
Beispiel #2
0
void Texture::setSubImageRectangle( GLsizei width, GLsizei height, const GLvoid* data, GLint xoffset, GLint yoffset )
{
    KVS_ASSERT( m_target == GL_TEXTURE_RECTANGLE_ARB );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    KVS_GL_CALL( glTexSubImage2D( m_target, level, xoffset, yoffset, width, height, m_external_format, m_external_type, data ) );
}
Beispiel #3
0
void Texture::copySubImage3D( GLint x, GLint y, GLsizei width, GLsizei height, GLint xoffset, GLint yoffset, GLint zoffset )
{
    KVS_ASSERT( m_target == GL_TEXTURE_3D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    KVS_GL_CALL( glCopyTexSubImage3D( m_target, level, xoffset, yoffset, zoffset, x, y, width, height ) );
}
Beispiel #4
0
void Texture::setImage1D( GLsizei width, const GLvoid* data )
{
    KVS_ASSERT( m_target == GL_TEXTURE_1D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    const GLint border = 0; // border width (0 or 1)
    KVS_GL_CALL( glTexImage1D( m_target, level, m_internal_format, width, border, m_external_format, m_external_type, data ) );
}
Beispiel #5
0
void Texture::copyImage2D( GLint x, GLint y, GLsizei width, GLsizei height )
{
    KVS_ASSERT( m_target == GL_TEXTURE_2D );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    const GLint border = 0; // border width (0 or 1)
    KVS_GL_CALL( glCopyTexImage2D( m_target, level, m_internal_format, x, y, width, height, border ) );
}
Beispiel #6
0
void Texture::setImageRectangle( GLsizei width, GLsizei height, const GLvoid* data )
{
    KVS_ASSERT( m_target == GL_TEXTURE_RECTANGLE_ARB );
    KVS_ASSERT( this->isBound() );

    const GLint level = 0; // level-of-detail number
    const GLint border = 0; // border width (0 or 1)
    KVS_GL_CALL( glTexImage2D( m_target, level, m_internal_format, width, height, border, m_external_format, m_external_type, data ) );
}
Beispiel #7
0
RGBColor& RGBColor::operator = ( const kvs::Vec3& rgb )
{
    KVS_ASSERT( 0.0f <= rgb.x() && rgb.x() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgb.y() && rgb.y() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgb.z() && rgb.z() <= 1.0f );

    m_red = kvs::Math::Round( rgb.x() * 255.0f );
    m_green = kvs::Math::Round( rgb.y() * 255.0f );
    m_blue = kvs::Math::Round( rgb.z() * 255.0f );
    return *this;
}
Beispiel #8
0
const kvs::Vector<T>& LUSolver<T>::solve( const kvs::Matrix<T>& A, const kvs::Vector<T>& b )
{
    KVS_ASSERT( A.rowSize() == A.columnSize() );
    KVS_ASSERT( A.columnSize() == b.size() );

    // LU decomposition.
    m_decomposer.setMatrix( A );
    m_decomposer.decompose();

    return( this->solve( b ) );
}
Beispiel #9
0
RGBAColor& RGBAColor::operator = ( const kvs::Vec4& rgba )
{
    KVS_ASSERT( 0.0f <= rgba.x() && rgba.x() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgba.y() && rgba.y() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgba.z() && rgba.z() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgba.w() && rgba.w() <= 1.0f );

    m_red = kvs::Math::Round( rgba.x() * 255.0f );
    m_green = kvs::Math::Round( rgba.y() * 255.0f );
    m_blue = kvs::Math::Round( rgba.z() * 255.0f );
    m_opacity = rgba.w();
    return *this;
}
Beispiel #10
0
kvs::RGBAColor& RGBAColor::operator = ( const kvs::Vec4& rgba )
{
    KVS_ASSERT( 0.0f <= rgba.x() && rgba.x() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgba.y() && rgba.y() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgba.z() && rgba.z() <= 1.0f );
    KVS_ASSERT( 0.0f <= rgba.w() && rgba.w() <= 1.0f );

    const kvs::UInt8 r = kvs::Math::Round( rgba.x() * 255.0f );
    const kvs::UInt8 g = kvs::Math::Round( rgba.y() * 255.0f );
    const kvs::UInt8 b = kvs::Math::Round( rgba.z() * 255.0f );
    kvs::RGBColor::set( r, g, b );
    m_a = rgba.w();
    return *this;
}
Beispiel #11
0
kvs::Mat3 PrismCell::localGradient()
{
    const kvs::Real32 p = m_local.x();
    const kvs::Real32 q = m_local.y();
    const kvs::Real32 r = m_local.z();
    KVS_ASSERT( 0.0f <= p && p <= 1.0f );
    KVS_ASSERT( 0.0f <= q && q <= 1.0f );
    KVS_ASSERT( 0.0f <= r && r <= 1.0f );
    KVS_ASSERT( p + q <= 1.0f );

    const kvs::Vec3 v02 = ::Mix( this->value(0), this->value(2), q );
    const kvs::Vec3 v35 = ::Mix( this->value(3), this->value(5), q );
    const kvs::Vec3 v12 = ::Mix( this->value(1), this->value(2), q );
    const kvs::Vec3 v45 = ::Mix( this->value(4), this->value(5), q );
    const kvs::Vec3 x0 = ::Mix( v02, v35, r );
    const kvs::Vec3 x1 = ::Mix( v12, v45, r );

    const kvs::Vec3 v01 = ::Mix( this->value(0), this->value(1), p );
    const kvs::Vec3 v34 = ::Mix( this->value(3), this->value(4), p );
    const kvs::Vec3 v21 = ::Mix( this->value(2), this->value(1), p );
    const kvs::Vec3 v54 = ::Mix( this->value(5), this->value(4), p );
    const kvs::Vec3 y0 = ::Mix( v01, v34, r );
    const kvs::Vec3 y1 = ::Mix( v21, v54, r );

    const kvs::Real32 ratio = kvs::Math::IsZero( 1 - q ) ? 0.0f : p / ( 1 - q );
    const kvs::Vec3 z0 = ::Mix( v02, v12, ratio );
    const kvs::Vec3 z1 = ::Mix( v35, v45, ratio );

    const kvs::Real32 dx = 1 - q;
    const kvs::Real32 dy = 1 - p;
    const kvs::Real32 dz = 1;

    const kvs::Real32 dudx = ( x1.x() - x0.x() ) / dx;
    const kvs::Real32 dudy = ( y1.x() - y0.x() ) / dy;
    const kvs::Real32 dudz = ( z1.x() - z0.x() ) / dz;

    const kvs::Real32 dvdx = ( x1.y() - x0.y() ) / dx;
    const kvs::Real32 dvdy = ( y1.y() - y0.y() ) / dy;
    const kvs::Real32 dvdz = ( z1.y() - z0.y() ) / dz;

    const kvs::Real32 dwdx = ( x1.z() - x0.z() ) / dx;
    const kvs::Real32 dwdy = ( y1.z() - y0.z() ) / dy;
    const kvs::Real32 dwdz = ( z1.z() - z0.z() ) / dz;

    return kvs::Mat3(
        dudx, dvdx, dwdx,
        dudy, dvdy, dwdy,
        dudz, dvdz, dwdz );
}
Beispiel #12
0
/*===========================================================================*/
void ScreenBase::create()
{
    KVS_ASSERT( m_id == -1 );

    // Initialize display mode.
    QGLFormat f = QGLFormat::defaultFormat();
    f.setDoubleBuffer( displayFormat().doubleBuffer() );
    f.setRgba( displayFormat().colorBuffer() );
    f.setDepth( displayFormat().depthBuffer() );
    f.setAccum( displayFormat().accumulationBuffer() );
    f.setStencil( displayFormat().stencilBuffer() );
    f.setStereo( displayFormat().stereoBuffer() );
    f.setSampleBuffers( displayFormat().multisampleBuffer() );
    f.setAlpha( displayFormat().alphaChannel() );
    QGLFormat::setDefaultFormat( f );

    // Set screen geometry.
    QWidget::setGeometry( BaseClass::x(), BaseClass::y(), BaseClass::width(), BaseClass::height() );

    QGLWidget::makeCurrent();

    // Initialize GLEW.
    GLenum result = glewInit();
    if ( result != GLEW_OK )
    {
        const GLubyte* message = glewGetErrorString( result );
        kvsMessageError( "GLEW initialization failed: %s.", message );
    }

    // Create window.
    static int counter = 0;
    m_id = counter++;
}
Beispiel #13
0
void GridBase::bind( const kvs::Vec3& global )
{
    const int grid_index = this->findGrid( global );
    KVS_ASSERT( grid_index >= 0 );
    this->bind( grid_index );
    this->setLocalPoint( this->globalToLocal( global ) );
}
Beispiel #14
0
/*==========================================================================*/
void TetrahedralCell::updateDifferentialFunctions( const kvs::Vec3& local ) const
{
    KVS_ASSERT( this->containsLocalPoint( local ) );
    kvs::IgnoreUnusedVariable( local );

    const size_t nnodes = BaseClass::numberOfCellNodes();
    kvs::Real32* dN = BaseClass::differentialFunctions();
    kvs::Real32* dNdp = dN;
    kvs::Real32* dNdq = dN + nnodes;
    kvs::Real32* dNdr = dN + nnodes + nnodes;

    dNdp[0] =   1.0f;
    dNdp[1] =   0.0f;
    dNdp[2] =   0.0f;
    dNdp[3] =  -1.0f;

    dNdq[0] =   0.0f;
    dNdq[1] =   1.0f;
    dNdq[2] =   0.0f;
    dNdq[3] =  -1.0f;

    dNdr[0] =   0.0f;
    dNdr[1] =   0.0f;
    dNdr[2] =   1.0f;
    dNdr[3] =  -1.0f;
}
Beispiel #15
0
void* BufferObject::mapBuffer( const GLenum access_type )
{
    KVS_ASSERT( this->isBound() );
    void* result = 0;
    KVS_GL_CALL( result = glMapBuffer( m_target, access_type ) );
    return result;
}
Beispiel #16
0
/*===========================================================================*/
const kvs::Mat3 CellBase::gradientTensor() const
{
    KVS_ASSERT( m_veclen == 3 );

    // Calculate a gradient tensor in the local coordinate.
    const kvs::UInt32 nnodes = m_nnodes;
    const float* dNdp = m_differential_functions;
    const float* dNdq = m_differential_functions + nnodes;
    const float* dNdr = m_differential_functions + nnodes + nnodes;
    const kvs::Real32* Su = m_values;
    const kvs::Real32* Sv = Su + nnodes;
    const kvs::Real32* Sw = Sv + nnodes;

    const float dudp = this->interpolateValue( Su, dNdp, nnodes );
    const float dudq = this->interpolateValue( Su, dNdq, nnodes );
    const float dudr = this->interpolateValue( Su, dNdr, nnodes );
    const float dvdp = this->interpolateValue( Sv, dNdp, nnodes );
    const float dvdq = this->interpolateValue( Sv, dNdq, nnodes );
    const float dvdr = this->interpolateValue( Sv, dNdr, nnodes );
    const float dwdp = this->interpolateValue( Sw, dNdp, nnodes );
    const float dwdq = this->interpolateValue( Sw, dNdq, nnodes );
    const float dwdr = this->interpolateValue( Sw, dNdr, nnodes );
    const kvs::Mat3 t( dudp, dvdp, dwdp, dudq, dvdq, dwdq, dudr, dvdr, dwdr );

    // Calculate a gradient tensor in the global coordinate.
    const kvs::Mat3 J = this->JacobiMatrix();

    float determinant = 0.0f;
    const kvs::Mat3 T = 3.0f * J.inverted( &determinant ) * t;
    return kvs::Math::IsZero( determinant ) ? kvs::Mat3::Zero() : T;
}
Beispiel #17
0
BufferObject::GuardedBinder::~GuardedBinder()
{
    KVS_ASSERT( m_bo.isCreated() );
    if ( static_cast<GLuint>( m_id ) != m_bo.id() )
    {
        KVS_GL_CALL( glBindBuffer( m_bo.target(), m_id ) );
    }
}
Beispiel #18
0
BufferObject::GuardedBinder::GuardedBinder( const kvs::BufferObject& bo ):
    m_bo( bo ),
    m_id( 0 )
{
    KVS_ASSERT( bo.isCreated() );
    m_id = kvs::OpenGL::Integer( bo.targetBinding() );
    if ( bo.id() != static_cast<GLuint>( m_id ) ) { bo.bind(); }
}
Beispiel #19
0
Texture::GuardedBinder::~GuardedBinder()
{
    KVS_ASSERT( m_texture.isCreated() );
    if ( static_cast<GLuint>( m_id ) != m_texture.id() )
    {
        KVS_GL_CALL( glBindTexture( m_texture.target(), m_id ) );
    }
}
Beispiel #20
0
kvs::Real32 GridBase::scalar() const
{
    KVS_ASSERT( m_veclen == 1 );

    const kvs::Real32* N = m_interpolation_functions;
    const kvs::Real32* S = m_values;
    return this->interpolateValue( S, N );
}
Beispiel #21
0
bool GRIBData::read( FILE* fp )
{
    KVS_ASSERT( fp );

    if ( !this->parse( fp ) ) { return false; }
    if ( !this->load() ) { return false; }
    return true;
}
Beispiel #22
0
Texture::Binder::Binder( const Texture& texture, GLint unit ) :
    m_texture( texture ),
    m_unit( unit )
{
    KVS_ASSERT( texture.isCreated() );
    Texture::SelectActiveUnit( unit );
    texture.bind();
}
Beispiel #23
0
TextureBinder::TextureBinder( const Texture& texture, GLint unit ) :
    m_texture( texture ),
    m_unit( unit )
{
    KVS_ASSERT( texture.isCreated() );
    kvs::OpenGL::ActivateTextureUnit( unit );
    texture.bind();
}
Beispiel #24
0
FrameBufferObject::GuardedBinder::~GuardedBinder()
{
    KVS_ASSERT( m_fbo.isCreated() );
    if ( static_cast<GLuint>( m_id ) != m_fbo.id() )
    {
        KVS_GL_CALL( glBindFramebufferEXT( GL_FRAMEBUFFER, m_id ) );
    }
}
Beispiel #25
0
FrameBufferObject::GuardedBinder::GuardedBinder( const kvs::FrameBufferObject& fbo ):
    m_fbo( fbo ),
    m_id( 0 )
{
    KVS_ASSERT( fbo.isCreated() );
    m_id = kvs::OpenGL::Integer( GL_FRAMEBUFFER_BINDING );
    if ( fbo.id() != static_cast<GLuint>( m_id ) ) { fbo.bind(); }
}
Beispiel #26
0
void FrameBufferObject::attachColorRenderBuffer( const kvs::RenderBuffer& render_buffer, const size_t color_buffer ) const
{
    KVS_ASSERT( static_cast<GLint>( color_buffer ) < kvs::OpenGL::MaxColorAttachments() );
    GuardedBinder binder( *this );
    const GLuint id = render_buffer.id();
    const GLenum attachment = GL_COLOR_ATTACHMENT0 + color_buffer;
    KVS_GL_CALL( glFramebufferRenderbuffer( GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, id ) );
}
Beispiel #27
0
/*===========================================================================*/
const kvs::Real32 CellBase::scalar() const
{
    KVS_ASSERT( m_veclen == 1 );

    const size_t nnodes = m_nnodes;
    const kvs::Real32* N = m_interpolation_functions;
    const kvs::Real32* S = m_values;
    return this->interpolateValue( S, N, nnodes );
}
Beispiel #28
0
/*===========================================================================*/
void FrameBufferObject::attachColorTexture( const kvs::Texture3D& texture, const size_t color_buffer, const int mip_level, const int zoffset ) const
{
    KVS_ASSERT( static_cast<GLint>( color_buffer ) < kvs::OpenGL::MaxColorAttachments() );
    GuardedBinder binder( *this );
    const GLuint id = texture.id();
    const GLenum attachment = GL_COLOR_ATTACHMENT0 + color_buffer;
    const GLenum type = GL_TEXTURE_3D;
    KVS_GL_CALL( glFramebufferTexture3D( GL_FRAMEBUFFER, attachment, type, id, mip_level, zoffset ) );
}
Beispiel #29
0
const kvs::Vector<T>& SVSolver<T>::solve( const kvs::Matrix<T>& A, const kvs::Vector<T>& b )
{
    KVS_ASSERT( A.columnSize() == b.size() );

    // Singular value decomposition.
    m_decomposer.setMatrix( A );
    m_decomposer.decompose();

    return( this->solve( b ) );
}
Beispiel #30
0
Texture::GuardedBinder::GuardedBinder( const Texture& texture ):
    m_texture( texture ),
    m_id( kvs::OpenGL::Integer( texture.targetBinding() ) )
{
    KVS_ASSERT( texture.isCreated() );
    if ( texture.id() != static_cast<GLuint>( m_id ) )
    {
        texture.bind();
    }
}