00001 #include "SIGEL_Visualisation/SIG_Renderer.h"
00002 #include "SIGEL_Tools/SIG_TypeConverter.h"
00003
00004 using namespace SIGEL_Tools;
00005
00006 namespace SIGEL_Visualisation
00007 {
00008
00009 SIG_Renderer::SIG_Renderer(int noOfObjects, int noOfFloatingTexts)
00010 : sceneObjects(noOfObjects),
00011 floatingTexts(noOfFloatingTexts)
00012 {
00013 sceneObjects.setAutoDelete(true);
00014 floatingTexts.setAutoDelete(true);
00015
00016 this->noOfObjects = static_cast<GLuint>(noOfObjects);
00017
00018 glListBase(0);
00019 displayListsOffset = glGenLists( this->noOfObjects );
00020 };
00021
00022 SIG_Renderer::~SIG_Renderer()
00023 {
00024 glDeleteLists( displayListsOffset, static_cast<GLsizei>(noOfObjects) );
00025 };
00026
00027 void SIG_Renderer::renderSceneObjects()
00028 {
00029 glMatrixMode(GL_MODELVIEW);
00030 for (GLuint i=0; i < noOfObjects; i++)
00031 if (sceneObjects[i]->getVisible())
00032 {
00033 sceneObjects[i]->applyColor();
00034 glPushMatrix();
00035 sceneObjects[i]->applyTransformation();
00036 glCallList( displayListsOffset + i );
00037 glPopMatrix();
00038 };
00039 };
00040
00041 QString SIG_Renderer::exportSceneObjectsToPovray()
00042 {
00043 QString resultString;
00044 QTextStream resultStream( &resultString, IO_WriteOnly );
00045
00046 for (int i=0; i < noOfObjects; i++)
00047 if (sceneObjects[ i ]->getVisible())
00048 {
00049 NEWMAT::Matrix rotation = ( SIG_TypeConverter::sigelToPovray()
00050 * SIG_TypeConverter::toMatrix( sceneObjects[ i ]->getRotation() ) ).t();
00051 NEWMAT::ColumnVector position = SIG_TypeConverter::sigelToPovray()
00052 * SIG_TypeConverter::toColumnVector( sceneObjects[ i ]->getPosition() );
00053
00054 resultStream << "object {\n"
00055 << " "
00056 << sceneObjects[ i ]->name
00057 << "\n"
00058 << " matrix <";
00059 for (int i=1; i<=3; i++)
00060 resultStream << " " << rotation( 1, i ) << ",";
00061 resultStream << "\n"
00062 << " ";
00063 for (int i=1; i<=3; i++)
00064 resultStream << " " << rotation( 2, i ) << ",";
00065 resultStream << "\n"
00066 << " ";
00067 for (int i=1; i<=3; i++)
00068 resultStream << " " << rotation( 3, i ) << ",";
00069 resultStream << "\n"
00070 << " 0 0 0 >\n"
00071 << " translate "
00072 << vectorToPovray( position )
00073 << "\n"
00074 << "}\n"
00075 << "\n";
00076 };
00077
00078 return resultString;
00079 };
00080
00081 QString SIG_Renderer::vectorToPovray( NEWMAT::ColumnVector input )
00082 {
00083 QString resultString;
00084
00085 QTextStream resultStream( &resultString, IO_WriteOnly );
00086 resultStream.precision( 5 );
00087
00088 resultStream << "<" << input( 1 ) << ", " << input( 2 ) << ", " << input( 3 ) << ">";
00089
00090 return resultString;
00091 };
00092 }