QRegion QvisColorGridWidget::drawHighlightedColor(QPainter* paint, int index) { QRegion retval; if (drawPixmap && index >= 0) { // Get the location of the index'th color box. int _x, _y, boxWidth, boxHeight; getColorRect(index, _x, _y, boxWidth, boxHeight); QRect r(_x - boxPaddingValue / 2, _y - boxPaddingValue / 2, boxWidth + boxPaddingValue, boxHeight + boxPaddingValue); // Draw the button and the color over the button. if (paint == 0) { QPainter p2(drawPixmap); drawBox(p2, r, palette().light().color(), palette().dark().color()); drawColor(p2, index); } else { drawBox(*paint, r, palette().light().color(), palette().dark().color()); drawColor(*paint, index); } // return the region that we drew on. retval = QRegion(_x - boxPaddingValue / 2, _y - boxPaddingValue / 2, boxWidth + boxPaddingValue, boxHeight + boxPaddingValue); } return retval; }
// add force and dye to fluid, and create particles void FluidParticles::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce ) { float speed = vel.x * vel.x + vel.y * vel.y * aspectRatio * aspectRatio; // balance the x and y components of speed with the screen aspect ratio if( speed > 0 ) { pos.x = constrain( pos.x, 0.0f, 1.0f ); pos.y = constrain( pos.y, 0.0f, 1.0f ); const float colorMult = 100; const float velocityMult = 30; float scalar = ( elapsedFrames % 360 ) / 360.0f; if( addColor ) { Color drawColor( CM_HSV, scalar, scalar, scalar ); fluidSolver.addColorAtPos( pos, drawColor * colorMult ); if( drawParticles ) particleSystem.addParticles( pos * Vec2f( surfaceSize ), 10 ); } if( addForce ) fluidSolver.addForceAtPos( pos, vel * velocityMult ); if( ! drawFluid && elapsedFrames%5==0 ) fadeToColor( 0, 0, 0, 0.1f ); } }
// add force and dye to fluid, and create particles void msaFluidParticlesApp::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce ) { float speed = vel.x * vel.x + vel.y * vel.y * getWindowAspectRatio() * getWindowAspectRatio(); // balance the x and y components of speed with the screen aspect ratio if( speed > 0 ) { pos.x = constrain( pos.x, 0.0f, 1.0f ); pos.y = constrain( pos.y, 0.0f, 1.0f ); const float colorMult = 100; const float velocityMult = 30; if( addColor ) { Color drawColor( CM_HSV, ( getElapsedFrames() % 360 ) / 360.0f, 1, 1 ); fluidSolver.addColorAtPos( pos, drawColor * colorMult ); if( drawParticles ) particleSystem.addParticles( pos * Vec2f( getWindowSize() ), 10 ); } if( addForce ) fluidSolver.addForceAtPos( pos, vel * velocityMult ); if( ! drawFluid && getElapsedFrames()%5==0 ) fadeToColor( 0, 0, 0, 0.1f ); } }
//-------------------------------------------------------------- void DrawerBase::draw(float x, float y, float renderWidth, float renderHeight) const { if(enabled == false) return; switch(drawMode) { case kDrawColor: drawColor(x, y, renderWidth, renderHeight); break; case kDrawMotion: drawMotion(x, y, renderWidth, renderHeight); break; case kDrawSpeed: drawSpeed(x, y, renderWidth, renderHeight); break; case kDrawVectors: drawVectors(x, y, renderWidth, renderHeight); break; default: break; } }
void UBGraphicsCompass::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { Q_UNUSED(styleOption); Q_UNUSED(widget); mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); QTransform antiScaleTransform; antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio); mCloseSvgItem->setTransform(antiScaleTransform); mCloseSvgItem->setPos( closeButtonRect().center().x() - mCloseSvgItem->boundingRect().width() * mAntiScaleRatio / 2, closeButtonRect().center().y() - mCloseSvgItem->boundingRect().height() * mAntiScaleRatio / 2); mResizeSvgItem->setTransform(antiScaleTransform); mResizeSvgItem->setPos( resizeButtonRect().center().x() - mResizeSvgItem->boundingRect().width() * mAntiScaleRatio / 2, resizeButtonRect().center().y() - mResizeSvgItem->boundingRect().height() * mAntiScaleRatio / 2); painter->setPen(drawColor()); painter->drawRoundedRect(hingeRect(), 4, 4); painter->fillPath(hingeShape(), middleFillColor()); painter->fillPath(needleShape(), middleFillColor()); painter->drawPath(needleShape()); painter->fillPath(needleBaseShape(), middleFillColor()); painter->drawPath(needleBaseShape()); QLinearGradient needleArmLinearGradient( QPointF(rect().left() + sNeedleLength + sNeedleBaseLength, rect().center().y()), QPointF(hingeRect().left(), rect().center().y())); needleArmLinearGradient.setColorAt(0, edgeFillColor()); needleArmLinearGradient.setColorAt(1, middleFillColor()); painter->fillPath(needleArmShape(), needleArmLinearGradient); painter->drawPath(needleArmShape()); QRectF hingeGripRect(rect().center().x() - 16, rect().center().y() - 16, 32, 32); painter->drawEllipse(hingeGripRect); if (mShowButtons) paintAngleDisplay(painter); QLinearGradient pencilArmLinearGradient( QPointF(hingeRect().right(), rect().center().y()), QPointF(rect().right() - sPencilLength - sPencilBaseLength, rect().center().y())); pencilArmLinearGradient.setColorAt(0, middleFillColor()); pencilArmLinearGradient.setColorAt(1, edgeFillColor()); painter->fillPath(pencilArmShape(), pencilArmLinearGradient); painter->drawPath(pencilArmShape()); if (scene()->isDarkBackground()) painter->fillPath(pencilShape(), UBApplication::boardController->penColorOnDarkBackground()); else painter->fillPath(pencilShape(), UBApplication::boardController->penColorOnLightBackground()); painter->fillPath(pencilBaseShape(), middleFillColor()); painter->drawPath(pencilBaseShape()); if (mResizing || mRotating || mDrawing || (mShowButtons && rect().width() > sDisplayRadiusOnPencilArmMinLength)) paintRadiusDisplay(painter); }
void QvisColorGridWidget::drawColorArray() { // Fill the pixmap with the background color or draw a frame. QPainter paint(drawPixmap); #ifdef Q_WS_MACX paint.fillRect(rect(), palette().brush(QPalette::Background)); #else paint.fillRect(rect(), palette().brush(QPalette::Button)); #endif if (drawFrame) { drawBox(paint, rect(), palette().light().color(), palette().dark().color()); } // Draw all of the color boxes. int index = 0; for (int i = 0; i < numRows; ++i) { for (int j = 0; j < numColumns; ++j, ++index) { if (index < numPaletteColors) { if (index == currentSelectedColor) drawSelectedColor(&paint, index); else if (index == activeColorIndex()) drawHighlightedColor(&paint, index); else drawColor(paint, index); } } } }
void UBGraphicsRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { Q_UNUSED(styleOption); Q_UNUSED(widget); UBAbstractDrawRuler::paint(); QTransform antiScaleTransform2; qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0; antiScaleTransform2.scale(ratio, 1.0); mResizeSvgItem->setTransform(antiScaleTransform2); mResizeSvgItem->setPos(resizeButtonRect().topLeft()); mRotateSvgItem->setTransform(antiScaleTransform2); mRotateSvgItem->setPos(rotateButtonRect().topLeft()); painter->setPen(drawColor()); painter->setRenderHint(QPainter::Antialiasing, true); painter->drawRoundedRect(rect(), sRoundingRadius, sRoundingRadius); fillBackground(painter); paintGraduations(painter); if (mRotating) paintRotationCenter(painter); }
// Draw Data void Kinect::draw() { // Draw Color drawColor(); // Draw Depth drawDepth(); }
// Draw Data void Kinect::draw() { // Draw Color drawColor(); // Draw Recognition drawRecognition(); }
void ColorWheel::composeWheel() { QPainter composePainter(&wheel); composePainter.drawImage(0, 0, wheelImage); composePainter.end(); drawIndicator(current.hue()); drawColor(innerColor); }
void QgsColorPreviewWidget::paintEvent( QPaintEvent *event ) { Q_UNUSED( event ); QPainter painter( this ); if ( mColor2.isValid() ) { //drawing with two color sections int verticalSplit = qRound( height() / 2.0 ); drawColor( mCurrentColor, QRect( 0, 0, width(), verticalSplit ), painter ); drawColor( mColor2, QRect( 0, verticalSplit, width(), height() - verticalSplit ), painter ); } else if ( mCurrentColor.isValid() ) { drawColor( mCurrentColor, QRect( 0, 0, width(), height() ), painter ); } painter.end(); }
QRegion QvisColorGridWidget::drawUnHighlightedColor(QPainter* paint, int index) { QRegion retval; if (drawPixmap && index >= 0) { // Get the location of the index'th color box. int _x, _y, boxWidth, boxHeight; getColorRect(index, _x, _y, boxWidth, boxHeight); #ifdef Q_WS_MACX QBrush brush(palette().brush(QPalette::Background)); #else QBrush brush(palette().brush(QPalette::Button)); #endif // Draw the button and the color over the button. if (paint == 0) { QPainter p2(drawPixmap); p2.fillRect(_x - boxPaddingValue / 2, _y - boxPaddingValue / 2, boxWidth + boxPaddingValue, boxHeight + boxPaddingValue, brush); drawColor(p2, index); } else { paint->fillRect(_x - boxPaddingValue / 2, _y - boxPaddingValue / 2, boxWidth + boxPaddingValue, boxHeight + boxPaddingValue, brush); drawColor(*paint, index); } // return the region that we drew on. retval = QRegion(_x - boxPaddingValue / 2, _y - boxPaddingValue / 2, boxWidth + boxPaddingValue, boxHeight + boxPaddingValue); } return retval; }
void UBGraphicsProtractor::paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget) { painter->save(); Q_UNUSED(styleOption); Q_UNUSED(widget); painter->setFont(QFont("Arial")); painter->setPen(drawColor()); painter->setBrush(fillBrush()); painter->drawPie(QRectF(rect().center().x() - radius(), rect().center().y() - radius(), 2 * radius(), 2 * radius()), mStartAngle * 16, mSpan * 16); paintGraduations(painter); paintButtons(painter); paintAngleMarker(painter); painter->restore(); }
//-------------------------------------------------------------- void FingerTracker::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce ) { float speed = vel.x * vel.x + vel.y * vel.y * getWindowAspectRatio() * getWindowAspectRatio(); if(speed > 0) { pos.x = constrain(pos.x, 0.0f, 1.0f); pos.y = constrain(pos.y, 0.0f, 1.0f); const float colorMult = 100; const float velocityMult = 30; int index = fluidSolver.getIndexForPos(pos); if(addColor) { Color drawColor( CM_HSV, ( getElapsedFrames() % 360 ) / 360.0f, 1, 1 ); fluidSolver.addColorAtIndex(index, drawColor * colorMult); if(drawParticles) { particleSystem.addParticlesWithVelc( pos*Vec2f(getWindowSize()), vel*Vec2f(getWindowSize()), 2 ); } } if(addForce) fluidSolver.addForceAtIndex(index, vel * velocityMult); } }
void UBGraphicsCurtainItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QColor color = drawColor(); if(widget == UBApplication::boardController->controlView()->viewport()) { color = UBSettings::paletteColor; if(!UBApplication::applicationController->displayManager()->hasDisplay()) { color = opaqueControlColor(); } } // Never draw the rubber band, we draw our custom selection with the DelegateFrame QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option); styleOption.state &= ~QStyle::State_Selected; painter->fillRect(rect(), color); }
void FluidParticles::update() { Vec2f boidNorm, boidVel; for (int i = 0; i < boids->numBoids(); i++) { float scalar = linlin((float)i, 0.0, (float)boids->numBoids() - 1, 120.0, 240.0) / 360.0; Color drawColor( CM_HSV, scalar, 1, 1); boidNorm = unmapVec2f(boids->getBoidAtIndex(i)->pos.xy(), 0, 400.0) ; boidVel = boids->getBoidAtIndex(i)->vec.xy(); addToFluidWithColor( boidNorm, boidVel, drawColor, true ); } if( resizeFluid ) { fluidSolver.setSize(fluidCellsX, fluidCellsX / aspectRatio ); fluidDrawer.setup(&fluidSolver); resizeFluid = false; } fluidSolver.update(); }
void ofxMSAFluidDrawer::draw(float x, float y, float renderWidth, float renderHeight) { switch(drawMode) { case FLUID_DRAW_COLOR: drawColor(x, y, renderWidth, renderHeight); break; case FLUID_DRAW_MOTION: drawMotion(x, y, renderWidth, renderHeight); break; case FLUID_DRAW_SPEED: drawSpeed(x, y, renderWidth, renderHeight); break; case FLUID_DRAW_VECTORS: drawVectors(x, y, renderWidth, renderHeight); break; } }
void QvisColorGridWidget::setPaletteColor(const QColor& color, int index) { if (index >= 0 && index < numPaletteColors) { // If the colors are different, update the widget. if (color != paletteColors[index]) { QRegion region; // Replace the color paletteColors[index] = color; // Redraw the color in the appropriate manner. if (index == currentSelectedColor) region = drawSelectedColor(0, index); else if (index == activeColorIndex()) region = drawHighlightedColor(0, index); else { int _x, _y, w, h; getColorRect(index, _x, _y, w, h); region = QRegion(_x, _y, w, h); if (drawPixmap) { QPainter paint(drawPixmap); drawColor(paint, index); } } // Repaint the region that was changed. if (isVisible()) repaint(region); else if (drawPixmap) { delete drawPixmap; drawPixmap = 0; } } } }
void Node::draw(const LayerPtr& currentLayer) { if (transformDirty) { calculateTransform(); } if (currentLayer) { if (currentLayer->getCamera()) { graphics::Color drawColor(color.r, color.g, color.b, static_cast<uint8_t>(color.a * opacity)); for (const DrawablePtr& drawable : drawables) { if (drawable->isVisible()) { drawable->draw(currentLayer->getCamera()->getViewProjection(), transform, drawColor); } } } } }
bool Percolation::percolate(PNG* pic) { queue<site> q; q.push(sites[dsetIndex(Width/2,0)]); site* cur; while(!q.empty()) { cur=&q.front(); q.pop(); int x=cur->x; int y=cur->y; if(canTravel(x,y,0) && sites[dsetIndex(x+1,y)].status==false) { //sites[dsetIndex(x+1,y)].dist=sites[dsetIndex(x,y)].dist+1; //sites[dsetIndex(x+1,y)].path=&sites[dsetIndex(x,y)]; sites[dsetIndex(x+1,y)].status=true; q.push(sites[dsetIndex(x+1,y)]); //drawSite(pic,x,y,0); } if(canTravel(x,y,1) && sites[dsetIndex(x,y+1)].status==false) { //sites[dsetIndex(x,y+1)].dist=sites[dsetIndex(x,y)].dist+1; //sites[dsetIndex(x,y+1)].path=&sites[dsetIndex(x,y)]; sites[dsetIndex(x,y+1)].status=true; q.push(sites[dsetIndex(x,y+1)]); //drawSite(pic,x,y,1); } if(canTravel(x,y,2) && sites[dsetIndex(x-1,y)].status==false) { //sites[dsetIndex(x-1,y)].dist=sites[dsetIndex(x,y)].dist+1; //sites[dsetIndex(x-1,y)].path=&sites[dsetIndex(x,y)]; sites[dsetIndex(x-1,y)].status=true; q.push(sites[dsetIndex(x-1,y)]); //drawSite(pic,x,y,2); } if(canTravel(x,y,3) && sites[dsetIndex(x,y-1)].status==false) { //sites[dsetIndex(x,y-1)].dist=sites[dsetIndex(x,y)].dist+1; //sites[dsetIndex(x,y-1)].path=&sites[dsetIndex(x,y)]; sites[dsetIndex(x,y-1)].status=true; q.push(sites[dsetIndex(x,y-1)]); //drawSite(pic,x,y,3); } sites[dsetIndex(x,y)].status=true; }//while //site* longest; //longest=&sites[dsetIndex(0,Height-1)]; //int best=longest->dist; bool result=false; for(int i=0;i<Width;i++) { if(dset.find(dsetIndex(i,Height-1)) == dset.find(dsetIndex(Width/2,0)) ) { q.push(sites[dsetIndex(i,Height-1)]); sites[dsetIndex(i,Height-1)].status=true; result= true; } } drawColor(pic); return result; }
void drawFrame() { // calculate locations g_DrawConfig.DepthLocation.uBottom = 0; g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y - 1; g_DrawConfig.DepthLocation.uLeft = 0; g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X - 1; g_DrawConfig.ColorLocation.uBottom = 0; g_DrawConfig.ColorLocation.uTop = WIN_SIZE_Y - 1; g_DrawConfig.ColorLocation.uLeft = 0; g_DrawConfig.ColorLocation.uRight = WIN_SIZE_X - 1; if (g_DrawConfig.Streams.ScreenArrangement == SIDE_BY_SIDE) { g_DrawConfig.DepthLocation.uTop = WIN_SIZE_Y / 2 - 1; g_DrawConfig.DepthLocation.uRight = WIN_SIZE_X / 2 - 1; g_DrawConfig.ColorLocation.uTop = WIN_SIZE_Y / 2 - 1; g_DrawConfig.ColorLocation.uLeft = WIN_SIZE_X / 2; } // Texture map init openni::VideoFrameRef* pDepthMD = &getDepthFrame(); if (isDepthOn() && pDepthMD->isValid()) { int maxDepth = 0; maxDepth = getDepthStream().getMaxPixelValue(); g_fMaxDepth = maxDepth; TextureMapInit(&g_texDepth, pDepthMD->getVideoMode().getResolutionX(), pDepthMD->getVideoMode().getResolutionY(), 4, pDepthMD->getWidth(), pDepthMD->getHeight()); fixLocation(&g_DrawConfig.DepthLocation, pDepthMD->getVideoMode().getResolutionX(), pDepthMD->getVideoMode().getResolutionY()); } openni::VideoFrameRef* pImageMD = NULL; if (isColorOn()) { pImageMD = &getColorFrame(); } else if (isIROn()) { pImageMD = &getIRFrame(); } if (pImageMD != NULL && pImageMD->isValid()) { TextureMapInit(&g_texColor, pImageMD->getVideoMode().getResolutionX(), pImageMD->getVideoMode().getResolutionY(), 4, pImageMD->getWidth(), pImageMD->getHeight()); fixLocation(&g_DrawConfig.ColorLocation, pImageMD->getVideoMode().getResolutionX(), pImageMD->getVideoMode().getResolutionY()); } // check if pointer is over a map bool bOverDepth = (pDepthMD != NULL && pDepthMD->isValid()) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.DepthLocation); bool bOverImage = (pImageMD != NULL && pImageMD->isValid()) && isPointInRect(g_DrawUserInput.Cursor, &g_DrawConfig.ColorLocation); bool bDrawDepthPointer = false; bool bDrawImagePointer = false; int imagePointerRed = 255; int imagePointerGreen = 0; int imagePointerBlue = 0; IntPair pointerInDepth = {0,0}; IntPair pointerInColor = {0,0}; if (bOverImage) { pointerInColor.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.ColorLocation.uLeft) / (g_DrawConfig.ColorLocation.uRight - g_DrawConfig.ColorLocation.uLeft + 1) * pImageMD->getVideoMode().getResolutionX(); pointerInColor.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.ColorLocation.uBottom) / (g_DrawConfig.ColorLocation.uTop - g_DrawConfig.ColorLocation.uBottom + 1) * pImageMD->getVideoMode().getResolutionY(); bDrawImagePointer = true; } if (bOverDepth) { pointerInDepth.X = (double)(g_DrawUserInput.Cursor.X - g_DrawConfig.DepthLocation.uLeft) / (g_DrawConfig.DepthLocation.uRight - g_DrawConfig.DepthLocation.uLeft + 1) * pDepthMD->getVideoMode().getResolutionX(); pointerInDepth.Y = (double)(g_DrawUserInput.Cursor.Y - g_DrawConfig.DepthLocation.uBottom) / (g_DrawConfig.DepthLocation.uTop - g_DrawConfig.DepthLocation.uBottom + 1) * pDepthMD->getVideoMode().getResolutionY(); bDrawDepthPointer = true; if (!bOverImage && g_DrawConfig.bShowPointer && pointerInDepth.X >= pDepthMD->getCropOriginX() && pointerInDepth.X < (pDepthMD->getCropOriginX() + pDepthMD->getWidth()) && pointerInDepth.Y >= pDepthMD->getCropOriginY() && pointerInDepth.Y < (pDepthMD->getCropOriginY() + pDepthMD->getHeight())) { // try to translate depth pixel to image openni::DepthPixel* pDepthPixels = (openni::DepthPixel*)pDepthMD->getData(); openni::DepthPixel pointerDepth = pDepthPixels[(pointerInDepth.Y - pDepthMD->getCropOriginY()) * pDepthMD->getWidth() + (pointerInDepth.X - pDepthMD->getCropOriginX())]; if (convertDepthPointToColor(pointerInDepth.X, pointerInDepth.Y, pointerDepth, &pointerInColor.X, &pointerInColor.Y)) { bDrawImagePointer = true; imagePointerRed = 0; imagePointerGreen = 0; imagePointerBlue = 255; } } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Setup the opengl env for fixed location view glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0,WIN_SIZE_X,WIN_SIZE_Y,0,-1.0,1.0); glDisable(GL_DEPTH_TEST); if (g_DrawConfig.Streams.Depth.Coloring == CYCLIC_RAINBOW_HISTOGRAM || g_DrawConfig.Streams.Depth.Coloring == LINEAR_HISTOGRAM || g_DrawConfig.bShowPointer) calculateHistogram(); drawColor(&g_DrawConfig.ColorLocation, bDrawImagePointer ? &pointerInColor : NULL, imagePointerRed, imagePointerGreen, imagePointerBlue); drawDepth(&g_DrawConfig.DepthLocation, bDrawDepthPointer ? &pointerInDepth : NULL); printRecordingInfo(); if (g_DrawConfig.bShowPointer) drawPointerMode(bOverDepth ? &pointerInDepth : NULL); drawUserInput(!bOverDepth && !bOverImage); drawUserMessage(); drawPlaybackSpeed(); if (g_DrawConfig.strErrorState[0] != '\0') drawErrorState(); if (g_DrawConfig.bHelp) drawHelpScreen(); glutSwapBuffers(); }
void BrushToolEdit::drawInner(const QPoint &pt, float strength) { float fixedStrength = params.strength; strength *= fixedStrength; auto color = params.color; std::array<int, 3> colorParts = Terrain::expandColor(color); __m128 colorMM = _mm_setr_ps(colorParts[0], colorParts[1], colorParts[2], 0); SseRoundingModeScope roundingModeScope(_MM_ROUND_NEAREST); (void) roundingModeScope; switch (tool->type()) { case BrushType::Blur: drawBlur(pt, std::min(strength / 5.f, 4.f)); break; case BrushType::Smoothen: drawSmoothen(pt, std::min(strength / 5.f, 4.f)); break; case BrushType::Raise: case BrushType::Lower: if (tool->type() == BrushType::Lower) { fixedStrength = -fixedStrength; strength = -strength; } switch (params.pressureMode) { case BrushPressureMode::AirBrush: strength *= 3.f; drawRaiseLower(pt, [=](float ¤t, float before, float tip) { (void) before; current -= tip * strength; }); break; case BrushPressureMode::Constant: if (tool->type() == BrushType::Lower) { drawRaiseLower(pt, [=](float ¤t, float before, float tip) { current = Terrain::quantizeOne(std::max(current, before - tip * fixedStrength)); }); } else { drawRaiseLower(pt, [=](float ¤t, float before, float tip) { current = Terrain::quantizeOne(std::min(current, before - tip * fixedStrength)); }); } break; case BrushPressureMode::Adjustable: drawRaiseLower(pt, [=](float ¤t, float before, float tip) { current = Terrain::quantizeOne(before - tip * strength); }); break; } break; case BrushType::Paint: switch (params.pressureMode) { case BrushPressureMode::AirBrush: strength = 1.f - std::exp2(-strength); drawColor(pt, [=](quint32 ¤t, quint32 before, float tip) { (void) before; // convert current color to FP32 auto currentMM = _mm_castps_si128(_mm_load_ss(reinterpret_cast<float *>(¤t))); currentMM = _mm_unpacklo_epi8(currentMM, _mm_setzero_si128()); currentMM = _mm_unpacklo_epi16(currentMM, _mm_setzero_si128()); auto currentMF = _mm_cvtepi32_ps(currentMM); auto factor = _mm_set1_ps(tip * strength); // blend auto diff = _mm_sub_ps(colorMM, currentMF); diff = _mm_mul_ps(diff, factor); currentMF = _mm_add_ps(currentMF, diff); // convert to RGB32 currentMF = _mm_add_ps(currentMF, globalDitherSampler.getM128()); currentMM = _mm_cvttps_epi32(currentMF); currentMM = _mm_packs_epi32(currentMM, currentMM); currentMM = _mm_packus_epi16(currentMM, currentMM); _mm_store_ss(reinterpret_cast<float *>(¤t), _mm_castsi128_ps(currentMM)); }); break; case BrushPressureMode::Constant: fixedStrength *= 0.01f; drawColor(pt, [=](quint32 ¤t, quint32 before, float tip) { // convert current color to FP32 auto currentMM = _mm_castps_si128(_mm_load_ss(reinterpret_cast<float *>(¤t))); currentMM = _mm_unpacklo_epi8(currentMM, _mm_setzero_si128()); currentMM = _mm_unpacklo_epi16(currentMM, _mm_setzero_si128()); auto currentMF = _mm_cvtepi32_ps(currentMM); // convert before color to FP32 auto beforeMM = _mm_setr_epi32(before, 0, 0, 0); beforeMM = _mm_unpacklo_epi8(beforeMM, _mm_setzero_si128()); beforeMM = _mm_unpacklo_epi16(beforeMM, _mm_setzero_si128()); auto beforeMF = _mm_cvtepi32_ps(beforeMM); // beforeMM = _mm_add_ps(beforeMM, globalDitherSampler.getM128()); // use "before" image to which way of color change is possible, and // compute possible range of result color auto diff = _mm_sub_ps(colorMM, beforeMF); auto factor = _mm_set1_ps(tip * fixedStrength); auto adddiff = _mm_mul_ps(diff, factor); beforeMF = _mm_add_ps(beforeMF, adddiff); auto diffDir = _mm_cmpgt_ps(diff, _mm_setzero_ps()); // compute output image auto out1 = _mm_max_ps(currentMF, beforeMF); auto out2 = _mm_min_ps(currentMF, beforeMF); currentMF = _mm_or_ps(_mm_and_ps(diffDir, out1), _mm_andnot_ps(diffDir, out2)); // convert to RGB32 currentMF = _mm_add_ps(currentMF, globalDitherSampler.getM128()); currentMM = _mm_cvttps_epi32(currentMF); currentMM = _mm_packs_epi32(currentMM, currentMM); currentMM = _mm_packus_epi16(currentMM, currentMM); _mm_store_ss(reinterpret_cast<float *>(¤t), _mm_castsi128_ps(currentMM)); }); break; case BrushPressureMode::Adjustable: strength *= 0.01f; drawColor(pt, [=](quint32 ¤t, quint32 before, float tip) { // convert before color to FP32 auto beforeMM = _mm_setr_epi32(before, 0, 0, 0); beforeMM = _mm_unpacklo_epi8(beforeMM, _mm_setzero_si128()); beforeMM = _mm_unpacklo_epi16(beforeMM, _mm_setzero_si128()); auto beforeMF = _mm_cvtepi32_ps(beforeMM); // blend auto diff = _mm_sub_ps(colorMM, beforeMF); auto factor = _mm_set1_ps(tip * strength); diff = _mm_mul_ps(diff, factor); beforeMF = _mm_add_ps(beforeMF, diff); // convert to RGB32 beforeMF = _mm_add_ps(beforeMF, globalDitherSampler.getM128()); beforeMM = _mm_cvttps_epi32(beforeMF); beforeMM = _mm_packs_epi32(beforeMM, beforeMM); beforeMM = _mm_packus_epi16(beforeMM, beforeMM); _mm_store_ss(reinterpret_cast<float *>(¤t), _mm_castsi128_ps(beforeMM)); }); break; } break; } }
void MainWindow::createActions() /*菜单选项*/ { /*文件菜单*/ openAction = new QAction(tr("打开"),this); openAction->setStatusTip(tr("打开新文件")); connect(openAction,SIGNAL(triggered()),this,SLOT(openFile())); importAction = new QAction(tr("导入"),this); importAction->setStatusTip(tr("导入数据")); connect(importAction,SIGNAL(triggered()),this,SLOT(importFile())); importAction->setDisabled(true); sortAction = new QAction(tr("分类数据"),this); sortAction->setStatusTip(tr("处理分类数据")); connect(sortAction,SIGNAL(triggered()),this,SLOT(sortFile())); sortAction->setDisabled(true); exitAction = new QAction(tr("退出"),this); exitAction->setStatusTip(tr("退出程序")); connect(exitAction,SIGNAL(triggered()),this,SLOT(close())); /*导入菜单*/ ebdicAction = new QAction(tr("显示EBDIC码"),this); ebdicAction->setStatusTip(tr("显示EBDIC码")); connect(ebdicAction,SIGNAL(triggered()),this,SLOT(loadEBDIC())); ebdicAction->setDisabled(true); reelAction = new QAction(tr("显示卷头"),this); reelAction->setStatusTip(tr("显示卷头信息")); connect(reelAction,SIGNAL(triggered()),this,SLOT(loadReel())); reelAction->setDisabled(true); traceAction = new QAction(tr("显示道头"),this); traceAction->setStatusTip(tr("显示选定位置道头信息")); connect(traceAction,SIGNAL(triggered()),this,SLOT(loadTrace())); traceAction->setDisabled(true); dataAction = new QAction(tr("地震数据"),this); dataAction->setStatusTip(tr("显示选定位置的地震记录")); connect(dataAction,SIGNAL(triggered()),this,SLOT(loadData())); dataAction->setDisabled(true); /*画图菜单*/ waveAction = new QAction(tr("波形显示"),this); waveAction->setStatusTip(tr("波形显示剖面")); connect(waveAction,SIGNAL(triggered()),this,SLOT(drawWave())); waveAction->setDisabled(true); grayAction = new QAction(tr("灰度显示"),this); grayAction->setStatusTip(tr("显示灰度图像")); connect(grayAction,SIGNAL(triggered()),this,SLOT(drawGray())); grayAction->setDisabled(true); colorAction = new QAction(tr("彩色显示"),this); colorAction->setStatusTip(tr("显示彩色图像")); connect(colorAction,SIGNAL(triggered()),this,SLOT(drawColor())); colorAction->setDisabled(true); //操作openGL图像 bigAction = new QAction(tr("放大"),this); bigAction->setStatusTip(tr("放大图像")); connect(bigAction,SIGNAL(triggered()),this,SLOT(bigger())); bigAction->setDisabled(true); littleAction = new QAction(tr("缩小"),this); littleAction->setStatusTip(tr("缩小图像")); connect(littleAction,SIGNAL(triggered()),this,SLOT(little())); littleAction->setDisabled(true); moveleftAction = new QAction(tr("左移"),this); moveleftAction->setStatusTip(tr("左移图像")); connect(moveleftAction,SIGNAL(triggered()),this,SLOT(moveleft())); moveleftAction->setDisabled(true); moverightAction = new QAction(tr("右移"),this); moverightAction->setStatusTip(tr("图像右移")); connect(moverightAction,SIGNAL(triggered()),this,SLOT(moveright())); moverightAction->setDisabled(true); moveupAction = new QAction(tr("上移"),this); moveupAction->setStatusTip(tr("上移图像")); connect(moveupAction,SIGNAL(triggered()),this,SLOT(moveup())); moveupAction->setDisabled(true); movedownAction = new QAction(tr("下移"),this); movedownAction->setStatusTip(tr("下移图像")); connect(movedownAction,SIGNAL(triggered()),this,SLOT(movedown())); movedownAction->setDisabled(true); moveMouseAction = new QAction(tr("移动"),this); moveMouseAction->setStatusTip(tr("使用鼠标移动图像")); connect(moveMouseAction,SIGNAL(triggered()),this,SLOT(moveMouse())); moveMouseAction->setDisabled(true); rotateMouseAction = new QAction(tr("旋转"),this); rotateMouseAction->setStatusTip(tr("旋转图像")); connect(rotateMouseAction,SIGNAL(triggered()),this,SLOT(rotateMouse())); rotateMouseAction->setDisabled(true); nextSliceAction = new QAction(tr("下一条剖面"),this); nextSliceAction->setStatusTip(tr("选择下一条剖面")); connect(nextSliceAction,SIGNAL(triggered()),this,SLOT(nextSlice())); nextSliceAction->setDisabled(true); preSliceAction = new QAction(tr("上一条剖面"),this); preSliceAction->setStatusTip(tr("选择上一条剖面")); connect(preSliceAction,SIGNAL(triggered()),this,SLOT(preSlice())); preSliceAction->setDisabled(true); drawGridAction = new QAction(tr("关闭网格"),this); drawGridAction->setStatusTip(tr("打开/关闭剖面图像上的网格")); connect(drawGridAction,SIGNAL(triggered()),this,SLOT(drawGrid())); drawGridAction->setDisabled(true); }
void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { painter->setPen(Qt::NoPen); QPolygonF polygon; QLinearGradient gradient1(QPointF(A1.x(), 0), QPointF(A2.x(), 0)); gradient1.setColorAt(0, edgeFillColor()); gradient1.setColorAt(1, middleFillColor()); painter->setBrush(gradient1); polygon << A1 << A2 << B2 << B1; painter->drawPolygon(polygon); polygon.clear(); QLinearGradient gradient2(QPointF(0, B1.y()), QPointF(0, B2.y())); gradient2.setColorAt(0, edgeFillColor()); gradient2.setColorAt(1, middleFillColor()); painter->setBrush(gradient2); polygon << B1 << B2 << C2 << C1; painter->drawPolygon(polygon); polygon.clear(); QLinearGradient gradient3(CC, C2); gradient3.setColorAt(0, edgeFillColor()); gradient3.setColorAt(1, middleFillColor()); painter->setBrush(gradient3); polygon << C1 << C2 << A2 << A1; painter->drawPolygon(polygon); polygon.clear(); painter->setBrush(Qt::NoBrush); painter->setPen(drawColor()); polygon << A1 << B1 << C1; painter->drawPolygon(polygon); polygon.clear(); polygon << A2 << B2 << C2; painter->drawPolygon(polygon); paintGraduations(painter); mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); QTransform antiScaleTransform; antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio); mCloseSvgItem->setTransform(antiScaleTransform); mHFlipSvgItem->setTransform(antiScaleTransform); mVFlipSvgItem->setTransform(antiScaleTransform); mRotateSvgItem->setTransform(antiScaleTransform); mCloseSvgItem->setPos(closeButtonRect().topLeft()); mHFlipSvgItem->setPos(hFlipRect().topLeft()); mVFlipSvgItem->setPos(vFlipRect().topLeft()); mRotateSvgItem->setPos(rotateRect().topLeft()); if (mShowButtons || mResizing1 || mResizing2) { painter->setBrush(QColor(0, 0, 0)); if (mShowButtons || mResizing1) painter->drawPolygon(resize1Polygon()); if (mShowButtons || mResizing2) painter->drawPolygon(resize2Polygon()); } }
void CGDIPracticeView::OnDraw(CDC* pDC) { CClientDC dc(this); //Client DC를 얻는다. // Client Rect를 얻는다. CRect rClientRect; GetClientRect(&rClientRect); // Bitmap 생성 Bitmap mBitmap(rClientRect.Width(), rClientRect.Height()); // Graphics를 얻는다. Graphics graphics(dc); // 비트맵을 메모리 내에서 그릴 그래픽 생성 Graphics memGraphics(&mBitmap); // 화면을 흰색 바탕으로 그리기 위한 브러쉬 SolidBrush drawBrush(Color(255,255,255)); // 검은색 컬러 지정 Color drawColor(255,0,0,0); // 팬 생성 Pen drawPen(drawColor, 1); drawPen.SetStartCap(LineCapRound); drawPen.SetEndCap(LineCapRound); // bitmap을 흰색으로 칠한다(line같은 경우 이미지가 남기 때문에) memGraphics.FillRectangle(&drawBrush, 0,0,rClientRect.Width(), rClientRect.Height()); int componentSize = m_components.GetSize(); CString str; str.Format(_T("size : %d\n"), componentSize); TRACE(str); for (int i = 0; i < componentSize; i++) { // 컴포넌트의 팬 설정 drawColor.SetFromCOLORREF(m_components.GetAt(i)->m_colorPen); drawPen.SetColor(drawColor); drawPen.SetWidth((float)m_components.GetAt(i)->m_nPenSize); // 얕은 복사 CDrawComponent *component = m_components.GetAt(i); switch (component->m_nDrawMode) { // 지우개인 경우 case DRAW_NONE: { // 팬의 브러쉬 색을 흰색으로 변경 drawBrush.SetColor(drawColor); // 지우개를 사용한 좌표를 순차적으로 다시 그린다. int pointSize = component->m_points.GetSize(); for (int j = 0; j < pointSize; j++) { // 흰색의 지우개 사각형을 그린다. memGraphics.FillRectangle(&drawBrush, component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y, component->m_nEraserSize * 2, component->m_nEraserSize * 2); } break; } case LINE_MODE: memGraphics.DrawLine(&drawPen, component->m_ptStart.x, component->m_ptStart.y, component->m_ptEnd.x, component->m_ptEnd.y); break; case RECT_MODE: { // 우측 아래 if(component->m_ptStart.x < component->m_ptEnd.x && component->m_ptStart.y < component->m_ptEnd.y) memGraphics.DrawRectangle(&drawPen, component->m_ptStart.x, component->m_ptStart.y, component->m_ptEnd.x - component->m_ptStart.x, component->m_ptEnd.y - component->m_ptStart.y); // 우측 위 else if(component->m_ptStart.x < component->m_ptEnd.x && component->m_ptStart.y > component->m_ptEnd.y) memGraphics.DrawRectangle(&drawPen, component->m_ptStart.x, component->m_ptEnd.y, component->m_ptEnd.x - component->m_ptStart.x, component->m_ptStart.y - component->m_ptEnd.y); // 좌측 아래 else if(component->m_ptStart.x > component->m_ptEnd.x && component->m_ptStart.y < component->m_ptEnd.y) memGraphics.DrawRectangle(&drawPen, component->m_ptEnd.x, component->m_ptStart.y, component->m_ptStart.x - component->m_ptEnd.x, component->m_ptEnd.y - component->m_ptStart.y); // 좌측 위 else memGraphics.DrawRectangle(&drawPen, component->m_ptEnd.x, component->m_ptEnd.y, component->m_ptStart.x - component->m_ptEnd.x, component->m_ptStart.y - component->m_ptEnd.y); break; } case CIRCLE_MODE: memGraphics.DrawEllipse(&drawPen, component->m_ptStart.x, component->m_ptStart.y, component->m_ptEnd.x - component->m_ptStart.x, component->m_ptEnd.y - component->m_ptStart.y); break; case FREE_MODE: if (component->m_points.GetSize() > 1) { // 자유선의 작은 선들을을 순차적으로 하나씩 그린다. int pointSize = component->m_points.GetSize(); for (int j = 1; j < pointSize; j++) memGraphics.DrawLine(&drawPen, component->m_points.GetAt(j - 1).X, component->m_points.GetAt(j - 1).Y, component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y); } break; case POLY_MODE: { int pointSize = component->m_points.GetSize(); for (int j = 1; j < pointSize; j++) memGraphics.DrawLine(&drawPen, component->m_points.GetAt(j-1).X, component->m_points.GetAt(j-1).Y, component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y); // 처음 점과 마지막점을 이어준다. memGraphics.DrawLine(&drawPen, component->m_points.GetAt(component->m_points.GetSize() - 1).X, component->m_points.GetAt(component->m_points.GetSize() - 1).Y, component->m_points.GetAt(0).X, component->m_points.GetAt(0).Y); break; } default: break; } } //현재 그리고 있는 것 drawColor.SetFromCOLORREF(m_colorPen); drawPen.SetColor(drawColor); drawPen.SetWidth(m_nPenSize); // 왼쪽 버튼 클릭시 || 지우개인경우 | 다각형인 경우(삭제) if (m_nDrawMode == DRAW_NONE || m_nDrawMode == POLY_MODE || m_bLButtonDown) { switch (m_nDrawMode) { case DRAW_NONE: { // 브러쉬 흰색 설정 drawColor.SetFromCOLORREF(RGB(255, 255, 255)); drawBrush.SetColor(drawColor); // 팬 컬러 검정색 설정 drawColor.SetFromCOLORREF(RGB(0, 0, 0)); drawPen.SetColor(drawColor); drawPen.SetWidth(1); int pointSize = m_points.GetSize()-1; for (int i = 0; i < pointSize; i++) { memGraphics.FillRectangle(&drawBrush, m_points.GetAt(i).X, m_points.GetAt(i).Y, m_nEraserSize * 2, m_nEraserSize * 2); } memGraphics.FillRectangle(&drawBrush, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y, m_nEraserSize * 2, m_nEraserSize * 2); memGraphics.DrawRectangle(&drawPen, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y, m_nEraserSize * 2, m_nEraserSize * 2); break; } case LINE_MODE: memGraphics.DrawLine(&drawPen, m_ptPrev.x, m_ptPrev.y, m_ptDrawing.x, m_ptDrawing.y); break; case RECT_MODE: { memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptPrev.y, m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y); // 우측 아래 if(m_ptPrev.x < m_ptDrawing.x && m_ptPrev.y < m_ptDrawing.y) memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptPrev.y, m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y); // 우측 위 else if(m_ptPrev.x < m_ptDrawing.x && m_ptPrev.y > m_ptDrawing.y) memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptDrawing.y, m_ptDrawing.x - m_ptPrev.x, m_ptPrev.y - m_ptDrawing.y); // 좌측 아래 else if(m_ptPrev.x > m_ptDrawing.x && m_ptPrev.y < m_ptDrawing.y) memGraphics.DrawRectangle(&drawPen, m_ptDrawing.x, m_ptPrev.y, m_ptPrev.x - m_ptDrawing.x, m_ptDrawing.y - m_ptPrev.y); // 좌측 위 else memGraphics.DrawRectangle(&drawPen, m_ptDrawing.x, m_ptDrawing.y, m_ptPrev.x - m_ptDrawing.x, m_ptPrev.y - m_ptDrawing.y); break; } case CIRCLE_MODE: memGraphics.DrawEllipse(&drawPen, m_ptPrev.x, m_ptPrev.y, m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y); break; case FREE_MODE: if (m_points.GetSize() > 1) { for (int i = 1; i < m_points.GetSize(); i++) memGraphics.DrawLine(&drawPen, m_points.GetAt(i - 1).X, m_points.GetAt(i - 1).Y, m_points.GetAt(i).X, m_points.GetAt(i).Y); } break; case POLY_MODE: if (m_points.GetSize() > 1) { for (int i = 1; i < m_points.GetSize(); i++) memGraphics.DrawLine(&drawPen, m_points.GetAt(i-1).X, m_points.GetAt(i-1).Y, m_points.GetAt(i).X, m_points.GetAt(i).Y); // 처음 점과 마지막점을 이어준다. memGraphics.DrawLine(&drawPen, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y, m_ptDrawing.x, m_ptDrawing.y); } else if (m_points.GetSize() == 1) memGraphics.DrawLine(&drawPen, m_points.GetAt(0).X, m_points.GetAt(0).Y, m_ptDrawing.x, m_ptDrawing.y); break; default: break; } } graphics.DrawImage(&mBitmap, 0, 0); }
void QuadtreeMeshBuilder::createDebugOutput(const std::deque<QuadtreeMeshBuilder::QuadTree *> & leaves, Util::PixelAccessor * sourceDepth, Util::PixelAccessor * sourceColor) { const uint32_t bitmapWidth = static_cast<uint32_t> (sourceDepth->getWidth()); const uint32_t bitmapHeight = static_cast<uint32_t> (sourceDepth->getHeight()); Util::Reference<Util::Bitmap> depthDebugBitmap = new Util::Bitmap(bitmapWidth, bitmapHeight, Util::PixelFormat::MONO_FLOAT); Util::Reference<Util::Bitmap> quadTreeDebugBitmap = new Util::Bitmap(bitmapWidth, bitmapHeight, Util::PixelFormat::RGBA); Util::Reference<Util::PixelAccessor> destQuadTree(Util::PixelAccessor::create(quadTreeDebugBitmap.get())); float depthMin = std::numeric_limits<float>::max(); float depthMax = std::numeric_limits<float>::lowest(); { for (uint_fast32_t y = 0; y < bitmapHeight; ++y) { for (uint_fast32_t x = 0; x < bitmapWidth; ++x) { const float depthValue = sourceDepth->readSingleValueFloat(x, y); if (depthValue < depthMin) { depthMin = depthValue; } if (depthValue > depthMax) { depthMax = depthValue; } } } Util::Reference<Util::PixelAccessor> destDepth(Util::PixelAccessor::create(depthDebugBitmap.get())); const float depthScale = depthMax - depthMin; for (uint_fast32_t y = 0; y < bitmapHeight; ++y) { for (uint_fast32_t x = 0; x < bitmapWidth; ++x) { const float depthValue = sourceDepth->readSingleValueFloat(x, y); destDepth->writeColor(x, bitmapHeight - y - 1, Util::Color4f((depthValue - depthMin) / depthScale, 0.0f, 0.0f, 0.0f)); destQuadTree->writeColor(x, bitmapHeight - y - 1, Util::Color4ub(0, 0, 0, 0)); } } } for (const auto & leaf : leaves) { const uint16_t xMin = leaf->getX(); const uint16_t yMin = leaf->getY(); const uint16_t xMax = leaf->getWidth() + xMin; const uint16_t yMax = leaf->getHeight() + yMin; for (uint_fast32_t x = xMin; x < xMax; ++x) { destQuadTree->writeColor(x, bitmapHeight - yMin - 1, Util::Color4ub(255, 255, 255, 127)); } for (uint_fast32_t y = yMin; y < yMax; ++y) { destQuadTree->writeColor(xMin, bitmapHeight - y - 1, Util::Color4ub(255, 255, 255, 127)); } const uint16_t xHalf = xMin + leaf->getWidth() / 2; const uint16_t yHalf = yMin + leaf->getHeight() / 2; const Util::Color4ub errorColor(255, 0, 255, 255); Util::Color4ub drawColor(255, 0, 0, 127); const QuadtreeMeshBuilder::QuadTree * west = leaf->getWestNeighbor(); if(west != nullptr) { const uint16_t westXHalf = west->getX() + west->getWidth() / 2; const uint16_t westYHalf = west->getY() + west->getHeight() / 2; // Check if neighbor is correct. if(west->getHeight() < leaf->getHeight()) { drawColor = errorColor; } if(west->getX() + west->getWidth() != xMin) { drawColor = errorColor; } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1 - 1, westXHalf, bitmapHeight - westYHalf - 1 - 1); } else { // Check if neighbor should be missing. if(xMin != 0) { drawColor = errorColor; } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1 - 1, static_cast<int32_t>(0.75 * xMin + 0.25 * xMax), bitmapHeight - yHalf - 1 - 1); } drawColor = Util::Color4ub(255, 255, 0, 127); const QuadtreeMeshBuilder::QuadTree * east = leaf->getEastNeighbor(); if(east != nullptr) { const uint16_t eastXHalf = east->getX() + east->getWidth() / 2; const uint16_t eastYHalf = east->getY() + east->getHeight() / 2; // Check if neighbor is correct. if(east->getHeight() < leaf->getHeight()) { drawColor = errorColor; } if(xMax != east->getX()) { drawColor = errorColor; } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1 + 1, eastXHalf, bitmapHeight - eastYHalf - 1 + 1); } else { // Check if neighbor should be missing. if(xMax != bitmapWidth - 1) { drawColor = errorColor; // Error } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1 + 1, static_cast<int32_t>(0.25 * xMin + 0.75 * xMax), bitmapHeight - yHalf - 1 + 1); } drawColor = Util::Color4ub(0, 0, 255, 127); const QuadtreeMeshBuilder::QuadTree * north = leaf->getNorthNeighbor(); if(north != nullptr) { const uint16_t northXHalf = north->getX() + north->getWidth() / 2; const uint16_t northYHalf = north->getY() + north->getHeight() / 2; // Check if neighbor is correct. if(north->getWidth() < leaf->getWidth()) { drawColor = errorColor; } if(north->getY() + north->getHeight() != yMin) { drawColor = errorColor; } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1, northXHalf, bitmapHeight - northYHalf - 1); } else { // Check if neighbor should be missing. if(yMin != 0) { drawColor = errorColor; // Error } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1, xHalf, static_cast<int32_t>(bitmapHeight - (0.75 * yMin + 0.25 * yMax) - 1)); } drawColor = Util::Color4ub(0, 255, 255, 127); const QuadtreeMeshBuilder::QuadTree * south = leaf->getSouthNeighbor(); if(south != nullptr) { const uint16_t southXHalf = south->getX() + south->getWidth() / 2; const uint16_t southYHalf = south->getY() + south->getHeight() / 2; // Check if neighbor is correct. if(south->getWidth() < leaf->getWidth()) { drawColor = errorColor; } if(yMax != south->getY()) { drawColor = errorColor; } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1, southXHalf, bitmapHeight - southYHalf - 1); } else { // Check if neighbor should be missing. if(yMax != bitmapHeight - 1) { drawColor = errorColor; // Error } drawLine(destQuadTree.get(), drawColor, xHalf, bitmapHeight - yHalf - 1, xHalf, static_cast<int32_t>(bitmapHeight - (0.25 * yMin + 0.75 * yMax) - 1)); } destQuadTree->writeColor(xHalf, bitmapHeight - yHalf - 1, Util::Color4ub(0, 0, 0, 127)); } const std::string currentTime = Util::Utils::createTimeStamp(); if(sourceColor != nullptr) { Util::Reference<Util::Bitmap> colorDebugBitmap = new Util::Bitmap(bitmapWidth, bitmapHeight, Util::PixelFormat::RGB); Util::Reference<Util::PixelAccessor> destColor(Util::PixelAccessor::create(colorDebugBitmap.get())); for (uint_fast32_t y = 0; y < bitmapHeight; ++y) { for (uint_fast32_t x = 0; x < bitmapWidth; ++x) { destColor->writeColor(x, bitmapHeight - y - 1, sourceColor->readColor4f(x, y)); } } Util::Serialization::saveBitmap(*colorDebugBitmap.get(), Util::FileName("screens/QuadTreeMeshBuilder_" + currentTime + "_Color.png")); } Util::Serialization::saveBitmap(*depthDebugBitmap.get(), Util::FileName("screens/QuadTreeMeshBuilder_" + currentTime + "_Depth.png")); Util::Serialization::saveBitmap(*quadTreeDebugBitmap.get(), Util::FileName("screens/QuadTreeMeshBuilder_" + currentTime + "_QuadTree.png")); std::ofstream textDebug("screens/QuadTreeMeshBuilder_Information.txt", std::ios_base::out | std::ios_base::app); textDebug << currentTime << '\t' << leaves.size() << '\t' << depthMin << '\t' << depthMax << '\n'; // sleep(1); }
void BoardWidget::paintEvent(QPaintEvent *) { QPainter p(this); if (boardPM.isNull()) drawBoard(); p.drawPixmap(0, 0, boardPM); /* draw balls */ if (renderMode) { drawPieces(&p); return; } int i,j; p.setRenderHint(QPainter::Antialiasing); int boardSize = width() *10/12; if (boardSize > height()) boardSize = height(); QMatrix m; QPoint cp = rect().center(); m.translate(cp.x(), cp.y()); m.scale(boardSize/1100.0, boardSize/1000.0); m.rotate(0); p.setMatrix(m); p.setBrush(palette().color(QPalette::WindowText)); for(j=-4;j<5;j++) for(i= ((j>0)?j-4:-4) ; i< ((j<0)?5+j:5) ;i++) { int x=xpos(i,j); int y=ypos(j); int w=field[60+j*11+i]; if (w==Board::color1) drawColor(&p, x,y, 35, redColor ); else if (w==Board::color1bright) drawColor(&p, x,y, 35, redHColor ); else if (w==Board::color2) drawColor(&p, x,y, 35, yellowColor ); else if (w==Board::color2bright) drawColor(&p, x,y, 35, yellowHColor ); } if (color1Count >0) { /* the outer marks of color1 */ if (color1Count <12) { for(i=11; i>8 && i>color1Count ;i--) drawColor(&p, xpos(12-i,7-i)+55, ypos(7-i), 35, redColor ); } for(i=14; i>11 && i>color1Count ;i--) drawColor(&p, xpos(-6,10-i)+55, ypos(10-i), 35, redColor ); /* the outer marks of color2 */ if (color2Count <12) { for(i=11; i>8 && i>color2Count ;i--) drawColor(&p, xpos(i-12,i-7)-55, ypos(i-7), 35, yellowColor); } for(i=14; i>11 && i>color2Count ;i--) drawColor(&p, xpos(6,i-10)-55, ypos(i-10), 35, yellowColor); } }