30 #include <osg/Geometry>
31 #include <osg/LightModel>
32 #include <osg/LineWidth>
34 #include "../common/WLogger.h"
35 #include "WGEGeodeUtils.h"
37 #include "WGraphicsEngine.h"
39 #include "shaders/WGEShader.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 std::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 std::unique_lock< std::shared_mutex > lock;
126 lock = std::unique_lock< std::shared_mutex >(
m_updateLock );
140 std::unique_lock< std::shared_mutex > lock;
141 lock = std::unique_lock< std::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 );
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
ValueT & y()
Access y element of vector.
ValueT & x()
Access x element of vector.
static const std::string unpickString
The string indicating picking has stopped.
Encapsulates info for pick action.
WVector2d getPickPixel() const
Returns the picked pixel coordinates in screen-space.
WVector3d getPickNormal() const
Get normal at position where object was hit.
int32_t getScrollWheel() const
Returns an integer denoting the wheel movement.
std::string getName() const
Get name of picked object.
modifierKey getModifierKey() const
Get the modifier key associated with the pick.
This only is a 3d double vector.
Node callback to handle updates properly.
static size_t maxBoxId
Current maximum boxId over all boxes.
void setNotColor(osg::Vec4 color)
Setter for color in negated state.
WROIBox(WPosition minPos, WPosition maxPos)
Yields box with desired extremal points minPos and maxPos.
osg::Vec4 m_notColor
the color of the box when negated
WPropPosition getMinPosProperty()
Get the corner of the box that has minimal x, y and z values.
std::shared_ptr< WGEViewer > m_viewer
makes viewer available all over this class.
WVector3d m_pickNormal
Store the normal that occured when the pick action was started.
void updateColor(osg::Vec4 color)
Set new color of the box in the geometry.
WPosition getMinPos() const
Get the corner of the box that has minimal x, y and z values.
WPickInfo m_pickInfo
Stores the pick information for potential redraw.
WVector2d m_oldPixelPosition
Caches the old picked position to a allow for cmoparison.
WPropPosition m_minPos
The minimum position of the box.
osg::Vec4 m_color
the color of the box
int16_t m_oldScrollWheel
caches scroll wheel value
void registerRedrawRequest(WPickInfo pickInfo)
note that there was a pick
osg::ref_ptr< osg::Geometry > m_surfaceGeometry
store this pointer for use in updates
WPropPosition getMaxPosProperty()
Get the corner of the box that has maximal x, y and z values.
WPosition getMaxPos() const
Get the corner of the box that has maximal x, y and z values.
bool m_isPicked
Indicates whether the box is currently picked or not.
virtual void updateGFX()
updates the graphics
size_t boxId
Id of the current box.
WPropGroup m_propGrp
Group for box specific props.
WPropPosition m_maxPos
The maximum position of the box.
WGEShader::RefPtr m_lightShader
Shader for proper lighting.
bool m_needVertexUpdate
If true, the box' vertex data is updated.
void setColor(osg::Vec4 color)
Setter for standard color.
void boxPropertiesChanged(std::shared_ptr< WPropertyBase > property)
Called when the specified property has changed.
std::shared_mutex m_updateLock
Lock to prevent concurrent threads trying to update the osg node.
Superclass for different ROI (region of interest) types.
osg::ref_ptr< WPickHandler > m_pickHandler
A pointer to the pick handler used to get gui events for moving the box.
std::shared_ptr< WProperties > m_properties
the property object for the module
WPropBool m_not
indicates if the roi is negated
void setDirty()
sets the dirty flag
WPropBool m_dirty
dirty flag, indicating the graphics needs updating, it is no longer used for bitfield updating since ...
osg::Vec3 unprojectFromScreen(const osg::Vec3 screen, osg::ref_ptr< WGECamera > camera)
Converts screen coordinates into Camera coordinates.
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.