29 #include <osg/LineWidth>
30 #include <osg/LightModel>
31 #include <osg/Geometry>
33 #include "../common/WLogger.h"
34 #include "shaders/WGEShader.h"
37 #include "WGraphicsEngine.h"
39 #include "WGEGeodeUtils.h"
48 m_oldScrollWheel( 0 ),
49 m_color( osg::Vec4( 0.391f, 0.594f, 0.828f, 0.5f ) ),
50 m_notColor( osg::Vec4( 0.828f, 0.391f, 0.391f, 0.5f ) )
53 m_minPos =
m_propGrp->addProperty(
"Min Position",
"When a box is described by its diagonal, this is the lower, left, front corner of it.",
55 m_maxPos =
m_propGrp->addProperty(
"Max Position",
"When a box is described by its diagonal, this is the upper, right, back corner of it.",
60 boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName(
"Main View" );
67 ss <<
"ROIBox" <<
boxId;
70 osg::StateSet* state = getOrCreateStateSet();
71 state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
73 osg::LineWidth* linewidth =
new osg::LineWidth();
74 linewidth->setWidth( 2.0f );
75 state->setAttributeAndModes( linewidth, osg::StateAttribute::ON );
77 osg::ref_ptr< osg::LightModel > lightModel =
new osg::LightModel();
78 lightModel->setTwoSided(
true );
80 state->setMode( GL_BLEND, osg::StateAttribute::ON );
125 boost::unique_lock< boost::shared_mutex > lock;
126 lock = boost::unique_lock< boost::shared_mutex >(
m_updateLock );
140 boost::unique_lock< boost::shared_mutex > lock;
141 lock = boost::unique_lock< boost::shared_mutex >(
m_updateLock );
143 std::stringstream ss;
144 ss <<
"ROIBox" <<
boxId <<
"";
150 osg::Vec3 in( newPixelPos.x(), newPixelPos.y(), 0.0 );
157 WPosition toDepthWorld( toDepth[0], toDepth[1], toDepth[2] );
161 WPosition newPixelWorldPos( world[0], world[1], world[2] );
165 oldPixelWorldPos = newPixelWorldPos;
171 oldPixelWorldPos =
WPosition( world[0], world[1], world[2] );
174 WVector3d moveVec = newPixelWorldPos - oldPixelWorldPos;
193 m_minPos->set(
m_minPos->get() + moveVec + ( 2.0 * toDepthWorld * depthMove ) );
194 m_maxPos->set(
m_maxPos->get() + moveVec + ( 2.0 * toDepthWorld * depthMove ) );
215 updateColor( osg::Vec4( 0.0f, 1.0f, 0.0f, 0.4f ) );
252 m_surfaceGeometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_LOOP, 0, 4 ) );
253 m_surfaceGeometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_LOOP, 4, 4 ) );
254 m_surfaceGeometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_LOOP, 8, 4 ) );
255 m_surfaceGeometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_LOOP, 12, 4 ) );
256 m_surfaceGeometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_LOOP, 16, 4 ) );
257 m_surfaceGeometry->addPrimitiveSet(
new osg::DrawArrays( osg::PrimitiveSet::LINE_LOOP, 20, 4 ) );
297 osg::ref_ptr<osg::Vec4Array> colors = osg::ref_ptr<osg::Vec4Array>(
new osg::Vec4Array );
298 colors->push_back( color );
300 WColor outline( 0.0, 0.0, 0.0, 1.0 );
302 colors->push_back( outline );
303 colors->push_back( outline );
304 colors->push_back( outline );
305 colors->push_back( outline );
306 colors->push_back( outline );
307 colors->push_back( outline );
void setDirty()
sets the dirty flag
osg::ref_ptr< WPickHandler > m_pickHandler
A pointer to the pick handler used to get gui events for moving the box.
WPropGroup m_propGrp
Group for box specific props.
static size_t maxBoxId
Current maximum boxId over all boxes.
WVector3d getPickNormal() const
Get normal at position where object was hit.
int32_t getScrollWheel() const
Returns an integer denoting the wheel movement.
void updateColor(osg::Vec4 color)
Set new color of the box in the geometry.
WPropPosition getMinPosProperty()
Get the corner of the box that has minimal x, y and z values.
Superclass for different ROI (region of interest) types.
boost::shared_mutex m_updateLock
Lock to prevent concurrent threads trying to update the osg node.
void setNotColor(osg::Vec4 color)
Setter for color in negated state.
WVector2d getPickPixel() const
Returns the picked pixel coordinates in screen-space.
WPickInfo m_pickInfo
Stores the pick information for potential redraw.
osg::Vec4 m_notColor
the color of the box when negated
This only is a 3d double vector.
WPosition getMaxPos() const
Get the corner of the box that has maximal x, y and z values.
WPosition getMinPos() const
Get the corner of the box that has minimal x, y and z values.
int16_t m_oldScrollWheel
caches scroll wheel value
virtual void updateGFX()
updates the graphics
boost::shared_ptr< WProperties > m_properties
the property object for the module
WVector3d m_pickNormal
Store the normal that occured when the pick action was started.
WPropPosition getMaxPosProperty()
Get the corner of the box that has maximal x, y and z values.
boost::shared_ptr< WGEViewer > m_viewer
makes viewer available all over this class.
modifierKey getModifierKey() const
Get the modifier key associated with the pick.
WPropBool m_dirty
dirty flag, indicating the graphics needs updating, it is no longer used for bitfield updating since ...
WROIBox(WPosition minPos, WPosition maxPos)
Yields box with desired extremal points minPos and maxPos.
A fixed size matrix class.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader...
WVector2d m_oldPixelPosition
Caches the old picked position to a allow for cmoparison.
void boxPropertiesChanged(boost::shared_ptr< WPropertyBase > property)
Called when the specified property has changed.
static boost::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
bool m_isPicked
Indicates whether the box is currently picked or not.
WPropBool m_not
indicates if the roi is negated
void registerRedrawRequest(WPickInfo pickInfo)
note that there was a pick
WPropPosition m_minPos
The minimum position of the box.
Encapsulates info for pick action.
Node callback to handle updates properly.
ValueT & y()
Access y element of vector.
bool m_needVertexUpdate
If true, the box' vertex data is updated.
WGEShader::RefPtr m_lightShader
Shader for proper lighting.
osg::Vec4 m_color
the color of the box
ValueT & x()
Access x element of vector.
std::string getName() const
Get name of picked object.
osg::Vec3 unprojectFromScreen(const osg::Vec3 screen, osg::ref_ptr< WGECamera > camera)
Converts screen coordinates into Camera coordinates.
void setColor(osg::Vec4 color)
Setter for standard color.
size_t boxId
Id of the current box.
WPropPosition m_maxPos
The maximum position of the box.
void createCube(osg::ref_ptr< osg::Geometry > geometry, const WPosition &position, const WPosition &size, const WColor &color)
Create an arbitrary cube and insert it into the given geometry.
osg::ref_ptr< osg::Geometry > m_surfaceGeometry
store this pointer for use in updates