[vtkusers] volume mapper error
Franks
masterwangzx at gmail.com
Tue Nov 13 20:09:50 EST 2018
Hi,
I want to test the volume mapper. I read the data from .vtk file and change
its points attributes(vtkUnsignedCharArray with one component) to the
vtkFloatArray with two components. Then I volume render it. But I get the
"Segmentation fault".
auto reader = vtkSmartPointer<vtkStructuredPointsReader>::New();
reader->SetFileName("../mummy.128.vtk");
reader->Update();
auto tuples = vtkSmartPointer<vtkFloatArray>::New();
tuples->DeepCopy(reader->GetOutput()->GetPointData()->GetScalars());
tuples->SetNumberOfComponents(2);
for (int i = 0; i < tuples->GetNumberOfTuples(); ++i) {
tuples->SetTuple2(i,80,80);
}
reader->GetOutput()->GetPointData()->RemoveArray(0);
reader->GetOutput()->GetPointData()->SetScalars(tuples);
auto volumeMapper = vtkSmartPointer<vtkSmartVolumeMapper>::New();
volumeMapper->SetInputConnection(reader->GetOutputPort());
auto volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();
auto compositeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New();
compositeOpacity->AddPoint(40, 0.00);
compositeOpacity->AddPoint(60, 0.40);
volumeProperty->SetScalarOpacity(compositeOpacity);
auto color = vtkSmartPointer<vtkColorTransferFunction>::New();
color->AddRGBPoint(0.000, 0.00, 0.00, 0.00);
color->AddRGBPoint(64.00, 1.00, 0.52, 0.30);
volumeProperty->SetColor(color);
auto volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
auto ren = vtkSmartPointer<vtkRenderer>::New();
ren->AddVolume(volume);
ren->SetBackground(1, 1, 1);
auto renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren);
auto style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
auto iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
Best regards
Frank
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list