Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

MainWindow Class Reference

creates the GUI with the help of the vtkandqt library More...

#include <ccInteractor.h>

Collaboration diagram for MainWindow:

Collaboration graph
[legend]
List of all members.

Public Slots

void openFile ()
 Method for handling a call to open a file.

void saveFile ()
 Method for handling a call to save an image.

void newSubdivision (void)
 Method for handling subdivision calls.


Public Member Functions

void init (void)
 initializes GUI


Private Attributes

RenderWindowInteractor * interactor
 provides GUI and OpenGL functionality

int subdiv
 Number of Subdivisions.

QString fileName
 filename of *.3DS to open

QString SaveFile
 filename of image file to save

vtkInterpolatingSubdivisionFilter * filter1
 indentifier for linear and butterfly subdivision method

vtkApproximatingSubdivisionFilter * filter2
 indentifier for catmull-clark and loop subdivision method

vtk3DSOurImporter * importer
 imports *.3DS files in vtk

QSpinBox * noOfSubdivisions
 GUI element for selection of the number of subdivisions.

QRadioButton * triangle
 GUI element: Radiobutton for selection of mesh type.

QRadioButton * quad
 GUI element: Radiobutton for selection of mesh type.

QRadioButton * loop
 GUI element: Radiobutton for selection of sudivision type.

QRadioButton * linear
 GUI element: Radiobutton for selection of subdivision type.

QRadioButton * butterfly
 GUI element: Radiobutton for selection of subdivision type.

QRadioButton * cc
 GUI element: Radiobutton for selection of subdivision type.

QLabel * lsubdiv
 GUI element: label.


Detailed Description

creates the GUI with the help of the vtkandqt library

Definition at line 46 of file ccInteractor.h.


Member Function Documentation

void MainWindow::init (  void   ) 
 

initializes GUI

Definition at line 4 of file ccInteractor.cpp.

References butterfly, cc, interactor, linear, loop, lsubdiv, newSubdivision(), noOfSubdivisions, openFile(), quad, saveFile(), and triangle.

Referenced by main().

00004                           {
00005     interactor = NULL;
00006     QVBox *mainBox = new QVBox(this);
00007     mainBox->setGeometry(10,10,330,400);
00008   
00009     QPushButton *buttonOK = new QPushButton("Open 3Ds-File...", mainBox, "button_open");
00010     buttonOK->setGeometry(10,10,310,20);
00011     QHBox *h1box = new QHBox(mainBox);
00012     h1box->setGeometry(10,30,310,20);
00013     lsubdiv = new QLabel("&Number of Subdivisions:",h1box);
00014     noOfSubdivisions = new QSpinBox(h1box,"spin1");
00015     noOfSubdivisions->setMinValue(1);
00016     noOfSubdivisions->setMaxValue(20);
00017     lsubdiv->setBuddy(noOfSubdivisions);
00018     QButtonGroup *selectStartType = new QButtonGroup("Select initial mesh type", mainBox);
00019     selectStartType->setGeometry(10,60,310,80);
00020     QButtonGroup *selectSubdivMeth = new QButtonGroup("Select initial subdivision method", mainBox);
00021     selectSubdivMeth->setGeometry(10,110,310,140);
00022     triangle = new QRadioButton("Triangle", selectStartType);
00023     triangle->setGeometry(10, 20, 100, 20);
00024     triangle->setChecked(true);
00025     quad = new QRadioButton("Quad", selectStartType);
00026     quad->setGeometry(10, 50, 100, 20);
00027     quad->setChecked(false);
00028     selectStartType->insert(triangle, 0);
00029     selectStartType->insert(quad, 1);
00030     linear = new QRadioButton("Linear", selectSubdivMeth);
00031     linear->setGeometry(10,20,200,20);
00032     linear->setChecked(true);
00033     loop = new QRadioButton("Loop", selectSubdivMeth);
00034     loop->setGeometry(10,50,200,20);
00035     loop->setChecked(false);
00036     butterfly = new QRadioButton("Butterfly",selectSubdivMeth);
00037     butterfly->setGeometry(10,80,200,20);
00038     butterfly->setChecked(false);
00039     cc = new QRadioButton("CatmullClark",selectSubdivMeth);
00040     cc->setGeometry(10,110,200,20);
00041     cc->setChecked(false);
00042 
00043     selectSubdivMeth->insert(linear,0);
00044     selectSubdivMeth->insert(loop,1);
00045     selectSubdivMeth->insert(butterfly,2);
00046     selectSubdivMeth->insert(cc,3);
00047     QPushButton *buttonSubdivide = new QPushButton("Subdivision", mainBox, "button_subdivide");
00048     QPushButton *buttonSave = new QPushButton("Save Image",mainBox,"button_save");
00049     connect( buttonOK, SIGNAL(clicked()), this, SLOT(openFile()));
00050     connect( buttonSubdivide, SIGNAL(clicked()), this, SLOT(newSubdivision()));
00051     connect( buttonSave, SIGNAL(clicked()),this,SLOT(saveFile()));
00052 }

