OpenWalnut  1.5.0dev
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 <memory>
26 #include <vector>
27 
28 #include <osg/Matrix>
29 #include <osg/Texture3D>
30 
31 #include "../common/math/WLinearAlgebraFunctions.h"
32 #include "../graphicsEngine/WGEViewer.h"
33 #include "../graphicsEngine/WGEZoomTrackballManipulator.h"
34 #include "../graphicsEngine/WGraphicsEngine.h"
35 #include "../graphicsEngine/WPickHandler.h"
36 #include "WKernel.h"
37 #include "WSelectionManager.h"
38 
39 
41  m_paintMode( PAINTMODE_NONE ),
42  m_textureOpacity( 1.0 ),
43  m_useTexture( false )
44 {
45  m_crosshair = std::shared_ptr< WCrosshair >( new WCrosshair() );
46 
47  m_sliceGroup = std::shared_ptr< WProperties >( new WProperties( "Slice Properties",
48  "Properties relating to the Axial,Coronal and Sagittal Slices." ) );
49 
50  // create dummy properties for slices. Get updated by modules.
51  m_axialPos = m_sliceGroup->addProperty( "Axial Position", "Slice X position.", 0.0, true );
52  m_coronalPos = m_sliceGroup->addProperty( "Coronal Position", "Slice Y position.", 0.0, true );
53  m_sagittalPos = m_sliceGroup->addProperty( "Sagittal Position", "Slice Z position.", 0.0, true );
54 
55  // visibility flags
56  m_axialShow = m_sliceGroup->addProperty( "Show Axial Slice", "Slice visible?", true, true );
57  m_coronalShow = m_sliceGroup->addProperty( "Show Coronal Slice", "Slice visible?", true, true );
58  m_sagittalShow = m_sliceGroup->addProperty( "Show Sagittal Slice", "Slice visible?", true, true );
59 
60  m_axialUpdateConnection = m_axialPos->getUpdateCondition()->subscribeSignal(
61  boost::bind( &WSelectionManager::updateCrosshairPosition, this )
62  );
63  m_coronalUpdateConnection = m_coronalPos->getUpdateCondition()->subscribeSignal(
64  boost::bind( &WSelectionManager::updateCrosshairPosition, this )
65  );
66  m_sagittalUpdateConnection = m_sagittalPos->getUpdateCondition()->subscribeSignal(
67  boost::bind( &WSelectionManager::updateCrosshairPosition, this )
68  );
69 }
70 
72 {
73 }
74 
75 std::shared_ptr< WCrosshair >WSelectionManager::getCrosshair()
76 {
77  return m_crosshair;
78 }
79 
81 {
82  std::shared_ptr< WGEViewer > viewer;
83  viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Main View" );
84  viewer->getCamera()->getViewMatrix();
85  osg::Matrix rm = viewer->getCamera()->getViewMatrix();
86 
87  WMatrix< double > rotMat( 4, 4 );
88  for( size_t i = 0; i < 4; ++i )
89  {
90  for( size_t j = 0; j < 4; ++j )
91  {
92  rotMat( i, j ) = rm( i, j );
93  }
94  }
95  WPosition v1( 0, 0, 1 );
96  WPosition view;
97  view = transformPosition3DWithMatrix4D( rotMat, v1 );
98 
99  std::vector<float> dots( 8 );
100  WPosition v2( 1, 1, 1 );
101  dots[0] = dot( v2, view );
102 
103  v2[2] = -1;
104  dots[1] = dot( v2, view );
105 
106  v2[1] = -1;
107  dots[2] = dot( v2, view );
108 
109  v2[2] = 1;
110  dots[3] = dot( v2, view );
111 
112  v2[0] = -1;
113  dots[4] = dot( v2, view );
114 
115  v2[2] = -1;
116  dots[5] = dot( v2, view );
117 
118  v2[1] = 1;
119  dots[6] = dot( v2, view );
120 
121  v2[2] = 1;
122  dots[7] = dot( v2, view );
123 
124  float max = 0.0;
125  int quadrant = 0;
126  for( int i = 0; i < 8; ++i )
127  {
128  if( dots[i] > max )
129  {
130  max = dots[i];
131  quadrant = i;
132  }
133  }
134  return quadrant;
135 }
136 
137 void WSelectionManager::setPaintMode( WPaintMode mode )
138 {
139  m_paintMode = mode;
140 
141  osg::static_pointer_cast<WGEZoomTrackballManipulator>(
142  WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() )->setPaintMode( mode );
143  WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getPickHandler()->setPaintMode( mode == PAINTMODE_PAINT );
144 }
145 
147 {
148  return m_paintMode;
149 }
150 
151 void WSelectionManager::setTexture( osg::ref_ptr< osg::Texture3D > texture, std::shared_ptr< WGridRegular3D >grid )
152 {
153  m_texture = texture;
154  m_textureGrid = grid;
155 }
156 
157 
158 std::shared_ptr< WGridRegular3D >WSelectionManager::getGrid()
159 {
160  return m_textureGrid;
161 }
162 
164 {
165  m_useTexture = flag;
166 }
167 
169 {
170  return m_useTexture;
171 }
172 
173 
175 {
176  return m_textureOpacity;
177 }
178 
180 {
181  if( value < 0.0 )
182  {
183  value = 0.0;
184  }
185  if( value > 1.0 )
186  {
187  value = 1.0;
188  }
189  m_textureOpacity = value;
190 }
191 
193 {
194  return m_axialPos;
195 }
196 
198 {
199  return m_coronalPos;
200 }
201 
203 {
204  return m_sagittalPos;
205 }
206 
208 {
209  return m_axialShow;
210 }
211 
213 {
214  return m_coronalShow;
215 }
216 
218 {
219  return m_sagittalShow;
220 }
221 
223 {
224  m_shader = shader;
225 }
226 
228 {
229  return m_shader;
230 }
231 
233 {
234  m_crosshair->setPosition( WPosition( m_sagittalPos->get(), m_coronalPos->get(), m_axialPos->get() ) );
235 }
236 
This class stores the position of the crossing navigation slices, which is also represented as crossh...
Definition: WCrosshair.h:42
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
Definition: WKernel.cpp:117
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Definition: WKernel.cpp:122
This only is a 3d double vector.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
boost::signals2::connection m_coronalUpdateConnection
The connection for the coronal property.
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 setShader(int shader)
setter for the shader index to be used with the custom texture
WPropDouble getPropAxialPos()
The property controlling the current axial position of slices.
boost::signals2::connection m_axialUpdateConnection
The connection for the axial property.
bool m_useTexture
flag indicating if this additional texture should be used.
WSelectionManager()
standard constructor
void setUseTexture(bool flag=true)
setter
int m_shader
index of the shader to use with the texture
WPropDouble getPropSagittalPos()
The property controlling the current sagittal position of slices.
int getFrontSector()
function returns an index of the direction one is currently looking at the scene
WProperties::SPtr m_sliceGroup
Contains the slice related properties.
void setPaintMode(WPaintMode mode)
setter for paint mode, also forwards it to the graphics engine
bool getUseTexture()
getter
WPropDouble m_sagittalPos
Sagittal slice position.
float getTextureOpacity()
getter
WPropDouble m_axialPos
Axial slice position.
WPropBool getPropAxialShow()
The property controlling the current axial visible-flag.
WPaintMode m_paintMode
stores the currently selected paint mode
WPropDouble getPropCoronalPos()
The property controlling the current coronal position of slices.
std::shared_ptr< WGridRegular3D > getGrid()
getter
std::shared_ptr< WCrosshair > getCrosshair()
Return the current position of the point selection.
WPropBool m_sagittalShow
Sagittal visible-flag.
float m_textureOpacity
the texture opacity
boost::signals2::connection m_sagittalUpdateConnection
The connection for the sagittal property.
std::shared_ptr< WGridRegular3D > m_textureGrid
stores a pointer to the grid to be used together with the texture
WPaintMode getPaintMode()
getter for paint mode
void setTextureOpacity(float value)
setter
WPropBool getPropCoronalShow()
The property controlling the current coronal visible-flag.
WPropBool getPropSagittalShow()
The property controlling the current sagittal visible-flag.
WPropBool m_coronalShow
Coronal visible-flag.
void setTexture(osg::ref_ptr< osg::Texture3D > texture, std::shared_ptr< WGridRegular3D >grid)
setter for texture and grid
void updateCrosshairPosition()
Updates the crosshair position.
WPropBool m_axialShow
Axial visible-flag.
std::shared_ptr< WCrosshair > m_crosshair
stores pointer to crosshair
WPropDouble m_coronalPos
Coronal slice position.
virtual ~WSelectionManager()
destructor