int Graph::bresenham(Point pt1, Point pt2 ){ //overloaded bresenham, each points has its own color Point p1 = pt1; Point p2 = pt2; int x, y, x_end, y_end, p; int dx = (p2.x - p1.x), dy = (p2.y - p1.y); //for determining sign of slope bool steep = false; float m = (float)dy/(float)dx ; //find the slope first DPRINT("The slope is %.2f\n", m); bool positive_slope; if( m >= 0 ) // positive slope positive_slope = true; else positive_slope = false; if( fabs(m) <= 1 ){ //shallow steep = false; } else{ //steep steep = true; swapXY(&p1); swapXY(&p2); } determineStartAndEndPoints(p1, p2, &x, &y, &x_end, &y_end); //DPRINT("x: %d,\ty: %d,\tx_end: %d,\ty_end:%d\n", x, y, x_end, y_end); dx = abs(x_end - x); dy = abs(y_end - y); //draw first point if(steep) drawPixel(y,x, linearInterpolation(x, p1.x, p2.x, p1.normalizedIntensity, p2.normalizedIntensity ) );//x and y was swapped before else drawPixel(x,y, linearInterpolation(y, p1.y, p2.y, p1.normalizedIntensity, p2.normalizedIntensity ) ); p = 2 * dy - dx; for( ; x < x_end; ){ x++; if( p >= 0){ // if d1 - d2 >= 0, means d2 is shorter, so advance y one level up positive_slope? y++:y--; p = p + 2*dy - 2*dx; } else // if d1 - d2 < 0; means d1 is shorter, so no change of y; p = p + 2*dy; if(steep) drawPixel(y,x, linearInterpolation(x, p1.x, p2.x, p1.normalizedIntensity, p2.normalizedIntensity ) );//x and y was swapped before else drawPixel(x,y, linearInterpolation(y, p1.y, p2.y, p1.normalizedIntensity, p2.normalizedIntensity ) ); } return 0; }
int main(void) { // Prompt for two numbers printf("This program swaps the value of two variables.\n"); printf("Enter the first number: "); x = GetInt(); printf("Enter the second number: "); y = GetInt(); printf("x=%i\n", x); printf("y=%i\n", y); swapXY(); printf("x=%i\n", x); printf("y=%i\n", y); return 0; }
AViz::AViz() : QMainWindow() { // Make menus in menubar QMenu *file = menuBar()->addMenu("&File"); QMenu *elements = menuBar()->addMenu( "&Elements"); QMenu *view = menuBar()->addMenu( "&View"); QMenu *settings = menuBar()->addMenu( "&Settings"); QMenu *data = menuBar()->addMenu("&Data"); menuBar()->addSeparator(); QMenu *help = menuBar()->addMenu("&Help"); // Make a cascade menu to read files QMenu *openfile = file->addMenu("&Open"); openfile->addAction("Open XYZ File...", this, SLOT(openXYZ())); openfile->addAction("Open File List...", this, SLOT(openList())); openfile->addAction("Open ViewParam File...", this, SLOT(openViewParam())); file->addAction( "Save ViewParam File...", this, SLOT(saveViewParam()) ); file->addSeparator(); file->addAction( "File List...", this, SLOT(launchFileList()) ); file->addAction( "Animation...", this, SLOT(launchAnimation()) ); file->addSeparator(); m_inOutWatchModelAction = file->addAction( "Watch XYZ File", this, SLOT(watchFile()) ); file->addSeparator(); file->addAction( "Snap PNG File...", this, SLOT(savePNGFile()) ); file->addSeparator(); file->addAction( "Set Default View Param", this, SLOT(setDefaultView())); file->addSeparator(); file->addAction( "E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q ); // Make a general view menu QMenu *viewpoint = view->addMenu("Set &Viewpoint"); view->addAction( "Clipping...", this, SLOT(launchClip()) ); view->addAction( "Slicing...", this, SLOT(launchSlice()) ); // Make a cascade menu to set standard view points viewpoint->addAction( "Explicit...", this, SLOT(launchExplicit()) ); viewpoint->addSeparator(); viewpoint->addAction( "Default View", this, SLOT(setDefaults()) ); viewpoint->addSeparator(); viewpoint->addAction( "View XY +", this, SLOT(viewXYPlus()) ); viewpoint->addAction( "View XY -", this, SLOT(viewXYMinus()) ); viewpoint->addSeparator(); viewpoint->addAction( "View XZ +", this, SLOT(viewXZPlus()) ); viewpoint->addAction( "View XZ -", this, SLOT(viewXZMinus()) ); viewpoint->addSeparator(); viewpoint->addAction( "View YZ +", this, SLOT(viewYZPlus()) ); viewpoint->addAction( "View YZ -", this, SLOT(viewYZMinus()) ); // Fill a general elements menu m_atomsMenu = elements->addMenu("Atoms..."); // Make a submenu for atom specifications m_atomsMenu->addAction( "Atoms/Molecules...", this, SLOT(launchAtoms()) ); m_atomsMenu->addAction( "Bonds...", this, SLOT(launchBonds()) ); m_spinsAction = elements->addAction( "Spins...", this, SLOT(launchSpins()) ); m_liquidCrystalsAction = elements->addAction( "Liquid Crystals...", this, SLOT(launchLiquidCrystals()) ); m_polymersMenu = elements->addMenu( "Polymers..."); m_poresAction = elements->addAction( "Pores ...", this, SLOT(launchPores()) ); elements->addAction( "Lights...", this, SLOT(launchLights()) ); elements->addAction( "Annotation...", this, SLOT(launchAnnotation()) ); // fill submenu for polymer specifications m_polymersMenu->addAction( "Polymers...", this, SLOT(launchPolymers()) ); m_polymersMenu->addAction( "Bonds...", this, SLOT(launchBonds()) ); // fill a general settings menu m_showHideAxesAction = settings->addAction( "Hide Axes", this, SLOT(showHideAxesCB()) ); m_showHideContourAction = settings->addAction( "Hide Contour", this, SLOT(showHideContourCB()) ); m_onlyContourAction = settings->addAction( "Only Contour", this, SLOT(onlyContourCB()) ); // fill a general data menu data->addAction( "&Translate...", this, SLOT(launchTranslation()) ); data->addSeparator(); data->addAction( "Swap XY", this, SLOT(swapXY()) ); data->addAction( "Swap XZ", this, SLOT(swapXZ()) ); data->addAction( "Swap YZ", this, SLOT(swapYZ()) ); data->addSeparator(); data->addAction( "Mirror X", this, SLOT(mirrorX()) ); data->addAction( "Mirror Y", this, SLOT(mirrorY()) ); data->addAction( "Mirror Z", this, SLOT(mirrorZ()) ); data->addSeparator(); data->addAction( "Stretch XYZ...", this, SLOT(launchStretch()) ); // fill a general help menu help->addAction( "&About", this, SLOT(about()), Qt::CTRL+Qt::Key_H ); help->addAction( "License", this, SLOT(license()) ); help->addAction( "Distribution", this, SLOT(distribute()) ); // Now construct the main form // (Note having aviz as paramter for MainForm ctor // is "This is an ugly hack, intended to propagate the // address of the calling class") m_mainForm = new MainForm(this/*parent*/, this /*aviz*/); setCentralWidget(m_mainForm); // Construct a timer m_watchTimer = new QTimer(this); // Set initial settings setAtomMenus(); }