void MainWindow::newSubdivision (  void   )  [slot]
 

Method for handling subdivision calls.

Definition at line 105 of file ccInteractor.cpp.

References butterfly, cc, fileName, filter1, filter2, RenderWindow::GetRenderer(), importer, interactor, linear, loop, vtkCatmullClarkFilter::New(), vtk3DSOurImporter::New(), noOfSubdivisions, vtk3DSOurImporter::SetPolys(), subdiv, and triangle.

Referenced by init().

00105                                     {
00106 
00107     printf("start of new subdivision\n");
00108 
00109     importer = vtk3DSOurImporter::New();
00110     if (triangle->isChecked()) importer->SetPolys("triangle"); else importer->SetPolys("quad");
00111     importer->ComputeNormalsOn();
00112     importer->SetFileName(fileName);
00113     importer->Read();
00114 
00115     printf("Test\n");
00116 
00117 
00118     subdiv = (noOfSubdivisions->value());
00119 
00120     filter1 = NULL;
00121     filter2 = NULL;
00122 
00123     // create Render Window Interactor
00124     interactor = new RenderWindowInteractor(this);
00125     CHECK_PTR( interactor );
00126     interactor->resize( 400, 400 );
00127     interactor->setGeometry( 360, 10, 400, 400 );
00128 
00129     if(linear->isChecked())
00130         (vtkLinearSubdivisionFilter*)filter1 = vtkLinearSubdivisionFilter::New();
00131     if(loop->isChecked())
00132         (vtkLoopSubdivisionFilter*)filter2 = vtkLoopSubdivisionFilter::New();
00133     if(butterfly->isChecked())
00134         (vtkButterflySubdivisionFilter*)filter1 = vtkButterflySubdivisionFilter::New();
00135     if(cc->isChecked())
00136         (vtkCatmullClarkFilter*)filter2 = vtkCatmullClarkFilter::New();
00137   
00138     if((filter1 != NULL)&&(filter2 == NULL))
00139         filter1->SetNumberOfSubdivisions(subdiv);
00140     else if((filter2 != NULL)&&(filter1 == NULL))
00141         filter2->SetNumberOfSubdivisions(subdiv);
00142     else exit(1);
00143   
00144     vtkRenderer *renderer = vtkRenderer::New();
00145     vtkRenderWindow *renderWindow = vtkRenderWindow::New();
00146     renderWindow->AddRenderer(renderer);
00147     renderer->SetBackground(0,0,0); 
00148 
00149     vtkActorCollection *ac = importer->GetRenderer()->GetActors();
00150     ac->InitTraversal();
00151     vtkActor *dsActor=ac->GetNextActor();
00152     while (dsActor!=NULL) {
00153         vtkPolyData *polyData = (vtkPolyData*)(dsActor->GetMapper()->GetInputAsDataSet());
00154 
00155         vtkPolyDataMapper *figureMapper = vtkPolyDataMapper::New();
00156   
00157         if(filter1 != NULL) {
00158             filter1->SetInput(polyData);
00159             figureMapper->SetInput(filter1->GetOutput());
00160         }
00161         if(filter2 != NULL) {
00162             filter2->SetInput(polyData);
00163             figureMapper->SetInput(filter2->GetOutput());
00164         }
00165         
00166         vtkActor *actor = vtkActor::New();
00167     
00168         actor->SetMapper(figureMapper);
00169         actor->SetProperty(dsActor->GetProperty()); 
00170 
00171         // ========================================================
00172         // Here the Actors are added to our interactor
00173         // ========================================================
00174         interactor->GetRenderer()->AddActor(actor);
00175 
00176         dsActor=ac->GetNextActor();
00177     }
00178 
00179     interactor->GetRenderer()->ResetCamera();
00180     printf("show interactor\n");
00181     interactor->show();
00182     
00183 }

void MainWindow::openFile (   )  [slot]
 

Method for handling a call to open a file.

Definition at line 55 of file ccInteractor.cpp.

References fileName.

Referenced by init().

00055                               {
00056 
00057     QFileDialog *fd = new QFileDialog( this, "Open File", TRUE );
00058         
00059     fd->setMode( QFileDialog::ExistingFile );
00060     fd->setViewMode( QFileDialog::List );
00061     fd->setFilter( "Data File (*.3ds)" );
00062 
00063     if( fd->exec() == QDialog::Accepted ) {
00064         fileName = fd->selectedFile();
00065     }
00066 }

