Commit 6b3a4d08 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD #59] loading of rois now works.

parent fc75b437
...@@ -41,14 +41,10 @@ WROIManager::~WROIManager() ...@@ -41,14 +41,10 @@ WROIManager::~WROIManager()
{ {
} }
void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi ) void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi, boost::shared_ptr< WRMBranch > toBranch )
{ {
// 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 );
// add roi to branch // add roi to branch
newBranch->addRoi( newRoi ); toBranch->addRoi( newRoi );
for( std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > >::iterator iter = m_addNotifiers.begin(); for( std::list< boost::shared_ptr< boost::function< void( osg::ref_ptr< WROI > ) > > >::iterator iter = m_addNotifiers.begin();
iter != m_addNotifiers.end(); ++iter ) iter != m_addNotifiers.end(); ++iter )
...@@ -57,6 +53,22 @@ void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi ) ...@@ -57,6 +53,22 @@ void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi )
} }
} }
void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi )
{
addRoi( newRoi, addBranch() );
}
boost::shared_ptr< WRMBranch > WROIManager::addBranch()
{
// 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 );
// return
return newBranch;
}
void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi ) void WROIManager::addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi )
{ {
// find branch // find branch
......
...@@ -50,6 +50,13 @@ public: ...@@ -50,6 +50,13 @@ public:
*/ */
~WROIManager(); ~WROIManager();
/**
* Add a new branch.
*
* \return the new branch.
*/
boost::shared_ptr< WRMBranch > addBranch();
/** /**
* adds a new master ROI * adds a new master ROI
* *
...@@ -67,6 +74,14 @@ public: ...@@ -67,6 +74,14 @@ public:
*/ */
void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi ); void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
/**
* Add a ROI to a branch.
*
* \param newRoi the new ROI to add
* \param toBranch the branch to add the ROI to.
*/
void addRoi( osg::ref_ptr< WROI > newRoi, boost::shared_ptr< WRMBranch > toBranch );
/** /**
* removes a roi * removes a roi
* *
......
...@@ -85,7 +85,7 @@ bool WRoiProjectFileIO::parse( std::string line, unsigned int lineNumber ) ...@@ -85,7 +85,7 @@ bool WRoiProjectFileIO::parse( std::string line, unsigned int lineNumber )
wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Property \"" << prop << "\" of Branch " << branch wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Property \"" << prop << "\" of Branch " << branch
<< " set to " << propValue; << " set to " << propValue;
// store info // store info
m_branchProperties[ branch ] = Property( prop, propValue ); m_branchProperties[ branch ].push_back( Property( prop, propValue ) );
} }
else if( boost::regex_match( line, matches, roiBoxPropRe ) ) else if( boost::regex_match( line, matches, roiBoxPropRe ) )
{ {
...@@ -95,7 +95,7 @@ bool WRoiProjectFileIO::parse( std::string line, unsigned int lineNumber ) ...@@ -95,7 +95,7 @@ bool WRoiProjectFileIO::parse( std::string line, unsigned int lineNumber )
wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Property \"" << prop << "\" of ROI " << roiID wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Property \"" << prop << "\" of ROI " << roiID
<< " set to " << propValue; << " set to " << propValue;
// store info // store info
m_roiProperties[ roiID ] = Property( prop, propValue ); m_roiProperties[ roiID ].push_back( Property( prop, propValue ) );
} }
else else
{ {
...@@ -108,7 +108,62 @@ bool WRoiProjectFileIO::parse( std::string line, unsigned int lineNumber ) ...@@ -108,7 +108,62 @@ bool WRoiProjectFileIO::parse( std::string line, unsigned int lineNumber )
void WRoiProjectFileIO::done() void WRoiProjectFileIO::done()
{ {
// apply boost::shared_ptr< WROIManager> rm = WKernel::getRunningKernel()->getRoiManager();
std::map< Branch, boost::shared_ptr< WRMBranch > > branches;
// add all branches
for( std::vector< Branch >::const_iterator i = m_branches.begin(); i != m_branches.end(); ++i )
{
boost::shared_ptr< WRMBranch > branch = rm->addBranch();
branches[ *i ] = branch;
// set the properties
for( Properties::const_iterator propI = m_branchProperties[ *i ].begin(); propI != m_branchProperties[ *i ].end();
++propI )
{
std::string name = ( *propI ).get< 0 >();
std::string value = ( *propI ).get< 1 >();
WPropertyBase::SPtr prop = branch->getProperties()->findProperty( name );
if( prop )
{
prop->setAsString( value );
}
else
{
addError( "The ROI does not have a property named \"" + name + "\". Skipping." );
}
}
}
// add ROIs to the branches
for( std::vector< Roi >::const_iterator i = m_rois.begin(); i != m_rois.end(); ++i )
{
// get branch of this ROI
boost::shared_ptr< WRMBranch > branch = branches[ ( *i ).get< 1 >() ];
// add ROI to branch
osg::ref_ptr< WROI > roi( new WROIBox( WPosition(), WPosition() ) );
rm->addRoi( roi, branch );
// set the properties
for( Properties::const_iterator propI = m_roiProperties[ ( *i ).get< 0 >() ].begin(); propI != m_roiProperties[ ( *i ).get< 0 >() ].end();
++propI )
{
std::string name = ( *propI ).get< 0 >();
std::string value = ( *propI ).get< 1 >();
WPropertyBase::SPtr prop = roi->getProperties()->findProperty( name );
if( prop )
{
prop->setAsString( value );
}
else
{
addError( "The ROI does not have a property named \"" + name + "\". Skipping." );
}
}
}
// clear everything // clear everything
m_branches.clear(); m_branches.clear();
...@@ -128,6 +183,7 @@ void WRoiProjectFileIO::save( std::ostream& output ) // NOLINT ...@@ -128,6 +183,7 @@ void WRoiProjectFileIO::save( std::ostream& output ) // NOLINT
// write all branches // write all branches
WROIManager::Branches branches =WKernel::getRunningKernel()->getRoiManager()->getBranches(); WROIManager::Branches branches =WKernel::getRunningKernel()->getRoiManager()->getBranches();
unsigned int branchIndex = 0; unsigned int branchIndex = 0;
unsigned int roiIndex = 0;
for( WROIManager::Branches::const_iterator branchIter = branches.begin(); branchIter != branches.end(); ++branchIter ) for( WROIManager::Branches::const_iterator branchIter = branches.begin(); branchIter != branches.end(); ++branchIter )
{ {
// get the branch // get the branch
...@@ -140,7 +196,6 @@ void WRoiProjectFileIO::save( std::ostream& output ) // NOLINT ...@@ -140,7 +196,6 @@ void WRoiProjectFileIO::save( std::ostream& output ) // NOLINT
// handle this branch's ROIs // handle this branch's ROIs
WROIManager::ROIs rois = branch->getRois(); WROIManager::ROIs rois = branch->getRois();
unsigned int roiIndex = 0;
for( WROIManager::ROIs::const_iterator roiIter = rois.begin(); roiIter != rois.end(); ++roiIter ) for( WROIManager::ROIs::const_iterator roiIter = rois.begin(); roiIter != rois.end(); ++roiIter )
{ {
// differentiate the type of roi, currently we will support only WROiBox // differentiate the type of roi, currently we will support only WROiBox
......
...@@ -84,6 +84,11 @@ private: ...@@ -84,6 +84,11 @@ private:
*/ */
typedef boost::tuple< std::string, std::string > Property; typedef boost::tuple< std::string, std::string > Property;
/**
* The properties as vector.
*/
typedef std::vector< Property > Properties;
/** /**
* All loaded branch IDs * All loaded branch IDs
*/ */
...@@ -92,7 +97,7 @@ private: ...@@ -92,7 +97,7 @@ private:
/** /**
* Properties of each branch * Properties of each branch
*/ */
std::map< Branch, Property > m_branchProperties; std::map< Branch, Properties > m_branchProperties;
/** /**
* ID of a ROI * ID of a ROI
...@@ -112,7 +117,7 @@ private: ...@@ -112,7 +117,7 @@ private:
/** /**
* Properties of each branch * Properties of each branch
*/ */
std::map< RoiID, Property > m_roiProperties; std::map< RoiID, Properties > m_roiProperties;
}; };
#endif // WROIPROJECTFILEIO_H #endif // WROIPROJECTFILEIO_H
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment