[vtkusers] Why two scalar volume rendering failed???

Enya Shen enya.shen2010 at gmail.com
Thu Mar 20 11:01:17 EDT 2014


The related code:


......

// Create volume volumeProperty and attach transfer functions

this->volumeProperty = vtkVolumeProperty::New();

this->volumeProperty->SetIndependentComponents(false);

this->volumeProperty->SetScalarOpacity(this->opacityFn);

this->volumeProperty->SetColor(this->colorFn);

this->volumeProperty->SetInterpolationTypeToLinear();

this->volumeProperty->ShadeOn();

......


void setBlendType(int blendType)

{

    // Init

    this->opacityFn->RemoveAllPoints();

    this->colorFn->RemoveAllPoints();

    this->opacityLevel  = 1048;

    this->opacityWindow = 2048;

        // Add function points

    switch (blendType)

    {

    // RGB

    case 0:

        if (this->scalarsRange.size() == 0) break;


        this->volumeProperty->SetIndependentComponents(false);


        this->colorFn->AddRGBPoint(this->scalarsRange[0][0], 0.0, 0.0, 1.0);

        this->colorFn->AddRGBPoint(0.5*(this->scalarsRange[0][0]+this->scalarsRange[0][1]),
0.0, 1.0, 0.0);

        this->colorFn->AddRGBPoint(this->scalarsRange[0][1], 1.0, 0.0, 0.0);


        this->opacityFn->AddPoint(this->scalarsRange[0][0], 0.0, 0.5, 0.0);

        this->opacityFn->AddPoint(0.5*(this->scalarsRange[0][0]+this->scalarsRange[0][1]),
0.5, 0.5, 0.0);

        this->opacityFn->AddPoint(this->scalarsRange[0][1], 1.0, 0.5, 0.0);


        this->volumeMapper->SetBlendModeToComposite();

        this->volumeProperty->SetAmbient(0.1);

        this->volumeProperty->SetDiffuse(0.9);

        this->volumeProperty->SetSpecular(0.2);

        this->volumeProperty->SetSpecularPower(10.0);

        break;

    // Two scalar

    case 1:

        if (this->scalarsRange.size() < 2) break;


        this->colorFn->AddRGBPoint(this->scalarsRange[0][0], 0.0, 0.0, 1.0);

        this->colorFn->AddRGBPoint(0.5*(this->scalarsRange[0][0]+this->scalarsRange[0][1]),
0.0, 1.0, 0.0);

        this->colorFn->AddRGBPoint(this->scalarsRange[0][1], 1.0, 0.0, 0.0);


        this->opacityFn->AddPoint(this->scalarsRange[1][0], 0.0, 0.5, 0.0);

        this->opacityFn->AddPoint(0.5*(this->scalarsRange[1][0]+this->scalarsRange[1][1]),
0.5, 0.5, 0.0);

        this->opacityFn->AddPoint(this->scalarsRange[1][1], 1.0, 0.5, 0.0);


        this->volumeProperty->SetIndependentComponents(true);


        break;

      default:

        this->opacityFn->AddSegment(this->opacityLevel -
0.5*this->opacityWindow, 0.0,

                                    this->opacityLevel +
0.5*this->opacityWindow, 1.0 );

        this->colorFn->AddRGBSegment(0, 1.0, 1.0, 1.0, 500, 1.0, 1.0, 1.0);

        this->volumeMapper->SetBlendModeToMaximumIntensity();

        break;

    }

}



2014-03-20 22:56 GMT+08:00 Enya Shen <enya.shen2010 at gmail.com>:

> I get nothing error message. And I only don't see any opacity!
>
> The range of the first scalar is about [0, 12]. And the second is [0,1].
>
> I am really confused.
>
>
> 2014-03-20 22:33 GMT+08:00 Aashish Chaudhary <
> aashish.chaudhary at kitware.com>:
>
>
>> On Thu, Mar 20, 2014 at 10:27 AM, Enya Shen <enya.shen2010 at gmail.com>wrote:
>>
>>> Hi all,
>>>
>>> I tried to use different scalar for color and opacity in volume
>>> rendering as follows. But it failed to use the second scalar to get
>>> opacity. Why? Thank you for any advice!!!
>>>
>>> ......
>>>
>>> vtkPiecewiseFunction* opacityFn = vtkPiecewiseFunction::New();
>>>
>>> vtkColorTransferFunction* colorFn = vtkColorTransferFunction::New();
>>>
>>>
>>> vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New();
>>>
>>> volumeProperty->SetIndependentComponents(false);
>>>
>>> volumeProperty->SetScalarOpacity(this->opacityFn);
>>>
>>> volumeProperty->SetColor(this->colorFn);
>>>
>>> volumeProperty->SetInterpolationTypeToLinear();
>>>
>>> volumeProperty->ShadeOn();
>>>
>>>
>>> vtkVolume* volumeActor = vtkVolume::New();
>>>
>>> volumeActor->SetProperty(this->volumeProperty);
>>>
>>>
>>> colorFn->AddRGBPoint(this->scalarsRange[0][0], 0.0, 0.0, 1.0);
>>>
>>> colorFn->AddRGBPoint(0.5*(this->scalarsRange[0][0]+this->scalarsRange[0][1]), 0.0, 1.0, 0.0);
>>>
>>> colorFn->AddRGBPoint(this->scalarsRange[0][1], 1.0, 0.0, 0.0);
>>>
>>> opacityFn->AddPoint(this->scalarsRange[1][0], 0.0, 0.0, 0.0);
>>>
>>>
>>> opacityFn->AddPoint(0.5*(this->scalarsRange[1][0]+this->scalarsRange[1][1]), 0.5, 0.0, 0.0);
>>>
>>> opacityFn->AddPoint(this->scalarsRange[1][1], 1.0, 0.0, 0.0);
>>>
>>> volumeProperty->SetIndependentComponents(true);
>>>
>>>
>>
>> Did you get any error or its just that you don't see any opacity?  What
>> are the ranges? I may have to look at the VTK code
>> and your data to provide a solution.
>>
>> - Aashish
>>
>>>
>>> ......
>>>
>>>
>>> Regards,
>>>
>>> Enya
>>>
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>
>>
>> --
>> | Aashish Chaudhary
>> | R&D Engineer
>> | Kitware Inc.
>> | www.kitware.com
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140320/13bdc05d/attachment.html>


More information about the vtkusers mailing list