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

terminator vjblog_info at yahoo.com
Thu Jun 14 06:50:40 EDT 2018


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


More information about the vtkusers mailing list