Transfer Functions in Volume Rendering of Lake Water Quality Considering Frequency Distribution

: To explore the distribution and diffusion of pollutants in lakes, the volume rendering technique was used to express the lake water quality model in three dimensions. Due to the narrow distribution ranges and small spatial differences of the scalar field of the lake water quality mode, the perspective expression of subtle differences in the volume rendering process becomes important but difficult. In view of the foregoing case, this paper proposed transfer functions (TFs) in volume rendering of lake water quality considering the frequency distribution. The frequency distribution of the lake water quality scalar field was counted, the voxel ratios and the coloring probabilities of the frequency ranges were calculated, and then the voxel values were effectively mapped to colors and transparencies according to the coloring probabilities, to realize the refined expression of the differences in the spatial distribution of lake water quality. Experiments showed that the perspective expression of the subtle differences of lake (especially shallow lakes) water quality was improved using this method, which is conducive to analyzing the characteristics and changing laws of lake water quality model.


Introduction
Lake water quality models are usually visualized in three dimensions by mainly using surface rendering methods, including Marching Cubes (MC), Surface Tracking, and other methods, but these methods generally have the problem of occlusion of sight.
Volume rendering technique directly projects voxels to a display plane (Drebin et al., 1988), which can flexibly display the internal structure of objects and has the advantage of three-dimensional perspective. Volume rendering technique is applied to visualize a water quality model scientifically, so that the surface visualization of the water quality model is improved into the three-dimensional perspective expression by constructing a water quality volume model "from the surface to the inside", which is conducive to studying the current distribution and changes of pollutants in lakes, and is of significance to water pollution management and prevention.
Volume rendering technique has been widely used in the scientific visualization of marine, meteorological, geological, medical three-dimensional CT and other fields (Lee et al., 2011;Levoy, 1988;Lu and Sakamoto, 2019;Perandini et al., 2010), but is barely used in that of water environment. To apply volume rendering technique to the study of lake water quality, it is necessary to design the volume rendering process and parameters for the lake water quality model and pollutant characteristics. At present, there has been no research on volume rendering of lake water quality. In this case, due to the small scale of research on volume rendering of lake water quality and insignificant spatial distribution differences, especially the smaller spatial differences of shallow lake water quality, how to visually express the subtle differences and characteristics of spatial distribution of lake water quality becomes difficult.
With reference to the volume rendering techniques of scalar fields in the atmosphere and ocean related fields (Lee et al., 2011;Levoy, 1988), the ray casting (Ray and Pfister, 2002) was mainly used, and scalar values of the voxels were converted into optical properties such as colors and opacities by simulating a process in which light rays pass through the voxels, that is, scalar values, gradient values, curvatures and other information about voxel data were mapped to opacities and colors using the TFs, to visually explore the internal structure and distribution of objects were. Some scholars perform volume rendering of ocean temperature fields and salinity fields (Fe Ng and Han, 2018;Guo et al., 2007) by setting segment or linear TFs based on manual experience, to linearly map values to colors and transparencies. As a result, in most cases, voxels in the same range are rendered in the same color, and local subtle distribution differences and characteristics cannot be expressed.
With reference to geology, medical CT and other small-scale scene volume rendering techniques (Levoy, 1988), there are a lot of research on the improvement of local detail expression through optimized design of TFs in volume rendering. For example, some scholars, earlier, extracted and described the topological structure using Reeb diagram (Fujishiro et al., 1999), to optimize TFs according to values such as threedimensional values of the scalar field. Such a method is used mainly for a scalar field with a simple or regular spatial structure. Later, Smith et al. (Kindlmann et al., 2003) proposed that the TFs were optimized using curvatures, but the calculation process was complicated, which was likely to cause a calculation bottleneck of the volume rendering.
In particular, scholars such as Correa et al. (Correa and Ma, 2011) used histograms to guide the TF design, used CT intensity values to distinguish different media, counted the intensity changes of different medium edges using the intensity-gradient magnitude histogram to analyze the medium edges, obtaining different medium classification results, and determined the colors and transparencies according to different medium characteristics in the process of volume rendering, to obtain a better perspective expression effect. In the case of the fusion of lake water bodies and pollutants, and the insignificant differences between regions, although the histogram counting method is unlikely to distinguish pollutants, it is conducive to analyzing water quality concentration distribution and spatial distribution characteristics.
Therefore, it can be learned that the histogram is applied to the volume rendering of a scalar field of lake water quality. This paper proposed TFsin volume rendering of lake water quality considering the frequency distribution. The frequency distribution of the lake water quality scalar field was counted, the voxel ratios and the coloring probabilities of the frequency ranges were calculated, and then the voxel values were effectively mapped to colors and transparencies according to the coloring probabilities, to realize the refined expression of the differences in the spatial distribution of lake water quality. Finally, taking data of the water quality scalar field of Chaohu Lake in China as an example, TFs in volume rendering considering the frequency distribution, were used to realize the visualization of volume rendering of a multi-time series water quality scalar field and dynamic simulation experiments, and effectively explore the process of water pollution changes.

