[20] | 1 | #include "screenGenerator.h" |
---|
| 2 | |
---|
| 3 | screenGenerator::screenGenerator(QWidget *parent, Qt::WFlags flags) |
---|
| 4 | : QMainWindow(parent, flags) |
---|
| 5 | { |
---|
| 6 | ui.setupUi(this); |
---|
| 7 | } |
---|
| 8 | |
---|
| 9 | screenGenerator::~screenGenerator() |
---|
| 10 | { |
---|
| 11 | |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | void screenGenerator::on_pBGenerate_clicked() |
---|
| 15 | { |
---|
| 16 | // Get filename to save |
---|
| 17 | QString filename = QFileDialog::getSaveFileName(this, tr("Save Wavefront Object File"), |
---|
| 18 | QDir::currentPath(), |
---|
| 19 | tr("Wavefront Object (*.obj)")); |
---|
| 20 | //Open file |
---|
| 21 | QFile file( filename ); |
---|
| 22 | file.remove(); |
---|
| 23 | file.open(QIODevice::ReadWrite | QIODevice::Text); |
---|
| 24 | QTextStream in(&file); |
---|
| 25 | in << "# Screen generator v0.1 OBJ File: \n"; |
---|
| 26 | in << "# Torben Dannhauer, 09 2009 \n"; |
---|
| 27 | |
---|
| 28 | // Raster the screen and save vertices |
---|
| 29 | double deltaVert = ui.dSB_upperEdge->value()-ui.dSB_lowerEdge->value(); |
---|
| 30 | deltaVert /= (ui.sB_horSubdivisions->value()+1); |
---|
| 31 | double deltaHor_rad = deg2rad( ui.sB_openingAngle->value() ) / (ui.sB_vertSubdivisions->value()+1); |
---|
| 32 | |
---|
| 33 | for(int i=0; i<=ui.sB_vertSubdivisions->value()+1; i++) // vertical |
---|
| 34 | { |
---|
| 35 | for (int j=0; j<=ui.sB_horSubdivisions->value()+1; j++) // horizontal |
---|
| 36 | { |
---|
| 37 | // calc current angle |
---|
| 38 | double currentAngle_rad = j*deltaHor_rad - deg2rad( ui.sB_openingAngle->value() / 2.0 ); |
---|
| 39 | |
---|
| 40 | double side = 0 - sin(currentAngle_rad)*ui.dSB_radius->value(); |
---|
| 41 | double up = ui.dSB_lowerEdge->value()+i*deltaVert; |
---|
| 42 | double depth = 0 - cos(currentAngle_rad)*ui.dSB_radius->value(); |
---|
| 43 | |
---|
| 44 | // write vertex line |
---|
| 45 | QString data = QString("v ")+QString::number(side, 'f', 6)+" "+QString::number(up, 'f', 6)+" "+QString::number(depth, 'f', 6)+" \n"; |
---|
| 46 | in << data; |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | // calculate polygon vertex order |
---|
| 51 | for( int row=0; row<ui.sB_vertSubdivisions->value()+1; row++) |
---|
| 52 | { |
---|
| 53 | for ( int col=0; col<ui.sB_horSubdivisions->value()+1; col++) |
---|
| 54 | { |
---|
| 55 | // write polygon vertex line |
---|
| 56 | int x = row*(ui.sB_horSubdivisions->value()+2)+col+1; |
---|
| 57 | in << "f "+QString::number(x)+" "+QString::number(x+ui.sB_horSubdivisions->value()+2)+" "+QString::number(x+1)+"\n"; |
---|
| 58 | in << "f "+QString::number(x+1)+" "+QString::number(x+ui.sB_horSubdivisions->value()+2)+" "+QString::number(x+ui.sB_horSubdivisions->value()+3)+"\n"; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | // close file |
---|
| 63 | file.close(); |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void screenGenerator::on_actionAbout_Qt_triggered() |
---|
| 72 | { |
---|
| 73 | QMessageBox::aboutQt(this); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void screenGenerator::on_actionAbout_screenGenerator_triggered() |
---|
| 77 | { |
---|
| 78 | QMessageBox::about( this, "screenGenerator V 0.1", "This software generates cylindrical curved screens to be used in the 'Projection Designer' software. The output format is wavefront object. The geometry and size can be specified." ); |
---|
| 79 | } |
---|