I am trying for a longer while now to create a mechanism that would create text labels next to my points on a plot with the coordinates. From the documentation, I have read that I need to use QCPItemTracer for that. No matter how i try, I cannot display any additional items on my plot using this object. In the QCustomPlot examples, there is one program that user QCPItemTracer, but when i run it, I also dont see any additional objects. I am trying to run the example code from bellow:
QCPItemTracer *phaseTracer = new QCPItemTracer(customPlot);
customPlot->addItem(phaseTracer);
phaseTracer->setGraph(customPlot->graph(DATA_PLOT));
phaseTracer->setGraphKey(7);
phaseTracer->setInterpolating(true);
phaseTracer->setStyle(QCPItemTracer::tsCircle);
phaseTracer->setPen(QPen(Qt::red));
phaseTracer->setBrush(Qt::red);
phaseTracer->setSize(7);
From my understanding this was supposed to add red circles on my plot points. It does not. I Would really aprichiate any help in this matter, some example code maybe. I am struggling with this for a really long time.
I have managed to get the labels working:
returnCodes_t PlotData::insertPointLabel(const int& index, const double& x, const double& y)
{
QCPItemText *textLabel = new QCPItemText(m_parentPlot);
m_parentPlot->addItem(textLabel);
textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
textLabel->position->setType(QCPItemPosition::ptPlotCoords);
textLabel->position->setCoords(x, y); // place position at center/top of axis rect
textLabel->setText(QString("x%1 y%2").arg(x).arg(y));
textLabel->setVisible(labelsVisible);
m_pointLabels.insert(index, textLabel);
return return_success;
}
Related
How would I get the position of the mouse in c++ SDL2? I found this wiki however I'm not really sure what it means and how would I get the x and y in int form?
https://wiki.libsdl.org/SDL_GetMouseState
Call the function described at the link you found; with pointers to the two int variables which you want to receive the coordinates.
Simplified, the function works like this one:
void SetXto5(int* x)
{*x = 5;}
i.e. the variable which your parameter points to will receive a value.
(This skips the check for NULL pointer, which is implied in the documentation.)
This does of course require the SDL environment to be correctly set up and initialised. I assume from your comments that you do not ask about that background part.
Hi i have this QUI project its based match 3 game. I have problem with checking if in row there is 3 same type pic. i try to check if the next label in row is same picture and add it to new vector adding at the moment i cant find any way i could compare two pictures. I have tried chacheKey and few other methods but don't make them work. If they are same i could use any help to this project. Thank you.
QPixmap pic_value = labels[y][x]->pixmap(Qt::ReturnByValue);
QPixmap pic_value2 = labels[y][x+1]->pixmap(Qt::ReturnByValue);
if (pic_value.cacheKey() == pic_value2.cacheKey())
{
match_set.append(labels[y][x+1]);
}
Try the following code:
if (pic_value.toImage() == pic_value2.toImage())
Reference: https://www.qtcentre.org/threads/13537-do-we-can-t-compare-QIcon-or-QPixmap
First, unfortunately you can't compare QPixmap directly with the == operator so you will compare it by transferring it to an image then compare it.
if (mLogo.toImage() == logo.toImage())
return;
Secondaly, based on the QImage comparison from this documentation
The comparison can be slow, unless there is some obvious difference (e.g. different size or format), in which case the function will return quickly.
So, the operation of setting the mLogo to logo is easier than the checking for comparison.
I am using QChart for an application. The application need to show some data realtime. There will be one chart and 24 series in the chart. The data rate is 400pts for every channel.
I used another thread for receiving and processing received data and emit the processed data to a slot for append datas to update the chart series.
I refered to https://doc.qt.io/qt-5/qtcharts-audio-example.html. In my case, each series is limited to 2000 points, if the number of points in the series is less than 2000, add the new point to the series, if the number of points in the seried is more than 2000, delete first point, move the rest of datas to left and add the new point in the end. This will make the chart look like move from right to left.
For good performance, I also used series->replace() and series->setUseOpenGL(true).
My problem is that the application will get freezed soon when it started. I tried delete the codes of update the chart, everything looked fine. Could anyone help me how to improve the performance of update the chart?
Thanks!
I have the same problem. The main problem I think is, that QLineSeries sends the signal pointAdded() and triggers a repaint. Additionally append() and remove are performance sinks. QtChart does only support QList and no form of a ring buffer as far as I know.
I tried the way putting new data into a QQueue<QPointsF> and copy the data within a timer hanler set to 20 Hz. To avoid updating I disable these:
void
MyGraph::handle_timer_timeout()
{
_chartView->setUpdatesEnabled(false);
// _chart->removeSeries(_series);
while(_buf->count()>0){
_series->append(_buf->dequeue());
_series->remove(0);
}
// _chart->addSeries(_series);
_axisX->setRange( _series->at(0).x(),
_series->at(_seriesSize-1).x());
_axisY->setRange(-1,1);
_chartView->setUpdatesEnabled(true);
}
This results in roughly 20-30% less processor usage.
I also found the hint that temporary removing the series (removeSeries(),addseries()) can result in some improvements but I can't confirm that.
This may be better but not really good enough. I hope someone finds a better solution.
or use QLineSeries::replace(). For that I use a double buffer QVector<QVector<QPointF>> *_lists:
void
MyGraph::handle_timer_timeout()
{
_chartView->setUpdatesEnabled(false);
auto listsother = (_listsCrurrent+1)%2;
auto bufcnt = _buf->count();
//
QVector<QPointF> *newData = &_lists->data()[listsother];
int idx;
for(idx=0; idx<_seriesSize-bufcnt;idx++){
newData->replace(
idx,
_lists->at(_listsCrurrent).at(idx+bufcnt));
}
for(; idx<_seriesSize;idx++){
newData->replace(
idx,
_buf->dequeue());
}
_listsCrurrent = listsother;
_series->replace(_lists->at(_listsCrurrent));
_axisX->setRange( _series->at(0).x(),
_series->at(_seriesSize-1).x());
_axisY->setRange(-1,1);
_chartView->setUpdatesEnabled(true);
}
This is more performant on my computer.
Alternatively you can take a look on QWT.
Hi I have a dropdown menu & whenever I change the option in the dropdown I want to change the content in the canvas...For example
var paper = Raphael("myDivID",400,400);
function smallRectangle(){
paper.rect(10,10,100,50);
}
function bigRectangle(){
paper.rect(10,10,150,100);
}
In my dropdown i'll have two options "small rectangle" & "big rectangle". I want to call corresponding functions on dropdown selection. The issue I'm facing with is that once i change the dropdown option Raphael don't seem to draw it. I have read from some questions in stackoverflow that there is no need to use redraw technique in RaphaelJS
See the Answer!
Even If I try this way:
var paper = Raphael("myDivID",400,400);
function smallRectangle(){
paper.clear()
paper.rect(10,10,100,50);
}
function bigRectangle(){
paper.clear()
paper.rect(10,10,150,100);
}
This don't seem to add elements to canvas after the clear() function. Canvas remains empty.
FYI:my code is very large so I posted this simple example here.
There is no need to redraw the rect again ....
function resize_Rect(rect,newWidth,newHeight){//passing rect ,new width and new height
rect.attr({'width':newWidth,'height':newHeight});
}
Hope it helps you out ...
I have a problem that I would like to tell you because is about some days that I don’t have new ideas.
I have an image pointed with a double* pointer, and I want to translate it into itk::smartpointer for updating the user graphic interface, for this purpose I made this method :
void prueba_r01::double2itk( double *im_proc, ImageType::Pointer *salida, int alto, int ancho)
// This method translate the double* image into itk:smartpointer image
ImageType::IndexType pixelIndex; // pixelIndex[0]= index x-axis; pixelIndex[1] = index y-axisy
ImageType::PixelType pixelValue;
ImageType::PixelType aux; //auxiliar variable for checking the behaviour of the programm
// Doing a sweep of all the image (is in double *im_proc) translating the values into itk pointer format
for (int x=0; x<ancho; x++){ // ancho: widht of the image
pixelIndex[0]=x;//x position
for (int y=0; y<alto; y++){ // alto: height of the image
pixelIndex[1]=y;//y position
pixelValue= *(im_proc+x+ancho*y);
(*salida)->SetPixel(pixelIndex,pixelValue);
aux = (*salida)->GetPixel(pixelIndex); // checking that the image has been correctly transtaled from im_proc to salida-- > CHECKED
}
}
}
And then is called here:
//Translation of the double* image into itk:smartpointer image
double2itk(out_inv, &(ui.imageframe->imagereader), alto, ancho);
And after that, the user interface is updated:
// Update of the image shonw in the user interface
ui.imageframe->update();
The problem is that it seems that everything is working correctly, but the image in the interface is not updated.
Another option also valid for my project could be to stored the image in a ‘.bmp’ or ‘.jpeg’ file.
Could someone help me? Any ideas of what is not working properly? Is there any function for creating this image files?
ITK has built-in mechanisms for this, with some considerable safety advantages. Also: they can be used in a pipeline like any image source, and because they use your existing array they will be considerably faster (I think) than looping over the indices.
http://www.itk.org/Doxygen/html/classitk_1_1ImportImageFilter.html
http://www.itk.org/Doxygen/html/classitk_1_1ImportImageContainer.html
http://www.itk.org/Wiki/ITK/Examples/IO/ImportImageFilter
You must use the ImportImageContainer, and be very careful how you set the memory management options.
By default ITK will clean up after itself, and will expect to be able to delete the memory pointed to by your external pointer.
There are examples of this in the Users Guide.
There is also a very nice wiki example at: http://www.vtk.org/Wiki/ITK/Examples/IO/ImportImageFilter