[vtkusers] Problem getting vtkActor2D and vtkActor to render simultaneously
Elvis Dowson
elvis.dowson at mac.com
Fri Oct 3 13:23:14 EDT 2008
Hi,
In the following code, I cannot get both vtkActor2D and
vtkActor to display simultaneously. If I enable 2D map source and text
source, it displays the map and the text. If I enable the 3D cylinder
source, the 3D cylinder doesnt get displayed. However, if I disable
the 2D map source, the cylinder and the text message appears.
How can I get the 2D map to display below, and the 3D cylinder to
appear to hover above the 2D map ?
Am I mixing things here? Should I be using vtkImageActor instead of
vtkActor2D, so that there is a 3D image plane and then display the 3D
source? I really dont want to do that at the moment.
Please help! :-)
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/474aedb2/attachment.htm>
More information about the vtkusers
mailing list