c++ application using qt, how to include gnuplot - c++

Im looking for a solution or some guidelines on how to, from a c++ application using Qt, create scientific plots. I have set my mind on gnuplot because it have nice features for later use of my plots in latex and such.
My question is then, can i and how do i accomplish to show a plot in qt and also makes it possible to expose the gnuplot commands for generating the plot later for reporting.
Should i based on my data create some datafile, and create a text file with the commands?
Can it be integrated into my c++ application such that i create the plot, see it in my application and then save the data and plot file.
Any input would be nice. I dont now gnuplot at the moment, and wonder if its a application on unix or its a library i can use in my application. Thanks.

Easiest way is to have your app run gnuplot in a system() or similar call, plotting to an image and then display the image.
If you want more detailed control there is an iostream lib to talk to gnuplot or an old C interface

If your not set on gnuplot look into:
KD Chart, it uses Qt ModelView programming model. It's cross platform and even has a plugin that appears as a widget in Qt Designer.
The R-Project is great for plotting might be all you need as a standalone program, but also as a Qt interface R-Forge. It too is cross platform.
Note:
I havn't tried R-Forge yet. R is actually a statistical programming language.
KD Chart targets business type charts but may have what you need.

Related

How to create a command line simulator GUI for C++

I'm looking into developing a text based game about cyber security akin to hackRUN or uplink but I have no experience with GUI programming and I doubt anyone in my family would want to learn how to make and run a .cpp file. So I need to create a GUI featuring a custom command-line akin to Linux or windows "cmd". Is there any resources available in that area?
You can create a textbox control that's the size of the entire window, and customize it to make it look like a console. For example, set the background to black, the color of the letters to white, etc.
How you create that textbox depends on what UI framework you're using. For C++ there's MFC or the managed WinForms, or you could create the UI part in C# using WPF and use C++/CLI as a bridge between C++ and C#. But if you want to make it work on both Windows and Linux you can use wxWidgets or Qt.
You can simulate a commandline by reading a line from the user and splitting on the first space (Python/pseudocode*):
for line in raw_input():
command,arguments = line.split(' ',1)
For example read book is the command read with the argument book.
Then you can process the command they gave using your own logic. The advantage of this approach is that you can just run your game via a shortcut on the desktop (whether linux or windows) and the OS console will support the interaction.
There is a class of games called 'text adventure' games, which were popular back when graphics were limited or nonexistent, which you may find particularly relevant. Consider using an existing text adventure engine so that you can concentrate on the game itself rather than the mechanics of text entry and parsing.
* Consider writing this in Python or a similar scripting language, as they provide straightforward handling of strings etc. You are unlikely to need the raw power and complexity of C++ for a commandline-style family game.

I'm trying to integrate a 3D model viewer into my GUI, but have not found a single library that will allow me to do this easily. Any suggestions?

I've tried with VTK, PCL and Qt (using the QVTKWidget.h), however, using CMake is incredibly inconvenient, as the second I update any one of the many libraries that my GUI uses, I have to spend at least another day trying to sort out the linker issues. Additionally, a lot of the time, a lot of information is lost from the 3D models using these libraries.
Note: I am focusing on using PLY as it holds color and geometry information in the same file, but any other format that does the same would be fine
I am currently trying to create a Meshlab plugin, but the support for this library is sparse, and I am yet to successfully compile the Meshlab source.
Any input or direction would be really appreciated. If you guys want to know anything more, please do let me know.
If it wasn't clear in the beginning, I am using Qt (C++) to create the GUI.
Use the QT OpenGL widget and write some OpenGL code to display your model.
PLY textural format is really simple and you can write a parser yourself.
Have you tried Coin3D? This is a Free implementation of OpenInventor wich was made by SGI back in the day as a C++ wrapper around OpenGL.
As for integration with Qt there is a library called SoQt (in the same site). They also have a newer library called Quarter that integrates more like a Qt component.
I've had greatest success with Coin + SoQt + Qt.

QML/D text editor and basic considerations