Methods
Volume rendering, considering the frequency distribution, of lake water quality is performed by three steps. First, construction of voxel model. A scalar field of a water quality chlorophyll grid was preprocessed to normalize the values to texture pixel values (RGBA). Linear spatial interpolations were used to improve the spatial smoothness of the scalar field. A three-dimensional voxel model was constructed using the scalar field of lake water quality. Second, transfer functions (TFs) generation based on a histogram. Each frequency voxel ratio was calculated. The coloring probabilities of frequency ranges were obtained. The frequency range color bands were generated based on the coloring probabilities. The mapping relationship between the scalar field data and transparencies was established. Third, light ray synthesis and image fusion.
The TFs were used to calculate the color and transparency of each voxel. Light rays were synthesized and images were fused according to the ray tracing in combination with the lighting model, and were finally outputted to a rendering window. The scalar field data of the lake water quality model were numerically simulated based on a regular grid system, and the simulation result data can be regarded as multitime series regular grid point data. During the process of volume rendering, a voxel model needed to be constructed based on the water quality scalar field data by the following steps.
(1) A three-dimensional grid scalar field was standardized. Grid values were standardized into three-dimensional texture pixel values (RGBA), that is, the grid data were standardized, in the min-max manner, into values in the range of [0, 1], and then were converted into pixel values. (2) Spatial interpolations of the three-dimensional grid scalar field were calculated. Linear interpolations were used for resampling. A discrete data field was transformed into a continuous data field to improve the data quality of the scalar field. (3) The three-dimensional voxel texture of irregular regions was constructed. Blank voxels were identified by determining empty and invalid values of the three-dimensional scalar field grid data. The blank voxels were filtered out according to the identification in the process of volume rendering. An effective voxel model was prepared for efficient volume rendering in irregular regions.

TF generation based on a histogram
First, the frequency distribution histogram was drawn by counting the numerical distribution characteristics of the water quality scalar field. Then, TFs in volume rendering of the lake water quality scalar field were generated according to the frequency of the numerical distribution.
(1) Drawing of frequency distribution histogram According to the standardized values in the three-dimensional voxel mode, the distribution of the voxels was counted to draw the frequency distribution histogram.
First, the standardized voxel model values were sorted in the ascending order to obtain the maximum and minimum values. Then, the voxel values were divided into a number of equal parts, the numerical range of each equal part was calculated, and the number of voxels was counted according to the ranges. Finally, a frequency distribution histogram was drawn according to the range frequency, and the histogram was used to clarify the numerical distribution frequency of each range, to affect the construction of the TF.

Statistics chart of Chaohu lake water quality
The steps of generating the TFs in the volume rendering of the lake water quality scalar field according to the frequency distribution are as follows: 1) The number of ranges N was determined according to range division of the frequency distribution histogram. In this case, corresponding color bands were initialized and set, and each range corresponds to a color band (C1-C2, C2-C3, ..., Ci-Ci+1, ..., and CN-CN+1).
2) According to the histogram, the number of voxels in each range was counted as a range frequency (F1, F2, ..., Fi, ..., and FN). The ratio of the range frequency value to the total number of voxels was counted as a voxel ratio of this range.
3) The voxel ratio of this range was used as a ratio of pixels to the entire mapped texture, so that a color band in the concentrated region occupied more pixels, ensuring more color grading levels.
4) The level of the global color band was set to P. The number of pixels in each color band was calculated according to the ratio of each color band.

5)
Each color band was generated cyclically. In addition, the color band was generated, using linear interpolations, based on the start color Ci and the end color Ci+1.
The end color of the previous color band is the start color of the next one.
6) According to the foregoing steps, the TFs were automatically generated, and the global color band was finally synthesized. The TF formulas based on numerical frequency statistics are as follows. is the start color of the i th color band, and +1 is the end color of the i th color band; and P is an adjustment constant, which represents the total number of pixels in all color bands, and ( ( , , ) , ( , , ) , ( , , ) ) are color values after the attribute value of the voxel at ( , , ) was mapped.
The color value obtained through calculation based on the TFs was stored as a texture picture. A mapped texture was found, through texture search in CPU, using normalized voxel values as texture coordinates. Then, a corresponding color was obtained according to the voxel values. As shown in the following figure, when a value of P was 256 (there are a total of 256 levels of final color band pixels), a value of N was 10 (10 ranges divided), and a value of C was ['#8B00FF', '#0000FF', '#00FFFF', '#008800', '#00FF00', '#FFFF00', '#FF7F00', '#FF5500', '#FF8888', '#FF0000', or '#880000'], the TFs were generated using the foregoing method, and color values were stored as texture pictures.
When the transparencies in volume rendering were set, considering the attenuation effect of light rays in the process of propagation in water, the relationship between water quality chlorophyll content and a three-dimensional voxel transparency was created, and TFs involving water depths, chlorophyll content, numerical frequency ranges, and voxel transparencies were set. Moreover, the perspective rendering of lake water quality was realized using ray casting method.

