reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

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

reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

terminator via vtkusers
Hi everyone,
Although subject is clear enough, but I want to know what's the reasons of
these limitations?
I found out that vtk supports up to 4 components in label map volume
rendering (with mask). I can set colors for each component, but just first
opacity (index=0) will applied and others will be ignored. Is there
technical issue for controlling each component opacity separately?
My last question, why number of components is restricted to four? seems the
overhead of a few transfer functions is not too much.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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: reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

Sankhesh Jhaveri-2

Hi,

In short, VTK’s support for label map masks is limited.

I’m not sure what you mean by opacity. If you see the documentation for vtkGPUVolumeRayCastMapper::SetMaskInput, it explains how the final sample color is determined.

As to why it works the way it does, I’ll defer to the authors but more likely, this was all that was required from the mapper at the time it was written.

The mapper might actually work(I’ve not tested this, but should, in general) with N number of components given that vtkProperty::IndependentComponents is set. The limitation of a maximum of 4 components is when they are treated as dependent.

Hope this helps.

Thanks,
Sankhesh


On Sun, Jun 10, 2018 at 9:10 PM terminator via vtkusers <[hidden email]> wrote:
Hi everyone,
Although subject is clear enough, but I want to know what's the reasons of
these limitations?
I found out that vtk supports up to 4 components in label map volume
rendering (with mask). I can set colors for each component, but just first
opacity (index=0) will applied and others will be ignored. Is there
technical issue for controlling each component opacity separately?
My last question, why number of components is restricted to four? seems the
overhead of a few transfer functions is not too much.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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
--
Sankhesh Jhaveri
Sr. Research & Development Engineer | Kitware | (518) 881-4417

_______________________________________________
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: reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

terminator via vtkusers
Thank you,
I read that link (about SetMaskInput) and I have no problem with controlling
components color.
But about opacity, I mean that I want to control opacity of each component
separately just like components' colors by different PieseWiseFunctions.
I use
SetScalarOpacity(0,...),SetScalarOpacity(1,...),SetScalarOpacity(2,...),...
but just first one affects on the volume. I cannot hide component 0,make
component 1 semi-transparent  and component 2 opaque.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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: reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

Sankhesh Jhaveri-2

Hi,

Just so I understand properly, you cannot get the scalar opacity piecewise functions to work for components 1 through N, right?
Could you please share sample code that reproduces the issue?

Thanks,
Sankhesh


On Tue, Jun 12, 2018 at 11:22 PM terminator via vtkusers <[hidden email]> wrote:
Thank you,
I read that link (about SetMaskInput) and I have no problem with controlling
components color.
But about opacity, I mean that I want to control opacity of each component
separately just like components' colors by different PieseWiseFunctions.
I use
SetScalarOpacity(0,...),SetScalarOpacity(1,...),SetScalarOpacity(2,...),...
but just first one affects on the volume. I cannot hide component 0,make
component 1 semi-transparent  and component 2 opaque.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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
--
Sankhesh Jhaveri
Sr. Research & Development Engineer | Kitware | (518) 881-4417

_______________________________________________
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: reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

terminator via vtkusers
Of curse,
It's the output:
<http://vtk.1045678.n5.nabble.com/file/t342452/output-vtk.jpg>

And this is the code:

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkTIFFReader.h>
#include <vtk_tiff.h>
#include <vtkVolume.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkOpenGLGPUVolumeRayCastMapper.h>
#include <vtkImageData.h>
#include <vtkVolumeProperty.h>
#include <vtkPiecewiseFunction.h>
#include <vtkColorTransferFunction.h>
#include <vtkStringArray.h>
#include <vtkStdString.h>
#include <string>

