File: QDataRadioButton.cpp

package info (click to toggle)
imagevis3d 2.0.1-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,872 kB
  • sloc: cpp: 53,586; sh: 788; ansic: 292; xml: 258; python: 35; makefile: 16
file content (172 lines) | stat: -rw-r--r-- 5,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
   For more information, please see: http://software.sci.utah.edu

   The MIT License

   Copyright (c) 2008 Scientific Computing and Imaging Institute,
   University of Utah.


   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE.
*/


//!    File   : QDataRadioButton.cpp
//!    Author : Jens Krueger
//!             SCI Institute
//!             University of Utah
//!    Date   : September 2008
//
//!    Copyright (C) 2008 SCI Institute

#include "QDataRadioButton.h"
#include <QtGui/QMouseEvent>
#include "../Tuvok/IO/TuvokJPEG.h"
#include "../Tuvok/IO/DICOM/DICOMParser.h"
#include "jconfig.h"

QDataRadioButton::QDataRadioButton(std::tr1::shared_ptr<FileStackInfo> stack,
                                   QWidget *parent) :
  QRadioButton(parent),
  m_iCurrentImage((unsigned int)(-1)),
  m_stackInfo(stack),
  m_fScale(1.0f)
{
  SetupInfo();
}

QDataRadioButton::QDataRadioButton(std::tr1::shared_ptr<FileStackInfo> stack,
                                   const QString &text, QWidget *parent) :
  QRadioButton(text, parent),
  m_iCurrentImage((unsigned int)(-1)),
  m_stackInfo(stack),
  m_fScale(1.0f)
{
  SetupInfo();
}


void QDataRadioButton::leaveEvent(QEvent * event) {
  QRadioButton::leaveEvent(event);

  SetStackImage(int(m_stackInfo->m_Elements.size()/2));
}

void QDataRadioButton::mouseMoveEvent(QMouseEvent *event){
  QRadioButton::mouseMoveEvent(event);
  unsigned int i;

  i = (unsigned int)(float(event->x()) / float(width()) *
                     m_stackInfo->m_Elements.size());
  SetStackImage(i);
}

void QDataRadioButton::SetBrightness(float fScale) {
  m_fScale = fScale;
  SetStackImage(m_iCurrentImage, true);
}



#ifdef DETECTED_OS_WINDOWS
  #pragma warning(disable:4996)
#endif

void QDataRadioButton::SetStackImage(unsigned int i, bool bForceUpdate) {

  if (!bForceUpdate && m_iCurrentImage == i) return;

  m_iCurrentImage = i;

  QIcon icon;

  std::vector<char> vData;
  if (m_stackInfo->m_bIsJPEGEncoded) {
    tuvok::JPEG jpg(m_stackInfo->m_Elements[i]->m_strFileName,
                    dynamic_cast<SimpleDICOMFileInfo*>
                      (m_stackInfo->m_Elements[i])->GetOffsetToData());
    const char *jpg_data = jpg.data();
    // JPEG library automagically downsamples the data.
    m_stackInfo->m_iAllocated = 8; //BITS_IN_JSAMPLE;
    vData.resize(jpg.size());
    std::copy(jpg_data, jpg_data + jpg.size(), &vData[0]);
  } else {
    m_stackInfo->m_Elements[i]->GetData(vData);
  }
  QImage image(m_stackInfo->m_ivSize.x, m_stackInfo->m_ivSize.y,
               QImage::Format_RGB32);

  if (m_stackInfo->m_iComponentCount == 1) {
    switch (m_stackInfo->m_iAllocated) {
      case 8  :{
            unsigned int i = 0;
            unsigned char* pCharData = reinterpret_cast<unsigned char*>
                                                       (&vData[0]);
            for (int y = 0;y<image.height();y++)
              for (int x = 0;x<image.width();x++) {
                unsigned char value = (unsigned char)(std::min(255.0f,m_fScale*pCharData[i]));
                image.setPixel(x,y, qRgb(value,value,value));
                i++;
              }
             } break;
      case 16 : {
            unsigned int i = 0;
            unsigned short* pShortData = reinterpret_cast<unsigned short*>
                                                         (&vData[0]);
            for (int y = 0;y<image.height();y++)
              for (int x = 0;x<image.width();x++) {
                unsigned char value = (unsigned char)(
                  std::min(255.0f, 255.0f * m_fScale * float(pShortData[i]) /
                                   float((2<<m_stackInfo->m_iStored)))
                );
                image.setPixel(x,y, qRgb(value,value,value));
                i++;
              }
             } break;
      default  : break; /// \todo handle other bitwith data
    }
  } else {
    /// \todo handle color data
  }
  icon.addPixmap(QPixmap::fromImage(image), QIcon::Normal, QIcon::Off);

  setIcon(icon);
  update();
}

#ifdef DETECTED_OS_WINDOWS
  #pragma warning(default:4996)
#endif


void QDataRadioButton::SetupInfo() {
  setMouseTracking(true);

  size_t iElemCount = m_stackInfo->m_Elements.size();

  QString desc = tr(" %1 \n Size: %2 x %3 x %4\n")
    .arg(m_stackInfo->m_strDesc.c_str())
    .arg(m_stackInfo->m_ivSize.x)
    .arg(m_stackInfo->m_ivSize.y)
    .arg(m_stackInfo->m_ivSize.z*iElemCount);

  setText(desc);

  SetStackImage(UINT32(iElemCount/2));
}