29 #include <osg/LineWidth>
30 #include <osg/LightModel>
31 #include <osg/Geometry>
33 #include "../common/WLogger.h"
36 #include "WGraphicsEngine.h"
41 void buildFacesFromPoints( osg::DrawElementsUInt* surfaceElements )
43 surfaceElements->push_back( 0 );
44 surfaceElements->push_back( 2 );
45 surfaceElements->push_back( 3 );
46 surfaceElements->push_back( 1 );
48 surfaceElements->push_back( 2 );
49 surfaceElements->push_back( 6 );
50 surfaceElements->push_back( 7 );
51 surfaceElements->push_back( 3 );
53 surfaceElements->push_back( 6 );
54 surfaceElements->push_back( 4 );
55 surfaceElements->push_back( 5 );
56 surfaceElements->push_back( 7 );
58 surfaceElements->push_back( 4 );
59 surfaceElements->push_back( 0 );
60 surfaceElements->push_back( 1 );
61 surfaceElements->push_back( 5 );
63 surfaceElements->push_back( 1 );
64 surfaceElements->push_back( 3 );
65 surfaceElements->push_back( 7 );
66 surfaceElements->push_back( 5 );
68 surfaceElements->push_back( 0 );
69 surfaceElements->push_back( 4 );
70 surfaceElements->push_back( 6 );
71 surfaceElements->push_back( 2 );
74 void buildLinesFromPoints( osg::DrawElementsUInt* surfaceElements )
76 surfaceElements->push_back( 0 );
77 surfaceElements->push_back( 2 );
78 surfaceElements->push_back( 2 );
79 surfaceElements->push_back( 3 );
80 surfaceElements->push_back( 3 );
81 surfaceElements->push_back( 1 );
82 surfaceElements->push_back( 1 );
83 surfaceElements->push_back( 0 );
85 surfaceElements->push_back( 6 );
86 surfaceElements->push_back( 4 );
87 surfaceElements->push_back( 4 );
88 surfaceElements->push_back( 5 );
89 surfaceElements->push_back( 5 );
90 surfaceElements->push_back( 7 );
91 surfaceElements->push_back( 7 );
92 surfaceElements->push_back( 6 );
94 surfaceElements->push_back( 2 );
95 surfaceElements->push_back( 6 );
96 surfaceElements->push_back( 7 );
97 surfaceElements->push_back( 3 );
99 surfaceElements->push_back( 4 );
100 surfaceElements->push_back( 0 );
101 surfaceElements->push_back( 1 );
102 surfaceElements->push_back( 5 );
107 vertices->push_back( osg::Vec3( minPos[0], minPos[1], minPos[2] ) );
108 vertices->push_back( osg::Vec3( minPos[0], minPos[1], maxPos[2] ) );
109 vertices->push_back( osg::Vec3( minPos[0], maxPos[1], minPos[2] ) );
110 vertices->push_back( osg::Vec3( minPos[0], maxPos[1], maxPos[2] ) );
111 vertices->push_back( osg::Vec3( maxPos[0], minPos[1], minPos[2] ) );
112 vertices->push_back( osg::Vec3( maxPos[0], minPos[1], maxPos[2] ) );
113 vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], minPos[2] ) );
114 vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], maxPos[2] ) );
122 m_oldScrollWheel( 0 ),
123 m_color( osg::Vec4( 0.f, 1.f, 1.f, 0.4f ) ),
124 m_notColor( osg::Vec4( 1.0f, 0.0f, 0.0f, 0.4f ) )
131 boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName(
"Main View" );
140 std::stringstream ss;
141 ss <<
"ROIBox" <<
boxId;
146 osg::ref_ptr<osg::Vec3Array> vertices = osg::ref_ptr<osg::Vec3Array>(
new osg::Vec3Array );
147 setVertices( vertices, minPos, maxPos );
150 osg::DrawElementsUInt* surfaceElements;
151 surfaceElements =
new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
152 buildFacesFromPoints( surfaceElements );
154 osg::DrawElementsUInt* lineElements;
155 lineElements =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
156 buildLinesFromPoints( lineElements );
161 osg::StateSet* state = getOrCreateStateSet();
162 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
164 osg::LineWidth* linewidth =
new osg::LineWidth();
165 linewidth->setWidth( 2.f );
166 state->setAttributeAndModes( linewidth, osg::StateAttribute::ON );
170 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
172 colors->push_back( osg::Vec4( 0.0f, 0.0f, 1.0f, 0.5f ) );
176 osg::ref_ptr< osg::LightModel > lightModel =
new osg::LightModel();
177 lightModel->setTwoSided(
true );
178 state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
179 state->setMode( GL_BLEND, osg::StateAttribute::ON );
208 boost::unique_lock< boost::shared_mutex > lock;
209 lock = boost::unique_lock< boost::shared_mutex >(
m_updateLock );
218 boost::unique_lock< boost::shared_mutex > lock;
219 lock = boost::unique_lock< boost::shared_mutex >(
m_updateLock );
221 std::stringstream ss;
222 ss <<
"ROIBox" <<
boxId <<
"";
228 osg::Vec3 in( newPixelPos.x(), newPixelPos.y(), 0.0 );
235 WPosition toDepthWorld( toDepth[0], toDepth[1], toDepth[2] );
239 WPosition newPixelWorldPos( world[0], world[1], world[2] );
243 oldPixelWorldPos = newPixelWorldPos;
249 oldPixelWorldPos =
WPosition( world[0], world[1], world[2] );
252 WVector3d moveVec = newPixelWorldPos - oldPixelWorldPos;
254 osg::ref_ptr<osg::Vec3Array> vertices = osg::ref_ptr<osg::Vec3Array>(
new osg::Vec3Array );
278 m_minPos += 2.0 * toDepthWorld * depthMove;
279 m_maxPos += 2.0 * toDepthWorld * depthMove;
290 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
303 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
304 colors->push_back( osg::Vec4( 0.0f, 1.0f, 0.0f, 0.4f ) );
321 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
337 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );