27 #include <boost/regex.hpp>
28 #include <boost/tokenizer.hpp>
32 #include "../common/WLogger.h"
33 #include "../common/WStringUtils.h"
35 #include "WGraphicsEngine.h"
36 #include "WGEViewer.h"
38 #include "WGEProjectFileIO.h"
59 double* parseDoubleSequence( std::string seq,
unsigned int size )
63 typedef boost::tokenizer<boost::char_separator< char > > tokenizer;
64 boost::char_separator< char > sep(
";" );
65 tokenizer tok( seq, sep );
68 double* values =
new double[ size ];
70 for( tokenizer::iterator it = tok.begin(); ( it != tok.end() ) && ( i < size ); ++it )
72 values[ i ] = string_utils::fromString< double >( ( *it ) );
87 double* parseMatrix( std::string matrix )
89 return parseDoubleSequence( matrix, 16 );
99 double* parseVector( std::string vec )
101 return parseDoubleSequence( vec, 3 );
107 static const boost::regex camRe(
"^ *CAMERA:([0-9]*):(.*)$" );
108 static const boost::regex matrixRe(
"^ *MANIPULATOR:\\(([0-9]*),Matrix\\)=(.*)$" );
109 static const boost::regex homeEyeRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeEye\\)=(.*)$" );
110 static const boost::regex homeCenterRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeCenter\\)=(.*)$" );
111 static const boost::regex homeUpRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeUp\\)=(.*)$" );
114 boost::smatch matches;
115 if( boost::regex_match( line, matches, camRe ) )
120 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera \"" << matches[2] <<
"\" with ID " << matches[1];
123 m_cameras[ string_utils::fromString< unsigned int >( matches[1] ) ] = matches[2];
127 else if( boost::regex_match( line, matches, matrixRe ) )
132 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Matrix with ID " << matches[1];
140 else if( boost::regex_match( line, matches, homeEyeRe ) )
146 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Eye Point with ID " << matches[1];
150 m_homeEyeVectors[ string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
154 else if( boost::regex_match( line, matches, homeCenterRe ) )
160 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Center Point with ID " << matches[1];
164 m_homeCenterVectors[ string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
168 else if( boost::regex_match( line, matches, homeUpRe ) )
174 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Up Point with ID " << matches[1];
178 m_homeUpVectors[string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
189 for( CameraList::const_iterator iter =
m_cameras.begin(); iter !=
m_cameras.end(); ++iter )
195 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but the corresponding view does " <<
196 "not exist. Ignoring.";
202 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but no proper manipulator matrix. " <<
203 "Leaving current matrix untouched.";
216 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but no proper manipulator home " <<
217 "position. Leaving current home untouched.";
221 view->getCameraManipulator()->setHomePosition(
m_homeEyeVectors[ ( *iter ).first ],
231 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
232 "// Camera definitions" << std::endl <<
233 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
240 output <<
"CAMERA:0:" << name << std::endl;
246 osg::Matrixd view = mani->getMatrix();
248 output <<
"//Camera Matrices: \"" << name <<
"\"" << std::endl;
249 output <<
" MANIPULATOR:(0,Matrix)=";
250 for(
unsigned int i = 0; i < 16; ++i )
252 output << view.ptr()[i];
264 mani->getHomePosition( eye, center, up );
269 output <<
" MANIPULATOR:(0,HomeEye)=";
270 output << eye.x() <<
";" << eye.y() <<
";" << eye.z() << std::endl;
271 output <<
" MANIPULATOR:(0,HomeCenter)=";
272 output << center.x() <<
";" << center.y() <<
";" << center.z() << std::endl;
273 output <<
" MANIPULATOR:(0,HomeUp)=";
274 output << up.x() <<
";" << up.y() <<
";" << up.z() << std::endl;
276 output <<
"//Camera Matrices END: \"" << name <<
"\"" << std::endl;