Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
displayformat.cpp
Go to the documentation of this file.
1 #include "Common.hpp"
2 #include "displayformat.h"
3 
4 #include <QDebug>
5 #include <QSettings>
6 
7 BW2DFormat::BW2DFormat( QObject *parent ) : DisplayFormat( parent ) {
12  m_numberOfViews = 1;
13  m_hasViewerControls = false;
14  m_enableTools = true;
15  m_rotateAll = false;
16  m_rotateSingle = true;
17  m_showNiftiViews = false;
18  m_showNiftiAxis = false;
19  m_showOrientation = false;
20  m_showPpmViews = false;
21  m_showPpmChannels = false;
22  m_hasOverlay = true;
23  m_hasLayout = false;
24  m_has3Views = false;
25  m_has4Views = false;
26  m_overlay = false;
28  loadSettings( );
29 }
30 
31 BW3DFormat::BW3DFormat( QObject *parent ) : DisplayFormat( parent ) {
36  m_numberOfViews = 3;
37  m_hasViewerControls = true;
38  m_enableTools = true;
39  m_rotateAll = true;
40  m_rotateSingle = false;
41  m_showNiftiViews = true;
42  m_showNiftiAxis = false;
43  m_showOrientation = true;
44  m_showPpmViews = false;
45  m_showPpmChannels = false;
46  m_hasOverlay = true;
47  m_hasLayout = true;
48  m_has3Views = true;
49  m_has4Views = false;
50  m_overlay = false;
52  loadSettings( );
53 }
54 
55 RGB2DFormat::RGB2DFormat( QObject *parent ) : DisplayFormat( parent ) {
60  m_numberOfViews = 1;
61  m_hasViewerControls = false;
62  m_enableTools = false;
63  m_rotateAll = true;
64  m_rotateSingle = false;
65  m_showNiftiViews = false;
66  m_showNiftiAxis = false;
67  m_showPpmViews = true;
68  m_showOrientation = false;
69  m_showPpmChannels = true;
70  m_hasOverlay = true;
71  m_hasLayout = false;
72  m_has3Views = false;
73  m_has4Views = true;
74  m_overlay = false;
76  loadSettings( );
77 }
78 
79 DisplayFormat::DisplayFormat( QObject *parent ) : QObject( parent ) {
80  m_overlayColor = Qt::green;
81 }
82 
84  QSettings settings;
85  settings.beginGroup( "DisplayFormat" );
86  settings.beginGroup( QString( "Type%1" ).arg( ( int ) modality( ) ) );
87  settings.setValue( "numberOfViews", m_numberOfViews );
88  settings.setValue( "currentLayout", ( int ) m_currentLayout );
89  settings.setValue( "currentViews", ( int ) m_currentViews );
90  settings.setValue( "defaultViews", ( int ) defaultViews );
91 }
92 
94  QSettings settings;
95  settings.beginGroup( "DisplayFormat" );
96  settings.beginGroup( QString( "Type%1" ).arg( ( int ) modality( ) ) );
97  if( settings.contains( "numberOfViews" ) ) {
98  try {
99  setNumberOfViews( settings.value( "numberOfViews" ).toInt( ) );
100  }
101  catch( std::invalid_argument e ) {
102  return;
103  }
104  }
105  if( settings.contains( "currentLayout" ) ) {
106  try {
107  setCurrentLayout( ( Layout ) settings.value( "currentLayout" ).toInt( ) );
108  }
109  catch( std::invalid_argument e ) {
110  return;
111  }
112  }
113  if( settings.contains( "currentViews" ) ) {
114  try {
115  setCurrentViews( ( Views ) settings.value( "currentViews" ).toInt( ) );
116  }
117  catch( std::invalid_argument e ) {
118  return;
119  }
120  }
121  if( settings.contains( "defaultViews" ) ) {
122  defaultViews = ( Views ) settings.value( "defaultViews" ).toInt( );
123  }
124 }
126  return( m_maximumNumberOfViews );
127 }
128 
130  return( m_modality );
131 }
133  return( m_currentLayout );
134 }
136  return( m_currentViews );
137 }
139  return( m_hasViewerControls );
140 }
142  return( m_enableTools );
143 }
145  return( m_rotateAll );
146 }
148  return( m_rotateSingle );
149 }
151  return( m_hasOverlay );
152 }
154  return( m_showNiftiViews );
155 }
157  return( m_showNiftiAxis );
158 }
160  return( m_showOrientation );
161 }
163  return( m_showPpmViews );
164 }
166  return( m_showPpmChannels );
167 }
169  return( m_hasLayout );
170 }
172  return( m_has3Views );
173 }
175  return( m_has4Views );
176 }
177 
178 std::array< bool, 4 > DisplayFormat::getViews( ) {
179  std::array< bool, 4 > views;
180 
181  views[ 0 ] = ( int ) currentViews( ) & ( int ) Views::SHOW0;
182  views[ 1 ] = ( int ) currentViews( ) & ( int ) Views::SHOW1;
183  views[ 2 ] = ( int ) currentViews( ) & ( int ) Views::SHOW2;
184  views[ 3 ] = ( int ) currentViews( ) & ( int ) Views::SHOW3;
185 
186  return( views );
187 }
189  return( m_numberOfViews );
190 }
191 
193  return( m_overlayColor );
194 }
195 
198  emit updated( );
199 }
200 
201 bool DisplayFormat::overlay( ) const {
202  return( m_overlay );
203 }
204 
206  COMMENT( "Layout set to " << ( int ) currentLayout, 0 );
208  emit updated( );
209 }
210 
212  COMMENT( "currentViews set to " << ( int ) currentViews, 0 );
214  if( currentViews <= Views::SHOW3 ) {
216  }
217  emit updated( );
218 }
219 
221  COMMENT( "Overlay set to " << overlay, 0 );
222  if( m_hasOverlay ) {
223  m_overlay = overlay;
224  emit updated( );
225  }
226 }
227 
229  setOverlay( !overlay( ) );
230 }
231 
232 void BW2DFormat::setNumberOfViews( int numberOfViews ) {
233  if( numberOfViews != 1 ) {
234  throw std::invalid_argument( "The number of views cannot be changed!" );
235  }
236 }
237 
238 void BW3DFormat::setNumberOfViews( int numberOfViews ) {
239  COMMENT( "Number of views set to " << numberOfViews << ".", 0 );
240  if( ( numberOfViews != 1 ) && ( numberOfViews != 3 ) ) {
241  throw std::invalid_argument( "Invalid number of views!" );
242  }
243  if( numberOfViews == 1 ) {
245  m_showNiftiAxis = true;
246  m_showOrientation = false;
247  }
248  else {
250  m_showNiftiAxis = false;
251  m_showOrientation = true;
252  }
253  m_numberOfViews = numberOfViews;
254  emit updated( );
255 }
256 
257 void RGB2DFormat::setNumberOfViews( int numberOfViews ) {
258  if( ( numberOfViews != 1 ) && ( numberOfViews != 4 ) ) {
259  throw std::invalid_argument( "Invalid number of views!" );
260  }
261  if( numberOfViews == 1 ) {
263  m_showPpmChannels = true;
264  }
265  else {
267  m_showPpmChannels = false;
268  }
269  m_numberOfViews = numberOfViews;
270  emit updated( );
271 }
bool m_showNiftiViews
Definition: displayformat.h:90
Modality
Definition: displayformat.h:9
virtual void setCurrentViews(const Views &currentViews)
RGB2DFormat(QObject *parent=0)
Modality modality() const
size_t getMaximumNumberOfViews() const
Modality m_modality
Definition: displayformat.h:73
void setOverlayColor(const QColor &overlayColor)
virtual void setNumberOfViews(int numberOfViews)=0
Content: Commonly used macros, types, static variables and functions. Description: Some macros used...
BW3DFormat(QObject *parent=0)
bool showNiftiAxis() const
int getNumberOfViews() const
Views
Definition: displayformat.h:11
void setNumberOfViews(int numberOfViews)
DisplayFormat(QObject *parent)
bool hasOverlay() const
bool m_showPpmChannels
Definition: displayformat.h:94
bool showPpmViews() const
Views defaultViews
Definition: displayformat.h:96
bool showNiftiViews() const
bool hasLayout() const
bool enableTools() const
BW2DFormat(QObject *parent=0)
void setNumberOfViews(int numberOfViews)
bool showOrientation() const
bool hasViewerControls() const
std::array< bool, 4 > getViews()
QColor overlayColor() const
void setOverlay(bool overlay)
bool m_hasViewerControls
Definition: displayformat.h:80
bool rotateSingle() const
void setNumberOfViews(int numberOfViews)
QColor m_overlayColor
Definition: displayformat.h:99
Views m_currentViews
Definition: displayformat.h:75
bool overlay() const
bool has3Views() const
bool showPpmChannels() const
Layout m_currentLayout
Definition: displayformat.h:74
Layout currentLayout() const
Views currentViews() const
bool rotateAll() const
bool m_showNiftiAxis
Definition: displayformat.h:91
bool m_showOrientation
Definition: displayformat.h:92
Layout
Definition: displayformat.h:10
size_t m_maximumNumberOfViews
Definition: displayformat.h:98
bool has4Views() const
virtual void setCurrentLayout(const Layout &currentLayout)