00001 //-------------------------------------------------- 00012 //--------------------------------------------------- 00013 00014 #include "slice_pixel_view.h" 00015 #include "../controller/data_view_mediator.h" 00016 00017 #include <Inventor/SbViewportRegion.h> 00018 #include <Inventor/actions/SoGetMatrixAction.h> 00019 #include <Inventor/nodes/SoCone.h> 00020 00021 namespace imedgine 00022 { 00023 SlicePixelView::SlicePixelView(view_type type) 00024 : VolumePixelView(type) 00025 { 00026 createSceneGraph(); 00027 } 00028 00029 //-------------------------------------------------- 00030 00031 SlicePixelView::SlicePixelView(SlicePixelView const& src) 00032 : VolumePixelView(src) 00033 { 00034 createSceneGraph(); 00035 } 00036 00037 //-------------------------------------------------- 00038 00039 SlicePixelView::~SlicePixelView() 00040 { 00041 } 00042 00043 //-------------------------------------------------- 00044 00045 void SlicePixelView::createSceneGraph() 00046 { 00047 View::createSceneGraph(); 00048 00049 dynamic_camera_ = new SoOrthographicCamera(); 00050 dynamic_sep_->addChild(dynamic_camera_); 00051 00052 //initialize slice 00053 slice_separator_ = new SoSeparator(); 00054 dynamic_sep_->addChild(slice_separator_); 00055 00056 current_image_texture_ = new SoTexture2; 00057 slice_separator_->addChild(current_image_texture_); 00058 00059 slice_dataset_material_ = new SoMaterial; 00060 slice_dataset_material_->transparency = 1e-6; //fully opaque 00061 slice_separator_->addChild(slice_dataset_material_); 00062 00063 slice_plane_ = new SoCube; 00064 slice_separator_->addChild(slice_plane_); 00065 00066 //initialize crosshair 00067 crosshair_sep_ = new SoSeparator(); 00068 crosshair_coords_ = new SoCoordinate3; 00069 crosshair_sep_->addChild(crosshair_coords_); 00070 crosshair_color_ = new SoBaseColor(); 00071 crosshair_color_->rgb = SbVec3f(0, 1, 0); //fluorescent green 00072 crosshair_sep_->addChild(crosshair_color_); 00073 crosshair_lines_ = new SoLineSet(); 00074 crosshair_sep_->addChild(crosshair_lines_); 00075 dynamic_sep_->addChild(crosshair_sep_); 00076 } 00077 00078 //-------------------------------------------------- 00079 00080 void SlicePixelView::setParent(QWidget* view_parent) 00081 throw(NullPointerException) 00082 { 00083 VolumePixelView::setParent(view_parent); 00084 00085 if (view_parent_ == 0) 00086 { 00087 throw(NullPointerException("SlicePixelView::setParent")); 00088 } 00089 00090 render_area_.reset(new ImedgineSliceViewer(this, view_parent_)); 00091 00092 //dynamic_camera_->viewAll(root_, render_area_->getViewportRegion()); 00093 00094 render_area_->setSceneGraph(root_); 00095 } 00096 00097 //-------------------------------------------------- 00098 00099 void SlicePixelView::setDataset(dataset_pointer_type dataset) 00100 throw(NullPointerException, InvalidCastException) 00101 { 00102 VolumePixelView::setDataset(dataset); 00103 00104 slice_plane_->depth = 0.0; 00105 float x_resolution = static_cast<float>(getSliceResolution()[X_DIMENSION]); 00106 float y_resolution = static_cast<float>(getSliceResolution()[Y_DIMENSION]); 00107 00108 if (x_resolution > y_resolution) 00109 { 00110 slice_plane_->height = 2.0 * 00111 (y_resolution / x_resolution); 00112 slice_plane_->width = 2.0; 00113 } 00114 else 00115 { 00116 slice_plane_->height = 2.0; 00117 slice_plane_->width = 2.0 * 00118 (x_resolution / y_resolution); 00119 } 00120 } 00121 00122 //--------------------------------------------------- 00123 00124 void SlicePixelView::setSecondDataset(dataset_pointer_type second_dataset) 00125 throw(NullPointerException, InvalidCastException) 00126 { 00127 VolumePixelView::setSecondDataset(second_dataset); 00128 00129 current_second_image_texture_ = new SoTexture2; 00130 slice_separator_->addChild(current_second_image_texture_); 00131 00132 slice_second_dataset_material_ = new SoMaterial; 00133 slice_second_dataset_material_->transparency = 1.0; 00134 slice_separator_->addChild(slice_second_dataset_material_); 00135 00136 second_slice_plane_ = new SoCube; 00137 slice_separator_->addChild(second_slice_plane_); 00138 00139 second_slice_plane_->depth = 0.0; 00140 float x_resolution = static_cast<float>(getSecondSliceResolution()[X_DIMENSION]); 00141 float y_resolution = static_cast<float>(getSecondSliceResolution()[Y_DIMENSION]); 00142 00143 if (x_resolution > y_resolution) 00144 { 00145 second_slice_plane_->height = 2.0 * 00146 (y_resolution / x_resolution); 00147 second_slice_plane_->width = 2.0; 00148 } 00149 else 00150 { 00151 second_slice_plane_->height = 2.0; 00152 second_slice_plane_->width = 2.0 * 00153 (x_resolution / y_resolution); 00154 } 00155 00156 if (data_view_mediator_ != 0) 00157 { 00158 data_view_mediator_->updateDataChanged( 00159 dataset_key_, DATASET_ATTRIBUTE_INTENSITY); 00160 } 00161 } 00162 00163 //--------------------------------------------------- 00164 00165 void SlicePixelView::unsetSecondDataset() 00166 { 00167 slice_separator_->removeChild(current_second_image_texture_); 00168 slice_separator_->removeChild(slice_second_dataset_material_); 00169 slice_separator_->removeChild(second_slice_plane_); 00170 00171 //set first dataset fully opaque 00172 slice_dataset_material_->transparency = 1e-6; 00173 00174 VolumePixelView::unsetSecondDataset(); 00175 } 00176 00177 //--------------------------------------------------- 00178 00179 void SlicePixelView::onDatasetDeletion(dataset_key_type dataset_key) 00180 { 00181 if (second_volume_dataset_.get() == 0) 00182 { 00183 return; 00184 } 00185 00186 if (second_volume_dataset_->getDatasetKey() == dataset_key) 00187 { 00188 unsetSecondDataset(); 00189 // adapt the texture to show only one slice again 00190 render_area_->unsetHybridView(); 00191 } 00192 } 00193 00194 //--------------------------------------------------- 00195 00196 void SlicePixelView::updateView() 00197 throw(NullPointerException) 00198 { 00199 if (render_area_.get() == 0) 00200 { 00201 throw(NullPointerException("SlicePixelView::updateView")); 00202 } 00203 00204 render_area_->updateDatasetStatusInfo(); 00205 00206 render_area_->show(); // maybe this is not needed here 00207 } 00208 00209 //-------------------------------------------------- 00210 00211 void SlicePixelView::onDataChangedEvent(dataset_attribute_type changed_attribute) 00212 throw(NullPointerException) 00213 { 00214 // reloading of the slice is handled by concrete slice views (XY, XZ or YZ) 00215 switch (changed_attribute) 00216 { 00217 case DATASET_ATTRIBUTE_FOCUS_POINT: 00218 { 00219 drawCrosshair(); 00220 render_area_->updateSliceSliderPosition(getSliceIndex()); 00221 break; 00222 } 00223 default : 00224 { 00225 updateView(); 00226 break; 00227 } 00228 } 00229 } 00230 }