void SpeechAudiometryWidget::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { // We passen een vector aan op positie i zetten we waarde j: bepaal i en j int i = (event->x() - BORDER_LEFT + gridWidth()/44) / (gridWidth()/22); int j = 100 - static_cast<int> (floor(((event->y() - BORDER_TOP * 1.0)/gridHeight() * 100.0) / 5.0 + 0.5)) * 5; if (j < 0 || j > 100) j = INVALID_VALUE; switch (m_drawMode) { case RE: m_reData[i] = j; emit changedREvalue(); break; case LE: m_leData[i] = j; emit changedLEvalue(); break; case RELE: m_releData[i] = j; emit changedRELEvalue(); break; default: Q_ASSERT(false); } update(); } }
void PureToneAudiometryWidget::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { // We are changing a vector: on position i we set value j: determine i and j int i1 = (event->x() - BORDER_LEFT + gridWidth()/24) / (gridWidth()/12); int i2 = (event->x() - BORDER_LEFT + gridWidth()/12) / (gridWidth()/6); int i = (i2 < 2) ? i2 : i1 - 2; int j = static_cast<int> ((((event->y() - BORDER_TOP * 1.0)/gridHeight() * 145.0)) / 5.0 + 0.5) * 5 - 10; if (j > 135 || j < 0) j = INVALID_VALUE; switch (m_drawMode) { case AC: m_acData[i] = j; emit changedACvalue(); break; case BC: m_bcData[i] = j; break; case UCL: m_uclData[i] = j; break; default: Q_ASSERT(false); } update(); } }
Constants::Constants(QObject* parent) : QObject(parent) { m_gridWidth = qApp->activeWindow()->width() / gridColumns(); m_gridHeight = qApp->activeWindow()->height() / gridHeight(); m_toolbarButtonSize = m_gridHeight; }
void PureToneAudiometryWidget::drawGrid() { QPainter paint; paint.begin(&m_grid); QFont boldFont; boldFont.setBold(true); // Paint the vertical axes int dB[] = {125, 250, 500, 750, 1000, 1500, 2000, 3000, 4000, 6000, 8000}; for (int i = 0; i < 11; ++i) { int x = BORDER_LEFT + ((i < 2) ? i*(gridWidth()/6) : (i+2)*(gridWidth()/12)); paint.setPen(Qt::black); paint.drawText((i<4)?x-6:x-9, (i>2 && i%2==1) ? (34+gridHeight()) : 12, QString::number(dB[i])); paint.setPen(QPen((i == 0 || i == 4) ? Qt::black : Qt::lightGray, (i == 0) ? 2 : 1)); paint.drawLine(x, BORDER_TOP, x, BORDER_TOP + gridHeight()); } paint.setPen(Qt::black); paint.setFont(boldFont); paint.drawText(BORDER_LEFT + gridWidth(), 34 + gridHeight(), "Hz"); paint.setFont(QFont()); // Paint the horizontal axes for (int i = 0; i < 30; ++i) { int y = BORDER_TOP + (static_cast<int> (i * gridHeight()/29.0)); if ((i != 0) && (i % 2 == 0)) { paint.setPen(Qt::black); paint.drawText(15 + 6*(((22-i)/20) + (22-i <= 0 ? 0 : 1)), y + 5, QString::number((i - 2) * 5)); } paint.setPen(QPen((i == 2 || i == 29) ? Qt::black : Qt::lightGray, (i == 29) ? 2 : 1)); paint.drawLine(BORDER_LEFT+1, y, BORDER_LEFT+gridWidth(), y); } paint.setPen(Qt::black); paint.setFont(boldFont); paint.drawText(19, 25, "dB"); paint.setFont(QFont()); paint.end(); }
BOOST_FOREACH(Species *s, species()) { // count all particles for this species int count=0; for (int x=0; x<gridWidth(); x++) for (int y=0; y<gridHeight(); y++) count += iBuffer[x + y*gridWidth() + scount*gridArea()]; // is it red or green? if ((s->id().c_str())[0]=='R') { //std::cout <<"Species "<<s->id().c_str()<<" is RED. Found "<<count <<" particles.\n"; nreds += count; } else if ((s->id().c_str())[0]=='G') { //std::cout <<"Species "<<s->id().c_str()<<" is GREEN. Found "<<count <<" particles.\n"; ngreens += count; } else { //std::cout <<"Species "<<s->id().c_str()<<" is UNKNOWN. Found "<<count <<" particles.\n"; } // increase species index scount++; }
void PureToneAudiometryWidget::drawData() { int xx = -1; int yy = -1; QPainter paint; QPen pen; paint.begin(&m_data); pen.setColor(m_side == RIGHT ? Qt::red : Qt::blue); pen.setStyle(Qt::SolidLine); paint.setPen(pen); // Draw AC data xx = -1; yy = -1; for (int i = 0; i < 11; ++i) { int x = BORDER_LEFT + ((i < 2) ? i*(gridWidth()/6) : (i+2)*(gridWidth()/12)); if (m_acData[i] >= 0) { int y = BORDER_TOP + static_cast<int> (((m_acData[i]+10.0)/145.0)*gridHeight() + 0.5); switch (m_side) { case RIGHT: paint.drawEllipse(x-4, y-4, 8, 8); break; case LEFT: paint.drawLine(x-4, y-4, x+4, y+4); paint.drawLine(x-4, y+4, x+4, y-4); break; default: Q_ASSERT(false); } if (xx > 0 && yy > 0) paint.drawLine(xx, yy, x, y); xx = x; yy = y; } } // Draw BC data xx = -1; yy = -1; for (int i = 0; i < 11; ++i) { int x = BORDER_LEFT + ((i < 2) ? i*(gridWidth()/6) : (i+2)*(gridWidth()/12)); if (m_bcData[i] >= 0) { int y = BORDER_TOP + static_cast<int> (((m_bcData[i]+10.0)/145.0)*gridHeight() + 0.5); switch (m_side) { case RIGHT: paint.drawLine(x, y, x+4, y+4); paint.drawLine(x, y, x+4, y-4); break; case LEFT: paint.drawLine(x-4, y-4, x, y); paint.drawLine(x-4, y+4, x, y); break; default: Q_ASSERT(false); } if (xx > 0 && yy > 0) { pen.setStyle(Qt::DashLine); paint.setPen(pen); paint.drawLine(xx, yy, x, y); pen.setStyle(Qt::SolidLine); paint.setPen(pen); } xx = x; yy = y; } } // Draw UCL data xx = -1; yy = -1; for (int i = 0; i < 11; ++i) { int x = BORDER_LEFT + ((i < 2) ? i*(gridWidth()/6) : (i+2)*(gridWidth()/12)); if (m_uclData[i] >= 0) { int y = BORDER_TOP + static_cast<int> (((m_uclData[i]+10.0)/145.0)*gridHeight() + 0.5); paint.drawLine(x-4, y-4, x+4, y-4); paint.drawLine(x-4, y-4, x, y+4); paint.drawLine(x, y+4, x+4, y-4); if (xx > 0 && yy > 0) paint.drawLine(xx, yy, x, y); xx = x; yy = y; } } }
void SpeechAudiometryWidget::drawData() { int xx = -1; int yy = -1; QPainter paint; paint.begin(&m_data); // Draw RE data paint.setPen(Qt::red); xx = -1; yy = -1; for (int i = 0; i < 23; ++i) { int x = BORDER_LEFT + i*gridWidth()/22; if (m_reData[i] >= 0) { int y = BORDER_TOP + static_cast<int> (((100 - m_reData[i])/100.0)*gridHeight() + 0.5); switch (m_kind) { case WITHOUT: paint.drawEllipse(x-4, y-4, 8, 8); break; case WITH: paint.setBrush(QBrush(paint.pen().color(), Qt::SolidPattern)); paint.drawEllipse(x-4, y-4, 8, 8); paint.setBrush(Qt::NoBrush); break; default: Q_ASSERT(false); } if (xx > 0 && yy > 0) paint.drawLine(xx, yy, x, y); xx = x; yy = y; } } // Draw LE data paint.setPen(Qt::blue); xx = -1; yy = -1; for (int i = 0; i < 23; ++i) { int x = BORDER_LEFT + i*gridWidth()/22; if (m_leData[i] >= 0) { int y = BORDER_TOP + static_cast<int> (((100 - m_leData[i])/100.0)*gridHeight() + 0.5); switch (m_kind) { case WITHOUT: paint.drawLine(x-4, y-4, x+4, y+4); paint.drawLine(x-4, y+4, x+4, y-4); break; case WITH: paint.fillRect(x-4, y-4, 8, 8, paint.pen().color()); break; default: Q_ASSERT(false); } if (xx > 0 && yy > 0) paint.drawLine(xx, yy, x, y); xx = x; yy = y; } } // Draw RELE data paint.setPen(Qt::darkGreen); xx = -1; yy = -1; for (int i = 0; i < 23; ++i) { int x = BORDER_LEFT + i*gridWidth()/22; if (m_releData[i] >= 0) { int y = BORDER_TOP + static_cast<int> (((100 - m_releData[i])/100.0)*gridHeight() + 0.5); switch (m_kind) { case WITHOUT: paint.drawLine(x-4, y+4, x+4, y+4); paint.drawLine(x-4, y+4, x, y-4); paint.drawLine(x, y-4, x+4, y+4); break; case WITH: { paint.setBrush(QBrush(paint.pen().color(), Qt::SolidPattern)); QPoint points[] = { QPoint(x-4, y+4), QPoint(x+4, y+4), QPoint(x, y-4) }; paint.drawConvexPolygon(points, 3); paint.setBrush(Qt::NoBrush); } break; default: Q_ASSERT(false); } if (xx > 0 && yy > 0) paint.drawLine(xx, yy, x, y); xx = x; yy = y; } } }
void SpeechAudiometryWidget::drawGrid() { QPainter paint; paint.begin(&m_rooster); QFont boldFont; boldFont.setBold(true); // Paint the vertical axes for (int i = 0; i < 23; ++i) { int x = BORDER_LEFT + i*gridWidth()/22; paint.setPen(Qt::black); if ((i % 2 == 0) && (i != 0) && (i < 20)) paint.drawText(x-6, gridHeight()+25, QString::number(i*5)); else if (i == 20) paint.drawText(x-9, gridHeight()+25, QString::number(i*5)); paint.setPen(QPen((i == 0 || i == 8 || i == 11 || i == 14) ? Qt::black : Qt::lightGray, (i == 0) ? 2 : 1)); paint.drawLine(x, BORDER_TOP, x, gridHeight()+BORDER_TOP); } paint.setPen(Qt::black); paint.setFont(boldFont); paint.drawText(BORDER_LEFT+gridWidth(), 25+gridHeight(), "dB"); paint.setFont(QFont()); // Paint the horizontal axes for (int i = 0; i < 21; ++i) { int y = BORDER_TOP + i*gridHeight()/20; if (i % 2 == 0) { paint.setPen(Qt::black); paint.drawText(15 + 6*((i/20) + (i == 0 ? 0 : 1)), y+6, QString::number((20-i)*5)); } paint.setPen(QPen((i == 10 || i == 20) ? Qt::black : Qt::lightGray, (i == 20) ? 2 : 1)); paint.drawLine(BORDER_LEFT+1, y, BORDER_LEFT+gridWidth(), y); } paint.setPen(Qt::black); paint.setFont(boldFont); paint.drawText(34, 8, "%"); paint.setFont(QFont()); // Tekenen van de curve int minY = BORDER_TOP; int maxY = BORDER_TOP + gridHeight(); paint.setPen(Qt::black); for (int x = BORDER_LEFT; x < BORDER_LEFT + 2*(gridWidth()/22); ++x) { double xx1 = (x - BORDER_LEFT*1.0) / (4.0*(gridWidth()/22.0) / 20.0); double yy1 = (3.0/5.0)*xx1*xx1 - xx1; double xx2 = (x - BORDER_LEFT*1.0 + 1.0) / (4.0*(gridWidth()/22.0) / 20.0); double yy2 = (3.0/5.0)*xx2*xx2 - xx2; int y1 = std::min(static_cast<int> (BORDER_TOP + ((100.0 - yy1) * gridHeight())/100.0), maxY); int y2 = std::min(static_cast<int> (BORDER_TOP + ((100.0 - yy2) * gridHeight())/100.0), maxY); paint.drawLine(x, y1, x+1, y2); } for (int x = BORDER_LEFT + 2*(gridWidth()/22); x < BORDER_LEFT + 4*(gridWidth()/22); ++x) { double xx1 = (x - BORDER_LEFT*1.0) / (4.0*(gridWidth()/22.0) / 20.0); double yy1 = (-3.0/5.0)*xx1*xx1 + 23.0*xx1 - 120.0; double xx2 = (x - BORDER_LEFT*1.0 + 1.0) / (4.0*(gridWidth()/22.0) / 20.0); double yy2 = (-3.0/5.0)*xx2*xx2 + 23.0*xx2 - 120.0; int y1 = std::max(static_cast<int> (BORDER_TOP + ((100.0 - yy1) * gridHeight())/100.0), minY); int y2 = std::max(static_cast<int> (BORDER_TOP + ((100.0 - yy2) * gridHeight())/100.0), minY); paint.drawLine(x, y1, x+1, y2); } }
void MajorityVoteProblem::writeSingleTimeHDF5(hid_t currentDataGroup, const char *buffer, size_t bufferStep, hid_t bufferType) { if (m_individual) { // just call the standard implementation DiffusionModel::writeSingleTimeHDF5(currentDataGroup, buffer, bufferStep, bufferType); } if (m_isNonDiffusive) { std::cout <<"MajorityVoteProblem::writeSingleTimeHDF5 called for non-diffusive system.\n"; // we assume that the buffer is int .. const int *iBuffer = &(runState().front()); // we need two new buffers int *iReds = new int[gridArea()]; int *iGreens = new int[gridArea()]; int scount = 0; // running counter for species // initialize buffers for (int x=0; x<gridWidth(); x++) { for (int y=0; y<gridHeight(); y++) { iReds[x+y*gridWidth()]=0; iGreens[x+y*gridWidth()]=0; } } for (int x=0; x<gridWidth(); x++) { for (int y=0; y<gridHeight(); y++) { scount=0; BOOST_FOREACH(Species *s, species()) { // is it red or green? if ((s->id().c_str())[0]=='R') { //std::cout <<"Species "<<s->id().c_str()<<" is RED. Found "<<count <<" particles.\n"; iReds[x+y*gridWidth()] += iBuffer[x + y*gridWidth() + scount*gridArea()]; } else if ((s->id().c_str())[0]=='G') { //std::cout <<"Species "<<s->id().c_str()<<" is GREEN. Found "<<count <<" particles.\n"; iGreens[x+y*gridWidth()] += iBuffer[x + y*gridWidth() + scount*gridArea()]; } else { //std::cout <<"Species "<<s->id().c_str()<<" is UNKNOWN. Found "<<count <<" particles.\n"; } // increase species index scount++; } // DEBUG: check if total species count agrees for each cell //if ((iReds[x+y*gridWidth()] + iGreens[x+y*gridWidth()]) != 150) { // std::cerr <<"ERROR: at x="<<x<<" and y = "<<y<<" we find r="<<iReds[x+y*gridWidth()]<<" and g="<<iGreens[x+y*gridWidth()]<<".\n"<<std::flush; // exit(1); // } } // dimensions of the dataset std::cout <<"Grid dimensions are: "<<gridWidth()<<" x "<<gridHeight()<<".\n"; hsize_t dims[2]; dims[0] = gridWidth(); dims[1] = gridHeight(); // data set and data space hid_t dataspace, dataset; // status variable herr_t status; dataspace = H5Screate_simple(2, dims, 0); dataset = H5Dcreate2(currentDataGroup, "Red", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, iReds); status = H5Dclose(dataset); status = H5Sclose(dataspace); dataspace = H5Screate_simple(2, dims, 0); dataset = H5Dcreate2(currentDataGroup, "Green", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, iGreens); status = H5Dclose(dataset); status = H5Sclose(dataspace); // delete temp buffers delete iReds; delete iGreens; } else {