コード例 #1
0
ファイル: SevenSegmentLED.cpp プロジェクト: njun-git/kvs
void ColonLED::create_coords( const kvs::Vector3f& center )
{
    m_coords.allocate( 3 * 8 );
    const float length = 2.0;
    const float width = 0.2;

    // Set const z coord.
    for ( size_t i = 2; i < 24; i += 3 ) m_coords[i] = center.z();

    for ( size_t i = 0; i < 2; i++ )
    {
        float is_minus = ( i == 0 ) ? 1.0f : - 1.0f;
        m_coords[ i * 12 +  0 ] = center.x() - width;
        m_coords[ i * 12 +  1 ] = center.y() + is_minus * length / 2 + width;

        m_coords[ i * 12 +  3 ] = center.x() + width;
        m_coords[ i * 12 +  4 ] = center.y() + is_minus * length / 2 + width;

        m_coords[ i * 12 +  6 ] = center.x() + width;
        m_coords[ i * 12 +  7 ] = center.y() + is_minus * length / 2 - width;

        m_coords[ i * 12 +  9 ] = center.x() - width;
        m_coords[ i * 12 + 10 ] = center.y() + is_minus * length / 2 - width;
    }
}
コード例 #2
0
ファイル: ExtractEdges.cpp プロジェクト: digirea/KVS
/*===========================================================================*/
void ExtractEdges::calculate_uniform_coords( const kvs::StructuredVolumeObject* volume )
{
    kvs::ValueArray<kvs::Real32> coords( 3 * volume->numberOfNodes() );
    kvs::Real32* coord = coords.data();

    const kvs::Vector3ui resolution( volume->resolution() );
    const kvs::Vector3f  volume_size( volume->maxObjectCoord() - volume->minObjectCoord() );
    const kvs::Vector3ui ngrids( resolution - kvs::Vector3ui( 1, 1, 1 ) );
    const kvs::Vector3f  grid_size(
        volume_size.x() / static_cast<float>( ngrids.x() ),
        volume_size.y() / static_cast<float>( ngrids.y() ),
        volume_size.z() / static_cast<float>( ngrids.z() ) );

    for ( size_t k = 0; k < resolution.z(); ++k )
    {
        const float z =
            grid_size.z() * static_cast<float>( k );
        for ( size_t j = 0; j < resolution.y(); ++j )
        {
            const float y =
                grid_size.y() * static_cast<float>( j );
            for ( size_t i = 0; i < resolution.x(); ++i )
            {
                const float x =
                    grid_size.x() * static_cast<float>( i );

                *( coord++ ) = x;
                *( coord++ ) = y;
                *( coord++ ) = z;
            }
        }
    }

    SuperClass::setCoords( coords );
}
コード例 #3
0
ファイル: DepthGenerator.cpp プロジェクト: njun-git/kvs
const kvs::Vector3f DepthGenerator::realPosition( const kvs::Vector3f& pos )
{
    if ( !m_is_created )
    {
        kvsMessageError( "DepthGenerator is not created yet." );
        return( pos );
    }

    XnPoint3D proj;
    XnPoint3D real;
    proj.X = pos.x();
    proj.Y = pos.y();
    proj.Z = pos.z();

    XnStatus status = m_generator.ConvertProjectiveToRealWorld( 1, &proj, &real );
    if ( status != XN_STATUS_OK )
    {
        kvsMessageError( "%s error: <%s>.",
            xnGetStatusName( status ),
            xnGetStatusString( status ) );
        return( pos );
    }

    return( kvs::Vector3f( real.X, real.Y, real.Z ) );
}
コード例 #4
0
ファイル: Ply.cpp プロジェクト: digirea/KVS
void Ply::calculate_normals()
{
    kvs::ValueArray<kvs::UInt32> counter( m_nverts );
    counter.fill( 0 );

    m_normals.allocate( m_nverts * 3 );
    const kvs::UInt32* pconnections = m_connections.data();
    const kvs::Real32* pcoords = m_coords.data();
    for ( size_t i = 0; i < m_nfaces; i++ )
    {
        // Calculate normal vector for each triangles.
        const kvs::UInt32 index0 = *(pconnections++);
        const kvs::UInt32 index1 = *(pconnections++);
        const kvs::UInt32 index2 = *(pconnections++);

        const kvs::Vector3f v0( pcoords + 3 * index0 );
        const kvs::Vector3f v1( pcoords + 3 * index1 );
        const kvs::Vector3f v2( pcoords + 3 * index2 );
        const kvs::Vector3f normal = ( ( v1 - v0 ).cross( v2 - v1 ) ).normalized();

        // Sum of the normal vectors of the adjacent triangles for the vertex.
        m_normals[ 3 * index0 + 0 ] = normal.x();
        m_normals[ 3 * index0 + 1 ] = normal.y();
        m_normals[ 3 * index0 + 2 ] = normal.z();
        counter[ index0 ] += 1;

        m_normals[ 3 * index1 + 0 ] = normal.x();
        m_normals[ 3 * index1 + 1 ] = normal.y();
        m_normals[ 3 * index1 + 2 ] = normal.z();
        counter[ index1 ] += 1;

        m_normals[ 3 * index2 + 0 ] = normal.x();
        m_normals[ 3 * index2 + 1 ] = normal.y();
        m_normals[ 3 * index2 + 2 ] = normal.z();
        counter[ index2 ] += 1;
    }

    for ( size_t i = 0; i < m_nverts; i++ )
    {
        if ( counter[i] == 0 ) continue;
        m_normals[ 3 * i + 0 ] /= static_cast<kvs::Real32>( counter[i] );
        m_normals[ 3 * i + 1 ] /= static_cast<kvs::Real32>( counter[i] );
        m_normals[ 3 * i + 2 ] /= static_cast<kvs::Real32>( counter[i] );
    }
}
コード例 #5
0
ファイル: ScreenController.cpp プロジェクト: njun-git/kvs
const kvs::Vector3f ScreenController::vertex_of_joint(
    const unsigned int index,
    const kvs::ni::Skeleton::SkeletonJoint& joint,
    kvs::ni::DepthGenerator& depth,
    kvs::ni::UserGenerator& user )
{
    const kvs::ni::JointPosition pos = user.skeleton().jointPosition( index, joint );
    const kvs::Vector3f proj_pos = depth.projectPosition( pos.position() );
    const float d = 0.001f * proj_pos.z();
    return( kvs::Vector3f(
        d * m_p2r * ( proj_pos.x() - m_cx ),
        d * m_p2r * ( float( m_height ) - proj_pos.y() - m_cy ),
        - d ) );
}
コード例 #6
0
ファイル: main.cpp プロジェクト: koron21/kvs
    void sliderMoved( void )
    {
        const float dy_new = this->value();
        const float _ymin = center.y() - dy_new / 2;
        const float _ymax = center.y() + dy_new / 2;

        m_seed_point->setYMin( _ymin );
        m_seed_point->setYMax( _ymax );
        m_seed_point->reset_coordinates();

#ifdef USE_KVS
        m_compositor->changeObject( m_seed_point, m_seed_point, false );
#else
        m_renderer->changeObject( m_seed_point, m_point_renderer, false );
#endif
    }
