Skip to content

Commit

Permalink
Fix window/level calculation for dicom dataset
Browse files Browse the repository at this point in the history
Use the auto calculated window/level unless the user
has manually set one by dragging the mouse in the viewer
  • Loading branch information
pieper committed Sep 1, 2011
1 parent bbb0889 commit a155a33
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions Libs/DICOM/Widgets/ctkDICOMDatasetView.cpp
Expand Up @@ -67,6 +67,7 @@ class ctkDICOMDatasetViewPrivate
QPoint OldMousePos;
double DicomIntensityLevel;
double DicomIntensityWindow;
bool AutoWindowLevel;

void init();

Expand Down Expand Up @@ -96,6 +97,8 @@ void ctkDICOMDatasetViewPrivate::init()

this->DicomIntensityWindow = 0;

this->AutoWindowLevel = true;

/*
this->Window->setParent(q);
QHBoxLayout* layout = new QHBoxLayout(q);
Expand Down Expand Up @@ -271,17 +274,24 @@ void ctkDICOMDatasetView::addImage( DicomImage & dcmImage, bool defaultIntensity
}
// Select first window defined in image. If none, compute min/max window as best guess.
// Only relevant for monochrome
// TODO: Re-Use code from ctkDICOMThumbnailGenerator by re-factoring it to a function?
if (dcmImage.isMonochrome())
if (d->AutoWindowLevel)
{
if (defaultIntensity && dcmImage.getWindowCount() > 0)
{
dcmImage.setWindow(0);
}
else
{
dcmImage.setWindow(d->DicomIntensityLevel, d->DicomIntensityWindow);
}
if (dcmImage.isMonochrome())
{
if (defaultIntensity && dcmImage.getWindowCount() > 0)
{
dcmImage.setWindow(0);
}
else
{
dcmImage.setMinMaxWindow(OFTrue /* ignore extreme values */);
dcmImage.getWindow(d->DicomIntensityLevel, d->DicomIntensityWindow);
}
}
}
else
{
dcmImage.setWindow(d->DicomIntensityLevel, d->DicomIntensityWindow);
}
/* get image extension and prepare image header */
const unsigned long width = dcmImage.getWidth();
Expand Down Expand Up @@ -363,6 +373,7 @@ void ctkDICOMDatasetView::mouseMoveEvent(QMouseEvent* event){

d->DicomIntensityWindow += (5*(nowPos.x()-d->OldMousePos.x()));
d->DicomIntensityLevel -= (5*(nowPos.y()-d->OldMousePos.y()));
d->AutoWindowLevel = false;

d->setImage(d->CurrentImageIndex, false);

Expand Down

0 comments on commit a155a33

Please sign in to comment.