Light ray synthesis and image fusion
The color values and opacities of sampling points of cast light rays were synthesized, to obtain the color values of screen pixels. Specifically, the color values and opacities of the sampling points were accumulated and synthesized along the directions of the cast light rays in the order from front to back. The synthesis formulas are as follows: where a value of is in the range of (1， ) , and represent the color In this paper, classification was performed in a texture-dependent manner, that is, after the re-sampling phase based on the ray casting, classification was performed to obtain the color values and opacities.

Results
In this experiment, JavaScript language was used. The volume rendering experiment of lake water quality model was carried out using Web Graphics Library.
The experiment region was Chaohu Lake, Anhui Province, China. A chlorophyll scalar field that was generated using a Chaohu Lake three-dimensional water quality model was used as experimental data. The scalar field includes 330 × 66 × 5 grid points, and each grid point identifies the chlorophyll content of the water body. The data were divided into 5 layers under water. In this paper, comparing the segment TF, the linear TF and the method of this paper, experiments were performed from three aspects: color expression, perspective expression, and water quality sequence changes of volume rendering.
(1) Comparative analysis of color expression In Fig. 3 (a), colors were divided, using the segment coloring TF, according to the voxel value ranges, to perform volume rendering. In the experiment, 10 range color bands corresponding to ten numerical ranges [0, 0.1, 0.2, …, 1.0] respectively were used. Significant color segmentations were shown in the volume rendering result. In Fig. 3 (b), on the basis of the segment TF, the linear TF was obtained using linear interpolations. Voxel values were linearly mapped to colors, but there was a problem that the color discrimination of the data set was insignificant. In Fig. 3 (c), in the method of this paper, the TFs was generated based on numerical statistics. High-frequency regions were divided with more color levels to ensure that the numerically concentrated regions have a better stratification effect and better reflect the subtle differences in the spatial distribution of the data. Fig. 3 (c) is better than Fig. 3 (a) and Fig. 3 (b).
(2) Comparative analysis of perspective expression Based on the TFs in volume rendering, the effects of transparencies on volume rendering were compared and analyzed. The direct ray casting method was used for Fig. 3 (a) Segment transfer function Fig. 3 (b) Linear transfer function Fig. 3 (c) Method of this paper volume rendering, to further analyze the range distribution of lake water quality scalar field. In terms of perspective analysis, in Fig. 3 (c), in the method of this paper, considering the effect of water depth on light attenuation, the values were mapped to voxel transparencies according to the frequency distribution, with an effect better than these in Fig. 3 (a) and Fig. 3 (b). Multi-time series data were used to analyze the water quality changes of Chaohu Lake, 8 time periods at equal intervals were selected, and the segment TF (Fig. 5 a), the linear TF (Fig. 5 b), and the method of this paper (Fig. 5 c) were used to perform volume rendering, obtaining three sets of 8 diagrams of spatio-temporal changes from left to right and top to bottom, which show that over time, lake pollutants gradually spread from west to east. Through comparison, in Fig. 5 c, the expression is more delicate with richer characteristics details, and the change trend of water quality concentration and the temporal and spatial characteristics of pollutant diffusion are better presented, with effects significantly better than these in Fig. 5 a and Fig. 5 b.

Discussion
To analyze the distribution and diffusion of underwater pollutants in the lake water quality model, the volume rendering technique is applied to this model, which is carried out with reference to the volume rendering methods in the ocean, meteorology and other fields, and it is found that the differences in the spatial distribution of lake water quality are difficult to express in a refined manner. The discussion is divided into two parts: discussion of method characteristics and discussion of experimental results Transfer functions (TFs) determine the volume rendering result and are an effective method to convert volume data into colors or transparencies (Ray and Pfister, 2002). In the TF design, in some studies, the gradient intensity histogram is used to analyze material boundary regions. The maximum value of the gradient indicates a boundary of a material, and the minimum value of the gradient indicates the inside of the material, which may be either the inside of two types of materials or that of different regions of the same material. Based on this feature, the intensity gradient histogram is used as a theoretical guide to design the TFs.