コード例 #7
0
ファイル: SevenSegmentLED.cpp プロジェクト: njun-git/kvs
void OneSegment::build_segment_coord(
    const kvs::Vector3f& center,
    const float length,
    const float width,
    const float offset,
    const float left_ratio,
    const float right_ratio,
    const float rotate_theta )
{
    m_coords.allocate( 3 * 6 );

    // Set const z coord.
    for ( size_t i = 2; i < 18; i += 3 ) m_coords[i] = center.z();

    const float half_length = length / 2;

    m_coords[ 0] = - ( half_length + left_ratio * width - offset );
    m_coords[ 1] = - left_ratio * width;

    m_coords[ 3] = - ( half_length - width - offset );
    m_coords[ 4] = width;

    m_coords[ 6] = - ( half_length - ( 1.0f - 2 * left_ratio ) * width - offset );
    m_coords[ 7] = - width;

    m_coords[ 9] = ( half_length - width - offset );
    m_coords[10] = width;

    m_coords[12] = ( half_length - ( 1.0f - 2 * right_ratio ) * width - offset );
    m_coords[13] = - width;

    m_coords[15] = ( half_length + right_ratio * width - offset );
    m_coords[16] = - right_ratio * width;

    for ( size_t i = 0; i < 6; i++ )
    {
        const float theta = kvs::Math::Deg2Rad( rotate_theta );
        const float x = m_coords[ i * 3 + 0 ];
        const float y = m_coords[ i * 3 + 1 ];
        m_coords[ i * 3 + 0 ] = center.x() + cosf( theta ) * x + sinf( theta ) * y;
        m_coords[ i * 3 + 1 ] = center.y() - sinf( theta ) * x + cosf( theta ) * y;
    }
}
コード例 #8
0
ファイル: PolygonToPolygon.cpp プロジェクト: koron21/kvs
/*===========================================================================*/
void PolygonToPolygon::calculate_triangle_normals( void )
{
    const size_t nvertices = SuperClass::nvertices();
    const size_t npolygons = SuperClass::nconnections();
    const float* p_coords = SuperClass::coords().pointer();
    const unsigned int* p_connections = SuperClass::connections().pointer();

    kvs::ValueArray<float> normals( 3 * nvertices );
    normals.fill( 0x00 );

    for ( size_t i = 0; i < npolygons; i++ )
    {
        size_t index[3];
        kvs::Vector3f vertex[3];
        for ( size_t j = 0; j < 3; j++ )
        {
            index[j] = p_connections[ 3 * i + j ];
            vertex[j] = kvs::Vector3f( p_coords + 3 * index[j] );
        }

        const kvs::Vector3f normal( ( vertex[1] - vertex[0] ).cross( vertex[2] - vertex[0] ) );
        for ( size_t j = 0; j < 3; j++ )
        {
            normals[ 3 * index[j]     ] += normal.x();
            normals[ 3 * index[j] + 1 ] += normal.y();
            normals[ 3 * index[j] + 2 ] += normal.z();
        }
    }

    // Normalize normals.
    const float* p_normals = normals.pointer();
    for ( size_t i = 0; i < nvertices; i++ )
    {
        kvs::Vector3f normal( p_normals + i * 3 );
        normal.normalize();
        normals[ i * 3     ] = normal.x();
        normals[ i * 3 + 1 ] = normal.y();
        normals[ i * 3 + 2 ] = normal.z();
    }

    SuperClass::setNormals( normals );
    SuperClass::setNormalType( kvs::PolygonObject::VertexNormal );
}
コード例 #9
0
ファイル: HandsGenerator.cpp プロジェクト: njun-git/kvs
const bool HandsGenerator::startTracking( const kvs::Vector3f& position )
{
    if ( !m_is_created )
    {
        kvsMessageError( "HandsGenerator is not created yet." );
        return( false );
    }

    XnPoint3D pos;
    pos.X = position.x();
    pos.Y = position.y();
    pos.Z = position.z();

    XnStatus status = m_generator.StartTracking( pos );
    if ( status != XN_STATUS_OK )
    {
        kvsMessageError( "%s error: <%s>.",
            xnGetStatusName( status ),
            xnGetStatusString( status ) );
        return( false );
    }

    return( true );
}
コード例 #10
0
ファイル: MarchingPyramid.cpp プロジェクト: fudy1129/kvs
void MarchingPyramid::extract_surfaces_with_duplication(
    const kvs::UnstructuredVolumeObject* volume )
{
    // Calculated the coordinate data array and the normal vector array.
    std::vector<kvs::Real32> coords;
    std::vector<kvs::Real32> normals;

    const kvs::UInt32 ncells( volume->numberOfCells() );
    const kvs::UInt32* connections =
        static_cast<const kvs::UInt32*>( volume->connections().data() );

    // Extract surfaces.
    size_t index = 0;
    size_t local_index[5];
    for ( kvs::UInt32 cell = 0; cell < ncells; ++cell, index += 5 )
    {
        // Calculate the indices of the target cell.
        local_index[0] = connections[ index + 0 ];
        local_index[1] = connections[ index + 1 ];
        local_index[2] = connections[ index + 2 ];
        local_index[3] = connections[ index + 3 ];
        local_index[4] = connections[ index + 4 ];

        // Calculate the index of the reference table.
        size_t table_index = this->calculate_table_index<T>( local_index );
        if ( table_index == 0 ) continue;
        if ( table_index == 10 || table_index == 11 || table_index == 20 || table_index == 21 ){
            table_index = this->calculate_special_table_index<T>( local_index, table_index );
        }
        if ( table_index == 36 ) continue;

        // Calculate the triangle polygons.
        for ( size_t i = 0; MarchingPyramidTable::TriangleID[ table_index ][i] != -1; i += 3 )
        {
            // Refer the edge IDs from the TriangleTable by using the table_index.
            const int e0 = MarchingPyramidTable::TriangleID[table_index][i];
            const int e1 = MarchingPyramidTable::TriangleID[table_index][i+2];
            const int e2 = MarchingPyramidTable::TriangleID[table_index][i+1];

            // Determine vertices for each edge.
            const int v0 = local_index[MarchingPyramidTable::VertexID[e0][0]];
            const int v1 = local_index[MarchingPyramidTable::VertexID[e0][1]];

            const int v2 = local_index[MarchingPyramidTable::VertexID[e1][0]];
            const int v3 = local_index[MarchingPyramidTable::VertexID[e1][1]];

            const int v4 = local_index[MarchingPyramidTable::VertexID[e2][0]];
            const int v5 = local_index[MarchingPyramidTable::VertexID[e2][1]];

            // Calculate coordinates of the vertices which are composed
            // of the triangle polygon.
            const kvs::Vector3f vertex0( this->interpolate_vertex<T>( v0, v1 ) );
            coords.push_back( vertex0.x() );
            coords.push_back( vertex0.y() );
            coords.push_back( vertex0.z() );

            const kvs::Vector3f vertex1( this->interpolate_vertex<T>( v2, v3 ) );
            coords.push_back( vertex1.x() );
            coords.push_back( vertex1.y() );
            coords.push_back( vertex1.z() );

            const kvs::Vector3f vertex2( this->interpolate_vertex<T>( v4, v5 ) );
            coords.push_back( vertex2.x() );
            coords.push_back( vertex2.y() );
            coords.push_back( vertex2.z() );

            // Calculate a normal vector for the triangle polygon.
            const kvs::Vector3f normal( ( vertex1 - vertex0 ).cross( vertex2 - vertex0 ) );
            normals.push_back( normal.x() );
            normals.push_back( normal.y() );
            normals.push_back( normal.z() );
        } // end of loop-triangle
    } // end of loop-cell

    // Calculate the polygon color for the isolevel.
    const kvs::RGBColor color = this->calculate_color<T>();

    if( coords.size() > 0 ){
        SuperClass::setCoords( kvs::ValueArray<kvs::Real32>( coords ) );
        SuperClass::setColor( color );
        SuperClass::setNormals( kvs::ValueArray<kvs::Real32>( normals ) );
        SuperClass::setOpacity( 255 );
        SuperClass::setPolygonType( kvs::PolygonObject::Triangle );
        SuperClass::setColorType( kvs::PolygonObject::PolygonColor );
        SuperClass::setNormalType( kvs::PolygonObject::PolygonNormal );
    }
}
コード例 #11
0
void StructuredVolumeImporter::import( const kvs::DicomList* dicom_list )
{
    if ( dicom_list->size() == 0 )
    {
        BaseClass::setSuccess( false );
        kvsMessageError("Dicom file is not included.");
        return;
    }

    const float spacing = static_cast<float>( dicom_list->sliceSpacing() );
    const float thickness = static_cast<float>( dicom_list->sliceThickness() );

    const size_t x_size = dicom_list->width();
    const size_t y_size = dicom_list->height();
    const size_t z_size = dicom_list->nslices();
    const float x_ratio = dicom_list->pixelSpacing()[0];
    const float y_ratio = dicom_list->pixelSpacing()[1];
    const float z_ratio = kvs::Math::IsZero( spacing ) ? kvs::Math::IsZero( thickness ) ? x_ratio : thickness : spacing;

    const kvs::Vector3f min_obj_coord( 0.0f, 0.0f, 0.0f );
    const kvs::Vector3f max_obj_coord( x_size - 1.0f, y_size - 1.0f, z_size - 1.0f );
    SuperClass::setMinMaxObjectCoords( min_obj_coord, max_obj_coord );

    const kvs::Vector3f min_ext_coord( min_obj_coord );
    const kvs::Vector3f max_ext_coord( max_obj_coord.x() * x_ratio,
                                       max_obj_coord.y() * y_ratio,
                                       max_obj_coord.z() * z_ratio );
    SuperClass::setMinMaxExternalCoords( min_ext_coord, max_ext_coord );

    bool shift = true;
    const kvs::Dicom* dicom = (*dicom_list)[0];
    const kvs::UInt32 bits_allocated = dicom->bitsAllocated();
    const bool pixel_representation = dicom->pixelRepresentation();
    switch ( bits_allocated )
    {
    case 8:
    {
        const kvs::AnyValueArray values = this->get_dicom_data<kvs::UInt8>( dicom_list, false );
        SuperClass::setValues( values );
        break;
    }
    case 16:
    {
        if ( pixel_representation )
        {
            const kvs::AnyValueArray values = this->get_dicom_data<kvs::UInt16>( dicom_list, false );
            SuperClass::setValues( values );
        }
        else
        {
            if ( shift )
            {
                const kvs::AnyValueArray values = this->get_dicom_data<kvs::UInt16>( dicom_list, true );
                SuperClass::setValues( values );
            }
            else
            {
                const kvs::AnyValueArray values = this->get_dicom_data<kvs::Int16>( dicom_list, false );
                SuperClass::setValues( values );
            }
        }
        break;
    }
    default: break;
    }

    const kvs::Vector3ui resolution( x_size, y_size, z_size );
    SuperClass::setGridType( kvs::StructuredVolumeObject::Uniform );
    SuperClass::setResolution( resolution );
    SuperClass::setVeclen( 1 );
    SuperClass::updateMinMaxValues();
}
コード例 #12
0
ファイル: main.cpp プロジェクト: koron21/kvs
    void pressed()
    {
#ifdef WIN32
        std::string default_volume1( "D:\\Koron\\Dropbox\\Work\\Viz\\Hyperstreamline\\data\\engine\\v6engine_stress_and_mises.kvsml" );
#else
        std::string default_volume1( "../../data/engine/v6engine_stress_and_mises.kvsml" );
#endif
        if ( p_arg->hasOption( "volume1" ) )
            m_volume1 = new kvs::UnstructuredVolumeImporter( p_arg->optionValue<std::string>("volume1") );
        else
            m_volume1 = new kvs::UnstructuredVolumeImporter( default_volume1 );

        if ( m_volume1->veclen() != 6 && m_volume1->veclen() != 7 )
        {
            p_pb_info->setCaption( "Veclen wrong!" );
            return;
        }

        // initialize sliders
        const kvs::Vector3f min_coord = m_volume1->minExternalCoord();
        const kvs::Vector3f max_coord = m_volume1->maxExternalCoord();
        xmin = min_coord.x();
        ymin = min_coord.y();
        zmin = min_coord.z();
        xmax = max_coord.x();
        ymax = max_coord.y();
        zmax = max_coord.z();
        center.x() = ( xmin + xmax ) / 2;
        center.y() = ( ymin + ymax ) / 2;
        center.z() = ( zmin + zmax ) / 2;
        resx = 10;
        resy = 10;
        resz = 10;
        const float dx = xmax - xmin;
        const float dy = ymax - ymin;
        const float dz = zmax - zmin;

        p_sld0->setValue( dx );
        p_sld0->setRange( 0.0, dx );
        p_sld0->activate();
        p_sld1->setValue( dy );
        p_sld1->setRange( 0.0, dy );
        p_sld1->activate();
        p_sld2->setValue( dz );
        p_sld2->setRange( 0, dz );
        p_sld2->activate();

        p_sld3->setValue( resx );
        p_sld3->setRange( 0, 30 );
        p_sld3->activate();
        p_sld4->setValue( resy );
        p_sld4->setRange( 0, 30 );
        p_sld4->activate();
        p_sld5->setValue( resz );
        p_sld5->setRange( 0, 30 );
        p_sld5->activate();

        m_seed_point->setResX( resx );
        m_seed_point->setResY( resy );
        m_seed_point->setResZ( resz );
        m_seed_point->setXMin( xmin );
        m_seed_point->setXMax( xmax );
        m_seed_point->setYMin( ymin );
        m_seed_point->setYMax( ymax );
        m_seed_point->setZMin( zmin );
        m_seed_point->setZMax( zmax );
        m_seed_point->reset_coordinates();
        m_seed_point->setMinMaxObjectCoords( m_volume1->minObjectCoord(), m_volume1->maxObjectCoord() );
        m_seed_point->setMinMaxExternalCoords( m_volume1->minExternalCoord(), m_volume1->maxExternalCoord() );
        
#ifdef USE_KVS
#else
        m_renderer->changeObject( m_seed_point, m_point_renderer, false );
#endif

        p_pb_info->setCaption( "Tensor Volume Read!" );
        std::cout << "Tensor Volume Read" << std::endl;
        this->deactivate();
    }