I am going to code a text/code editor (GUI with QML and the rest in D*). But I have several problems:
I code the GUI with QML and C++ and then I connect it with a D-Backend for formatting etc. purposes. What is the best way to connect different Languages? Pipes, Sockets or in D the ability to use C++ Libraries?
IMHO rich text is used to format the text (in most cases). How is it possible to edit this "markup" in an easy way?? Is the formated code like a background image and the user edits an opaque non-formated-text?
Are there common techniques?
*Because QML is cool, platform indepedent and fast. On the other hand D is powerful and easy to use.
As you might know, there is QtD, Qt binding for D. It's not production ready right now, but it might be some day.
Another option would be connecting C++ and D, through C wrapper. This is the most commonly used way of interacting between C++ and D.
extern(C++) interfaces are specific to DigitalMars C++ compiler on Windows and are very limited, so that probably wouldn't help with your problem.
Also you might want to look at SWIG. It's a tool automatically generating glue code for interaction of other languages with C++. It supports D.
If performance is not an issue communications with D code could work through sockets or pipes.
QML isn't for WebApp. It s QtQuick Markup Language. The 'new' way to do UI at Qt. And QWidget will probably be deprecated in favor of QML in Qt5.
I've try to do the same thing. But i fear that qml isn't ready yet to do things like that. Most element available today are just good enought to draw image, rectangle, listview, one line text input and do transition.
I was trying to achieve that by coloring with python and pygments, too slow, using html3.2 style to do that isn't the right way. But it's the only way to style text in qml textedit. ;(
QtQuick 2.0 should bring better text control.

Stock Charts in C++

I am trying to create some charts of data (eg http://www.amibroker.com/). Is there a C++ library that can do this without a lot of extra work? I'm thinking Qt or wxWindows would have something like it, but it wasn't immediately obvious.
Thanks!
FLTK is a light and portable C++ toolkit for GUI. There's a chart class. Sample.
Qwt does at least some of the things you are trying to achieve (basic plots, bar charts and so on), and integrates well with Qt.
I think you need to pick your GUI framework first, then find a charting control for the given framework, since that affects what charting controls you could feasibly use. For example, must this be portable?
For the project I'm working on (a large MFC application) we use Cedric Moonen's ChartCtrl. We've had a pretty good experience with it so far.
I've done some graph plotting with gnuplot lately, which is quite powerful. Although I think it is Linux only, which may or may not be a problem.
Also, believe it or not, some amazing things can be done with LaTeX. I've used the tkz (tikz) library to produce some awesome graphs.
Both solutions plot to a file which you can include in your interface.
They aren't C++ libraries but you can easily create the datafiles and call the necessary programs from within your C++ program (Being creative with system() and possible some shell scripts).

Scatter Plots in C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
What is the best way to graph scatter plots in C++?
Do you write data to a file and use another tool? Is there a library like matplotlib in Python?
I always write out data and then using gnuplot to create my graphs. It is by far the best way I have found of producing graphs in a variety of formats: eps, png, jpeg, xpm, you name it.
gnuplot will do scatter plot very easily. Provided the x and y values are in 2 space-separated columnss, then
plot "data.txt" using 1:2
Will give you a quick scatter plot. Then you can adjust it and what not using other gnuplot commands.
If you are involved in sciences, then learning gnuplot will be very valuable to you. It kicks the crap out of doing excel plots for sure and it eases the task of making plots to include in papers.
If you are looking for a C++ library rather than I independent plotting tool like gnuplot, I would consider the following:
Koolplot
dislin (Wikipedia article on dislin)
dislin seems to be the more interesting of the two. Here is a description extracted from the wikipedia article:
DISLIN is a high-level and easy to use plotting library developed by Helmut Michels at the Max Planck Institute in Katlenburg-Lindau, Germany. Helmut Michels currently works as a mathematician and Unix system manager at the computer center of the institute.
The DISLIN library contains routines and functions for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours and maps. Several output formats are supported such as X11, VGA, PostScript, PDF, CGM, HPGL, SVG, PNG, BMP, PPM, GIF and TIFF.
DISLIN is available for the programming languages Fortran 77, Fortran 90/95 and C. Plotting extensions for the languages Perl, Python and Java are also supported for most operating systems. The current version of DISLIN is 9.4, released in October 2008. The first version 1.0 was released in December 1986.
The DISLIN software is free for non-commercial use.
Very heavy solution: you could link against ROOT, which will do just about anything you want:
runs on Mac, Windows and Linux
runs compiled or using the cint interperter
output to a file in encapsulated postscript, PDF, gif, png...
display to the screen using several different technologies
serialize the data in an internal format that can be manipulated later
Sure, its a bit much for most people, but it does do exactly what you asked for. I use it because I know it and it is already on my machines becase I'm that kind of physicist.
Good old GNU, they have everything...
http://directory.fsf.org/project/plotutils/
This is certainly not the best way but I usually write output files that can be read by R and use this, along with an appropriate script, to plot the graphs.
The problem here is that C++, unlike Java for example, does not have built-in GUI or graphics. If you want to generate graphs with C++ you would need to use a GUI library available for your OS. There are free GUI libraries, many cross-plaform such as Qt or GTK.
However, as other people have pointed out, the easiest thing for you to do would be to save the data into a text file, and use another program to generate the graph. gnuplot is definitely a good choice. It comes standard with most linux distros, and you get for Windows under cygwin.
Regards plotting in C++ for anyone who didn't do it yet. I will say what I did to plot Graphs in C++
Download the zipped file "gp443win32.zip" from http://sourceforge.jp/projects/sfnet_gnuplot/downloads/gnuplot/4.4.3/gp443win32.zip/
Extract it in "C:\Gnuplot"
then I read "C:\Gnuplot\gnuplot\README.Windows"
and I got these information:
I used Windows 7 ==> so you need to download "winhlp32.exe"... just search for it "winhlp32.exe Windows 7" in a search engine and go through the first link.
Append to the "Path" Environment variable the path for binary folder which is "C:\Gnuplot\gnuplot\binary"
then I shutdown my computer and open it again. After I found that it didn't sense the change in the environment variables :D
you need now to write a sample code to test your plotting ability :)
so you can visit this link
http://code.google.com/p/gnuplot-cpp/source/browse/#svn%2Ftrunk
to see the header file "gnuplot_i.hpp" and source file "example.cc".
You will get many and many graphs, choose your appropriate graph, customize your core, and enjoy :)
If you're familiar with matplotlib, you can embed python in C/C++ applications. Depending on what you want it for, this might be a quick solution.
Chart Director has bindings for C++. I've used their .Net libraries, and I've been pretty happy with them. It's a pretty cheap library, and gives you the power to do all sorts of different charts.