Problem with color and shading when rendering vtkimagedata

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with color and shading when rendering vtkimagedata

shadzzz90
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 for forum.jpg image for forum2.jpg
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












_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Problem with color and shading when rendering vtkimagedata

shadzzz90
Guys,
Waiting for reply!

Please help!




On Wed, Dec 5, 2018 at 2:08 PM shadab anwar <[hidden email]> wrote:
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,





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












_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Problem with color and shading when rendering vtkimagedata

David E DeMarle via vtkusers
Can you be more specific? How do the images differ from what you expect? Is there are particular VTK example you are following that you are trying to change?

Aron

On Wed, Dec 12, 2018 at 1:40 PM shadab anwar <[hidden email]> wrote:
Guys,
Waiting for reply!

Please help!




On Wed, Dec 5, 2018 at 2:08 PM shadab anwar <[hidden email]> wrote:
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 for forum.jpg image for forum2.jpg
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











_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Problem with color and shading when rendering vtkimagedata

shadzzz90
Hi Aron,
Thanks for your reply.
I am not using any specific example.

I am trying to render voxels using imagedata, I have used the above code for doing so.
The problem I am facing is that whenever I rotate the image after rendering I don't get proper shading and uniform coloring. Instead, I am getting above rendering results, where you can see the few voxels are shaded as black!
I am not able to understand where I am going wrong. I tried changing few shading and lighting parameters but no success.

I am a newbie, apology If my problem is too basic!


On Wed, Dec 12, 2018 at 4:06 PM Aron Helser <[hidden email]> wrote:
Can you be more specific? How do the images differ from what you expect? Is there are particular VTK example you are following that you are trying to change?

Aron

On Wed, Dec 12, 2018 at 1:40 PM shadab anwar <[hidden email]> wrote:
Guys,
Waiting for reply!

Please help!




On Wed, Dec 5, 2018 at 2:08 PM shadab anwar <[hidden email]> wrote:
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 for forum.jpg image for forum2.jpg
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











_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Problem with color and shading when rendering vtkimagedata

David E DeMarle via vtkusers
I have no experience with volume rendering in vtk, so my best suggestion is to look at some of the examples:
and see how the parameters are set there, compared to your code.
You might have success modifying one of the examples to use your data.

On Wed, Dec 12, 2018 at 4:15 PM shadab anwar <[hidden email]> wrote:
Hi Aron,
Thanks for your reply.
I am not using any specific example.

I am trying to render voxels using imagedata, I have used the above code for doing so.
The problem I am facing is that whenever I rotate the image after rendering I don't get proper shading and uniform coloring. Instead, I am getting above rendering results, where you can see the few voxels are shaded as black!
I am not able to understand where I am going wrong. I tried changing few shading and lighting parameters but no success.

I am a newbie, apology If my problem is too basic!


On Wed, Dec 12, 2018 at 4:06 PM Aron Helser <[hidden email]> wrote:
Can you be more specific? How do the images differ from what you expect? Is there are particular VTK example you are following that you are trying to change?

Aron

On Wed, Dec 12, 2018 at 1:40 PM shadab anwar <[hidden email]> wrote:
Guys,
Waiting for reply!

Please help!




On Wed, Dec 5, 2018 at 2:08 PM shadab anwar <[hidden email]> wrote:
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 for forum.jpg image for forum2.jpg
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











_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Problem with color and shading when rendering vtkimagedata

shadzzz90
Aron,
Thanks! I have been through these examples.
I'll be happy if you can suggest my question to someone who has an experience in volume rendering.

Thanks,
Shadab 

On Wed, Dec 12, 2018 at 5:51 PM Aron Helser <[hidden email]> wrote:
I have no experience with volume rendering in vtk, so my best suggestion is to look at some of the examples:
and see how the parameters are set there, compared to your code.
You might have success modifying one of the examples to use your data.

On Wed, Dec 12, 2018 at 4:15 PM shadab anwar <[hidden email]> wrote:
Hi Aron,
Thanks for your reply.
I am not using any specific example.

I am trying to render voxels using imagedata, I have used the above code for doing so.
The problem I am facing is that whenever I rotate the image after rendering I don't get proper shading and uniform coloring. Instead, I am getting above rendering results, where you can see the few voxels are shaded as black!
I am not able to understand where I am going wrong. I tried changing few shading and lighting parameters but no success.

I am a newbie, apology If my problem is too basic!


On Wed, Dec 12, 2018 at 4:06 PM Aron Helser <[hidden email]> wrote:
Can you be more specific? How do the images differ from what you expect? Is there are particular VTK example you are following that you are trying to change?

Aron

On Wed, Dec 12, 2018 at 1:40 PM shadab anwar <[hidden email]> wrote:
Guys,
Waiting for reply!

Please help!




On Wed, Dec 5, 2018 at 2:08 PM shadab anwar <[hidden email]> wrote:
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 for forum.jpg image for forum2.jpg
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











_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/vtkusers