VivoQuant 6.5.0
Loading...
Searching...
No Matches
HistogramForm Class Reference

Description

Histogram tool. Plots the intensity distribution of a dataset, optionally restricted to one ROI of the active ROI layer with the ROI Filter.

The tool can be driven from a script without being shown:

var h = VQ.histogramTool();
h.setDataset(VQ.index(0)); // or h.setDataset(0) for leaf 0
h.setNumBins(64);
h.setRange(0, 1000);
h.setROIByName("Heart"); // or h.setROI(1); h.setROI(-1) turns the ROI filter off
h.setChannel(4); // RGB data only: 0 backing, 1 red, 2 green, 3 blue, 4 all three
var r = h.getHistogram(); // { dataset, roi, min, max, binStep, binStarts:[], counts:[] }
h.saveCSVFile("C:/tmp/heart_hist.csv");

See also VQ.histogramTool() to obtain this object, and the Histogram Tool example.

Classes

struct  RangeEnd
 One end of the range: the Min or Max box, and the exact value last put in it. More...

Public Types

enum  Channel

Public Slots

void showDataset ()
 Recomputes the plot with the current settings.
void saveCSVFile (string fileName)
 Saves the histogram as CSV: one line per bin, "binStart,count".
void savePDFFile (string fileName)
 Saves the histogram plot as a PDF.
void refreshROIs ()
 Rebuilds the ROI selector from the global ROI object, keeping the current selection by name where possible. Hides the selector when there are no ROIs.
void reload ()
 Rebuilds the ROI selector and recomputes the plot. Called on show; launchers should call it when the dialog is already visible, since show() then sends no showEvent.

Public Member Functions

int currentIndex ()
 Top-level row selected in the dataset combo box.
Index currentDataIndex ()
 Data being plotted: a dynamic frame set by setDataset(), otherwise the top-level row's active image.
QList< double > getValues (Index idx, int numValues, float min, float max, float &binStep)
 Computes raw bin counts for the given dataset index and range.
QList< double > getValues (int idx, int numValues, float min, float max, float &binStep)
float getMin ()
 Left edge of the histogram range (inclusive lower bound of the first bin).
float getMax ()
 Right edge of the histogram range (inclusive upper bound; voxels at exactly max land in the last bin).
bool setDataset (Index idx)
 Selects the dataset to plot.
bool setDataset (int i)
 Selects the dataset to plot.
Index getDataset ()
 Returns the index of the data being plotted (see VQ.index()), invalid if none.
void setNumBins (int n)
 Sets the number of bins.
int getNumBins ()
 Returns the number of bins.
void setRange (double min, double max)
 Sets the histogram range and replots.
void resetRange ()
 Sets the histogram range to the min/max of the current dataset and replots.
bool setROILayer (int layerID)
 Uses a specific ROI layer instead of the active one.
int getROILayer ()
 Returns the ROI layer in use, or -1 when following the active layer.
bool setROI (int roiID)
 Restricts the histogram to one ROI of the ROI layer and turns the ROI filter on.
bool setROIByName (string name)
 Restricts the histogram to the ROI with the given name.
void setROIFilterEnabled (bool on)
 Turns the ROI filter on or off, keeping the selected ROI. Turning it on with nothing selected picks the first ROI. If no ROI exists yet, the first one is picked once it appears.
bool isROIFilterEnabled ()
 Returns whether the ROI filter is on.
int getROI ()
 Returns the selected ROI label value, or -1 when the ROI filter is off.
bool hasROIs ()
 Returns whether ROIs are available for the histogram.
bool setChannel (int channel)
 Selects which values of RGB data are used.
int getChannel ()
 Returns the channel used for the current dataset: the selected one for RGB data, otherwise 0 (backing).
VariantMap getHistogram ()
 Computes the histogram with the current settings.
void setupROIs (TRasterUChar *)
 Kept for backwards compatibility; the argument is ignored, equivalent to refreshROIs().

Static Public Attributes

static constexpr int NO_ROI = -1
 ROI value meaning "no ROI restriction" (ROI filter group box unchecked).
static constexpr int ACTIVE_LAYER = -1
 Layer value meaning "follow the active ROI layer".

