0
$\begingroup$

Rosanswers logo

(ROS GROOVY) Hi,

has anybody the plotting library MathGl included into the CMake process? Under https://groups.google.com/forum/#!topic/mathgl/3MFOIqTsyKE I found a FindMathGL.cmake which I evoked in cmakelist.txt:

##MH Include a custom cmake file for MathGl list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) find_package(MathGL REQUIRED)

It stops with: CMake Error at function/safety_trajectoryplanning_conti/ros/cmake/FindMathGL.cmake:67 (MESSAGE): Cannot determine MathGL version: mgl2/config.h parse error -- Configuring incomplete, errors occurred!

whereby the path mgl2/config.h was not found. MathGL was installed in /usr/local/lib and include. I put a symlink to /usr/include - lib, which was not working.

MathGL can be found here: http://mathgl.sourceforge.net/doc_en/Main.html

thanks


Originally posted by MartinHummel on ROS Answers with karma: 156 on 2014-04-14

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi,

I got it working with MathGL 1.11, which can be installed from the 12.04 Ubuntu repository. If additionally the GNU Scientific Library (GSL) is to be used, you find it in the repository (don't forget to install the SDK also).

First:

Install MathGl and additionally the development package libmgl-dev. The include path the is in /usr/include/mgl

Second:

Add in the CMakeLists.txt the following entries:

{

for adding the GNU Scientific Library

  • find_package( PkgConfig REQUIRED)
  • pkg_check_modules( gsl REQUIRED gsl )

}

  • add_executable( ... mathgl_example.cpp ## find the example in appendix )

  • target_link_libraries(ros_function_safety_trajectoryplanning_conti_node ${catkin_LIBRARIES}

    ${gsl_LIBRARIES} ## if you want to add the GNU Scientific Library also mgl mgl-fltk

    roscpp roslib rostime roscpp_serialization rosconsole pthread rt )

Third:

Include mathgl_example.cpp / .h in your project and

evoke it from eg. main()

// ====> MATHGL mglGraphFLTK mathglHnd; static pthread_t mathglThread; CMATHGL_EXAMPLE* mathgl=new CMATHGL_EXAMPLE(&mathglHnd, &mathglThread); // ===========

mathgl_example.h:

#include <mgl/mgl_fltk.h> #include <pthread.h>

#ifndef MATHGL_EXAMPLE_H_ #define MATHGL_EXAMPLE_H_

class CMATHGL_EXAMPLE { public: CMATHGL_EXAMPLE(mglGraphFLTK* mathglHnd, pthread_t* mathglThread); ~CMATHGL_EXAMPLE();

};

#endif /* MATHGL_EXAMPLE_H_ */ =======mathgl_example.cpp

int sample(mglGraph gr, void ) { mglData a(50,15),d(50),d1(50),d2(50); d.Modify("0.7sin(2pix) + 0.5cos(3pix) + 0.2sin(pix)"); d1.Modify("cos(2pix)"); d2.Modify("sin(2pix)"); a.Modify("pow(x,4*y)");

gr->NewFrame();
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Simple plot of one curve");
gr->Plot(d);
gr->EndFrame();

gr->NewFrame();
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Three curves with manual styles");
gr->Plot(d,"b");
gr->Plot(d1,"ri");
gr->Plot(d2,"m|^");
gr->Plot(d,"l o");
gr->EndFrame();

gr->NewFrame();
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Three curves with automatic styles");
gr->Plot(d);
gr->Plot(d1);
gr->Plot(d2);
gr->EndFrame();

gr->NewFrame();
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Curves from matrix");
gr->Plot(a);
gr->EndFrame();

gr->NewFrame();
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Parametrical curves in 2D");
gr->Plot(d1,d2,"b");
gr->Plot(d1,d,"ri");
gr->EndFrame();

gr->NewFrame();
gr->Text(mglPoint(0,1.2,1),"Parametrical curves in 3D");
gr->Rotate(60,40);
gr->Box();  gr->Axis(); gr->Label('x',"x"); gr->Label('y',"y"); gr->Label('z',"z");
gr->Plot(d1,d2,d,"b");
gr->EndFrame();

gr->NewFrame();
gr->SubPlot(2,2,0);
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Area plot");
gr->Area(d);
gr->SubPlot(2,2,1);
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Step plot");
gr->Step(d);
gr->SubPlot(2,2,2);
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Stem plot");
gr->Stem(d);
gr->SubPlot(2,2,3);
gr->Box();  gr->Axis("xy"); gr->Label('x',"x"); gr->Label('y',"y");
gr->Text(mglPoint(0,1.2,1),"Bars plot");
gr->Bars(d);
gr->EndFrame();

gr->NewFrame();
gr->SubPlot(2,2,0);
gr->Text(mglPoint(0,1.2,1),"Area plot in 3D");
gr->Rotate(60,40);
gr->Box();  gr->Axis(); gr->Label('x',"x"); gr->Label('y',"y");
gr->Area(d1,d2,d);
gr->SubPlot(2,2,1);
gr->Text(mglPoint(0,1.2,1),"Step plot in 3D");
gr->Rotate(60,40);
gr->Box();  gr->Axis(); gr->Label('x',"x"); gr->Label('y',"y");
gr->Step(d1,d2,d);
gr->SubPlot(2,2,2);
gr->Text(mglPoint(0,1.2,1),"Stem plot in 3D");
gr->Rotate(60,40);
gr->Box();  gr->Axis(); gr->Label('x',"x"); gr->Label('y',"y");
gr->Stem(d1,d2,d);
gr->SubPlot(2,2,3);
gr->Text(mglPoint(0,1.2,1),"Bars plot in 3D");
gr->Rotate(60,40);
gr->Box();  gr->Axis(); gr->Label('x',"x"); gr->Label('y',"y");
gr->Bars(d1,d2,d);
gr->EndFrame();
return gr->GetNumFrame();

}

void *mgl_fltk_tmp(void *) { mglFlRun(); return 0; }

CMATHGL_EXAMPLE::CMATHGL_EXAMPLE(mglGraphFLTK* mathglHnd, pthread_t* mathglThread) { mathglHnd->Window(0,0,sample,"Test"); pthread_create(mathglThread, 0, mgl_fltk_tmp, 0); };

CMATHGL_EXAMPLE::~CMATHGL_EXAMPLE() { };


Originally posted by MartinHummel with karma: 156 on 2014-04-24

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.