libpappsomspp
Library for mass spectrometry
pappso::BaseColorMapPlotWidget Class Reference

#include <basecolormapplotwidget.h>

Inheritance diagram for pappso::BaseColorMapPlotWidget:
pappso::BasePlotWidget pappso::DriftSpecMassSpecColorMapPlotWidget pappso::TicXicChromDriftSpecColorMapPlotWidget pappso::TicXicChromMassSpecColorMapPlotWidget

Public Member Functions

 BaseColorMapPlotWidget (QWidget *parent, const QString &x_axis_label, const QString &y_axis_label)
 
virtual ~BaseColorMapPlotWidget ()
 Destruct this BaseColorMapPlotWidget instance. More...
 
virtual void setColorMapPlotConfig (const ColorMapPlotConfig &color_map_config)
 
virtual const ColorMapPlotConfiggetColorMapPlotConfig ()
 
const ColorMapPlotConfiggetOrigColorMapPlotConfig ()
 
virtual QCPColorMap * addColorMap (std::shared_ptr< std::map< double, MapTrace >> double_map_trace_map_sp, const ColorMapPlotConfig color_map_plot_config, const QColor &color)
 
virtual void transposeAxes ()
 
virtual void zAxisScaleToLog10 ()
 
virtual void zAxisFilterLowPassPercentage (double threshold_percentage)
 
virtual void zAxisFilterHighPassPercentage (double threshold_percentage)
 
virtual void zAxisDataResetToOriginal ()
 
DataKind xAxisDataKind () const
 
DataKind yAxisDataKind () const
 
AxisScale axisScale (Axis axis) const
 
AxisScale xAxisScale () const
 
AxisScale yAxisScale () const
 
AxisScale zAxisScale () const
 
virtual void setPlottingColor (QCPAbstractPlottable *plottable_p, const QColor &new_color) override
 
virtual QColor getPlottingColor (int index=0) const override
 
QString dataToString ()
 
- Public Member Functions inherited from pappso::BasePlotWidget
 BasePlotWidget (QWidget *parent)
 
 BasePlotWidget (QWidget *parent, const QString &x_axis_label, const QString &y_axis_label)
 
virtual ~BasePlotWidget ()
 Destruct this BasePlotWidget instance. More...
 
virtual bool setupWidget ()
 
virtual void setPen (const QPen &pen)
 
virtual const QPen & getPen () const
 
virtual void setPlottingColor (int index, const QColor &new_color)
 
virtual QColor getPlottingColor (QCPAbstractPlottable *plottable_p) const
 
virtual void setAxisLabelX (const QString &label)
 
virtual void setAxisLabelY (const QString &label)
 
virtual void resetAxesRangeHistory ()
 
virtual void updateAxesRangeHistory ()
 Create new axis range history items and append them to the history. More...
 
virtual void restorePreviousAxesRangeHistory ()
 Go up one history element in the axis history. More...
 
virtual void restoreAxesRangeHistory (std::size_t index)
 Get the axis histories at index index and update the plot ranges. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void keyReleaseEvent (QKeyEvent *event)
 Handle specific key codes and trigger respective actions. More...
 
virtual void spaceKeyReleaseEvent (QKeyEvent *event)
 
virtual void directionKeyPressEvent (QKeyEvent *event)
 
virtual void directionKeyReleaseEvent (QKeyEvent *event)
 
virtual void mousePseudoButtonKeyPressEvent (QKeyEvent *event)
 
virtual void mousePseudoButtonKeyReleaseEvent (QKeyEvent *event)
 
