00001
00012
00013
00014 #include "imedgine_slice_viewer.h"
00015 #include "slice_pixel_view.h"
00016 #include "../controller/controller.h"
00017 #include "polyline_ROI.h"
00018
00019 #include <Inventor/actions/SoRayPickAction.h>
00020 #include <Inventor/SoPickedPoint.h>
00021 #include <Inventor/Qt/SoQtCursor.h>
00022 #include <Inventor/nodes/SoTexture2.h>
00023 #include <Inventor/nodes/SoBaseColor.h>
00024 #include <Inventor/nodes/SoCone.h>
00025 #include <Inventor/sensors/SoFieldSensor.h>
00026 #include <Inventor/projectors/SbPlaneProjector.h>
00027
00028
00029 #include <QPixmap>
00030 #include <QImage>
00031 #include <QDataStream>
00032
00033 #include <sstream>
00034 #include <limits>
00035
00036 #include <stdio.h>
00037
00038 namespace imedgine
00039 {
00040 ImedgineSliceViewer::ImedgineSliceViewer(
00041 SlicePixelView* slice_view, QWidget* parent, const char* name )
00042 : ImedgineViewer(parent, name),
00043 slice_view_(slice_view),
00044 view_mode_(DEFAULT_MODE),
00045 region_of_interest_(0),
00046 double_click_check_time_(0.0),
00047 is_hybrid_view_(false),
00048 mouse_movement_scaling_factor_(1.0),
00049 ignore_next_slice_slider_update_(false)
00050 {
00051 QWidget* widget = this->buildWidget(this->getParentWidget());
00052 this->setBaseWidget(widget);
00053 this->setDecoration(false);
00054
00055 popup_button_sep_ = new SoSeparator;
00056 slice_view_->getStaticSceneSeparator()->addChild(popup_button_sep_);
00057
00058 SoTransform* popup_button_transform_ = new SoTransform;
00059 popup_button_transform_->translation = SbVec3f(-0.94, 0.93, 0.3);
00060 popup_button_sep_->addChild(popup_button_transform_);
00061
00062 SoTexture2* popup_button_texture = new SoTexture2;
00063 popup_button_sep_->addChild(popup_button_texture);
00064
00065 QPixmap temp_pixmap(":/icons/document-open.png");
00066
00067 unsigned char* converted_image = temp_pixmap.toImage().bits();
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 std::cout << "Num bytes: " << temp_pixmap.toImage().numBytes() << std::endl;
00083 std::cout << "Num bytes per line: " << temp_pixmap.toImage().bytesPerLine() << std::endl;
00084 std::cout << "Height: " << temp_pixmap.toImage().size().height() << std::endl;
00085 std::cout << "Width: " << temp_pixmap.toImage().size().width() << std::endl;
00086
00087 popup_button_texture->image.setValue(
00088 SbVec2s(16,16),
00089 4, converted_image);
00090
00091 popup_button_ = new SoCube;
00092 popup_button_->depth = 0;
00093 popup_button_->height = 0.1;
00094 popup_button_->width = 0.1;
00095 popup_button_sep_->addChild(popup_button_);
00096
00097 status_info_sep_ = new SoSeparator;
00098 slice_view_->getStaticSceneSeparator()->addChild(status_info_sep_);
00099 SoBaseColor* status_info_color = new SoBaseColor;
00100 status_info_color->rgb = SbVec3f(0, 1, 0);
00101 status_info_sep_->addChild(status_info_color);
00102
00103
00104 slice_status_info_transform_ = new SoTransform;
00105 slice_status_info_transform_->translation.setValue(0.97, 0.92, 0.3);
00106 status_info_sep_->addChild(slice_status_info_transform_);
00107 slice_status_info_text_ = new SoText2;
00108 slice_status_info_text_->justification = SoText2::RIGHT;
00109 status_info_sep_->addChild(slice_status_info_text_);
00110
00111
00112 dataset_status_info_transform_ = new SoTransform;
00113 dataset_status_info_transform_->translation.setValue(-1.8, 0, 0);
00114 status_info_sep_->addChild(dataset_status_info_transform_);
00115 dataset_status_info_text_ = new SoText2;
00116 dataset_status_info_text_->justification = SoText2::LEFT;
00117 status_info_sep_->addChild(dataset_status_info_text_);
00118
00119
00120 slice_slider_sep_ = new SoSeparator;
00121 slice_view_->getStaticSceneSeparator()->addChild(slice_slider_sep_);
00122 SoTransform* slice_slider_transform = new SoTransform;
00123 slice_slider_transform->scaleFactor.setValue(0.1, 0.1, 0.1);
00124 slice_slider_transform->translation.setValue(0, -0.90, 0.3);
00125
00126 slice_slider_sep_->addChild(slice_slider_transform);
00127 slice_slider_dragger_ = new SoTranslate1Dragger;
00128 slice_slider_sep_->addChild(slice_slider_dragger_);
00129 SoMaterial* slice_slider_material = new SoMaterial;
00130 slice_slider_sep_->addChild(slice_slider_material);
00131 slice_slider_material->diffuseColor.setValue(0, 1, 0);
00132 slice_slider_material->transparency = 0.86;
00133 SoCube* slice_slider_area = new SoCube;
00134 slice_slider_sep_->addChild(slice_slider_area);
00135 slice_slider_area->depth = 0;
00136 slice_slider_area->width = 15;
00137 slice_slider_area->height = 0.15;
00138 SoFieldSensor *sliceSliderSensor =
00139 new SoFieldSensor(sliceSliderPositionChangedCB, this);
00140 sliceSliderSensor->attach(&slice_slider_dragger_->translation);
00141
00142
00143 transparency_slider_switch_ = new SoSwitch;
00144 transparency_slider_switch_->whichChild = SO_SWITCH_NONE;
00145 slice_view_->getStaticSceneSeparator()->addChild(transparency_slider_switch_);
00146 transparency_slider_sep_ = new SoSeparator;
00147 transparency_slider_switch_->addChild(transparency_slider_sep_);
00148 SoTransform* transparency_slider_transform = new SoTransform;
00149 transparency_slider_transform->scaleFactor.setValue(0.1, 0.1, 0.1);
00150 transparency_slider_transform->translation.setValue(-0.94, 0, 0.3);
00151 transparency_slider_transform->rotation = SbRotation(SbVec3f(0, 0, 1), M_PI/2);
00152 transparency_slider_sep_->addChild(transparency_slider_transform);
00153 transparency_slider_dragger_ = new SoTranslate1Dragger;
00154 transparency_slider_sep_->addChild(transparency_slider_dragger_);
00155 SoMaterial* transparency_slider_material = new SoMaterial;
00156 transparency_slider_sep_->addChild(transparency_slider_material);
00157 transparency_slider_material->diffuseColor.setValue(0, 1, 0);
00158 transparency_slider_material->transparency = 0.86;
00159 SoCube* transparency_slider_area = new SoCube;
00160 transparency_slider_sep_->addChild(transparency_slider_area);
00161 transparency_slider_area->depth = 0;
00162 transparency_slider_area->width = 15;
00163 transparency_slider_area->height = 0.15;
00164 SoFieldSensor *transparencySliderSensor = new
00165 SoFieldSensor(transparencySliderPositionChangedCB, this);
00166 transparencySliderSensor->attach(&transparency_slider_dragger_->translation);
00167
00168 region_of_interest_sep_ = new SoSeparator;
00169 slice_view_->getDynamicSceneSeparator()->addChild(region_of_interest_sep_);
00170
00171 mouse_movement_scaling_factor_ = (slice_view_->getMaxPixelValue() -
00172 slice_view_->getMinPixelValue()) / 1200.0;
00173 }
00174
00175
00176
00177 ImedgineSliceViewer::~ImedgineSliceViewer()
00178 {
00179 #ifdef DEBUG
00180 std::cout << "Deleting ImedgineSliceViewer" << std::endl;
00181 #endif
00182 }
00183
00184
00185
00186 SbBool ImedgineSliceViewer::processSoEvent(const SoEvent * const ev)
00187 {
00188 const SoType type(ev->getTypeId());;
00189
00190
00191
00192 this->setComponentCursor(SoQtCursor::DEFAULT);
00193
00194 if (type.isDerivedFrom(SoLocation2Event::getClassTypeId()))
00195 {
00196 const SoLocation2Event * event = dynamic_cast<const SoLocation2Event *>(ev);
00197 SbVec2s pos = ev->getPosition();
00198
00199 if (view_mode_ == ZOOM_IN_OUT_MODE)
00200 {
00201
00202 this->setComponentCursor(SoQtCursor::getZoomCursor());
00203
00204 int diff = last_position_[Y_DIMENSION] - pos[Y_DIMENSION];
00205
00206 SbViewVolume view_volume = this->getCamera()->getViewVolume();
00207
00208
00209 if (diff < 0)
00210 {
00211
00212 if (view_volume.getHeight() < 0.3)
00213 {
00214 return(false);
00215 }
00216 else if (diff == 0)
00217 {
00218 return(false);
00219 }
00220 else if (diff % 3 == 0)
00221 {
00222 last_position_ = event->getPosition();
00223 last_button_click_event_->setButton(SoMouseButtonEvent::BUTTON5);
00224 return(ImedgineViewer::processSoEvent(last_button_click_event_.get()));
00225 }
00226 }
00227
00228 else
00229 {
00230
00231 if (view_volume.getHeight() > 5)
00232 {
00233 return(false);
00234 }
00235 else if (diff == 0)
00236 {
00237 return(false);
00238 }
00239 else if (diff % 3 == 0)
00240 {
00241 last_position_ = event->getPosition();
00242 last_button_click_event_->setButton(SoMouseButtonEvent::BUTTON4);
00243 return(ImedgineViewer::processSoEvent(last_button_click_event_.get()));
00244 }
00245 }
00246 }
00247 }
00248
00249 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId()))
00250 {
00251 const SoMouseButtonEvent * const event = dynamic_cast<const SoMouseButtonEvent *>(ev);
00252 const int button = event->getButton();
00253
00254 const SbVec2s size(this->getGLSize());
00255 const SbVec2s pos(ev->getPosition());
00256
00257 switch (button)
00258 {
00259 case SoMouseButtonEvent::BUTTON1:
00260 {
00261 if (SoMouseButtonEvent::isButtonPressEvent(event,
00262 SoMouseButtonEvent::BUTTON1))
00263 {
00264 view_mode_ = FAST_SLICE_SCROLL_MODE;
00265
00266
00267 left_mouse_button_press_location_ = pos;
00268
00269
00270 if (Controller::getInstance().getGuiInteractionMode() ==
00271 REGION_OF_INTEREST_POLY_LINE_MODE)
00272 {
00273 if (region_of_interest_ == 0)
00274 {
00275 region_of_interest_ = new PolylineROI(region_of_interest_sep_);
00276 }
00277
00278 try
00279 {
00280 static_cast<PolylineROI*>(region_of_interest_)->addPoint(convertCoordsFromWorldToSpace(pos));
00281 static_cast<PolylineROI*>(region_of_interest_)->drawROI();
00282 }
00283 catch (NullPointerException const&)
00284 {
00285
00286
00287 }
00288
00289 return (false);
00290 }
00291
00292
00293 SoRayPickAction rp(slice_view_->getRenderArea()->getViewportRegion());
00294 rp.setPoint(pos);
00295 rp.apply(slice_view_->getRenderArea()->getSceneGraph());
00296
00297 if ((rp.getPickedPoint() != 0) &&
00298 (rp.getPickedPoint()->getPath()->getTail() == popup_button_))
00299 {
00300 buildPopupMenu();
00301
00302 std::auto_ptr<SoMouseButtonEvent> popup_button_click;
00303 popup_button_click.reset(new SoMouseButtonEvent(*event));
00304 popup_button_click->setButton(SoMouseButtonEvent::BUTTON2);
00305 return(ImedgineViewer::processSoEvent(popup_button_click.get()));
00306 }
00307
00308
00309 else if ((rp.getPickedPoint() != 0) &&
00310 ((rp.getPickedPoint()->getPath()->getTail() == slice_slider_dragger_) ||
00311 (rp.getPickedPoint()->getPath()->getTail() == transparency_slider_dragger_)))
00312 {
00313 this->setViewing(false);
00314 view_mode_ = SLIDER_MOVE_MODE;
00315 return(ImedgineViewer::processSoEvent(ev));
00316 }
00317
00318
00319 if (double_click_check_time_ == 0.0)
00320 {
00321 double_click_check_time_ = ev->getTime();
00322 return(false);
00323 }
00324
00325 double_click_check_time_ = ev->getTime() - double_click_check_time_;
00326
00327 if (double_click_check_time_ < 0.5)
00328 {
00329 SbVec2s texture_coords;
00330 if (!convertCoordsFromScreenToTexture(pos, texture_coords))
00331 {
00332 return(false);
00333 }
00334
00335 slice_view_->setFocusPoint2D(
00336 texture_coords[X_DIMENSION],
00337 texture_coords[Y_DIMENSION]);
00338
00339
00340 double_click_check_time_ = 0.0;
00341 }
00342 else
00343 {
00344 double_click_check_time_ = ev->getTime();
00345 }
00346 }
00347
00348 if (SoMouseButtonEvent::isButtonReleaseEvent(event,
00349 SoMouseButtonEvent::BUTTON1))
00350 {
00351 if (view_mode_ == SLIDER_MOVE_MODE)
00352 {
00353 view_mode_ = DEFAULT_MODE;
00354 ImedgineViewer::processSoEvent(ev);
00355 this->setViewing(true);
00356 return (false);
00357 }
00358
00359
00360 SbVec2s left_mouse_button_release_location = pos;
00361
00362 int x_difference = left_mouse_button_release_location[X_DIMENSION] -
00363 left_mouse_button_press_location_[X_DIMENSION];
00364 int y_difference = left_mouse_button_release_location[Y_DIMENSION] -
00365 left_mouse_button_press_location_[Y_DIMENSION];
00366
00367
00368
00369
00370 double new_window = slice_view_->getIntensityWindow();
00371 new_window += x_difference * mouse_movement_scaling_factor_;
00372 if (new_window < 0)
00373 {
00374 new_window = 1;
00375 }
00376
00377 double new_level = slice_view_->getIntensityLevel();
00378 new_level += y_difference * mouse_movement_scaling_factor_;
00379
00380 slice_view_->setIntensity(new_window, new_level);
00381
00382 view_mode_ = DEFAULT_MODE;
00383 }
00384
00385 return(false);
00386 }
00387
00388 case SoMouseButtonEvent::BUTTON2:
00389 {
00390
00391 if (Controller::getInstance().getGuiInteractionMode() == REGION_OF_INTEREST_POLY_LINE_MODE)
00392 {
00393
00394 static_cast<PolylineROI*>(region_of_interest_)->autoCloseROI();
00395 static_cast<PolylineROI*>(region_of_interest_)->drawROI();
00396
00397 Controller::getInstance().setGuiInteractionMode(STANDARD_MODE);
00398 return (false);
00399 }
00400
00401 last_position_ = event->getPosition();
00402 last_button_click_event_.reset(new SoMouseButtonEvent(*event));
00403
00404 if (SoMouseButtonEvent::isButtonPressEvent(event,
00405 SoMouseButtonEvent::BUTTON2))
00406 {
00407 view_mode_ = ZOOM_IN_OUT_MODE;
00408 }
00409 else
00410 {
00411 view_mode_ = DEFAULT_MODE;
00412 }
00413
00414 return(false);
00415 }
00416 case SoMouseButtonEvent::BUTTON3:
00417 {
00418 return(ImedgineViewer::processSoEvent(event));
00419 }
00420 case SoMouseButtonEvent::BUTTON4:
00421 {
00422 int current_slide_index = slice_view_->getSliceIndex();
00423
00424 if (view_mode_ == FAST_SLICE_SCROLL_MODE)
00425 {
00426 current_slide_index += 10;
00427 }
00428 else
00429 {
00430 ++current_slide_index;
00431 }
00432 slice_view_->setSliceIndex(current_slide_index);
00433 return(false);
00434 }
00435 case SoMouseButtonEvent::BUTTON5:
00436 {
00437 int current_slide_index = slice_view_->getSliceIndex();
00438
00439 if (view_mode_ == FAST_SLICE_SCROLL_MODE)
00440 {
00441 current_slide_index -= 10;
00442 }
00443 else
00444 {
00445 --current_slide_index;
00446 }
00447
00448 if (current_slide_index < 0)
00449 {
00450 current_slide_index = 0;
00451 }
00452 slice_view_->setSliceIndex(current_slide_index);
00453 return(false);
00454 }
00455 default:
00456 {
00457 return(ImedgineViewer::processSoEvent(ev));
00458 }
00459 }
00460 }
00461
00462 return(ImedgineViewer::processSoEvent(ev));
00463 }
00464
00465
00466
00467 bool ImedgineSliceViewer::convertCoordsFromScreenToTexture(
00468 SbVec2s const& screen_coords, SbVec2s& texture_coords)
00469 {
00470 SoRayPickAction rp(slice_view_->getRenderArea()->getViewportRegion());
00471 rp.setPoint(screen_coords);
00472 rp.apply(slice_view_->getRenderArea()->getSceneGraph());
00473
00474 SoPickedPoint* picked_point = rp.getPickedPoint();
00475
00476 if (picked_point == 0)
00477 {
00478
00479 return(false);
00480 }
00481
00482 texture_coords[X_DIMENSION] = static_cast<short int>(
00483 (slice_view_->getSliceResolution()[X_DIMENSION] *
00484 (picked_point->getPoint()[X_DIMENSION] +
00485 (slice_view_->getSlicePlane()->width.getValue() / 2.0))) /
00486 slice_view_->getSlicePlane()->width.getValue());
00487
00488 texture_coords[Y_DIMENSION] = static_cast<short int>(
00489 (slice_view_->getSliceResolution()[Y_DIMENSION] *
00490 (picked_point->getPoint()[Y_DIMENSION] + (slice_view_->getSlicePlane()->height.getValue() /
00491 2.0))) / slice_view_->getSlicePlane()->height.getValue());
00492
00493 return (true);
00494 }
00495
00496
00497
00498 void ImedgineSliceViewer::convertCoordsFromTextureToWorld(
00499 SbVec2s const& texture_coords, SbVec2f& space_coords)
00500 {
00501 space_coords[X_DIMENSION] =
00502 (static_cast<float>(texture_coords[X_DIMENSION]) *
00503 slice_view_->getSlicePlane()->width.getValue() /
00504 static_cast<float>(slice_view_->getSliceResolution()[X_DIMENSION])) -
00505 (slice_view_->getSlicePlane()->width.getValue() / 2.0);
00506
00507 space_coords[Y_DIMENSION] =
00508 (static_cast<float>(texture_coords[Y_DIMENSION]) *
00509 slice_view_->getSlicePlane()->height.getValue() /
00510 static_cast<float>(slice_view_->getSliceResolution()[Y_DIMENSION])) -
00511 (slice_view_->getSlicePlane()->height.getValue() / 2.0);
00512
00513 }
00514
00515
00516
00517 void ImedgineSliceViewer::buildPopupMenu()
00518 {
00519 popup_menu = SoQtPopupMenu::createInstance();
00520 popup_menu->newMenu("SLICE MENU", SLICE_ROOT_MENU);
00521 popup_menu->setMenuTitle(SLICE_ROOT_MENU, "SLICE MENU");
00522
00523 popup_menu->newMenu("add_second_dataset_menu", SLICE_ADD_SECOND_DATASET_MENU);
00524 popup_menu->setMenuTitle(SLICE_ADD_SECOND_DATASET_MENU, "Add/remove second dataset");
00525 popup_menu->newRadioGroup(SLICE_ADD_SECOND_DATASET_GROUP);
00526
00527 popup_menu->newMenu("lock_datasets_menu", LOCK_DATASETS_MENU);
00528 popup_menu->setMenuTitle(LOCK_DATASETS_MENU, "Lock datasets");
00529
00530
00531 std::vector<dataset_key_type> key_container;
00532 Controller::getInstance().getLoadedDatasetKeys(key_container);
00533
00534 int add_dataset_key_menu_item_id = SLICE_ADD_SECOND_DATASET_MENU_ITEM;
00535 int lock_datasets_menu_item_id = LOCK_DATASETS_MENU_ITEM;
00536
00537 for (std::vector<dataset_key_type>::const_iterator dataset_key_iter =
00538 key_container.begin();
00539 dataset_key_iter != key_container.end(); ++dataset_key_iter)
00540 {
00541
00542 if (*dataset_key_iter != slice_view_->getDatasetKey())
00543 {
00544 popup_menu->newMenuItem(dataset_key_iter->c_str(), add_dataset_key_menu_item_id);
00545 popup_menu->addMenuItem(SLICE_ADD_SECOND_DATASET_MENU, add_dataset_key_menu_item_id);
00546 popup_menu->addRadioGroupItem(SLICE_ADD_SECOND_DATASET_GROUP, add_dataset_key_menu_item_id);
00547
00548 popup_menu->newMenuItem(dataset_key_iter->c_str(), lock_datasets_menu_item_id);
00549 popup_menu->addMenuItem(LOCK_DATASETS_MENU, lock_datasets_menu_item_id);
00550
00551
00552
00553 if (*dataset_key_iter == slice_view_->getSecondDatasetKey())
00554 {
00555 popup_menu->setMenuItemMarked(add_dataset_key_menu_item_id, true);
00556 }
00557
00558
00559 if (slice_view_->isLockedWithDataset(*dataset_key_iter) == true)
00560 {
00561 popup_menu->setMenuItemMarked(lock_datasets_menu_item_id, true);
00562 }
00563
00564 add_dataset_key_menu_item_id++;
00565 lock_datasets_menu_item_id++;
00566 }
00567 }
00568
00569 popup_menu->addMenu(SLICE_ROOT_MENU, SLICE_ADD_SECOND_DATASET_MENU);
00570 popup_menu->addMenu(SLICE_ROOT_MENU, LOCK_DATASETS_MENU);
00571 popup_menu->addMenuSelectionCallback(ImedgineViewer::menuSelectionCallback, (void *) this);
00572
00573 this->prefmenu = popup_menu;
00574
00575 }
00576
00577
00578
00579 void ImedgineSliceViewer::menuSelection(int menu_item_id)
00580 {
00581 if (menu_item_id >= SLICE_ADD_SECOND_DATASET_MENU_ITEM &&
00582 menu_item_id < LOCK_DATASETS_MENU_ITEM)
00583 {
00584 std::vector<dataset_key_type> key_container;
00585 Controller::getInstance().getLoadedDatasetKeys(key_container);
00586
00587 if (is_hybrid_view_ == false)
00588 {
00589 slice_view_->setSecondDataset(
00590 Controller::getInstance().getDataset(popup_menu->getMenuItemTitle(menu_item_id)));
00591
00592 is_hybrid_view_ = true;
00593
00594
00595 transparency_slider_switch_->whichChild = SO_SWITCH_ALL; ;
00596 }
00597 else if (is_hybrid_view_ == true &&
00598 popup_menu->getMenuItemTitle(menu_item_id) != slice_view_->getSecondDatasetKey())
00599 {
00600
00601 slice_view_->unsetSecondDataset();
00602
00603
00604 slice_view_->setSecondDataset(
00605 Controller::getInstance().getDataset(popup_menu->getMenuItemTitle(menu_item_id)));
00606
00607 is_hybrid_view_ = true;
00608
00609
00610 transparency_slider_switch_->whichChild = SO_SWITCH_ALL; ;
00611 }
00612 else
00613 {
00614 slice_view_->unsetSecondDataset();
00615
00616 is_hybrid_view_ = false;
00617
00618
00619 transparency_slider_switch_->whichChild = SO_SWITCH_NONE;
00620 }
00621 }
00622 else if (menu_item_id >= LOCK_DATASETS_MENU_ITEM)
00623 {
00624 if (slice_view_->isLockedWithDataset(popup_menu->getMenuItemTitle(menu_item_id)) == false)
00625 {
00626 slice_view_->lockWithDataset(popup_menu->getMenuItemTitle(menu_item_id));
00627 }
00628 else
00629 {
00630 slice_view_->unlockFromDataset(popup_menu->getMenuItemTitle(menu_item_id));
00631 }
00632 }
00633 }
00634
00635
00636
00637 void ImedgineSliceViewer::updateSliceStatusInfo(
00638 index_type current_slice_index, index_type maximum_slice_index)
00639 {
00640 std::ostringstream slice_info_tmp;
00641 slice_info_tmp << "Slice: ";
00642 slice_info_tmp << current_slice_index;
00643 slice_info_tmp << "/";
00644 slice_info_tmp << maximum_slice_index;
00645 slice_status_info_text_->string = slice_info_tmp.str().c_str();
00646 }
00647
00648
00649
00650 void ImedgineSliceViewer::updateDatasetStatusInfo()
00651 {
00652 std::ostringstream dataset_info_tmp;
00653 dataset_info_tmp << slice_view_->getDatasetKey();
00654
00655 if (slice_view_->getSecondDatasetKey() != "")
00656 {
00657 dataset_info_tmp << "/";
00658 dataset_info_tmp << slice_view_->getSecondDatasetKey();
00659 }
00660
00661 dataset_status_info_text_->string = dataset_info_tmp.str().c_str();
00662 }
00663
00664
00665
00666
00667 void ImedgineSliceViewer::unsetHybridView()
00668 {
00669
00670 transparency_slider_switch_->whichChild = SO_SWITCH_NONE;
00671 }
00672
00673
00674
00675 SbVec3f ImedgineSliceViewer::convertCoordsFromWorldToSpace(SbVec2s screen_coords)
00676 throw(NullPointerException)
00677 {
00678 SoRayPickAction ray_pick(this->getViewportRegion());
00679 ray_pick.setPoint(screen_coords);
00680 ray_pick.apply(this->getSceneGraph());
00681
00682 std::cout << "Picked point: " << ray_pick.getPickedPoint()->getPoint()[X_DIMENSION]
00683 << "/" << ray_pick.getPickedPoint()->getPoint()[Y_DIMENSION] << std::endl;
00684
00685 if (ray_pick.getPickedPoint() == 0)
00686 {
00687 throw(NullPointerException("ImedgineSliceViewer::getWorldSpacePosition()"));
00688 }
00689
00690 return(ray_pick.getPickedPoint()->getPoint());
00691 }
00692
00693
00694
00695 void ImedgineSliceViewer::updateSliceSliderPosition(index_type slice_index)
00696 {
00697 slice_slider_dragger_->translation.setValue(
00698 12.0 * static_cast<float>(slice_index) /
00699 static_cast<float>(slice_view_->getNumSlices()) - 6, 0, 0);
00700
00701 std::cout << "Slider position: " << 12.0 * static_cast<float>(slice_index) /
00702 static_cast<float>(slice_view_->getNumSlices()) - 6 << std::endl;
00703
00704 ignore_next_slice_slider_update_ = true;
00705 }
00706
00707
00708
00709 void sliceSliderPositionChangedCB(void *data, SoSensor* sensor)
00710 {
00711 ImedgineSliceViewer* viewer = static_cast<ImedgineSliceViewer *>(data);
00712
00713 SoTranslate1Dragger* slider_dragger = viewer->getSliceSliderDragger();
00714
00715
00716 if (slider_dragger->translation.getValue()[0] > 6)
00717 {
00718 slider_dragger->translation.setValue(6, 0, 0);
00719 return;
00720 }
00721 else if (slider_dragger->translation.getValue()[0] < -6)
00722 {
00723 slider_dragger->translation.setValue(-6, 0, 0);
00724 return;
00725 }
00726
00727 if (viewer->getIgnoreNextSliceSliderUpdate() == true)
00728 {
00729 viewer->setIgnoreNextSliceSliderUpdate(false);
00730 return;
00731 }
00732
00733 viewer->getSlicePixelView()->setSliceIndex(
00734 static_cast<int>((slider_dragger->translation.getValue()[0] + 6) *
00735 viewer->getSlicePixelView()->getNumSlices() / 12));
00736 }
00737
00738
00739
00740 void transparencySliderPositionChangedCB(void *data, SoSensor* sensor)
00741 {
00742 ImedgineSliceViewer* viewer = static_cast<ImedgineSliceViewer *>(data);
00743
00744 SoTranslate1Dragger* slider_dragger = viewer->getTransparencySliderDragger();
00745
00746
00747 if (slider_dragger->translation.getValue()[0] > 6)
00748 {
00749 slider_dragger->translation.setValue(6, 0, 0);
00750 return;
00751 }
00752 else if (slider_dragger->translation.getValue()[0] < -6)
00753 {
00754 slider_dragger->translation.setValue(-6, 0, 0);
00755 return;
00756 }
00757
00758 float transparency_percent =
00759 (slider_dragger->translation.getValue()[0] + 6) * 1.0 / 12.0;
00760
00761 if (transparency_percent > 1.0)
00762 transparency_percent = 1.0;
00763
00764 viewer->getSlicePixelView()->getSliceDatasetMaterial()->transparency = transparency_percent;
00765
00766 viewer->getSlicePixelView()->getSliceSecondDatasetMaterial()->transparency =
00767 1.0 - transparency_percent;
00768 }
00769 }