27 #include <boost/regex.hpp>
28 #include <boost/tokenizer.hpp>
32 #include "../common/WLogger.h"
33 #include "../common/WStringUtils.h"
34 #include "../kernel/WProjectFile.h"
36 #include "WGraphicsEngine.h"
37 #include "WGEViewer.h"
38 #include "WGECamera.h"
40 #include "WGEProjectFileIO.h"
57 p->setProject( project );
69 double* parseDoubleSequence( std::string seq,
unsigned int size )
73 typedef boost::tokenizer<boost::char_separator< char > > tokenizer;
74 boost::char_separator< char > sep(
";" );
75 tokenizer tok( seq, sep );
78 double* values =
new double[ size ];
80 for( tokenizer::iterator it = tok.begin(); ( it != tok.end() ) && ( i < size ); ++it )
82 values[ i ] = string_utils::fromString< double >( ( *it ) );
97 double* parseMatrix( std::string matrix )
99 return parseDoubleSequence( matrix, 16 );
109 double* parseVector( std::string vec )
111 return parseDoubleSequence( vec, 3 );
117 static const boost::regex camRe(
"^ *CAMERA:([0-9]*):(.*)$" );
118 static const boost::regex matrixRe(
"^ *MANIPULATOR:\\(([0-9]*),Matrix\\)=(.*)$" );
119 static const boost::regex homeEyeRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeEye\\)=(.*)$" );
120 static const boost::regex homeCenterRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeCenter\\)=(.*)$" );
121 static const boost::regex homeUpRe(
"^ *MANIPULATOR:\\(([0-9]*),HomeUp\\)=(.*)$" );
124 boost::smatch matches;
125 if( boost::regex_match( line, matches, camRe ) )
130 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera \"" << matches[2] <<
"\" with ID " << matches[1];
133 m_cameras[ string_utils::fromString< unsigned int >( matches[1] ) ] = matches[2];
137 else if( boost::regex_match( line, matches, matrixRe ) )
142 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Matrix with ID " << matches[1];
150 else if( boost::regex_match( line, matches, homeEyeRe ) )
156 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Eye Point with ID " << matches[1];
160 m_homeEyeVectors[ string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
164 else if( boost::regex_match( line, matches, homeCenterRe ) )
170 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Center Point with ID " << matches[1];
174 m_homeCenterVectors[ string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
178 else if( boost::regex_match( line, matches, homeUpRe ) )
184 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Camera Manipulator Home Up Point with ID " << matches[1];
188 m_homeUpVectors[string_utils::fromString< unsigned int >( matches[1] ) ] = osg::Vec3d( vals[0], vals[1], vals[2] );
199 for( CameraList::const_iterator iter =
m_cameras.begin(); iter !=
m_cameras.end(); ++iter )
205 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but the corresponding view does " <<
206 "not exist. Ignoring.";
212 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but no proper manipulator matrix. " <<
213 "Leaving current matrix untouched.";
226 wlog::warn(
"Project Loader" ) <<
"Project file contained a camera \"" << ( *iter ).second <<
"\" but no proper manipulator home " <<
227 "position. Leaving current home untouched.";
231 view->getCameraManipulator()->setHomePosition(
m_homeEyeVectors[ ( *iter ).first ],
241 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
242 "// Camera definitions" << std::endl <<
243 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
250 output <<
"CAMERA:0:" << name << std::endl;
256 osg::Matrixd view = mani->getMatrix();
258 output <<
"//Camera Matrices: \"" << name <<
"\"" << std::endl;
259 output <<
" MANIPULATOR:(0,Matrix)=";
260 for(
unsigned int i = 0; i < 16; ++i )
262 output << view.ptr()[i];
274 mani->getHomePosition( eye, center, up );
279 output <<
" MANIPULATOR:(0,HomeEye)=";
280 output << eye.x() <<
";" << eye.y() <<
";" << eye.z() << std::endl;
281 output <<
" MANIPULATOR:(0,HomeCenter)=";
282 output << center.x() <<
";" << center.y() <<
";" << center.z() << std::endl;
283 output <<
" MANIPULATOR:(0,HomeUp)=";
284 output << up.x() <<
";" << up.y() <<
";" << up.z() << std::endl;
286 output <<
"//Camera Matrices END: \"" << name <<
"\"" << std::endl;