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

ccInteractor.cpp

Go to the documentation of this file.
00001 
00002 #include "ccInteractor.h"
00003 
00004 void MainWindow::init(void) {
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 }
00053 
00054 
00055 void MainWindow::openFile(void) {
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 }
00067 
00068 void MainWindow::saveFile(void) {
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 }
00104 
00105 void MainWindow::newSubdivision(void) {
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 }
00184 
00185 int main( int argc, char* argv[] ) {
00186 
00187     // ========================================================
00188     // Set up the QT-Application and init QT GUI- and VTK-stuff
00189     // ========================================================
00190     printf("Application starting\n");
00191     QApplication myApp( argc, argv );
00192   
00193     // create Main Window
00194     MainWindow *mainWindow = new MainWindow();
00195     mainWindow->setGeometry(100, 50, 800, 600);
00196     mainWindow->setCaption("MMCG - Subdivision Surfaces");
00197   
00198     // generate the interaction-gui
00199     mainWindow->init();
00200   
00201     // declare main window and show it
00202     myApp.setMainWidget( mainWindow );
00203     printf("show main window\n");
00204     mainWindow->show();
00205   
00206     //mainWindow->openFile();
00207   
00208     //mainWindow->newSubdivision();
00209   
00210     // qt main event loop
00211     //printf("execute application\n");
00212     int nReturn = myApp.exec();
00213   
00214     // clean vtk stuff
00215     // ToDo
00216   
00217     return nReturn;
00218 }

Generated on Sun Jun 22 12:13:09 2003 for Catmull Clark by doxygen 1.3.2