virtual void mousePressHandler (QMouseEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void mouseReleaseHandler (QMouseEvent *event)
 
virtual void mouseReleaseHandlerLeftButton ()
 
virtual void mouseReleaseHandlerRightButton ()
 
virtual void mouseMoveHandler (QMouseEvent *event)
 KEYBOARD-related EVENTS. More...
 
virtual void mouseMoveHandlerNotDraggingCursor ()
 
virtual void mouseMoveHandlerDraggingCursor ()
 
virtual void mouseMoveHandlerLeftButtonDraggingCursor ()
 
virtual void mouseMoveHandlerRightButtonDraggingCursor ()
 
virtual void axisDoubleClickHandler (QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event)
 
bool isClickOntoXAxis (const QPointF &mousePoint)
 
bool isClickOntoYAxis (const QPointF &mousePoint)
 
int dragDirection ()
 MOUSE-related EVENTS. More...
 
virtual void moveMouseCursorGraphCoordToGlobal (QPointF plot_coordinates)
 
virtual void moveMouseCursorPixelCoordToGlobal (QPointF local_coordinates)
 
virtual void horizontalMoveMouseCursorCountPixels (int pixel_count)
 
virtual QPointF horizontalGetGraphCoordNewPointCountPixels (int pixel_count)
 
virtual void verticalMoveMouseCursorCountPixels (int pixel_count)
 
virtual QPointF verticalGetGraphCoordNewPointCountPixels (int pixel_count)
 
virtual QCPRange getRangeX (bool &found_range, int index) const
 MOUSE MOVEMENTS mouse/keyboard-triggered. More...
 
virtual QCPRange getRangeY (bool &found_range, int index) const
 
QCPRange getRange (Axis axis, RangeType range_type, bool &found_range) const
 
virtual QCPRange getInnermostRangeX (bool &found_range) const
 
virtual QCPRange getOutermostRangeX (bool &found_range) const
 
virtual QCPRange getInnermostRangeY (bool &found_range) const
 
virtual QCPRange getOutermostRangeY (bool &found_range) const
 
void yMinMaxOnXAxisCurrentRange (double &min, double &max, QCPAbstractPlottable *plottable_p=nullptr)
 
void yMinMaxOnXAxisCurrentRange (double &min, double &max, int index)
 
virtual void axisRescale ()
 RANGE-related functions. More...
 
virtual void axisReframe ()
 
virtual void axisZoom ()
 
virtual void axisPan ()
 
virtual void replotWithAxesRanges (QCPRange xAxisRange, QCPRange yAxisRange, Axis whichAxis)
 
virtual void replotWithAxisRangeX (double lower, double upper)
 
virtual void replotWithAxisRangeY (double lower, double upper)
 
virtual void hideAllPlotItems ()
 PLOTTING / REPLOTTING functions. More...
 
virtual void showTracers ()
 Show the traces (vertical and horizontal). More...
 
virtual void hideTracers ()
 Hide the traces (vertical and horizontal). More...
 
virtual void drawXDeltaFeatures ()
 
virtual void drawYDeltaFeatures ()
 
virtual void calculateDragDeltas ()
 
virtual bool isVerticalDisplacementAboveThreshold ()
 
virtual void drawSelectionRectangleAndPrepareZoom (bool as_line_segment=false, bool for_integration=false)
 
virtual void updateSelectionRectangle (bool as_line_segment=false, bool for_integration=false)
 
virtual void resetSelectionRectangle ()
 
virtual void hideSelectionRectangle (bool reset_values=false)
 
virtual bool isSelectionRectangleVisible ()
 
virtual PolygonType whatIsVisibleOfTheSelectionRectangle ()
 
virtual void setFocus ()
 PLOT ITEMS : TRACER TEXT ITEMS... More...
 
virtual void redrawPlotBackground (QWidget *focusedPlotWidget)
 Redraw the background of the focusedPlotWidget plot widget. More...
 
virtual void updateContextXandYAxisRanges ()
 
virtual const BasePlotContextgetContext () const
 

Protected Attributes

QCPColorMapData * mpa_origColorMapData = nullptr
 
ColorMapPlotConfig m_colorMapPlotConfig
 
ColorMapPlotConfigmpa_origColorMapPlotConfig = nullptr
 
- Protected Attributes inherited from pappso::BasePlotWidget
QString m_name = "NOT_SET"
 Name of the plot widget. More...
 
QString m_desc = "NOT_SET"
 Description of the plot widget. More...
 
QString m_fileName
 The name of the data file from which the mass data were read. More...
 
QString m_axisLabelX
 
QString m_axisLabelY
 
BasePlotContext m_context
 
int m_leftMousePseudoButtonKey = Qt::Key_Less
 
int m_rightMousePseudoButtonKey = Qt::Key_Greater
 
QCPItemLine * mp_selectionRectangeLine1 = nullptr
 Rectangle defining the borders of zoomed-in/out data. More...
 
QCPItemLine * mp_selectionRectangeLine2 = nullptr
 
QCPItemLine * mp_selectionRectangeLine3 = nullptr
 
QCPItemLine * mp_selectionRectangeLine4 = nullptr
 
QCPItemText * mp_xDeltaTextItem = nullptr
 Text describing the x-axis delta value during a drag operation. More...
 
QCPItemText * mp_yDeltaTextItem = nullptr
 
bool m_shouldTracersBeVisible = true
 Tells if the tracers should be visible. More...
 
QCPItemLine * mp_hPosTracerItem = nullptr
 Horizontal position tracer. More...
 
QCPItemLine * mp_vPosTracerItem = nullptr
 Vertical position tracer. More...
 
QCPItemLine * mp_vStartTracerItem = nullptr
 Vertical selection start tracer (typically in green). More...
 
QCPItemLine * mp_vEndTracerItem = nullptr
 Vertical selection end tracer (typically in red). More...
 
std::size_t m_lastAxisRangeHistoryIndex = 0
 Index of the last axis range history item. More...
 
std::vector< QCPRange * > m_xAxisRangeHistory
 List of x axis ranges occurring during the panning zooming actions. More...
 
std::vector< QCPRange * > m_yAxisRangeHistory
 List of y axis ranges occurring during the panning zooming actions. More...
 
int m_mouseMoveHandlerSkipAmount = 10
 How many mouse move events must be skipped *‍/. More...
 
int m_mouseMoveHandlerSkipCount = 0
 Counter to handle the "fat data" mouse move event handling. More...
 
QColor m_unfocusedColor = QColor("lightgray")
 Color used for the background of unfocused plot. More...
 
QBrush m_unfocusedBrush = QBrush(m_unfocusedColor)
 Color used for the background of unfocused plot. More...
 
QColor m_focusedColor = QColor(Qt::transparent)
 Color used for the background of focused plot. More...
 
QBrush m_focusedBrush = QBrush(m_focusedColor)
 Color used for the background of focused plot. More...
 
QPen m_pen
 Pen used to draw the graph and textual elements in the plot widget. More...
 

Additional Inherited Members

- Signals inherited from pappso::BasePlotWidget
void setFocusSignal ()
 
void lastCursorHoveredPointSignal (const QPointF &pointf)
 
void plotRangesChangedSignal (const BasePlotContext &context)
 
void xAxisMeasurementSignal (const BasePlotContext &context, bool with_delta)
 
void keyPressEventSignal (const BasePlotContext &context)
 
void keyReleaseEventSignal (const BasePlotContext &context)
 
void mouseReleaseEventSignal (const BasePlotContext &context)
 
void plottableSelectionChangedSignal (QCPAbstractPlottable *plottable_p, bool selected)
 
void integrationRequestedSignal (const BasePlotContext &context)
 
void plottableDestructionRequestedSignal (BasePlotWidget *base_plot_widget_p, QCPAbstractPlottable *plottable_p, const BasePlotContext &context)
 
- Protected Member Functions inherited from pappso::BasePlotWidget
virtual void createAllAncillaryItems ()
 
virtual void update1DSelectionRectangle (bool for_integration=false)
 
virtual void update2DSelectionRectangleSquare (bool for_integration=false)
 
virtual void update2DSelectionRectangleSkewed (bool for_integration=false)
 
virtual QString allLayerNamesToString () const
 
virtual QString layerableLayerName (QCPLayerable *layerable_p) const
 
virtual int layerableLayerIndex (QCPLayerable *layerable_p) const
 

Detailed Description

Definition at line 61 of file basecolormapplotwidget.h.

Constructor & Destructor Documentation

◆ BaseColorMapPlotWidget()

pappso::BaseColorMapPlotWidget::BaseColorMapPlotWidget ( QWidget *  parent,
const QString &  x_axis_label,
const QString &  y_axis_label 
)
explicit

Definition at line 44 of file basecolormapplotwidget.cpp.

47  : BasePlotWidget(parent, x_axis_label, y_axis_label)
48 {
49  // Do not call createAllAncillaryItems() in this base class because all the
50  // items will have been created *before* the addition of plots and then the
51  // rendering order will hide them to the viewer, since the rendering order is
52  // according to the order in which the items have been created.
53  //
54  // The fact that the ancillary items are created before trace plots is not a
55  // problem because the trace plots are sparse and do not effectively hide the
56  // data.
57  //
58  // But, in the color map plot widgets, we cannot afford to create the
59  // ancillary items *before* the plot itself because then, the rendering of the
60  // plot (created after) would screen off the ancillary items (created before).
61  //
62  // So, the createAllAncillaryItems() function needs to be called in the
63  // derived classes at the most appropriate moment in the setting up of the
64  // widget.
65  //
66  // In the present case, the function needs to be called right after addition
67  // of the color map plot.
68 }
BasePlotWidget(QWidget *parent)

◆ ~BaseColorMapPlotWidget()

pappso::BaseColorMapPlotWidget::~BaseColorMapPlotWidget ( )
virtual

Destruct this BaseColorMapPlotWidget instance.

The destruction involves clearing the history, deleting all the axis range history items for x and y axes.

Definition at line 78 of file basecolormapplotwidget.cpp.

79 {
80  if(mpa_origColorMapData != nullptr)
81  delete mpa_origColorMapData;
82 
83  if(mpa_origColorMapPlotConfig != nullptr)
85 }
ColorMapPlotConfig * mpa_origColorMapPlotConfig

References mpa_origColorMapData, and mpa_origColorMapPlotConfig.

Member Function Documentation

◆ addColorMap()

QCPColorMap * pappso::BaseColorMapPlotWidget::addColorMap ( std::shared_ptr< std::map< double, MapTrace >>  double_map_trace_map_sp,
const ColorMapPlotConfig  color_map_plot_config,
const QColor &  color 
)
virtual

Definition at line 111 of file basecolormapplotwidget.cpp.

115 {
116  // qDebug() << "Adding color map with config:" <<
117  // color_map_plot_config.toString();
118 
119  if(!color.isValid())
120  throw PappsoException(
121  QString("The color to be used for the plot graph is invalid."));
122 
123  QCPColorMap *color_map_p = new QCPColorMap(xAxis, yAxis);
124 
125  color_map_p->setLayer("plotsLayer");
126 
127  // Do not forget to copy the config!
128  m_colorMapPlotConfig = color_map_plot_config;
129 
130  // Immediately create a copy of the original data for backup.
131  mpa_origColorMapPlotConfig = new ColorMapPlotConfig(color_map_plot_config);
132 
133 #if 0
134  // This is the code on the QCustomPlot documentation and it works fine.
135  QCPColorMap *color_map_p = new QCPColorMap(xAxis, yAxis);
136 
137  color_map_p->data()->setSize(50, 50);
138  color_map_p->data()->setRange(QCPRange(0, 2), QCPRange(0, 2));
139  for(int x = 0; x < 50; ++x)
140  for(int y = 0; y < 50; ++y)
141  color_map_p->data()->setCell(x, y, qCos(x / 10.0) + qSin(y / 10.0));
142  color_map_p->setGradient(QCPColorGradient::gpPolar);
143  color_map_p->rescaleDataRange(true);
144  rescaleAxes();
145  replot();
146 #endif
147 
148  // Only now can afford to call createAllAncillaryItems() in this derived class
149  // because the color map has been created already. The rendering order will
150  // thus not hide the ancillary items, since they have been created after the
151  // color map plot (since the rendering order is according to the
152  // order in which the items have been created). See contructor note.
154 
155  // Connect the signal of selection change so that we can re-emit it for the
156  // widget that is using *this widget.
157 
158  connect(color_map_p,
159  static_cast<void (QCPAbstractPlottable::*)(bool)>(
160  &QCPAbstractPlottable::selectionChanged),
161  [this, color_map_p]() {
162  emit plottableSelectionChangedSignal(color_map_p,
163  color_map_p->selected());
164  });
165 
166  // qDebug() << "Configuring the color map with this config:"
167  //<< color_map_plot_config.toString();
168 
169  color_map_p->data()->setSize(color_map_plot_config.keyCellCount,
170  color_map_plot_config.mzCellCount);
171 
172  color_map_p->data()->setRange(QCPRange(color_map_plot_config.minKeyValue,
173  color_map_plot_config.maxKeyValue),
174  QCPRange(color_map_plot_config.minMzValue,
175  color_map_plot_config.maxMzValue));
176  color_map_p->data()->fill(0.0);
177 
178  // We have now to fill the color map.
179 
180  for(auto &&pair : *double_map_trace_map_sp)
181  {
182 
183  // The first value is the key and the second value is the MapTrace into
184  // which we need to iterated and for each point (double mz, double
185  // intensity) create a map cell.
186 
187  double dt_or_rt_key = pair.first;
188  MapTrace map_trace = pair.second;
189 
190  for(auto &&data_point_pair : map_trace)
191  {
192  double mz = data_point_pair.first;
193  double intensity = data_point_pair.second;
194 
195  // We are filling dynamically the color map. If a cell had already
196  // something in, then we need to take that into account. This is
197  // because we let QCustomPlot handle the fuzzy transition between
198  // color map plot cells.
199 
200  double prev_intensity = color_map_p->data()->data(dt_or_rt_key, mz);
201  double new_intensity = prev_intensity + intensity;
202 
203  // Record the min/max cell intensity value (origM(in/ax)ZValue). We
204  // will need that later. Also update the lastM(in/ax)ZValue because
205  // when doing this kind of data conversion it is assume that the user
206  // actually changes the data.
208  std::min(m_colorMapPlotConfig.origMinZValue, new_intensity));
209 
211  std::max(m_colorMapPlotConfig.origMaxZValue, new_intensity));
212 
213  // qDebug() << "Setting tri-point:" << dt_or_rt_key << "," << mz <<
214  // ","
215  //<< new_intensity;
216 
217  color_map_p->data()->setData(dt_or_rt_key, mz, new_intensity);
218  }
219  }
220 
221  // At this point we have finished filling-up the color map.
222 
223  // The gpThermal is certainly one of the best.
224 
225  color_map_p->setGradient(QCPColorGradient::gpThermal);
226 
227  color_map_p->rescaleDataRange(true);
228 
229  color_map_p->rescaleAxes();
231 
232  // The pen of the color map itself is of no use. Instead the user will see the
233  // color of the axes' labels.
234 
235  QPen pen = xAxis->basePen();
236  pen.setColor(color);
237 
238  xAxis->setBasePen(pen);
239  xAxis->setLabelColor(color);
240  xAxis->setTickLabelColor(color);
241 
242  yAxis->setBasePen(pen);
243  yAxis->setLabelColor(color);
244  yAxis->setTickLabelColor(color);
245 
246  // And now set the color map's pen to the same color, even if we do not use
247  // it, we need it for coloring the plots that might be integrated from this
248  // color map.
249 
250  color_map_p->setPen(pen);
251 
252  // Copy the original color map's data into a backup copy.
253 
254  mpa_origColorMapData = new QCPColorMapData(*(color_map_p->data()));
255 
256  replot();
257 
258  return color_map_p;
259 }
virtual void createAllAncillaryItems()
virtual void resetAxesRangeHistory()
void plottableSelectionChangedSignal(QCPAbstractPlottable *plottable_p, bool selected)
void setOrigAndLastMaxZValue(double value)
void setOrigAndLastMinZValue(double value)