コード例 #13
0
ファイル: main.cpp プロジェクト: koron21/kvs
int main( int argc, char** argv )
{
    kvs::glut::Application app( argc, argv );
    Argument arg( app.argc(), app.argv() );
    p_arg = &arg;

    // for empty objects
    std::vector<kvs::Real32> coords;
    std::vector<kvs::UInt32> connections;
    std::vector<kvs::UInt8>  colors;
    std::vector<float>       values;
    std::vector<float>       eigenvalues;

    colors.push_back(255);
    colors.push_back(255);
    colors.push_back(255);
    for ( unsigned int i = 0; i < 3; i++ )
    {
        coords.push_back(0.0);
    }
    for ( unsigned int i = 0; i < 2; i ++ )
    {
        connections.push_back(0);
        values.push_back(0.0);
    }
    eigenvalues.push_back(0);

    // Volume 2 (Displacement)
    m_volume2 = new kvs::UnstructuredVolumeObject();
    m_volume2->setCellType( kvs::UnstructuredVolumeObject::Tetrahedra );
    m_volume2->setConnections( kvs::ValueArray<kvs::UInt32>( connections ) );
    m_volume2->setCoords( kvs::ValueArray<float>( coords ) );
    m_volume2->setValues( kvs::AnyValueArray( values ) );
    m_volume2->setNCells(0);
    m_volume2->setNNodes(0);

    // polygon (Empty External)
#ifdef WIN32
    std::string default_polygon( "D:\\Koron\\Dropbox\\Work\\Viz\\Hyperstreamline\\data\\engine\\v6engine_external_face.kvsml" );
#else
    std::string default_polygon( "../../data/engine/v6engine_external_face.kvsml" );
#endif
    if ( p_arg->hasOption( "polygon" ) )
    {
       kvs::PolygonObject* import_polygon = new kvs::PolygonImporter( p_arg->optionValue<std::string>("polygon") );
       m_polygon = new kvs::PolygonToPolygon( import_polygon );
    }
    else
    {
        kvs::PolygonObject* import_polygon = new kvs::PolygonImporter( default_polygon );
        m_polygon = new kvs::PolygonToPolygon( import_polygon );
    }

    if ( !m_polygon )
    {
        kvsMessageError( "Cannot create surface." );
        exit( EXIT_FAILURE );
    }
    m_polygon->setOpacity( opacity_polygon );
    m_polygon->setColor( kvs::RGBColor( 255,255,255 ) );

    const kvs::Vector3f min_coord = m_polygon->minExternalCoord();
    const kvs::Vector3f max_coord = m_polygon->maxExternalCoord();
    xmin = min_coord.x();
    ymin = min_coord.y();
    zmin = min_coord.z();
    xmax = max_coord.x();
    ymax = max_coord.y();
    zmax = max_coord.z();
    resx = 10;
    resy = 10;
    resz = 10;

    m_seed_point = new kvs::CubicPointObject();
    m_seed_point->reset_coordinates( resx, resy, resz, xmin, xmax, ymin, ymax, zmin, zmax );
    m_seed_point->updateMinMaxCoords();

    // streamlines (Empty LineObject)
    m_streamline = new kvs::HyperStreamline();
    m_streamline->setLineType( kvs::LineObject::Polyline );
    m_streamline->setColorType( kvs::LineObject::VertexColor );
    m_streamline->setCoords( kvs::ValueArray<kvs::Real32>( coords ) );
    m_streamline->setConnections( kvs::ValueArray<kvs::UInt32>( connections ) );
    m_streamline->setEigenValues( eigenvalues );
    m_streamline->setColors( kvs::ValueArray<kvs::UInt8>( colors ) );
    m_streamline->setSize( 1.0f );

    // main screen
    kvs::glut::Screen main_screen( &app );
    p_main_screen = &main_screen;
    //main_screen.background()->setColor( kvs::RGBAColor( 0, 0, 0, 1 ) );
    int interval = 30;
    kvs::glut::Timer timer( interval );
    TimerEvent timer_event;
    KeyPressEvent keypress_event;

    main_screen.addTimerEvent( &timer_event, &timer );
    main_screen.addKeyPressEvent( &keypress_event );
    main_screen.show();

    // renderer
#ifdef USE_KVS
    m_compositor = new kvs::glew::StochasticRenderingCompositor( &main_screen );
    m_compositor->enableLODControl();

    m_tfunc.adjustRange( m_volume2 );
    m_tfunc.setColorMap( kvs::RGBFormulae::AFMHot(256) );

    m_volume_renderer = new kvs::glew::StochasticTetrahedraEngine();
    m_volume_renderer->setTransferFunction( m_tfunc );
    m_volume_renderer->setShader( kvs::Shader::BlinnPhong() );
    m_volume_renderer->disableShading();
    m_volume_renderer->setEdgeSize( 2 );

    m_polygon_renderer = new kvs::glew::StochasticPolygonEngine();
    m_polygon_renderer->setShader( kvs::Shader::BlinnPhong() );
   
    m_point_renderer = new kvs::glew::StochasticPointEngine();
    m_point_renderer->disableShading();

    m_line_renderer = new kvs::glew::StochasticLineEngine();
    m_line_renderer->setShader( kvs::Shader::BlinnPhong() );
    m_line_renderer->setOpacity( opacity_line );

    m_compositor->registerObject( m_volume2, m_volume_renderer );
    m_compositor->registerObject( m_polygon, m_polygon_renderer );
    m_compositor->registerObject( m_seed_point, m_point_renderer );
    m_compositor->registerObject( m_streamline, m_line_renderer );
#else
    m_renderer = new kvs::glew::StochasticRenderer( 1 );
    m_renderer->enableLODControl();

    m_tfunc.adjustRange( m_volume2 );
    m_tfunc.setColorMap( kvs::RGBFormulae::AFMHot(256) );
    m_volume_renderer = new kvs::glew::StochasticVolumeRenderer( m_volume2 );
    m_volume_renderer->setTransferFunction( m_tfunc );
    m_volume_renderer->setShader( kvs::Shader::BlinnPhong() );
    m_volume_renderer->disableShading();
    m_volume_renderer->setEdgeSize( 2 );
    m_renderer->registerRenderer( m_volume_renderer );

    m_polygon_renderer = new kvs::glew::StochasticPolygonRenderer( m_polygon );
    m_polygon_renderer->setShader( kvs::Shader::BlinnPhong() );
    m_renderer->registerRenderer( m_polygon_renderer );

    m_point_renderer = new kvs::glew::StochasticPointRenderer( m_seed_point );
    m_point_renderer->disableShading();
    m_renderer->registerRenderer( m_point_renderer );

    m_line_renderer = new kvs::glew::StochasticLineRenderer( m_streamline );
    m_line_renderer->setShader( kvs::Shader::BlinnPhong() );
    m_line_renderer->setOpacity( opacity_line );
    m_renderer->registerRenderer( m_line_renderer );

    null = new::kvs::NullObject( m_seed_point );
    null->setName( "null" );
    main_screen.registerObject( null, m_renderer );
    main_screen.show();

#endif

    // tfunc editor
    //TransferFunctionEditor editor( &main_screen, m_renderer, m_volume_renderer );
    //editor.setVolumeObject( m_volume2 );
    //editor.show();


    //kvs::ControlScreen control_screen( &app );
    MouseMoveEvent mouse_move_event;
    kvs::glut::Screen control_screen( &app );
    //control_screen.addMouseMoveEvent( &mouse_move_event );
    control_screen.setMouseMoveEvent( &mouse_move_event );
    control_screen.setTitle( "kvs::ControlScreen" );
    control_screen.setGeometry( 512, 0, 600, 560 );

#ifdef USE_KVS
    //control_screen.attachMainScreen( p_main_screen, m_seed_point, m_compositor, m_point_renderer );
#else
    //control_screen.attachMainScreen( p_main_screen, m_seed_point, m_renderer, m_point_renderer );
#endif
    control_screen.show();

    PaintEvent paint_event;
    control_screen.addPaintEvent( &paint_event );

    const int width = control_screen.width();
    const int height = control_screen.height();
    const int ui_width = 240;

    PB_INFO pb_info( &control_screen );
    p_pb_info = &pb_info;
    pb_info.setX( width/6 );
    pb_info.setY( height - 40 );
    pb_info.setWidth( 400 );
    pb_info.setMargin( 5 );
    pb_info.setTextMargin( 5 );
    pb_info.setCaption("");
    //pb_info.deactivate();
    pb_info.show();


    PB00 pb00( &control_screen );
    p_pb00 = &pb00;
    pb00.setX( width - ui_width );
    pb00.setY( 10 );
    pb00.setWidth( 220 );
    pb00.setMargin( 5 );
    pb00.setTextMargin( 5 );
    pb00.setCaption("Read volume1(Stress)");
    pb00.show();

    PB01 pb01( &control_screen );
    p_pb01 = &pb01;
    pb01.setX( pb00.x() );
    pb01.setY( pb00.y() + pb00.height() );
    pb01.setWidth( 220 );
    pb01.setMargin( 5 );
    pb01.setTextMargin( 5 );
    pb01.setCaption("Read volume2(Displacement)");
    pb01.deactivate();
    pb01.show();

    PB02 pb02( &control_screen );
    p_pb02 = &pb02;
    pb02.setX( pb01.x() );
    pb02.setY( pb01.y() + pb01.height() );
    pb02.setWidth( 220 );
    pb02.setMargin( 5 );
    pb02.setTextMargin( 5 );
    pb02.setCaption("Hide Polygon");
    //pb02.deactivate();
    pb02.show();

    PB03 pb03( &control_screen );
    p_pb03 = &pb03;
    pb03.setX( pb02.x() );
    pb03.setY( pb02.y() + pb02.height() );
    pb03.setWidth( 220 );
    pb03.setMargin( 5 );
    pb03.setTextMargin( 5 );
    pb03.setCaption("Read CellTree(Optional)");
    //pb03.deactivate();
    pb03.show();

    SLD0 sld0( &control_screen );
    p_sld0 = &sld0;
    sld0.setX( pb03.x() );
    sld0.setY( pb03.y() + pb03.height() );
    sld0.setWidth( 220 );
    sld0.setMargin( 0 );
    sld0.setCaption("dx");
    //sld0.deactivate();
    sld0.show();

    SLD1 sld1( &control_screen );
    p_sld1 = &sld1;
    sld1.setX( sld0.x() );
    sld1.setY( sld0.y() + sld0.height() );
    sld1.setWidth( 220 );
    sld1.setMargin( 0 );
    sld1.setCaption("dy");
    //sld1.deactivate();
    sld1.show();

    SLD2 sld2( &control_screen );
    p_sld2 = &sld2;
    sld2.setX( sld1.x() );
    sld2.setY( sld1.y() + sld1.height() );
    sld2.setWidth( 220 );
    sld2.setMargin( 0 );
    sld2.setCaption("dz");
    //sld2.deactivate();
    sld2.show();

    SLD3 sld3( &control_screen );
    p_sld3 = &sld3;
    sld3.setX( sld2.x() );
    sld3.setY( sld2.y() + sld2.height() );
    sld3.setWidth( 220 );
    sld3.setMargin( 0 );
    sld3.setCaption("resx");
    //sld3.deactivate();
    sld3.show();

    SLD4 sld4( &control_screen );
    p_sld4 = &sld4;
    sld4.setX( sld3.x() );
    sld4.setY( sld3.y() + sld3.height() );
    sld4.setWidth( 220 );
    sld4.setMargin( 0 );
    sld4.setCaption("resy");
    //sld4.deactivate();
    sld4.show();

    SLD5 sld5( &control_screen );
    p_sld5 = &sld5;
    sld5.setX( sld4.x() );
    sld5.setY( sld4.y() + sld4.height() );
    sld5.setWidth( 220 );
    sld5.setMargin( 0 );
    sld5.setCaption("resz");
    //sld5.deactivate();
    sld5.show();

    PB04 pb04( &control_screen );
    p_pb04 = &pb04;
    pb04.setX( sld5.x() );
    pb04.setY( sld5.y() + sld5.height() );
    pb04.setWidth( 220 );
    pb04.setMargin( 15 );
    pb04.setTextMargin( 5 );
    pb04.setCaption("Update Streamline");
    //pb04.deactivate();
    pb04.show();

    PB05 pb05( &control_screen );
    p_pb05 = &pb05;
    pb05.setX( 10 );
    pb05.setY( pb04.y() + 10 );
    pb05.setWidth( 120 );
    pb05.setMargin( 5 );
    pb05.setTextMargin( 5 );
    pb05.setCaption("Buffer Line");
    //pb04.deactivate();
    pb05.show();

    PB06 pb06( &control_screen );
    p_pb06 = &pb06;
    pb06.setX( pb05.x() + pb05.width() );
    pb06.setY( pb05.y() );
    pb06.setWidth( 80 );
    pb06.setMargin( 5 );
    pb06.setTextMargin( 5 );
    pb06.setCaption("Clear");
    //pb04.deactivate();
    pb06.show();

    PB07 pb07( &control_screen );
    p_pb07 = &pb07;
    pb07.setX( pb06.x() + pb06.width() );
    pb07.setY( pb06.y() );
    pb07.setWidth( 160 );
    pb07.setMargin( 5 );
    pb07.setTextMargin( 5 );
    pb07.setCaption("Save CellTree.dat");
    //pb04.deactivate();
    pb07.show();

    RB00 rb00( &control_screen );
    rb00.setX( pb05.x() );
    rb00.setY( pb05.y() - pb05.height() );
    rb00.setWidth( 100 );
    rb00.setMargin( 15 );
    rb00.setCaption( "Principal" );
    rb00.setState( "true" );

    RB01 rb01( &control_screen );
    rb01.setX( rb00.x() + rb00.width() );
    rb01.setY( rb00.y() );
    rb01.setWidth( 130 );
    rb01.setMargin( 15 );
    rb01.setCaption( "Intermediate" );

    RB02 rb02( &control_screen );
    rb02.setX( rb01.x() + rb01.width() );
    rb02.setY( rb01.y() );
    rb02.setWidth( 100 );
    rb02.setMargin( 15 );
    rb02.setCaption( "Minor" );

    kvs::glut::RadioButtonGroup rbg0( &control_screen );
    rbg0.add( &rb00 );
    rbg0.add( &rb01 );
    rbg0.add( &rb02 );
    rbg0.show();

    CB00 cb00( &control_screen );
    cb00.setX( rb00.x() + rb00.width() );
    cb00.setY( rb00.y() - rb00.height() );
    cb00.setWidth( 100 );
    cb00.setMargin( 25 );
    cb00.setCaption( "Cache" );
    cb00.setState( true );
    cb00.show();

    kvs::ColorMap cmap;
    cmap.setRange( -127, 127 );
    cmap.create();

    kvs::glut::LegendBar legend_bar( &main_screen );
    legend_bar.setColorMap( cmap );
    legend_bar.show();

    return( app.run() );

}
コード例 #14
0
ファイル: main.cpp プロジェクト: koron21/kvs
    void update ( kvs::MouseEvent* event = 0 )
    {
        if ( event->x() > 20 && event->x() < 330 && event->y() > 20 && event->y() < 400 && m_seed_point->nvertices() > 0 )
        {
            const kvs::Xform x = p_main_screen->objectManager()->xform();

            const float* pcoord = m_seed_point->coords().pointer();
            const unsigned int nvertices = m_seed_point->nvertices();
            kvs::ValueArray<float> coords( nvertices * 3 );

            if ( event->button() == kvs::MouseButton::Right )
            {
                this->screen()->mouse()->setMode( kvs::Mouse::Translation );
                this->screen()->mouse()->move( event->x(), event->y() );
                kvs::Vector3f translation = this->screen()->mouse()->translation();
                const kvs::Vector3f normalize = p_main_screen->objectManager()->normalize();

                translation.x() /= normalize.x() * x.scaling().x();
                translation.y() /= normalize.y() * x.scaling().y();
                translation.z() /= normalize.z() * x.scaling().z();

                for ( unsigned int i = 0; i < nvertices; i ++ )
                {
                    kvs::Vector3f coord( pcoord );
                    const kvs::Vector3f new_coord = coord + translation * x.rotation();
                    coords[ 3 * i] = new_coord.x();
                    coords[ 3 * i + 1] = new_coord.y();
                    coords[ 3 * i + 2] = new_coord.z();
                    pcoord += 3;
                }
                m_seed_point->setCoords( coords );
                
            }

            if ( event->button() == kvs::MouseButton::Left )
            {
                this->screen()->mouse()->setMode( kvs::Mouse::Rotation );
                this->screen()->mouse()->move( event->x(), event->y() );
                kvs::Matrix33f rotation = this->screen()->mouse()->rotation().toMatrix();

                for ( unsigned int i = 0; i < nvertices; i ++ )
                {
                    kvs::Vector3f coord( pcoord );
                    const kvs::Vector3f new_coord = coord * rotation;
                    coords[ 3 * i] = new_coord.x();
                    coords[ 3 * i + 1] = new_coord.y();
                    coords[ 3 * i + 2] = new_coord.z();
                    pcoord += 3;
                }
                m_seed_point->setCoords( coords );
            }
#ifdef USE_KVS
            m_compositor->changeObject( m_seed_point, m_seed_point, false );
#else
            m_renderer->changeObject( m_seed_point, m_point_renderer, false );
#endif
            m_seed_point->updateMinMaxCoords();
            const kvs::Vector3f min = m_seed_point->minObjectCoord();
            const kvs::Vector3f max = m_seed_point->maxObjectCoord();
            center = ( min + max ) / 2;
            m_seed_point->setXMin( min.x() );
            m_seed_point->setXMax( max.x() );
            m_seed_point->setYMin( min.y() );
            m_seed_point->setYMax( max.y() );
            m_seed_point->setZMin( min.z() );
            m_seed_point->setZMax( max.z() );

            if ( m_seed_point->nvertices() <= 8 )
                update_streamline();
        }
    }