Commit 7a98ec96 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents c8dbc566 07842619
......@@ -36,7 +36,9 @@
#include "WWorkerThread.h"
#include "WSharedObject.h"
//! an enum indicating the status of a multithreaded computation
/**
* An enum indicating the status of a multithreaded computation
*/
enum WThreadedFunctionStatus
{
W_THREADS_INITIALIZED, //! the status after constructing the function
......@@ -46,6 +48,15 @@ enum WThreadedFunctionStatus
W_THREADS_FINISHED //! all threads completed their work successfully
};
/**
* An enum indicating the number of threads used
*/
enum WThreadedFunctionNbThreads
{
W_AUTOMATIC_NB_THREADS = 0 //!< Use half the available cores as number of threads
};
/**
* \class WThreadedFunction
*
......@@ -201,7 +212,7 @@ WThreadedFunction< Function_T >::WThreadedFunction( std::size_t numThreads, boos
}
// find a suitable number of threads
if( m_numThreads == 0 )
if( m_numThreads == W_AUTOMATIC_NB_THREADS )
{
m_numThreads = 1;
while( m_numThreads < boost::thread::hardware_concurrency() / 2 && m_numThreads < 1024 )
......
......@@ -45,7 +45,7 @@
*/
namespace wmath
{
// Pi constants - we dont use the macro M_PI, because it is not part of the C++-standard.
// Pi constants - we don't use the macro M_PI, because it is not part of the C++-standard.
// ref.: http://stackoverflow.com/questions/1727881/how-to-use-the-pi-constant-in-c
/** the pi constant in float format */
const float piFloat = boost::math::constants::pi<float>();
......@@ -69,7 +69,7 @@ namespace wmath
#endif
}
/**
* Checks if the triangle intersects with the given plane. If you are interessted in the points of
* Checks if the triangle intersects with the given plane. If you are interested in the points of
* intersection if any \see intersection().
*
* \param p1 first point of the triangle
......@@ -84,13 +84,13 @@ namespace wmath
/**
* Checks if the given segment intersects with the plane or not. Even if
* just one endpoint intersects with the plane it should be returned as
* point of intersection. If the segement is totally inside of that plane
* point of intersection. If the segment is totally inside of that plane
* the first endpoint (which was given: p1 ) should be returned in the
* cutPoint parameter.
*
* \param p The plane to test with intersection
* \param p1 The first endpoint of the line segement
* \param p2 The second endpoint of the line segement
* \param p1 The first endpoint of the line segment
* \param p2 The second endpoint of the line segment
* \param pointOfIntersection The point of intersection if any, otherwise 0,0,0
*
* \return True if an intersection was detected, false otherwise.
......@@ -101,12 +101,12 @@ namespace wmath
boost::shared_ptr< wmath::WPosition > pointOfIntersection );
/**
* Checks a line (consecutive line segements) on intersection with a plane
* Checks a line (consecutive line segments) on intersection with a plane
* and selects (if there are more than one point of intersection) the
* closest to the base point of the plane.
*
* \param p The plane to test with intersection
* \param l The line segements
* \param l The line segments
* \param cutPoint The return parameter for the point of intersection
*
* \return True if an intersection was detected, false otherwise.
......
......@@ -61,7 +61,7 @@ public:
}
/**
* Makes the matix contain the identity matrix, i.e. 1 on the diagonal.
* Makes the matrix contain the identity matrix, i.e. 1 on the diagonal.
*/
WMatrix& makeIdentity()
{
......@@ -100,7 +100,7 @@ public:
}
/**
* Returns a reference to the component an row i, colums j in order to
* Returns a reference to the component an row i, columns j in order to
* provide access to the component.
* \param i row
* \param j column
......@@ -112,7 +112,7 @@ public:
}
/**
* Returns a const reference to the component an row i, colums j in order to
* Returns a const reference to the component an row i, columns j in order to
* provide read-only access to the component.
* \param i row
* \param j column
......
......@@ -58,7 +58,7 @@ public:
* \param first First vector perpendicular to the normal
* \param second Second vector perpendicular to the normal and linearly independent from first.
*
* \note Due to numerical stability a comparision to 0.0 is not performed. Instead the absolute value of the dot product is checked to
* \note Due to numerical stability a comparison to 0.0 is not performed. Instead the absolute value of the dot product is checked to
* be smaller than the FLT_EPS. FLT_EPS is used instead of DBL_EPS just numerical errors may sum up above DBL_EPS.
*/
WPlane( const wmath::WVector3D& normal, const wmath::WPosition& pos, const wmath::WVector3D& first, const wmath::WVector3D& second );
......
......@@ -91,7 +91,7 @@ public:
size_t getOrder() const;
/**
* Calculate the generalized fractional anisotropy for this odf.
* Calculate the generalized fractional anisotropy for this ODF.
*
* See: David S. Tuch, "Q-Ball Imaging", Magn. Reson. Med. 52, 2004, 1358-1372
*
......@@ -104,9 +104,9 @@ public:
double calcGFA( std::vector< wmath::WUnitSphereCoordinates > const& orientations ) const;
/**
* Calculate the generalized fractional anisotropy for this odf. This version of
* Calculate the generalized fractional anisotropy for this ODF. This version of
* the function uses precomputed base functions (because calculating the base function values
* is rather expensive). Use this version if you want to compute the gfa for multiple ODFs
* is rather expensive). Use this version if you want to compute the GFA for multiple ODFs
* with the same base functions. The base function Matrix can be computed using \see calcBMatrix().
*
* See: David S. Tuch, "Q-Ball Imaging", Magn. Reson. Med. 52, 2004, 1358-1372
......@@ -122,8 +122,8 @@ public:
/**
* This calculates the transformation/fitting matrix T like in the 2007 Descoteaux paper. The orientations are given as wmath::WVector3D.
* \param orientations The vector with the used orientation on the unit sphere (usually the gradients of the HARDI)
* \param order The order of the spherical harmonics intented to create
* \param lambda Regularisation parameter for smoothing matrix
* \param order The order of the spherical harmonics intended to create
* \param lambda Regularization parameter for smoothing matrix
* \param withFRT include the Funk-Radon-Transformation?
* \return Transformation matrix
*/
......@@ -135,8 +135,8 @@ public:
/**
* This calculates the transformation/fitting matrix T like in the 2007 Descoteaux paper. The orientations are given as wmath::WUnitSphereCoordinates .
* \param orientations The vector with the used orientation on the unit sphere (usually the gradients of the HARDI)
* \param order The order of the spherical harmonics intented to create
* \param lambda Regularisation parameter for smoothing matrix
* \param order The order of the spherical harmonics intended to create
* \param lambda Regularization parameter for smoothing matrix
* \param withFRT include the Funk-Radon-Transformation?
* \return Transformation matrix
*/
......@@ -146,9 +146,9 @@ public:
bool withFRT );
/**
* Calculates the base matrix B like in the diss of Descoteaux.
* Calculates the base matrix B like in the dissertation of Descoteaux.
* \param orientations The vector with the used orientation on the unit sphere (usually the gradients of the HARDI)
* \param order The order of the spherical harmonics intented to create
* \param order The order of the spherical harmonics intended to create
* \return The base Matrix B
*/
static wmath::WMatrix<double> calcBaseMatrix( const std::vector< wmath::WUnitSphereCoordinates >& orientations, int order );
......
......@@ -713,7 +713,7 @@ public:
/**
* Compare this WTensorBaseSym to another one.
*
* \param other The WBensorBaseSym to compare to.
* \param other The WTensorBaseSym to compare to.
*
* \return True, iff this tensors' elements are equal to another tensors' elements.
*/
......@@ -722,7 +722,7 @@ public:
/**
* Compare this WTensorBaseSym to another one.
*
* \param other The WBensorBaseSym to compare to.
* \param other The WTensorBaseSym to compare to.
*
* \return True, iff this tensors' elements are not equal to another tensors' elements.
*/
......
......@@ -151,7 +151,7 @@ void jacobiEigenvector3D( WTensorSym< 2, 3, Data_T > const& mat,
/**
* Calculate eigenvectors via the characteristic polynomial. This is essentially the same
* function as in the gpu glyph shaders. This is for 3 dimensions only.
* function as in the GPU glyph shaders. This is for 3 dimensions only.
*
* \param m The symmetric matrix to calculate the eigenvalues from.
* \return A std::vector of 3 eigenvalues in descending order.
......
......@@ -54,8 +54,8 @@ public:
WUnitSphereCoordinates( double theta, double phi );
/**
* Constructor for euclidean coordinates.
* \param vector euclidean coordinates
* Constructor for Euclidean coordinates.
* \param vector Euclidean coordinates
*/
explicit WUnitSphereCoordinates( wmath::WVector3D vector );
......@@ -87,7 +87,7 @@ public:
void setPhi( double phi );
/**
* Returns the stored sphere coordinates as euclidean coordinates.
* Returns the stored sphere coordinates as Euclidean coordinates.
*/
wmath::WVector3D getEuclidean() const;
......@@ -102,4 +102,3 @@ private:
}
#endif // WUNITSPHERECOORDINATES_H
......@@ -123,7 +123,7 @@ public:
}
/**
* Adds a the argument componentwise to the components of this WValue
* Adds a the argument component-wise to the components of this WValue
* \param rhs The right hand side of the assignment
*/
WValue& operator+=( const WValue& rhs )
......@@ -135,7 +135,7 @@ public:
}
/**
* Subtracts the argument componentwise from the components of this WValue
* Subtracts the argument component-wise from the components of this WValue
* \param rhs The right hand side of the assignment
*/
WValue& operator-=( const WValue& rhs )
......@@ -158,7 +158,7 @@ public:
}
/**
* Scales each component of this WValue with the coressponding
* Scales each component of this WValue with the corresponding
* component of the given argument WValue
* \param rhs The right hand side of the assignment
*/
......@@ -183,7 +183,7 @@ public:
/**
* Componentwise addition.
* Component-wise addition.
* \param summand2 The right hand side of the summation
*/
const WValue operator+( const WValue& summand2 ) const
......@@ -195,7 +195,7 @@ public:
}
/**
* Componentwise subtraction.
* Component-wise subtraction.
* \param subtrahend The right hand side of the subtraction
*/
const WValue operator-( const WValue& subtrahend ) const
......@@ -207,7 +207,7 @@ public:
}
/**
* Componentwise multiplication.
* Component-wise multiplication.
* \param factor2 The right hand side of the product
*/
const WValue operator*( const WValue& factor2 ) const
......@@ -348,7 +348,7 @@ template< typename T > inline const WValue< T > operator/( const WValue< T >& lh
* \param os The operator will write to this stream.
* \param rhs This will be written to the stream.
*
* \return the outputstream
* \return the output stream
*/
template< typename U > inline std::ostream& operator<<( std::ostream& os, const WValue< U > &rhs )
{
......@@ -361,7 +361,7 @@ template< typename U > inline std::ostream& operator<<( std::ostream& os, const
* \param in the input stream
* \param rhs the value to where to write the stream
*
* \return the inputstream
* \return the input stream
*/
template< typename U > inline std::istream& operator>>( std::istream& in, WValue< U >& rhs )
{
......
......@@ -68,7 +68,7 @@ public:
inline WVector3D( osg::Vec3d::value_type x, osg::Vec3d::value_type y, osg::Vec3d::value_type z );
/**
* Calculate euclidean square distance between this Position and another one.
* Calculate Euclidean square distance between this Position and another one.
*
* \param other The other position.
* \return Square distance.
......@@ -81,18 +81,18 @@ public:
inline osg::Vec3d::value_type norm() const;
/**
* Returns a noralized vecrsion of the vector
* Returns a normalized version of the vector
*/
inline WVector3D normalized() const;
/**
* Compute the cross product of the current WValue with the parameter.
* Compute the cross product of the current WVector3D with the parameter.
* \param factor2 This vector will be multiplied with the current vector. (right hand side of the product)
*/
const WVector3D crossProduct( const WVector3D& factor2 ) const;
/**
* Compute the dot product of the current WValue with the parameter.
* Compute the dot product of the current WVector3D with the parameter.
* \param factor2 This vector will be multiplied with the current vector. (right hand side of the product)
*/
inline osg::Vec3d::value_type dotProduct( const WVector3D& factor2 ) const;
......@@ -108,7 +108,7 @@ public:
inline size_t size() const;
/**
* Componentwise subtraction.
* Component-wise subtraction.
* \param subtrahend The right hand side of the subtraction
*/
inline const WVector3D operator-( const WVector3D& subtrahend ) const;
......@@ -127,7 +127,7 @@ typedef WVector3D WPosition;
* \param os The operator will write to this stream.
* \param rhs This will be written to the stream.
*
* \return the outputstream
* \return the output stream
*/
inline std::ostream& operator<<( std::ostream& os, const WVector3D &rhs )
......@@ -138,12 +138,12 @@ inline std::ostream& operator<<( std::ostream& os, const WVector3D &rhs )
}
/**
* Write an input stream into a WValue.
* Write an input stream into a WVector3D.
*
* \param in the input stream
* \param rhs the value to where to write the stream
*
* \return the inputstream
* \return the input stream
*/
inline std::istream& operator>>( std::istream& in, WVector3D &rhs )
{
......
......@@ -124,6 +124,24 @@ public:
TS_ASSERT_DELTA( ds.interpolate( wmath::WPosition( 0.5, 0.5, 0.5 ), &success )[2], 33.5, 1e-9 );
TS_ASSERT( success );
}
/**
* A test for ticket #313
*/
void testBoundary_ticket313( void )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( 3, 4, 5, 1, 1, 1 ) );
bool success = false;
std::vector< double > data( grid->size() * 3 );
for( size_t i = 0; i < grid->size() * 3; ++i )
{
data[i] = i;
}
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
WDataSetVector ds( valueSet, grid );
ds.interpolate( wmath::WPosition( 2.0, 3.0, 4.0 ), &success );
TS_ASSERT( !success );
}
};
#endif // WDATASETVECTOR_TEST_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "callbacks/WGEViewportCallback.h"
#include "WGEOffscreenRenderNode.h"
WGEOffscreenRenderNode::WGEOffscreenRenderNode( osg::ref_ptr< osg::Camera > reference, size_t width, size_t height, bool noHud ):
WGEGroupNode(),
m_referenceCamera( reference ),
m_hud( new WGETextureHud() ),
m_textureWidth( width ),
m_textureHeight( height ),
m_nextPassNum( 0 )
{
// initialize members
if ( !noHud )
{
m_hud->addUpdateCallback( new WGEViewportCallback< WGETextureHud >( m_referenceCamera ) );
m_hud->coupleViewportWithTextureViewport();
insert( m_hud );
}
}
WGEOffscreenRenderNode::~WGEOffscreenRenderNode()
{
// cleanup
}
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addRenderPass( std::string name )
{
// create a new pass
osg::ref_ptr< WGEOffscreenRenderPass > pass = new WGEOffscreenRenderPass( m_textureWidth, m_textureHeight, m_hud, name, m_nextPassNum );
m_nextPassNum++;
// this node needs to keep all the pass instances. Only this way, the OSG traverses and renders these nodes in the order specified by
// m_nextPassNum.
insert( pass ); // insert into this group
// ensure proper propagation of viewport changes
pass->addUpdateCallback( new WGEViewportCallback< WGEOffscreenRenderPass >( m_referenceCamera ) );
// set clear mask and color according to reference cam
pass->setClearMask( m_referenceCamera->getClearMask() );
pass->setClearColor( m_referenceCamera->getClearColor() );
return pass;
}
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addGeometryRenderPass( osg::ref_ptr< osg::Node > node, std::string name )
{
// create a plain render pass and add some geometry
osg::ref_ptr< WGEOffscreenRenderPass > pass = addRenderPass( name );
pass->addChild( node );
return pass;
}
osg::ref_ptr< WGEOffscreenRenderPass > WGEOffscreenRenderNode::addTextureProcessingPass( std::string name )
{
osg::ref_ptr< WGEOffscreenRenderPass > pass = addRenderPass( name );
// we need to create a nice quad for texture processing spanning the whole texture space
return pass;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGEOFFSCREENRENDERNODE_H
#define WGEOFFSCREENRENDERNODE_H
#include <string>
#include <osg/Camera>
#include "WGEGroupNode.h"
#include "WGEOffscreenRenderPass.h"
#include "WGETextureHud.h"
/**
* This type of node basically is a convenience class for managing and creating offscreen renderings. The children of this node should be of type
* \ref WGEOffscreenRenderPass. This class provides factories to create offscreen-render-pass instances with proper sizes with a coupling to a
* reference camera. This is useful to provide automatic viewport scaling etc. to each render-pass. You do not explicitly need this class to
* create offscreen-renderings at all. You can manually manage multiple WGEOffscreenRenderPass instances.
*
* It is important to understand, that the graph (your scene) must not be a children of this node. This node can be placed somewhere in your
* scene. The OSG collects all the cameras (and offscreen-cameras) and render then independently from their position in the graph (except for
* transformations inherited from others).
*
* \note Please not that you should not modify the whole wiring and offscreen configuration if the this node has been added as it is not
* thread-safe.
*/
class WGEOffscreenRenderNode: public WGEGroupNode
{
public:
/**
* Create a new managing instance. It uses the specified camera as reference to all created offscreen-render-pass instances. Especially
* viewport, clear-mask and clear-color get used. The default texture resolution is 2048x2048 which is more than full-HD resolution. So it
* should be enough.
*
* \param reference camera used as reference
* \param width the width of the textures used in this rendering
* \param height the height of the textures used in this rendering*
* \param noHud If true, no hud gets displayed showing the created and used textures.
*/
WGEOffscreenRenderNode( osg::ref_ptr< osg::Camera > reference, size_t width = 2048, size_t height = 2048, bool noHud = false );
/**
* Destructor.
*/
virtual ~WGEOffscreenRenderNode();
/**
* Creates a new offscreen-render-pass coupled with the reference camera which renders a specified OSG graph to a texture.
*
* \param node the node which represents the subgraph.
* \param name the name of the render pass. You should specify it to enable the nice debugging feature of WGETextureHud.
*
* \note never forget to remove the returned node if not used anymore or use WGEGroup::clean.
*
* \return the geometry render pass.
*/
virtual osg::ref_ptr< WGEOffscreenRenderPass > addGeometryRenderPass( osg::ref_ptr< osg::Node > node, std::string name = "Unnamed" );
/**
* Creates a new offscreen-render-pass coupled with the reference camera which simply processes textures. All the in- and output textures
* have to be specified manually.
*
* \note never forget to remove the returned node if not used anymore or use WGEGroup::clean.
*
* \param name the name of the render pass. You should specify it to enable the nice debugging feature of WGETextureHud.
*
* \return the texture processing pass created.
*/
virtual osg::ref_ptr< WGEOffscreenRenderPass > addTextureProcessingPass( std::string name = "Unnamed" );
/**
* Creates a new offscreen-render-pass coupled with the reference camera. This pass actually does nothing. The method is useful for custom
* variants of WGEOffscreenRenderPass.
*
* \param name the name of the render pass. You should specify it to enable the nice debugging feature of WGETextureHud.
*
* \return new instance of a plain render pass
*/
virtual osg::ref_ptr< WGEOffscreenRenderPass > addRenderPass( std::string name = "Unnamed" );
protected:
private:
/**
* The camera to which is used for setting this camera up.
*/
osg::ref_ptr< osg::Camera > m_referenceCamera;
/**
* The pointer to the hud used to render all used texture buffers. This can be NULL. It gets distributed to all created render-pass
* instances.
*/
osg::ref_ptr< WGETextureHud > m_hud;
/**
* The width of each texture in this offscreen rendering.
*/
size_t m_textureWidth;
/**
* The height of each texture in this offscreen rendering.
*/
size_t m_textureHeight;
/**
* The number of the next pass getting added.
*/
size_t m_nextPassNum;
};
#endif // WGEOFFSCREENRENDERNODE_H
......@@ -22,54 +22,98 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <boost/lexical_cast.hpp>
#include <osg/Textu