References pappso::BasePlotWidget::createAllAncillaryItems(), pappso::ColorMapPlotConfig::keyCellCount, m_colorMapPlotConfig, pappso::ColorMapPlotConfig::maxKeyValue, pappso::ColorMapPlotConfig::maxMzValue, pappso::ColorMapPlotConfig::minKeyValue, pappso::ColorMapPlotConfig::minMzValue, mpa_origColorMapData, mpa_origColorMapPlotConfig, pappso::mz, pappso::ColorMapPlotConfig::mzCellCount, pappso::ColorMapPlotConfig::origMaxZValue, pappso::ColorMapPlotConfig::origMinZValue, pappso::BasePlotWidget::plottableSelectionChangedSignal(), pappso::BasePlotWidget::resetAxesRangeHistory(), pappso::ColorMapPlotConfig::setOrigAndLastMaxZValue(), pappso::ColorMapPlotConfig::setOrigAndLastMinZValue(), pappso::x, and pappso::y.

◆ axisScale()

AxisScale pappso::BaseColorMapPlotWidget::axisScale ( Axis  axis) const

Definition at line 727 of file basecolormapplotwidget.cpp.

728 {
729  if(axis == Axis::x)
731  else if(axis == Axis::y)
733  else if(axis == Axis::z)
735  else
736  throw PappsoException(
737  QString("basecolormapplotwidget.cpp: The axis cannot be different than "
738  "x, y or z."));
739 
740  return AxisScale::unset;
741 }

