00001
00012
00013
00014 #include "yz_slice_view.h"
00015 #include "../exceptions/index_out_of_bounds_exception.h"
00016
00017 namespace imedgine
00018 {
00019 YZSliceView::YZSliceView()
00020 : SlicePixelView(YZ_SLICE_VIEW)
00021 {
00022 }
00023
00024
00025
00026 YZSliceView::YZSliceView(view_type type)
00027 : SlicePixelView(type)
00028 {
00029 }
00030
00031
00032
00033 YZSliceView::YZSliceView(YZSliceView const& src)
00034 : SlicePixelView(src)
00035 {
00036 }
00037
00038
00039
00040 YZSliceView::~YZSliceView()
00041 {
00042 #ifdef DEBUG
00043 std::cout << "Deleting XZ_SLICE_VIEW id: " << std::endl;
00044 #endif
00045 }
00046
00047
00048
00049 view_pointer_type YZSliceView::clone() const
00050 {
00051 return view_pointer_type(new YZSliceView(*this));
00052 }
00053
00054
00055
00056 void YZSliceView::updateView()
00057 throw(NullPointerException)
00058 {
00059 if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00060 {
00061 return;
00062 }
00063
00064 external_data_pointer_type requested_slice;
00065 try
00066 {
00067 requested_slice =
00068 volume_dataset_->getSliceYZ(volume_dataset_->getFocusPoint()[X_DIMENSION]);
00069 }
00070 catch (IndexOutOfBoundsException const&)
00071 {
00072 requested_slice =
00073 volume_dataset_->getSliceYZ(volume_dataset_->getSize()[X_DIMENSION] - 1);
00074 }
00075
00076 current_image_texture_->image.setValue(
00077 SbVec2s(volume_dataset_->getSize()[Y_DIMENSION],
00078 volume_dataset_->getSize()[Z_DIMENSION]), 1, requested_slice);
00079
00080 if ((second_volume_dataset_.get() != 0) && (second_volume_dataset_->isDataSet() == true))
00081 {
00082 external_data_pointer_type second_requested_slice;
00083 try
00084 {
00085 second_requested_slice =
00086 second_volume_dataset_->getSliceYZ(
00087 volume_dataset_->getFocusPoint()[X_DIMENSION]);
00088 }
00089 catch (IndexOutOfBoundsException const&)
00090 {
00091
00092 second_requested_slice =
00093 second_volume_dataset_->getSliceYZ(
00094 second_volume_dataset_->getSize()[X_DIMENSION] - 1);
00095 }
00096
00097 current_second_image_texture_->image.setValue(
00098 SbVec2s(second_volume_dataset_->getSize()[Y_DIMENSION],
00099 second_volume_dataset_->getSize()[Z_DIMENSION]), 1,
00100 second_requested_slice);
00101
00102 slice_dataset_material_->transparency = 0.5;
00103 slice_second_dataset_material_->transparency = 0.5;
00104 }
00105
00106 drawCrosshair();
00107 render_area_->updateSliceStatusInfo(getSliceIndex(),
00108 volume_dataset_->getSize()[X_DIMENSION]);
00109
00110 SlicePixelView::updateView();
00111 }
00112
00113
00114
00115 void YZSliceView::onDataChangedEvent(dataset_attribute_type changed_attribute)
00116 throw(NullPointerException)
00117 {
00118 if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00119 {
00120 return;
00121 }
00122
00123 switch (changed_attribute)
00124 {
00125 case DATASET_ATTRIBUTE_FOCUS_POINT :
00126 {
00127 if (current_focus_point_[X_DIMENSION] != volume_dataset_->getFocusPoint()[X_DIMENSION])
00128 {
00129 updateView();
00130 }
00131
00132 current_focus_point_ = volume_dataset_->getFocusPoint();
00133 break;
00134 }
00135 default :
00136 {
00137 break;
00138 }
00139 }
00140 SlicePixelView::onDataChangedEvent(changed_attribute);
00141 }
00142
00143
00144
00145 void YZSliceView::setFocusPoint2D(index_type y, index_type z)
00146 throw(NullPointerException)
00147 {
00148 if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00149 {
00150 return;
00151 }
00152
00153
00154 try
00155 {
00156 volume_dataset_->setFocusPointAt(Y_DIMENSION, y);
00157 }
00158 catch (IndexOutOfBoundsException const&)
00159 {
00160 volume_dataset_->setFocusPointAt(
00161 Y_DIMENSION, volume_dataset_->getSize()[Y_DIMENSION] - 1);
00162 }
00163 try
00164 {
00165 volume_dataset_->setFocusPointAt(Z_DIMENSION, z);
00166 }
00167 catch (IndexOutOfBoundsException const&)
00168 {
00169 volume_dataset_->setFocusPointAt(
00170 Z_DIMENSION, volume_dataset_->getSize()[Z_DIMENSION] - 1);
00171 }
00172
00173 notifyDataChangedEvent(DATASET_ATTRIBUTE_FOCUS_POINT);
00174 }
00175
00176
00177
00178 void YZSliceView::setSliceIndex(index_type slice_index)
00179 throw(NullPointerException)
00180 {
00181 if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00182 {
00183 return;
00184 }
00185
00186 try
00187 {
00188 volume_dataset_->setFocusPointAt(X_DIMENSION, slice_index);
00189 }
00190 catch (IndexOutOfBoundsException const&)
00191 {
00192 volume_dataset_->setFocusPointAt(
00193 X_DIMENSION, volume_dataset_->getSize()[X_DIMENSION] - 1);
00194 }
00195
00196 notifyDataChangedEvent(DATASET_ATTRIBUTE_FOCUS_POINT);
00197 }
00198
00199
00200
00201 index_type YZSliceView::getSliceIndex() const
00202 {
00203 return(current_focus_point_[X_DIMENSION]);
00204 }
00205
00206
00207
00208 index_type YZSliceView::getNumSlices() const
00209 {
00210 return(volume_dataset_->getSize()[X_DIMENSION]);
00211 }
00212
00213
00214
00215 SbVec2s YZSliceView::getSliceResolution() const
00216 {
00217 if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00218 {
00219 return(SbVec2s(0, 0));
00220 }
00221 return(SbVec2s(volume_dataset_->getSize()[Y_DIMENSION],
00222 volume_dataset_->getSize()[Z_DIMENSION]));
00223 }
00224
00225
00226
00227 SbVec2s YZSliceView::getSecondSliceResolution() const
00228 {
00229 if ((second_volume_dataset_.get() == 0) ||
00230 (second_volume_dataset_->isDataSet() == false))
00231 {
00232 return(SbVec2s(0, 0));
00233 }
00234 return(SbVec2s(second_volume_dataset_->getSize()[Y_DIMENSION],
00235 second_volume_dataset_->getSize()[Z_DIMENSION]));
00236 }
00237
00238
00239
00240 void YZSliceView::drawCrosshair()
00241 {
00242 SbVec2s current_focus_point_2D;
00243 SbVec2f crosshair_origin;
00244
00245
00246 current_focus_point_2D[X_DIMENSION] = current_focus_point_[Y_DIMENSION];
00247 current_focus_point_2D[Y_DIMENSION] = current_focus_point_[Z_DIMENSION];
00248
00249 render_area_->convertCoordsFromTextureToWorld(current_focus_point_2D, crosshair_origin);
00250
00251 crosshair_coords_->point.set1Value(0, SbVec3f(-10, crosshair_origin[Y_DIMENSION], 0.01));
00252 crosshair_coords_->point.set1Value(1, SbVec3f(10, crosshair_origin[Y_DIMENSION], 0.01));
00253 crosshair_coords_->point.set1Value(2, SbVec3f(crosshair_origin[X_DIMENSION], -10, 0.01));
00254 crosshair_coords_->point.set1Value(3, SbVec3f(crosshair_origin[X_DIMENSION], 10, 0.01));
00255
00256 crosshair_lines_->numVertices.setValue(4);
00257 }
00258 }