Page MenuHomePhabricator

Improvement of the Level Window
Closed, ResolvedPublic

Description

Hi

I am not allowed to commit changes but i have the problem that the level window slider does not show the numbers approriately when using scale ranges less than 400 gray values, and it gets especially worse if the scale range is less than 10 gray values.

So i modified the level window slider a little bit that it also works for small ranges, maybe it is interresting for someone else:

void QmitkSliderLevelWindowWidget::paintEvent( QPaintEvent* itkNotUsed(e) )
{

QPixmap pm(width(), height());
//pm.fill( static_cast<QWidget*>(parent())->paletteBackgroundColor() );
pm.fill(this, 0, 0);
QPainter painter(&pm);

painter.setFont( m_Font );
//painter.setPen(static_cast<QWidget*>(parent())->paletteForegroundColor());
painter.setPen(this->palette().color(this->foregroundRole()));

QColor c(93,144,169);
QColor cl = c.light();
QColor cd = c.dark();

painter.setBrush(c);
painter.drawRect(m_Rect);

float mr = m_LevelWindow.GetRange();

if ( mr < 1 )
  mr = 1;
 
float fact = (float) m_MoveHeight / mr;

//begin draw scale
if (m_ScaleVisible)
{
  int minRange = (int)m_LevelWindow.GetRangeMin();
  int maxRange = (int)m_LevelWindow.GetRangeMax();
  int yValue = m_MoveHeight + (int)(minRange*fact);
  QString s = " 0";
  if (minRange <= 0 && maxRange >= 0)
  {
    painter.drawLine( 5, yValue , 15, yValue);
    painter.drawText( 21, yValue + 3, s );
  }

  int count = 1;
  int k = 5;
  bool enoughSpace = false;
  bool enoughSpace2 = false;

  double dStepSize;

  if(mr >= 6000)
      dStepSize = 40;//200 step
  else if(mr >= 3000)
      dStepSize = 20;//100 step
  else if(mr >= 1500)
      dStepSize = 10;//50 step
  else if(mr >= 750)
      dStepSize = 5; //25 step
  else if(mr >= 300)
      dStepSize = 2; //10 step
  else if(mr >= 150)
      dStepSize = 1;//5 step
  else if(mr >= 60)
      dStepSize = 0.4;//2 step
  else if(mr >= 30)
      dStepSize = 0.2;//1 step;
  else if(mr >= 15)
      dStepSize = 0.1; //0.5 step
  else if(mr >= 7.5)
      dStepSize = 0.05;//0.25
  else if(mr >= 3)
      dStepSize = 0.02;//0.1
  else
      dStepSize = 0.01;//0.05


  for(int i = m_MoveHeight + (int)(minRange*fact); i < m_MoveHeight;)//negative
  {
    if (-count*dStepSize < minRange)
      break;
    yValue = m_MoveHeight + (int)((minRange + count*dStepSize)*fact);

    s = QString::number(-count*dStepSize);
    if (count % k && ((dStepSize*fact) > 2.5))
    {
      painter.drawLine( 8, yValue, 12, yValue);
      enoughSpace = true;
    }
    else if (!(count % k))
    {
      if ((k*dStepSize*fact) > 7)
      {
        painter.drawLine( 5, yValue, 15, yValue);
        painter.drawText( 21, yValue + 3, s );
        enoughSpace2 = true;
      }
      else
      {
        k += 5;
      }
    }
    if (enoughSpace)
    {
      i=yValue;
      count++;
    }
    else if (enoughSpace2)
    {
      i=yValue;
      count += k;
    }
    else
    {
      i=yValue;
      count = k;
    }
  }
  count = 1;
  k = 5;
  enoughSpace = false;
  enoughSpace2 = false;

  for(int i = m_MoveHeight + (int)(minRange*fact); i >= 0;)
  {
    if (count*dStepSize > maxRange)
      break;
    yValue = m_MoveHeight + (int)((minRange - count*dStepSize)*fact);

    s = QString::number(count*dStepSize);
    if(count % k && ((dStepSize*fact) > 2.5))
    {
      if (!(minRange > 0 && (count*dStepSize) < minRange))
        painter.drawLine( 8, yValue, 12, yValue);
      enoughSpace = true;
    }
    else if (!(count % k))
    {
      if ((k*dStepSize*fact) > 7)
      {
        if (!(minRange > 0 && (count*dStepSize) < minRange))
        {
          painter.drawLine( 5, yValue, 15, yValue);
          painter.drawText( 21, yValue + 3, s );
        }
        enoughSpace2 = true;
      }
      else
      {
        k += 5;
      }
    }
    if (enoughSpace)
    {
      i=yValue;
      count++;
    }
    else if (enoughSpace2)
    {
      i=yValue;
      count += k;
    }
    else
    {
      i=yValue;
      count = k;
    }
  }
}
//end draw scale
painter.setPen (cl);
painter.drawLine(m_Rect.topLeft(),m_Rect.topRight());
painter.drawLine(m_Rect.topLeft(),m_Rect.bottomLeft());

painter.setPen (cd);
painter.drawLine(m_Rect.topRight(),m_Rect.bottomRight());
painter.drawLine(m_Rect.bottomRight(),m_Rect.bottomLeft());
painter.end();

QPainter p (this);
p.drawPixmap(0, 0, pm);

}

Event Timeline

Many thanks for sending this fix! Someone will look into how this can be integrated into MITK

Implemented proposed solution and changed step size calculation to be dependent on the maximum grayvalue range in the image.

Added change request.

[fa28b5]: Merge branch 'bug-7106-LevelWindowScale'

Merged commits:

2011-06-29 16:57:37 Alexander Seitel [7ce43d]
Adaptively compute the step size for the level window scale.

[f9610c]: Merge branch 'bug-7106-UseCorrectPowFunction'

Merged commits:

2011-07-08 10:47:16 Alexander Seitel [6b0e39]
pow10 doesn't exist anymore. Use pow(10,x) instead.