#define PIC_STEP 5
int main(int, char *[])
{
        int start = 3785, end = 4285;
        std::string ctPath = "..\\CTDATA\\";
        std::string maskPath = "..\\labelmap\\";
        vtkSmartPointer<vtkTIFFReader> ctReader =
vtkSmartPointer<vtkTIFFReader>::New();
        vtkSmartPointer<vtkTIFFReader> maskReader =
vtkSmartPointer<vtkTIFFReader>::New();
        vtkImageData * ctImages;
        vtkImageData * maskImages;
        vtkVolume * volume;
        vtkGPUVolumeRayCastMapper * vMap;
        vtkVolumeProperty * vProp;
        vtkPiecewiseFunction * tf[3];
        vtkColorTransferFunction * cf[3];
       

        int pic_num = start;
        ctReader->SetFileName((ctPath + std::to_string(pic_num) + ".tif").c_str());
        ctReader->Update();
        int * extents = ctReader->GetOutput()->GetExtent();


        vtkStdString * ctFileNames = new vtkStdString[(end - start) / PIC_STEP +
1];
        vtkStdString * maskFileNames = new vtkStdString[(end - start) / PIC_STEP +
1];
        int i = 0;
        for (int pic_num = start; pic_num <= end; pic_num += PIC_STEP) {
                ctFileNames[i] = ctPath + std::to_string(pic_num) + ".tif";
                maskFileNames[i] = maskPath + std::to_string(pic_num) + ".tif";
                i++;
        }
        vtkStringArray * ctFileNameArr = vtkStringArray::New();
        vtkStringArray * maskFileNameArr = vtkStringArray::New();
        ctFileNameArr->SetArray(ctFileNames, (end - start) / PIC_STEP + 1, 0);
        maskFileNameArr->SetArray(maskFileNames, (end - start) / PIC_STEP + 1, 0);
        std::cout << "Slices: " << (end - start) / PIC_STEP << std::endl;
        ctReader->SetDataExtent(extents[0], extents[1], extents[2], extents[3], 0,
((end - start) / PIC_STEP));
        ctReader->SetFileNames(ctFileNameArr);
        ctReader->Update();
        ctImages = ctReader->GetOutput();
        maskReader->SetDataExtent(extents[0], extents[1], extents[2], extents[3],
0, ((end - start) / PIC_STEP));
        maskReader->SetFileNames(maskFileNameArr);
        maskReader->SetOrientationType(ORIENTATION_LEFTBOT);
        maskReader->Update();
        maskImages = maskReader->GetOutput();
       
        //Opacity TF
        tf[0] = vtkPiecewiseFunction::New();
        tf[0]->AddPoint(20, 0);
        tf[0]->AddPoint(255, 0.2);
        tf[1] = vtkPiecewiseFunction::New();
        tf[1]->AddPoint(0, 1);
        tf[1]->AddPoint(255, 1);
        tf[2] = vtkPiecewiseFunction::New();
        tf[2]->AddPoint(0, 0);
        tf[2]->AddPoint(255, 0);
        //Color TF
        cf[0] = vtkColorTransferFunction::New();
        cf[0]->AddRGBPoint(0, 0, 0, 0);
        cf[0]->AddRGBPoint(255, 1, 1, 1);
        cf[1] = vtkColorTransferFunction::New();
        cf[1]->AddRGBPoint(0, 1, 0, 0);
        cf[1]->AddRGBPoint(255, 1, 0, 0);
        cf[2] = vtkColorTransferFunction::New();
        cf[2]->AddRGBPoint(0, 0, 0, 1);
        cf[2]->AddRGBPoint(255, 0, 0, 1);

        vProp = vtkVolumeProperty::New();
        vProp->IndependentComponentsOn();
        vProp->SetScalarOpacity(0, tf[0]);
        vProp->SetGradientOpacity(0, tf[0]);
        vProp->SetScalarOpacity(1, tf[1]);
        vProp->SetGradientOpacity(1, tf[1]);
        vProp->SetScalarOpacity(2, tf[2]);
        vProp->SetGradientOpacity(2, tf[2]);
        vProp->SetColor(0, cf[0]);
        vProp->SetColor(1, cf[1]);
        vProp->SetColor(2, cf[2]);


        vMap = vtkGPUVolumeRayCastMapper::New();
        vMap->SetInputData(ctImages);
        vMap->SetMaskTypeToLabelMap();
        vMap->SetMaskBlendFactor(0.8);
        vMap->SetMaskInput(maskImages);
       
        volume = vtkVolume::New();
        volume->SetMapper(vMap);
        volume->SetProperty(vProp);

        vtkRenderer * render = vtkRenderer::New();
        vtkRenderWindow * renderWin = vtkRenderWindow::New();
        vtkRenderWindowInteractor * irenWin = vtkRenderWindowInteractor::New();
        render->SetBackground(0, 0.5, 0.5);
        render->AddVolume(volume);
        renderWin->AddRenderer(render);
        irenWin->SetRenderWindow(renderWin);
        renderWin->Render();
        irenWin->Start();
        return EXIT_SUCCESS;
}



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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: reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

