00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <vector>
00026
00027 #include <osg/Matrix>
00028
00029 #include "../common/math/WLinearAlgebraFunctions.h"
00030 #include "../graphicsEngine/WGEViewer.h"
00031 #include "../graphicsEngine/WGEZoomTrackballManipulator.h"
00032 #include "../graphicsEngine/WGraphicsEngine.h"
00033 #include "WKernel.h"
00034 #include "WSelectionManager.h"
00035
00036
00037 WSelectionManager::WSelectionManager() :
00038 m_paintMode( PAINTMODE_NONE ),
00039 m_textureOpacity( 1.0 ),
00040 m_useTexture( false )
00041 {
00042 m_crosshair = boost::shared_ptr< WCrosshair >( new WCrosshair() );
00043
00044 m_sliceGroup = boost::shared_ptr< WProperties >( new WProperties( "Slice Properties",
00045 "Properties relating to the Axial,Coronal and Sagittal Slices." ) );
00046
00047
00048 m_axialPos = m_sliceGroup->addProperty( "Axial Position", "Slice X position.", 0.0, true );
00049 m_coronalPos = m_sliceGroup->addProperty( "Coronal Position", "Slice Y position.", 0.0, true );
00050 m_sagittalPos = m_sliceGroup->addProperty( "Sagittal Position", "Slice Z position.", 0.0, true );
00051
00052
00053 m_axialShow = m_sliceGroup->addProperty( "Show Axial Slice", "Slice visible?", true, true );
00054 m_coronalShow = m_sliceGroup->addProperty( "Show Coronal Slice", "Slice visible?", true, true );
00055 m_sagittalShow = m_sliceGroup->addProperty( "Show Sagittal Slice", "Slice visible?", true, true );
00056
00057
00058 m_axialPos->setMin( 0.0 );
00059 m_coronalPos->setMin( 0.0 );
00060 m_sagittalPos->setMin( 0.0 );
00061 m_axialPos->setMax( 0.0 );
00062 m_coronalPos->setMax( 0.0 );
00063 m_sagittalPos->setMax( 0.0 );
00064
00065 m_axialUpdateConnection = m_axialPos->getUpdateCondition()->subscribeSignal(
00066 boost::bind( &WSelectionManager::updateCrosshairPosition, this )
00067 );
00068 m_coronalUpdateConnection = m_coronalPos->getUpdateCondition()->subscribeSignal(
00069 boost::bind( &WSelectionManager::updateCrosshairPosition, this )
00070 );
00071 m_sagittalUpdateConnection = m_sagittalPos->getUpdateCondition()->subscribeSignal(
00072 boost::bind( &WSelectionManager::updateCrosshairPosition, this )
00073 );
00074 }
00075
00076 WSelectionManager::~WSelectionManager()
00077 {
00078 }
00079
00080 boost::shared_ptr< WCrosshair >WSelectionManager::getCrosshair()
00081 {
00082 return m_crosshair;
00083 }
00084
00085 int WSelectionManager::getFrontSector()
00086 {
00087 boost::shared_ptr< WGEViewer > viewer;
00088 viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
00089 viewer->getCamera()->getViewMatrix();
00090 osg::Matrix rm = viewer->getCamera()->getViewMatrix();
00091
00092 WMatrix< double > rotMat( 4, 4 );
00093 for( size_t i = 0; i < 4; ++i )
00094 {
00095 for( size_t j = 0; j < 4; ++j )
00096 {
00097 rotMat( i, j ) = rm( i, j );
00098 }
00099 }
00100 WPosition v1( 0, 0, 1 );
00101 WPosition view;
00102 view = transformPosition3DWithMatrix4D( rotMat, v1 );
00103
00104 std::vector<float> dots( 8 );
00105 WPosition v2( 1, 1, 1 );
00106 dots[0] = dot( v2, view );
00107
00108 v2[2] = -1;
00109 dots[1] = dot( v2, view );
00110
00111 v2[1] = -1;
00112 dots[2] = dot( v2, view );
00113
00114 v2[2] = 1;
00115 dots[3] = dot( v2, view );
00116
00117 v2[0] = -1;
00118 dots[4] = dot( v2, view );
00119
00120 v2[2] = -1;
00121 dots[5] = dot( v2, view );
00122
00123 v2[1] = 1;
00124 dots[6] = dot( v2, view );
00125
00126 v2[2] = 1;
00127 dots[7] = dot( v2, view );
00128
00129 float max = 0.0;
00130 int quadrant = 0;
00131 for( int i = 0; i < 8; ++i )
00132 {
00133 if( dots[i] > max )
00134 {
00135 max = dots[i];
00136 quadrant = i;
00137 }
00138 }
00139 return quadrant;
00140 }
00141
00142 void WSelectionManager::setPaintMode( WPaintMode mode )
00143 {
00144 m_paintMode = mode;
00145
00146 osg::static_pointer_cast<WGEZoomTrackballManipulator>(
00147 WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() )->setPaintMode( mode );
00148 WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->setPaintMode( mode );
00149 }
00150
00151 WPaintMode WSelectionManager::getPaintMode()
00152 {
00153 return m_paintMode;
00154 }
00155
00156 void WSelectionManager::setTexture( osg::ref_ptr< osg::Texture3D > texture, boost::shared_ptr< WGridRegular3D >grid )
00157 {
00158 m_texture = texture;
00159 m_textureGrid = grid;
00160 }
00161
00162
00163 boost::shared_ptr< WGridRegular3D >WSelectionManager::getGrid()
00164 {
00165 return m_textureGrid;
00166 }
00167
00168 void WSelectionManager::setUseTexture( bool flag )
00169 {
00170 m_useTexture = flag;
00171 }
00172
00173 bool WSelectionManager::getUseTexture()
00174 {
00175 return m_useTexture;
00176 }
00177
00178
00179 float WSelectionManager::getTextureOpacity()
00180 {
00181 return m_textureOpacity;
00182 }
00183
00184 void WSelectionManager::setTextureOpacity( float value )
00185 {
00186 if( value < 0.0 )
00187 {
00188 value = 0.0;
00189 }
00190 if( value > 1.0 )
00191 {
00192 value = 1.0;
00193 }
00194 m_textureOpacity = value;
00195 }
00196
00197 WPropDouble WSelectionManager::getPropAxialPos()
00198 {
00199 return m_axialPos;
00200 }
00201
00202 WPropDouble WSelectionManager::getPropCoronalPos()
00203 {
00204 return m_coronalPos;
00205 }
00206
00207 WPropDouble WSelectionManager::getPropSagittalPos()
00208 {
00209 return m_sagittalPos;
00210 }
00211
00212 WPropBool WSelectionManager::getPropAxialShow()
00213 {
00214 return m_axialShow;
00215 }
00216
00217 WPropBool WSelectionManager::getPropCoronalShow()
00218 {
00219 return m_coronalShow;
00220 }
00221
00222 WPropBool WSelectionManager::getPropSagittalShow()
00223 {
00224 return m_sagittalShow;
00225 }
00226
00227 void WSelectionManager::setShader( int shader )
00228 {
00229 m_shader = shader;
00230 }
00231
00232 int WSelectionManager::getShader()
00233 {
00234 return m_shader;
00235 }
00236
00237 void WSelectionManager::updateCrosshairPosition()
00238 {
00239 m_crosshair->setPosition( WPosition( m_sagittalPos->get(), m_coronalPos->get(), m_axialPos->get() ) );
00240 }
00241