[vtkusers] How to scroll and zoom into an image rendered using vtkActor2D

Elvis Dowson elvis.dowson at mac.com
Fri Oct 3 13:11:15 EDT 2008


Hi,
        How can I perform a scroll (horizontal & vertical) and zoom  
into an image rendered using vtkActor2D ?

Best regards,

Elvis Dowson


#include "qapplication.h"
#include <QtGui>

#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkImageActor.h>
#include <vtkTextActor.h>
#include <vtkJPEGReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageMapper.h>
#include <vtkPolyDataMapper.h>
#include <vtkCylinderSource.h>


#if QT_VERSION >= 0x040000
# include "ui_GUI4.h"
#endif

#define PROTOTYPE_2D_MAP_SOURCE
#define PROTOTYPE_2D_TEXT_SOURCE
//#define PROTOTYPE_3D_CYLINDER_SOURCE

int main(int argc, char** argv)
{
   QApplication app(argc, argv);
	
#if QT_VERSION >= 0x040000
	Ui::Dialog ui;
	QDialog dialog;
#endif
	
	ui.setupUi(&dialog);
	dialog.setAttribute(Qt::WA_QuitOnClose);
	
	// Qt vtk integration
	vtkRenderer* ren = NULL;
	ren = vtkRenderer::New();
		ui.qvtkWidget->GetRenderWindow()->AddRenderer(ren);
	
	// Prototype: 2D Map Source
	// ----------------------------
	#ifdef PROTOTYPE_2D_MAP_SOURCE
  	{
	// Declare object instance variables
	vtkJPEGReader* imageReader	= NULL;
	vtkImageMapper* imageMapper = NULL;
	vtkActor2D* mapActor		= NULL;			
			
	// Read 2D image file
	imageReader = vtkJPEGReader::New();
		imageReader->SetFileName("/Users/elvis/Image/sample.jpg");
		imageReader->Update();
	
	// Map 2D image file
	imageMapper = vtkImageMapper::New();
		imageMapper->SetInput(imageReader->GetOutput());
		imageMapper->SetColorWindow(255);
		imageMapper->SetColorLevel(127.5);
		
	// Actor in scene
	mapActor = vtkActor2D::New();
		mapActor->SetMapper(imageMapper);	

	// Actor in scene
	mapActor = vtkActor2D::New();
		//mapActor->SetLayerNumber(0);
		mapActor->SetMapper(imageMapper);			

	// Add Actor to renderer
	ren->AddActor2D(mapActor);
	}
	#endif

	// Prototype: 2D Text Source
	// -----------------------------
	#ifdef PROTOTYPE_2D_TEXT_SOURCE
	{
		// Declare object instance variables
		vtkTextActor* textActor;
		
		// Initialize objects
		textActor = NULL;
		
		// Actor in scene
		textActor = vtkTextActor::New();
		textActor->SetTextScaleMode(vtkTextActor::TEXT_SCALE_MODE_NONE);
		textActor->SetInput("This is a text message!");
		
		// Add Actor to renderer
		ren->AddActor2D(textActor);
	}
	#endif
	

	// Prototype: 3D Cyclinder Source
	// ----------------------------------
	#ifdef PROTOTYPE_3D_CYLINDER_SOURCE	
	{
	// Declare object instance variables
	vtkCylinderSource* source;
	vtkPolyDataMapper* mapper;
	vtkActor* actor;

	// Initialize objects
	source = NULL;
	mapper = NULL;
	actor = NULL;
	
	// Geometry
	source = vtkCylinderSource::New();
	
	// Mapper
	mapper = vtkPolyDataMapper::New();
	mapper->ImmediateModeRenderingOn();
	mapper->SetInputConnection(source->GetOutputPort());
	
	// Actor in scene
	actor = vtkActor::New();
	actor->SetMapper(mapper);
	
	// Add Actor to renderer
	ren->AddActor(actor);
	}
	#endif
	
	// Reset camera
	ren->ResetCamera();
	
	// Render the scene
	ren->GetRenderWindow()->Render();
	
	// Display the dialog window
	dialog.show();

   return app.exec();
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081003/4c53ffa0/attachment.htm>


More information about the vtkusers mailing list