Commit 918aff30 by Alexander Wiebel

[---] added changes of 8173f90f5856, 973c35789f0a, 0bd18abdebc9 and

1c8de374b61a as patch to release
branch, as schurade wants to have them in.
parent 2ccb3fa1
......@@ -203,7 +203,9 @@ std::string WReaderFiberVTK::getLine( const std::string& desc )
std::string line;
try
{
std::getline( *m_ifs, line );
// we use '\n' as line termination under every platform so our files (which are most likely to be generated on Unix systems)
// can be read from all platforms not having those line termination symbols like e.g. windows ('\r\n').
std::getline( *m_ifs, line, '\n' );
}
catch( const std::ios_base::failure &e )
{
......
......@@ -47,17 +47,20 @@ void WWriterFiberVTK::writeFibs( boost::shared_ptr< const WDataSetFiberVector >
{
throw WDHIOFailure( "Invalid file, or permission: " + m_fname );
}
out << "# vtk DataFile Version 3.0" << std::endl;
out << "Fibers from OpenWalnut" << std::endl;
out << "BINARY" << std::endl;
out << "DATASET POLYDATA" << std::endl;
// We use '\n' as line delimiter so also files written under windows (having '\r\n' as delimtier) may be read anywhere
char lineDelimiter = '\n';
out << "# vtk DataFile Version 3.0" << lineDelimiter;
out << "Fibers from OpenWalnut" << lineDelimiter;
out << "BINARY" << lineDelimiter;
out << "DATASET POLYDATA" << lineDelimiter;
unsigned int numPoints = 0;
unsigned int numLines = fiberDS->size();
for( size_t i = 0; i < fiberDS->size(); ++i )
{
numPoints += (*fiberDS)[i].size();
}
out << "POINTS " << numPoints << " float" << std::endl;
out << "POINTS " << numPoints << " float" << lineDelimiter;
unsigned int *rawLineData = new unsigned int[numPoints + numLines];
float *rawPointData = new float[numPoints * 3];
......@@ -82,9 +85,9 @@ void WWriterFiberVTK::writeFibs( boost::shared_ptr< const WDataSetFiberVector >
wiotools::switchByteOrderOfArray< float >( rawPointData, numPoints * 3 );
wiotools::switchByteOrderOfArray< unsigned int >( rawLineData, numLines + numPoints );
out.write( reinterpret_cast< char* >( rawPointData ), sizeof( float ) * numPoints * 3 );
out << std::endl;
out << "LINES " << numLines << " " << numPoints + numLines << std::endl;
out << lineDelimiter;
out << "LINES " << numLines << " " << numPoints + numLines << lineDelimiter;
out.write( reinterpret_cast< char* >( rawLineData ), sizeof( unsigned int ) * ( numPoints + numLines ) );
out << std::endl;
out << lineDelimiter;
out.close();
}
......@@ -526,29 +526,21 @@ void WQtDatasetBrowser::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
WQtBranchTreeItem* branchItem;
m_tiRois->setExpanded( true );
bool found = false;
if ( m_roiTreeWidget->selectedItems().count() != 0 )
// go through all branches
for( int branchID = 0; branchID < m_tiRois->childCount(); ++branchID )
{
switch ( m_roiTreeWidget->selectedItems().at( 0 )->type() )
branchItem = dynamic_cast< WQtBranchTreeItem* >( m_tiRois->child( branchID ) );
// if branch == roi branch
if ( branchItem->getBranch() == roi->getBranch() )
{
case ROI :
{
branchItem =( static_cast< WQtBranchTreeItem* >( m_roiTreeWidget->selectedItems().at( 0 )->parent() ) );
break;
}
case ROIBRANCH :
{
branchItem =( static_cast< WQtBranchTreeItem* >( m_roiTreeWidget->selectedItems().at( 0 ) ) );
break;
}
default:
{
branchItem = m_tiRois->addBranch( roi->getBranch() );
break;
}
found = true;
break;
}
}
else
if ( !found )
{
branchItem = m_tiRois->addBranch( roi->getBranch() );
}
......@@ -558,6 +550,7 @@ void WQtDatasetBrowser::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
newItem = branchItem->addRoiItem( roi );
newItem->setDisabled( false );
newItem->setSelected( true );
WKernel::getRunningKernel()->getRoiManager()->setSelectedRoi( getSelectedRoi() );
}
void WQtDatasetBrowser::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi )
......@@ -581,6 +574,7 @@ void WQtDatasetBrowser::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi
}
}
}
WKernel::getRunningKernel()->getRoiManager()->setSelectedRoi( getSelectedRoi() );
}
boost::shared_ptr< WModule > WQtDatasetBrowser::getSelectedModule()
......@@ -727,18 +721,20 @@ void WQtDatasetBrowser::selectRoiTreeItem()
case MODULEHEADER:
case MODULE:
case ROIHEADER:
WKernel::getRunningKernel()->getRoiManager()->setSelectedRoi( getSelectedRoi() );
break;
case ROIBRANCH:
props = ( static_cast< WQtBranchTreeItem* >( m_roiTreeWidget->selectedItems().at( 0 ) ) )->getBranch()->getProperties();
WKernel::getRunningKernel()->getRoiManager()->setSelectedRoi( getFirstRoiInSelectedBranch() );
break;
case ROI:
props = ( static_cast< WQtRoiTreeItem* >( m_roiTreeWidget->selectedItems().at( 0 ) ) )->getRoi()->getProperties();
WKernel::getRunningKernel()->getRoiManager()->setSelectedRoi( getSelectedRoi() );
break;
default:
break;
}
}
WKernel::getRunningKernel()->getRoiManager()->setSelectedRoi( getFirstRoiInSelectedBranch() );
buildPropTab( props, boost::shared_ptr< WProperties >() );
}
......
......@@ -32,7 +32,7 @@
WQtRoiHeaderTreeItem::WQtRoiHeaderTreeItem( QTreeWidget * parent ) :
QTreeWidgetItem( parent, ROIHEADER )
{
setFlags( Qt::ItemIsEnabled );
setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
}
WQtRoiHeaderTreeItem::~WQtRoiHeaderTreeItem()
......
......@@ -31,22 +31,40 @@
WRMBranch::WRMBranch( boost::shared_ptr< WROIManagerFibers > roiManager ) :
m_dirty( true ),
m_roiManager( roiManager )
{
setDirty();
m_size = m_roiManager->size();
properties();
}
WRMBranch::~WRMBranch()
{
}
void WRMBranch::properties()
{
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This branch's properties" ) );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMBranch::slotToggleNot, this ) );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMBranch::propertyChanged, this ) );
m_bundleColor = m_properties->addProperty( "Bundle Color", "description", WColor( 1.0, 0.0, 0.0, 1.0 ),
boost::bind( &WRMBranch::slotChangeBundleColor, this ) );
boost::bind( &WRMBranch::propertyChanged, this ) );
}
WRMBranch::~WRMBranch()
void WRMBranch::propertyChanged()
{
if ( m_bundleColor->changed() )
{
m_roiManager->updateBundleColor( shared_from_this(), m_bundleColor->get( true ) );
}
setDirty();
}
void WRMBranch::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
{
m_rois.push_back( roi );
setDirty();
}
void WRMBranch::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi )
......@@ -73,84 +91,64 @@ boost::shared_ptr< std::vector< bool > > WRMBranch::getBitField()
{
recalculate();
}
return m_bitField;
}
void WRMBranch::addBitField( size_t size )
{
boost::shared_ptr< std::vector< bool > >bf = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( size, false ) );
m_bitField = bf;
for( std::list< boost::shared_ptr< WRMROIRepresentation> >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{
( *iter )->addBitField( size );
}
setDirty();
return m_outputBitfield;
}
void WRMBranch::recalculate()
{
// boost::shared_lock<boost::shared_mutex> slock;
// slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
boost::shared_ptr< std::vector<bool> > mbf = m_bitField;
int size = mbf->size();
mbf->clear();
bool atLeastOneActive = false;
if ( m_rois.size() == 1 && !m_rois.front()->isActive() )
for( std::list< boost::shared_ptr< WRMROIRepresentation > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{
mbf->resize( size, false );
if ( ( *iter )->active() )
{
atLeastOneActive = true;
}
}
else
if ( atLeastOneActive )
{
mbf->resize( size, true );
m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, true ) );
for( std::list< boost::shared_ptr< WRMROIRepresentation > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{
if ( ( *iter )->isActive() )
if ( ( *iter )->active() )
{
boost::shared_ptr< std::vector<bool> > bf = ( *iter )->getBitField();
bool isnot = ( *iter )->getROI()->isNot();
if ( !isnot )
{
for ( size_t i = 0 ; i < mbf->size() ; ++i )
for ( size_t i = 0 ; i < m_size ; ++i )
{
( *mbf )[i] = ( *mbf )[i] & ( *bf )[i];
( *m_workerBitfield )[i] = ( *m_workerBitfield )[i] & ( *bf )[i];
}
}
else
{
for ( size_t i = 0 ; i < mbf->size() ; ++i )
for ( size_t i = 0 ; i < m_size ; ++i )
{
( *mbf )[i] = ( *mbf )[i] & !( *bf )[i];
( *m_workerBitfield )[i] = ( *m_workerBitfield )[i] & !( *bf )[i];
}
}
}
}
}
if ( m_isNot->get() )
{
for ( size_t i = 0 ; i < mbf->size() ; ++i )
if ( m_isNot->get() )
{
( *mbf )[i] = !( *mbf )[i];
for ( size_t i = 0 ; i < m_size ; ++i )
{
( *m_workerBitfield )[i] = !( *m_workerBitfield )[i];
}
}
}
// int counter = 0;
// for (int i = 0 ; i < mbf->size() ; ++i)
// {
// if ( mbf->at(i) )
// ++counter;
// }
// std::cout << "active fibers in branch :" << counter << std::endl;
else
{
m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, false ) );
}
m_dirty = false;
// slock.unlock();
}
bool WRMBranch::isDirty()
{
return m_dirty;
m_outputBitfield = m_workerBitfield;
}
void WRMBranch::setDirty()
......@@ -169,23 +167,7 @@ boost::shared_ptr< WROIManagerFibers > WRMBranch::getRoiManager()
return m_roiManager;
}
bool WRMBranch::isEmpty()
{
return m_rois.empty();
}
void WRMBranch::slotToggleNot()
{
//std::cout << "toggle not " << (m_isNot->get() ? "true" : "false") << std::endl;
setDirty();
}
boost::shared_ptr< WProperties > WRMBranch::getProperties()
{
return m_properties;
}
void WRMBranch::slotChangeBundleColor()
{
m_roiManager->updateBundleColor( shared_from_this(), m_bundleColor->get() );
}
......@@ -85,13 +85,6 @@ public:
boost::shared_ptr< std::vector< bool > > getBitField();
/**
* creates and adds a bitfield to the list
*
* \param size of the bitfield
*/
void addBitField( size_t size );
/**
* updates the branch bitfield for this branch
*/
void recalculate();
......@@ -101,7 +94,7 @@ public:
*
* \return the dirty flag
*/
bool isDirty();
bool dirty();
/**
* sets dirty flag true and notifies the branch
......@@ -111,7 +104,7 @@ public:
/**
* returns whether the branch is empty
*/
bool isEmpty();
bool empty();
/**
* returns a pointer to the first roi in the branch
......@@ -135,24 +128,31 @@ public:
protected:
/**
* slot gets called when a property has changed
*
* initializes properties
*/
void slotToggleNot();
void properties();
/**
* slot gets called when a property has changed
*
*/
void slotChangeBundleColor();
void propertyChanged();
private:
bool m_dirty; //!< dirty flag to indicate the bit field must be recalculated
size_t m_size; //!< number of fibers in the dataset
boost::shared_ptr< WROIManagerFibers > m_roiManager; //!< stores a pointer to the roi manager
boost::shared_ptr< std::vector<bool> >m_bitField; //!< list of bit fields for each fiber dataset
/**
* pointer to the bitfield that represents the current selection by the roi
*/
boost::shared_ptr< std::vector<bool> >m_outputBitfield;
/**
* pointer to the bitfield we work on
*/
boost::shared_ptr< std::vector<bool> >m_workerBitfield;
std::list< boost::shared_ptr< WRMROIRepresentation> > m_rois; //!< list of rois in this this branch,
// first in the list is the master roi
......@@ -177,4 +177,14 @@ private:
WPropColor m_bundleColor;
};
inline bool WRMBranch::empty()
{
return m_rois.empty();
}
inline bool WRMBranch::dirty()
{
return m_dirty;
}
#endif // WRMBRANCH_H
......@@ -38,16 +38,33 @@
#include "WRMROIRepresentation.h"
WRMROIRepresentation::WRMROIRepresentation( osg::ref_ptr< WROI > roi, boost::shared_ptr< WRMBranch > branch ) :
m_dirty( true ),
m_roi( roi ),
m_branch( branch )
{
m_size = m_branch->getRoiManager()->size();
m_currentArray = m_branch->getRoiManager()->getDataSet()->getVertices();
m_currentReverse = m_branch->getRoiManager()->getDataSet()->getVerticesReverse();
m_kdTree = m_branch->getRoiManager()->getKdTree();
properties();
roi->getSignalIsModified()->connect( boost::bind( &WRMROIRepresentation::setDirty, this ) );
setDirty();
}
WRMROIRepresentation::~WRMROIRepresentation()
{
removeFromGE();
}
void WRMROIRepresentation::properties()
{
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMROIRepresentation::slotToggleNot, this ) );
m_threshold = m_properties->addProperty( "Threshold", "description", 0., boost::bind( &WRMROIRepresentation::slotChangeThreshold, this ) );
m_isNot = m_properties->addProperty( "NOT", "description", false, boost::bind( &WRMROIRepresentation::propertyChanged, this ) );
m_threshold = m_properties->addProperty( "Threshold", "description", 0., boost::bind( &WRMROIRepresentation::propertyChanged, this ) );
m_threshold->setHidden( true );
m_isActive = m_properties->addProperty( "active", "description", true, boost::bind( &WRMROIRepresentation::slotToggleNot, this ) );
m_isActive = m_properties->addProperty( "active", "description", true, boost::bind( &WRMROIRepresentation::propertyChanged, this ) );
m_isActive->setHidden( true );
if ( osg::dynamic_pointer_cast<WROIArbitrary>( m_roi ).get() )
......@@ -58,11 +75,28 @@ WRMROIRepresentation::WRMROIRepresentation( osg::ref_ptr< WROI > roi, boost::sha
}
}
WRMROIRepresentation::~WRMROIRepresentation()
void WRMROIRepresentation::propertyChanged()
{
WGraphicsEngine::getGraphicsEngine()->getScene()->remove( m_roi );
m_roi->setNot( m_isNot->get() );
m_roi->setActive( m_isActive->get() );
if ( m_isActive->get() )
{
m_roi->setNodeMask( 0xFFFFFFFF );
}
else
{
m_roi->setNodeMask( 0x0 );
}
if ( osg::dynamic_pointer_cast< WROIArbitrary >( m_roi ).get() )
{
osg::dynamic_pointer_cast< WROIArbitrary >( m_roi ).get()->setThreshold( m_threshold->get() );
setDirty();
}
setDirty();
}
void WRMROIRepresentation::removeFromGE()
{
WGraphicsEngine::getGraphicsEngine()->getScene()->remove( m_roi );
......@@ -79,26 +113,12 @@ boost::shared_ptr< std::vector< bool > > WRMROIRepresentation::getBitField()
{
recalculate();
}
return m_bitField;
}
void WRMROIRepresentation::addBitField( size_t size )
{
boost::shared_ptr< std::vector< bool > >bf = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( size, false ) );
m_bitField = bf;
setDirty();
return m_outputBitfield;
}
void WRMROIRepresentation::recalculate()
{
m_currentBitfield = m_bitField;
size_t size = m_currentBitfield->size();
m_currentBitfield->clear();
m_currentBitfield->resize( size, false );
m_currentArray = m_branch->getRoiManager()->getDataSet()->getVertices();
m_currentReverse = m_branch->getRoiManager()->getDataSet()->getVerticesReverse();
m_kdTree = m_branch->getRoiManager()->getKdTree();
m_workerBitfield = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >( m_size, false ) );
if ( osg::dynamic_pointer_cast<WROIBox>( m_roi ).get() )
{
......@@ -133,10 +153,6 @@ void WRMROIRepresentation::recalculate()
for ( size_t i = 0; i < m_currentArray->size()/3; ++i )
{
//int x = wxMin( nx - 1, wxMax(0, (int)m_pointArray[i * 3 ])) / dx;
//int y = wxMin( ny - 1, wxMax(0, (int)m_pointArray[i * 3 + 1])) / dy;
//int z = wxMin( nz - 1, wxMax(0, (int)m_pointArray[i * 3 + 2])) / dz;
size_t x = static_cast<size_t>( ( *m_currentArray )[i * 3 ] / dx );
size_t y = static_cast<size_t>( ( *m_currentArray )[i * 3 + 1] / dy );
size_t z = static_cast<size_t>( ( *m_currentArray )[i * 3 + 2] / dz );
......@@ -144,11 +160,12 @@ void WRMROIRepresentation::recalculate()
if ( static_cast<float>( roi->getValue( index ) ) - threshold > 0.1 )
{
( *m_currentBitfield )[getLineForPoint( i )] = 1;
( *m_workerBitfield )[getLineForPoint( i )] = 1;
}
}
}
m_dirty = false;
m_outputBitfield = m_workerBitfield;
}
void WRMROIRepresentation::boxTest( int left, int right, int axis )
......@@ -176,55 +193,19 @@ void WRMROIRepresentation::boxTest( int left, int right, int axis )
>= m_boxMin[axis1] && ( *m_currentArray )[pointIndex + axis2] <= m_boxMax[axis2]
&& ( *m_currentArray )[pointIndex + axis2] >= m_boxMin[axis2] )
{
( *m_currentBitfield )[getLineForPoint( m_kdTree->m_tree[root] )] = 1;
( *m_workerBitfield )[getLineForPoint( m_kdTree->m_tree[root] )] = 1;
}
boxTest( left, root - 1, axis1 );
boxTest( root + 1, right, axis1 );
}
}
size_t WRMROIRepresentation::getLineForPoint( size_t point )
{
return ( *m_currentReverse )[point];
}
bool WRMROIRepresentation::isDirty()
{
return m_dirty;
}
void WRMROIRepresentation::setDirty()
{
m_dirty = true;
m_branch->setDirty();
}
void WRMROIRepresentation::slotToggleNot()
{
m_roi->setNot( m_isNot->get() );
m_roi->setActive( m_isActive->get() );
if ( m_isActive->get() )
{
m_roi->setNodeMask( 0xFFFFFFFF );
}
else
{
m_roi->setNodeMask( 0x0 );
}
setDirty();
}
void WRMROIRepresentation::slotChangeThreshold()
{
if ( osg::dynamic_pointer_cast< WROIArbitrary >( m_roi ).get() )
{
osg::dynamic_pointer_cast< WROIArbitrary >( m_roi ).get()->setThreshold( m_threshold->get() );
setDirty();
}
}
boost::shared_ptr< WProperties > WRMROIRepresentation::getProperties()
{
return m_properties;
......@@ -234,8 +215,3 @@ boost::shared_ptr< WRMBranch > WRMROIRepresentation::getBranch()
{
return m_branch;
}
bool WRMROIRepresentation::isActive()
{
return m_isActive->get();
}
......@@ -74,13 +74,6 @@ public:
boost::shared_ptr< std::vector< bool > > getBitField();
/**
* adds a bit field of a given size to the list of bit fields
*
* \param size
*/
void addBitField( size_t size );
/**
* updates the bit fields with the fibers selected by the associated roi
*/
void recalculate();
......@@ -90,7 +83,7 @@ public:
*
* \return dirty flag
*/
bool isDirty();
bool dirty();
/**
* sets dirty flag true and notifies the branch
......@@ -113,7 +106,7 @@ public:
*
* \return roi is active
*/
bool isActive();
bool active();
/**
* removes the graphical representation from the graphics engine
......@@ -123,14 +116,15 @@ public:
protected:
/**
* slot gets called when a property has changed
* initialize the properties
*/
void slotToggleNot();
void properties();
/**
* slot gets called when a property has changed
*/
void slotChangeThreshold();
void propertyChanged();
private:
/**
* tests the kd tree for intersections with the roi
......@@ -149,18 +143,21 @@ private:
bool m_dirty; //!< dirty flag, indicates the bit fields need updating
size_t m_size; //!< number of fibers in the dataset
osg::ref_ptr< WROI > m_roi; //!< stores a pointer to the associated roi
boost::shared_ptr< WRMBranch > m_branch; //!< stores a pointer to the branch this roi belongs to
boost::shared_ptr< std::vector<bool> >m_bitField; //!< list of bit fields, one for each loaded
// fiber dataset
/**
* pointer to the bitfield that represents the current selection by the roi
*/
boost::shared_ptr< std::vector<bool> >m_outputBitfield;
/**
* pointer to the bitfield, that is currently updated
* this is used for the recursive update function, to reduce the amount of function parameters
* pointer to the bitfield we work on
*/
boost::shared_ptr< std::vector<bool> >m_currentBitfield;
boost::shared_ptr< std::vector<bool> >m_workerBitfield;
/**
* pointer to the array that is used for updating
......@@ -205,4 +202,19 @@ private:
WPropBool m_isActive;
};
inline bool WRMROIRepresentation::dirty()
{
return m_dirty;
}
inline bool WRMROIRepresentation::active()
{
return m_isActive->get();
}
inline size_t WRMROIRepresentation::getLineForPoint( size_t point )
{
return ( *m_currentReverse )[point];
}
#endif // WRMROIREPRESENTATION_H
......@@ -30,10 +30,9 @@
#include "WROIManagerFibers.h"
#include "../../../graphicsEngine/WROIBox.h"
WROIManagerFibers::WROIManagerFibers()
WROIManagerFibers::WROIManagerFibers() :
m_recalcLock( false )
{
m_activeBitField = 0;
m_recalcLock = false;
}
WROIManagerFibers::~WROIManagerFibers()
......@@ -44,21 +43,18 @@ boost::shared_ptr< WRMROIRepresentation > WROIManagerFibers::addRoi( osg::ref_pt
{
// create new branch
boost::shared_ptr< WRMBranch > newBranch = boost::shared_ptr< WRMBranch >( new WRMBranch( shared_from_this() ) );
// add branch to list
m_branches.push_back( newBranch );
// create roi
boost::shared_ptr< WRMROIRepresentation > rroi = boost::shared_ptr< WRMROIRepresentation >( new WRMROIRepresentation( newRoi, newBranch ) );
// add roi to branch
newBranch->addRoi( rroi );
// add branch to list
m_branches.push_back( newBranch );
// add bit fields
newBranch->addBitField( m_fibers.get()->size() );
for ( std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > >::iterator iter = m_addNotifiers.begin();
iter != m_addNotifiers.end(); ++iter )
{
( *iter )( rroi );
}
return rroi;
}