void MainWindow::saveFile (   )  [slot]
 

Method for handling a call to save an image.

Definition at line 68 of file ccInteractor.cpp.

References interactor, and SaveFile.

Referenced by init().

00068                               {
00069     if(interactor != NULL) {
00070         SaveFile = QFileDialog::getSaveFileName("/home","Images (*.bmp *.xbm *.xpm *.png *.jpg *.jpeg )",
00071                                                 this, "save file dialog", 
00072                                                 "Choose a file name to save under");
00073         QImage *newImg = new QImage();
00074         *newImg = interactor->grabFrameBuffer();
00075 
00076         if ( SaveFile != NULL ) {
00077             if(SaveFile.endsWith("jpg") || 
00078                SaveFile.endsWith("JPG") || 
00079                SaveFile.endsWith("JPEG")||
00080                SaveFile.endsWith("jpeg")) { 
00081                 newImg->save(SaveFile,"JPEG",100);
00082             } else {
00083                 if(SaveFile.endsWith("bmp") ||
00084                    SaveFile.endsWith("BMP")) {
00085                     newImg->save(SaveFile,"BMP",100);
00086                 } else {
00087                     if(SaveFile.endsWith("xbm") ||
00088                        SaveFile.endsWith("XBM")) {
00089                         newImg->save(SaveFile,"XBM",100);
00090                     } else {
00091                         if(SaveFile.endsWith("xpm") ||
00092                            SaveFile.endsWith("XPM")) {
00093                             newImg->save(SaveFile,"XPM",100);
00094                         } else {
00095                             newImg->save(SaveFile,"PNG",100);
00096                         }
00097                     }
00098                 }
00099             }
00100         }
00101         delete newImg;
00102     }
00103 }


Member Data Documentation

QRadioButton* MainWindow::butterfly [private]
 

GUI element: Radiobutton for selection of subdivision type.

Definition at line 77 of file ccInteractor.h.

Referenced by init(), and newSubdivision().

QRadioButton* MainWindow::cc [private]
 

GUI element: Radiobutton for selection of subdivision type.

Definition at line 79 of file ccInteractor.h.

Referenced by init(), and newSubdivision().

QString MainWindow::fileName [private]
 

filename of *.3DS to open

Definition at line 55 of file ccInteractor.h.

Referenced by newSubdivision(), and openFile().

vtkInterpolatingSubdivisionFilter* MainWindow::filter1 [private]
 

indentifier for linear and butterfly subdivision method

Definition at line 59 of file ccInteractor.h.

Referenced by newSubdivision().

vtkApproximatingSubdivisionFilter* MainWindow::filter2 [private]
 

indentifier for catmull-clark and loop subdivision method

Definition at line 61 of file ccInteractor.h.

Referenced by newSubdivision().

vtk3DSOurImporter* MainWindow::importer [private]
 

imports *.3DS files in vtk

Definition at line 63 of file ccInteractor.h.

Referenced by newSubdivision().

RenderWindowInteractor* MainWindow::interactor [private]
 

provides GUI and OpenGL functionality

Definition at line 51 of file ccInteractor.h.

Referenced by init(), newSubdivision(), and saveFile().

QRadioButton* MainWindow::linear [private]
 

GUI element: Radiobutton for selection of subdivision type.

Definition at line 75 of file ccInteractor.h.

Referenced by init(), and newSubdivision().

QRadioButton* MainWindow::loop [private]
 

GUI element: Radiobutton for selection of sudivision type.

Definition at line 73 of file ccInteractor.h.

Referenced by init(), and newSubdivision().

QLabel* MainWindow::lsubdiv [private]
 

GUI element: label.

Definition at line 81 of file ccInteractor.h.

Referenced by init().

QSpinBox* MainWindow::noOfSubdivisions [private]
 

GUI element for selection of the number of subdivisions.

Definition at line 67 of file ccInteractor.h.

Referenced by init(), and newSubdivision().

QRadioButton* MainWindow::quad [private]
 

GUI element: Radiobutton for selection of mesh type.

Definition at line 71 of file ccInteractor.h.

Referenced by init().

QString MainWindow::SaveFile [private]
 

filename of image file to save

Definition at line 57 of file ccInteractor.h.

Referenced by saveFile().

int MainWindow::subdiv [private]
 

Number of Subdivisions.

Definition at line 53 of file ccInteractor.h.

Referenced by newSubdivision().

QRadioButton* MainWindow::triangle [private]
 

GUI element: Radiobutton for selection of mesh type.

Definition at line 69 of file ccInteractor.h.

Referenced by init(), and newSubdivision().


The documentation for this class was generated from the following files:
Generated on Sun Jun 22 12:13:16 2003 for Catmull Clark by doxygen 1.3.2