[Insight-users] Qt itk filter
platon galatis
pgalatis at hotmail.com
Sat Dec 9 13:08:20 EST 2006
Hello Matthias,I have never used the QtSlotAdaptor but there is another simple way to do what u want.You can use Qts signal-slot mechanism.You need to create a class with the Q_OBJECT macro ,in a slot of this class put the itk functionality, create a QPushButton and an object of that class and connect the buttons signal clicked() to that slot.#ifnded myclass_h#define myclass_h#include "itkMedianImageFilter.h"#include "qstring.h"#include "itkImage.h"#include "qfiledialog.h"class myclass{Q_OBJECTtypedef itk::Image<short int ,2>InputImageType;typedef itk::Image<short int ,2>OutputImageType;public: public slots: void myslot() { typedef itk::ImageFileReader<InputImageType> readertype; readertype::Pointer reader=readertype::New(); typedef itk::ImageFileWriter<OutputImageType> writertype; writertype::Pointer writer=writertype::New(); typedef itk::MedianImageFilter <InputImageType, OutputImageType>FilterType; FilterType::Pointer filter=FilterType::New() QString filename; filename=QFileDialog::getOpenFileName(); reader->SetFileName(filename.latin1()); filename=QFileDialog::getSaveFileName(); writer->SetFileName(filename.latin1()); filter->SetInput(reader->GetOutput()); writer->SetInput(filter->GetOutput()); filter->Update(); }};#endifand in ur main.ccp file: (i use qt 3.2.1 , it would be a little different in Qt 4 )#include <qapplication.h>#include "myclass.h"#include <qpushbutton.h>int main( int argc, char **argv ){QApplication a( argc, argv );QPushButton button;a.setMainWidget(&button); myclass median;connect(button,SIGNAL(clicked()),median,SLOT(myslot()));button.show();return a.exec();}Note that all objects created with New() will be deleted at the end of myslot(). If u dont want that u should declare a smart pointer in the header file:typedef itk::ImageFileReader<InputImageType> readertype;readertype::Pointer reader=NULL;and initialize it inside myslot()readertype::New();Also note that since myclass is now a Q_OBJECT it needs moc and in your CMakeLists.txt you should addSET(myProject_MOC_SRCS myclass.h )Hope the above works havent tried it.Plato.> Date: Sat, 9 Dec 2006 14:35:28 +0100> From: mebert at uni-koblenz.de> To: insight-users at itk.org> Subject: [Insight-users] Qt itk filter> > Hi everyone,> > i am new to this mailing list, so first of all: hello :)> > i try to get a simple qt-itk example to work, but i got some problems> launching my filter using a qt button.> i dont know if its the right way i try to do this:> > 1.) i create a median filter (according to the example in> ItkSoftwareGuide):> > typedef itk::MedianImageFilter <InputImageType, OutputImageType>> FilterType;> FilterType::Pointer filter = FilterType::New();> > 2.) i create a simple qt-button:> > QPushButton medianFilterButton("Median Filter", &mainWidget);> medianFilterButton.setGeometry(horizontalPosition, 20, buttonWidth,> buttonHeight);> > 3.) i use the qt-itk-adaptor (guess this is wrong):> > typedef itk::QtSlotAdaptor<FilterType> SlotAdaptorType;> SlotAdaptorType slotAdaptor;> slotAdaptor.SetCallbackFunction(filter, & FilterType::Update);> QObject::connect(&medianFilterButton, SIGNAL(clicked()), &slotAdaptor,> SLOT(Slot()));> > so here are my questions:> > how do i launch my median filter using a qt-button? i need to set the> input for the filter and the writer doing something like this:> > filter->SetInput(reader->GetOutput());> writer->SetInput(filter->GetOutput());> > but thats not the way i want to do it. i just want this to happen after> pushing the button.> can anyone explain me how i figure out which filter has which slots? i> am a bit confused about this ...> > if u need more code to understand what i mean, please let me know!> > thanks for help,> > Matthias> _______________________________________________> Insight-users mailing list> Insight-users at itk.org> http://www.itk.org/mailman/listinfo/insight-users
_________________________________________________________________
Call friends with PC-to-PC calling -- FREE
http://get.live.com/messenger/overview
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20061209/53315cfd/attachment.htm
More information about the Insight-users
mailing list