MedicalImageViewer.cpp 8.77 KB
Newer Older
1
/*****************************************************************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * $CAMITK_LICENCE_BEGIN$
 *
 * CamiTK - Computer Assisted Medical Intervention ToolKit
 * (c) 2001-2012 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
 *
 * Visit http://camitk.imag.fr for more information
 *
 * This file is part of CamiTK.
 *
 * CamiTK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * CamiTK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with CamiTK.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $CAMITK_LICENCE_END$
 ****************************************************************************/
25
26
27
28

// -- Core stuff
#include "MedicalImageViewer.h"
#include "InteractiveViewer.h"
29
#include "Application.h"
30
#include "Action.h"
31
32
33
34
35

//-- Qt stuff
#include <QColorDialog>
#include <QHBoxLayout>
#include <QGridLayout>
36
#include <QToolBar>
37

38
39
40
41
42
43
44
45
46
47
48
namespace camitk {
MedicalImageViewer* MedicalImageViewer::singleton = NULL;

MedicalImageViewer* MedicalImageViewer::getInstance() {
    if (!singleton)
        singleton = new MedicalImageViewer();

    return singleton;
}


49
50
// -------------------- Constructor --------------------
MedicalImageViewer::MedicalImageViewer() : Viewer("Medical Image Viewer") {
51
52
53
54
    // init view members
    frame = NULL;
    frameLayout = NULL;
    viewerMenu = NULL;
55

56
57
    // view only 3D scene by default
    visibleLayout = VIEWER_3D;
58

59
    displayedTopLevelComponents = 0;
60
61
62
63
64
}


// -------------------- Destructor --------------------
MedicalImageViewer::~MedicalImageViewer() {
65
66
    if (frame)
        delete frame;
67
68
69
70
71
}


// -------------------- numberOfViewedComponentgetWidget --------------------
unsigned int MedicalImageViewer::numberOfViewedComponent() {
72
73
74
75
76
77
78
    unsigned int count = 0;

    for(unsigned int i=0; viewerVisibility[i]!=VIEWER_ALL; i++) {
        count += viewers.value(viewerVisibility[i])->numberOfViewedComponent();
    }

    return count;
79
80
81
82
}

// -------------------- refresh --------------------
void MedicalImageViewer::refresh(Viewer *whoIsAsking) {
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    // just tell everyone to update!
    foreach(Viewer *v, viewers.values())
    v->refresh(this);

    // view everything?
    if (displayedTopLevelComponents != Application::getTopLevelComponents().size()) {
        // if there the nr of Component changed since last refresh,
        // and if there is something displayed in the slices viewer, show all view
        if (InteractiveViewer::getAxialViewer()->numberOfViewedComponent() > 0
                && InteractiveViewer::getCoronalViewer()->numberOfViewedComponent() > 0
                && InteractiveViewer::getSagittalViewer()->numberOfViewedComponent() > 0) {
            visibleLayout = VIEWER_ALL;
        }
        else {
            visibleLayout = VIEWER_3D;
        }

        updateLayout();

        // update the counter
        displayedTopLevelComponents = Application::getTopLevelComponents().size();
104
105
106
107
108
    }
}

// -------------------- getWidget --------------------
QWidget * MedicalImageViewer::getWidget(QWidget * parent) {
109
110
111
112
113
114
115
116
117
    if (!frame) {
        frame = new QFrame(parent);
        frame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);

        //-- init layout
        frameLayout = new QGridLayout(frame);
        frameLayout->setSpacing(0);
        frameLayout->setMargin(0);

promayon's avatar
promayon committed
118
        // gulp the enum 
119
120
121
122
        viewerVisibility.append(VIEWER_3D);
        viewerVisibility.append(VIEWER_AXIAL);
        viewerVisibility.append(VIEWER_CORONAL);
        viewerVisibility.append(VIEWER_SAGITTAL);
promayon's avatar
promayon committed
123
        viewerVisibility.append(VIEWER_ARBITRARY); // ARBITRARY has to be before ALL
124
125
126
127
128
129
130
131
132
133
        viewerVisibility.append(VIEWER_ALL); // ALL has to be the end of visible viewers

        // list of viewer name
        viewers.insert(VIEWER_3D, InteractiveViewer::get3DViewer());
        viewers.insert(VIEWER_ARBITRARY, InteractiveViewer::getArbitraryViewer());
        viewers.insert(VIEWER_AXIAL, InteractiveViewer::getAxialViewer());
        viewers.insert(VIEWER_CORONAL, InteractiveViewer::getCoronalViewer());
        viewers.insert(VIEWER_SAGITTAL, InteractiveViewer::getSagittalViewer());

        //-- add the InteractiveViewers
134
	topLeftLayout = new QVBoxLayout();
promayon's avatar
promayon committed
135
136
137
	frameLayout->addLayout(topLeftLayout, 0, 0);
        topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame)); // north-west
	topLeftLayout->addWidget(InteractiveViewer::getArbitraryViewer()->getWidget(frame)); // north-west
