0026342: No materials are read from STEP
[occt.git] / dox / user_guides / voxels_wp / voxels_wp.md
CommitLineData
ba06f8bb 1Voxel Package {#occt_user_guides__voxels_wp}
bf62b306 2========================
3
4@tableofcontents
5
6@section occt_voxels_wp_1 Introduction
7
8 A voxel is a sub-volume box with constant scalar/vector value.
9 The object in voxel representation is split into many small sub-volumes (voxels)
10 and its properties are distributed through voxels.
11
12 Voxels are used for analysis and visualization of 3D-dimensional distribution of data.
13 Medicine (mainly, tomography), computational physics (hydrodynamics, aerodynamics, nuclear physics)
14 and many other industries use voxels for 3D data visualization and analysis of physical processes.
15
16 To produce a voxel representation the 3D space is split by equal intervals
17 along the main orthogonal coordinate axes to obtain nx x ny x nz voxels (small cubes):
18
dd21889e 19@image html voxels_wp_image003.png "A cube of 3 X 3 X 3  = 9 voxels."
20@image latex voxels_wp_image003.png "A cube of 3 X 3 X 3  = 9 voxels."
bf62b306 21
22 The data are attached to each voxel and remain the same within the voxel.
23 It means that we obtain the 3D space with discrete data distribution.
24
25 The number of voxels used in a calculation can vary.
26 An average model contains several tens of millions of voxels.
27 Such a great amount of data requires special algorithms of computation,
28 data containers keeping data in memory and visualization tools.
29
30 Open CASCADE Technology provides several basic data containers for voxels
31 with fast access to the data and optimal allocation of data in memory.
32
33 Also, a special visualization toolkit allows visualizing voxels
34 as colored or black/white points and cubes, displaying only the voxels
35 visible from the user's point of view.
36
dd21889e 37@image html voxels_wp_image004.png "A shape and its voxel representation"
38@image html voxels_wp_image005.png "A shape and its voxel representation"
39
40@image latex voxels_wp_image004.png "A shape and its voxel representation"
41@image latex voxels_wp_image005.png "A shape and its voxel representation"
bf62b306 42
43In these images a boundary representation is displayed to the left. In the center and to the right there are 3D discrete representations (or 3D discrete topology). Any solid shape can be translated into a voxel representation.
44
45@section occt_voxels_wp_2 Data structure
46
47 The data structure to store the voxels data is a special class which gives
48 fast access to the data of each voxel and allocates the data in an optimal way in the memory of a computer.
49
50 Fast access to the data is provided by means of bit-wise operators on the indices of internal arrays.
51
52 The optimal data allocation is reached through division
53 of the whole data set into data subsets and keeping only non-zero pieces of data in memory.
54
55 A voxel can contain different data types, 
56 but presently Open CASCADE Technology implements only several basic ones:
57 * 1 bit or Boolean data type – a voxel contains a flag: 0 or 1 (false or true).
58 * 4 bits or Color data type – a voxel contains a value occupying 4 bits.
59 It is an integer in the range of 0 .. 15. The data can be divided into 16 subsets and displayed by Color-voxels.
60 * 4 bytes or Float data type – a voxel contains a floating-point data type.
61
62 In addition, the data structures provide methods for calculation of a center point
63 by voxel indices and a reverse task – fast search of a voxel by a point inside the cube of voxels.
64
65@section occt_voxels_wp_3 Algorithms
66
67 There are two service classes implemented for data structures of voxels:
68
69 * Boolean operations – provides simple boolean operations on cubes of voxels (fuse and cut).
70 * Voxelization – the conversion of a geometrical model into its voxel representation.
71
72### Boolean operations
73
74Fusion and cutting of two cubes of voxels are performed the class *Voxel_BooleanOperations*. The cubes should have the same size and be split into voxels in the same way.
ba06f8bb 75* <i>\::Fuse()</i> summarizes the values of the corresponding voxels and limits the result by the upper limit (if succeeded).
76* <i>\::Cut()</i> subtracts the values of the corresponding voxels and limits the result by zero.
bf62b306 77
78### Voxelization
79
80A class *Voxel_Convert* converts a *TopoDS_Shape* into one of the voxel data structures filling the solid shape by non-zero values.
81
82The algorithm of voxelization generates only 1-bit or 4-bit voxels. Other data types may be obtained by conversion of voxels from one type to another.
83
84Voxelization of a shape is performed by means of computation of intersection points between lines filling the volume and triangulation of the shape. The lines are parallel to main orthogonal axes and can intersect the shape from different sides: along +X, +Y and/or +Z axes.
85
86The algorithm can run in multi-threaded mode (the number of threads is unlimited). The user can see an integer value indicating the progress of computation.
87
88@section occt_voxels_wp_4 Visualization
89
90 Visualization of voxels is not a simple task due to a great amount of data used for 3D analysis.
91
92 Open CASCADE Technology allows visualization of a cube of voxels in two modes:
93 * Points – the centers of voxels as 3D points.
94 * Boxes – the voxels as 3D cubes of adjustable size.
95
96 A degenerated mode displays only the points (boxes) visible
97 from the point of view of the user for transformation operations (zoom, pan and rotate).
98
99 To focus on a particular part of the model non-relevant voxels can be erased.
100 The displayed region is defined by six co-ordinates along X, Y and Z axes .
101
102 It is possible to display the voxels from a particular range of values (iso-volume):
103
dd21889e 104@image html voxels_wp_image006.png "Iso-volume of a shape"
105@image latex voxels_wp_image006.png "Iso-volume of a shape"
bf62b306 106
107The voxels are displayed by means of "direct drawing in Open GL" technology or "user draw" technology. Therefore, some visualization files are compiled within Open CASCADE Technology, but the files of "direct drawing" are compiled  by the end-user application.
108
109It is necessary to include the files *Voxel_VisData.h*, *VoxelClient_VisDrawer.h* and *VoxelClient_VisDrawer.cxx* into the visualization library of the application (containing all files of *OpenGl* package) and call the method *Voxel_VisDrawer::Init()* from the application before the visualization of voxels.
110
111@section occt_voxels_wp_5 Demo-application
112
113 A demonstration application has been created to show OCCT voxel models.
114 This is a test demo application because it includes a set of non-regression tests
115 and other commands for testing the functionality (accessible only through TEST pre-processor definition).
116
117 The *File* menu allows creation of canonical shapes (box, cylinder, sphere, torus) or loading of shapes in BREP format:
118
dd21889e 119@image html voxels_wp_image007.png "Demo-application. Creation or loading of a shape"
120@image latex voxels_wp_image007.png "Demo-application. Creation or loading of a shape"
bf62b306 121
122The menu *Converter* voxelizes the shape. Two types of voxels can be obtained: 1-bit or 4-bit voxels.
123 * 1-bit voxels are displayed in white color on black background.
124 * 4-bit voxels use 16 colors filling the model in a special way for demonstrative purposes:
125
dd21889e 126@image html voxels_wp_image008.png "Demo-application. Voxelization"
127@image latex voxels_wp_image008.png "Demo-application. Voxelization"
bf62b306 128
129 The converter uses two threads (two processors, if available) to perform voxelization.
130
131 The menu *Visualization* offers two modes of visualization: Points and Boxes,
132 allows defining the size of points and boxes (quadrangles),
133 the minimum and the maximum displayed color, and the boundaries of the bounding box for displayed voxels:
134
dd21889e 135@image html voxels_wp_image009.png "Demo-application. Visualization"
136@image latex voxels_wp_image009.png "Demo-application. Visualization"
bf62b306 137
138 The last menu, *Demo* contains a demo-command for running waves of 4-bit voxels:
139
dd21889e 140@image html voxels_wp_image010.png "Demo-application. Running waves"
141@image latex voxels_wp_image010.png "Demo-application. Running waves"
bf62b306 142
143@section occt_voxels_wp_6 Future development
144
145In the future OPEN CASCADE plans to develop the platform of voxels in the following directions:
146 * Data structure:
147 * Extension of the list of basic data types.
148 * Development of a deeper hierarchy of voxels (for example, octree – division of a voxel into 8 sub-voxels).
149 * Development of a doxel (4D voxels where the fourth co-ordinate is the time, for example).
150
151 * Algorithms:
152 * Conversion of a voxel model into a geometrical model (a reversed operation to voxelization).
153
154 * Visualization:
155 * Optimization of visualization (mainly, the speed of visualization).
156 * New shapes of voxel presentation in the 3D Viewer and new approaches to visualization.
157 * Selection of voxels.
158