Protected Member Functions

ROILayer * roiLayer ()
 Resolves the ROI layer on every use, since the ROI object can be replaced or deleted.
int channelFor (Index idx)
 Channel used for the given data: the selected one for RGB data, otherwise CHANNEL_BACKING.
bool currentDataRange (float &min, float &max)
 Min/max of the values the histogram uses for the current dataset (see Channel).
void updateChannelSelector (Index idx)
 Shows the channel selector for RGB data and names the backing channel.

Protected Attributes

QPersistentModelIndex m_dataIndex
 Set by setDataset() to pin a specific (possibly dynamic child) index; cleared when the combo changes.

Member Enumeration Documentation

◆ Channel

enum Channel

Values the histogram is computed from. Only RGB data offers a choice; other data always uses its (backing) values. CHANNEL_RGB counts all three colour values of each voxel.

Member Function Documentation

◆ getHistogram()

VariantMap getHistogram ( )

Computes the histogram with the current settings.

Returns
{ dataset, roi, channel, min, max, binStep, binStarts: [...], counts: [...] }, empty on error. dataset is the index as a string, e.g. "0", or "0.3" for frame 3 of dynamic data set 0

◆ getValues() [1/2]

QList< double > getValues ( Index idx,
int numValues,
float min,
float max,
float & binStep )

Computes raw bin counts for the given dataset index and range.

Parameters
idxData index (see currentDataIndex())
numValuesNumber of bins
minLeft edge of the first bin (inclusive)
maxRight edge of the last bin (inclusive; the interval is [min, max])
binStepOutput: width of each bin, set to (max-min)/numValues
Returns
Per-bin counts, or an empty list if the data or ROI is unavailable. Voxels outside [min, max] are excluded and do not accumulate in the edge bins.

◆ getValues() [2/2]

QList< double > getValues ( int idx,
int numValues,
float min,
float max,
float & binStep )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
idxTop-level row in the Data Manager (active image for dynamic data)

◆ saveCSVFile

void saveCSVFile ( string fileName)
slot

Saves the histogram as CSV: one line per bin, "binStart,count".

Parameters
fileNameFull path of the output file
Note
Bin start is written with 3 decimal places; count is written as an integer.

◆ savePDFFile

void savePDFFile ( string fileName)
slot

Saves the histogram plot as a PDF.

Parameters
fileNameFull path of the output file

◆ setChannel()

bool setChannel ( int channel)

Selects which values of RGB data are used.

Parameters
channel0 backing channel (default), 1 red, 2 green, 3 blue, 4 all three colour channels
Returns
false if the value is out of range
Note
Data without RGB values always uses its backing values; see getChannel()

◆ setDataset() [1/2]

bool setDataset ( Index idx)

Selects the dataset to plot.

Parameters
idxIndex of data (see VQ.index())
Returns
false if the index is not valid

◆ setDataset() [2/2]

bool setDataset ( int i)

Selects the dataset to plot.

Parameters
iIndex of the leaf in the data manager
Returns
false if the index is not valid

◆ setRange()

void setRange ( double min,
double max )

Sets the histogram range and replots.

Parameters
minLeft edge of the first bin (inclusive)
maxRight edge of the last bin (inclusive)
Note
Voxels outside [min, max] are excluded from all bins entirely; they do not accumulate in the first or last bin.

◆ setROI()

bool setROI ( int roiID)

Restricts the histogram to one ROI of the ROI layer and turns the ROI filter on.

Parameters
roiIDROI label value (0 = background), or -1 to turn the ROI filter off
Returns
false if the ID is unknown in the current layer
Note
The cbROI combo index equals the ROI id, so selecting it directly (e.g. through ThreeDimROIOperator::getHistogramWidget("cbROI")) is equivalent and also turns the filter on.

◆ setROIByName()

bool setROIByName ( string name)

Restricts the histogram to the ROI with the given name.

Returns
false if no ROI with that name exists in the layer

◆ setROILayer()

bool setROILayer ( int layerID)

Uses a specific ROI layer instead of the active one.

Parameters
layerIDLayer index, or -1 to follow the active layer (default)
Returns
false if the layer does not exist