30 #include <boost/regex.hpp>
32 #include "../common/WLogger.h"
33 #include "../common/WProperties.h"
34 #include "../common/WPropertyBase.h"
35 #include "../common/WPropertyTypes.h"
36 #include "../common/WPropertyVariable.h"
37 #include "../common/WStringUtils.h"
38 #include "../common/exceptions/WFileNotFound.h"
39 #include "../graphicsEngine/WROI.h"
40 #include "../graphicsEngine/WROIBox.h"
42 #include "WProjectFile.h"
43 #include "WROIManager.h"
44 #include "WRoiProjectFileIO.h"
61 p->setProject( project );
68 static const boost::regex branchRe(
"^ *SELECTOR_BRANCH:([0-9]*)$" );
69 static const boost::regex roiBoxRe(
"^ *SELECTOR_ROIBOX:([0-9]*):SELECTOR_BRANCH([0-9]*)$" );
70 static const boost::regex branchPropRe(
"^ *PROPERTY:\\(SELECTOR_BRANCH([0-9]*),(.*)\\)=(.*)$" );
71 static const boost::regex roiBoxPropRe(
"^ *PROPERTY:\\(SELECTOR_ROIBOX([0-9]*),(.*)\\)=(.*)$" );
73 boost::smatch matches;
74 if( boost::regex_match( line, matches, branchRe ) )
76 Branch branch = string_utils::fromString< Branch >( matches[1] );
77 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Branch with ID " << branch;
82 else if( boost::regex_match( line, matches, roiBoxRe ) )
84 Branch parentBranch = string_utils::fromString< Branch >( matches[2] );
85 RoiID roiID = string_utils::fromString< RoiID >( matches[1] );
86 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": ROI with ID " << roiID <<
" in Branch " << parentBranch;
89 m_rois.push_back(
Roi( roiID, parentBranch ) );
91 else if( boost::regex_match( line, matches, branchPropRe ) )
93 Branch branch = string_utils::fromString< Branch >( matches[1] );
94 std::string prop = matches[2];
95 std::string propValue = matches[3];
96 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Property \"" << prop <<
"\" of Branch " << branch
97 <<
" set to " << propValue;
101 else if( boost::regex_match( line, matches, roiBoxPropRe ) )
103 RoiID roiID = string_utils::fromString< RoiID >( matches[1] );
104 std::string prop = matches[2];
105 std::string propValue = matches[3];
106 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Property \"" << prop <<
"\" of ROI " << roiID
107 <<
" set to " << propValue;
124 std::map< Branch, std::shared_ptr< WRMBranch > > branches;
128 std::shared_ptr< WRMBranch > branch = rm->addBranch();
129 branches[ *i ] = branch;
135 std::string name = ( *propI ).get< 0 >();
136 std::string value = ( *propI ).get< 1 >();
141 prop->setAsString( value );
145 addError(
"The ROI does not have a property named \"" + name +
"\". Skipping." );
151 for( std::vector< Roi >::const_iterator i =
m_rois.begin(); i !=
m_rois.end(); ++i )
154 std::shared_ptr< WRMBranch > branch = branches[ ( *i ).get< 1 >() ];
158 rm->addRoi( roi, branch );
164 std::string name = ( *propI ).get< 0 >();
165 std::string value = ( *propI ).get< 1 >();
170 prop->setAsString( value );
174 addError(
"The ROI does not have a property named \"" + name +
"\". Skipping." );
189 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
190 "// ROI Structure" << std::endl <<
191 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
196 unsigned int branchIndex = 0;
197 unsigned int roiIndex = 0;
198 for( WROIManager::Branches::const_iterator branchIter = branches.begin(); branchIter != branches.end(); ++branchIter )
204 output <<
"SELECTOR_BRANCH:" << branchIndex << std::endl;
205 printProperties( output, branch->getProperties(),
"",
"", branchIndex,
"SELECTOR_BRANCH" );
210 for( WROIManager::ROIs::const_iterator roiIter = rois.begin(); roiIter != rois.end(); ++roiIter )
215 output <<
"SELECTOR_ROIBOX:" << roiIndex <<
":SELECTOR_BRANCH" << branchIndex << std::endl;
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WROIManager > getRoiManager()
get for roi manager
This only is a 3d double vector.
A base class for all parts of OpenWalnut which can be serialized to a project file.
std::shared_ptr< WProjectFileIO > SPtr
Abbreviation for a shared pointer.
void addError(std::string description)
Add an error.
void printProperties(std::ostream &output, std::shared_ptr< WProperties > props, std::string indent, std::string prefix, unsigned int index, std::string indexPrefix="")
Recursively prints the properties and nested properties.
Class loading project files.
std::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyBase >
std::shared_ptr< WRMBranch > SPtr
Convenience type for a shared pointer of this type.
A box representing a region of interest.
std::vector< std::shared_ptr< WRMBranch > > Branches
Branches list.
std::vector< osg::ref_ptr< WROI > > ROIs
ROI list.
std::shared_ptr< WProperties > getProperties()
Getter.
unsigned int Branch
Branch by ID.
WRoiProjectFileIO()
Default constructor.
virtual void save(std::ostream &output)
Saves the state to the specified stream.
virtual SPtr clone(WProjectFile *project) const
Create a clone of the IO.
boost::tuple< std::string, std::string > Property
Property for branch/roi with ID.
std::map< Branch, Properties > m_branchProperties
Properties of each branch.
boost::tuple< RoiID, Branch > Roi
ROI by ID, second is parent branch ID.
virtual bool parse(std::string line, unsigned int lineNumber)
This method parses the specified line and interprets it.
virtual ~WRoiProjectFileIO()
Destructor.
unsigned int RoiID
ID of a ROI.
virtual void done()
Called whenever the end of the project file has been reached.
std::vector< Roi > m_rois
All loaded rois.
std::vector< Branch > m_branches
All loaded branch IDs.
std::map< RoiID, Properties > m_roiProperties
Properties of each branch.
WStreamedLogger debug(const std::string &source)
Logging a debug message.