00001
00012
00013
00014 #include "image_pixel_view.h"
00015 #include "../controller/data_view_mediator.h"
00016 #include "../datasets/image_pixel_dataset.h"
00017
00018 #include <Inventor/SbViewportRegion.h>
00019 #include <Inventor/actions/SoGetMatrixAction.h>
00020 #include <Inventor/nodes/SoCone.h>
00021
00022 namespace imedgine
00023 {
00024 ImagePixelView::ImagePixelView()
00025 : PixelView(IMAGE_PIXEL_VIEW)
00026 {
00027 createSceneGraph();
00028 }
00029
00030
00031
00032 ImagePixelView::ImagePixelView(ImagePixelView const& src)
00033 : PixelView(src)
00034 {
00035 createSceneGraph();
00036 }
00037
00038
00039
00040 ImagePixelView::~ImagePixelView()
00041 {
00042 }
00043
00044
00045
00046 view_pointer_type ImagePixelView::clone() const
00047 {
00048 return view_pointer_type(new ImagePixelView(*this));
00049 }
00050
00051
00052
00053 dataset_key_type ImagePixelView::getDatasetKey() const
00054 {
00055 if (image_dataset_.get() != 0)
00056 {
00057 return(image_dataset_->getDatasetKey());
00058 }
00059 else
00060 {
00061 return(dataset_key_type());
00062 }
00063 }
00064
00065
00066
00067 void ImagePixelView::createSceneGraph()
00068 {
00069 View::createSceneGraph();
00070
00071 dynamic_camera_ = new SoOrthographicCamera();
00072 dynamic_sep_->addChild(dynamic_camera_);
00073
00074
00075 slice_separator_ = new SoSeparator();
00076 dynamic_sep_->addChild(slice_separator_);
00077
00078 current_image_texture_ = new SoTexture2;
00079 slice_separator_->addChild(current_image_texture_);
00080
00081 slice_dataset_material_ = new SoMaterial;
00082 slice_dataset_material_->transparency = 0;
00083 slice_separator_->addChild(slice_dataset_material_);
00084
00085 slice_plane_ = new SoCube;
00086 slice_separator_->addChild(slice_plane_);
00087
00088
00089 crosshair_sep_ = new SoSeparator();
00090 crosshair_coords_ = new SoCoordinate3;
00091 crosshair_sep_->addChild(crosshair_coords_);
00092 crosshair_color_ = new SoBaseColor();
00093 crosshair_color_->rgb = SbVec3f(0, 1, 0);
00094 crosshair_sep_->addChild(crosshair_color_);
00095 crosshair_lines_ = new SoLineSet();
00096 crosshair_sep_->addChild(crosshair_lines_);
00097 dynamic_sep_->addChild(crosshair_sep_);
00098 }
00099
00100
00101
00102 void ImagePixelView::setParent(QWidget* view_parent)
00103 throw(NullPointerException)
00104 {
00105 PixelView::setParent(view_parent);
00106
00107 if (view_parent_ == 0)
00108 {
00109 throw(NullPointerException("ImagePixelView::setParent"));
00110 }
00111
00112 render_area_.reset(new ImedgineImageViewer(this, view_parent_));
00113
00114
00115
00116 render_area_->setSceneGraph(root_);
00117 }
00118
00119
00120
00121 void ImagePixelView::setDataset(dataset_pointer_type dataset)
00122 throw(NullPointerException, InvalidCastException)
00123 {
00124 if(dataset.get() == 0)
00125 {
00126 throw(NullPointerException("ImagePixelView::setDataset"));
00127 }
00128
00129 ImagePixelDataset* image_pixel_dataset =
00130 dynamic_cast<ImagePixelDataset*>(dataset.get());
00131
00132 if (image_pixel_dataset == 0)
00133 {
00134 throw(InvalidCastException("ImagePixelView::setDataset",
00135 "dataset_pointer_type", "ImagePixelDataset*"));
00136 }
00137
00138 image_pixel_dataset_pointer_type temp_dataset_copy(
00139 dataset, boost::detail::dynamic_cast_tag());
00140 image_dataset_ = temp_dataset_copy;
00141
00142 View::setDataset(dataset);
00143
00144 slice_plane_->depth = 0.0;
00145 float x_resolution = static_cast<float>(getSize()[X_DIMENSION]);
00146 float y_resolution = static_cast<float>(getSize()[Y_DIMENSION]);
00147
00148 if (x_resolution > y_resolution)
00149 {
00150 slice_plane_->height = 2.0 *
00151 (y_resolution / x_resolution);
00152 slice_plane_->width = 2.0;
00153 }
00154 else
00155 {
00156 slice_plane_->height = 2.0;
00157 slice_plane_->width = 2.0 *
00158 (x_resolution / y_resolution);
00159 }
00160 }
00161
00162
00163
00164 dataset_position_type const& ImagePixelView::getSize() const
00165 {
00166 return(image_dataset_->getSize());
00167 }
00168
00169
00170
00171 void ImagePixelView::updateView()
00172 throw(NullPointerException)
00173 {
00174 if (render_area_.get() == 0)
00175 {
00176 throw(NullPointerException("ImagePixelView::updateView"));
00177 }
00178
00179 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00180 {
00181 return;
00182 }
00183
00184 external_data_pointer_type image_data = image_dataset_->getData();
00185
00186 current_image_texture_->image.setValue(
00187 SbVec2s(image_dataset_->getSize()[X_DIMENSION],
00188 image_dataset_->getSize()[Y_DIMENSION]), 1, image_data);
00189
00190 render_area_->updateDatasetStatusInfo();
00191
00192 render_area_->show();
00193 }
00194
00195
00196
00197 void ImagePixelView::onDataChangedEvent(dataset_attribute_type changed_attribute)
00198 throw(NullPointerException)
00199 {
00200
00201 switch (changed_attribute)
00202 {
00203 case DATASET_ATTRIBUTE_INTENSITY :
00204 {
00205 updateView();
00206 break;
00207 }
00208 case DATASET_ATTRIBUTE_DATA :
00209 {
00210 updateView();
00211 break;
00212 }
00213 default :
00214 {
00215 break;
00216 }
00217 }
00218 }
00219
00220
00221
00222 double ImagePixelView::getMinPixelValue() const
00223 {
00224 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00225 {
00226 return(0.0);
00227 }
00228 return(image_dataset_->getMinPixelValue());
00229 }
00230
00231
00232
00233 double ImagePixelView::getMaxPixelValue() const
00234 {
00235 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00236 {
00237 return(0.0);
00238 }
00239 return(image_dataset_->getMaxPixelValue());
00240 }
00241
00242
00243
00244 void ImagePixelView::setIntensity(double window, double level)
00245 throw(NullPointerException)
00246 {
00247 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00248 {
00249 return;
00250 }
00251
00252 image_dataset_->setIntensity(window, level);
00253
00254 notifyDataChangedEvent(DATASET_ATTRIBUTE_INTENSITY);
00255 }
00256
00257
00258
00259 double ImagePixelView::getIntensityWindow() const
00260 {
00261 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00262 {
00263 return(0.0);
00264 }
00265 return(image_dataset_->getIntensityWindow());
00266 }
00267
00268
00269
00270 double ImagePixelView::getIntensityLevel() const
00271 {
00272 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00273 {
00274 return(0.0);
00275 }
00276 return(image_dataset_->getIntensityLevel());
00277 }
00278
00279
00280
00281 void ImagePixelView::setFocusPoint2D(index_type x, index_type y)
00282 throw(NullPointerException)
00283 {
00284 if ((image_dataset_.get() == 0) || (image_dataset_->isDataSet() == false))
00285 {
00286 return;
00287 }
00288
00289
00290 try
00291 {
00292 image_dataset_->setFocusPointAt(X_DIMENSION, x);
00293 }
00294 catch (IndexOutOfBoundsException const&)
00295 {
00296 image_dataset_->setFocusPointAt(
00297 X_DIMENSION, image_dataset_->getSize()[X_DIMENSION] - 1);
00298 }
00299 try
00300 {
00301 image_dataset_->setFocusPointAt(Y_DIMENSION, y);
00302 }
00303 catch (IndexOutOfBoundsException const&)
00304 {
00305 image_dataset_->setFocusPointAt(
00306 Y_DIMENSION, image_dataset_->getSize()[Y_DIMENSION] - 1);
00307 }
00308
00309 notifyDataChangedEvent(DATASET_ATTRIBUTE_FOCUS_POINT);
00310 }
00311
00312
00313
00314 void ImagePixelView::drawCrosshair()
00315 {
00316 SbVec2s current_focus_point_2D;
00317 SbVec2f crosshair_origin;
00318
00319
00320 current_focus_point_2D[X_DIMENSION] = image_dataset_->getFocusPoint()[X_DIMENSION];
00321 current_focus_point_2D[Y_DIMENSION] = image_dataset_->getFocusPoint()[Y_DIMENSION];
00322
00323 render_area_->convertCoordsFromTextureToWorld(current_focus_point_2D, crosshair_origin);
00324
00325 crosshair_coords_->point.set1Value(0, SbVec3f(-10, crosshair_origin[Y_DIMENSION], 0.01));
00326 crosshair_coords_->point.set1Value(1, SbVec3f(10, crosshair_origin[Y_DIMENSION], 0.01));
00327 crosshair_coords_->point.set1Value(2, SbVec3f(crosshair_origin[X_DIMENSION], -10, 0.01));
00328 crosshair_coords_->point.set1Value(3, SbVec3f(crosshair_origin[X_DIMENSION], 10, 0.01));
00329
00330 crosshair_lines_->numVertices.setValue(4);
00331 }
00332 }