[vtkusers] exporting a scalar bar in VRML format

Rebecca Savage Rebecca.Savage at sea.co.uk
Wed Sep 18 11:25:48 EDT 2002


Apologies if this is obvious.

I am using vtkVRMLExporter to export my data to a VRML file, which works fine (picture, axes etc.),  with the exception of the scalar bar.
The rendering window has a renderer, which has various actors added to it, including the scalar bar one. How can I make the scalar bar appear in my VRML file?
I have attached some of the relevant C++ functions below.

Thanks in advance,

Rebecca Savage


Senior Systems Engineer 
Systems Engineering & Assessment Ltd 



(some) class members:
vtkRenderer* m_pRen;
vtkRenderWindow* m_pRenWin;
vtkScalarBarActor* m_pScalarBar;
vtkDataSetMapper* m_pMapper;


//---------------------------------------------------------------------------------
// WriteOutputToVrmlFile
//---------------------------------------------------------------------------------
void ANColourMap::WriteOutputToVrmlFile(string fileName)
{
	vtkVRMLExporter* exporter = vtkVRMLExporter::New();
	exporter->SetRenderWindow(m_pRenWin);
	exporter->SetFileName(fileName.c_str());
	exporter->Write();

	// clear up
	exporter->Delete();
}

//---------------------------------------------------------------------------------
// AddScalarBar
//---------------------------------------------------------------------------------
void ANColourMap::AddScalarBar(string units)
{
	m_pScalarBar = vtkScalarBarActor::New();
	m_pScalarBar->SetLookupTable(m_pMapper->GetLookupTable());
	m_pScalarBar->SetTitle(units.c_str());
	m_pRen->AddActor(m_pScalarBar);
}

//---------------------------------------------------------------------------------
// CreateRenderobjects
//---------------------------------------------------------------------------------
void ANColourMap::CreateRenderObjects(void* handle)
{
	// create the actor
	m_pActor = vtkActor::New();
    m_pActor->SetMapper(m_pMapper);

	// create the renderer and the render window
	m_pRen = vtkRenderer::New();
	m_pRen->AddActor(m_pActor);
	m_pRen->SetBackground( 0.8, 0.8, 0.8 );


	// add the scalar bar
	if (m_bScalarBar)
		AddScalarBar(m_units);

	m_pRenWin = vtkRenderWindow::New();
    m_pRenWin->AddRenderer(m_pRen);
	m_pRenWin->SetParentId(handle);
	m_pRenWin->SetSize(m_xSize, m_ySize);
	m_pRenWin->SetPosition(m_xPosition, m_yPosition);

	// create the render window interactor
	m_pIRenWin = vtkRenderWindowInteractor::New();
    m_pIRenWin->SetRenderWindow(m_pRenWin);

	// add the axes
	if (m_bAxes && m_xGridPositions.size() > 0 && m_yGridPositions.size() > 0)
		AddAxes();

	// draw the resulting scene
	m_pRenWin->Render();
}






More information about the vtkusers mailing list