References m_colorMapPlotConfig, pappso::unset, pappso::x, pappso::ColorMapPlotConfig::xAxisScale, pappso::y, pappso::ColorMapPlotConfig::yAxisScale, pappso::z, and pappso::ColorMapPlotConfig::zAxisScale.

◆ dataToString()

QString pappso::BaseColorMapPlotWidget::dataToString ( )

Definition at line 808 of file basecolormapplotwidget.cpp.

809 {
810  // We want to export the data to a string in the x y z format, with
811  // x=key (cell's x coordinate)
812  // y=value (cell's y coordinate)
813  // z=intensity (cell value)
814 
815  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
816 
817  QCPColorMapData *map_data = color_map_p->data();
818 
819  int keySize = map_data->keySize();
820  int valueSize = map_data->valueSize();
821 
822  QString text;
823 
824  for(int iter = 0; iter < keySize; ++iter)
825  {
826  for(int jter = 0; jter < valueSize; ++jter)
827  {
828  text += QString("%1 %2 %3\n")
829  .arg(iter, 0, 'f', 6, ' ')
830  .arg(jter, 0, 'f', 6, ' ')
831  .arg(map_data->cell(iter, jter), 0, 'f', 6, ' ');
832  }
833  }
834 
835  return text;
836 }

◆ getColorMapPlotConfig()

