OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 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 "../graphicsEngine/WPickHandler.h" 00034 #include "WKernel.h" 00035 00036 #include "WSelectionManager.h" 00037 00038 00039 WSelectionManager::WSelectionManager() : 00040 m_paintMode( PAINTMODE_NONE ), 00041 m_textureOpacity( 1.0 ), 00042 m_useTexture( false ) 00043 { 00044 m_crosshair = boost::shared_ptr< WCrosshair >( new WCrosshair() ); 00045 00046 m_sliceGroup = boost::shared_ptr< WProperties >( new WProperties( "Slice Properties", 00047 "Properties relating to the Axial,Coronal and Sagittal Slices." ) ); 00048 00049 // create dummy properties for slices. Get updated by modules. 00050 m_axialPos = m_sliceGroup->addProperty( "Axial Position", "Slice X position.", 0.0, true ); 00051 m_coronalPos = m_sliceGroup->addProperty( "Coronal Position", "Slice Y position.", 0.0, true ); 00052 m_sagittalPos = m_sliceGroup->addProperty( "Sagittal Position", "Slice Z position.", 0.0, true ); 00053 00054 // visibility flags 00055 m_axialShow = m_sliceGroup->addProperty( "Show Axial Slice", "Slice visible?", true, true ); 00056 m_coronalShow = m_sliceGroup->addProperty( "Show Coronal Slice", "Slice visible?", true, true ); 00057 m_sagittalShow = m_sliceGroup->addProperty( "Show Sagittal Slice", "Slice visible?", true, true ); 00058 00059 m_axialUpdateConnection = m_axialPos->getUpdateCondition()->subscribeSignal( 00060 boost::bind( &WSelectionManager::updateCrosshairPosition, this ) 00061 ); 00062 m_coronalUpdateConnection = m_coronalPos->getUpdateCondition()->subscribeSignal( 00063 boost::bind( &WSelectionManager::updateCrosshairPosition, this ) 00064 ); 00065 m_sagittalUpdateConnection = m_sagittalPos->getUpdateCondition()->subscribeSignal( 00066 boost::bind( &WSelectionManager::updateCrosshairPosition, this ) 00067 ); 00068 } 00069 00070 WSelectionManager::~WSelectionManager() 00071 { 00072 } 00073 00074 boost::shared_ptr< WCrosshair >WSelectionManager::getCrosshair() 00075 { 00076 return m_crosshair; 00077 } 00078 00079 int WSelectionManager::getFrontSector() 00080 { 00081 boost::shared_ptr< WGEViewer > viewer; 00082 viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" ); 00083 viewer->getCamera()->getViewMatrix(); 00084 osg::Matrix rm = viewer->getCamera()->getViewMatrix(); 00085 00086 WMatrix< double > rotMat( 4, 4 ); 00087 for( size_t i = 0; i < 4; ++i ) 00088 { 00089 for( size_t j = 0; j < 4; ++j ) 00090 { 00091 rotMat( i, j ) = rm( i, j ); 00092 } 00093 } 00094 WPosition v1( 0, 0, 1 ); 00095 WPosition view; 00096 view = transformPosition3DWithMatrix4D( rotMat, v1 ); 00097 00098 std::vector<float> dots( 8 ); 00099 WPosition v2( 1, 1, 1 ); 00100 dots[0] = dot( v2, view ); 00101 00102 v2[2] = -1; 00103 dots[1] = dot( v2, view ); 00104 00105 v2[1] = -1; 00106 dots[2] = dot( v2, view ); 00107 00108 v2[2] = 1; 00109 dots[3] = dot( v2, view ); 00110 00111 v2[0] = -1; 00112 dots[4] = dot( v2, view ); 00113 00114 v2[2] = -1; 00115 dots[5] = dot( v2, view ); 00116 00117 v2[1] = 1; 00118 dots[6] = dot( v2, view ); 00119 00120 v2[2] = 1; 00121 dots[7] = dot( v2, view ); 00122 00123 float max = 0.0; 00124 int quadrant = 0; 00125 for( int i = 0; i < 8; ++i ) 00126 { 00127 if( dots[i] > max ) 00128 { 00129 max = dots[i]; 00130 quadrant = i; 00131 } 00132 } 00133 return quadrant; 00134 } 00135 00136 void WSelectionManager::setPaintMode( WPaintMode mode ) 00137 { 00138 m_paintMode = mode; 00139 00140 osg::static_pointer_cast<WGEZoomTrackballManipulator>( 00141 WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() )->setPaintMode( mode ); 00142 WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->setPaintMode( mode ); 00143 } 00144 00145 WPaintMode WSelectionManager::getPaintMode() 00146 { 00147 return m_paintMode; 00148 } 00149 00150 void WSelectionManager::setTexture( osg::ref_ptr< osg::Texture3D > texture, boost::shared_ptr< WGridRegular3D >grid ) 00151 { 00152 m_texture = texture; 00153 m_textureGrid = grid; 00154 } 00155 00156 00157 boost::shared_ptr< WGridRegular3D >WSelectionManager::getGrid() 00158 { 00159 return m_textureGrid; 00160 } 00161 00162 void WSelectionManager::setUseTexture( bool flag ) 00163 { 00164 m_useTexture = flag; 00165 } 00166 00167 bool WSelectionManager::getUseTexture() 00168 { 00169 return m_useTexture; 00170 } 00171 00172 00173 float WSelectionManager::getTextureOpacity() 00174 { 00175 return m_textureOpacity; 00176 } 00177 00178 void WSelectionManager::setTextureOpacity( float value ) 00179 { 00180 if( value < 0.0 ) 00181 { 00182 value = 0.0; 00183 } 00184 if( value > 1.0 ) 00185 { 00186 value = 1.0; 00187 } 00188 m_textureOpacity = value; 00189 } 00190 00191 WPropDouble WSelectionManager::getPropAxialPos() 00192 { 00193 return m_axialPos; 00194 } 00195 00196 WPropDouble WSelectionManager::getPropCoronalPos() 00197 { 00198 return m_coronalPos; 00199 } 00200 00201 WPropDouble WSelectionManager::getPropSagittalPos() 00202 { 00203 return m_sagittalPos; 00204 } 00205 00206 WPropBool WSelectionManager::getPropAxialShow() 00207 { 00208 return m_axialShow; 00209 } 00210 00211 WPropBool WSelectionManager::getPropCoronalShow() 00212 { 00213 return m_coronalShow; 00214 } 00215 00216 WPropBool WSelectionManager::getPropSagittalShow() 00217 { 00218 return m_sagittalShow; 00219 } 00220 00221 void WSelectionManager::setShader( int shader ) 00222 { 00223 m_shader = shader; 00224 } 00225 00226 int WSelectionManager::getShader() 00227 { 00228 return m_shader; 00229 } 00230 00231 void WSelectionManager::updateCrosshairPosition() 00232 { 00233 m_crosshair->setPosition( WPosition( m_sagittalPos->get(), m_coronalPos->get(), m_axialPos->get() ) ); 00234 } 00235