[vtkusers] VTK+GTKMM+VTKMM+Glade
Jihan Zoghbi
jihan at uol.com.br
Wed Sep 10 15:23:58 EDT 2008
Hi people,
I'm trying to build an application to read DICOM and Analyse images. First, I made the interface using glade and I had no problem with that. I exported it to C++ code. After that, I eddited the code to read DICOM images. I want to display the image on a vtk renderer window and for that I used vtkmm. The problem is that the program reads the image but it doesn' t display it (render it... actually I don't know exactlly what's going on!). Here is the main C++ source code:
#include <gtkmm/stock.h>
#include <gtkmm/filechooserdialog.h>
#include <vtkPolyDataMapper.h>
#include <vtkCubeSource.h>
#include <vtkSphereSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkVolume16Reader.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkOutlineFilter.h>
#include <vtkCamera.h>
#include <vtkStripper.h>
#include <vtkLookupTable.h>
#include <vtkImageDataGeometryFilter.h>
#include <vtkProperty.h>
#include <vtkPolyDataNormals.h>
#include <vtkContourFilter.h>
#include <vtkImageData.h>
#include <vtkImageMapToColors.h>
#include <vtkImageActor.h>
#include <vtkDICOMImageReader.h>
#include <vtkImageGaussianSmooth.h>
#include "vtkmm.h"
#include "config.h"
#include "window1.hh"
window1::window1() : window1_glade()
{
this->signal_check_resize().
connect(sigc::mem_fun(*this, &window1::checkResize));
// Creates a widget for VTK rendering
renArea = new class Gtk::Vtk::RenderingArea();
renderer = renArea->get_vtk_renderer();
renderer->SetBackground(0,0,0);
renArea2 = new class Gtk::Vtk::RenderingArea();
renderer2 = renArea2->get_vtk_renderer();
renderer2->SetBackground(0,0,0);
renArea3 = new class Gtk::Vtk::RenderingArea();
renderer3 = renArea3->get_vtk_renderer();
renderer3->SetBackground(0,0,0);
// Reserves 200 pixels for the VTK widget
hpaned1->set_position(800);
fixed1->set_size_request(400,(this->get_height())/2);
fixed2->set_size_request(400,(this->get_height())/2);
fixed3->set_size_request(400,(this->get_height())/2);
// Adds the VTK widget to its reserved area
fixed1->add(*renArea);
fixed2->add(*renArea2);
fixed3->add(*renArea3);
renArea->show();
renArea2->show();
renArea3->show();
this->maximize();
}
void window1::on_dicom1_activate()
{
Gtk::FileChooserDialog dialog("Please choose a file",Gtk::FILE_CHOOSER_ACTION_OPEN);
dialog.set_transient_for(*this);
//Add response buttons the the dialog:
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
//Add filters, so that only certain file types can be selected:
Gtk::FileFilter filter_dicom;
filter_dicom.set_name("DICOM images");
filter_dicom.add_pattern("*");
dialog.add_filter(filter_dicom);
int result = dialog.run();
//Handle the response:
switch(result)
{
case(Gtk::RESPONSE_OK):
{
std::cout << "Open clicked." << std::endl;
//Notice that this is a std::string, not a Glib::ustring.
std::string strFolderPath = "/home/talita/Projetos/projeto3/src/Fatias";//dialog.get_filename();//
std::cout << "File selected: " << strFolderPath << std::endl;
renderer = renArea->get_vtk_renderer();
renderer->RemoveAllViewProps();
vtkDICOMImageReader *dicom = vtkDICOMImageReader::New();//
dicom->SetDirectoryName (strFolderPath.c_str());//letitura das imagens atraves do string digitado
dicom->Update();// ler
vtkImageGaussianSmooth *GaussianSmooth = vtkImageGaussianSmooth::New();
GaussianSmooth->SetInputConnection(dicom->GetOutputPort());
GaussianSmooth->Update();
vtkContourFilter *skinExtractor = vtkContourFilter::New();
skinExtractor->SetInputConnection( GaussianSmooth->GetOutputPort());
skinExtractor->SetValue(0, 50);
vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
skinNormals->SetInputConnection(skinExtractor->GetOutputPort());
skinNormals->SetFeatureAngle(60.0);
vtkStripper *skinStripper = vtkStripper::New();
skinStripper->SetInputConnection(skinNormals->GetOutputPort());
vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
skinMapper->SetInputConnection(skinStripper->GetOutputPort());
skinMapper->ScalarVisibilityOff();
vtkActor *skin = vtkActor::New();
skin->SetMapper(skinMapper);
skin->GetProperty()->SetDiffuseColor(1, .49, .25);
skin->GetProperty()->SetSpecular(.3);
skin->GetProperty()->SetSpecularPower(20);
vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
outlineData->SetInputConnection(dicom->GetOutputPort());
vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
mapOutline->SetInputConnection(outlineData->GetOutputPort());
vtkActor *outline = vtkActor::New();
outline->SetMapper(mapOutline);
outline->GetProperty()->SetColor(1,0,0);
renderer->AddActor(outline);
// THE PROGRAM STOPS HERE AND DOES'T DISPLAY THE IMAGE
renderer->AddActor(skin);
renderer->GetActiveCamera()->SetPosition(0.0, 0.0, -4.0);
renderer->GetActiveCamera()->SetViewUp(0.0, 0.0, 0.0);
renderer->GetActiveCamera()->SetFocalPoint(0.0, 0.0, 0.0);
renderer->GetActiveCamera()->SetClippingRange(1.0, 4.0);
renderer->GetActiveCamera()->ComputeViewPlaneNormal();
renArea->get_vtk_window()->Render();
break;
}
case(Gtk::RESPONSE_CANCEL):
{
std::cout << "Cancel clicked." << std::endl;
break;
}
default:
{
std::cout << "Unexpected button clicked." << std::endl;
break;
}
}
}
void window1::checkResize()
{
renArea->set_size_request(fixed1->get_width(), (this->get_height())/2);
renArea2->set_size_request(fixed2->get_width(), (this->get_height())/2);
renArea3->set_size_request(fixed3->get_width(), (this->get_height())/2);
}
I would aprecciate some help.
Thank you in advance,
Jihan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080910/3aea1db1/attachment.htm>
More information about the vtkusers
mailing list