Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2008-05-11 |
2 | // Created by: Vladislav ROMASHKO | |
3 | // Copyright (c) 2008-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
7fd59977 | 20 | |
21 | #include <Voxel_DS.ixx> | |
22 | ||
23 | // Empty constructor | |
24 | Voxel_DS::Voxel_DS() | |
25 | :myData(0), | |
26 | myX(0.0),myY(0.0),myZ(0.0), | |
27 | myXLen(0.0),myYLen(0.0),myZLen(0.0), | |
28 | myNbX(0),myNbY(0),myNbZ(0), | |
29 | myNbXY(0),myDX(0.0),myDY(0.0),myDZ(0.0), | |
30 | myHalfDX(0.0),myHalfDY(0.0),myHalfDZ(0.0) | |
31 | { | |
32 | ||
33 | } | |
34 | ||
35 | // Constructor with intialization. | |
36 | Voxel_DS::Voxel_DS(const Standard_Real x, const Standard_Real y, const Standard_Real z, | |
37 | const Standard_Real xlen, const Standard_Real ylen, const Standard_Real zlen, | |
38 | const Standard_Integer nbx, const Standard_Integer nby, const Standard_Integer nbz) | |
39 | { | |
40 | Init(x, y, z, xlen, ylen, zlen, nbx, nby, nbz); | |
41 | } | |
42 | ||
43 | // Initialization. | |
44 | void Voxel_DS::Init(const Standard_Real x, const Standard_Real y, const Standard_Real z, | |
45 | const Standard_Real xlen, const Standard_Real ylen, const Standard_Real zlen, | |
46 | const Standard_Integer nbx, const Standard_Integer nby, const Standard_Integer nbz) | |
47 | { | |
48 | myX = x; | |
49 | myY = y; | |
50 | myZ = z; | |
51 | myXLen = xlen; | |
52 | myYLen = ylen; | |
53 | myZLen = zlen; | |
54 | myNbX = nbx; | |
55 | myNbY = nby; | |
56 | myNbZ = nbz; | |
57 | myNbXY = myNbX * myNbY; | |
58 | myDX = myXLen / (Standard_Real) myNbX; | |
59 | myDY = myYLen / (Standard_Real) myNbY; | |
60 | myDZ = myZLen / (Standard_Real) myNbZ; | |
61 | myHalfDX = myDX / 2.0; | |
62 | myHalfDY = myDY / 2.0; | |
63 | myHalfDZ = myDZ / 2.0; | |
64 | } | |
65 | ||
66 | // Get the initial information on voxels | |
67 | Standard_Real Voxel_DS::GetX() const | |
68 | { | |
69 | return myX; | |
70 | } | |
71 | ||
72 | Standard_Real Voxel_DS::GetY() const | |
73 | { | |
74 | return myY; | |
75 | } | |
76 | ||
77 | Standard_Real Voxel_DS::GetZ() const | |
78 | { | |
79 | return myZ; | |
80 | } | |
81 | ||
82 | Standard_Real Voxel_DS::GetXLen() const | |
83 | { | |
84 | return myXLen; | |
85 | } | |
86 | ||
87 | Standard_Real Voxel_DS::GetYLen() const | |
88 | { | |
89 | return myYLen; | |
90 | } | |
91 | ||
92 | Standard_Real Voxel_DS::GetZLen() const | |
93 | { | |
94 | return myZLen; | |
95 | } | |
96 | ||
97 | Standard_Integer Voxel_DS::GetNbX() const | |
98 | { | |
99 | return myNbX; | |
100 | } | |
101 | ||
102 | Standard_Integer Voxel_DS::GetNbY() const | |
103 | { | |
104 | return myNbY; | |
105 | } | |
106 | ||
107 | Standard_Integer Voxel_DS::GetNbZ() const | |
108 | { | |
109 | return myNbZ; | |
110 | } | |
111 | ||
112 | void Voxel_DS::GetCenter(const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, | |
113 | Standard_Real& xc, Standard_Real& yc, Standard_Real& zc) const | |
114 | { | |
31065946 P |
115 | GetOrigin(ix, iy, iz, xc, yc, zc); |
116 | xc += myHalfDX; | |
117 | yc += myHalfDY; | |
118 | zc += myHalfDZ; | |
119 | } | |
120 | ||
121 | void Voxel_DS::GetOrigin(const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, | |
122 | Standard_Real& x0, Standard_Real& y0, Standard_Real& z0) const | |
123 | { | |
124 | x0 = myX + ix * myDX; | |
125 | y0 = myY + iy * myDY; | |
126 | z0 = myZ + iz * myDZ; | |
7fd59977 | 127 | } |
128 | ||
129 | // The method uses a chordial approach to find the index of voxel by co-ordinate. | |
130 | static Standard_Integer findIndex(const Standard_Real xstart, const Standard_Real dx, | |
131 | const Standard_Integer ix1, const Standard_Integer ix2, | |
132 | const Standard_Real x) | |
133 | { | |
134 | if (ix2 - ix1 < 2) | |
135 | { | |
136 | if (x < xstart + ix2 * dx) | |
137 | return ix1; | |
138 | return ix2; | |
139 | } | |
140 | ||
141 | // Middle index | |
142 | const Standard_Integer ixm = (ix1 + ix2) / 2; | |
143 | ||
144 | // Check if it is in the first half: | |
145 | if (x >= xstart + ix1 * dx && x < xstart + ixm * dx) | |
146 | { | |
147 | return findIndex(xstart, dx, ix1, ixm, x); | |
148 | } | |
149 | ||
150 | return findIndex(xstart, dx, ixm, ix2, x); | |
151 | } | |
152 | ||
153 | Standard_Boolean Voxel_DS::GetVoxel(const Standard_Real x, const Standard_Real y, const Standard_Real z, | |
154 | Standard_Integer& ix, Standard_Integer& iy, Standard_Integer& iz) const | |
155 | { | |
156 | // X | |
157 | if (!GetVoxelX(x, ix)) | |
158 | return Standard_False; | |
159 | ||
160 | // Y | |
161 | if (!GetVoxelY(y, iy)) | |
162 | return Standard_False; | |
163 | ||
164 | // Z | |
165 | return GetVoxelZ(z, iz); | |
166 | } | |
167 | ||
168 | Standard_Boolean Voxel_DS::GetVoxelX(const Standard_Real x, | |
169 | Standard_Integer& ix) const | |
170 | { | |
171 | // X | |
172 | if (x < myX || x > myX + myXLen) | |
173 | return Standard_False; | |
174 | ix = findIndex(myX, myXLen / (Standard_Real) myNbX, 0, myNbX - 1, x); | |
175 | return Standard_True; | |
176 | } | |
177 | ||
178 | Standard_Boolean Voxel_DS::GetVoxelY(const Standard_Real y, | |
179 | Standard_Integer& iy) const | |
180 | { | |
181 | // Y | |
182 | if (y < myY || y > myY + myYLen) | |
183 | return Standard_False; | |
184 | iy = findIndex(myY, myYLen / (Standard_Real) myNbY, 0, myNbY - 1, y); | |
185 | return Standard_True; | |
186 | } | |
187 | ||
188 | Standard_Boolean Voxel_DS::GetVoxelZ(const Standard_Real z, | |
189 | Standard_Integer& iz) const | |
190 | { | |
191 | // Z | |
192 | if (z < myZ || z > myZ + myZLen) | |
193 | return Standard_False; | |
194 | iz = findIndex(myZ, myZLen / (Standard_Real) myNbZ, 0, myNbZ - 1, z); | |
195 | return Standard_True; | |
196 | } |