const ColorMapPlotConfig & pappso::BaseColorMapPlotWidget::getColorMapPlotConfig ( )
virtual

Definition at line 104 of file basecolormapplotwidget.cpp.

105 {
106  return m_colorMapPlotConfig;
107 }

References m_colorMapPlotConfig.

◆ getOrigColorMapPlotConfig()

const ColorMapPlotConfig * pappso::BaseColorMapPlotWidget::getOrigColorMapPlotConfig ( )

Definition at line 97 of file basecolormapplotwidget.cpp.

98 {
100 }

References mpa_origColorMapPlotConfig.

◆ getPlottingColor()

QColor pappso::BaseColorMapPlotWidget::getPlottingColor ( int  index = 0) const
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 798 of file basecolormapplotwidget.cpp.

799 {
800  Q_UNUSED(index);
801 
802  QPen pen = xAxis->basePen();
803  return pen.color();
804 }

◆ setColorMapPlotConfig()

void pappso::BaseColorMapPlotWidget::setColorMapPlotConfig ( const ColorMapPlotConfig color_map_config)
virtual

Definition at line 89 of file basecolormapplotwidget.cpp.

91 {
92  m_colorMapPlotConfig = color_map_config;
93 }

References m_colorMapPlotConfig.

◆ setPlottingColor()

void pappso::BaseColorMapPlotWidget::setPlottingColor ( QCPAbstractPlottable *  plottable_p,
const QColor &  new_color 
)
overridevirtual

Reimplemented from pappso::BasePlotWidget.

Definition at line 766 of file basecolormapplotwidget.cpp.

768 {
769  Q_UNUSED(plottable_p);
770 
771  // The pen of the color map itself is of no use. Instead the user will see the
772  // color of the axes' labels.
773 
774  QPen pen = xAxis->basePen();
775  pen.setColor(new_color);
776 
777  xAxis->setBasePen(pen);
778  xAxis->setLabelColor(new_color);
779  xAxis->setTickLabelColor(new_color);
780 
781  yAxis->setBasePen(pen);
782  yAxis->setLabelColor(new_color);
783  yAxis->setTickLabelColor(new_color);
784 
785  // And now set the color map's pen to the same color, even if we do not use
786  // it, we need it for coloring the plots that might be integrated from this
787  // color map.
788 
789  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
790 
791  color_map_p->setPen(pen);
792 
793  replot();
794 }

◆ transposeAxes()

void pappso::BaseColorMapPlotWidget::transposeAxes ( )
virtual

Definition at line 263 of file basecolormapplotwidget.cpp.

264 {
265  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()" ;
266 
267  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
268 
269  QCPColorMapData *origData = color_map_p->data();
270 
271  int keySize = origData->keySize();
272  int valueSize = origData->valueSize();
273 
274  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
275  //<< "Orig data size:" << keySize << valueSize;
276 
277  QCPRange keyRange = origData->keyRange();
278  QCPRange valueRange = origData->valueRange();
279 
280  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
281  //<< "Value at cell 80,650:" << origData->cell(80,650);
282 
283  // Transposed map.
284  QCPColorMapData *newData =
285  new QCPColorMapData(valueSize, keySize, valueRange, keyRange);
286 
287  for(int iter = 0; iter < keySize; ++iter)
288  {
289  for(int jter = 0; jter < valueSize; ++jter)
290  {
291  double cellData = origData->cell(iter, jter);
292 
293  newData->setCell(jter, iter, cellData);
294  }
295  }
296 
297  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
298  //<< "New data size:" << newData->keySize() << newData->valueSize();
299 
300  // At this point the transposition has been done.
301 
302  color_map_p->data()->clear();
303  color_map_p->rescaleDataRange(true);
304 
305  // Now we need to invert the labels and data kinds.
306 
309  m_colorMapPlotConfig.yAxisDataKind = temp_data_kind;
310 
311  QString temp_axis_label = xAxis->label();
312  xAxis->setLabel(yAxis->label());
313  yAxis->setLabel(temp_axis_label);
314 
315  // Will take ownership of the newData.
316  color_map_p->setData(newData);
317 
318  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()"
319  //<< "Value at cell 80,650:" << newData->cell(80,650)
320  //<< "Value at cell 650, 80:" << newData->cell(650,80);
321 
322  // QCPAxis *p_keyAxis = mp_colorMap->keyAxis();
323  // QCPAxis *p_valueAxis = mp_colorMap->valueAxis();
324 
325  // mp_colorMap->setKeyAxis(p_valueAxis);
326  // mp_colorMap->setValueAxis(p_keyAxis);
327 
328  color_map_p->rescaleAxes();
329 
330  replot();
331 }
DataKind
Definition: types.h:171

References m_colorMapPlotConfig, pappso::ColorMapPlotConfig::xAxisDataKind, and pappso::ColorMapPlotConfig::yAxisDataKind.

◆ xAxisDataKind()

DataKind pappso::BaseColorMapPlotWidget::xAxisDataKind ( ) const

◆ xAxisScale()

