28 #include <osg/LineWidth>
29 #include <osg/LightModel>
32 #include "WGraphicsEngine.h"
37 void buildFacesFromPoints( osg::DrawElementsUInt* surfaceElements )
39 surfaceElements->push_back( 0 );
40 surfaceElements->push_back( 2 );
41 surfaceElements->push_back( 3 );
42 surfaceElements->push_back( 1 );
44 surfaceElements->push_back( 2 );
45 surfaceElements->push_back( 6 );
46 surfaceElements->push_back( 7 );
47 surfaceElements->push_back( 3 );
49 surfaceElements->push_back( 6 );
50 surfaceElements->push_back( 4 );
51 surfaceElements->push_back( 5 );
52 surfaceElements->push_back( 7 );
54 surfaceElements->push_back( 4 );
55 surfaceElements->push_back( 0 );
56 surfaceElements->push_back( 1 );
57 surfaceElements->push_back( 5 );
59 surfaceElements->push_back( 1 );
60 surfaceElements->push_back( 3 );
61 surfaceElements->push_back( 7 );
62 surfaceElements->push_back( 5 );
64 surfaceElements->push_back( 0 );
65 surfaceElements->push_back( 4 );
66 surfaceElements->push_back( 6 );
67 surfaceElements->push_back( 2 );
70 void buildLinesFromPoints( osg::DrawElementsUInt* surfaceElements )
72 surfaceElements->push_back( 0 );
73 surfaceElements->push_back( 2 );
74 surfaceElements->push_back( 2 );
75 surfaceElements->push_back( 3 );
76 surfaceElements->push_back( 3 );
77 surfaceElements->push_back( 1 );
78 surfaceElements->push_back( 1 );
79 surfaceElements->push_back( 0 );
81 surfaceElements->push_back( 6 );
82 surfaceElements->push_back( 4 );
83 surfaceElements->push_back( 4 );
84 surfaceElements->push_back( 5 );
85 surfaceElements->push_back( 5 );
86 surfaceElements->push_back( 7 );
87 surfaceElements->push_back( 7 );
88 surfaceElements->push_back( 6 );
90 surfaceElements->push_back( 2 );
91 surfaceElements->push_back( 6 );
92 surfaceElements->push_back( 7 );
93 surfaceElements->push_back( 3 );
95 surfaceElements->push_back( 4 );
96 surfaceElements->push_back( 0 );
97 surfaceElements->push_back( 1 );
98 surfaceElements->push_back( 5 );
103 vertices->push_back( osg::Vec3( minPos[0], minPos[1], minPos[2] ) );
104 vertices->push_back( osg::Vec3( minPos[0], minPos[1], maxPos[2] ) );
105 vertices->push_back( osg::Vec3( minPos[0], maxPos[1], minPos[2] ) );
106 vertices->push_back( osg::Vec3( minPos[0], maxPos[1], maxPos[2] ) );
107 vertices->push_back( osg::Vec3( maxPos[0], minPos[1], minPos[2] ) );
108 vertices->push_back( osg::Vec3( maxPos[0], minPos[1], maxPos[2] ) );
109 vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], minPos[2] ) );
110 vertices->push_back( osg::Vec3( maxPos[0], maxPos[1], maxPos[2] ) );
118 m_color( osg::Vec4( 0.f, 1.f, 1.f, 0.4f ) ),
119 m_notColor( osg::Vec4( 1.0f, 0.0f, 0.0f, 0.4f ) )
126 boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName(
"main" );
136 std::stringstream ss;
137 ss <<
"ROIBox" <<
boxId;
142 osg::ref_ptr<osg::Vec3Array> vertices = osg::ref_ptr<osg::Vec3Array>(
new osg::Vec3Array );
143 setVertices( vertices, minPos, maxPos );
146 osg::DrawElementsUInt* surfaceElements;
147 surfaceElements =
new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
148 buildFacesFromPoints( surfaceElements );
150 osg::DrawElementsUInt* lineElements;
151 lineElements =
new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 );
152 buildLinesFromPoints( lineElements );
157 osg::StateSet* state = getOrCreateStateSet();
158 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
160 osg::LineWidth* linewidth =
new osg::LineWidth();
161 linewidth->setWidth( 2.f );
162 state->setAttributeAndModes( linewidth, osg::StateAttribute::ON );
166 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
168 colors->push_back( osg::Vec4( 0.0f, 0.0f, 1.0f, 0.5f ) );
172 osg::ref_ptr< osg::LightModel > lightModel =
new osg::LightModel();
173 lightModel->setTwoSided(
true );
174 state->setAttributeAndModes( lightModel.get(), osg::StateAttribute::ON );
175 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 );
231 WPosition newPixelWorldPos( world[0], world[1], world[2] );
235 oldPixelWorldPos = newPixelWorldPos;
241 oldPixelWorldPos =
WPosition( world[0], world[1], world[2] );
244 WVector3d moveVec = newPixelWorldPos - oldPixelWorldPos;
246 osg::ref_ptr<osg::Vec3Array> vertices = osg::ref_ptr<osg::Vec3Array>(
new osg::Vec3Array );
279 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
292 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
293 colors->push_back( osg::Vec4( 0.0f, 1.0f, 0.0f, 0.4f ) );
307 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
323 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );