[vtkusers] QVTKWidget HelloWorld example?
Carlos Capdepon
carlos.capdepon at gmail.com
Fri Apr 7 19:28:45 EDT 2006
>
> QVTKWidget HelloWorld example code:
>
> CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
# Project customization.
SET(PROJECT_NAME "VTK_QT_HW")
SET(EXECUTABLE_NAME "vtkQtHelloWorld")
SET(${PROJECT_NAME}_SOURCES vtkQtHello.cxx)
# Project's name.
PROJECT(${PROJECT_NAME})
# Find Visualization Toolkit 5.x
FIND_PACKAGE(VTK REQUIRED)
IF(VTK_FOUND)
INCLUDE(${VTK_USE_FILE})
MESSAGE(STATUS "Visualization Toolkit found.")
ELSE(VTK_FOUND)
MESSAGE(FATAL_ERROR "Cannot build ${PROJECT_NAME} without VTK. Please set
VTK_DIR.")
ENDIF(VTK_FOUND)
MARK_AS_ADVANCED(VTK_DIR)
# Find Qt 4.x
FIND_PACKAGE(QT4 REQUIRED)
IF(QT_FOUND)
INCLUDE(${QT_USE_FILE})
MESSAGE(STATUS "Qt4 found.")
ELSE(QT_FOUND)
MESSAGE(FATAL_ERROR "Cannot build ${PROJECT_NAME} without Qt4.")
ENDIF(QT_FOUND)
MARK_AS_ADVANCED(QT_QMAKE_EXECUTABLE)
# Disable deprecated function warning = #pragma warning(disable : 4996)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
# Executable's name and sources.
ADD_EXECUTABLE(${EXECUTABLE_NAME} ${${PROJECT_NAME}_SOURCES})
# Link the executable to the vtkRendering library.
SET(VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${QT_LIBRARIES} ${VTK_LIBRARIES})
> vtkQtHello.cxx
// QVTKWidget Hello World!
#include <QApplication>
#include <QMainWindow>
#include <QVTKWidget.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkTextSource.h>
#include <vtkVectorText.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
int main( int argc, char **argv )
{
QApplication app(argc,argv);
QMainWindow *mainWindow = new QMainWindow;
mainWindow->setFixedSize(640,360);
QVTKWidget *widget = new QVTKWidget;
mainWindow->setCentralWidget(widget);
vtkTextSource *text = vtkTextSource::New();
text->SetText("Hello World!");
text->BackingOff();
vtkVectorText *vectorText = vtkVectorText::New();
vectorText->SetText("QVTKWidget");
vtkPolyDataMapper *textMapper = vtkPolyDataMapper::New();
textMapper->SetInput(text->GetOutput());
vtkPolyDataMapper *vectorTextMapper = vtkPolyDataMapper::New();
vectorTextMapper->SetInput(vectorText->GetOutput());
vtkActor *textActor = vtkActor::New();
textActor->SetMapper(textMapper);
vtkActor *vectorTextActor = vtkActor::New();
vectorTextActor->SetMapper(vectorTextMapper);
vtkRenderer *renderer = vtkRenderer::New();
renderer->SetBackground(0.4,0.6,0.8);
renderer->AddActor(textActor);
renderer->AddActor(vectorTextActor);
vtkRenderWindow *renderWindow = vtkRenderWindow::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetStereoTypeToDresden();
widget->SetRenderWindow(renderWindow);
mainWindow->show();
app.aboutQt();
return app.exec();
}
> Any answer about QVTKWidgetPlugin linking errors? :-(
--
Un saludo,
"Carlos Capdepón" <carlos.capdepon at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060408/6e9d97d8/attachment.htm>
More information about the vtkusers
mailing list