[vtkusers] Problem with color and shading when rendering vtkimagedata

shadab anwar sk.shadabanwar at gmail.com
Wed Dec 5 14:08:34 EST 2018


Hey amigos,

VTK noob here!

I facing a few problems while rendering vtkimagedata. The code snippet as
follows,


 int X =4, Y=4, Z=4;

       imageData->SetDimensions(X,Y,Z);

       imageData->SetSpacing(1,1,1);

       imageData->AllocateScalars(VTK_INT,1);



 for (int k = 0; k < Z ; k++)

       {

           for (int j = 0; j < Y ; j++)

           {

               for (int i = 0; i < X ; i++)

               {

                   int* voxel =
static_cast<int*>(imageData->GetScalarPointer(i, j, k));

                      voxel[0] = 10;


               }

           }

       }


 for (int i=2;i!=-1;i--)

       {

       int* voxel = static_cast<int*>(imageData->GetScalarPointer(2,i,i));

        voxel[0]=0;

        }


    mapper->SetBlendModeToComposite();

     mapper->SetRequestedRenderModeToRayCast();

      mapper->SetInputData(imageData);

     compositeOpacity->AddPoint(10,1);

      color->AddRGBPoint(10,1,0,0);

     compositeOpacity->AddPoint(0,0);

       color->AddRGBPoint(0,0,0, 0);

       volumeProperty->SetAmbient(0.3);

        volumeProperty->SetDiffuse(0.4);

        volumeProperty->SetSpecular(0.8);

       volumeProperty->SetInterpolationType(0);

        volumeProperty->ShadeOn();

        volumeProperty->SetColor(color);

         volumeProperty->SetScalarOpacity(compositeOpacity);

          renderer->SetBackground(0.5, 0.5, 0.5);

        volume->SetMapper(mapper);

        volume->SetProperty(volumeProperty);

        renderer->AddViewProp(volume);

I am getting the below results,


[image: image for forum.jpg]  [image: image for forum2.jpg]
[image: image for forum3.jpg]


It can be seen that everytime I rotate my image I don't get a proper
shading and color for the object. I have tried changing the lightining
properties and shading properties but no sucess.

I would be really thankful if anyone could help me.


Just for your information I am mechanical engineering with a bit of
programming knowledge, so if my question is irrattional please forgive
me.




Best,

Shadab
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181205/bc1d4ae3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image for forum.jpg
Type: image/jpeg
Size: 18410 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181205/bc1d4ae3/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image for forum2.jpg
Type: image/jpeg
Size: 22226 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181205/bc1d4ae3/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image for forum3.jpg
Type: image/jpeg
Size: 22181 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181205/bc1d4ae3/attachment-0002.jpg>


More information about the vtkusers mailing list