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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
|
/*LICENSE_START*/
/*
* Copyright 1995-2002 Washington University School of Medicine
*
* http://brainmap.wustl.edu
*
* This file is part of CARET.
*
* CARET is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CARET 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CARET; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*LICENSE_END*/
#include <iostream>
#include <QApplication>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QLayout>
#include <QMessageBox>
#include <QPushButton>
#include "AreaColorFile.h"
#include "BrainModelVolume.h"
#include "BrainModelVolumeVoxelColoring.h"
#include "BrainSet.h"
#include "GuiBrainModelOpenGL.h"
#include "GuiColorSelectionDialog.h"
#include "GuiFilesModified.h"
#include "GuiMainWindow.h"
#include "GuiNameSelectionDialog.h"
#include "GuiVolumePaintEditorDialog.h"
#include "QtUtilities.h"
#include "global_variables.h"
/**
* Constructor.
*/
GuiVolumePaintEditorDialog::GuiVolumePaintEditorDialog(QWidget* parent)
: WuQDialog(parent)
{
setWindowTitle("Paint Volume Editor");
//
// Vertical box for all items in dialog
//
QVBoxLayout* dialogLayout = new QVBoxLayout(this);
dialogLayout->setMargin(5);
dialogLayout->setSpacing(2);
//
// Create the toggle voxels section
//
dialogLayout->addWidget(createToggleVoxelsSection());
//
// Paint name
//
QLabel* paintNameLabel = new QLabel("Paint Name ");
paintNameLineEdit = new QLineEdit;
QPushButton* nameButton = new QPushButton("Select...");
nameButton->setFixedSize(nameButton->sizeHint());
nameButton->setAutoDefault(false);
QObject::connect(nameButton, SIGNAL(clicked()),
this, SLOT(slotNameSelectionPushButton()));
//
// Arrange paint name items
//
QHBoxLayout* paintNameLayout = new QHBoxLayout;
paintNameLayout->addWidget(paintNameLabel);
paintNameLayout->addWidget(paintNameLineEdit);
paintNameLayout->addWidget(nameButton);
paintNameLayout->setStretchFactor(paintNameLabel, 0);
paintNameLayout->setStretchFactor(paintNameLineEdit, 1000);
paintNameLayout->setStretchFactor(nameButton, 0);
dialogLayout->addLayout(paintNameLayout);
//
// Horizontal layout for buttons
//
QHBoxLayout* buttonsLayout = new QHBoxLayout;
buttonsLayout->setSpacing(2);
dialogLayout->addLayout(buttonsLayout);
//
// Apply button
//
QPushButton* applyButton = new QPushButton("Apply");
buttonsLayout->addWidget(applyButton);
applyButton->setAutoDefault(false);
QObject::connect(applyButton, SIGNAL(clicked()),
this, SLOT(slotApplyButton()));
//
//
// Undo button
//
undoButton = new QPushButton("Undo");
buttonsLayout->addWidget(undoButton);
undoButton->setAutoDefault(false);
QObject::connect(undoButton, SIGNAL(clicked()),
this, SLOT(slotUndoButton()));
//
// Close button
//
QPushButton* closeButton = new QPushButton("Close");
buttonsLayout->addWidget(closeButton);
closeButton->setAutoDefault(false);
QObject::connect(closeButton, SIGNAL(clicked()),
this, SLOT(close()));
//
// Make buttons same size
//
QtUtilities::makeButtonsSameSize(applyButton, undoButton, closeButton);
//
// Initialize dialog
//
clearUndoStack();
//
// Update the dialog
//
updateDialog();
}
/**
* Destructor.
*/
GuiVolumePaintEditorDialog::~GuiVolumePaintEditorDialog()
{
}
/**
* called when name select push button is pressed.
*/
void
GuiVolumePaintEditorDialog::slotNameSelectionPushButton()
{
static GuiNameSelectionDialog::LIST_ITEMS_TYPE itemForDisplay =
GuiNameSelectionDialog::LIST_AREA_COLORS_ALPHA;
GuiNameSelectionDialog nsd(this,
GuiNameSelectionDialog::LIST_ALL,
itemForDisplay);
if (nsd.exec() == QDialog::Accepted) {
QString name(nsd.getNameSelected());
if (name.isEmpty() == false) {
paintNameLineEdit->setText(name);
}
}
}
/**
* update the dialog.
*/
void
GuiVolumePaintEditorDialog::updateDialog()
{
}
/**
* called when apply button is pressed.
*/
void
GuiVolumePaintEditorDialog::slotApplyButton()
{
QString paintName = paintNameLineEdit->text();
//
// Find the matching color
//
bool areaColorMatch = false;
AreaColorFile* areaColorFile = theMainWindow->getBrainSet()->getAreaColorFile();
const int areaColorIndex = areaColorFile->getColorIndexByName(paintName, areaColorMatch);
//
// Area color may need to be created
//
if (areaColorMatch == false) {
QString msg("Matching area color \"");
msg.append(paintName);
msg.append("\" not found");
QString defineButtonText("Define Area Color ");
int result = 0;
if (areaColorIndex >= 0) {
QString partialMatchButtonText("Use ");
partialMatchButtonText.append(areaColorFile->getColorNameByIndex(areaColorIndex));
QMessageBox msgBox(this);
msgBox.setWindowTitle("Set Area Color");
msgBox.setText(msg);
msgBox.addButton(defineButtonText, QMessageBox::ActionRole);
QPushButton* partialMatchPushButton = msgBox.addButton(partialMatchButtonText,
QMessageBox::ActionRole);
if (msgBox.clickedButton() == partialMatchPushButton) {
result = 1;
}
else {
result = 0;
}
}
if (result == 0) {
//
// define the area color
//
QString title("Create Area Color: ");
title.append(paintName);
GuiColorSelectionDialog* csd = new GuiColorSelectionDialog(this,
title,
false,
false,
false,
false);
csd->exec();
//
// Add new area color
//
float pointSize = 2.0, lineSize = 1.0;
unsigned char r, g, b, a;
ColorFile::ColorStorage::SYMBOL symbol;
csd->getColorInformation(r, g, b, a, pointSize, lineSize, symbol);
areaColorFile->addColor(paintName, r, g, b, a, pointSize, lineSize, symbol);
//
// Area Color File has changed
//
GuiFilesModified fm;
fm.setAreaColorModified();
theMainWindow->fileModificationUpdate(fm);
}
else if (result == 2) {
//
// do nothing so that partially matching color is used
//
}
}
theMainWindow->getBrainModelOpenGL()->setMouseMode(
GuiBrainModelOpenGL::MOUSE_MODE_VOLUME_PAINT_EDIT);
}
/**
* Create the toggle voxels widget.
*/
QWidget*
GuiVolumePaintEditorDialog::createToggleVoxelsSection()
{
//
// Voxel size combo box and label
//
QLabel* toggleVoxelsLabel = new QLabel("Brush Size");
toggleVoxelsSizeComboBox = new QComboBox;
toggleVoxelsSizeComboBox->insertItem(TOGGLE_VOXELS_SIZE_1_BY_1, "1 x 1");
toggleVoxelsSizeComboBox->insertItem(TOGGLE_VOXELS_SIZE_3_BY_3, "3 x 3");
toggleVoxelsSizeComboBox->insertItem(TOGGLE_VOXELS_SIZE_5_BY_5, "5 x 5");
toggleVoxelsSizeComboBox->insertItem(TOGGLE_VOXELS_SIZE_7_BY_7, "7 x 7");
toggleVoxelsSizeComboBox->insertItem(TOGGLE_VOXELS_SIZE_9_BY_9, "9 x 9");
toggleVoxelsSizeComboBox->insertItem(TOGGLE_VOXELS_SIZE_11_BY_11, "11 x 11");
toggleVoxelsSizeComboBox->setCurrentIndex(TOGGLE_VOXELS_SIZE_1_BY_1);
//
// Layout the items
//
QWidget* toggleVoxelsWidget = new QWidget;
QHBoxLayout* toggleVoxelsLayout = new QHBoxLayout(toggleVoxelsWidget);
toggleVoxelsLayout->addWidget(toggleVoxelsLabel);
toggleVoxelsLayout->addWidget(toggleVoxelsSizeComboBox);
toggleVoxelsLayout->addStretch();
return toggleVoxelsWidget;
}
/**
* called when dialog is closed.
*/
void
GuiVolumePaintEditorDialog::close()
{
clearUndoStack();
//
// If in paint edit mode, switch to view mode
//
GuiBrainModelOpenGL* openGL = theMainWindow->getBrainModelOpenGL();
if (openGL->getMouseMode() == GuiBrainModelOpenGL::MOUSE_MODE_VOLUME_PAINT_EDIT) {
openGL->setMouseMode(GuiBrainModelOpenGL::MOUSE_MODE_VIEW);
}
QDialog::close();
}
/**
* called when dialog is popped up.
*/
void
GuiVolumePaintEditorDialog::show()
{
clearUndoStack();
WuQDialog::show();
theMainWindow->getBrainModelOpenGL()->setMouseMode(
GuiBrainModelOpenGL::MOUSE_MODE_VOLUME_PAINT_EDIT);
}
/**
* Called when a voxel is selected for editing in the main window.
*/
void
GuiVolumePaintEditorDialog::processVoxel(const int ii, const int jj, const int kk,
const VolumeFile::VOLUME_AXIS pickAxis)
{
BrainModelVolume* bmv = theMainWindow->getBrainModelVolume();
if (bmv == NULL) {
close();
return;
}
VolumeFile::VOLUME_AXIS axis = bmv->getSelectedAxis(0);
switch (axis) {
case VolumeFile::VOLUME_AXIS_X:
break;
case VolumeFile::VOLUME_AXIS_Y:
break;
case VolumeFile::VOLUME_AXIS_Z:
break;
case VolumeFile::VOLUME_AXIS_ALL:
if ((pickAxis == VolumeFile::VOLUME_AXIS_X) ||
(pickAxis == VolumeFile::VOLUME_AXIS_Y) ||
(pickAxis == VolumeFile::VOLUME_AXIS_Z)) {
axis = pickAxis;
}
else {
return;
}
break;
case VolumeFile::VOLUME_AXIS_OBLIQUE:
case VolumeFile::VOLUME_AXIS_OBLIQUE_X:
case VolumeFile::VOLUME_AXIS_OBLIQUE_Y:
case VolumeFile::VOLUME_AXIS_OBLIQUE_Z:
case VolumeFile::VOLUME_AXIS_OBLIQUE_ALL:
QApplication::restoreOverrideCursor();
QMessageBox::critical(this, "ERROR",
"Editing of oblique slices is not allowed.");
return;
case VolumeFile::VOLUME_AXIS_UNKNOWN:
return;
break;
}
VolumeFile* vf = bmv->getSelectedVolumePaintFile();
if (vf != NULL) {
//
// Set indice range for voxels that are to be processed
//
int mm = 0;
switch (static_cast<TOGGLE_VOXELS_SIZE>(toggleVoxelsSizeComboBox->currentIndex())) {
case TOGGLE_VOXELS_SIZE_1_BY_1:
mm = 0;
break;
case TOGGLE_VOXELS_SIZE_3_BY_3:
mm = 1;
break;
case TOGGLE_VOXELS_SIZE_5_BY_5:
mm = 2;
break;
case TOGGLE_VOXELS_SIZE_7_BY_7:
mm = 3;
break;
case TOGGLE_VOXELS_SIZE_9_BY_9:
mm = 4;
break;
case TOGGLE_VOXELS_SIZE_11_BY_11:
mm = 5;
break;
}
int ijkMin[3] = { ii - mm, jj - mm, kk - mm };
int ijkMax[3] = { ii + mm, jj + mm, kk + mm };
//
// Process three dim aspect
//
int threeDim = 0;
switch (axis) {
case VolumeFile::VOLUME_AXIS_X:
ijkMin[0] = ii - threeDim;
ijkMax[0] = ii + threeDim;
break;
case VolumeFile::VOLUME_AXIS_Y:
ijkMin[1] = jj - threeDim;
ijkMax[1] = jj + threeDim;
break;
case VolumeFile::VOLUME_AXIS_Z:
ijkMin[2] = kk - threeDim;
ijkMax[2] = kk + threeDim;
break;
case VolumeFile::VOLUME_AXIS_ALL:
case VolumeFile::VOLUME_AXIS_OBLIQUE:
case VolumeFile::VOLUME_AXIS_OBLIQUE_X:
case VolumeFile::VOLUME_AXIS_OBLIQUE_Y:
case VolumeFile::VOLUME_AXIS_OBLIQUE_Z:
case VolumeFile::VOLUME_AXIS_OBLIQUE_ALL:
case VolumeFile::VOLUME_AXIS_UNKNOWN:
break;
}
VolumeModification modifiedVoxels;
//
// Perform operation on the volume
//
vf->assignPaintVolumeVoxels(paintNameLineEdit->text(),
ijkMin,
ijkMax,
&modifiedVoxels);
if (modifiedVoxels.getNumberOfVoxels()) {
undoStack.push(modifiedVoxels);
}
enableUndoButton();
GuiBrainModelOpenGL::updateAllGL();
}
QApplication::restoreOverrideCursor();
}
/**
* Clear the undo stack
*/
void
GuiVolumePaintEditorDialog::clearUndoStack()
{
while (undoStack.empty() == false) {
undoStack.pop();
}
enableUndoButton();
}
/**
* Called when the undo button is pressed.
*/
void
GuiVolumePaintEditorDialog::slotUndoButton()
{
BrainModelVolume* bmv = theMainWindow->getBrainModelVolume();
if (bmv == NULL) {
close();
return;
}
VolumeFile* vf = bmv->getSelectedVolumePaintFile();
if (vf != NULL) {
if (undoStack.empty() == false) {
VolumeModification volumeModification = undoStack.top();
undoStack.pop();
vf->undoModification(&volumeModification);
}
GuiBrainModelOpenGL::updateAllGL();
}
enableUndoButton();
}
/**
* Enable the undo button.
*/
void
GuiVolumePaintEditorDialog::enableUndoButton()
{
undoButton->setEnabled(undoStack.empty() == false);
}
|