AxisScale pappso::BaseColorMapPlotWidget::xAxisScale ( ) const

Definition at line 745 of file basecolormapplotwidget.cpp.

746 {
748 }

References m_colorMapPlotConfig, and pappso::ColorMapPlotConfig::xAxisScale.

◆ yAxisDataKind()

DataKind pappso::BaseColorMapPlotWidget::yAxisDataKind ( ) const

◆ yAxisScale()

AxisScale pappso::BaseColorMapPlotWidget::yAxisScale ( ) const

Definition at line 752 of file basecolormapplotwidget.cpp.

753 {
755 }

References m_colorMapPlotConfig, and pappso::ColorMapPlotConfig::yAxisScale.

◆ zAxisDataResetToOriginal()

void pappso::BaseColorMapPlotWidget::zAxisDataResetToOriginal ( )
virtual

Definition at line 676 of file basecolormapplotwidget.cpp.

677 {
678  // The user might have changed to the axis scale to log10, for example.
679  // While doing this, the original data were still available in
680  // mpa_origColorMapData,with mpa_origColorMapPlotConfig. We need to reset the
681  // current data to the original data.
682  //
683  // Same thing for filters that might have been applied to the data.
684 
685  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
686  color_map_p->data()->clear();
687 
688  if(mpa_origColorMapData == nullptr)
689  throw(PappsoException(
690  "Not possible that the mpa_origColorMapData pointer be null."));
691 
692  // We do no want that the color_map_p takes ownership of the data, because
693  // these must remain there always, so pass true, to say that we want to copy
694  // the data not transfer the pointer.
695  color_map_p->setData(mpa_origColorMapData, true);
696 
697  color_map_p->data()->recalculateDataBounds();
698  color_map_p->rescaleDataRange(true);
699 
700  // We should not do this, as the user might have zoomed to a region of
701  // interest.
702  // color_map_p->rescaleAxes();
703 
704  // Reset the current plot config to what it was originally. The member
705  // m_colorMapPlotConfig.zAxisScale is now AxisScale::orig.
707 
708  replot();
709 }

References m_colorMapPlotConfig, mpa_origColorMapData, and mpa_origColorMapPlotConfig.

◆ zAxisFilterHighPassPercentage()

void pappso::BaseColorMapPlotWidget::zAxisFilterHighPassPercentage ( double  threshold_percentage)
virtual

Definition at line 565 of file basecolormapplotwidget.cpp.

567 {
568  // This filter allows all the value greater than a threshold to remain
569  // unchanged. Instead, all the values below the threshold will be reset to
570  // that threshold value.
571  //
572  // The effect of this filter is to reduce the low-intensity signal: reduce
573  // noise.
574 
575  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
576 
577  QCPColorMapData *map_data = color_map_p->data();
578 
579  int keySize = map_data->keySize();
580  int valueSize = map_data->valueSize();
581 
582  QCPRange keyRange = map_data->keyRange();
583  QCPRange valueRange = map_data->valueRange();
584 
585  double minZValue = m_colorMapPlotConfig.lastMinZValue;
586  double maxZValue = m_colorMapPlotConfig.lastMaxZValue;
587 
588  double amplitude = maxZValue - minZValue;
589 
590  double amplitude_fraction = amplitude * threshold_percentage / 100;
591 
592  double threshold = minZValue + amplitude_fraction;
593 
594  //qDebug() << "Before filtering minZValue:" << minZValue
595  //<< "maxZValue:" << maxZValue << "fraction:" << fraction
596  //<< "threshold:" << threshold
597  //<< "new threshold percentage:" << new_threshold_percentage;
598 
599  // Make a copy of the current config so that we can modify
600  // the xxxZvalue values.
601  ColorMapPlotConfig new_color_map_plot_config(m_colorMapPlotConfig);
602 
603  // But we need to reset these two values to be able to update them using
604  // std::min() and std::max() below.
605  new_color_map_plot_config.lastMinZValue = std::numeric_limits<double>::max();
606  new_color_map_plot_config.lastMaxZValue = std::numeric_limits<double>::min();
607 
608  // Filtered
609  QCPColorMapData *new_map_data =
610  new QCPColorMapData(keySize, valueSize, keyRange, valueRange);
611 
612  for(int iter = 0; iter < keySize; ++iter)
613  {
614  for(int jter = 0; jter < valueSize; ++jter)
615  {
616  double cell_data = map_data->cell(iter, jter);
617 
618  double new_cell_data = 0;
619 
620  if(cell_data > threshold)
621  // Keep the value, we are in high-pass
622  new_cell_data = cell_data;
623  else
624  new_cell_data = threshold;
625 
626  // Store the new values here.
627  new_color_map_plot_config.lastMinZValue =
628  //(new_cell_data < new_color_map_plot_config.minZValue
629  //? new_cell_data
630  //: new_color_map_plot_config.minZValue);
631  std::min(new_color_map_plot_config.lastMinZValue, new_cell_data);
632 
633  new_color_map_plot_config.lastMaxZValue =
634  //(new_cell_data > new_color_map_plot_config.maxZValue
635  //? new_cell_data
636  //: new_color_map_plot_config.maxZValue);
637  std::max(new_color_map_plot_config.lastMaxZValue, new_cell_data);
638 
639  // qDebug() << "cell_data:" << cell_data
640  //<< "new_cell_data:" << new_cell_data
641  //<< "new_color_map_plot_config.minZValue:"
642  //<< new_color_map_plot_config.minZValue
643  //<< "new_color_map_plot_config.maxZValue:"
644  //<< new_color_map_plot_config.maxZValue;
645 
646  new_map_data->setCell(iter, jter, new_cell_data);
647  }
648  }
649 
650  color_map_p->data()->clear();
651 
652  // Will take ownership of the new_map_data.
653  color_map_p->setData(new_map_data);
654 
655  color_map_p->data()->recalculateDataBounds();
656  color_map_p->rescaleDataRange(true);
657 
658 
659  // At this point the new color map data have taken their place, we can update
660  // the config. This, way any new filtering can take advantage of the new
661  // values and compute the threshold correctly.
662  m_colorMapPlotConfig = new_color_map_plot_config;
663 
664  // qDebug() << "Member colormap plot config is now, after filter was applied:"
665  //<< m_colorMapPlotConfig.toString();
666 
667  // We should not do this, as the user might have zoomed to a region of
668  // interest.
669  // color_map_p->rescaleAxes();
670 
671  replot();
672 }

