Commit 2671a30e authored by schurade's avatar schurade
Browse files

[ADD] allow deleting of rois

parent 07c10bdd
......@@ -26,6 +26,11 @@
#include "WPickHandler.h"
WROI::WROI() :
osg::Geode()
{
}
WROI::~WROI()
{
}
......
......@@ -39,9 +39,11 @@ class WPickHandler;
/**
* Superclass for different ROI (region of interest) types.
*/
class WROI
class WROI : public osg::Geode
{
public:
WROI();
/**
* Need virtual destructor because of virtual function.
*/
......@@ -70,7 +72,7 @@ public:
protected:
osg::ref_ptr< WPickHandler > m_pickHandler; //!< A pointer to the pick handler used to get gui events for moving the box.
osg::ref_ptr< osg::Geode> m_geode; //!< The graphical representation of the ROI.
bool m_isModified; //!< Indicates whether a changed ROI has already taken effect. Means: if true, still some updates needed.
/**
......
......@@ -129,11 +129,11 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
m_surfaceGeometry = osg::ref_ptr<osg::Geometry>( new osg::Geometry() );
m_surfaceGeometry->setDataVariance( osg::Object::DYNAMIC );
m_geode = osg::ref_ptr<osg::Geode>( new osg::Geode );
//m_geode = osg::ref_ptr<osg::Geode>( new osg::Geode );
std::stringstream ss;
ss << "ROIBox" << boxId;
m_geode->setName( ss.str() );
setName( ss.str() );
m_surfaceGeometry->setName( ss.str() );
osg::ref_ptr<osg::Vec3Array> vertices = osg::ref_ptr<osg::Vec3Array>( new osg::Vec3Array );
......@@ -150,8 +150,8 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
m_surfaceGeometry->addPrimitiveSet( surfaceElements );
m_surfaceGeometry->addPrimitiveSet( lineElements );
m_geode->addDrawable( m_surfaceGeometry );
osg::StateSet* state = m_geode->getOrCreateStateSet();
addDrawable( m_surfaceGeometry );
osg::StateSet* state = getOrCreateStateSet();
state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
osg::LineWidth* linewidth = new osg::LineWidth();
......@@ -175,10 +175,18 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
m_isNot = false;
assert( WGraphicsEngine::getGraphicsEngine() );
WGraphicsEngine::getGraphicsEngine()->getScene()->addChild( m_geode );
WGraphicsEngine::getGraphicsEngine()->getScene()->addChild( this );
m_geode->setUserData( this );
m_geode->setUpdateCallback( new ROIBoxNodeCallback );
setUserData( this );
setUpdateCallback( osg::ref_ptr<ROIBoxNodeCallback>( new ROIBoxNodeCallback ) );
}
WROIBox::~WROIBox()
{
// std::cout << "destructor called" << std::endl;
// std::cout << "ref count geode: " << m_geode->referenceCount() << std::endl;
//
// WGraphicsEngine::getGraphicsEngine()->getScene()->remove( m_geode );
}
wmath::WPosition WROIBox::getMinPos() const
......
......@@ -39,7 +39,7 @@
/**
* A box representing a region of interest.
*/
class WROIBox : public WROI, public osg::Referenced
class WROIBox : public WROI
{
public:
/**
......@@ -49,6 +49,8 @@ public:
*/
WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos );
virtual ~WROIBox();
/**
* Get the corner of the box that has minimal x, y and z values
*/
......
......@@ -607,16 +607,16 @@ void WMainWindow::newRoi()
return;
}
if ( m_datasetBrowser->getSelectedRoi().get() == NULL )
if ( m_datasetBrowser->getFirstRoiInSelectedBranch().get() == NULL )
{
boost::shared_ptr< WROIBox > newRoi = boost::shared_ptr< WROIBox >( new WROIBox( wmath::WPosition( 60., 60., 60. ),
osg::ref_ptr< WROIBox > newRoi = osg::ref_ptr< WROIBox >( new WROIBox( wmath::WPosition( 60., 60., 60. ),
wmath::WPosition( 80., 80., 80. ) ) );
WKernel::getRunningKernel()->getRoiManager()->addRoi( newRoi );
}
else
{
boost::shared_ptr< WROIBox > newRoi = boost::shared_ptr< WROIBox >( new WROIBox( wmath::WPosition( 60., 60., 60. ),
osg::ref_ptr< WROIBox > newRoi = osg::ref_ptr< WROIBox >( new WROIBox( wmath::WPosition( 60., 60., 60. ),
wmath::WPosition( 80., 80., 80. ) ) );
WKernel::getRunningKernel()->getRoiManager()->addRoi( newRoi, m_datasetBrowser->getSelectedRoi()->getROI() );
WKernel::getRunningKernel()->getRoiManager()->addRoi( newRoi, m_datasetBrowser->getFirstRoiInSelectedBranch()->getROI() );
}
}
//---------------------------------------------------------------------------
//
// 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 "WTreeItemTypes.h"
#include "WQtRoiTreeItem.h"
#include "WQtBranchTreeItem.h"
WQtBranchTreeItem::WQtBranchTreeItem( QTreeWidgetItem * parent ) :
QTreeWidgetItem( parent, ROIBRANCH )
{
}
WQtBranchTreeItem::~WQtBranchTreeItem()
{
}
WQtRoiTreeItem* WQtBranchTreeItem::addRoiItem( boost::shared_ptr< WRMROIRepresentation > roi )
{
WQtRoiTreeItem* rti = new WQtRoiTreeItem( this, roi, ROI );
std::string name = "ROI";
rti->setText( 0, QString( name.c_str() ) );
return rti;
}
//---------------------------------------------------------------------------
//
// 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 WQTBRANCHTREEITEM_H
#define WQTBRANCHTREEITEM_H
#include <QtCore/QTimer>
#include <QtGui/QProgressBar>
#include <QtGui/QTreeWidgetItem>
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
#include "WQtTreeItem.h"
class WQtRoiTreeItem;
/**
* This class represents a roi branch in the tree widget
*/
class WQtBranchTreeItem : public QTreeWidgetItem
{
public:
/**
* default constructor
*
* \param parent
*/
explicit WQtBranchTreeItem( QTreeWidgetItem * parent );
/**
* destructor
*/
~WQtBranchTreeItem();
/**
* Add a roi to the tree view.
* \param roi The new roi.
*/
WQtRoiTreeItem* addRoiItem( boost::shared_ptr< WRMROIRepresentation > roi );
protected:
private:
};
#endif // WQTBRANCHTREEITEM_H
......@@ -30,6 +30,7 @@
#include <QtCore/QList>
#include <QtGui/QScrollArea>
#include <QtGui/QShortcut>
#include "../../../common/WLogger.h"
#include "../../../common/WPreferences.h"
......@@ -44,6 +45,7 @@
#include "WQtNumberEdit.h"
#include "WQtNumberEditDouble.h"
#include "WQtTextureSorter.h"
#include "WQtBranchTreeItem.h"
#include "../../../kernel/WModuleFactory.h"
#include "../WMainWindow.h"
......@@ -92,6 +94,9 @@ WQtDatasetBrowser::WQtDatasetBrowser( WMainWindow* parent )
// preset for toolbar text.
m_showToolBarText = true;
WPreferences::getPreference( "qt4gui.toolBarIconText", &m_showToolBarText );
QShortcut* shortcut = new QShortcut( QKeySequence( Qt::Key_Delete ), m_treeWidget );
connect( shortcut, SIGNAL( activated() ), this, SLOT( deleteTreeItem() ) );
}
WQtDatasetBrowser::~WQtDatasetBrowser()
......@@ -233,26 +238,28 @@ void WQtDatasetBrowser::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
{
case ROI :
{
WQtRoiTreeItem* roiItem =( static_cast< WQtRoiTreeItem* >( m_treeWidget->selectedItems().at( 0 ) ) );
WQtBranchTreeItem* branchItem =( static_cast< WQtBranchTreeItem* >( m_treeWidget->selectedItems().at( 0 )->parent() ) );
m_tiRois->setExpanded( true );
roiItem->setExpanded( true );
WQtRoiTreeItem* item = roiItem->addRoiItem( roi );
branchItem->setExpanded( true );
WQtRoiTreeItem* item = branchItem->addRoiItem( roi );
item->setDisabled( false );
break;
}
case SUBROI :
case ROIBRANCH :
{
WQtRoiTreeItem* roiItem =( static_cast< WQtRoiTreeItem* >( m_treeWidget->selectedItems().at( 0 )->parent() ) );
WQtBranchTreeItem* branchItem =( static_cast< WQtBranchTreeItem* >( m_treeWidget->selectedItems().at( 0 ) ) );
m_tiRois->setExpanded( true );
roiItem->setExpanded( true );
WQtRoiTreeItem* item = roiItem->addRoiItem( roi );
branchItem->setExpanded( true );
WQtRoiTreeItem* item = branchItem->addRoiItem( roi );
item->setDisabled( false );
break;
}
default:
{
m_tiRois->setExpanded( true );
WQtRoiTreeItem* item = m_tiRois->addRoiItem( roi );
WQtBranchTreeItem* newBranch = m_tiRois->addBranch();
newBranch->setExpanded( true );
WQtRoiTreeItem* item = newBranch->addRoiItem( roi );
item->setDisabled( false );
break;
}
......@@ -261,7 +268,9 @@ void WQtDatasetBrowser::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
else
{
m_tiRois->setExpanded( true );
WQtRoiTreeItem* item = m_tiRois->addRoiItem( roi );
WQtBranchTreeItem* newBranch = m_tiRois->addBranch();
newBranch->setExpanded( true );
WQtRoiTreeItem* item = newBranch->addRoiItem( roi );
item->setDisabled( false );
}
}
......@@ -309,8 +318,9 @@ void WQtDatasetBrowser::selectTreeItem()
break;
case ROIHEADER:
break;
case ROIBRANCH:
break;
case ROI:
case SUBROI:
props = ( static_cast< WQtRoiTreeItem* >( m_treeWidget->selectedItems().at( 0 ) ) )->getRoi()->getProperties();
break;
default:
......@@ -449,9 +459,58 @@ boost::shared_ptr< WRMROIRepresentation > WQtDatasetBrowser::getSelectedRoi()
{
roi =( static_cast< WQtRoiTreeItem* >( m_treeWidget->selectedItems().at( 0 ) ) )->getRoi();
}
if ( m_treeWidget->selectedItems().at( 0 )->type() == SUBROI )
return roi;
}
boost::shared_ptr< WRMROIRepresentation > WQtDatasetBrowser::getFirstRoiInSelectedBranch()
{
boost::shared_ptr< WRMROIRepresentation >roi;
if ( m_treeWidget->selectedItems().count() == 0 )
{
roi =( static_cast< WQtRoiTreeItem* >( m_treeWidget->selectedItems().at( 0 )->parent() ) )->getRoi();
return roi;
}
if ( m_treeWidget->selectedItems().at( 0 )->type() == ROI )
{
WQtBranchTreeItem* branch = ( static_cast< WQtBranchTreeItem* >( m_treeWidget->selectedItems().at( 0 )->parent() ) );
roi =( static_cast< WQtRoiTreeItem* >( branch->child( 0 ) ) )->getRoi();
}
if ( m_treeWidget->selectedItems().at( 0 )->type() == ROIBRANCH )
{
WQtBranchTreeItem* branch = ( static_cast< WQtBranchTreeItem* >( m_treeWidget->selectedItems().at( 0 ) ) );
if ( branch->childCount() > 0 )
{
roi =( static_cast< WQtRoiTreeItem* >( branch->child( 0 ) ) )->getRoi();
}
}
return roi;
}
void WQtDatasetBrowser::deleteTreeItem()
{
boost::shared_ptr< WRMROIRepresentation >roi;
if ( m_treeWidget->selectedItems().at( 0 )->type() == ROIBRANCH )
{
roi = getFirstRoiInSelectedBranch();
if ( roi )
{
WKernel::getRunningKernel()->getRoiManager()->removeBranch( roi );
}
delete m_treeWidget->selectedItems().at( 0 );
}
else if ( m_treeWidget->selectedItems().at( 0 )->type() == ROI )
{
roi =( static_cast< WQtRoiTreeItem* >( m_treeWidget->selectedItems().at( 0 ) ) )->getRoi();
WQtBranchTreeItem* branch = ( static_cast< WQtBranchTreeItem* >( m_treeWidget->selectedItems().at( 0 )->parent() ) );
if ( roi )
{
delete m_treeWidget->selectedItems().at( 0 );
WKernel::getRunningKernel()->getRoiManager()->removeRoi( roi );
}
if ( branch->childCount() == 0 )
{
delete branch;
}
}
}
......@@ -129,6 +129,13 @@ public:
*/
boost::shared_ptr< WRMROIRepresentation > getSelectedRoi();
/**
* Returns the first roi in the currently selected branch.
*
* \return pointer to roi representation
*/
boost::shared_ptr< WRMROIRepresentation > getFirstRoiInSelectedBranch();
protected:
/**
......@@ -197,6 +204,11 @@ private slots:
*/
void moveTreeItemUp();
/**
* delete a tree item
*/
void deleteTreeItem();
signals:
/**
......
......@@ -38,11 +38,10 @@ WQtRoiHeaderTreeItem::~WQtRoiHeaderTreeItem()
{
}
WQtRoiTreeItem* WQtRoiHeaderTreeItem::addRoiItem( boost::shared_ptr< WRMROIRepresentation > roi )
WQtBranchTreeItem* WQtRoiHeaderTreeItem::addBranch()
{
WQtRoiTreeItem* rti = new WQtRoiTreeItem( this, roi );
std::string name = "ROI";
WQtBranchTreeItem* rti = new WQtBranchTreeItem( this );
std::string name = "Branch";
rti->setText( 0, QString( name.c_str() ) );
return rti;
}
......@@ -29,6 +29,7 @@
#include <QtGui/QTreeWidgetItem>
#include "WQtBranchTreeItem.h"
#include "WQtRoiTreeItem.h"
/**
......@@ -50,10 +51,10 @@ public:
virtual ~WQtRoiHeaderTreeItem();
/**
* Add a roi to the tree view.
* \param roi The new roi.
* Add new branch to the tree view.
*/
WQtRoiTreeItem* addRoiItem( boost::shared_ptr< WRMROIRepresentation > roi );
WQtBranchTreeItem* addBranch();
protected:
private:
......
......@@ -41,12 +41,3 @@ boost::shared_ptr< WRMROIRepresentation > WQtRoiTreeItem::getRoi()
{
return m_roi;
}
WQtRoiTreeItem* WQtRoiTreeItem::addRoiItem( boost::shared_ptr< WRMROIRepresentation > roi )
{
WQtRoiTreeItem* rti = new WQtRoiTreeItem( this, roi, SUBROI );
std::string name = "ROI";
rti->setText( 0, QString( name.c_str() ) );
return rti;
}
......@@ -59,13 +59,6 @@ public:
*/
boost::shared_ptr< WRMROIRepresentation > getRoi();
/**
* Add a roi to the tree view.
* \param roi The new roi.
*/
WQtRoiTreeItem* addRoiItem( boost::shared_ptr< WRMROIRepresentation > roi );
protected:
private:
boost::shared_ptr< WRMROIRepresentation > m_roi; //!< roi
......
......@@ -24,6 +24,7 @@
#include "WQtTreeWidget.h"
#include "WQtSubjectTreeItem.h"
#include <QtGui/QKeyEvent>
WQtTreeWidget::WQtTreeWidget( QWidget* parent )
: QTreeWidget( parent )
......@@ -76,3 +77,8 @@ void WQtTreeWidget::moveTreeItemUp()
}
}
}
//void WQtTreeWidget::keyPressEvent(QKeyEvent *e)
//{
// std::cout << "key pressed: " << e->key() << std::endl;
//}
......@@ -56,6 +56,10 @@ public slots:
* change order of items, move currently selected item up
*/
void moveTreeItemUp();
//void keyPressEvent(QKeyEvent *e);
protected:
private:
};
......
......@@ -33,8 +33,8 @@ typedef enum
MODULEHEADER,
MODULE,
ROIHEADER,
ROI,
SUBROI
ROIBRANCH,
ROI
}
WTreeItemType;
......
......@@ -45,6 +45,24 @@ void WRMBranch::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
m_rois.push_back( roi );
}
void WRMBranch::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi )
{
for( std::list< boost::shared_ptr< WRMROIRepresentation > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{
if ( ( *iter ) == roi )
{
m_rois.erase( iter );
setDirty();
break;
}
}
}
void WRMBranch::removeAllRois()
{
m_rois.clear();
}
boost::shared_ptr< std::vector< bool > > WRMBranch::getBitField()
{
if ( m_dirty )
......@@ -127,3 +145,8 @@ boost::shared_ptr< WROIManagerFibers > WRMBranch::getRoiManager()
{
return m_roiManager;
}
bool WRMBranch::isEmpty()
{
return m_rois.empty();
}
......@@ -59,6 +59,21 @@ public:
*/
void addRoi( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* removes a roi from the branch
*
* \param roi
*/
void removeRoi( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* removes all rois from the branch
*
*/
void removeAllRois();
/**
* getter for the bitfield
*
......@@ -90,6 +105,11 @@ public:
*/
void setDirty();
/**
* returns whether the branch is empty
*/
bool isEmpty();
/**
* returns a pointer to the first roi in the branch
*
......
......@@ -29,13 +29,14 @@
#include "WRMBranch.h"
#include "WROIManagerFibers.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../graphicsEngine/WROIBox.h"
#include "WRMROIRepresentation.h"
WRMROIRepresentation::WRMROIRepresentation( boost::shared_ptr< WROI > roi, boost::shared_ptr< WRMBranch > branch ) :
WRMROIRepresentation::WRMROIRepresentation( osg::ref_ptr< WROI > roi, boost::shared_ptr< WRMBranch > branch ) :
m_roi( roi ),
m_branch( branch )
{
......@@ -47,9 +48,10 @@ WRMROIRepresentation::WRMROIRepresentation( boost::shared_ptr< WROI > roi, boost
WRMROIRepresentation::~WRMROIRepresentation()
{
WGraphicsEngine::getGraphicsEngine()->getScene()->remove( m_roi );
}