28 #include <boost/regex.hpp>
29 #include <boost/tokenizer.hpp>
31 #include <osgGA/TrackballManipulator>
33 #include "../common/WLogger.h"
34 #include "../common/WStringUtils.h"
35 #include "../kernel/WProjectFile.h"
36 #include "WGECamera.h"
37 #include "WGEProjectFileIO.h"
38 #include "WGEViewer.h"
39 #include "WGraphicsEngine.h"
58 p->setProject( project );
70 double* parseDoubleSequence( std::string seq,
unsigned int size )
74 typedef boost::tokenizer<boost::char_separator< char > > tokenizer;
75 boost::char_separator< char > sep(
";" );
76 tokenizer tok( seq, sep );
79 double* values =
new double[ size ];
81 for( tokenizer::iterator it = tok.begin(); ( it != tok.end() ) && ( i < size ); ++it )
83 values[ i ] = string_utils::fromString< double >( ( *it ) );
98 double* parseMatrix( std::string matrix )
100 return parseDoubleSequence( matrix, 16 );
110 double* parseVector( std::string vec )
112 return parseDoubleSequence( vec, 3 );
118 static const boost::regex camRe(
"^ *CAMERA:([0-9]*):(.*)$" );
119 static const boost::regex matrixRe(
"^ *MANIPULATOR:\\(([0-9]*),Matrix\\)=(.*)$" );
120 static const boost::regex homeEyeRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeEye\\)=(.*)$" );
121 static const boost::regex homeCenterRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeCenter\\)=(.*)$" );
122 static const boost::regex homeUpRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeUp\\)=(.*)$" );
125 boost::smatch matches;
126 if( boost::regex_match( line, matches, camRe ) )
131 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera \"" << matches[2] <<
"\" with ID " << matches[1];
134 m_cameras[ string_utils::fromString< unsigned int >( matches[1] ) ] = matches[2];
138 else if( boost::regex_match( line, matches, matrixRe ) )
143 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Matrix with ID " << matches[1];
151 else if( boost::regex_match( line, matches, homeEyeRe ) )
157 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Eye Point with ID " << matches[1];
161 m_homeEyeVectors[ string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
165 else if( boost::regex_match( line, matches, homeCenterRe ) )
171 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Center Point with ID " << matches[1];
175 m_homeCenterVectors[ string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
179 else if( boost::regex_match( line, matches, homeUpRe ) )
185 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Up Point with ID " << matches[1];
189 m_homeUpVectors[string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
200 for( CameraList::const_iterator iter =
m_cameras.begin(); iter !=
m_cameras.end(); ++iter )
206 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but the corresponding view does " <<
207 "not exist. Ignoring.";
217 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but no proper manipulator home " <<
218 "position. Leaving current home untouched.";
222 view->getCameraManipulator()->setHomePosition(
m_homeEyeVectors[ ( *iter ).first ],
228 osg::ref_ptr<osgGA::TrackballManipulator> cm = osg::dynamic_pointer_cast<osgGA::TrackballManipulator>( view->getCameraManipulator() );
238 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but no proper manipulator matrix. " <<
239 "Leaving current matrix untouched.";
250 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
251 "// Camera definitions" << std::endl <<
252 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
259 output <<
"CAMERA:0:" << name << std::endl;
265 osg::Matrixd view = mani->getMatrix();
267 output <<
"//Camera Matrices: \"" << name <<
"\"" << std::endl;
268 output <<
" MANIPULATOR:(0,Matrix)=";
269 for(
unsigned int i = 0; i < 16; ++i )
271 output << view.ptr()[i];
283 mani->getHomePosition( eye, center, up );
288 output <<
" MANIPULATOR:(0,HomeEye)=";
289 output << eye.x() <<
";" << eye.y() <<
";" << eye.z() << std::endl;
290 output <<
" MANIPULATOR:(0,HomeCenter)=";
291 output << center.x() <<
";" << center.y() <<
";" << center.z() << std::endl;
292 output <<
" MANIPULATOR:(0,HomeUp)=";
293 output << up.x() <<
";" << up.y() <<
";" << up.z() << std::endl;
295 output <<
"//Camera Matrices END: \"" << name <<
"\"" << std::endl;
std::map< unsigned int, osg::Matrixd > m_manipulatorMatrices
All view's manipulator matrices.
std::map< unsigned int, osg::Vec3d > m_homeCenterVectors
The home position center point.
WGEProjectFileIO()
Default constructor.
virtual ~WGEProjectFileIO()
Destructor.
std::map< unsigned int, osg::Vec3d > m_homeEyeVectors
The home position eye point.
virtual void done()
Called whenever the end of the project file has been reached.
virtual SPtr clone(WProjectFile *project) const
Create a clone of the IO.
virtual bool parse(std::string line, unsigned int lineNumber)
This method parses the specified line and interprets it.
std::map< unsigned int, osg::Vec3d > m_homeUpVectors
The home position up vector.
virtual void save(std::ostream &output)
Saves the state to the specified stream.
CameraList m_cameras
Camera map.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
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.
Class loading project files.
std::string toString(const T &value)
Convert a given value to a string.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
WStreamedLogger warn(const std::string &source)
Logging a warning message.