1 // Created on: 2008-05-21
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 2008-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <Voxel_BooleanOperation.ixx>
22 #include <Precision.hxx>
24 Voxel_BooleanOperation::Voxel_BooleanOperation()
29 Standard_Boolean Voxel_BooleanOperation::Fuse( Voxel_BoolDS& theVoxels1,
30 const Voxel_BoolDS& theVoxels2) const
33 if (!Check(theVoxels1, theVoxels2))
34 return Standard_False;
36 // Take the values of the second cube and put them to the first one.
37 Standard_Integer ix, iy, iz;
38 for (iz = 0; iz < theVoxels2.GetNbZ(); iz++)
40 for (iy = 0; iy < theVoxels2.GetNbY(); iy++)
42 for (ix = 0; ix < theVoxels2.GetNbX(); ix++)
44 Standard_Boolean value2 = theVoxels2.Get(ix, iy, iz);
46 theVoxels1.Set(ix, iy, iz, value2);
54 Standard_Boolean Voxel_BooleanOperation::Fuse( Voxel_ColorDS& theVoxels1,
55 const Voxel_ColorDS& theVoxels2) const
58 if (!Check(theVoxels1, theVoxels2))
59 return Standard_False;
61 // Take the values of the second cube and put them to the first one.
62 Standard_Integer ix, iy, iz;
63 for (iz = 0; iz < theVoxels2.GetNbZ(); iz++)
65 for (iy = 0; iy < theVoxels2.GetNbY(); iy++)
67 for (ix = 0; ix < theVoxels2.GetNbX(); ix++)
69 Standard_Byte value2 = theVoxels2.Get(ix, iy, iz);
72 Standard_Byte value1 = theVoxels1.Get(ix, iy, iz);
73 Standard_Byte value = value1 + value2;
76 theVoxels1.Set(ix, iy, iz, value);
85 Standard_Boolean Voxel_BooleanOperation::Fuse( Voxel_FloatDS& theVoxels1,
86 const Voxel_FloatDS& theVoxels2) const
89 if (!Check(theVoxels1, theVoxels2))
90 return Standard_False;
92 // Take the values of the second cube and put them to the first one.
93 Standard_Integer ix, iy, iz;
94 for (iz = 0; iz < theVoxels2.GetNbZ(); iz++)
96 for (iy = 0; iy < theVoxels2.GetNbY(); iy++)
98 for (ix = 0; ix < theVoxels2.GetNbX(); ix++)
100 Standard_ShortReal value2 = theVoxels2.Get(ix, iy, iz);
103 Standard_ShortReal value1 = theVoxels1.Get(ix, iy, iz);
104 theVoxels1.Set(ix, iy, iz, value1 + value2);
110 return Standard_True;
113 Standard_Boolean Voxel_BooleanOperation::Cut( Voxel_BoolDS& theVoxels1,
114 const Voxel_BoolDS& theVoxels2) const
117 if (!Check(theVoxels1, theVoxels2))
118 return Standard_False;
120 // Subtract the values.
121 Standard_Integer ix, iy, iz;
122 for (iz = 0; iz < theVoxels2.GetNbZ(); iz++)
124 for (iy = 0; iy < theVoxels2.GetNbY(); iy++)
126 for (ix = 0; ix < theVoxels2.GetNbX(); ix++)
128 Standard_Boolean value1 = theVoxels1.Get(ix, iy, iz);
131 Standard_Boolean value2 = theVoxels2.Get(ix, iy, iz);
133 theVoxels1.Set(ix, iy, iz, Standard_False);
139 return Standard_True;
142 Standard_Boolean Voxel_BooleanOperation::Cut( Voxel_ColorDS& theVoxels1,
143 const Voxel_ColorDS& theVoxels2) const
146 if (!Check(theVoxels1, theVoxels2))
147 return Standard_False;
149 // Subtract the values.
150 Standard_Integer ix, iy, iz;
151 for (iz = 0; iz < theVoxels2.GetNbZ(); iz++)
153 for (iy = 0; iy < theVoxels2.GetNbY(); iy++)
155 for (ix = 0; ix < theVoxels2.GetNbX(); ix++)
157 Standard_Byte value2 = theVoxels2.Get(ix, iy, iz);
160 Standard_Byte value1 = theVoxels1.Get(ix, iy, iz);
163 Standard_Integer value = value1 - value2;
166 theVoxels1.Set(ix, iy, iz, value);
173 return Standard_True;
176 Standard_Boolean Voxel_BooleanOperation::Cut( Voxel_FloatDS& theVoxels1,
177 const Voxel_FloatDS& theVoxels2) const
180 if (!Check(theVoxels1, theVoxels2))
181 return Standard_False;
183 // Subtract the values.
184 Standard_Integer ix, iy, iz;
185 for (iz = 0; iz < theVoxels2.GetNbZ(); iz++)
187 for (iy = 0; iy < theVoxels2.GetNbY(); iy++)
189 for (ix = 0; ix < theVoxels2.GetNbX(); ix++)
191 Standard_ShortReal value2 = theVoxels2.Get(ix, iy, iz);
194 Standard_ShortReal value1 = theVoxels1.Get(ix, iy, iz);
195 theVoxels1.Set(ix, iy, iz, value1 - value2);
201 return Standard_True;
204 Standard_Boolean Voxel_BooleanOperation::Check(const Voxel_DS& theVoxels1,
205 const Voxel_DS& theVoxels2) const
208 // Number of splits along X, Y and Z axes.
209 if (!theVoxels1.GetNbX() && theVoxels1.GetNbX() != theVoxels2.GetNbX())
210 return Standard_False;
211 if (!theVoxels1.GetNbY() && theVoxels1.GetNbY() != theVoxels2.GetNbY())
212 return Standard_False;
213 if (!theVoxels1.GetNbZ() && theVoxels1.GetNbZ() != theVoxels2.GetNbZ())
214 return Standard_False;
216 if (fabs(theVoxels1.GetX() - theVoxels2.GetX()) > Precision::Confusion() ||
217 fabs(theVoxels1.GetY() - theVoxels2.GetY()) > Precision::Confusion() ||
218 fabs(theVoxels1.GetZ() - theVoxels2.GetZ()) > Precision::Confusion())
220 return Standard_False;
222 // Length along X, Y and Z axes.
223 if (fabs(theVoxels1.GetXLen() - theVoxels2.GetXLen()) > Precision::Confusion() ||
224 fabs(theVoxels1.GetYLen() - theVoxels2.GetYLen()) > Precision::Confusion() ||
225 fabs(theVoxels1.GetZLen() - theVoxels2.GetZLen()) > Precision::Confusion())
227 return Standard_False;
229 return Standard_True;