Discussion of method characteristics
The frequency distribution histogram is used to study the TFs in volume rendering of lake water quality. This method has many excellent characteristics in terms of refined color expression, perspective expression of multi-layer water quality, and TF generation efficiency.
(1) The frequency distribution histogram is the basis on which the colors are expressed in a refined manner using the TFs. The ratio of voxels in each range is calculated by counting numerical frequency distribution. An increasingly high ratio indicates an increasing quantity of voxels in a range, and therefore, more color levels need to be divided to directly guide value range division and level division using TFs.
For example, Fig. 2 shows a histogram in which the frequency distribution of the chlorophyll content scalar field of lake water quality is shown. In Fig.2, there are more than 450 voxels in the range [0.17, 0.22], the voxel ratio is the highest, and therefore, the probability of color expression is higher, which is convenient for refined expression of voxel characteristics in this range.
(2) Opacity synthesis effectively realizes the refined perspective expression of multi-layer water quality. Concentrations of water quality pollutants and underwater depths are mainly considered to map opacity and synthesize light rays. On the one hand, pollutants with greater concentrations are more opaque, and functions for converting chlorophyll content and voxel transparency conversion are set; on the other hand, considering the attenuation effect of light rays during the propagation underwater, water depths were set as positive correlation variables of voxel transparencies, ray casting method was used to realize volume rendering of multi-temporal lake water quality scalar field, which is helpful to study the stratification effect of the water scalar field at different depths, and lighting effects such as light reflection and scattering are used to improve volume rendering results (Deakin and Knackstedt, 2020).
(3) The method for designing frequency distribution greatly improves the efficiency of generating the TFs. Because occlusion, nonlinear mixing, and complex factors such as mixed specific regions exist during volume data visualization, a lot of manual experiments are required to set the TFs. By adjusting the TFs, the subtle differences and characteristics in the volume data are shown to find visualization results matching the characteristics of the volume data. However, it is difficult to obtain limitedly optimized TFs. By using the frequency distribution method, not only the local subtle differences and characteristics of the scalar field are improved, but also the TFs are automatically generated, greatly improving the efficiency of generating the TFs in volume rendering of the scalar field.

Discussion of experimental results
Experiments show that compared with conventional the linear TF, TFs, considering the frequency distribution, in the volume rendering show better performance and effects.
(1) In terms of color expression, Fig. 3 (c) is better than Fig. 3 (a) and (b). As shown in Fig. 3 (a), the segment TF is used to perform coloring at different levels. Due to the uniform distribution of color bands, subtle differences in numerically concentrated regions cannot be distinguished, and the noncontinuous segmented color bands lead to segmentation of volume rendering colors, which is not conducive to stratification expression and perspective analysis in detail; as shown in Fig. 3 (b), the conventional linear TF is used without considering the value distribution. As a result, the color discrimination in numerically concentrated regions is small, which is not conducive to analyzing the characteristics of data distribution; and as shown in Fig. 3 (c), the method of this paper is used to allocate color bands according to the numerical frequency ranges and convert the numerical range frequency into the color expression probability, greatly improving the refined expression and the color discrimination effect of volume rendering of the lake water quality.
(2) In terms of perspective expression, as shown in Fig. 4, the scalar field values are mapped to the transparencies of volume rendering, achieving a good rendering effect. As shown in Fig. 4 (a) and (b), the chlorophyll content is linearly mapped to the opacity, but the perspective effect is not obvious, and the difference in the layered distribution of water quality cannot be seen; In Fig. 4 (c), considering the attenuation effect of light rays during the propagation underwater, the method of this paper is used to set functions of converting water depths, chlorophyll content, and voxel transparencies. In addition, the ray casting method is used to realize the perspective analysis of lake water quality, significantly improving the perspective effect of the scalar field of the water body at different depths.
As shown in Fig. 5 (a) and (b), due to the rough expression of colors and transparencies, in space, of the segment TF and the linear TF, the characteristics of subtle temporal changes of water quality cannot be fully expressed. As shown in Fig. 5 (c), the method of this paper is used to fully present the characteristics of lake water quality changes over time, with the effect better than these of the segment TF and the linear TF, which is conducive to the refined expression of the spatial distribution of lake water quality.

Conclusion
In this paper, the volume rendering method was first applied to the threedimensional visual analysis of the water quality of shallow lakes. This method is used to construct a water quality scalar field model "from the surface to the inside", and is able to express any sectioned layer or surface of water quality of water environments, compared with the traditional rendering method in which only the exterior surface of water quality is visualized. In the application process, according to the spatial distribution characteristics of shallow lake water quality, transfer functions (TFs), considering the frequency distribution, in volume rendering were designed to map data of the lake water quality to colors and transparencies scientifically and reasonably, optimizing subtle expression of volume rendering of lake water quality, and providing an effective visual method for analyzing water quality changes in multi-time series.