Raycasting Rendering

In this example, you import the structured volume data and render by using raycasting renderering method.

 

1. Make a working directory

First please create a working directory (e.g., RayCasting) and move in this directory.

# mkdir  RayCasting

# cd RayCasting

 

2. Programming

In order to import the volume data form standard input, you check the number of command-line argument.

int main( int argc, char** argv )

{

 if( !(argc == 2 ) ) {

   std::cerr << "USAGE (1): ./RayCasting volume_data" << std::endl;

   exit(1) ;

 }

 return ( 0 );

}

 

3. File Importer

The input data file imports by using kvs::StructuredVolumeImporter and transfers to kvs::StructuredVolumeObject.

kvs::StructuredVolumeObject* object

    = new kvs::StructuredVolumeImporter( std::string( argv[1] ) );

if ( !object ) 

{

  kvsMessageError( "Cannot create a structured volume object." );

  return( false );

}

4. Create renderer

In order to apply the ray casting method for rendering the structured volume data, you create the instance of kvs::RayCastingRenderer class.

For example:

kvs::RayCastingRenderer* renderer = new kvs::RayCastingRenderer();

if ( !renderer )

{

kvsMessageError( "Cannot create a ray casting renderer." );

delete object;

return( false );

}

5. Drawing

For visualization, we should instantiate classes kvs::glut::Application and kvs::glut::Screen and resiter the viusalized objects to the screen.

Notice that the renderer registers with the object.

kvs::glut::Application app( argc, argv );

kvs::glut::Screen screen( &app );

// renderer registers with object

screen.registerObject( object, renderer );

screen.setGeometry( 0, 0, 512, 512 );

screen.setTitle( "RayCastingRenderer" );

screen.show();

 

return( app.run() );

6. Header file

You have to include the header file for following class:

Therefore, you include :

#include <kvs/StructuredVolumeObject>

#include <kvs/StructuredVolumeImporter>

#include <kvs/RayCastingRenderer>

#include <kvs/glut/Application>

#include <kvs/glut/Screen>

7. Sample program

Sample program: RayCasting.tgz

Notice that this sample program includes sample data:

 

8. Compile and execute

Let's try to compile and execute above program.

When compiling a KVS program, it is easy to use the automatic Makefile-generation tool kvsmake supplied by KVS.

 

# kvsmake -G          <-- Create Makefiel

# kvsmake            <-- Compile

And then, you show following image.

# ./RayCasting test.fld

# ./RayCasting hydrogen.kvsml

 

test.fld   hydrogen.kvsml

test.fld                             hydrogen.kvsml

 

TOP