void PlotMatrix::updateLayout() { for ( int row = 0; row < numRows(); row++ ) { for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( row, col ); if ( p ) { bool showAxis[QwtPlot::axisCnt]; showAxis[QwtPlot::xBottom] = axisEnabled( QwtPlot::xBottom ) && row == numRows() - 1; showAxis[QwtPlot::xTop] = axisEnabled( QwtPlot::xTop ) && row == 0; showAxis[QwtPlot::yLeft] = axisEnabled( QwtPlot::yLeft ) && col == 0; showAxis[QwtPlot::yRight] = axisEnabled( QwtPlot::yRight ) && col == numColumns() - 1; for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { enablePlotAxis( p, axis, showAxis[axis] ); } } } } for ( int row = 0; row < numRows(); row++ ) { alignAxes( row, QwtPlot::xTop ); alignAxes( row, QwtPlot::xBottom ); alignScaleBorder( row, QwtPlot::yLeft ); alignScaleBorder( row, QwtPlot::yRight ); } for ( int col = 0; col < numColumns(); col++ ) { alignAxes( col, QwtPlot::yLeft ); alignAxes( col, QwtPlot::yRight ); alignScaleBorder( col, QwtPlot::xBottom ); alignScaleBorder( col, QwtPlot::xTop ); } for ( int row = 0; row < numRows(); row++ ) { for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( row, col ); if ( p ) p->replot(); } } }
void PlotMatrix::alignScaleBorder( int rowOrColumn, int axis ) { int startDist = 0; int endDist = 0; if ( axis == QwtPlot::yLeft ) { QwtPlot *p = plotAt( rowOrColumn, 0 ); if ( p ) p->axisWidget( axis )->getBorderDistHint( startDist, endDist ); for ( int col = 1; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) p->axisWidget( axis )->setMinBorderDist( startDist, endDist ); } } else if ( axis == QwtPlot::yRight ) { QwtPlot *p = plotAt( rowOrColumn, numColumns() - 1 ); if ( p ) p->axisWidget( axis )->getBorderDistHint( startDist, endDist ); for ( int col = 0; col < numColumns() - 1; col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) p->axisWidget( axis )->setMinBorderDist( startDist, endDist ); } } if ( axis == QwtPlot::xTop ) { QwtPlot *p = plotAt( rowOrColumn, 0 ); if ( p ) p->axisWidget( axis )->getBorderDistHint( startDist, endDist ); for ( int row = 1; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) p->axisWidget( axis )->setMinBorderDist( startDist, endDist ); } } else if ( axis == QwtPlot::xBottom ) { QwtPlot *p = plotAt( numRows() - 1, rowOrColumn ); if ( p ) p->axisWidget( axis )->getBorderDistHint( startDist, endDist ); for ( int row = 0; row < numRows() - 1; row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) p->axisWidget( axis )->setMinBorderDist( startDist, endDist ); } } }
void PlotMatrix::setAxisScale( int axis, int rowOrColumn, double min, double max, double step ) { int row = 0; int col = 0; if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) col = rowOrColumn; else row = rowOrColumn; QwtPlot *plt = plotAt( row, col ); if ( plt ) { plt->setAxisScale( axis, min, max, step ); plt->updateAxes(); } }
void Organism::evolve() { // user-mediated evolution procedure char key = 0; drawTree(leftChild != NULL && !leftChild->terminal, midChild != NULL && !midChild->terminal, rightChild != NULL && !rightChild->terminal); // grow the parent and two children until a key is pressed // try a new child while this is happening Organism *newChild = spawnChild(); assert(newChild != NULL); do { // repeat this loop until the space key is pressed plotAt(vc.numxpixels/2, vc.numypixels*3/4); nextGen(); if (leftChild == NULL) leftChild = spawnChild(); // make new left child else leftChild->plotAt(vc.numxpixels/6, vc.numypixels/3); assert(leftChild != NULL); leftChild->nextGen(); if (midChild == NULL) midChild = spawnChild(); // make new mid child else midChild->plotAt(vc.numxpixels/2, vc.numypixels/4); assert(leftChild != NULL); midChild->nextGen(); if (rightChild == NULL) rightChild = spawnChild(); // make new left child else rightChild->plotAt(vc.numxpixels*5/6, vc.numypixels/3); assert(leftChild != NULL); rightChild->nextGen(); terminal = 0; // if the node was terminal before, its not now if (newChild->age < 25) newChild->nextGen(); else if (leftChild->terminal == 1 && newChild->fitness()*0.7 > leftChild->fitness()) { // replace the left child with the new child delete leftChild; leftChild = newChild; newChild = spawnChild(); assert(newChild != NULL); } else if (midChild->terminal == 1 && newChild->fitness()*0.7 > midChild->fitness()) { // replace the left child with the new child delete midChild; midChild = newChild; newChild = spawnChild(); assert(newChild != NULL); } else if (rightChild->terminal == 1 && newChild->fitness()*0.7 > rightChild->fitness()) { // replace the left child with the new child delete rightChild; rightChild = newChild; newChild = spawnChild(); assert(newChild != NULL); } else if (newChild->age > 50) { // new child is 50 generations old and still has not promoted delete newChild; newChild = spawnChild(); assert(newChild != NULL); } else newChild->nextGen(); if (kbhit()) { // read the key and see what needs to be done key = getch(); if (_stackavail() > 0x0400) { // only process child branch if there is enough stack space if (key == 'A' || key == 'a') leftChild->evolve(); else if (key == 'G' || key == 'g') midChild->evolve(); else if (key == 'L' || key == 'l') rightChild->evolve(); drawTree(leftChild != NULL && !leftChild->terminal, midChild != NULL && !midChild->terminal, rightChild != NULL && !rightChild->terminal); }; // if } else key = 0; } while (key != ' '); delete newChild; }; // Organism::evolve()
void PlotMatrix::alignAxes( int rowOrColumn, int axis ) { if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) { double maxExtent = 0; for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } } else { double maxExtent = 0; for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); QwtScaleDraw *sd = scaleWidget->scaleDraw(); sd->setMinimumExtent( 0.0 ); const double extent = sd->extent( scaleWidget->font() ); if ( extent > maxExtent ) maxExtent = extent; } } for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p ) { QwtScaleWidget *scaleWidget = p->axisWidget( axis ); scaleWidget->scaleDraw()->setMinimumExtent( maxExtent ); } } } }
void PlotMatrix::scaleDivChanged() { if ( d_data->inScaleSync ) return; d_data->inScaleSync = true; QwtPlot *plt = NULL; int axisId = -1; int rowOrColumn = -1; // find the changed axis for ( int row = 0; row < numRows(); row++ ) { for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( row, col ); if ( p ) { for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( p->axisWidget( axis ) == sender() ) { plt = p; axisId = axis; if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop ) rowOrColumn = col; else rowOrColumn = row; } } } } } if ( plt ) { const QwtScaleDiv scaleDiv = plt->axisScaleDiv( axisId ); // synchronize the axes if ( axisId == QwtPlot::xBottom || axisId == QwtPlot::xTop ) { for ( int row = 0; row < numRows(); row++ ) { QwtPlot *p = plotAt( row, rowOrColumn ); if ( p != plt ) { p->setAxisScaleDiv( axisId, scaleDiv ); } } } else { for ( int col = 0; col < numColumns(); col++ ) { QwtPlot *p = plotAt( rowOrColumn, col ); if ( p != plt ) { p->setAxisScaleDiv( axisId, scaleDiv ); } } } updateLayout(); } d_data->inScaleSync = false; }