Commit d82c02c0 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 291db3f0 5816666b
wiebel = Alexander_Wiebel
wiebel@hegel.informatik.uni-leipzig.de = Alexander_Wiebel
alexander.wiebel@hs-coburg.de = Alexander_Wiebel
openwalnut@dergrosse.de = Alexander_Wiebel
wiebel@openwalnut.org = Alexander_Wiebel
wiebel_openwalnut@dergrosse.de = Alexander_Wiebel
......@@ -12,6 +13,7 @@ schurade = Ralph_Schurade
alois.schloegl@ist.ac.at = Alois_Schloegl
softinst@heraklit.informatik.informatik.uni-leipzig.de = Sebastian_Eichelbaum
ebaum = Sebastian_Eichelbaum
sebastian.eichelbaum@nemtics.com = Sebastian_Eichelbaum
eichelbaum@informatik.uni-leipzig.de = Sebastian_Eichelbaum
Sebastian Eichelbaum = Sebastian_Eichelbaum
cornimueller = Cornelius_Mueller
......
......@@ -240,7 +240,7 @@ inline void WBoundingBoxImpl< VT >::reset()
template< class VT >
inline typename WBoundingBoxImpl< VT >::value_type WBoundingBoxImpl< VT >::radiusSquare() const
{
return this->raidus2();
return this->radius2();
}
template< class VT >
......
......@@ -115,67 +115,67 @@ void WPropertyBase::setHidden( bool hidden )
WPropInt WPropertyBase::toPropInt()
{
return boost::static_pointer_cast< WPVInt >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVInt >( shared_from_this() );
}
WPropDouble WPropertyBase::toPropDouble()
{
return boost::static_pointer_cast< WPVDouble >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVDouble >( shared_from_this() );
}
WPropBool WPropertyBase::toPropBool()
{
return boost::static_pointer_cast< WPVBool >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVBool >( shared_from_this() );
}
WPropString WPropertyBase::toPropString()
{
return boost::static_pointer_cast< WPVString >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVString >( shared_from_this() );
}
WPropFilename WPropertyBase::toPropFilename()
{
return boost::static_pointer_cast< WPVFilename >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVFilename >( shared_from_this() );
}
WPropSelection WPropertyBase::toPropSelection()
{
return boost::static_pointer_cast< WPVSelection >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVSelection >( shared_from_this() );
}
WPropColor WPropertyBase::toPropColor()
{
return boost::static_pointer_cast< WPVColor >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVColor >( shared_from_this() );
}
WPropPosition WPropertyBase::toPropPosition()
{
return boost::static_pointer_cast< WPVPosition >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVPosition >( shared_from_this() );
}
WPropGroup WPropertyBase::toPropGroup()
{
return boost::static_pointer_cast< WPVGroup >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVGroup >( shared_from_this() );
}
WPropertyGroupBase::SPtr WPropertyBase::toPropGroupBase()
{
return boost::static_pointer_cast< WPropertyGroupBase >( shared_from_this() );
return boost::dynamic_pointer_cast< WPropertyGroupBase >( shared_from_this() );
}
WPropMatrix4X4 WPropertyBase::toPropMatrix4X4()
{
return boost::static_pointer_cast< WPVMatrix4X4 >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVMatrix4X4 >( shared_from_this() );
}
WPropTrigger WPropertyBase::toPropTrigger()
{
return boost::static_pointer_cast< WPVTrigger >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVTrigger >( shared_from_this() );
}
WPropTransferFunction WPropertyBase::toPropTransferFunction()
{
return boost::static_pointer_cast< WPVTransferFunction >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVTransferFunction >( shared_from_this() );
}
boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
......@@ -185,6 +185,6 @@ boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
WPropInterval WPropertyBase::toPropInterval()
{
return boost::static_pointer_cast< WPVInterval >( shared_from_this() );
return boost::dynamic_pointer_cast< WPVInterval >( shared_from_this() );
}
......@@ -29,6 +29,7 @@
#include <algorithm>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "WStringUtils.h"
#include "WLogger.h"
......@@ -139,6 +140,43 @@ boost::shared_ptr< WPropertyBase > WPropertyGroupBase::findProperty( std::string
return result;
}
void WPropertyGroupBase::visitAsString( WPropertyGroupBase::PropertyStringVisitor visitor, std::string pathPrefix ) const
{
// read access
PropertySharedContainerType::ReadTicket r = getReadTicket();
for( PropertyConstIterator it = r->get().begin(); it != r->get().end(); ++it )
{
// path: handle some special cases:
std::string propName = pathPrefix + WPropertyGroupBase::separator + ( *it )->getName();
// 1: user added a separator
if( boost::algorithm::ends_with( pathPrefix, WPropertyGroupBase::separator ) )
{
propName = pathPrefix + ( *it )->getName();
}
// 2: avoid separator if prefix is empty
if( pathPrefix.empty() )
{
propName = ( *it )->getName();
}
// is it a group type?
WPropertyGroupBase::SPtr g = ( *it )->toPropGroupBase();
if( g )
{
// recurse down
g->visitAsString( visitor, propName );
}
else
{
// it is a leaf, call visitor
std::string value = ( *it )->getAsString();
visitor( propName, value );
}
}
}
bool WPropertyGroupBase::existsProperty( std::string name )
{
return ( findProperty( name ) != boost::shared_ptr< WPropertyBase >() );
......
......@@ -40,8 +40,6 @@
#include "WPropertyVariable.h"
#include "WSharedSequenceContainer.h"
/**
* This is the base class and interface for property groups. This class itself is abstract and derived from WPropertyBase. So if you create a
* group of properties, this ensures that your group is a property itself. This interface defines no way to add, remove or edit the property list
......@@ -167,6 +165,23 @@ public:
*/
virtual boost::shared_ptr< WPropertyBase > findProperty( std::string name ) const;
/**
* The visitor type used to visit properties as strings. The first parameter is the name, including the path of the property, relative to
* this group. The second parameter is the value as string.
*/
typedef boost::function< void ( std::string, std::string )> PropertyStringVisitor;
/**
* Visit all leafs in the property three that aren't empty groups. This is especially interesting when using it with lambda functionality.
* The visitor function gets two parameters: 1st: the name of the property, including the path beginning at this group; 2nd: the value as
* string.
*
* \param visitor the function to use for each property.
* \param pathPrefix add this prefix to the property name in the visitor. It might be interesting if manually implementing group visitors
* that always require a complete path, so you can add an upper-level path here.
*/
virtual void visitAsString( PropertyStringVisitor visitor, std::string pathPrefix = "" ) const;
protected:
/**
* Helping function to find a property inside a specific group. It does not recursively find properties nested inside other property groups.
......
......@@ -382,12 +382,12 @@ WFiber WDataSetFibers::operator[]( size_t numTract ) const
return result;
}
WFiberIterator WDataSetFibers::begin()
WDataSetFibers::const_iterator WDataSetFibers::begin() const
{
return WFiberIterator( this, 0 );
}
WFiberIterator WDataSetFibers::end()
WDataSetFibers::const_iterator WDataSetFibers::end() const
{
return WFiberIterator( this, m_lineLengths->size() );
}
......@@ -494,6 +494,16 @@ WFiberPointsIterator WFiberIterator::rend()
return WFiberPointsIterator( m_fibers, m_index, numPoints(), true );
}
std::size_t WFiberIterator::getLineStartIndex() const
{
return m_fibers->getLineStartIndexes()->operator[]( getIndex() );
}
std::size_t WFiberIterator::getIndex() const
{
return m_index;
}
WFiberPointsIterator::WFiberPointsIterator()
: m_fibers( NULL ),
m_fiberIndex( 0 ),
......@@ -563,7 +573,7 @@ WFiberPointsIterator WFiberPointsIterator::operator--( int )
return t;
}
osg::Vec3 WFiberPointsIterator::operator*()
std::size_t WFiberPointsIterator::getBaseIndex() const
{
WAssert( m_fibers, "" );
WAssert( m_fiberIndex < m_fibers->getLineLengths()->size(), "" );
......@@ -574,8 +584,13 @@ osg::Vec3 WFiberPointsIterator::operator*()
{
i = m_fibers->getLineLengths()->operator[] ( m_fiberIndex ) - i - 1;
}
std::size_t v = m_fibers->getLineStartIndexes()->operator[] ( m_fiberIndex ) + i;
return osg::Vec3( m_fibers->getVertices()->operator[]( 3 * v + 0 ),
return m_fibers->getLineStartIndexes()->operator[] ( m_fiberIndex ) + i;
}
WPosition WFiberPointsIterator::operator*()
{
std::size_t v = getBaseIndex();
return WPosition( m_fibers->getVertices()->operator[]( 3 * v + 0 ),
m_fibers->getVertices()->operator[]( 3 * v + 1 ),
m_fibers->getVertices()->operator[]( 3 * v + 2 ) );
}
......@@ -595,3 +610,72 @@ bool WFiberPointsIterator::operator!=( WFiberPointsIterator const& rhs ) const
return !( this->operator==( rhs ) );
}
double WFiberPointsIterator::getParameter( double def ) const
{
if( m_fibers->getVertexParameters() )
{
return m_fibers->getVertexParameters()->operator[]( getBaseIndex() );
}
return def;
}
WPosition WFiberPointsIterator::getTangent() const
{
std::size_t v = getBaseIndex();
return WPosition( m_fibers->getTangents()->operator[]( 3 * v + 0 ),
m_fibers->getTangents()->operator[]( 3 * v + 1 ),
m_fibers->getTangents()->operator[]( 3 * v + 2 ) );
}
WColor WFiberPointsIterator::getColor( const boost::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const
{
std::size_t v = getBaseIndex();
WColor ret;
switch( scheme->getMode() )
{
case WDataSetFibers::ColorScheme::GRAY:
{
double r = scheme->getColor()->operator[]( 1 * v + 0 );
ret.set( r, r, r, 1.0 );
}
break;
case WDataSetFibers::ColorScheme::RGB:
{
double r = scheme->getColor()->operator[]( 3 * v + 0 );
double g = scheme->getColor()->operator[]( 3 * v + 1 );
double b = scheme->getColor()->operator[]( 3 * v + 2 );
ret.set( r, g, b, 1.0 );
}
break;
case WDataSetFibers::ColorScheme::RGBA:
{
double r = scheme->getColor()->operator[]( 4 * v + 0 );
double g = scheme->getColor()->operator[]( 4 * v + 1 );
double b = scheme->getColor()->operator[]( 4 * v + 2 );
double a = scheme->getColor()->operator[]( 4 * v + 3 );
ret.set( r, g, b, a );
}
break;
default:
ret.set( 1.0, 1.0, 1.0, 1.0 );
break;
}
return ret;
}
WColor WFiberPointsIterator::getColor() const
{
return getColor( m_fibers->getColorScheme() );
}
WColor WFiberPointsIterator::getColor( std::size_t idx ) const
{
return getColor( m_fibers->getColorScheme( idx ) );
}
WColor WFiberPointsIterator::getColor( std::string name ) const
{
return getColor( m_fibers->getColorScheme( name ) );
}
......@@ -92,6 +92,17 @@ public:
*/
typedef boost::shared_ptr< std::vector< double > > VertexParemeterArray;
/**
* Iterator to go through the fibers.
*/
typedef WFiberIterator iterator;
/**
* Const iterator to go through fibers. As the WFiberIterators does not allow any modifications per-se, the const iterator and the standard
* iterator are the same.
*/
typedef WFiberIterator const_iterator;
/**
* Item used in the selection below also containing color info.
*/
......@@ -403,18 +414,18 @@ public:
WFiber operator[]( size_t numTract ) const;
/**
* Returns an iterator to the first fiber of the dataset.
* Returns an iterator to the first fiber of the dataset. The iterator does not allow any modification of the data.
*
* \return An iterator to the first fiber.
*/
WFiberIterator begin();
const_iterator begin() const;
/**
* Returns an iterator pointing beyond the last fiber.
* Returns an iterator pointing beyond the last fiber. The iterator does not allow any modification of the data.
*
* \return An iterator pointing beyond the last fiber.
*/
WFiberIterator end();
const_iterator end() const;
protected:
/**
......@@ -601,6 +612,27 @@ public:
*/
std::size_t numPoints() const;
/**
* Get the index in the point array where the points data starts for this line. You can use \ref numPoints to know how much data to read
* from the vertex array.
*
* \note You should avoid using these indices as can use the iterators to query the data. But it might get handy in some situations,
* where raw data processing is needed.
*
* \return the start index.
*/
std::size_t getLineStartIndex() const;
/**
* Get the index of the line.
*
* \note You should avoid using these indices as can use the iterators to query the data. But it might get handy in some situations,
* where raw data processing is needed.
*
* \return the index.
*/
std::size_t getIndex() const;
private:
//! The pointer to the fibers.
WDataSetFibers const* m_fibers;
......@@ -664,7 +696,7 @@ public:
/**
* Decrement operator. Makes the iterator point to the previous point.
*
*3
* \return The incremented iterator.
*/
WFiberPointsIterator& operator-- ();
......@@ -706,7 +738,75 @@ public:
*
* \return The current coordinates.
*/
osg::Vec3 operator* ();
WPosition operator* ();
/**
* Returns the parameter specified in the vertex parameter array of the dataset. If no such array was set, the specified default will be
* returned.
*
* \param def the default value which will be returned if no vertex parameter array was defined.
*
* \return the value or the specified default
*/
double getParameter( double def = 0.0 ) const;
/**
* The tangent of the point.
*
* \return the tangent
*/
WPosition getTangent() const;
/**
* Return the color of the point.
*
* \return the color.
*/
WColor getColor() const;
/**
* Return the color of the point.
*
* \param idx the index of the colorscheme to use.
*
* \throw WDHNoSuchDataSet if the colorscheme does not exist.
*
* \return the color.
*/
WColor getColor( std::size_t idx ) const;
/**
* Return the color of the point.
*
* \param name the name of the colorscheme to use.
*
* \throw WDHNoSuchDataSet if the colorscheme does not exist.
*
* \return the color.
*/
WColor getColor( std::string name ) const;
/**
* Return the color of the point.
*
* \param scheme the colorscheme to use.
*
* \throw WDHNoSuchDataSet if the colorscheme does not exist.
*
* \return the color.
*/
WColor getColor( const boost::shared_ptr< WDataSetFibers::ColorScheme > scheme ) const;
protected:
/**
* Calculates the index of this point in the dataset arrays. But be aware that this index works vertex-wise. This mens, getting the y
* coordinate of the vertex in the dataset vertex array, use 3 * getBaseIndex() + 1. This depends on the type of array you like to query.
*
* \note this function properly handles the case when walking in reverse direction.
*
* \return the base index, vertex-wise.
*/
std::size_t getBaseIndex() const;
private:
//! The pointer to the fibers.
......
......@@ -486,7 +486,7 @@ osg::ref_ptr< osg::Geode > wge::genFinitePlane( double xSize, double ySize, cons
return geode;
}
osg::ref_ptr< osg::Geode > wge::genFinitePlane( osg::Vec3 const& base, osg::Vec3 const& a, osg::Vec3 const& b )
osg::ref_ptr< osg::Geode > wge::genFinitePlane( osg::Vec3 const& base, osg::Vec3 const& a, osg::Vec3 const& b, const WColor& color )
{
// the stuff needed by the OSG to create a geometry instance
osg::ref_ptr< osg::Vec3Array > vertices = new osg::Vec3Array;
......@@ -509,7 +509,7 @@ osg::ref_ptr< osg::Geode > wge::genFinitePlane( osg::Vec3 const& base, osg::Vec3
bNorm.normalize();
normals->push_back( aCrossB );
colors->push_back( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
colors->push_back( color );
texcoords0->push_back( osg::Vec3( 0.0, 0.0, 0.0 ) );
texcoords0->push_back( aNorm );
texcoords0->push_back( aNorm + bNorm );
......
......@@ -202,10 +202,12 @@ namespace wge
* \param base the origin position. NOT the center.
* \param a the first vector spanning the plane
* \param b the second vector spanning the plane
* \param color the color to use.
*
* \return the geode
*/
osg::ref_ptr< osg::Geode > genFinitePlane( osg::Vec3 const& base, osg::Vec3 const& a, osg::Vec3 const& b );
osg::ref_ptr< osg::Geode > genFinitePlane( osg::Vec3 const& base, osg::Vec3 const& a, osg::Vec3 const& b,
const WColor& color = defaultColor::WHITE );
} // end of namespace wge
#endif // WGEGEODEUTILS_H
......@@ -112,6 +112,24 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
// add the stats handler
m_View->addEventHandler( new osgViewer::StatsHandler );
// Properties of the view. Collects props of the effects and similar
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "The view's properties" ) );
m_bgColor = m_properties->addProperty( "Background Color", "Default background color if not overwritten by a camera effect.",
defaultColor::WHITE,
boost::bind( &WGEViewer::updateBgColor, this ) );
m_throwing = m_properties->addProperty( "Throwing", "If checked, you can grab the scene and throw it. It will keep the rotation impulse.",
false,
boost::bind( &WGEViewer::updateThrowing, this ) );
WPropGroup effects = m_properties->addPropertyGroup( "Camera Effects", "Several effects that to not depend on any scene content." );
effects->addProperty( m_effectHorizon->getProperties() );
effects->addProperty( m_effectVignette->getProperties() );
effects->addProperty( m_effectImageOverlay->getProperties() );
// apply the above default
updateThrowing();
updateBgColor();
}
catch( ... )
{
......@@ -175,9 +193,28 @@ osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
return m_scene;
}
void WGEViewer::updateThrowing()
{
WGEZoomTrackballManipulator* manipulator = dynamic_cast< WGEZoomTrackballManipulator* >( getCameraManipulator().get() );
if( manipulator )
{
manipulator->setThrow( m_throwing->get() );
}
}
void WGEViewer::updateBgColor()
{
m_View->getCamera()->setClearColor( m_bgColor->get() );
}
void WGEViewer::setBgColor( const WColor& bgColor )
{
m_View->getCamera()->setClearColor( bgColor );
m_bgColor->set( bgColor );
}
WColor WGEViewer::getBgColor() const
{
return m_bgColor->get();
}
void WGEViewer::paint()
......@@ -331,3 +368,8 @@ WGEViewerEffectVignette::ConstSPtr WGEViewer::getVignette() const
{
return m_effectVignette;
}
WProperties::SPtr WGEViewer::getProperties() const
{
return m_properties;
}
......@@ -194,6 +194,13 @@ public:
*/
void setBgColor( const WColor& bgColor );
/**
* Returns the current default background color. This color is only visible if no camera effect overrides it.
*
* \return The color.
*/
WColor getBgColor() const;
/**
* Getter for the pick handler
*
......@@ -286,6 +293,13 @@ public:
*/
WGEViewerEffectVignette::ConstSPtr getVignette() const;
/**
* Return a pointer to the properties object of the view.
*
* \return the properties.
*/
WProperties::SPtr getProperties() const;
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
......@@ -401,7 +415,31 @@ protected:
* Image overlay effect.