Exemplo n.º 1
0
int YARPIntegralImage::computeLp(YARPImageOf<YarpPixelMono> &input)
{
	int r;
	int c;

	// first pixel, init
	_rowSum(0,0) = 0; //input(0,0)/255.0;
	_integralImg(0,0) = _rowSum(0,0);
	
	// fovea, zero it for now
	for(r = 0; r<_nfovea; r++)
		for(c = 0; c < _nCols; c++)
		{
			_rowSum(c,r) = 0;
			_integralImg(c,r) = 0;
		}
	
	
	for(r = _nfovea; r < _nRows; r++)
	{
		// first col
		_rowSum(0,r) = (float) (input(0,r)*pSize(c,r,_nfovea));
		_integralImg(0, r) = _integralImg(0, r-1) + _rowSum(0,r);
		
		for(c = 1; c < _nCols; c++)
		{
			_rowSum(c,r) = _rowSum(c-1,r) + (float) (input(c,r)*pSize(c,r,_nfovea));
			_integralImg(c,r) = _integralImg(c, r-1) + _rowSum(c,r);
		}
	}

	return YARP_OK;
}
void YARPLpHistoSegmentation::Apply(YARPImageOf<YarpPixelHSV> &src)
{
	int i;
	int j;
	unsigned char *h;
	unsigned char *s;
	unsigned char *v;
			
	for(i = 0; i < src.GetHeight(); i++)
	{
		h = (unsigned char *) src.GetArray()[i];
		s = h+1;
		v = h+2;

		double w = pSize(1, i);
		for(j = 0; j < src.GetWidth(); j++)
		{
			if (_checkThresholds(*h,*s,*v))
				YARP3DHistogram::Apply(*h, *s, 0, w);
						
			h += 3;
			s += 3;
			v += 3;
		}
	}
}
void YARPLpHistoSegmentation::Apply(YARPImageOf<YarpPixelRGB> &src)
{
	int i;
	int j;
	unsigned char *r;
	unsigned char *g;
	unsigned char *b;
			
	for(i = 0; i < src.GetHeight(); i++)
	{
		r = (unsigned char *) src.GetArray()[i];
		g = r+1;
		b = r+2;

//		unsigned char rp, gp, bp;
		double w = pSize(1, i);	
		for(j = 0; j < src.GetWidth(); j++)
		{
			// YARPHistoSegmentation::_normalize(*r, *g, *b, &rp, &gp, &bp);
			// YARP3DHistogram::Apply(rp, gp, bp, w);
			if (_checkThresholds(YarpPixelRGB(*r,*g,*b)))
				YARP3DHistogram::Apply(*r, *g, *b);
				
			b += 3;
			g += 3;
			r += 3;
		}
	}
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void DREAM3DGraphicsView::updateDisplay()
{

//  std::cout << "DREAM3DGraphicsView::updateDisplay()" << std::endl;
  QPainter painter;
  QSize pSize(0, 0);
  if (m_BaseImage.isNull() == false)
  {
    pSize = m_BaseImage.size();
  }
  else
  {
    return;
  }

  QImage paintImage(pSize, QImage::Format_ARGB32_Premultiplied);
  QPoint point(0, 0);
  painter.begin(&paintImage);
  painter.setPen(Qt::NoPen);
  if (m_ImageDisplayType == EmMpm_Constants::OriginalImage)
  {
    painter.drawImage(point, m_BaseImage);
  }

  painter.end();

  if (paintImage.isNull() == true)
  {
    return;
  }
  QGraphicsPixmapItem* pixItem = qgraphicsitem_cast<QGraphicsPixmapItem*> (m_ImageGraphicsItem);
  pixItem->setPixmap(QPixmap::fromImage(paintImage));

  this->update();
}
void DREAM3DGraphicsView::loadBaseImageFile(const QString& filename)
{
  m_BaseImage = QImage(filename);
  if (m_BaseImage.isNull() == true)
  {
    return;
  }
  QSize pSize(0, 0);
  pSize = m_BaseImage.size();

  m_OverlayImage = m_BaseImage;
  m_CompositedImage = m_BaseImage;

  QVector<QRgb > colorTable(256);
  for (quint32 i = 0; i < 256; ++i)
  {
    colorTable[i] = qRgb(i, i, i);
  }
  m_BaseImage.setColorTable(colorTable);

  if (m_BaseImage.isNull() == true)
  {
    std::cout << "Base Image was NULL for some reason. Returning" << std::endl;
    return;
  }
  QGraphicsScene* gScene = scene();
  if (gScene == NULL)
  {
    gScene = new QGraphicsScene(this);
    setScene(gScene);
  }
  else
  {

    setScene(NULL);
    gScene->deleteLater();
    gScene = new QGraphicsScene(this);
    setScene(gScene);

    delete m_ImageGraphicsItem;
    m_ImageGraphicsItem = NULL;
  }
  if (NULL == m_ImageGraphicsItem)
  {
    QImageReader reader(filename);
    QPixmap pixmap = QPixmap::fromImageReader(&reader, 0);
    m_ImageGraphicsItem = gScene->addPixmap(pixmap);
  }
  m_ImageGraphicsItem->setAcceptDrops(true);
  m_ImageGraphicsItem->setZValue(-1);


  QRectF rect = m_ImageGraphicsItem->boundingRect();
  gScene->setSceneRect(rect);
  centerOn(m_ImageGraphicsItem);
  this->updateDisplay();
  emit fireBaseImageFileLoaded(filename);
}
Exemplo n.º 6
0
/*!
  Tries to find a line that is not a neighbour of  \c handleIdx.
 */
int QHeader::findLine( int c )
{
    int i = cellAt( c );
    if ( i == -1 )
	return handleIdx; //####### frustrating, but safe behaviour.
    if ( i == handleIdx )
	return i;
    if ( i == handleIdx - 1 &&  pPos( handleIdx ) - c > MARKSIZE/2 )
	return i;
    if ( i == handleIdx + 1 && c - pPos( i ) > MARKSIZE/2 )
	return i + 1;
    if ( c - pPos( i ) > pSize( i ) / 2 )
	return i + 1;
    else
	return i;
}
Exemplo n.º 7
0
void QHeader::paintCell( QPainter *p, int row, int col )
{
    int i = ( orient == Horizontal ) ? col : row;
    int size = pSize( i );
    bool down = (i==handleIdx) && ( state == Pressed || state == Moving );

    QRect fr( 0, 0, orient == Horizontal ?  size : width(),
	      orient == Horizontal ?  height() : size );

    if ( style() == WindowsStyle )
	qDrawWinButton( p, fr, colorGroup(), down );
    else
	qDrawShadePanel( p, fr, colorGroup(), down );

    int logIdx = mapToLogical(i);

    const char *s = data->labels[logIdx];
    int d = 0;
    if ( style() == WindowsStyle  &&
	 i==handleIdx && ( state == Pressed || state == Moving ) )
	d = 1;

    QRect r;
    if (orient == Horizontal )
      r = QRect( QH_MARGIN+d, 2+d, size - 6, height() - 4 );
    else
      r = QRect( QH_MARGIN+d, 2+d, width() - 6, size - 4 );

    if ( s ) {
	p->drawText ( r, AlignLeft| AlignVCenter|SingleLine, s );
    } else {
	QString str;
	if ( orient == Horizontal )
	    str.sprintf( "Col %d", logIdx );
	else
	    str.sprintf( "Row %d", logIdx );
	p->drawText ( r, AlignLeft| AlignVCenter|SingleLine, str );
    }
}
Exemplo n.º 8
0
/*!
  Tries to find a line that is not a neighbor of  \c handleIdx.
 */
int QHeader::findLine( int c )
{
    int lastpos = d->positions[d->count-1] + d->sizes[d->i2s[d->count-1]];
    int i = 0;
    if ( c > lastpos ) {
	return d->count;
    } else {
	int section = sectionAt( c );
	if ( section < 0 )
	    return handleIdx;
	i = d->s2i[section];
    }
    if ( i == handleIdx )
	return i;
    if ( i == handleIdx - 1 &&  pPos( handleIdx ) - c > MARKSIZE/2 )
	return i;
    if ( i == handleIdx + 1 && c - pPos( i ) > MARKSIZE/2 )
	return i + 1;
    if ( c - pPos( i ) > pSize( i ) / 2 )
	return i + 1;
    else
	return i;
}
Exemplo n.º 9
0
/*!
  \reimp
*/
void QHeader::mouseMoveEvent( QMouseEvent *e )
{
    int section;
    bool hit;

    int c = orient == Horizontal ? e->pos().x() : e->pos().y();
    c += offset();

    switch( state ) {
    case Idle:
	hit = FALSE;
	if ( (section = sectionAt( c )) >= 0 ) {
	    int index = d->s2i[section];
	    if ( (index > 0 && c < d->positions[index] + GRIPMARGIN) ||
		 (c > d->positions[index] + d->sizes[section] - GRIPMARGIN) ) {
		if ( index > 0 && c < d->positions[index]  + GRIPMARGIN )
		    section = d->i2s[--index];
		if ( d->resize.testBit(section) ) {
		    hit = TRUE;
#ifndef QT_NO_CURSOR
		    if ( orient == Horizontal )
			setCursor( splitHCursor );
		    else
			setCursor( splitVCursor );
#endif
		}
	    }
	}
#ifndef QT_NO_CURSOR
	if ( !hit )
	    unsetCursor();
#endif
	break;
    case Blocked:
	break;
    case Pressed:
	if ( QABS( c - clickPos ) > 4 && d->move ) {
	    state = Moving;
	    moveToIdx = -1;
#ifndef QT_NO_CURSOR
	    if ( orient == Horizontal )
		setCursor( sizeHorCursor );
	    else
		setCursor( sizeVerCursor );
#endif
	}
	break;
    case Sliding:
	handleColumnResize( handleIdx, c, FALSE );
	break;
    case Moving: {
	int newPos = findLine( c );
	if ( newPos != moveToIdx ) {
	    if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 )
		repaint( sRect(handleIdx) );
	    else
		unMarkLine( moveToIdx );
	    moveToIdx = newPos;
	    if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 )
		paintRect( pPos( handleIdx ), pSize( handleIdx ) );
	    else
		markLine( moveToIdx );
	}
	break;
    }
    default:
	qWarning( "QHeader::mouseMoveEvent: (%s) unknown state", name() );
	break;
    }
}
Exemplo n.º 10
0
void QHeader::mouseMoveEvent( QMouseEvent *m )
{
    int s = orient == Horizontal ? m->pos().x() : m->pos().y();
    if ( state == Idle ) {
	bool hit = FALSE;
	int i = 0;
	while ( i <= (int) count() ) {
	    if ( i && pPos(i) - MINSIZE/2 < s && s < pPos(i) + MINSIZE/2 &&
		 data->resize.testBit(i-1) ) {
		hit = TRUE;
		if ( orient == Horizontal )
		    setCursor( *hSplitCur );
		else
		    setCursor( *vSplitCur );
		break;
	    }
	    i++;
	}
	if ( !hit )
	    setCursor( arrowCursor );
    } else {
	switch ( state ) {
	case Idle:
	    debug( "QHeader::mouseMoveEvent() (%s) Idle state",
		   name( "unnamed" ) );
	    break;
	case Pressed:
	case Blocked:
	    if ( QABS( s - clickPos ) > 4 && data->move ) {
		state = Moving;
		moveToIdx = -1;
		if ( orient == Horizontal )
		    setCursor( sizeHorCursor );
		else
		    setCursor( sizeVerCursor );
	    }
	    break;
	case Sliding:
	    handleColumnResize( handleIdx, s, FALSE );
	    break;
	case Moving: {
	    int newPos = findLine( s );
	    if ( newPos != moveToIdx ) {
		if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 )
		    repaint( sRect(handleIdx) );
		else
		    unMarkLine( moveToIdx );
		moveToIdx = newPos;
		if ( moveToIdx == handleIdx || moveToIdx == handleIdx + 1 )
		    paintRect( pPos( handleIdx ), pSize( handleIdx ) );
		else
		    markLine( moveToIdx );
	    }
	    break;
	}
	default:
	    warning( "QHeader::mouseMoveEvent: (%s) unknown state",
		     name( "unnamed" ) );
	    break;
	}
    }
}
Exemplo n.º 11
0
int QHeader::cellSize( int i ) const
{
    int s = pSize( i );
    return s;
}