A histogram is often useful to visualize the distribution of values in a volume data set.
The getHistogram() method in SoVolumeData returns a histogram for the volume as an array of integers and a count. The count is the number of bins in the histogram. Depending on the number of bins and the range of values the histogram represents, each bin may represent a single voxel value or a range of voxel values. When a volume is converted to LDM format, VolumeViz (by default) builds a histogram and stores the histogram in the LDM file header. When an application calls the getHistogram() method, VolumeViz asks the volume reader for the histogram. If the volume is in LDM format, the reader will normally have a histogram available (read from the file header) and the getHistogram() method returns quickly. Custom volume readers that have a pre-computed histogram can also satisfy this request quickly. For most volume data formats (and for in-memory volumes) the histogram must be computed by the getHistogram() method, which can take a lot of time for a large volume. In this case, if the application may need to re-use the histogram in subsequent runs, the application should store the histogram.
Internally VolumeViz uses the class SoVolumeHistogram to build and manage a histogram. Applications can also use this class directly to build and query a histogram. An instance of SoVolumeHistogram is not directly associated with an SoVolumeData node. Instead the SoVolumeHistogram builds a histogram from one or more buffers of data passed to the addValues() method. This allows the application to build a histogram for a region of a volume or even a single slice. The data access API (discussed in Data Access and Computing can be used to get the data from the volume.
The current implementation of SoVolumeHistogram has some limitations, in particular it is not possible to specify the number of bins in the histogram or the value range for integer data types. Applications using integer data types larger than one byte may wish to implement their own histogram computation to avoid these limitations.