xy_slice_view.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------
00012 //---------------------------------------------------
00013 
00014 #include "xy_slice_view.h"
00015 
00016 namespace imedgine 
00017 {
00018   XYSliceView::XYSliceView()
00019   : SlicePixelView(XY_SLICE_VIEW)
00020   { 
00021   }
00022   
00023   //---------------------------------------------------
00024   
00025   XYSliceView::XYSliceView(view_type type)
00026   : SlicePixelView(type)
00027   { 
00028   }
00029   
00030   //---------------------------------------------------
00031   
00032   XYSliceView::XYSliceView(XYSliceView const& src)
00033   : SlicePixelView(src)
00034   {
00035   }
00036   
00037   //---------------------------------------------------
00038   
00039   XYSliceView::~XYSliceView()
00040   {
00041 #ifdef DEBUG
00042     std::cout << "Deleting XY_SLICE_VIEW" << std::endl;
00043 #endif
00044   }
00045   
00046   //---------------------------------------------------
00047   
00048   view_pointer_type XYSliceView::clone() const
00049   {
00050     return view_pointer_type(new XYSliceView(*this));
00051   }
00052   
00053   //---------------------------------------------------
00054   
00055   void XYSliceView::updateView()
00056       throw(NullPointerException)      
00057   {
00058     if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00059     {
00060       return;
00061     }
00062 
00063     external_data_pointer_type requested_slice;
00064     try
00065     {
00066       requested_slice = 
00067           volume_dataset_->getSliceXY(volume_dataset_->getFocusPoint()[Z_DIMENSION]);
00068     }
00069     catch (IndexOutOfBoundsException const&)
00070     {
00071       requested_slice = 
00072           volume_dataset_->getSliceXY(volume_dataset_->getSize()[Z_DIMENSION] - 1);
00073     }
00074   
00075     current_image_texture_->image.setValue(
00076         SbVec2s(volume_dataset_->getSize()[X_DIMENSION], 
00077                 volume_dataset_->getSize()[Y_DIMENSION]), 1, requested_slice);
00078       
00079     if ((second_volume_dataset_.get() != 0) && (second_volume_dataset_->isDataSet() == true))
00080     {         
00081       external_data_pointer_type second_requested_slice;
00082       try
00083       {
00084         second_requested_slice = 
00085             second_volume_dataset_->getSliceXY(
00086             volume_dataset_->getFocusPoint()[Z_DIMENSION]);
00087       }
00088       catch (IndexOutOfBoundsException const&) 
00089       { 
00090         //take the last available slice
00091         second_requested_slice = 
00092             second_volume_dataset_->getSliceXY(
00093             second_volume_dataset_->getSize()[Z_DIMENSION] - 1);  
00094       } 
00095      
00096       current_second_image_texture_->image.setValue(
00097           SbVec2s(second_volume_dataset_->getSize()[X_DIMENSION], 
00098                   second_volume_dataset_->getSize()[Y_DIMENSION]), 1, 
00099           second_requested_slice);
00100       
00101       slice_dataset_material_->transparency = 0.5;
00102       slice_second_dataset_material_->transparency = 0.5;  
00103     }
00104     
00105     drawCrosshair();
00106         
00107     render_area_->updateSliceStatusInfo(getSliceIndex(),
00108                                         volume_dataset_->getSize()[Z_DIMENSION]);              
00109     
00110     SlicePixelView::updateView();
00111   }
00112   
00113   //---------------------------------------------------
00114   
00115   void XYSliceView::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_[Z_DIMENSION] != volume_dataset_->getFocusPoint()[Z_DIMENSION])
00128         {
00129          updateView();
00130         }     
00131         current_focus_point_ = volume_dataset_->getFocusPoint();
00132         break;
00133       }
00134       default :
00135       {
00136         break;
00137       }
00138     }
00139     
00140     SlicePixelView::onDataChangedEvent(changed_attribute);
00141   }
00142   
00143   //---------------------------------------------------
00144   
00145   void XYSliceView::setFocusPoint2D(index_type x, index_type y)
00146       throw(NullPointerException)
00147   {
00148     if ((volume_dataset_.get() == 0) || (volume_dataset_->isDataSet() == false))
00149     {
00150       return;
00151     }      
00152     
00153     //update focus point of dataset  
00154     try
00155     {
00156       volume_dataset_->setFocusPointAt(X_DIMENSION, x);
00157     }
00158     catch (IndexOutOfBoundsException const&)
00159     {
00160       volume_dataset_->setFocusPointAt(
00161           X_DIMENSION, volume_dataset_->getSize()[X_DIMENSION] - 1);
00162     }
00163     try
00164     {
00165       volume_dataset_->setFocusPointAt(Y_DIMENSION, y);
00166     }
00167     catch (IndexOutOfBoundsException const&)
00168     {
00169       volume_dataset_->setFocusPointAt(
00170           Y_DIMENSION, volume_dataset_->getSize()[Y_DIMENSION] - 1);
00171     }
00172       
00173     notifyDataChangedEvent(DATASET_ATTRIBUTE_FOCUS_POINT);
00174   }
00175   
00176   //---------------------------------------------------
00177   
00178   void XYSliceView::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(Z_DIMENSION, slice_index);
00189     }
00190     catch (IndexOutOfBoundsException const&)
00191     {
00192       volume_dataset_->setFocusPointAt(
00193           Z_DIMENSION, volume_dataset_->getSize()[Z_DIMENSION] - 1);
00194     }
00195     
00196     notifyDataChangedEvent(DATASET_ATTRIBUTE_FOCUS_POINT);
00197   }
00198   
00199   //---------------------------------------------------
00200   
00201   index_type XYSliceView::getSliceIndex() const
00202   {
00203     return(current_focus_point_[Z_DIMENSION]);
00204   }
00205   
00206   //---------------------------------------------------
00207   
00208   index_type XYSliceView::getNumSlices() const
00209   {
00210     return(volume_dataset_->getSize()[Z_DIMENSION]);
00211   }  
00212   
00213   //---------------------------------------------------
00214   
00215   SbVec2s XYSliceView::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()[X_DIMENSION], 
00222            volume_dataset_->getSize()[Y_DIMENSION]));
00223   }   
00224   
00225   //---------------------------------------------------
00226   
00227   SbVec2s XYSliceView::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()[X_DIMENSION],
00235            second_volume_dataset_->getSize()[Y_DIMENSION]));
00236   }    
00237   
00238   //---------------------------------------------------
00239   
00240   void XYSliceView::drawCrosshair()
00241   {
00242     SbVec2s current_focus_point_2D;  
00243     SbVec2f crosshair_origin;
00244       
00245     //mapping from 3D to relevant 2D points
00246     current_focus_point_2D[X_DIMENSION] = current_focus_point_[X_DIMENSION];
00247     current_focus_point_2D[Y_DIMENSION] = current_focus_point_[Y_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 }

Generated on Sun Aug 13 18:19:41 2006 for iMEDgine by  doxygen 1.4.6