void ZDvidTile::enhanceContrast(bool high) { if (high != hasVisualEffect(NeuTube::Display::Image::VE_HIGH_CONTRAST)) { if (high) { addVisualEffect(NeuTube::Display::Image::VE_HIGH_CONTRAST); } else { removeVisualEffect(NeuTube::Display::Image::VE_HIGH_CONTRAST); } if (m_image != NULL) { m_image->enhanceContrast( hasVisualEffect(NeuTube::Display::Image::VE_HIGH_CONTRAST)); updatePixmap(); } } }
void ZCircle::display(ZPainter &painter, int n, ZStackObject::EDisplayStyle style) const { if (!isVisible()) { return; } UNUSED_PARAMETER(style); #if _QT_GUI_USED_ painter.save(); QPen pen(m_color, getPenWidth()); pen.setCosmetic(m_usingCosmeticPen); if (hasVisualEffect(VE_DASH_PATTERN)) { pen.setStyle(Qt::DotLine); } painter.setPen(pen); //qDebug() << "Internal color: " << m_color; // const QBrush &oldBrush = painter.getBrush(); if (hasVisualEffect(VE_GRADIENT_FILL)) { QRadialGradient gradient(50, 50, 50, 50, 50); gradient.setColorAt(0, QColor::fromRgbF(0, 1, 0, 1)); gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0)); /* QBrush brush(gradient); brush.setColor(m_color); brush.setStyle(Qt::RadialGradientPattern); painter.setBrush(brush); */ //painter.setBrush(m_color); //painter.setBrush(QBrush(m_color, Qt::RadialGradientPattern)); } else { if (hasVisualEffect(VE_NO_FILL)) { painter.setBrush(Qt::NoBrush); } } displayHelper(&painter, n, style); // painter.setBrush(oldBrush); painter.restore(); #endif }
void ZCircle::display(QPainter *painter, int n, Display_Style style) const { UNUSED_PARAMETER(style); #if defined(_QT_GUI_USED_) double adjustedRadius = m_r + m_defaultPenWidth * 0.5; QRectF rect; if (hasVisualEffect(VE_BOUND_BOX)) { rect.setLeft(m_center.x() - adjustedRadius); rect.setTop(m_center.y() - adjustedRadius); rect.setWidth(adjustedRadius + adjustedRadius); rect.setHeight(adjustedRadius + adjustedRadius); } bool visible = false; if (n == -1) { visible = true; } else { if (isCuttingPlane(m_center.z(), m_r, n)) { double h = fabs(m_center.z() - n); if (m_r > h) { double r = sqrt(m_r * m_r - h * h); adjustedRadius = r + m_defaultPenWidth * 0.5; visible = true; } else { //too small, show at least one plane adjustedRadius = m_defaultPenWidth * 0.5; visible = true; } } } if (visible) { if (hasVisualEffect(VE_BOUND_BOX)) { painter->drawRect(rect); } if (!hasVisualEffect(VE_NO_CIRCLE)) { painter->drawEllipse(QPointF(m_center.x(), m_center.y()), adjustedRadius, adjustedRadius); } } #endif }
void ZCircle::display(QPainter &painter, int n, ZStackDrawable::Display_Style style) const { UNUSED_PARAMETER(style); #if _QT_GUI_USED_ QPen pen(m_color, m_defaultPenWidth); if (hasVisualEffect(VE_DASH_PATTERN)) { pen.setStyle(Qt::DotLine); } painter.setPen(pen); display(&painter, n, style); #endif }
void ZDvidTile::loadDvidSlice(const uchar *buf, int length, int z) { bool loading = true; if (m_view != NULL) { if (m_view->getZ(NeuTube::COORD_STACK) != z) { loading = false; } } bool modified = false; if (loading) { if (m_image == NULL) { m_image = new ZImage; } #ifdef _DEBUG_2 std::cout << "Decoding tile ..." << std::endl; #endif m_image->loadFromData(buf, length); m_image->setScale(1.0 / m_res.getScale(), 1.0 / m_res.getScale()); m_image->setOffset(-getX(), -getY()); modified = true; m_image->enhanceContrast( hasVisualEffect(NeuTube::Display::Image::VE_HIGH_CONTRAST)); #ifdef _DEBUG_2 std::cout << "Format: " << m_image->format() << std::endl; setVisualEffect(NeuTube::Display::Image::VE_HIGH_CONTRAST); #endif m_z = z; } if (modified) { updatePixmap(); } }
void ZCircle::displayHelper(ZPainter *painter, int stackFocus, EDisplayStyle style) const { UNUSED_PARAMETER(style); #if defined(_QT_GUI_USED_) double adjustedRadius = getAdjustedRadius(m_r); double dataFocus = stackFocus - painter->getZOffset(); bool visible = false; const QBrush &oldBrush = painter->getBrush(); const QPen &oldPen = painter->getPen(); double alpha = oldPen.color().alphaF(); if (stackFocus == -1) { visible = true; } else { if (isCuttingPlane(m_center.z(), m_r, dataFocus, m_zScale)) { double h = fabs(m_center.z() - dataFocus) / m_zScale; double r = 0.0; if (m_r > h) { r = sqrt(m_r * m_r - h * h); adjustedRadius = getAdjustedRadius(r); //adjustedRadius = r + getPenWidth() * 0.5; visible = true; } else { //too small, show at least one plane //adjustedRadius = getPenWidth() * 0.5; r = 0.1; adjustedRadius = getAdjustedRadius(r); visible = true; } if (hasVisualEffect(VE_OUT_FOCUS_DIM)) { alpha *= r * r / m_r / m_r; //alpha *= alpha; } } } if (visible) { if (!hasVisualEffect(VE_NO_CIRCLE)) { //qDebug() << painter->brush().color(); QColor color = painter->getPenColor(); color.setAlphaF(alpha); painter->setPen(color); painter->drawEllipse(QPointF(m_center.x(), m_center.y()), adjustedRadius, adjustedRadius); } } if (hasVisualEffect(VE_BOUND_BOX)) { QRectF rect; double halfSize = adjustedRadius; if (m_usingCosmeticPen) { halfSize += 0.5; } rect.setLeft(m_center.x() - halfSize); rect.setTop(m_center.y() - halfSize); rect.setWidth(halfSize * 2); rect.setHeight(halfSize * 2); painter->setBrush(Qt::NoBrush); QPen pen = oldPen; if (visible) { pen.setStyle(Qt::SolidLine); } else { pen.setStyle(Qt::DotLine); } pen.setCosmetic(m_usingCosmeticPen); painter->setPen(pen); #if 0 //for future versions QPen pen = oldPen; QVector<qreal> pattern; pattern << 1 << 2; pen.setDashPattern(pattern); painter->setPen(pen); painter->drawRect(rect); pen.setColor(Qt::black); pen.setDashOffset(1.5); painter->setPen(pen); #endif //QPainter::CompositionMode oldMode = painter->compositionMode(); //painter->setCompositionMode(QPainter::RasterOp_SourceXorDestination); painter->drawRect(rect); //painter->setCompositionMode(oldMode); } painter->setBrush(oldBrush); painter->setPen(oldPen); #endif }
void ZDvidSynapse::display(ZPainter &painter, int slice, EDisplayStyle option, neutube::EAxis sliceAxis) const { bool visible = true; int z = painter.getZ(slice); if (slice < 0) { visible = isProjectionVisible(); } else { visible = isSliceVisible(z, sliceAxis); } double radius = getRadius(z, sliceAxis); ZIntPoint center = m_position; center.shiftSliceAxis(sliceAxis); bool isFocused = (z == center.getZ()); if (visible) { QPen pen; QColor color = getColor(); double alpha = 1.0; if (option == SKELETON) { alpha = 0.1; } if (!isFocused) { alpha *= radius / m_radius; alpha *= alpha * 0.5; alpha += 0.1; } color.setAlphaF(alpha * color.alphaF()); pen.setColor(color); painter.setPen(pen); painter.setBrush(Qt::NoBrush); if (isFocused) { int x = center.getX(); int y = center.getY(); painter.drawLine(QPointF(x - 1, y), QPointF(x + 1, y)); painter.drawLine(QPointF(x, y - 1), QPointF(x, y + 1)); if (getStatus() == STATUS_DUPLICATED) { painter.drawEllipse( QPointF(center.getX(), center.getY()), 1, 1); } } if (radius > 0.0) { double oldWidth = pen.widthF(); QColor oldColor = pen.color(); if (getKind() == EKind::KIND_POST_SYN) { if (option != SKELETON) { pen.setWidthF(oldWidth + 1.0); } if (isSelected()) { pen.setColor(QColor(255, 0, 255, oldColor.alpha())); } } else { if (isSelected()) { pen.setWidthF(pen.widthF() + 1.0); } } painter.setPen(pen); painter.drawEllipse(QPointF(center.getX(), center.getY()), radius, radius); pen.setWidthF(oldWidth); pen.setColor(oldColor); } // QString decorationText; if (isVerified()) { // decorationText = "U"; color.setRgb(0, 0, 0); if (isSelected()) { if (getKind() == EKind::KIND_PRE_SYN) { color.setRgb(0, 255, 0); size_t index = 0; for (std::vector<bool>::const_iterator iter = m_isPartnerVerified.begin(); iter != m_isPartnerVerified.end(); ++iter, ++index) { bool verified = *iter; if (m_partnerKind[index] == EKind::KIND_POST_SYN) { if (!verified) { color.setRgb(0, 0, 0); break; } } } } } color.setAlphaF(alpha); pen.setColor(color); pen.setWidthF(pen.widthF() + 0.5); painter.setPen(pen); double margin = 0.5; painter.drawLine(QPointF(center.getX(), center.getY() + radius - margin), QPointF(center.getX() + radius - margin, center.getY())); painter.drawLine(QPointF(center.getX(), center.getY() + radius - margin), QPointF(center.getX() - radius + margin, center.getY())); } double conf = getConfidence(); if (conf < 1.0) { // double lineWidth = radius * conf * 0.5 + 1.0; double lineWidth = radius * 0.5; double red = 1.0 - conf; double green = conf; QColor color; color.setRedF(red); if (getKind() == ZDvidAnnotation::EKind::KIND_POST_SYN) { color.setBlueF(green); } else { color.setGreenF(green); } color.setAlphaF(alpha); painter.setPen(color); double x = center.getX(); double y = center.getY(); /* painter.drawLine(QPointF(x - lineWidth, y), QPointF(x + lineWidth, y)); */ int startAngle = 0; int spanAngle = iround((1.0 - conf) * 180) * 16; painter.drawArc(QRectF(QPointF(x - lineWidth, y - lineWidth), QPointF(x + lineWidth, y + lineWidth)), startAngle, spanAngle); // painter.drawEllipse(QPointF(x, y), lineWidth, lineWidth); // decorationText += QString(".%1").arg(iround(conf * 10.0)); } #if 0 int height = iround(getRadius() * 1.5); int width = decorationText.size() * height; if (decorationText != m_textDecoration.text()) { m_textDecoration.setText(decorationText); m_textDecoration.setTextWidth(width); } if (!decorationText.isEmpty()) { QFont font; font.setPixelSize(height); font.setWeight(QFont::Light); font.setStyleStrategy(QFont::PreferMatch); painter.setFont(font); QColor oldColor = painter.getPen().color(); QColor color = QColor(0, 0, 0); color.setAlphaF(alpha); QPen pen = painter.getPen(); pen.setColor(color); painter.setPen(pen); painter.drawStaticText(center.getX() - height / 2, center.getY(), m_textDecoration); // painter.drawText(center.getX() - height / 2, center.getY(), width, height, // Qt::AlignLeft, decorationText); painter.setPen(oldColor); } #endif } QPen pen; pen.setCosmetic(m_usingCosmeticPen); bool drawingBoundBox = false; bool drawingArrow = false; if (isSelected()) { if (visible) { drawingBoundBox = true; } else { drawingArrow = true; } QColor color; color.setRgb(255, 255, 0, 255); pen.setColor(color); pen.setCosmetic(true); } else if (hasVisualEffect(neutube::display::Sphere::VE_BOUND_BOX)) { drawingBoundBox = true; pen.setStyle(Qt::SolidLine); pen.setCosmetic(m_usingCosmeticPen); } if (drawingBoundBox) { QRectF rect; double halfSize = m_radius; if (m_usingCosmeticPen) { halfSize += 0.5; } rect.setLeft(center.getX() - halfSize); rect.setTop(center.getY() - halfSize); rect.setWidth(halfSize * 2); rect.setHeight(halfSize * 2); painter.setBrush(Qt::NoBrush); pen.setWidthF(pen.widthF() * 0.5); if (visible) { pen.setStyle(Qt::SolidLine); } else { pen.setStyle(Qt::DotLine); } painter.setPen(pen); painter.drawRect(rect); } if (drawingArrow) { painter.setPen(pen); QRectF rect(center.getX() - m_radius, center.getY() - m_radius, m_radius + m_radius, m_radius + m_radius); // pen.setStyle(Qt::SolidLine); // pen.setColor(GetArrowColor(isVerified())); // painter.setPen(pen); QPointF ptArray[4]; // double s = 5.0; if (z > center.getZ()) { ZFlyEmMisc::MakeTriangle(rect, ptArray, neutube::ECardinalDirection::NORTH); /* pt[0] = QPointF(rect.center().x() - rect.width() / s, rect.top() + rect.height() / s); pt[1] = QPointF(rect.center().x(), rect.top() - rect.height() / s); pt[2] = QPointF(rect.center().x() + rect.width() / s, rect.top() + rect.height() / s); */ } else { ZFlyEmMisc::MakeTriangle(rect, ptArray, neutube::ECardinalDirection::SOUTH); /* pt[0] = QPointF(rect.center().x() - rect.width() / s, rect.bottom() - rect.height() / s); pt[1] = QPointF(rect.center().x(), rect.bottom() + rect.height() / s); pt[2] = QPointF(rect.center().x() + rect.width() / s, rect.bottom() - rect.height() / s); */ } painter.drawPolyline(ptArray, 4); // painter.drawLine(pt[0], pt[1]); // painter.drawLine(pt[1], pt[2]); // painter.drawLine(pt[0], pt[2]); } if (isSelected()) { pen.setStyle(Qt::SolidLine); size_t index = 0; if (m_isPartnerVerified.size() == m_partnerHint.size()) { for (std::vector<ZIntPoint>::const_iterator iter = m_partnerHint.begin(); iter != m_partnerHint.end(); ++iter, ++index) { pen.setColor(GetArrowColor(m_isPartnerVerified[index])); painter.setPen(pen); const ZIntPoint &partner = *iter; double len = 0.0; if (partner.getZ() < z && getPosition().getZ() < z) { len = -1.0; } else if (partner.getZ() > z && getPosition().getZ() > z) { len = 1.0; } if (len != 0.0) { QPointF pt[3]; pt[0].setX(partner.getX() - len); pt[0].setY(partner.getY() - len); pt[1].setX(partner.getX() + len); pt[1].setY(partner.getY() - len); pt[2].setX(partner.getX()); pt[2].setY(partner.getY() + len); painter.drawLine(pt[0], pt[1]); painter.drawLine(pt[1], pt[2]); painter.drawLine(pt[0], pt[2]); } if (m_partnerKind[index] == EKind::KIND_POST_SYN) { ZDvidSynapse partnerSynapse; partnerSynapse.setKind(EKind::KIND_POST_SYN); partnerSynapse.setStatus(m_partnerStatus[index]); partnerSynapse.setPosition(partner); partnerSynapse.setDefaultColor(); partnerSynapse.setDefaultRadius(); painter.save(); partnerSynapse.display(painter, slice, ZStackObject::NORMAL, sliceAxis); painter.restore(); } } } index = 0; for (std::vector<ZIntPoint>::const_iterator iter = m_partnerHint.begin(); iter != m_partnerHint.end(); ++iter, ++index) { ZLineSegmentObject line; line.setStartPoint(getPosition()); line.setEndPoint(*iter); if (getKind() == EKind::KIND_PRE_SYN && m_partnerKind[index] == EKind::KIND_PRE_SYN) { line.setColor(QColor(0, 255, 255)); line.setFocusColor(QColor(0, 255, 255)); } else if (m_partnerKind[index] == EKind::KIND_UNKNOWN) { line.setColor(QColor(164, 0, 0)); line.setFocusColor(QColor(255, 0, 0)); } else { line.setColor(QColor(255, 255, 0)); line.setFocusColor(QColor(255, 0, 255)); } line.setVisualEffect(neutube::display::Line::VE_LINE_PROJ); line.display(painter, slice, option, sliceAxis); /* ZIntPoint pos = *iter; painter.drawLine(getPosition().getX(), getPosition().getY(), pos.getX(), pos.getY()); */ } } }