References pappso::ColorMapPlotConfig::lastMaxZValue, pappso::ColorMapPlotConfig::lastMinZValue, and m_colorMapPlotConfig.

◆ zAxisFilterLowPassPercentage()

void pappso::BaseColorMapPlotWidget::zAxisFilterLowPassPercentage ( double  threshold_percentage)
virtual

Definition at line 455 of file basecolormapplotwidget.cpp.

457 {
458  // This filter allows all the values smaller than a threshold to remain
459  // unchanged. Instead, all the values above the threshold will be reset to
460  // that threshold.
461  //
462  // The effect of this filter is to enhance the high-intensity signal.
463 
464  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
465 
466  QCPColorMapData *map_data = color_map_p->data();
467 
468  int keySize = map_data->keySize();
469  int valueSize = map_data->valueSize();
470 
471  QCPRange keyRange = map_data->keyRange();
472  QCPRange valueRange = map_data->valueRange();
473 
474  double minZValue = m_colorMapPlotConfig.lastMinZValue;
475  double maxZValue = m_colorMapPlotConfig.lastMaxZValue;
476 
477  double amplitude = maxZValue - minZValue;
478 
479  double amplitude_fraction = amplitude * threshold_percentage / 100;
480 
481  double threshold = minZValue + amplitude_fraction;
482 
483  //qDebug() << "Before filtering minZValue:" << minZValue
484  //<< "maxZValue:" << maxZValue << "fraction:" << fraction
485  //<< "threshold:" << threshold
486  //<< "new threshold percentage:" << new_threshold_percentage;
487 
488  // Make a copy of the current config so that we can modify
489  // the xxxZvalue values.
490  ColorMapPlotConfig new_color_map_plot_config(m_colorMapPlotConfig);
491 
492  // But we need to reset these two values to be able to update them using
493  // std::min() and std::max() below.
494  new_color_map_plot_config.lastMinZValue = std::numeric_limits<double>::max();
495  new_color_map_plot_config.lastMaxZValue = std::numeric_limits<double>::min();
496 
497  // Filtered
498  QCPColorMapData *new_map_data =
499  new QCPColorMapData(keySize, valueSize, keyRange, valueRange);
500 
501  for(int iter = 0; iter < keySize; ++iter)
502  {
503  for(int jter = 0; jter < valueSize; ++jter)
504  {
505  double cell_data = map_data->cell(iter, jter);
506 
507  double new_cell_data = 0;
508 
509  if(cell_data < threshold)
510  // Keep the value, we are in low-pass
511  new_cell_data = cell_data;
512  else
513  new_cell_data = threshold;
514 
515  // Store the new values here.
516  new_color_map_plot_config.lastMinZValue =
517  //(new_cell_data < new_color_map_plot_config.minZValue
518  //? new_cell_data
519  //: new_color_map_plot_config.minZValue);
520  std::min(new_color_map_plot_config.lastMinZValue, new_cell_data);
521 
522  new_color_map_plot_config.lastMaxZValue =
523  //(new_cell_data > new_color_map_plot_config.maxZValue
524  //? new_cell_data
525  //: new_color_map_plot_config.maxZValue);
526  std::max(new_color_map_plot_config.lastMaxZValue, new_cell_data);
527 
528  // qDebug() << "cell_data:" << cell_data
529  //<< "new_cell_data:" << new_cell_data
530  //<< "new_color_map_plot_config.minZValue:"
531  //<< new_color_map_plot_config.minZValue
532  //<< "new_color_map_plot_config.maxZValue:"
533  //<< new_color_map_plot_config.maxZValue;
534 
535  new_map_data->setCell(iter, jter, new_cell_data);
536  }
537  }
538 
539  color_map_p->data()->clear();
540 
541  // Will take ownership of the new_map_data.
542  color_map_p->setData(new_map_data);
543 
544  color_map_p->data()->recalculateDataBounds();
545  color_map_p->rescaleDataRange(true);
546 
547 
548  // At this point the new color map data have taken their place, we can update
549  // the config. This, way any new filtering can take advantage of the new
550  // values and compute the threshold correctly.
551  m_colorMapPlotConfig = new_color_map_plot_config;
552 
553  // qDebug() << "Member colormap plot config is now, after filter was applied:"
554  //<< m_colorMapPlotConfig.toString();
555 
556  // We should not do this, as the user might have zoomed to a region of
557  // interest.
558  // color_map_p->rescaleAxes();
559 
560  replot();
561 }

References pappso::ColorMapPlotConfig::lastMaxZValue, pappso::ColorMapPlotConfig::lastMinZValue, and m_colorMapPlotConfig.

◆ zAxisScale()

AxisScale pappso::BaseColorMapPlotWidget::zAxisScale ( ) const