138
139
140
        frameLayout->addWidget(InteractiveViewer::getCoronalViewer()->getWidget(frame), 0, 1); // north-east
        frameLayout->addWidget(InteractiveViewer::getSagittalViewer()->getWidget(frame), 1, 0); // south-west
        frameLayout->addWidget(InteractiveViewer::get3DViewer()->getWidget(frame), 1, 1); // south-east
promayon's avatar
promayon committed
141
	
142
143
144
145
146
147
148
149
150
151
152
        //-- connect
        foreach(LayoutVisibility v, viewerVisibility) {
            if (viewers.value(v)) // prevent ALL
                connect(viewers.value(v), SIGNAL(selectionChanged()), this, SLOT(synchronizeSelection()));
        }

        //-- show the correct viewer
        updateLayout();
    }

    return frame;
153
154
155
156
}

// ---------------------- getPropertyObject ----------------------------
QObject * MedicalImageViewer::getPropertyObject() {
157
    return InteractiveViewer::get3DViewer();
158
159
160
161
}

// -------------------- getMenu --------------------
QMenu * MedicalImageViewer::getMenu() {
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
    if (!viewerMenu) {
        //-- create the main menu
        viewerMenu = new QMenu(objectName());
        viewerMenu->setTearOffEnabled(true);

	//-- build up menu
        QMenu * layoutMenu = new QMenu("Visible Viewers");
        viewerMenu->addMenu(layoutMenu);
        layoutMenu->addAction(Application::getAction("Show All Viewers")->getQAction());
        layoutMenu->addSeparator();

	//-- add the visibility action
        QActionGroup *viewerGroup = new QActionGroup(this);
        Application::getAction("Show All Viewers")->getQAction()->setActionGroup(viewerGroup);
	Application::getAction("Show 3D Viewer")->getQAction()->setActionGroup(viewerGroup);
	layoutMenu->addAction(Application::getAction("Show 3D Viewer")->getQAction());
	Application::getAction("Show Axial Viewer")->getQAction()->setActionGroup(viewerGroup);
	layoutMenu->addAction(Application::getAction("Show Axial Viewer")->getQAction());
        Application::getAction("Show Sagittal Viewer")->getQAction()->setActionGroup(viewerGroup);
	layoutMenu->addAction(Application::getAction("Show Sagittal Viewer")->getQAction());
        Application::getAction("Show Coronal Viewer")->getQAction()->setActionGroup(viewerGroup);
	layoutMenu->addAction(Application::getAction("Show Coronal Viewer")->getQAction());
promayon's avatar
promayon committed
184
185
186
	Application::getAction("Show Arbitrary Viewer")->getQAction()->setActionGroup(viewerGroup);
	layoutMenu->addAction(Application::getAction("Show Arbitrary Viewer")->getQAction());
	
187
188
189
190
191
192
193
194
        for(unsigned int i=0; viewerVisibility[i]!=VIEWER_ALL; i++) {
            // and viewer menu as submenu
            viewerMenu->addMenu(viewers.value(viewerVisibility[i])->getMenu());
        }

    }

    return viewerMenu;
195
196
197
198
}

// -------------------- getToolBar --------------------
QToolBar * MedicalImageViewer::getToolBar() {
199
    return viewers.value(VIEWER_3D)->getToolBar();
200
201
202
}


203
204
// -------------------- setVisibleViewer --------------------
void MedicalImageViewer::setVisibleViewer(LayoutVisibility visibleViewer) {
promayon's avatar
promayon committed
205
    
206
    visibleLayout = visibleViewer;
207

208
    updateLayout();
209
210
211
212
213
}

// -------------------- updateLayout --------------------
void MedicalImageViewer::updateLayout() {

214
    if (visibleLayout == VIEWER_ALL) {
promayon's avatar
promayon committed
215
216
217
218
219
	viewers.value(VIEWER_3D)->getWidget(frame)->show();
	viewers.value(VIEWER_AXIAL)->getWidget(frame)->show();
	viewers.value(VIEWER_CORONAL)->getWidget(frame)->show();
	viewers.value(VIEWER_SAGITTAL)->getWidget(frame)->show();
	viewers.value(VIEWER_ARBITRARY)->getWidget(frame)->hide();
220
221
222
223
224
    }
    else {
        for (unsigned int i=0; viewerVisibility[i]!=VIEWER_ALL; i++) {
            viewers.value(viewerVisibility[i])->getWidget(frame)->hide();
        }
promayon's avatar
promayon committed
225
	
226
227
        viewers.value(visibleLayout)->getWidget(frame)->show();
    }
228

229
230
    if (visibleLayout==VIEWER_3D || visibleLayout==VIEWER_ALL)
        getToolBar()->show();
231

232
}
233

234
235
236
// -------------------- synchronizeSelection --------------------
void MedicalImageViewer::synchronizeSelection() {
    Viewer * whoIsAsking = qobject_cast<Viewer *>(sender());
237

238
239
240
241
    foreach(Viewer *v, viewers.values()) {
        if (v != whoIsAsking)
            v->refresh(whoIsAsking);
    }
242

243
244
    // lets inform the extern viewers that there was a modification
    emit selectionChanged();
245
246
247
}

}
248