0022815: Missing delete operator for placement new
[occt.git] / src / VoxelClient / VoxelClient_VisDrawer.cxx
1 #include "VoxelClient_VisDrawer.h"
2
3 #include <ElSLib.hxx>
4 #include <gp_Dir.hxx>
5 #include <Geom_Plane.hxx>
6 #include <gce_MakePln.hxx>
7 #include <Quantity_Color.hxx>
8 #include <Aspect_TypeOfLine.hxx>
9 #include <Graphic3d_CUserDraw.hxx>
10
11 #include <InterfaceGraphic_telem.hxx>
12 #include <OpenGl_Element.hxx>
13 #include <OpenGl_Callback.hxx>
14 #include <OpenGl_NamedStatus.hxx>
15
16 #include <GL/gl.h>
17 #include <GL/glu.h>
18
19 /**************************************************************************/
20
21 class VoxelClient_VisDrawer::VisElement : public OpenGl_Element
22 {
23 public:
24
25   VisElement (Voxel_VisData*);
26   virtual ~VisElement();
27
28   void EvaluateBounds (Graphic3d_CBounds& theMinMax);
29
30   void Render (const Handle(OpenGl_Workspace) &theWorkspace) const;
31
32 private:
33
34   VoxelClient_VisDrawer* myHandler;
35
36 public:
37
38   DEFINE_STANDARD_ALLOC
39
40 };
41
42 //=======================================================================
43 //function : VisElement
44 //purpose  : Constructor
45 //=======================================================================
46
47 VoxelClient_VisDrawer::VisElement::VisElement (Voxel_VisData* theData)
48 {
49   myHandler = new VoxelClient_VisDrawer (theData);
50 }
51
52 //=======================================================================
53 //function : ~VisElement
54 //purpose  : Destructor
55 //=======================================================================
56
57 VoxelClient_VisDrawer::VisElement::~VisElement ()
58 {
59   delete myHandler;
60 }
61
62 //=======================================================================
63 //function : EvaluateBounds
64 //purpose  :
65 //=======================================================================
66
67 void VoxelClient_VisDrawer::VisElement::EvaluateBounds
68   (Graphic3d_CBounds& theMinMax)
69 {
70   myHandler->EvalMinMax (theMinMax);
71 }
72
73 //=======================================================================
74 //function : Render
75 //purpose  : display element
76 //=======================================================================
77
78 void VoxelClient_VisDrawer::VisElement::Render
79   (const Handle (OpenGl_Workspace) &theWorkspace) const
80 {
81   const Standard_Boolean aHl = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT);
82   myHandler->Display (aHl);
83 }
84
85 //=======================================================================
86 //function : VisDrawerCallBack
87 //purpose  : visdrawer element create callback, adds an element to graphic
88 //           driver's structure
89 //=======================================================================
90
91 static OpenGl_Element* VisDrawerCallBack (const Graphic3d_CUserDraw* theUserDraw)
92 {
93   if (theUserDraw == 0)
94     return 0;
95
96   // Retrieve the user structure
97   Voxel_VisData* aUserData = (Voxel_VisData*) (theUserDraw->Data);
98
99   if (aUserData == 0)
100     return 0;
101
102   VoxelClient_VisDrawer::VisElement *aElem = 
103     new VoxelClient_VisDrawer::VisElement (aUserData);
104
105   if (theUserDraw->Bounds != 0)
106     aElem->EvaluateBounds (*(theUserDraw->Bounds));
107
108   return aElem;
109 }
110
111 /**************************************************************************/
112 void VoxelClient_VisDrawer::Init()
113 {
114     static Standard_Boolean isInitializeded(Standard_False);
115
116     if (!isInitializeded)
117     {
118         isInitializeded = Standard_True;
119
120         OpenGl_UserDrawCallback& aCallback = UserDrawCallback ();
121         aCallback = VisDrawerCallBack;
122     }
123 }
124
125 /**************************************************************************/
126 VoxelClient_VisDrawer::VoxelClient_VisDrawer(Voxel_VisData * theData):myData(theData)
127 {
128
129 }
130
131 /**************************************************************************/
132 VoxelClient_VisDrawer::~VoxelClient_VisDrawer()
133 {
134     if (myData)
135     {
136         // Because a pointer to the data is copied, 
137         // it is possible to make an attempt to delete GL lists for
138         // a structure, which is already deleted.
139         // Such a situation may happen on close of the application.
140         // Therefore, this try / catch is used.
141
142         try
143         {
144             Standard_Integer idir;
145
146             // Points
147
148             // BoolDS
149             if (myData->myDisplay.myBoolPointsList > 0)
150             {
151                 glDeleteLists(myData->myDisplay.myBoolPointsList, 1);
152                 myData->myDisplay.myBoolPointsList = -1;
153             }
154             for (idir = Xminus; idir <= Zplus; idir++)
155             {
156                 if (myData->myDisplay.myBoolNearestPointsList[idir] > 0)
157                 {
158                     glDeleteLists(myData->myDisplay.myBoolNearestPointsList[idir], 1);
159                     myData->myDisplay.myBoolNearestPointsList[idir] = -1;
160                 }
161             }
162
163             // ColorDS
164             if (myData->myDisplay.myColorPointsList > 0)
165             {
166                 glDeleteLists(myData->myDisplay.myColorPointsList, 1);
167                 myData->myDisplay.myColorPointsList = -1;
168             }
169             for (idir = Xminus; idir <= Zplus; idir++)
170             {
171                 if (myData->myDisplay.myColorNearestPointsList[idir] > 0)
172                 {
173                     glDeleteLists(myData->myDisplay.myColorNearestPointsList[idir], 1);
174                     myData->myDisplay.myColorNearestPointsList[idir] = -1;
175                 }
176             }
177
178             // ROctBoolDS
179             if (myData->myDisplay.myROctBoolPointsList > 0)
180             {
181                 glDeleteLists(myData->myDisplay.myROctBoolPointsList, 1);
182                 myData->myDisplay.myROctBoolPointsList = -1;
183             }
184             for (idir = Xminus; idir <= Zplus; idir++)
185             {
186                 if (myData->myDisplay.myROctBoolNearestPointsList[idir] > 0)
187                 {
188                     glDeleteLists(myData->myDisplay.myROctBoolNearestPointsList[idir], 1);
189                     myData->myDisplay.myROctBoolNearestPointsList[idir] = -1;
190                 }
191             }
192
193             // Triangulation
194             if (myData->myDisplay.myTriangulationList > 0)
195             {
196                 glDeleteLists(myData->myDisplay.myTriangulationList, 1);
197                 myData->myDisplay.myTriangulationList = -1;
198             }
199         }
200         catch (...)
201         {
202
203         }
204     }
205 }
206
207 /**************************************************************************/
208 void VoxelClient_VisDrawer::EvalMinMax(Graphic3d_CBounds & theMinMax) const 
209 {
210     theMinMax.XMin = FLT_MAX;
211     theMinMax.YMin = FLT_MAX;
212     theMinMax.ZMin = FLT_MAX;
213     theMinMax.XMax = -FLT_MAX;
214     theMinMax.YMax = -FLT_MAX;
215     theMinMax.ZMax = -FLT_MAX;
216     if(!myData)
217         return;
218     if(myData->myBoolVoxels)
219     {
220         if (theMinMax.XMin > myData->myBoolVoxels->GetX())
221                 theMinMax.XMin = myData->myBoolVoxels->GetX();
222         if (theMinMax.XMax < myData->myBoolVoxels->GetX() + myData->myBoolVoxels->GetXLen())
223                 theMinMax.XMax = myData->myBoolVoxels->GetX() + myData->myBoolVoxels->GetXLen();
224         if (theMinMax.YMin > myData->myBoolVoxels->GetY())
225                 theMinMax.YMin = myData->myBoolVoxels->GetY();
226         if (theMinMax.YMax < myData->myBoolVoxels->GetY() + myData->myBoolVoxels->GetYLen())
227                 theMinMax.YMax = myData->myBoolVoxels->GetY() + myData->myBoolVoxels->GetYLen();
228         if (theMinMax.ZMin > myData->myBoolVoxels->GetZ())
229                 theMinMax.ZMin = myData->myBoolVoxels->GetZ();
230         if (theMinMax.ZMax < myData->myBoolVoxels->GetZ() + myData->myBoolVoxels->GetZLen())
231                 theMinMax.ZMax = myData->myBoolVoxels->GetZ() + myData->myBoolVoxels->GetZLen();
232     }
233     if(myData->myColorVoxels)
234     {
235         if (theMinMax.XMin > myData->myColorVoxels->GetX())
236                 theMinMax.XMin = myData->myColorVoxels->GetX();
237         if (theMinMax.XMax < myData->myColorVoxels->GetX() + myData->myColorVoxels->GetXLen())
238                 theMinMax.XMax = myData->myColorVoxels->GetX() + myData->myColorVoxels->GetXLen();
239         if (theMinMax.YMin > myData->myColorVoxels->GetY())
240                 theMinMax.YMin = myData->myColorVoxels->GetY();
241         if (theMinMax.YMax < myData->myColorVoxels->GetY() + myData->myColorVoxels->GetYLen())
242                 theMinMax.YMax = myData->myColorVoxels->GetY() + myData->myColorVoxels->GetYLen();
243         if (theMinMax.ZMin > myData->myColorVoxels->GetZ())
244                 theMinMax.ZMin = myData->myColorVoxels->GetZ();
245         if (theMinMax.ZMax < myData->myColorVoxels->GetZ() + myData->myColorVoxels->GetZLen())
246                 theMinMax.ZMax = myData->myColorVoxels->GetZ() + myData->myColorVoxels->GetZLen();
247     }
248     if(myData->myROctBoolVoxels)
249     {
250         if (theMinMax.XMin > myData->myROctBoolVoxels->GetX())
251                 theMinMax.XMin = myData->myROctBoolVoxels->GetX();
252         if (theMinMax.XMax < myData->myROctBoolVoxels->GetX() + myData->myROctBoolVoxels->GetXLen())
253                 theMinMax.XMax = myData->myROctBoolVoxels->GetX() + myData->myROctBoolVoxels->GetXLen();
254         if (theMinMax.YMin > myData->myROctBoolVoxels->GetY())
255                 theMinMax.YMin = myData->myROctBoolVoxels->GetY();
256         if (theMinMax.YMax < myData->myROctBoolVoxels->GetY() + myData->myROctBoolVoxels->GetYLen())
257                 theMinMax.YMax = myData->myROctBoolVoxels->GetY() + myData->myROctBoolVoxels->GetYLen();
258         if (theMinMax.ZMin > myData->myROctBoolVoxels->GetZ())
259                 theMinMax.ZMin = myData->myROctBoolVoxels->GetZ();
260         if (theMinMax.ZMax < myData->myROctBoolVoxels->GetZ() + myData->myROctBoolVoxels->GetZLen())
261                 theMinMax.ZMax = myData->myROctBoolVoxels->GetZ() + myData->myROctBoolVoxels->GetZLen();
262     }
263     if (!myData->myTriangulation.IsNull())
264     {
265         Standard_Real x, y, z;
266         const TColgp_Array1OfPnt& nodes = myData->myTriangulation->Nodes();
267         Standard_Integer inode = nodes.Lower(), nb_nodes = nodes.Upper();
268         for (; inode <= nb_nodes; inode++)
269         {
270             nodes.Value(inode).Coord(x, y, z);
271             if (theMinMax.XMin > x)
272                     theMinMax.XMin = x;
273             if (theMinMax.XMax < x)
274                     theMinMax.XMax = x;
275             if (theMinMax.YMin > y)
276                     theMinMax.YMin = y;
277             if (theMinMax.YMax < y)
278                     theMinMax.YMax = y;
279             if (theMinMax.ZMin > z)
280                     theMinMax.ZMin = z;
281             if (theMinMax.ZMax < z)
282                     theMinMax.ZMax = z;
283         }
284     }
285 }
286
287 /**************************************************************************/
288 void VoxelClient_VisDrawer::Display(const Standard_Boolean theHighlight)
289 {
290     if (!myData)
291         return;
292     if (myData->myBoolVoxels)
293         DisplayVoxels(theHighlight);
294     if (myData->myColorVoxels)
295         DisplayVoxels(theHighlight);
296     if (myData->myROctBoolVoxels)
297         DisplayVoxels(theHighlight);
298     if (!myData->myTriangulation.IsNull())
299         DisplayTriangulation(theHighlight);
300 }
301
302 // Some static method to define Open GL visual attributes
303 // COlor
304 static void setColor(const Quantity_Color& color, const Standard_Boolean highlight)
305 {
306     static Quantity_Color highlight_color(Quantity_NOC_BLUE1);
307                 if(highlight)
308         glColor3f(highlight_color.Red(), highlight_color.Green(), highlight_color.Blue());
309     else
310         glColor3d(color.Red(), color.Green(), color.Blue());
311 }
312
313 // Type of Line
314 static void setTypeOfLine(const Aspect_TypeOfLine type)
315 {
316     if(type == Aspect_TOL_SOLID)
317     {
318         glDisable(GL_LINE_STIPPLE);
319     }
320     else
321     {
322         glEnable(GL_LINE_STIPPLE);
323         if(type == Aspect_TOL_DOT)
324             glLineStipple(1, 0xCCCC);
325         else if(type == Aspect_TOL_DASH)
326             glLineStipple(1, 0xFFC0);
327         else if(type == Aspect_TOL_DOTDASH)
328             glLineStipple(1, 0xFF18);
329     }
330 }
331
332 // Width of Line
333 static void setWidthOfLine(const Standard_Integer width)
334 {
335     glLineWidth((Standard_ShortReal) width);
336 }
337
338 // Normal of the view
339 static void getNormal(gp_Dir& normal) 
340 {
341         Standard_Real x, y, z;
342         GLint viewport[4];
343         GLdouble model_matrix[16], proj_matrix[16];
344
345         glGetDoublev(GL_MODELVIEW_MATRIX,  model_matrix);
346         glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix);
347         glGetIntegerv(GL_VIEWPORT, viewport);
348
349         gluUnProject(viewport[0], viewport[1], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
350         gp_Pnt p1(x, y, z);
351         gluUnProject(viewport[0] + viewport[2], viewport[1], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
352         gp_Pnt p2(x, y, z);
353         gluUnProject(viewport[0], viewport[1] + viewport[3], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
354         gp_Pnt p3(x, y, z);
355
356         gce_MakePln mkNormal(p1, p2, p3);
357         if (mkNormal.IsDone()) 
358         {
359                 const gp_Pln& normal_plane = mkNormal.Value();
360                 normal = normal_plane.Axis().Direction();
361         }
362         else
363         {
364                 normal = gp::DZ();
365         }
366 }
367
368 // Normal 2 VoxelDirection converter
369 static VoxelDirection getVoxelDirection(const gp_Dir& viewnormal)
370 {
371     VoxelDirection vdir;
372         Standard_Real fabsviewnormalx = fabs(viewnormal.X());
373         Standard_Real fabsviewnormaly = fabs(viewnormal.Y());
374         Standard_Real fabsviewnormalz = fabs(viewnormal.Z());
375         if (fabsviewnormalx >= fabsviewnormaly &&
376                 fabsviewnormalx >= fabsviewnormalz)
377         {
378                 if (viewnormal.X() > 0)
379                         vdir = Xminus;
380                 else
381                         vdir = Xplus;
382         }
383         else if (fabsviewnormaly >= fabsviewnormalx &&
384                          fabsviewnormaly >= fabsviewnormalz)
385         {
386                 if (viewnormal.Y() > 0)
387                         vdir = Yminus;
388                 else
389                         vdir = Yplus;
390         }
391         else if (fabsviewnormalz >= fabsviewnormalx &&
392                          fabsviewnormalz >= fabsviewnormaly)
393         {
394                 if (viewnormal.Z() > 0)
395                         vdir = Zminus;
396                 else
397                         vdir = Zplus;
398         }
399     return vdir;
400 }
401
402 // Normal 2 VoxelDirection 3 converter
403 static void getVoxel3Directions(const gp_Dir& viewnormal,
404                                 VoxelDirection& vdir1,
405                                 VoxelDirection& vdir2,
406                                 VoxelDirection& vdir3)
407 {
408     Standard_Boolean vdir1_set = Standard_False, vdir2_set = Standard_False, vdir3_set = Standard_False;
409
410     // Test X minus
411     Standard_Real dot = viewnormal.Dot(-gp::DX());
412     if (dot >= 0.0)
413     {
414         if (!vdir1_set)
415         {
416             vdir1 = Xminus;
417             vdir1_set = Standard_True;
418         }
419         else if (!vdir2_set)
420         {
421             vdir2 = Xminus;
422             vdir2_set = Standard_True;
423         }
424         else if (!vdir3_set)
425         {
426             vdir3 = Xminus;
427             vdir3_set = Standard_True;
428         }
429     }
430
431     // Test X plus
432     dot = viewnormal.Dot(gp::DX());
433     if (dot >= 0.0)
434     {
435         if (!vdir1_set)
436         {
437             vdir1 = Xplus;
438             vdir1_set = Standard_True;
439         }
440         else if (!vdir2_set)
441         {
442             vdir2 = Xplus;
443             vdir2_set = Standard_True;
444         }
445         else if (!vdir3_set)
446         {
447             vdir3 = Xplus;
448             vdir3_set = Standard_True;
449         }
450     }
451
452     // Test Y minus
453     dot = viewnormal.Dot(-gp::DY());
454     if (dot >= 0.0)
455     {
456         if (!vdir1_set)
457         {
458             vdir1 = Yminus;
459             vdir1_set = Standard_True;
460         }
461         else if (!vdir2_set)
462         {
463             vdir2 = Yminus;
464             vdir2_set = Standard_True;
465         }
466         else if (!vdir3_set)
467         {
468             vdir3 = Yminus;
469             vdir3_set = Standard_True;
470         }
471     }
472
473     // Test Y plus
474     dot = viewnormal.Dot(gp::DY());
475     if (dot >= 0.0)
476     {
477         if (!vdir1_set)
478         {
479             vdir1 = Yplus;
480             vdir1_set = Standard_True;
481         }
482         else if (!vdir2_set)
483         {
484             vdir2 = Yplus;
485             vdir2_set = Standard_True;
486         }
487         else if (!vdir3_set)
488         {
489             vdir3 = Yplus;
490             vdir3_set = Standard_True;
491         }
492     }
493
494     // Test Z minus
495     dot = viewnormal.Dot(-gp::DZ());
496     if (dot >= 0.0)
497     {
498         if (!vdir1_set)
499         {
500             vdir1 = Zminus;
501             vdir1_set = Standard_True;
502         }
503         else if (!vdir2_set)
504         {
505             vdir2 = Zminus;
506             vdir2_set = Standard_True;
507         }
508         else if (!vdir3_set)
509         {
510             vdir3 = Zminus;
511             vdir3_set = Standard_True;
512         }
513     }
514
515     // Test Y plus
516     dot = viewnormal.Dot(gp::DZ());
517     if (dot >= 0.0)
518     {
519         if (!vdir1_set)
520         {
521             vdir1 = Zplus;
522             vdir1_set = Standard_True;
523         }
524         else if (!vdir2_set)
525         {
526             vdir2 = Zplus;
527             vdir2_set = Standard_True;
528         }
529         else if (!vdir3_set)
530         {
531             vdir3 = Zplus;
532             vdir3_set = Standard_True;
533         }
534     }
535 }
536
537 static Standard_Boolean CheckSize(Voxel_DS* voxels, 
538                       const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, 
539                       const Standard_Real xmin, const Standard_Real xmax,
540                       const Standard_Real ymin, const Standard_Real ymax,
541                       const Standard_Real zmin, const Standard_Real zmax,
542                       Standard_Real& xc, Standard_Real& yc, Standard_Real& zc)
543 {
544     voxels->GetCenter(ix, iy, iz, xc, yc, zc);
545     if (xc < xmin || xc > xmax)
546         return Standard_False;
547     if (yc < ymin || yc > ymax)
548         return Standard_False;
549     if (zc < zmin || zc > zmax)
550         return Standard_False;
551     return Standard_True;
552 }
553
554 static Standard_Boolean CheckSize(Voxel_ROctBoolDS* voxels, 
555                       const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, 
556                       const Standard_Integer i, const Standard_Integer j,
557                       const Standard_Real xmin, const Standard_Real xmax,
558                       const Standard_Real ymin, const Standard_Real ymax,
559                       const Standard_Real zmin, const Standard_Real zmax,
560                       Standard_Real& xc, Standard_Real& yc, Standard_Real& zc)
561 {
562     if (j == -1)
563         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
564     else
565         voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
566     if (xc < xmin || xc > xmax)
567         return Standard_False;
568     if (yc < ymin || yc > ymax)
569         return Standard_False;
570     if (zc < zmin || zc > zmax)
571         return Standard_False;
572     return Standard_True;
573 }
574
575 static void drawBoolPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
576                            Voxel_BoolDS* voxels,
577                            const Standard_Real xmin, const Standard_Real xmax,
578                            const Standard_Real ymin, const Standard_Real ymax,
579                            const Standard_Real zmin, const Standard_Real zmax)
580 {
581         Standard_Real xc, yc, zc;
582         Standard_Integer ix = 0, nbx = voxels->GetNbX();
583         Standard_Integer iy = 0, nby = voxels->GetNbY();
584         Standard_Integer iz = 0, nbz = voxels->GetNbZ();
585
586     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
587                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
588                        zmin <= DBL_MAX && zmax >= DBL_MAX);
589     check_size = !check_size;
590
591     glBegin(GL_POINTS);
592     switch (vdir)
593         {
594                 case Xminus:
595                 {
596                         for (iy = 0; iy < nby; iy++)
597                         {
598                                 for (iz = 0; iz < nbz; iz++)
599                                 {
600                                         for (ix = 0; ix < nbx; ix++)
601                                         {
602                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
603                             continue;
604                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
605                                                 if (value)
606                                                 {
607                             if (!check_size)
608                                                             voxels->GetCenter(ix, iy, iz, xc, yc, zc);
609                                                         glVertex3d(xc, yc, zc);
610                             if (nearest)
611                                 break;
612                                                 }
613                                         }
614                                 }
615                         }
616                         break;
617                 }
618                 case Xplus:
619                 {
620                         for (iy = 0; iy < nby; iy++)
621                         {
622                                 for (iz = 0; iz < nbz; iz++)
623                                 {
624                                         for (ix = nbx - 1; ix >= 0; ix--)
625                                         {
626                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
627                             continue;
628                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
629                                                 if (value)
630                                                 {
631                             if (!check_size)
632                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
633                                                         glVertex3d(xc, yc, zc);
634                             if (nearest)
635                                 break;
636                                                 }
637                                         }
638                                 }
639                         }
640                         break;
641                 }
642                 case Yminus:
643                 {
644                         for (ix = 0; ix < nbx; ix++)
645                         {
646                                 for (iz = 0; iz < nbz; iz++)
647                                 {
648                                         for (iy = 0; iy < nby; iy++)
649                                         {
650                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
651                             continue;
652                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
653                                                 if (value)
654                                                 {
655                             if (!check_size)
656                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
657                                                         glVertex3d(xc, yc, zc);
658                             if (nearest)
659                                 break;
660                                                 }
661                                         }
662                                 }
663                         }
664                         break;
665                 }
666                 case Yplus:
667                 {
668                         for (ix = 0; ix < nbx; ix++)
669                         {
670                                 for (iz = 0; iz < nbz; iz++)
671                                 {
672                                         for (iy = nby - 1; iy >= 0; iy--)
673                                         {
674                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
675                             continue;
676                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
677                                                 if (value)
678                                                 {
679                             if (!check_size)
680                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
681                                                         glVertex3d(xc, yc, zc);
682                             if (nearest)
683                                 break;
684                                                 }
685                                         }
686                                 }
687                         }
688                         break;
689                 }
690                 case Zminus:
691                 {
692                         for (ix = 0; ix < nbx; ix++)
693                         {
694                                 for (iy = 0; iy < nby; iy++)
695                                 {
696                                         for (iz = 0; iz < nbz; iz++)
697                                         {
698                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
699                             continue;
700                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
701                                                 if (value)
702                                                 {
703                             if (!check_size)
704                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
705                                                         glVertex3d(xc, yc, zc);
706                             if (nearest)
707                                 break;
708                                                 }
709                                         }
710                                 }
711                         }
712                         break;
713                 }
714                 case Zplus:
715                 {
716                         for (ix = 0; ix < nbx; ix++)
717                         {
718                                 for (iy = 0; iy < nby; iy++)
719                                 {
720                                         for (iz = nbz - 1; iz >= 0; iz--)
721                                         {
722                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
723                             continue;
724                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
725                                                 if (value)
726                                                 {
727                             if (!check_size)
728                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
729                                                         glVertex3d(xc, yc, zc);
730                             if (nearest)
731                                 break;
732                                                 }
733                                         }
734                                 }
735                         }
736                         break;
737                 }
738         }
739     glEnd();
740 }
741
742 static void drawROctBoolPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
743                                Voxel_ROctBoolDS* voxels,
744                                const Standard_Real xmin, const Standard_Real xmax,
745                                const Standard_Real ymin, const Standard_Real ymax,
746                                const Standard_Real zmin, const Standard_Real zmax)
747 {
748         Standard_Real xc, yc, zc;
749         Standard_Integer ix = 0, nbx = voxels->GetNbX();
750         Standard_Integer iy = 0, nby = voxels->GetNbY();
751         Standard_Integer iz = 0, nbz = voxels->GetNbZ();
752     Standard_Integer i, j;
753
754     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
755                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
756                        zmin <= DBL_MAX && zmax >= DBL_MAX);
757     check_size = !check_size;
758
759     glBegin(GL_POINTS);
760     switch (vdir)
761         {
762                 case Xminus:
763                 {
764                         for (iy = 0; iy < nby; iy++)
765                         {
766                                 for (iz = 0; iz < nbz; iz++)
767                                 {
768                                         for (ix = 0; ix < nbx; ix++)
769                                         {
770                         switch (voxels->Deepness(ix, iy, iz))
771                         {
772                             case 0:
773                             {
774                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
775                                     continue;
776                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
777                                                         if (value)
778                                                         {
779                                     if (!check_size)
780                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
781                                                                 glVertex3d(xc, yc, zc);
782                                     if (nearest)
783                                         break;
784                                                         }
785                                 break;
786                             }
787                             case 1:
788                             {
789                                 for (i = 0; i < 8; i++)
790                                 {
791                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
792                                         continue;
793                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
794                                                             if (value)
795                                                             {
796                                         if (!check_size)
797                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
798                                                                     glVertex3d(xc, yc, zc);
799                                         if (nearest)
800                                             break;
801                                                             }
802                                 }
803                                 break;
804                             }
805                             case 2:
806                             {
807                                 for (i = 0; i < 8; i++)
808                                 {
809                                     for (j = 0; j < 8; j++)
810                                     {
811                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
812                                             continue;
813                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
814                                                                 if (value)
815                                                                 {
816                                             if (!check_size)
817                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
818                                                                         glVertex3d(xc, yc, zc);
819                                             if (nearest)
820                                                 break;
821                                                                 }
822                                     }
823                                 }
824                                 break;
825                             }
826                         }
827                                         }
828                                 }
829                         }
830                         break;
831                 }
832                 case Xplus:
833                 {
834                         for (iy = 0; iy < nby; iy++)
835                         {
836                                 for (iz = 0; iz < nbz; iz++)
837                                 {
838                                         for (ix = nbx - 1; ix >= 0; ix--)
839                                         {
840                         switch (voxels->Deepness(ix, iy, iz))
841                         {
842                             case 0:
843                             {
844                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
845                                     continue;
846                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
847                                                         if (value)
848                                                         {
849                                     if (!check_size)
850                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
851                                                                 glVertex3d(xc, yc, zc);
852                                     if (nearest)
853                                         break;
854                                                         }
855                                 break;
856                             }
857                             case 1:
858                             {
859                                 for (i = 0; i < 8; i++)
860                                 {
861                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
862                                         continue;
863                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
864                                                             if (value)
865                                                             {
866                                         if (!check_size)
867                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
868                                                                     glVertex3d(xc, yc, zc);
869                                         if (nearest)
870                                             break;
871                                                             }
872                                 }
873                                 break;
874                             }
875                             case 2:
876                             {
877                                 for (i = 0; i < 8; i++)
878                                 {
879                                     for (j = 0; j < 8; j++)
880                                     {
881                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
882                                             continue;
883                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
884                                                                 if (value)
885                                                                 {
886                                             if (!check_size)
887                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
888                                                                         glVertex3d(xc, yc, zc);
889                                             if (nearest)
890                                                 break;
891                                                                 }
892                                     }
893                                 }
894                                 break;
895                             }
896                         }
897                                         }
898                                 }
899                         }
900                         break;
901                 }
902                 case Yminus:
903                 {
904                         for (ix = 0; ix < nbx; ix++)
905                         {
906                                 for (iz = 0; iz < nbz; iz++)
907                                 {
908                                         for (iy = 0; iy < nby; iy++)
909                                         {
910                         switch (voxels->Deepness(ix, iy, iz))
911                         {
912                             case 0:
913                             {
914                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
915                                     continue;
916                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
917                                                         if (value)
918                                                         {
919                                     if (!check_size)
920                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
921                                                                 glVertex3d(xc, yc, zc);
922                                     if (nearest)
923                                         break;
924                                                         }
925                                 break;
926                             }
927                             case 1:
928                             {
929                                 for (i = 0; i < 8; i++)
930                                 {
931                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
932                                         continue;
933                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
934                                                             if (value)
935                                                             {
936                                         if (!check_size)
937                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
938                                                                     glVertex3d(xc, yc, zc);
939                                         if (nearest)
940                                             break;
941                                                             }
942                                 }
943                                 break;
944                             }
945                             case 2:
946                             {
947                                 for (i = 0; i < 8; i++)
948                                 {
949                                     for (j = 0; j < 8; j++)
950                                     {
951                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
952                                             continue;
953                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
954                                                                 if (value)
955                                                                 {
956                                             if (!check_size)
957                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
958                                                                         glVertex3d(xc, yc, zc);
959                                             if (nearest)
960                                                 break;
961                                                                 }
962                                     }
963                                 }
964                                 break;
965                             }
966                         }
967                                         }
968                                 }
969                         }
970                         break;
971                 }
972                 case Yplus:
973                 {
974                         for (ix = 0; ix < nbx; ix++)
975                         {
976                                 for (iz = 0; iz < nbz; iz++)
977                                 {
978                                         for (iy = nby - 1; iy >= 0; iy--)
979                                         {
980                         switch (voxels->Deepness(ix, iy, iz))
981                         {
982                             case 0:
983                             {
984                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
985                                     continue;
986                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
987                                                         if (value)
988                                                         {
989                                     if (!check_size)
990                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
991                                                                 glVertex3d(xc, yc, zc);
992                                     if (nearest)
993                                         break;
994                                                         }
995                                 break;
996                             }
997                             case 1:
998                             {
999                                 for (i = 0; i < 8; i++)
1000                                 {
1001                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1002                                         continue;
1003                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
1004                                                             if (value)
1005                                                             {
1006                                         if (!check_size)
1007                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1008                                                                     glVertex3d(xc, yc, zc);
1009                                         if (nearest)
1010                                             break;
1011                                                             }
1012                                 }
1013                                 break;
1014                             }
1015                             case 2:
1016                             {
1017                                 for (i = 0; i < 8; i++)
1018                                 {
1019                                     for (j = 0; j < 8; j++)
1020                                     {
1021                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1022                                             continue;
1023                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1024                                                                 if (value)
1025                                                                 {
1026                                             if (!check_size)
1027                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1028                                                                         glVertex3d(xc, yc, zc);
1029                                             if (nearest)
1030                                                 break;
1031                                                                 }
1032                                     }
1033                                 }
1034                                 break;
1035                             }
1036                         }
1037                                         }
1038                                 }
1039                         }
1040                         break;
1041                 }
1042                 case Zminus:
1043                 {
1044                         for (ix = 0; ix < nbx; ix++)
1045                         {
1046                                 for (iy = 0; iy < nby; iy++)
1047                                 {
1048                                         for (iz = 0; iz < nbz; iz++)
1049                                         {
1050                         switch (voxels->Deepness(ix, iy, iz))
1051                         {
1052                             case 0:
1053                             {
1054                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1055                                     continue;
1056                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1057                                                         if (value)
1058                                                         {
1059                                     if (!check_size)
1060                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1061                                                                 glVertex3d(xc, yc, zc);
1062                                     if (nearest)
1063                                         break;
1064                                                         }
1065                                 break;
1066                             }
1067                             case 1:
1068                             {
1069                                 for (i = 0; i < 8; i++)
1070                                 {
1071                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1072                                         continue;
1073                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
1074                                                             if (value)
1075                                                             {
1076                                         if (!check_size)
1077                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1078                                                                     glVertex3d(xc, yc, zc);
1079                                         if (nearest)
1080                                             break;
1081                                                             }
1082                                 }
1083                                 break;
1084                             }
1085                             case 2:
1086                             {
1087                                 for (i = 0; i < 8; i++)
1088                                 {
1089                                     for (j = 0; j < 8; j++)
1090                                     {
1091                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1092                                             continue;
1093                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1094                                                                 if (value)
1095                                                                 {
1096                                             if (!check_size)
1097                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1098                                                                         glVertex3d(xc, yc, zc);
1099                                             if (nearest)
1100                                                 break;
1101                                                                 }
1102                                     }
1103                                 }
1104                                 break;
1105                             }
1106                         }
1107                                         }
1108                                 }
1109                         }
1110                         break;
1111                 }
1112                 case Zplus:
1113                 {
1114                         for (ix = 0; ix < nbx; ix++)
1115                         {
1116                                 for (iy = 0; iy < nby; iy++)
1117                                 {
1118                                         for (iz = nbz - 1; iz >= 0; iz--)
1119                                         {
1120                         switch (voxels->Deepness(ix, iy, iz))
1121                         {
1122                             case 0:
1123                             {
1124                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1125                                     continue;
1126                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1127                                                         if (value)
1128                                                         {
1129                                     if (!check_size)
1130                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1131                                                                 glVertex3d(xc, yc, zc);
1132                                     if (nearest)
1133                                         break;
1134                                                         }
1135                                 break;
1136                             }
1137                             case 1:
1138                             {
1139                                 for (i = 0; i < 8; i++)
1140                                 {
1141                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1142                                         continue;
1143                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
1144                                                             if (value)
1145                                                             {
1146                                         if (!check_size)
1147                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1148                                                                     glVertex3d(xc, yc, zc);
1149                                         if (nearest)
1150                                             break;
1151                                                             }
1152                                 }
1153                                 break;
1154                             }
1155                             case 2:
1156                             {
1157                                 for (i = 0; i < 8; i++)
1158                                 {
1159                                     for (j = 0; j < 8; j++)
1160                                     {
1161                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1162                                             continue;
1163                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1164                                                                 if (value)
1165                                                                 {
1166                                             if (!check_size)
1167                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1168                                                                         glVertex3d(xc, yc, zc);
1169                                             if (nearest)
1170                                                 break;
1171                                                                 }
1172                                     }
1173                                 }
1174                                 break;
1175                             }
1176                         }
1177                                         }
1178                                 }
1179                         }
1180                         break;
1181                 }
1182         }
1183     glEnd();
1184 }
1185
1186
1187
1188 static void drawColorPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
1189                             Voxel_ColorDS* voxels, const Handle(Quantity_HArray1OfColor)& hcolors,
1190                             const Standard_Byte minvalue, const Standard_Byte maxvalue,
1191                             const Standard_Real xmin, const Standard_Real xmax,
1192                             const Standard_Real ymin, const Standard_Real ymax,
1193                             const Standard_Real zmin, const Standard_Real zmax)
1194 {
1195         Standard_Real xc, yc, zc;
1196         Standard_Integer ix = 0, nbx = voxels->GetNbX();
1197         Standard_Integer iy = 0, nby = voxels->GetNbY();
1198         Standard_Integer iz = 0, nbz = voxels->GetNbZ();
1199     Standard_Byte value;
1200
1201     // Colors
1202     const Quantity_Array1OfColor& colors = hcolors->Array1();
1203
1204     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
1205                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
1206                        zmin <= DBL_MAX && zmax >= DBL_MAX);
1207     check_size = !check_size;
1208
1209     glBegin(GL_POINTS);
1210     switch (vdir)
1211         {
1212                 case Xminus:
1213                 {
1214                         for (iy = 0; iy < nby; iy++)
1215                         {
1216                                 for (iz = 0; iz < nbz; iz++)
1217                                 {
1218                                         for (ix = 0; ix < nbx; ix++)
1219                                         {
1220                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1221                             continue;
1222                             value = voxels->Get(ix, iy, iz);
1223                             if (value >= minvalue && value <= maxvalue)
1224                             {
1225                             if (!check_size)
1226                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1227                             setColor(colors.Value(value), Standard_False);
1228                                     glVertex3d(xc, yc, zc);
1229                             if (nearest)
1230                                 break;
1231                         }
1232                                         }
1233                                 }
1234                         }
1235                         break;
1236                 }
1237                 case Xplus:
1238                 {
1239                         for (iy = 0; iy < nby; iy++)
1240                         {
1241                                 for (iz = 0; iz < nbz; iz++)
1242                                 {
1243                                         for (ix = nbx - 1; ix >= 0; ix--)
1244                                         {
1245                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1246                             continue;
1247                             value = voxels->Get(ix, iy, iz);
1248                             if (value >= minvalue && value <= maxvalue)
1249                             {
1250                             if (!check_size)
1251                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1252                             setColor(colors.Value(value), Standard_False);
1253                                     glVertex3d(xc, yc, zc);
1254                             if (nearest)
1255                                 break;
1256                         }
1257                                         }
1258                                 }
1259                         }
1260                         break;
1261                 }
1262                 case Yminus:
1263                 {
1264                         for (ix = 0; ix < nbx; ix++)
1265                         {
1266                                 for (iz = 0; iz < nbz; iz++)
1267                                 {
1268                                         for (iy = 0; iy < nby; iy++)
1269                                         {
1270                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1271                             continue;
1272                             value = voxels->Get(ix, iy, iz);
1273                             if (value >= minvalue && value <= maxvalue)
1274                             {
1275                             if (!check_size)
1276                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1277                             setColor(colors.Value(value), Standard_False);
1278                                     glVertex3d(xc, yc, zc);
1279                             if (nearest)
1280                                 break;
1281                         }
1282                                         }
1283                                 }
1284                         }
1285                         break;
1286                 }
1287                 case Yplus:
1288                 {
1289                         for (ix = 0; ix < nbx; ix++)
1290                         {
1291                                 for (iz = 0; iz < nbz; iz++)
1292                                 {
1293                                         for (iy = nby - 1; iy >= 0; iy--)
1294                                         {
1295                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1296                             continue;
1297                             value = voxels->Get(ix, iy, iz);
1298                             if (value >= minvalue && value <= maxvalue)
1299                             {
1300                             if (!check_size)
1301                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1302                             setColor(colors.Value(value), Standard_False);
1303                                     glVertex3d(xc, yc, zc);
1304                             if (nearest)
1305                                 break;
1306                         }
1307                                         }
1308                                 }
1309                         }
1310                         break;
1311                 }
1312                 case Zminus:
1313                 {
1314                         for (ix = 0; ix < nbx; ix++)
1315                         {
1316                                 for (iy = 0; iy < nby; iy++)
1317                                 {
1318                                         for (iz = 0; iz < nbz; iz++)
1319                                         {
1320                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1321                             continue;
1322                             value = voxels->Get(ix, iy, iz);
1323                             if (value >= minvalue && value <= maxvalue)
1324                             {
1325                             if (!check_size)
1326                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1327                             setColor(colors.Value(value), Standard_False);
1328                                     glVertex3d(xc, yc, zc);
1329                             if (nearest)
1330                                 break;
1331                         }
1332                                         }
1333                                 }
1334                         }
1335                         break;
1336                 }
1337                 case Zplus:
1338                 {
1339                         for (ix = 0; ix < nbx; ix++)
1340                         {
1341                                 for (iy = 0; iy < nby; iy++)
1342                                 {
1343                                         for (iz = nbz - 1; iz >= 0; iz--)
1344                                         {
1345                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1346                             continue;
1347                             value = voxels->Get(ix, iy, iz);
1348                             if (value >= minvalue && value <= maxvalue)
1349                             {
1350                             if (!check_size)
1351                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1352                             setColor(colors.Value(value), Standard_False);
1353                                     glVertex3d(xc, yc, zc);
1354                             if (nearest)
1355                                 break;
1356                         }
1357                                         }
1358                                 }
1359                         }
1360                         break;
1361                 }
1362     }
1363     glEnd();
1364 }
1365
1366 static void drawBoolQuadrangles(Voxel_BoolDS* voxels, const VoxelDirection vdir, 
1367                                 const gp_Dir& viewnormal, const Standard_Boolean nearest,
1368                                 const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
1369                                 const Standard_Real xmin, const Standard_Real xmax,
1370                                 const Standard_Real ymin, const Standard_Real ymax,
1371                                 const Standard_Real zmin, const Standard_Real zmax)
1372 {
1373     gp_Vec vc;
1374     gp_Pnt pc1, pc2, pc3, pc4;
1375     Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 1.0;
1376     Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ();
1377
1378     // Normal
1379     viewnormal.Coord(xn, yn, zn);
1380
1381     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
1382                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
1383                        zmin <= DBL_MAX && zmax >= DBL_MAX);
1384     check_size = !check_size;
1385
1386     glBegin(GL_QUADS);
1387     switch (vdir)
1388         {
1389                 case Xminus:
1390                 {
1391                         for (iy = 0; iy < nby; iy++)
1392                         {
1393                                 for (iz = 0; iz < nbz; iz++)
1394                                 {
1395                                         for (ix = 0; ix < nbx; ix++)
1396                                         {
1397                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1398                             continue;
1399                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1400                         if (value)
1401                         {
1402                             // Define translation vector
1403                             if (!check_size)
1404                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1405                             vc.SetCoord(xc, yc, zc);
1406
1407                             // Translate
1408                             pc1 = p1.Translated(vc);
1409                             pc2 = p2.Translated(vc);
1410                             pc3 = p3.Translated(vc);
1411                             pc4 = p4.Translated(vc);
1412
1413                             // Display
1414                             glNormal3d(xn, yn, zn);
1415                             pc1.Coord(xc, yc, zc);
1416                             glVertex3d(xc, yc, zc);
1417                             pc2.Coord(xc, yc, zc);
1418                             glVertex3d(xc, yc, zc);
1419                             pc3.Coord(xc, yc, zc);
1420                             glVertex3d(xc, yc, zc);
1421                             pc4.Coord(xc, yc, zc);
1422                             glVertex3d(xc, yc, zc);
1423
1424                             if (nearest)
1425                                 break;
1426                         }
1427                     }
1428                                 }
1429                         }
1430                         break;
1431                 }
1432                 case Xplus:
1433                 {
1434                         for (iy = 0; iy < nby; iy++)
1435                         {
1436                                 for (iz = 0; iz < nbz; iz++)
1437                                 {
1438                                         for (ix = nbx - 1; ix >= 0; ix--)
1439                                         {
1440                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1441                             continue;
1442                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1443                         if (value)
1444                         {
1445                             // Define translation vector
1446                             if (!check_size)
1447                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1448                             vc.SetCoord(xc, yc, zc);
1449
1450                             // Translate
1451                             pc1 = p1.Translated(vc);
1452                             pc2 = p2.Translated(vc);
1453                             pc3 = p3.Translated(vc);
1454                             pc4 = p4.Translated(vc);
1455
1456                             // Display
1457                             glNormal3d(xn, yn, zn);
1458                             pc1.Coord(xc, yc, zc);
1459                             glVertex3d(xc, yc, zc);
1460                             pc2.Coord(xc, yc, zc);
1461                             glVertex3d(xc, yc, zc);
1462                             pc3.Coord(xc, yc, zc);
1463                             glVertex3d(xc, yc, zc);
1464                             pc4.Coord(xc, yc, zc);
1465                             glVertex3d(xc, yc, zc);
1466
1467                             if (nearest)
1468                                 break;
1469                         }
1470                                         }
1471                                 }
1472                         }
1473                         break;
1474                 }
1475                 case Yminus:
1476                 {
1477                         for (ix = 0; ix < nbx; ix++)
1478                         {
1479                                 for (iz = 0; iz < nbz; iz++)
1480                                 {
1481                                         for (iy = 0; iy < nby; iy++)
1482                                         {
1483                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1484                             continue;
1485                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1486                         if (value)
1487                         {
1488                             // Define translation vector
1489                             if (!check_size)
1490                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1491                             vc.SetCoord(xc, yc, zc);
1492
1493                             // Translate
1494                             pc1 = p1.Translated(vc);
1495                             pc2 = p2.Translated(vc);
1496                             pc3 = p3.Translated(vc);
1497                             pc4 = p4.Translated(vc);
1498
1499                             // Display
1500                             glNormal3d(xn, yn, zn);
1501                             pc1.Coord(xc, yc, zc);
1502                             glVertex3d(xc, yc, zc);
1503                             pc2.Coord(xc, yc, zc);
1504                             glVertex3d(xc, yc, zc);
1505                             pc3.Coord(xc, yc, zc);
1506                             glVertex3d(xc, yc, zc);
1507                             pc4.Coord(xc, yc, zc);
1508                             glVertex3d(xc, yc, zc);
1509
1510                             if (nearest)
1511                                 break;
1512                         }
1513                                         }
1514                                 }
1515                         }
1516                         break;
1517                 }
1518                 case Yplus:
1519                 {
1520                         for (ix = 0; ix < nbx; ix++)
1521                         {
1522                                 for (iz = 0; iz < nbz; iz++)
1523                                 {
1524                                         for (iy = nby - 1; iy >= 0; iy--)
1525                                         {
1526                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1527                             continue;
1528                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1529                         if (value)
1530                         {
1531                             // Define translation vector
1532                             if (!check_size)
1533                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1534                             vc.SetCoord(xc, yc, zc);
1535
1536                             // Translate
1537                             pc1 = p1.Translated(vc);
1538                             pc2 = p2.Translated(vc);
1539                             pc3 = p3.Translated(vc);
1540                             pc4 = p4.Translated(vc);
1541
1542                             // Display
1543                             glNormal3d(xn, yn, zn);
1544                             pc1.Coord(xc, yc, zc);
1545                             glVertex3d(xc, yc, zc);
1546                             pc2.Coord(xc, yc, zc);
1547                             glVertex3d(xc, yc, zc);
1548                             pc3.Coord(xc, yc, zc);
1549                             glVertex3d(xc, yc, zc);
1550                             pc4.Coord(xc, yc, zc);
1551                             glVertex3d(xc, yc, zc);
1552
1553                             if (nearest)
1554                                 break;
1555                         }
1556                                         }
1557                                 }
1558                         }
1559                         break;
1560                 }
1561                 case Zminus:
1562                 {
1563                         for (ix = 0; ix < nbx; ix++)
1564                         {
1565                                 for (iy = 0; iy < nby; iy++)
1566                                 {
1567                                         for (iz = 0; iz < nbz; iz++)
1568                                         {
1569                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1570                             continue;
1571                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1572                         if (value)
1573                         {
1574                             // Define translation vector
1575                             if (!check_size)
1576                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1577                             vc.SetCoord(xc, yc, zc);
1578
1579                             // Translate
1580                             pc1 = p1.Translated(vc);
1581                             pc2 = p2.Translated(vc);
1582                             pc3 = p3.Translated(vc);
1583                             pc4 = p4.Translated(vc);
1584
1585                             // Display
1586                             glNormal3d(xn, yn, zn);
1587                             pc1.Coord(xc, yc, zc);
1588                             glVertex3d(xc, yc, zc);
1589                             pc2.Coord(xc, yc, zc);
1590                             glVertex3d(xc, yc, zc);
1591                             pc3.Coord(xc, yc, zc);
1592                             glVertex3d(xc, yc, zc);
1593                             pc4.Coord(xc, yc, zc);
1594                             glVertex3d(xc, yc, zc);
1595
1596                             if (nearest)
1597                                 break;
1598                         }
1599                                         }
1600                                 }
1601                         }
1602                         break;
1603                 }
1604                 case Zplus:
1605                 {
1606                         for (ix = 0; ix < nbx; ix++)
1607                         {
1608                                 for (iy = 0; iy < nby; iy++)
1609                                 {
1610                                         for (iz = nbz - 1; iz >= 0; iz--)
1611                                         {
1612                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1613                             continue;
1614                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1615                         if (value)
1616                         {
1617                             // Define translation vector
1618                             if (!check_size)
1619                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1620                             vc.SetCoord(xc, yc, zc);
1621
1622                             // Translate
1623                             pc1 = p1.Translated(vc);
1624                             pc2 = p2.Translated(vc);
1625                             pc3 = p3.Translated(vc);
1626                             pc4 = p4.Translated(vc);
1627
1628                             // Display
1629                             glNormal3d(xn, yn, zn);
1630                             pc1.Coord(xc, yc, zc);
1631                             glVertex3d(xc, yc, zc);
1632                             pc2.Coord(xc, yc, zc);
1633                             glVertex3d(xc, yc, zc);
1634                             pc3.Coord(xc, yc, zc);
1635                             glVertex3d(xc, yc, zc);
1636                             pc4.Coord(xc, yc, zc);
1637                             glVertex3d(xc, yc, zc);
1638
1639                             if (nearest)
1640                                 break;
1641                         }
1642                                         }
1643                                 }
1644                         }
1645                         break;
1646                 }
1647     }
1648     glEnd();
1649 }
1650
1651 static void drawROctBoolQuadrangles(Voxel_ROctBoolDS* voxels, const VoxelDirection vdir, 
1652                                     const gp_Dir& viewnormal, const Standard_Boolean nearest,
1653                                     const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
1654                                     const Standard_Real xmin, const Standard_Real xmax,
1655                                     const Standard_Real ymin, const Standard_Real ymax,
1656                                     const Standard_Real zmin, const Standard_Real zmax)
1657 {
1658     gp_Vec vc;
1659     gp_Pnt pc1, pc2, pc3, pc4;
1660     Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 1.0;
1661     Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ(), i, j, deepness;
1662
1663     // Normal
1664     viewnormal.Coord(xn, yn, zn);
1665
1666     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
1667                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
1668                        zmin <= DBL_MAX && zmax >= DBL_MAX);
1669     check_size = !check_size;
1670
1671     glBegin(GL_QUADS);
1672     switch (vdir)
1673         {
1674                 case Xminus:
1675                 {
1676                         for (iy = 0; iy < nby; iy++)
1677                         {
1678                                 for (iz = 0; iz < nbz; iz++)
1679                                 {
1680                                         for (ix = 0; ix < nbx; ix++)
1681                                         {
1682                         deepness = voxels->Deepness(ix, iy, iz);
1683                         for (i = 0; i < 8; i++)
1684                         {
1685                             for (j = 0; j < 8; j++)
1686                             {
1687                                 if (deepness == 0 && j)
1688                                 {
1689                                     i = 8;
1690                                     break;
1691                                 }
1692                                 if (deepness == 1 && j)
1693                                     break;
1694                                 if (deepness == 0)
1695                                 {
1696                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1697                                         continue;
1698                                 }
1699                                 else if (deepness == 1)
1700                                 {
1701                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1702                                         continue;
1703                                 }
1704                                 else if (deepness == 2)
1705                                 {
1706                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1707                                         continue;
1708                                 }
1709
1710                                 Standard_Boolean value;
1711                                 switch (deepness)
1712                                 {
1713                                     case 0:
1714                                         value = voxels->Get(ix, iy, iz) == Standard_True;
1715                                         break;
1716                                     case 1:
1717                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
1718                                         break;
1719                                     case 2:
1720                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1721                                         break;
1722                                 }
1723                                 
1724                                 if (value)
1725                                 {
1726                                     // Define translation vector
1727                                     if (!check_size)
1728                                     {
1729                                         switch (deepness)
1730                                         {
1731                                             case 0:
1732                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1733                                                 break;
1734                                             case 1:
1735                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1736                                                 break;
1737                                             case 2:
1738                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1739                                                 break;
1740                                         }
1741                                     }
1742                                     vc.SetCoord(xc, yc, zc);
1743
1744                                     // Translate
1745                                     pc1 = p1.Translated(vc);
1746                                     pc2 = p2.Translated(vc);
1747                                     pc3 = p3.Translated(vc);
1748                                     pc4 = p4.Translated(vc);
1749
1750                                     // Display
1751                                     glNormal3d(xn, yn, zn);
1752                                     pc1.Coord(xc, yc, zc);
1753                                     glVertex3d(xc, yc, zc);
1754                                     pc2.Coord(xc, yc, zc);
1755                                     glVertex3d(xc, yc, zc);
1756                                     pc3.Coord(xc, yc, zc);
1757                                     glVertex3d(xc, yc, zc);
1758                                     pc4.Coord(xc, yc, zc);
1759                                     glVertex3d(xc, yc, zc);
1760
1761                                     if (nearest)
1762                                         break;
1763                                 }
1764                             }
1765                         }
1766                     }
1767                                 }
1768                         }
1769                         break;
1770                 }
1771                 case Xplus:
1772                 {
1773                         for (iy = 0; iy < nby; iy++)
1774                         {
1775                                 for (iz = 0; iz < nbz; iz++)
1776                                 {
1777                                         for (ix = nbx - 1; ix >= 0; ix--)
1778                                         {
1779                         deepness = voxels->Deepness(ix, iy, iz);
1780                         for (i = 0; i < 8; i++)
1781                         {
1782                             for (j = 0; j < 8; j++)
1783                             {
1784                                 if (deepness == 0 && j)
1785                                 {
1786                                     i = 8;
1787                                     break;
1788                                 }
1789                                 if (deepness == 1 && j)
1790                                     break;
1791                                 if (deepness == 0)
1792                                 {
1793                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1794                                         continue;
1795                                 }
1796                                 else if (deepness == 1)
1797                                 {
1798                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1799                                         continue;
1800                                 }
1801                                 else if (deepness == 2)
1802                                 {
1803                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1804                                         continue;
1805                                 }
1806
1807                                 Standard_Boolean value;
1808                                 switch (deepness)
1809                                 {
1810                                     case 0:
1811                                         value = voxels->Get(ix, iy, iz) == Standard_True;
1812                                         break;
1813                                     case 1:
1814                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
1815                                         break;
1816                                     case 2:
1817                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1818                                         break;
1819                                 }
1820                                 
1821                                 if (value)
1822                                 {
1823                                     // Define translation vector
1824                                     if (!check_size)
1825                                     {
1826                                         switch (deepness)
1827                                         {
1828                                             case 0:
1829                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1830                                                 break;
1831                                             case 1:
1832                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1833                                                 break;
1834                                             case 2:
1835                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1836                                                 break;
1837                                         }
1838                                     }
1839                                     vc.SetCoord(xc, yc, zc);
1840
1841                                     // Translate
1842                                     pc1 = p1.Translated(vc);
1843                                     pc2 = p2.Translated(vc);
1844                                     pc3 = p3.Translated(vc);
1845                                     pc4 = p4.Translated(vc);
1846
1847                                     // Display
1848                                     glNormal3d(xn, yn, zn);
1849                                     pc1.Coord(xc, yc, zc);
1850                                     glVertex3d(xc, yc, zc);
1851                                     pc2.Coord(xc, yc, zc);
1852                                     glVertex3d(xc, yc, zc);
1853                                     pc3.Coord(xc, yc, zc);
1854                                     glVertex3d(xc, yc, zc);
1855                                     pc4.Coord(xc, yc, zc);
1856                                     glVertex3d(xc, yc, zc);
1857
1858                                     if (nearest)
1859                                         break;
1860                                 }
1861                             }
1862                         }
1863                                         }
1864                                 }
1865                         }
1866                         break;
1867                 }
1868                 case Yminus:
1869                 {
1870                         for (ix = 0; ix < nbx; ix++)
1871                         {
1872                                 for (iz = 0; iz < nbz; iz++)
1873                                 {
1874                                         for (iy = 0; iy < nby; iy++)
1875                                         {
1876                         deepness = voxels->Deepness(ix, iy, iz);
1877                         for (i = 0; i < 8; i++)
1878                         {
1879                             for (j = 0; j < 8; j++)
1880                             {
1881                                 if (deepness == 0 && j)
1882                                 {
1883                                     i = 8;
1884                                     break;
1885                                 }
1886                                 if (deepness == 1 && j)
1887                                     break;
1888                                 if (deepness == 0)
1889                                 {
1890                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1891                                         continue;
1892                                 }
1893                                 else if (deepness == 1)
1894                                 {
1895                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1896                                         continue;
1897                                 }
1898                                 else if (deepness == 2)
1899                                 {
1900                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1901                                         continue;
1902                                 }
1903
1904                                 Standard_Boolean value;
1905                                 switch (deepness)
1906                                 {
1907                                     case 0:
1908                                         value = voxels->Get(ix, iy, iz) == Standard_True;
1909                                         break;
1910                                     case 1:
1911                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
1912                                         break;
1913                                     case 2:
1914                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1915                                         break;
1916                                 }
1917                                 
1918                                 if (value)
1919                                 {
1920                                     // Define translation vector
1921                                     if (!check_size)
1922                                     {
1923                                         switch (deepness)
1924                                         {
1925                                             case 0:
1926                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1927                                                 break;
1928                                             case 1:
1929                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1930                                                 break;
1931                                             case 2:
1932                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1933                                                 break;
1934                                         }
1935                                     }
1936                                     vc.SetCoord(xc, yc, zc);
1937
1938                                     // Translate
1939                                     pc1 = p1.Translated(vc);
1940                                     pc2 = p2.Translated(vc);
1941                                     pc3 = p3.Translated(vc);
1942                                     pc4 = p4.Translated(vc);
1943
1944                                     // Display
1945                                     glNormal3d(xn, yn, zn);
1946                                     pc1.Coord(xc, yc, zc);
1947                                     glVertex3d(xc, yc, zc);
1948                                     pc2.Coord(xc, yc, zc);
1949                                     glVertex3d(xc, yc, zc);
1950                                     pc3.Coord(xc, yc, zc);
1951                                     glVertex3d(xc, yc, zc);
1952                                     pc4.Coord(xc, yc, zc);
1953                                     glVertex3d(xc, yc, zc);
1954
1955                                     if (nearest)
1956                                         break;
1957                                 }
1958                             }
1959                         }
1960                                         }
1961                                 }
1962                         }
1963                         break;
1964                 }
1965                 case Yplus:
1966                 {
1967                         for (ix = 0; ix < nbx; ix++)
1968                         {
1969                                 for (iz = 0; iz < nbz; iz++)
1970                                 {
1971                                         for (iy = nby - 1; iy >= 0; iy--)
1972                                         {
1973                         deepness = voxels->Deepness(ix, iy, iz);
1974                         for (i = 0; i < 8; i++)
1975                         {
1976                             for (j = 0; j < 8; j++)
1977                             {
1978                                 if (deepness == 0 && j)
1979                                 {
1980                                     i = 8;
1981                                     break;
1982                                 }
1983                                 if (deepness == 1 && j)
1984                                     break;
1985                                 if (deepness == 0)
1986                                 {
1987                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1988                                         continue;
1989                                 }
1990                                 else if (deepness == 1)
1991                                 {
1992                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1993                                         continue;
1994                                 }
1995                                 else if (deepness == 2)
1996                                 {
1997                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1998                                         continue;
1999                                 }
2000
2001                                 Standard_Boolean value;
2002                                 switch (deepness)
2003                                 {
2004                                     case 0:
2005                                         value = voxels->Get(ix, iy, iz) == Standard_True;
2006                                         break;
2007                                     case 1:
2008                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
2009                                         break;
2010                                     case 2:
2011                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
2012                                         break;
2013                                 }
2014                                 
2015                                 if (value)
2016                                 {
2017                                     // Define translation vector
2018                                     if (!check_size)
2019                                     {
2020                                         switch (deepness)
2021                                         {
2022                                             case 0:
2023                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
2024                                                 break;
2025                                             case 1:
2026                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
2027                                                 break;
2028                                             case 2:
2029                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
2030                                                 break;
2031                                         }
2032                                     }
2033                                     vc.SetCoord(xc, yc, zc);
2034
2035                                     // Translate
2036                                     pc1 = p1.Translated(vc);
2037                                     pc2 = p2.Translated(vc);
2038                                     pc3 = p3.Translated(vc);
2039                                     pc4 = p4.Translated(vc);
2040
2041                                     // Display
2042                                     glNormal3d(xn, yn, zn);
2043                                     pc1.Coord(xc, yc, zc);
2044                                     glVertex3d(xc, yc, zc);
2045                                     pc2.Coord(xc, yc, zc);
2046                                     glVertex3d(xc, yc, zc);
2047                                     pc3.Coord(xc, yc, zc);
2048                                     glVertex3d(xc, yc, zc);
2049                                     pc4.Coord(xc, yc, zc);
2050                                     glVertex3d(xc, yc, zc);
2051
2052                                     if (nearest)
2053                                         break;
2054                                 }
2055                             }
2056                         }
2057                                         }
2058                                 }
2059                         }
2060                         break;
2061                 }
2062                 case Zminus:
2063                 {
2064                         for (ix = 0; ix < nbx; ix++)
2065                         {
2066                                 for (iy = 0; iy < nby; iy++)
2067                                 {
2068                                         for (iz = 0; iz < nbz; iz++)
2069                                         {
2070                         deepness = voxels->Deepness(ix, iy, iz);
2071                         for (i = 0; i < 8; i++)
2072                         {
2073                             for (j = 0; j < 8; j++)
2074                             {
2075                                 if (deepness == 0 && j)
2076                                 {
2077                                     i = 8;
2078                                     break;
2079                                 }
2080                                 if (deepness == 1 && j)
2081                                     break;
2082                                 if (deepness == 0)
2083                                 {
2084                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2085                                         continue;
2086                                 }
2087                                 else if (deepness == 1)
2088                                 {
2089                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2090                                         continue;
2091                                 }
2092                                 else if (deepness == 2)
2093                                 {
2094                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2095                                         continue;
2096                                 }
2097
2098                                 Standard_Boolean value;
2099                                 switch (deepness)
2100                                 {
2101                                     case 0:
2102                                         value = voxels->Get(ix, iy, iz) == Standard_True;
2103                                         break;
2104                                     case 1:
2105                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
2106                                         break;
2107                                     case 2:
2108                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
2109                                         break;
2110                                 }
2111                                 
2112                                 if (value)
2113                                 {
2114                                     // Define translation vector
2115                                     if (!check_size)
2116                                     {
2117                                         switch (deepness)
2118                                         {
2119                                             case 0:
2120                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
2121                                                 break;
2122                                             case 1:
2123                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
2124                                                 break;
2125                                             case 2:
2126                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
2127                                                 break;
2128                                         }
2129                                     }
2130                                     vc.SetCoord(xc, yc, zc);
2131
2132                                     // Translate
2133                                     pc1 = p1.Translated(vc);
2134                                     pc2 = p2.Translated(vc);
2135                                     pc3 = p3.Translated(vc);
2136                                     pc4 = p4.Translated(vc);
2137
2138                                     // Display
2139                                     glNormal3d(xn, yn, zn);
2140                                     pc1.Coord(xc, yc, zc);
2141                                     glVertex3d(xc, yc, zc);
2142                                     pc2.Coord(xc, yc, zc);
2143                                     glVertex3d(xc, yc, zc);
2144                                     pc3.Coord(xc, yc, zc);
2145                                     glVertex3d(xc, yc, zc);
2146                                     pc4.Coord(xc, yc, zc);
2147                                     glVertex3d(xc, yc, zc);
2148
2149                                     if (nearest)
2150                                         break;
2151                                 }
2152                             }
2153                         }
2154                                         }
2155                                 }
2156                         }
2157                         break;
2158                 }
2159                 case Zplus:
2160                 {
2161                         for (ix = 0; ix < nbx; ix++)
2162                         {
2163                                 for (iy = 0; iy < nby; iy++)
2164                                 {
2165                                         for (iz = nbz - 1; iz >= 0; iz--)
2166                                         {
2167                         deepness = voxels->Deepness(ix, iy, iz);
2168                         for (i = 0; i < 8; i++)
2169                         {
2170                             for (j = 0; j < 8; j++)
2171                             {
2172                                 if (deepness == 0 && j)
2173                                 {
2174                                     i = 8;
2175                                     break;
2176                                 }
2177                                 if (deepness == 1 && j)
2178                                     break;
2179                                 if (deepness == 0)
2180                                 {
2181                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2182                                         continue;
2183                                 }
2184                                 else if (deepness == 1)
2185                                 {
2186                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2187                                         continue;
2188                                 }
2189                                 else if (deepness == 2)
2190                                 {
2191                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2192                                         continue;
2193                                 }
2194
2195                                 Standard_Boolean value;
2196                                 switch (deepness)
2197                                 {
2198                                     case 0:
2199                                         value = voxels->Get(ix, iy, iz) == Standard_True;
2200                                         break;
2201                                     case 1:
2202                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
2203                                         break;
2204                                     case 2:
2205                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
2206                                         break;
2207                                 }
2208                                 
2209                                 if (value)
2210                                 {
2211                                     // Define translation vector
2212                                     if (!check_size)
2213                                     {
2214                                         switch (deepness)
2215                                         {
2216                                             case 0:
2217                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
2218                                                 break;
2219                                             case 1:
2220                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
2221                                                 break;
2222                                             case 2:
2223                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
2224                                                 break;
2225                                         }
2226                                     }
2227                                     vc.SetCoord(xc, yc, zc);
2228
2229                                     // Translate
2230                                     pc1 = p1.Translated(vc);
2231                                     pc2 = p2.Translated(vc);
2232                                     pc3 = p3.Translated(vc);
2233                                     pc4 = p4.Translated(vc);
2234
2235                                     // Display
2236                                     glNormal3d(xn, yn, zn);
2237                                     pc1.Coord(xc, yc, zc);
2238                                     glVertex3d(xc, yc, zc);
2239                                     pc2.Coord(xc, yc, zc);
2240                                     glVertex3d(xc, yc, zc);
2241                                     pc3.Coord(xc, yc, zc);
2242                                     glVertex3d(xc, yc, zc);
2243                                     pc4.Coord(xc, yc, zc);
2244                                     glVertex3d(xc, yc, zc);
2245
2246                                     if (nearest)
2247                                         break;
2248                                 }
2249                             }
2250                         }
2251                                         }
2252                                 }
2253                         }
2254                         break;
2255                 }
2256     }
2257     glEnd();
2258 }
2259
2260
2261
2262 static void drawColorQuadrangles(Voxel_ColorDS* voxels, const VoxelDirection vdir, 
2263                                  const gp_Dir& viewnormal, const Standard_Boolean nearest,
2264                                  const Handle(Quantity_HArray1OfColor)& hcolors,
2265                                  const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
2266                                  const Standard_Byte minvalue, const Standard_Byte maxvalue,
2267                                  const Standard_Real xmin, const Standard_Real xmax,
2268                                  const Standard_Real ymin, const Standard_Real ymax,
2269                                  const Standard_Real zmin, const Standard_Real zmax)
2270 {
2271     gp_Vec vc;
2272     gp_Pnt pc1, pc2, pc3, pc4;
2273     Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 0.0;
2274     Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ();
2275     Standard_Byte value;
2276
2277     // Normal
2278     //viewnormal.Coord(xn, yn, zn);
2279     glNormal3d(xn, yn, zn);
2280
2281     // Colors
2282     const Quantity_Array1OfColor& colors = hcolors->Array1();
2283
2284     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
2285                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
2286                        zmin <= DBL_MAX && zmax >= DBL_MAX);
2287     check_size = !check_size;
2288
2289     glBegin(GL_QUADS);
2290     switch (vdir)
2291         {
2292                 case Xminus:
2293                 {
2294                         for (iy = 0; iy < nby; iy++)
2295                         {
2296                                 for (iz = 0; iz < nbz; iz++)
2297                                 {
2298                                         for (ix = 0; ix < nbx; ix++)
2299                                         {
2300                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2301                             continue;
2302                         value = voxels->Get(ix, iy, iz);
2303                         if (value >= minvalue && value <= maxvalue)
2304                         {
2305                             // Define translation vector
2306                             if (!check_size)
2307                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2308                             vc.SetCoord(xc, yc, zc);
2309
2310                             // Translate
2311                             pc1 = p1.Translated(vc);
2312                             pc2 = p2.Translated(vc);
2313                             pc3 = p3.Translated(vc);
2314                             pc4 = p4.Translated(vc);
2315
2316                             // Color
2317                             setColor(colors.Value(value), Standard_False);
2318
2319                             // Display
2320                             //glNormal3d(xn, yn, zn);
2321                             pc1.Coord(xc, yc, zc);
2322                             glVertex3d(xc, yc, zc);
2323                             pc2.Coord(xc, yc, zc);
2324                             glVertex3d(xc, yc, zc);
2325                             pc3.Coord(xc, yc, zc);
2326                             glVertex3d(xc, yc, zc);
2327                             pc4.Coord(xc, yc, zc);
2328                             glVertex3d(xc, yc, zc);
2329
2330                             if (nearest)
2331                                 break;
2332                         }
2333                     }
2334                                 }
2335                         }
2336                         break;
2337                 }
2338                 case Xplus:
2339                 {
2340                         for (iy = 0; iy < nby; iy++)
2341                         {
2342                                 for (iz = 0; iz < nbz; iz++)
2343                                 {
2344                                         for (ix = nbx - 1; ix >= 0; ix--)
2345                                         {
2346                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2347                             continue;
2348                         value = voxels->Get(ix, iy, iz);
2349                         if (value >= minvalue && value <= maxvalue)
2350                         {
2351                             // Define translation vector
2352                             if (!check_size)
2353                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2354                             vc.SetCoord(xc, yc, zc);
2355
2356                             // Translate
2357                             pc1 = p1.Translated(vc);
2358                             pc2 = p2.Translated(vc);
2359                             pc3 = p3.Translated(vc);
2360                             pc4 = p4.Translated(vc);
2361
2362                             // Color
2363                             setColor(colors.Value(value), Standard_False);
2364
2365                             // Display
2366                             //glNormal3d(xn, yn, zn);
2367                             pc1.Coord(xc, yc, zc);
2368                             glVertex3d(xc, yc, zc);
2369                             pc2.Coord(xc, yc, zc);
2370                             glVertex3d(xc, yc, zc);
2371                             pc3.Coord(xc, yc, zc);
2372                             glVertex3d(xc, yc, zc);
2373                             pc4.Coord(xc, yc, zc);
2374                             glVertex3d(xc, yc, zc);
2375
2376                             if (nearest)
2377                                 break;
2378                         }
2379                                         }
2380                                 }
2381                         }
2382                         break;
2383                 }
2384                 case Yminus:
2385                 {
2386                         for (ix = 0; ix < nbx; ix++)
2387                         {
2388                                 for (iz = 0; iz < nbz; iz++)
2389                                 {
2390                                         for (iy = 0; iy < nby; iy++)
2391                                         {
2392                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2393                             continue;
2394                         value = voxels->Get(ix, iy, iz);
2395                         if (value >= minvalue && value <= maxvalue)
2396                         {
2397                             // Define translation vector
2398                             if (!check_size)
2399                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2400                             vc.SetCoord(xc, yc, zc);
2401
2402                             // Translate
2403                             pc1 = p1.Translated(vc);
2404                             pc2 = p2.Translated(vc);
2405                             pc3 = p3.Translated(vc);
2406                             pc4 = p4.Translated(vc);
2407
2408                             // Color
2409                             setColor(colors.Value(value), Standard_False);
2410
2411                             // Display
2412                             //glNormal3d(xn, yn, zn);
2413                             pc1.Coord(xc, yc, zc);
2414                             glVertex3d(xc, yc, zc);
2415                             pc2.Coord(xc, yc, zc);
2416                             glVertex3d(xc, yc, zc);
2417                             pc3.Coord(xc, yc, zc);
2418                             glVertex3d(xc, yc, zc);
2419                             pc4.Coord(xc, yc, zc);
2420                             glVertex3d(xc, yc, zc);
2421
2422                             if (nearest)
2423                                 break;
2424                         }
2425                                         }
2426                                 }
2427                         }
2428                         break;
2429                 }
2430                 case Yplus:
2431                 {
2432                         for (ix = 0; ix < nbx; ix++)
2433                         {
2434                                 for (iz = 0; iz < nbz; iz++)
2435                                 {
2436                                         for (iy = nby - 1; iy >= 0; iy--)
2437                                         {
2438                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2439                             continue;
2440                         value = voxels->Get(ix, iy, iz);
2441                         if (value >= minvalue && value <= maxvalue)
2442                         {
2443                             // Define translation vector
2444                             if (!check_size)
2445                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2446                             vc.SetCoord(xc, yc, zc);
2447
2448                             // Translate
2449                             pc1 = p1.Translated(vc);
2450                             pc2 = p2.Translated(vc);
2451                             pc3 = p3.Translated(vc);
2452                             pc4 = p4.Translated(vc);
2453
2454                             // Color
2455                             setColor(colors.Value(value), Standard_False);
2456
2457                             // Display
2458                             //glNormal3d(xn, yn, zn);
2459                             pc1.Coord(xc, yc, zc);
2460                             glVertex3d(xc, yc, zc);
2461                             pc2.Coord(xc, yc, zc);
2462                             glVertex3d(xc, yc, zc);
2463                             pc3.Coord(xc, yc, zc);
2464                             glVertex3d(xc, yc, zc);
2465                             pc4.Coord(xc, yc, zc);
2466                             glVertex3d(xc, yc, zc);
2467
2468                             if (nearest)
2469                                 break;
2470                         }
2471                                         }
2472                                 }
2473                         }
2474                         break;
2475                 }
2476                 case Zminus:
2477                 {
2478                         for (ix = 0; ix < nbx; ix++)
2479                         {
2480                                 for (iy = 0; iy < nby; iy++)
2481                                 {
2482                                         for (iz = 0; iz < nbz; iz++)
2483                                         {
2484                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2485                             continue;
2486                         value = voxels->Get(ix, iy, iz);
2487                         if (value >= minvalue && value <= maxvalue)
2488                         {
2489                             // Define translation vector
2490                             if (!check_size)
2491                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2492                             vc.SetCoord(xc, yc, zc);
2493
2494                             // Translate
2495                             pc1 = p1.Translated(vc);
2496                             pc2 = p2.Translated(vc);
2497                             pc3 = p3.Translated(vc);
2498                             pc4 = p4.Translated(vc);
2499
2500                             // Color
2501                             setColor(colors.Value(value), Standard_False);
2502
2503                             // Display
2504                             //glNormal3d(xn, yn, zn);
2505                             pc1.Coord(xc, yc, zc);
2506                             glVertex3d(xc, yc, zc);
2507                             pc2.Coord(xc, yc, zc);
2508                             glVertex3d(xc, yc, zc);
2509                             pc3.Coord(xc, yc, zc);
2510                             glVertex3d(xc, yc, zc);
2511                             pc4.Coord(xc, yc, zc);
2512                             glVertex3d(xc, yc, zc);
2513
2514                             if (nearest)
2515                                 break;
2516                         }
2517                                         }
2518                                 }
2519                         }
2520                         break;
2521                 }
2522                 case Zplus:
2523 &nb