OpenWalnut  1.4.0
WSelectionManager.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <vector>
26 
27 #include <osg/Matrix>
28 
29 #include "../common/math/WLinearAlgebraFunctions.h"
30 #include "../graphicsEngine/WGEViewer.h"
31 #include "../graphicsEngine/WGEZoomTrackballManipulator.h"
32 #include "../graphicsEngine/WGraphicsEngine.h"
33 #include "../graphicsEngine/WPickHandler.h"
34 #include "WKernel.h"
35 
36 #include "WSelectionManager.h"
37 
38 
40  m_paintMode( PAINTMODE_NONE ),
41  m_textureOpacity( 1.0 ),
42  m_useTexture( false )
43 {
44  m_crosshair = boost::shared_ptr< WCrosshair >( new WCrosshair() );
45 
46  m_sliceGroup = boost::shared_ptr< WProperties >( new WProperties( "Slice Properties",
47  "Properties relating to the Axial,Coronal and Sagittal Slices." ) );
48 
49  // create dummy properties for slices. Get updated by modules.
50  m_axialPos = m_sliceGroup->addProperty( "Axial Position", "Slice X position.", 0.0, true );
51  m_coronalPos = m_sliceGroup->addProperty( "Coronal Position", "Slice Y position.", 0.0, true );
52  m_sagittalPos = m_sliceGroup->addProperty( "Sagittal Position", "Slice Z position.", 0.0, true );
53 
54  // visibility flags
55  m_axialShow = m_sliceGroup->addProperty( "Show Axial Slice", "Slice visible?", true, true );
56  m_coronalShow = m_sliceGroup->addProperty( "Show Coronal Slice", "Slice visible?", true, true );
57  m_sagittalShow = m_sliceGroup->addProperty( "Show Sagittal Slice", "Slice visible?", true, true );
58 
59  m_axialUpdateConnection = m_axialPos->getUpdateCondition()->subscribeSignal(
60  boost::bind( &WSelectionManager::updateCrosshairPosition, this )
61  );
62  m_coronalUpdateConnection = m_coronalPos->getUpdateCondition()->subscribeSignal(
63  boost::bind( &WSelectionManager::updateCrosshairPosition, this )
64  );
65  m_sagittalUpdateConnection = m_sagittalPos->getUpdateCondition()->subscribeSignal(
66  boost::bind( &WSelectionManager::updateCrosshairPosition, this )
67  );
68 }
69 
71 {
72 }
73 
74 boost::shared_ptr< WCrosshair >WSelectionManager::getCrosshair()
75 {
76  return m_crosshair;
77 }
78 
80 {
81  boost::shared_ptr< WGEViewer > viewer;
82  viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
83  viewer->getCamera()->getViewMatrix();
84  osg::Matrix rm = viewer->getCamera()->getViewMatrix();
85 
86  WMatrix< double > rotMat( 4, 4 );
87  for( size_t i = 0; i < 4; ++i )
88  {
89  for( size_t j = 0; j < 4; ++j )
90  {
91  rotMat( i, j ) = rm( i, j );
92  }
93  }
94  WPosition v1( 0, 0, 1 );
95  WPosition view;
96  view = transformPosition3DWithMatrix4D( rotMat, v1 );
97 
98  std::vector<float> dots( 8 );
99  WPosition v2( 1, 1, 1 );
100  dots[0] = dot( v2, view );
101 
102  v2[2] = -1;
103  dots[1] = dot( v2, view );
104 
105  v2[1] = -1;
106  dots[2] = dot( v2, view );
107 
108  v2[2] = 1;
109  dots[3] = dot( v2, view );
110 
111  v2[0] = -1;
112  dots[4] = dot( v2, view );
113 
114  v2[2] = -1;
115  dots[5] = dot( v2, view );
116 
117  v2[1] = 1;
118  dots[6] = dot( v2, view );
119 
120  v2[2] = 1;
121  dots[7] = dot( v2, view );
122 
123  float max = 0.0;
124  int quadrant = 0;
125  for( int i = 0; i < 8; ++i )
126  {
127  if( dots[i] > max )
128  {
129  max = dots[i];
130  quadrant = i;
131  }
132  }
133  return quadrant;
134 }
135 
136 void WSelectionManager::setPaintMode( WPaintMode mode )
137 {
138  m_paintMode = mode;
139 
140  osg::static_pointer_cast<WGEZoomTrackballManipulator>(
141  WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() )->setPaintMode( mode );
142  WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->setPaintMode( mode );
143 }
144 
146 {
147  return m_paintMode;
148 }
149 
150 void WSelectionManager::setTexture( osg::ref_ptr< osg::Texture3D > texture, boost::shared_ptr< WGridRegular3D >grid )
151 {
152  m_texture = texture;
153  m_textureGrid = grid;
154 }
155 
156 
157 boost::shared_ptr< WGridRegular3D >WSelectionManager::getGrid()
158 {
159  return m_textureGrid;
160 }
161 
163 {
164  m_useTexture = flag;
165 }
166 
168 {
169  return m_useTexture;
170 }
171 
172 
174 {
175  return m_textureOpacity;
176 }
177 
179 {
180  if( value < 0.0 )
181  {
182  value = 0.0;
183  }
184  if( value > 1.0 )
185  {
186  value = 1.0;
187  }
188  m_textureOpacity = value;
189 }
190 
192 {
193  return m_axialPos;
194 }
195 
197 {
198  return m_coronalPos;
199 }
200 
202 {
203  return m_sagittalPos;
204 }
205 
207 {
208  return m_axialShow;
209 }
210 
212 {
213  return m_coronalShow;
214 }
215 
217 {
218  return m_sagittalShow;
219 }
220 
222 {
223  m_shader = shader;
224 }
225 
227 {
228  return m_shader;
229 }
230 
232 {
233  m_crosshair->setPosition( WPosition( m_sagittalPos->get(), m_coronalPos->get(), m_axialPos->get() ) );
234 }
235 
int getFrontSector()
function returns an index of the direction one is currently looking at the scene
WPropDouble m_coronalPos
Coronal slice position.
bool m_useTexture
flag indicating if this additional texture should be used.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
Definition: WKernel.cpp:117
void setPaintMode(WPaintMode mode)
setter for paint mode, also forwards it to the graphics engine
float m_textureOpacity
the texture opacity
boost::shared_ptr< WCrosshair > m_crosshair
stores pointer to crosshair
WSelectionManager()
standard constructor
boost::shared_ptr< WGridRegular3D > m_textureGrid
stores a pointer to the grid to be used together with the texture
boost::signals2::connection m_sagittalUpdateConnection
The connection for the sagittal property.
void setShader(int shader)
setter for the shader index to be used with the custom texture
boost::signals2::connection m_coronalUpdateConnection
The connection for the coronal property.
WPropBool getPropSagittalShow()
The property controlling the current sagittal visible-flag.
This only is a 3d double vector.
WProperties::SPtr m_sliceGroup
Contains the slice related properties.
osg::ref_ptr< osg::Texture3D > m_texture
stores a pointer to a texture 3d, this is used to provide a faster texture generation process than cr...
void setUseTexture(bool flag=true)
setter
WPaintMode m_paintMode
stores the currently selected paint mode
virtual ~WSelectionManager()
destructor
int m_shader
index of the shader to use with the texture
WPropBool m_axialShow
Axial visible-flag.
WPropDouble getPropAxialPos()
The property controlling the current axial position of slices.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
void updateCrosshairPosition()
Updates the crosshair position.
WPropDouble m_sagittalPos
Sagittal slice position.
float getTextureOpacity()
getter
WPropDouble getPropCoronalPos()
The property controlling the current coronal position of slices.
boost::signals2::connection m_axialUpdateConnection
The connection for the axial property.
WPropBool m_coronalShow
Coronal visible-flag.
This class stores the position of the crossing navigation slices, which is also represented as crossh...
Definition: WCrosshair.h:39
WPropBool m_sagittalShow
Sagittal visible-flag.
bool getUseTexture()
getter
WPropDouble m_axialPos
Axial slice position.
WPropBool getPropAxialShow()
The property controlling the current axial visible-flag.
WPropBool getPropCoronalShow()
The property controlling the current coronal visible-flag.
boost::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Definition: WKernel.cpp:122
WPropDouble getPropSagittalPos()
The property controlling the current sagittal position of slices.
boost::shared_ptr< WCrosshair > getCrosshair()
Return the current position of the point selection.
WPaintMode getPaintMode()
getter for paint mode
void setTextureOpacity(float value)
setter
New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
void setTexture(osg::ref_ptr< osg::Texture3D > texture, boost::shared_ptr< WGridRegular3D >grid)
setter for texture and grid
boost::shared_ptr< WGridRegular3D > getGrid()
getter