forked from fhwedel-hoe/OpenRoadEd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xodr2osg.cpp
91 lines (72 loc) · 2.23 KB
/
xodr2osg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
xodr2osg.cpp
OpenDrive Xodr to OSG converter and Xodr viewer.
Miguel Leitao, ISEP, 2019
*/
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/MatrixTransform>
#include <osgGA/TrackballManipulator>
#include "OpenDrive/OpenDrive.h"
#include "Osg/OSGMain.h"
#include "OpenDrive/OpenDriveXmlParser.h"
void usage(char *app_name) {
printf("Usage: %s [options] file_in [file_out]\n", app_name);
exit(1);
}
int main(int argc, char* argv[])
{
// osg::Matrix myMatrix;
if ( argc<2 ) usage(argv[0]);
int runViewer = 0;
char *fout_name = NULL;
if ( strstr(argv[0], "xodrviewer")!=NULL ) {
runViewer = 1;
}
else {
if ( argc<3 ) {
fout_name = (char *)malloc(strlen(argv[1]+6));
strcpy(fout_name,argv[1]);
strcat(fout_name,".osg");
}
else fout_name = strdup(argv[2]);
}
// Creating the root node
osg::Group* SceneRoot = new osg::Group;
// Creates the OpenDrive structure
OpenDrive mOpenDrive;
OpenDriveXmlParser mOpenDriveParser(&mOpenDrive);
printf("Parsing file\n");
printf("Parsing file %s\n",argv[1]);
mOpenDriveParser.ReadFile(argv[1]);
printf("File parsed\n");
// Creates the OSG object
OSGMain mOsgMain( &(mOpenDrive) );
printf("Drawing roads\n");
mOsgMain.DrawRoads();
if ( ! mOsgMain.mRootGroup ) {
fprintf(stderr,"Road not built\n");
}
else {
if ( ! runViewer ) {
osgDB::writeNodeFile(*(mOsgMain.mRoadsGroup.get()), fout_name);
//osgDB::writeNodeFile(*(SceneRoot), "scene.osg");
}
else {
// Creating the viewer
osgViewer::Viewer viewer;
printf("Adding rootgroup\n");
viewer.setSceneData( mOsgMain.mRootGroup );
//SceneRoot->addChild(mOsgMain.mRootGroup);
// Setup camera
osg::Matrix matrix;
matrix.makeLookAt( osg::Vec3(0.,-30.,5.), osg::Vec3(0.,0.,0.), osg::Vec3(0.,0.,1.) );
viewer.getCamera()->setViewMatrix(matrix);
viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
while( !viewer.done() ) {
viewer.frame();
}
}
}
free(fout_name);
}