[vtkusers] vtkChartHistogram2D use case

BBerco bebe0705 at colorado.edu
Wed May 30 17:38:24 EDT 2018


I am trying to use an instance of vtkChartHistogram2D to visualize a
vtkImageData. I think it is a possibility in VTK given the partial example
on page 48 of this document
<https://pdfs.semanticscholar.org/presentation/a2bd/c9861a548bb1e8807a1d39b43e526a7c4564.pdf> 
. 

Unfortunately, the above example is incomplete, and replicating it has been
unsuccessful. Below is what I have so far: a QVTKOpenGLWidget sharing a
vtkGenericOpenGLRenderWindow with a vtkContextView. 

Any advice?

*
vtkSmartPointer<vtkGenericOpenGLRenderWindow> render_window =
vtkSmartPointer< vtkGenericOpenGLRenderWindow>::New();
	
	this -> view = vtkSmartPointer<vtkContextView>::New ();
	this -> view -> SetRenderWindow(render_window);
	this -> qvtkWidget = new QVTKOpenGLWidget(this);
	this -> qvtkWidget -> SetRenderWindow(render_window);

// Normalizing the image
	vtkDataArray * scalars = this -> images[0] -> GetPointData() ->
GetScalars();
	double max_val = -1;
	for (vtkIdType tupleIdx = 0; tupleIdx < scalars -> GetNumberOfTuples();
++tupleIdx){
		max_val = std::max(scalars -> GetTuple1(tupleIdx),max_val);
	}



	vtkSmartPointer<vtkChartHistogram2D> histo =
vtkSmartPointer<vtkChartHistogram2D>::New();
	vtkSmartPointer<vtkColorTransferFunction> fun =
vtkSmartPointer<vtkColorTransferFunction>::New();

	fun -> AddRGBPoint(0,    0.0, 0.0, 0.0);
        fun -> AddRGBPoint(max_value,  1.0, 1, 1);
	fun -> Build();

	histo -> SetInputData(this -> images[0]);
	histo -> SetTransferFunction(fun);

	vtkSmartPointer<vtkStringArray> label =
vtkSmartPointer<vtkStringArray>::New();
	label -> InsertNextValue("Range (m)");
	label -> InsertNextValue("Range-rate (m/s)");
	histo -> GetPlot(0) -> SetLabels(label);
	histo -> Update();

// CRASHES HERE

*


















--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list