Sankhesh Jhaveri-2

Hi,

The code you shared seems fine to me.
I see the image you shared but could you please describe what we’re looking at and what we expect to see?

It would help to identify the issue by removing all additional logic and minimizing the test case.
Do you see the issue without the gradient opacity function and masking?

Thanks,
Sankhesh


On Thu, Jun 14, 2018 at 6:50 AM terminator via vtkusers <[hidden email]> wrote:
Of curse,
It's the output:
<http://vtk.1045678.n5.nabble.com/file/t342452/output-vtk.jpg>

And this is the code:

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkTIFFReader.h>
#include <vtk_tiff.h>
#include <vtkVolume.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkOpenGLGPUVolumeRayCastMapper.h>
#include <vtkImageData.h>
#include <vtkVolumeProperty.h>
#include <vtkPiecewiseFunction.h>
#include <vtkColorTransferFunction.h>
#include <vtkStringArray.h>
#include <vtkStdString.h>
#include <string>

#define PIC_STEP 5
int main(int, char *[])
{
        int start = 3785, end = 4285;
        std::string ctPath = "..\\CTDATA\\";
        std::string maskPath = "..\\labelmap\\";
        vtkSmartPointer<vtkTIFFReader> ctReader =
vtkSmartPointer<vtkTIFFReader>::New();
        vtkSmartPointer<vtkTIFFReader> maskReader =
vtkSmartPointer<vtkTIFFReader>::New();
        vtkImageData * ctImages;
        vtkImageData * maskImages;
        vtkVolume * volume;
        vtkGPUVolumeRayCastMapper * vMap;
        vtkVolumeProperty * vProp;
        vtkPiecewiseFunction * tf[3];
        vtkColorTransferFunction * cf[3];


        int pic_num = start;
        ctReader->SetFileName((ctPath + std::to_string(pic_num) + ".tif").c_str());
        ctReader->Update();
        int * extents = ctReader->GetOutput()->GetExtent();


        vtkStdString * ctFileNames = new vtkStdString[(end - start) / PIC_STEP +
1];
        vtkStdString * maskFileNames = new vtkStdString[(end - start) / PIC_STEP +
1];
        int i = 0;
        for (int pic_num = start; pic_num <= end; pic_num += PIC_STEP) {
                ctFileNames[i] = ctPath + std::to_string(pic_num) + ".tif";
                maskFileNames[i] = maskPath + std::to_string(pic_num) + ".tif";
                i++;
        }
        vtkStringArray * ctFileNameArr = vtkStringArray::New();
        vtkStringArray * maskFileNameArr = vtkStringArray::New();
        ctFileNameArr->SetArray(ctFileNames, (end - start) / PIC_STEP + 1, 0);
        maskFileNameArr->SetArray(maskFileNames, (end - start) / PIC_STEP + 1, 0);
        std::cout << "Slices: " << (end - start) / PIC_STEP << std::endl;
        ctReader->SetDataExtent(extents[0], extents[1], extents[2], extents[3], 0,
((end - start) / PIC_STEP));
        ctReader->SetFileNames(ctFileNameArr);
        ctReader->Update();
        ctImages = ctReader->GetOutput();
        maskReader->SetDataExtent(extents[0], extents[1], extents[2], extents[3],
0, ((end - start) / PIC_STEP));
        maskReader->SetFileNames(maskFileNameArr);
        maskReader->SetOrientationType(ORIENTATION_LEFTBOT);
        maskReader->Update();
        maskImages = maskReader->GetOutput();

        //Opacity TF
        tf[0] = vtkPiecewiseFunction::New();
        tf[0]->AddPoint(20, 0);
        tf[0]->AddPoint(255, 0.2);
        tf[1] = vtkPiecewiseFunction::New();
        tf[1]->AddPoint(0, 1);
        tf[1]->AddPoint(255, 1);
        tf[2] = vtkPiecewiseFunction::New();
        tf[2]->AddPoint(0, 0);
        tf[2]->AddPoint(255, 0);
        //Color TF
        cf[0] = vtkColorTransferFunction::New();
        cf[0]->AddRGBPoint(0, 0, 0, 0);
        cf[0]->AddRGBPoint(255, 1, 1, 1);
        cf[1] = vtkColorTransferFunction::New();
        cf[1]->AddRGBPoint(0, 1, 0, 0);
        cf[1]->AddRGBPoint(255, 1, 0, 0);
        cf[2] = vtkColorTransferFunction::New();
        cf[2]->AddRGBPoint(0, 0, 0, 1);
        cf[2]->AddRGBPoint(255, 0, 0, 1);

        vProp = vtkVolumeProperty::New();
        vProp->IndependentComponentsOn();
        vProp->SetScalarOpacity(0, tf[0]);
        vProp->SetGradientOpacity(0, tf[0]);
        vProp->SetScalarOpacity(1, tf[1]);
        vProp->SetGradientOpacity(1, tf[1]);
        vProp->SetScalarOpacity(2, tf[2]);
        vProp->SetGradientOpacity(2, tf[2]);
        vProp->SetColor(0, cf[0]);
        vProp->SetColor(1, cf[1]);
        vProp->SetColor(2, cf[2]);


        vMap = vtkGPUVolumeRayCastMapper::New();
        vMap->SetInputData(ctImages);
        vMap->SetMaskTypeToLabelMap();
        vMap->SetMaskBlendFactor(0.8);
        vMap->SetMaskInput(maskImages);

        volume = vtkVolume::New();
        volume->SetMapper(vMap);
        volume->SetProperty(vProp);

        vtkRenderer * render = vtkRenderer::New();
        vtkRenderWindow * renderWin = vtkRenderWindow::New();
        vtkRenderWindowInteractor * irenWin = vtkRenderWindowInteractor::New();
        render->SetBackground(0, 0.5, 0.5);
        render->AddVolume(volume);
        renderWin->AddRenderer(render);
        irenWin->SetRenderWindow(renderWin);
        renderWin->Render();
        irenWin->Start();
        return EXIT_SUCCESS;
}



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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
--
Sankhesh Jhaveri
Sr. Research & Development Engineer | Kitware | (518) 881-4417

_______________________________________________
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: reasons of limitations on opacity per component and up to 4 components in label-map volume rendering?

terminator via vtkusers
Hi,

In the image, component 1 is red, component 2 is blue and the rest of that
is component 0. As you can see the left image shows partially all of the
component while (scalar) opacity transfer function of component 2 is always
zero. But we see partially all of components with the transfer function of
component zero. Which I expected is component 2 must be invisible.
In the right image, (scalar) opacity of component 0 is zero for all input
values (intensity of ct image), but two other components (red and blue) must
be opaque and visible, but what we see is entirely invisible volume, which
means just opacity transfer function of component 0 is applied to the
volume. (each tf[i] under the images shows scalar opacity transfer function
for component i)


> Do you see the issue without the gradient opacity function and masking?

I forgot to remove gradient opacity, but it doesn't help. The problem still
exists.
Without masking I don't have any problem, but the point is I need masking
for visualizing and controlling several components in a volume.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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