Definition at line 759 of file basecolormapplotwidget.cpp.

760 {
762 }

References m_colorMapPlotConfig, and pappso::ColorMapPlotConfig::zAxisScale.

◆ zAxisScaleToLog10()

void pappso::BaseColorMapPlotWidget::zAxisScaleToLog10 ( )
virtual

Definition at line 335 of file basecolormapplotwidget.cpp.

336 {
337  // The user wants to rescale the intensity values of the color map according
338  // to: new_int = log10(orig_int).
339 
340  // qDebug() << __FILE__ << __LINE__ << __FUNCTION__ << "()" ;
341 
343  {
344  qDebug() << "Asking to change z axis scale to log10 while it is already "
345  "like so.";
346 
347  return;
348  }
349 
350  // qDebug() << "m_colorMapPlotConfig:" << m_colorMapPlotConfig.toString();
351 
352  QCPColorMap *color_map_p = static_cast<QCPColorMap *>(plottable(0));
353 
354  QCPColorMapData *map_data = color_map_p->data();
355 
356  int keySize = map_data->keySize();
357  int valueSize = map_data->valueSize();
358 
359  QCPRange keyRange = map_data->keyRange();
360  QCPRange valueRange = map_data->valueRange();
361 
362  // Make a copy of the current config so that we can modify
363  // the xxxZvalue values.
364  ColorMapPlotConfig new_color_map_plot_config(m_colorMapPlotConfig);
365 
366  // But we need to reset these two values to be able to update them using
367  // std::min() and std::max() below.
368  new_color_map_plot_config.setOrigAndLastMinZValue(
369  std::numeric_limits<double>::max());
370 
371  new_color_map_plot_config.setOrigAndLastMaxZValue(
372  std::numeric_limits<double>::min());
373 
374  // qDebug() << "new_color_map_plot_config"
375  //<< new_color_map_plot_config.toString();
376 
377  // Log-ified heat map.
378  QCPColorMapData *new_map_data =
379  new QCPColorMapData(keySize, valueSize, keyRange, valueRange);
380 
381  // qDebug() << "Starting iteration in the color map.";
382 
383  for(int iter = 0; iter < keySize; ++iter)
384  {
385  for(int jter = 0; jter < valueSize; ++jter)
386  {
387  double cell_data = map_data->cell(iter, jter);
388 
389  double new_cell_data = 0;
390 
391  if(!cell_data)
392  // The log10 would be -inf, but then we'd have a huge data range and
393  // the color map would look totally blue... that is like 0 intensity
394  // all over.
395  new_cell_data = -1;
396  else
397  new_cell_data = std::log10(cell_data);
398 
399  // Store the new values here. Should we change the last or orig or
400  // both ?
401  new_color_map_plot_config.lastMinZValue =
402  //(new_cell_data < new_color_map_plot_config.minZValue
403  //? new_cell_data
404  //: new_color_map_plot_config.minZValue);
405  std::min(new_color_map_plot_config.lastMinZValue, new_cell_data);
406 
407  new_color_map_plot_config.lastMaxZValue =
408  //(new_cell_data > new_color_map_plot_config.maxZValue
409  //? new_cell_data
410  //: new_color_map_plot_config.maxZValue);
411  std::max(new_color_map_plot_config.lastMaxZValue, new_cell_data);
412 
413  // qDebug() << "cell_data:" << cell_data
414  //<< "new_cell_data:" << new_cell_data
415  //<< "new_color_map_plot_config.minZValue:"
416  //<< new_color_map_plot_config.minZValue
417  //<< "new_color_map_plot_config.maxZValue:"
418  //<< new_color_map_plot_config.maxZValue;
419 
420  new_map_data->setCell(iter, jter, new_cell_data);
421  }
422  }
423 
424  // qDebug() << "Finished iteration in the color map.";
425 
426  color_map_p->data()->clear();
427 
428  // Will take ownership of the new_map_data.
429  color_map_p->setData(new_map_data);
430 
431  color_map_p->data()->recalculateDataBounds();
432  color_map_p->rescaleDataRange(true);
433 
434  // At this point the new color map data have taken their place, we can update
435  // the config. This, way any new filtering can take advantage of the new
436  // values and compute the threshold correctly.
437  m_colorMapPlotConfig = new_color_map_plot_config;
438 
439  // Now we need to document the change.
441 
442  // qDebug() << "new_color_map_plot_config"
443  //<< new_color_map_plot_config.toString();
444 
445  // qDebug() << "m_colorMapPlotConfig:" << m_colorMapPlotConfig.toString();
446 
447  // We should not do this, as the user might have zoomed to a region of
448  // interest.
449  // color_map_p->rescaleAxes();
450 
451  replot();
452 }

References pappso::ColorMapPlotConfig::lastMaxZValue, pappso::ColorMapPlotConfig::lastMinZValue, pappso::log10, m_colorMapPlotConfig, pappso::ColorMapPlotConfig::setOrigAndLastMaxZValue(), pappso::ColorMapPlotConfig::setOrigAndLastMinZValue(), and pappso::ColorMapPlotConfig::zAxisScale.

Member Data Documentation

◆ m_colorMapPlotConfig

◆ mpa_origColorMapData

QCPColorMapData* pappso::BaseColorMapPlotWidget::mpa_origColorMapData = nullptr
protected

◆ mpa_origColorMapPlotConfig

ColorMapPlotConfig* pappso::BaseColorMapPlotWidget::mpa_origColorMapPlotConfig = nullptr
protected

The documentation for this class was generated from the following files: