// Create a volume rendering node with all desired attachments
NodePtr makeVolume(ImagePtr datImage)
{  
    vol         = DVRVolume::create();
    DVRAppearancePtr     app         = DVRAppearance::create(); 
    DVRVolumeTexturePtr  tex         = DVRVolumeTexture::create();

    beginEditCP(tex);
    tex->setImage(datImage);
    endEditCP(tex);

    // Attach the volume texture to the appearance
    beginEditCP(app, Node::AttachmentsFieldMask);
    app->addAttachment(tex);
    endEditCP  (app, Node::AttachmentsFieldMask);

    // Assign the appearance to the volume core
    beginEditCP(vol);
    vol->setAppearance(app);
    vol->setShader(DVRSimpleShader::create());
    endEditCP(vol);

    // Create a node for the volume core
    NodePtr newGeom = Node::create();
    beginEditCP(newGeom);
    newGeom->setCore(vol);
    endEditCP(newGeom);
    
    return newGeom;
}
Пример #2
0
//! set the bounding volume of the node
void DVRVolume::adjustVolume(Volume &volume)
{
    volume.setValid();
    volume.setEmpty();
    
    DVRVolumeTexturePtr tex = DVRVOLUME_PARAMETER(this, DVRVolumeTexture);

    if (tex != NullFC) 
    {
        const Vec3f & res   = tex->getResolution    ();
        const Vec3f & slice = tex->getSliceThickness();
    
        Vec3f minBB(-0.5f * res[0] * slice[0],
                    -0.5f * res[1] * slice[1],
                    -0.5f * res[2] * slice[2]);

        Vec3f maxBB(-minBB);
    
        volume.extendBy(minBB);
        volume.extendBy(maxBB);
    }    
    else 
    {
        // something wrong with initialization - show boundingbox either
        Vec3f minBB(-0.5, -0.5, -0.5);
        Vec3f maxBB( 0.5,  0.5,  0.5);
        
        volume.extendBy(minBB);
        volume.extendBy(maxBB);
    }
}
// Create a volume rendering node with all desired attachments
NodePtr makeVolume( const char * datFile)
{
    DVRVolumePtr         vol         = DVRVolume::create();
    DVRAppearancePtr     app         = DVRAppearance::create();
    DVRVolumeTexturePtr  tex         = DVRVolumeTexture::create();
    DVRLookupTablePtr    lut         = DVRLookupTable::create();

    volume = vol;

    // Load the 3D-image and store it in the volume texture attachment
    ImagePtr datImage = Image::create();
    if (false == datImage->read(datFile)) {
        SLOG << "File: " << datFile << " not found" << std::endl;
        exit (-1);
    }
    beginEditCP(tex);
    tex->setImage(datImage);
    tex->setFileName(datFile);
    endEditCP(tex);

    //!! FIXME - Initialize the lookup table
    //!! This should not be neccessary if the OpenSG reader works correctly
    beginEditCP(lut, DVRLookupTable::TouchedFieldMask);
    lut->setTouched(true);
    endEditCP(lut, DVRLookupTable::TouchedFieldMask);

    // Initialize the lookup table
    beginEditCP(lut, DVRLookupTable::DataFieldMask);
    for (int i = 0; i < 1024; i++)
        lut->getData()[i] = lutData[i];
    endEditCP(lut, DVRLookupTable::DataFieldMask);

    // Attach the volume texture and lookup table to the appearance
    beginEditCP(app, Node::AttachmentsFieldMask);
    app->addAttachment(tex);
    app->addAttachment(lut);
    endEditCP  (app, Node::AttachmentsFieldMask);

    // Create a shader
    shader = DVRSimpleLUTShader::create();

    // Assign the appearance and shader to the volume core
    beginEditCP(vol);
    vol->setFileName(datFile);
    vol->setAppearance(app);
    vol->setShader(shader);
    endEditCP(vol);

    // Create a node for the volume core
    NodePtr newGeom = Node::create();
    beginEditCP(newGeom);
    newGeom->setCore(vol);
    endEditCP(newGeom);

    return newGeom;
}
Пример #4
0
void DVRVolume::initializeClipObjects(      DrawActionBase *action, 
                                      const Matrix         &volumeToWorld)
{
    DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(this, DVRClipObjects);
  
    if(clipObjects                != NullFC && 
       clipObjects->getClipMode() != DVRClipObjects::Off)
    {
        
        DVRVolumeTexturePtr tex = DVRVOLUME_PARAMETER(this, DVRVolumeTexture);

        if(tex != NullFC) 
        {
            const Vec3f &res   = tex->getResolution();
            const Vec3f &slice = tex->getSliceThickness();
            
            Vec3f diag(res[0] * slice[0], 
                       res[1] * slice[1], 
                       res[2] * slice[2]);
            
            Vec3f sliceDir;
            
            if(getShader()->useMTSlabs())
            {
                Slicer::getAASlicingDirection(action,&sliceDir);
            }
            else
            {  
                switch (getTextures2D()) 
                {
                    case 0: // 3D textures
                        Slicer::getSlicingDirection(action, &sliceDir);    
                        break;

                    case 1: // 2D textures  
                        Slicer::getAASlicingDirection(action, &sliceDir);
                        break;

                    default: // auto
                        Window *window = action->getWindow();

                        if(window->hasExtension(_extTex3D))
                            Slicer::getSlicingDirection(action, &sliceDir);
                        else
                            Slicer::getAASlicingDirection(action, &sliceDir);
                }
            }
            
            Plane clipReferencePlane(sliceDir, -0.5f * diag.length());  
            
            clipObjects->initialize(volumeToWorld, clipReferencePlane);

            clipper.setReferencePlane(clipReferencePlane);
        }
    }
}
// Create a volume rendering node with all desired attachments
NodePtr makeVolume( const char * datFile)
{  
    DVRVolumePtr         vol         = DVRVolume::create();
    DVRAppearancePtr     app         = DVRAppearance::create(); 
    DVRVolumeTexturePtr  tex         = DVRVolumeTexture::create();

    // Load the 3D-image and store it in the volume texture attachment
    ImagePtr datImage = Image::create();
    if (false == datImage->read(datFile)) {
        SLOG << "File: " << datFile << " not found" << std::endl;
	exit (-1);
    }
    beginEditCP(tex);
    tex->setImage(datImage);
    tex->setFileName(datFile);
    endEditCP(tex);

    // Attach the volume texture to the appearance
    beginEditCP(app, Node::AttachmentsFieldMask);
    app->addAttachment(tex);
    endEditCP  (app, Node::AttachmentsFieldMask);

    // Assign the appearance to the volume core
    beginEditCP(vol);
    vol->setFileName(datFile);
    vol->setAppearance(app);
    vol->setShader(DVRSimpleShader::create());
    endEditCP(vol);

    // Create a node for the volume core
    NodePtr newGeom = Node::create();
    beginEditCP(newGeom);
    newGeom->setCore(vol);
    endEditCP(newGeom);
    
    return newGeom;
}