0021189: Clean up KAS:dev:ros and Products
[occt.git] / samples / qt / VoxelDemo / src / VoxelClient_VisDrawer.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include "VoxelClient_VisDrawer.h"
19
20 #include <ElSLib.hxx>
21 #include <gp_Dir.hxx>
22 #include <Geom_Plane.hxx>
23 #include <gce_MakePln.hxx>
24 #include <Quantity_Color.hxx>
25 #include <Aspect_TypeOfLine.hxx>
26 #include <Graphic3d_CUserDraw.hxx>
27
28 #include <InterfaceGraphic_telem.hxx>
29 #include <OpenGl_Element.hxx>
30 #include <OpenGl_Callback.hxx>
31 #include <OpenGl_NamedStatus.hxx>
32
33 #include <GL/gl.h>
34 #include <GL/glu.h>
35
36 /**************************************************************************/
37
38 class VoxelClient_VisDrawer::VisElement : public OpenGl_Element
39 {
40 public:
41
42   VisElement (Voxel_VisData*);
43   virtual ~VisElement();
44
45   void EvaluateBounds (Graphic3d_CBounds& theMinMax);
46
47   void Render (const Handle(OpenGl_Workspace) &theWorkspace) const;
48
49 private:
50
51   VoxelClient_VisDrawer* myHandler;
52
53 public:
54
55   DEFINE_STANDARD_ALLOC
56
57 };
58
59 //=======================================================================
60 //function : VisElement
61 //purpose  : Constructor
62 //=======================================================================
63
64 VoxelClient_VisDrawer::VisElement::VisElement (Voxel_VisData* theData)
65 {
66   myHandler = new VoxelClient_VisDrawer (theData);
67 }
68
69 //=======================================================================
70 //function : ~VisElement
71 //purpose  : Destructor
72 //=======================================================================
73
74 VoxelClient_VisDrawer::VisElement::~VisElement ()
75 {
76   delete myHandler;
77 }
78
79 //=======================================================================
80 //function : EvaluateBounds
81 //purpose  :
82 //=======================================================================
83
84 void VoxelClient_VisDrawer::VisElement::EvaluateBounds
85   (Graphic3d_CBounds& theMinMax)
86 {
87   myHandler->EvalMinMax (theMinMax);
88 }
89
90 //=======================================================================
91 //function : Render
92 //purpose  : display element
93 //=======================================================================
94
95 void VoxelClient_VisDrawer::VisElement::Render
96   (const Handle (OpenGl_Workspace) &theWorkspace) const
97 {
98   const Standard_Boolean aHl = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT);
99   myHandler->Display (aHl);
100 }
101
102 //=======================================================================
103 //function : VisDrawerCallBack
104 //purpose  : visdrawer element create callback, adds an element to graphic
105 //           driver's structure
106 //=======================================================================
107
108 static OpenGl_Element* VisDrawerCallBack (const Graphic3d_CUserDraw* theUserDraw)
109 {
110   if (theUserDraw == 0)
111     return 0;
112
113   // Retrieve the user structure
114   Voxel_VisData* aUserData = (Voxel_VisData*) (theUserDraw->Data);
115
116   if (aUserData == 0)
117     return 0;
118
119   VoxelClient_VisDrawer::VisElement *aElem = 
120     new VoxelClient_VisDrawer::VisElement (aUserData);
121
122   if (theUserDraw->Bounds != 0)
123     aElem->EvaluateBounds (*(theUserDraw->Bounds));
124
125   return aElem;
126 }
127
128 /**************************************************************************/
129 void VoxelClient_VisDrawer::Init()
130 {
131     static Standard_Boolean isInitializeded(Standard_False);
132
133     if (!isInitializeded)
134     {
135         isInitializeded = Standard_True;
136
137         OpenGl_UserDrawCallback& aCallback = UserDrawCallback ();
138         aCallback = VisDrawerCallBack;
139     }
140 }
141
142 /**************************************************************************/
143 VoxelClient_VisDrawer::VoxelClient_VisDrawer(Voxel_VisData * theData):myData(theData)
144 {
145
146 }
147
148 /**************************************************************************/
149 VoxelClient_VisDrawer::~VoxelClient_VisDrawer()
150 {
151     if (myData)
152     {
153         // Because a pointer to the data is copied, 
154         // it is possible to make an attempt to delete GL lists for
155         // a structure, which is already deleted.
156         // Such a situation may happen on close of the application.
157         // Therefore, this try / catch is used.
158
159         try
160         {
161             Standard_Integer idir;
162
163             // Points
164
165             // BoolDS
166             if (myData->myDisplay.myBoolPointsList > 0)
167             {
168                 glDeleteLists(myData->myDisplay.myBoolPointsList, 1);
169                 myData->myDisplay.myBoolPointsList = -1;
170             }
171             for (idir = Xminus; idir <= Zplus; idir++)
172             {
173                 if (myData->myDisplay.myBoolNearestPointsList[idir] > 0)
174                 {
175                     glDeleteLists(myData->myDisplay.myBoolNearestPointsList[idir], 1);
176                     myData->myDisplay.myBoolNearestPointsList[idir] = -1;
177                 }
178             }
179
180             // ColorDS
181             if (myData->myDisplay.myColorPointsList > 0)
182             {
183                 glDeleteLists(myData->myDisplay.myColorPointsList, 1);
184                 myData->myDisplay.myColorPointsList = -1;
185             }
186             for (idir = Xminus; idir <= Zplus; idir++)
187             {
188                 if (myData->myDisplay.myColorNearestPointsList[idir] > 0)
189                 {
190                     glDeleteLists(myData->myDisplay.myColorNearestPointsList[idir], 1);
191                     myData->myDisplay.myColorNearestPointsList[idir] = -1;
192                 }
193             }
194
195             // ROctBoolDS
196             if (myData->myDisplay.myROctBoolPointsList > 0)
197             {
198                 glDeleteLists(myData->myDisplay.myROctBoolPointsList, 1);
199                 myData->myDisplay.myROctBoolPointsList = -1;
200             }
201             for (idir = Xminus; idir <= Zplus; idir++)
202             {
203                 if (myData->myDisplay.myROctBoolNearestPointsList[idir] > 0)
204                 {
205                     glDeleteLists(myData->myDisplay.myROctBoolNearestPointsList[idir], 1);
206                     myData->myDisplay.myROctBoolNearestPointsList[idir] = -1;
207                 }
208             }
209
210             // Triangulation
211             if (myData->myDisplay.myTriangulationList > 0)
212             {
213                 glDeleteLists(myData->myDisplay.myTriangulationList, 1);
214                 myData->myDisplay.myTriangulationList = -1;
215             }
216         }
217         catch (...)
218         {
219
220         }
221     }
222 }
223
224 /**************************************************************************/
225 void VoxelClient_VisDrawer::EvalMinMax(Graphic3d_CBounds & theMinMax) const 
226 {
227     theMinMax.XMin = FLT_MAX;
228     theMinMax.YMin = FLT_MAX;
229     theMinMax.ZMin = FLT_MAX;
230     theMinMax.XMax = -FLT_MAX;
231     theMinMax.YMax = -FLT_MAX;
232     theMinMax.ZMax = -FLT_MAX;
233     if(!myData)
234         return;
235     if(myData->myBoolVoxels)
236     {
237         if (theMinMax.XMin > myData->myBoolVoxels->GetX())
238                 theMinMax.XMin = myData->myBoolVoxels->GetX();
239         if (theMinMax.XMax < myData->myBoolVoxels->GetX() + myData->myBoolVoxels->GetXLen())
240                 theMinMax.XMax = myData->myBoolVoxels->GetX() + myData->myBoolVoxels->GetXLen();
241         if (theMinMax.YMin > myData->myBoolVoxels->GetY())
242                 theMinMax.YMin = myData->myBoolVoxels->GetY();
243         if (theMinMax.YMax < myData->myBoolVoxels->GetY() + myData->myBoolVoxels->GetYLen())
244                 theMinMax.YMax = myData->myBoolVoxels->GetY() + myData->myBoolVoxels->GetYLen();
245         if (theMinMax.ZMin > myData->myBoolVoxels->GetZ())
246                 theMinMax.ZMin = myData->myBoolVoxels->GetZ();
247         if (theMinMax.ZMax < myData->myBoolVoxels->GetZ() + myData->myBoolVoxels->GetZLen())
248                 theMinMax.ZMax = myData->myBoolVoxels->GetZ() + myData->myBoolVoxels->GetZLen();
249     }
250     if(myData->myColorVoxels)
251     {
252         if (theMinMax.XMin > myData->myColorVoxels->GetX())
253                 theMinMax.XMin = myData->myColorVoxels->GetX();
254         if (theMinMax.XMax < myData->myColorVoxels->GetX() + myData->myColorVoxels->GetXLen())
255                 theMinMax.XMax = myData->myColorVoxels->GetX() + myData->myColorVoxels->GetXLen();
256         if (theMinMax.YMin > myData->myColorVoxels->GetY())
257                 theMinMax.YMin = myData->myColorVoxels->GetY();
258         if (theMinMax.YMax < myData->myColorVoxels->GetY() + myData->myColorVoxels->GetYLen())
259                 theMinMax.YMax = myData->myColorVoxels->GetY() + myData->myColorVoxels->GetYLen();
260         if (theMinMax.ZMin > myData->myColorVoxels->GetZ())
261                 theMinMax.ZMin = myData->myColorVoxels->GetZ();
262         if (theMinMax.ZMax < myData->myColorVoxels->GetZ() + myData->myColorVoxels->GetZLen())
263                 theMinMax.ZMax = myData->myColorVoxels->GetZ() + myData->myColorVoxels->GetZLen();
264     }
265     if(myData->myROctBoolVoxels)
266     {
267         if (theMinMax.XMin > myData->myROctBoolVoxels->GetX())
268                 theMinMax.XMin = myData->myROctBoolVoxels->GetX();
269         if (theMinMax.XMax < myData->myROctBoolVoxels->GetX() + myData->myROctBoolVoxels->GetXLen())
270                 theMinMax.XMax = myData->myROctBoolVoxels->GetX() + myData->myROctBoolVoxels->GetXLen();
271         if (theMinMax.YMin > myData->myROctBoolVoxels->GetY())
272                 theMinMax.YMin = myData->myROctBoolVoxels->GetY();
273         if (theMinMax.YMax < myData->myROctBoolVoxels->GetY() + myData->myROctBoolVoxels->GetYLen())
274                 theMinMax.YMax = myData->myROctBoolVoxels->GetY() + myData->myROctBoolVoxels->GetYLen();
275         if (theMinMax.ZMin > myData->myROctBoolVoxels->GetZ())
276                 theMinMax.ZMin = myData->myROctBoolVoxels->GetZ();
277         if (theMinMax.ZMax < myData->myROctBoolVoxels->GetZ() + myData->myROctBoolVoxels->GetZLen())
278                 theMinMax.ZMax = myData->myROctBoolVoxels->GetZ() + myData->myROctBoolVoxels->GetZLen();
279     }
280     if (!myData->myTriangulation.IsNull())
281     {
282         Standard_Real x, y, z;
283         const TColgp_Array1OfPnt& nodes = myData->myTriangulation->Nodes();
284         Standard_Integer inode = nodes.Lower(), nb_nodes = nodes.Upper();
285         for (; inode <= nb_nodes; inode++)
286         {
287             nodes.Value(inode).Coord(x, y, z);
288             if (theMinMax.XMin > x)
289                     theMinMax.XMin = x;
290             if (theMinMax.XMax < x)
291                     theMinMax.XMax = x;
292             if (theMinMax.YMin > y)
293                     theMinMax.YMin = y;
294             if (theMinMax.YMax < y)
295                     theMinMax.YMax = y;
296             if (theMinMax.ZMin > z)
297                     theMinMax.ZMin = z;
298             if (theMinMax.ZMax < z)
299                     theMinMax.ZMax = z;
300         }
301     }
302 }
303
304 /**************************************************************************/
305 void VoxelClient_VisDrawer::Display(const Standard_Boolean theHighlight)
306 {
307     if (!myData)
308         return;
309     if (myData->myBoolVoxels)
310         DisplayVoxels(theHighlight);
311     if (myData->myColorVoxels)
312         DisplayVoxels(theHighlight);
313     if (myData->myROctBoolVoxels)
314         DisplayVoxels(theHighlight);
315     if (!myData->myTriangulation.IsNull())
316         DisplayTriangulation(theHighlight);
317 }
318
319 // Some static method to define Open GL visual attributes
320 // COlor
321 static void setColor(const Quantity_Color& color, const Standard_Boolean highlight)
322 {
323     static Quantity_Color highlight_color(Quantity_NOC_BLUE1);
324                 if(highlight)
325         glColor3f(highlight_color.Red(), highlight_color.Green(), highlight_color.Blue());
326     else
327         glColor3d(color.Red(), color.Green(), color.Blue());
328 }
329
330 // Type of Line
331 static void setTypeOfLine(const Aspect_TypeOfLine type)
332 {
333     if(type == Aspect_TOL_SOLID)
334     {
335         glDisable(GL_LINE_STIPPLE);
336     }
337     else
338     {
339         glEnable(GL_LINE_STIPPLE);
340         if(type == Aspect_TOL_DOT)
341             glLineStipple(1, 0xCCCC);
342         else if(type == Aspect_TOL_DASH)
343             glLineStipple(1, 0xFFC0);
344         else if(type == Aspect_TOL_DOTDASH)
345             glLineStipple(1, 0xFF18);
346     }
347 }
348
349 // Width of Line
350 static void setWidthOfLine(const Standard_Integer width)
351 {
352     glLineWidth((Standard_ShortReal) width);
353 }
354
355 // Normal of the view
356 static void getNormal(gp_Dir& normal) 
357 {
358         Standard_Real x, y, z;
359         GLint viewport[4];
360         GLdouble model_matrix[16], proj_matrix[16];
361
362         glGetDoublev(GL_MODELVIEW_MATRIX,  model_matrix);
363         glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix);
364         glGetIntegerv(GL_VIEWPORT, viewport);
365
366         gluUnProject(viewport[0], viewport[1], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
367         gp_Pnt p1(x, y, z);
368         gluUnProject(viewport[0] + viewport[2], viewport[1], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
369         gp_Pnt p2(x, y, z);
370         gluUnProject(viewport[0], viewport[1] + viewport[3], 0., model_matrix, proj_matrix, viewport, &x, &y, &z);
371         gp_Pnt p3(x, y, z);
372
373         gce_MakePln mkNormal(p1, p2, p3);
374         if (mkNormal.IsDone()) 
375         {
376                 const gp_Pln& normal_plane = mkNormal.Value();
377                 normal = normal_plane.Axis().Direction();
378         }
379         else
380         {
381                 normal = gp::DZ();
382         }
383 }
384
385 // Normal 2 VoxelDirection converter
386 static VoxelDirection getVoxelDirection(const gp_Dir& viewnormal)
387 {
388     VoxelDirection vdir;
389         Standard_Real fabsviewnormalx = fabs(viewnormal.X());
390         Standard_Real fabsviewnormaly = fabs(viewnormal.Y());
391         Standard_Real fabsviewnormalz = fabs(viewnormal.Z());
392         if (fabsviewnormalx >= fabsviewnormaly &&
393                 fabsviewnormalx >= fabsviewnormalz)
394         {
395                 if (viewnormal.X() > 0)
396                         vdir = Xminus;
397                 else
398                         vdir = Xplus;
399         }
400         else if (fabsviewnormaly >= fabsviewnormalx &&
401                          fabsviewnormaly >= fabsviewnormalz)
402         {
403                 if (viewnormal.Y() > 0)
404                         vdir = Yminus;
405                 else
406                         vdir = Yplus;
407         }
408         else if (fabsviewnormalz >= fabsviewnormalx &&
409                          fabsviewnormalz >= fabsviewnormaly)
410         {
411                 if (viewnormal.Z() > 0)
412                         vdir = Zminus;
413                 else
414                         vdir = Zplus;
415         }
416     return vdir;
417 }
418
419 // Normal 2 VoxelDirection 3 converter
420 static void getVoxel3Directions(const gp_Dir& viewnormal,
421                                 VoxelDirection& vdir1,
422                                 VoxelDirection& vdir2,
423                                 VoxelDirection& vdir3)
424 {
425     Standard_Boolean vdir1_set = Standard_False, vdir2_set = Standard_False, vdir3_set = Standard_False;
426
427     // Test X minus
428     Standard_Real dot = viewnormal.Dot(-gp::DX());
429     if (dot >= 0.0)
430     {
431         if (!vdir1_set)
432         {
433             vdir1 = Xminus;
434             vdir1_set = Standard_True;
435         }
436         else if (!vdir2_set)
437         {
438             vdir2 = Xminus;
439             vdir2_set = Standard_True;
440         }
441         else if (!vdir3_set)
442         {
443             vdir3 = Xminus;
444             vdir3_set = Standard_True;
445         }
446     }
447
448     // Test X plus
449     dot = viewnormal.Dot(gp::DX());
450     if (dot >= 0.0)
451     {
452         if (!vdir1_set)
453         {
454             vdir1 = Xplus;
455             vdir1_set = Standard_True;
456         }
457         else if (!vdir2_set)
458         {
459             vdir2 = Xplus;
460             vdir2_set = Standard_True;
461         }
462         else if (!vdir3_set)
463         {
464             vdir3 = Xplus;
465             vdir3_set = Standard_True;
466         }
467     }
468
469     // Test Y minus
470     dot = viewnormal.Dot(-gp::DY());
471     if (dot >= 0.0)
472     {
473         if (!vdir1_set)
474         {
475             vdir1 = Yminus;
476             vdir1_set = Standard_True;
477         }
478         else if (!vdir2_set)
479         {
480             vdir2 = Yminus;
481             vdir2_set = Standard_True;
482         }
483         else if (!vdir3_set)
484         {
485             vdir3 = Yminus;
486             vdir3_set = Standard_True;
487         }
488     }
489
490     // Test Y plus
491     dot = viewnormal.Dot(gp::DY());
492     if (dot >= 0.0)
493     {
494         if (!vdir1_set)
495         {
496             vdir1 = Yplus;
497             vdir1_set = Standard_True;
498         }
499         else if (!vdir2_set)
500         {
501             vdir2 = Yplus;
502             vdir2_set = Standard_True;
503         }
504         else if (!vdir3_set)
505         {
506             vdir3 = Yplus;
507             vdir3_set = Standard_True;
508         }
509     }
510
511     // Test Z minus
512     dot = viewnormal.Dot(-gp::DZ());
513     if (dot >= 0.0)
514     {
515         if (!vdir1_set)
516         {
517             vdir1 = Zminus;
518             vdir1_set = Standard_True;
519         }
520         else if (!vdir2_set)
521         {
522             vdir2 = Zminus;
523             vdir2_set = Standard_True;
524         }
525         else if (!vdir3_set)
526         {
527             vdir3 = Zminus;
528             vdir3_set = Standard_True;
529         }
530     }
531
532     // Test Y plus
533     dot = viewnormal.Dot(gp::DZ());
534     if (dot >= 0.0)
535     {
536         if (!vdir1_set)
537         {
538             vdir1 = Zplus;
539             vdir1_set = Standard_True;
540         }
541         else if (!vdir2_set)
542         {
543             vdir2 = Zplus;
544             vdir2_set = Standard_True;
545         }
546         else if (!vdir3_set)
547         {
548             vdir3 = Zplus;
549             vdir3_set = Standard_True;
550         }
551     }
552 }
553
554 static Standard_Boolean CheckSize(Voxel_DS* voxels, 
555                       const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, 
556                       const Standard_Real xmin, const Standard_Real xmax,
557                       const Standard_Real ymin, const Standard_Real ymax,
558                       const Standard_Real zmin, const Standard_Real zmax,
559                       Standard_Real& xc, Standard_Real& yc, Standard_Real& zc)
560 {
561     voxels->GetCenter(ix, iy, iz, xc, yc, zc);
562     if (xc < xmin || xc > xmax)
563         return Standard_False;
564     if (yc < ymin || yc > ymax)
565         return Standard_False;
566     if (zc < zmin || zc > zmax)
567         return Standard_False;
568     return Standard_True;
569 }
570
571 static Standard_Boolean CheckSize(Voxel_ROctBoolDS* voxels, 
572                       const Standard_Integer ix, const Standard_Integer iy, const Standard_Integer iz, 
573                       const Standard_Integer i, const Standard_Integer j,
574                       const Standard_Real xmin, const Standard_Real xmax,
575                       const Standard_Real ymin, const Standard_Real ymax,
576                       const Standard_Real zmin, const Standard_Real zmax,
577                       Standard_Real& xc, Standard_Real& yc, Standard_Real& zc)
578 {
579     if (j == -1)
580         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
581     else
582         voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
583     if (xc < xmin || xc > xmax)
584         return Standard_False;
585     if (yc < ymin || yc > ymax)
586         return Standard_False;
587     if (zc < zmin || zc > zmax)
588         return Standard_False;
589     return Standard_True;
590 }
591
592 static void drawBoolPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
593                            Voxel_BoolDS* voxels,
594                            const Standard_Real xmin, const Standard_Real xmax,
595                            const Standard_Real ymin, const Standard_Real ymax,
596                            const Standard_Real zmin, const Standard_Real zmax)
597 {
598         Standard_Real xc, yc, zc;
599         Standard_Integer ix = 0, nbx = voxels->GetNbX();
600         Standard_Integer iy = 0, nby = voxels->GetNbY();
601         Standard_Integer iz = 0, nbz = voxels->GetNbZ();
602
603     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
604                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
605                        zmin <= DBL_MAX && zmax >= DBL_MAX);
606     check_size = !check_size;
607
608     glBegin(GL_POINTS);
609     switch (vdir)
610         {
611                 case Xminus:
612                 {
613                         for (iy = 0; iy < nby; iy++)
614                         {
615                                 for (iz = 0; iz < nbz; iz++)
616                                 {
617                                         for (ix = 0; ix < nbx; ix++)
618                                         {
619                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
620                             continue;
621                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
622                                                 if (value)
623                                                 {
624                             if (!check_size)
625                                                             voxels->GetCenter(ix, iy, iz, xc, yc, zc);
626                                                         glVertex3d(xc, yc, zc);
627                             if (nearest)
628                                 break;
629                                                 }
630                                         }
631                                 }
632                         }
633                         break;
634                 }
635                 case Xplus:
636                 {
637                         for (iy = 0; iy < nby; iy++)
638                         {
639                                 for (iz = 0; iz < nbz; iz++)
640                                 {
641                                         for (ix = nbx - 1; ix >= 0; ix--)
642                                         {
643                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
644                             continue;
645                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
646                                                 if (value)
647                                                 {
648                             if (!check_size)
649                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
650                                                         glVertex3d(xc, yc, zc);
651                             if (nearest)
652                                 break;
653                                                 }
654                                         }
655                                 }
656                         }
657                         break;
658                 }
659                 case Yminus:
660                 {
661                         for (ix = 0; ix < nbx; ix++)
662                         {
663                                 for (iz = 0; iz < nbz; iz++)
664                                 {
665                                         for (iy = 0; iy < nby; iy++)
666                                         {
667                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
668                             continue;
669                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
670                                                 if (value)
671                                                 {
672                             if (!check_size)
673                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
674                                                         glVertex3d(xc, yc, zc);
675                             if (nearest)
676                                 break;
677                                                 }
678                                         }
679                                 }
680                         }
681                         break;
682                 }
683                 case Yplus:
684                 {
685                         for (ix = 0; ix < nbx; ix++)
686                         {
687                                 for (iz = 0; iz < nbz; iz++)
688                                 {
689                                         for (iy = nby - 1; iy >= 0; iy--)
690                                         {
691                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
692                             continue;
693                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
694                                                 if (value)
695                                                 {
696                             if (!check_size)
697                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
698                                                         glVertex3d(xc, yc, zc);
699                             if (nearest)
700                                 break;
701                                                 }
702                                         }
703                                 }
704                         }
705                         break;
706                 }
707                 case Zminus:
708                 {
709                         for (ix = 0; ix < nbx; ix++)
710                         {
711                                 for (iy = 0; iy < nby; iy++)
712                                 {
713                                         for (iz = 0; iz < nbz; iz++)
714                                         {
715                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
716                             continue;
717                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
718                                                 if (value)
719                                                 {
720                             if (!check_size)
721                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
722                                                         glVertex3d(xc, yc, zc);
723                             if (nearest)
724                                 break;
725                                                 }
726                                         }
727                                 }
728                         }
729                         break;
730                 }
731                 case Zplus:
732                 {
733                         for (ix = 0; ix < nbx; ix++)
734                         {
735                                 for (iy = 0; iy < nby; iy++)
736                                 {
737                                         for (iz = nbz - 1; iz >= 0; iz--)
738                                         {
739                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
740                             continue;
741                                                 Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
742                                                 if (value)
743                                                 {
744                             if (!check_size)
745                                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
746                                                         glVertex3d(xc, yc, zc);
747                             if (nearest)
748                                 break;
749                                                 }
750                                         }
751                                 }
752                         }
753                         break;
754                 }
755         }
756     glEnd();
757 }
758
759 static void drawROctBoolPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
760                                Voxel_ROctBoolDS* voxels,
761                                const Standard_Real xmin, const Standard_Real xmax,
762                                const Standard_Real ymin, const Standard_Real ymax,
763                                const Standard_Real zmin, const Standard_Real zmax)
764 {
765         Standard_Real xc, yc, zc;
766         Standard_Integer ix = 0, nbx = voxels->GetNbX();
767         Standard_Integer iy = 0, nby = voxels->GetNbY();
768         Standard_Integer iz = 0, nbz = voxels->GetNbZ();
769     Standard_Integer i, j;
770
771     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
772                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
773                        zmin <= DBL_MAX && zmax >= DBL_MAX);
774     check_size = !check_size;
775
776     glBegin(GL_POINTS);
777     switch (vdir)
778         {
779                 case Xminus:
780                 {
781                         for (iy = 0; iy < nby; iy++)
782                         {
783                                 for (iz = 0; iz < nbz; iz++)
784                                 {
785                                         for (ix = 0; ix < nbx; ix++)
786                                         {
787                         switch (voxels->Deepness(ix, iy, iz))
788                         {
789                             case 0:
790                             {
791                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
792                                     continue;
793                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
794                                                         if (value)
795                                                         {
796                                     if (!check_size)
797                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
798                                                                 glVertex3d(xc, yc, zc);
799                                     if (nearest)
800                                         break;
801                                                         }
802                                 break;
803                             }
804                             case 1:
805                             {
806                                 for (i = 0; i < 8; i++)
807                                 {
808                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
809                                         continue;
810                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
811                                                             if (value)
812                                                             {
813                                         if (!check_size)
814                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
815                                                                     glVertex3d(xc, yc, zc);
816                                         if (nearest)
817                                             break;
818                                                             }
819                                 }
820                                 break;
821                             }
822                             case 2:
823                             {
824                                 for (i = 0; i < 8; i++)
825                                 {
826                                     for (j = 0; j < 8; j++)
827                                     {
828                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
829                                             continue;
830                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
831                                                                 if (value)
832                                                                 {
833                                             if (!check_size)
834                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
835                                                                         glVertex3d(xc, yc, zc);
836                                             if (nearest)
837                                                 break;
838                                                                 }
839                                     }
840                                 }
841                                 break;
842                             }
843                         }
844                                         }
845                                 }
846                         }
847                         break;
848                 }
849                 case Xplus:
850                 {
851                         for (iy = 0; iy < nby; iy++)
852                         {
853                                 for (iz = 0; iz < nbz; iz++)
854                                 {
855                                         for (ix = nbx - 1; ix >= 0; ix--)
856                                         {
857                         switch (voxels->Deepness(ix, iy, iz))
858                         {
859                             case 0:
860                             {
861                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
862                                     continue;
863                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
864                                                         if (value)
865                                                         {
866                                     if (!check_size)
867                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
868                                                                 glVertex3d(xc, yc, zc);
869                                     if (nearest)
870                                         break;
871                                                         }
872                                 break;
873                             }
874                             case 1:
875                             {
876                                 for (i = 0; i < 8; i++)
877                                 {
878                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
879                                         continue;
880                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
881                                                             if (value)
882                                                             {
883                                         if (!check_size)
884                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
885                                                                     glVertex3d(xc, yc, zc);
886                                         if (nearest)
887                                             break;
888                                                             }
889                                 }
890                                 break;
891                             }
892                             case 2:
893                             {
894                                 for (i = 0; i < 8; i++)
895                                 {
896                                     for (j = 0; j < 8; j++)
897                                     {
898                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
899                                             continue;
900                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
901                                                                 if (value)
902                                                                 {
903                                             if (!check_size)
904                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
905                                                                         glVertex3d(xc, yc, zc);
906                                             if (nearest)
907                                                 break;
908                                                                 }
909                                     }
910                                 }
911                                 break;
912                             }
913                         }
914                                         }
915                                 }
916                         }
917                         break;
918                 }
919                 case Yminus:
920                 {
921                         for (ix = 0; ix < nbx; ix++)
922                         {
923                                 for (iz = 0; iz < nbz; iz++)
924                                 {
925                                         for (iy = 0; iy < nby; iy++)
926                                         {
927                         switch (voxels->Deepness(ix, iy, iz))
928                         {
929                             case 0:
930                             {
931                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
932                                     continue;
933                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
934                                                         if (value)
935                                                         {
936                                     if (!check_size)
937                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
938                                                                 glVertex3d(xc, yc, zc);
939                                     if (nearest)
940                                         break;
941                                                         }
942                                 break;
943                             }
944                             case 1:
945                             {
946                                 for (i = 0; i < 8; i++)
947                                 {
948                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
949                                         continue;
950                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
951                                                             if (value)
952                                                             {
953                                         if (!check_size)
954                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
955                                                                     glVertex3d(xc, yc, zc);
956                                         if (nearest)
957                                             break;
958                                                             }
959                                 }
960                                 break;
961                             }
962                             case 2:
963                             {
964                                 for (i = 0; i < 8; i++)
965                                 {
966                                     for (j = 0; j < 8; j++)
967                                     {
968                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
969                                             continue;
970                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
971                                                                 if (value)
972                                                                 {
973                                             if (!check_size)
974                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
975                                                                         glVertex3d(xc, yc, zc);
976                                             if (nearest)
977                                                 break;
978                                                                 }
979                                     }
980                                 }
981                                 break;
982                             }
983                         }
984                                         }
985                                 }
986                         }
987                         break;
988                 }
989                 case Yplus:
990                 {
991                         for (ix = 0; ix < nbx; ix++)
992                         {
993                                 for (iz = 0; iz < nbz; iz++)
994                                 {
995                                         for (iy = nby - 1; iy >= 0; iy--)
996                                         {
997                         switch (voxels->Deepness(ix, iy, iz))
998                         {
999                             case 0:
1000                             {
1001                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1002                                     continue;
1003                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1004                                                         if (value)
1005                                                         {
1006                                     if (!check_size)
1007                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1008                                                                 glVertex3d(xc, yc, zc);
1009                                     if (nearest)
1010                                         break;
1011                                                         }
1012                                 break;
1013                             }
1014                             case 1:
1015                             {
1016                                 for (i = 0; i < 8; i++)
1017                                 {
1018                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1019                                         continue;
1020                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
1021                                                             if (value)
1022                                                             {
1023                                         if (!check_size)
1024                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1025                                                                     glVertex3d(xc, yc, zc);
1026                                         if (nearest)
1027                                             break;
1028                                                             }
1029                                 }
1030                                 break;
1031                             }
1032                             case 2:
1033                             {
1034                                 for (i = 0; i < 8; i++)
1035                                 {
1036                                     for (j = 0; j < 8; j++)
1037                                     {
1038                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1039                                             continue;
1040                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1041                                                                 if (value)
1042                                                                 {
1043                                             if (!check_size)
1044                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1045                                                                         glVertex3d(xc, yc, zc);
1046                                             if (nearest)
1047                                                 break;
1048                                                                 }
1049                                     }
1050                                 }
1051                                 break;
1052                             }
1053                         }
1054                                         }
1055                                 }
1056                         }
1057                         break;
1058                 }
1059                 case Zminus:
1060                 {
1061                         for (ix = 0; ix < nbx; ix++)
1062                         {
1063                                 for (iy = 0; iy < nby; iy++)
1064                                 {
1065                                         for (iz = 0; iz < nbz; iz++)
1066                                         {
1067                         switch (voxels->Deepness(ix, iy, iz))
1068                         {
1069                             case 0:
1070                             {
1071                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1072                                     continue;
1073                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1074                                                         if (value)
1075                                                         {
1076                                     if (!check_size)
1077                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1078                                                                 glVertex3d(xc, yc, zc);
1079                                     if (nearest)
1080                                         break;
1081                                                         }
1082                                 break;
1083                             }
1084                             case 1:
1085                             {
1086                                 for (i = 0; i < 8; i++)
1087                                 {
1088                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1089                                         continue;
1090                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
1091                                                             if (value)
1092                                                             {
1093                                         if (!check_size)
1094                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1095                                                                     glVertex3d(xc, yc, zc);
1096                                         if (nearest)
1097                                             break;
1098                                                             }
1099                                 }
1100                                 break;
1101                             }
1102                             case 2:
1103                             {
1104                                 for (i = 0; i < 8; i++)
1105                                 {
1106                                     for (j = 0; j < 8; j++)
1107                                     {
1108                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1109                                             continue;
1110                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1111                                                                 if (value)
1112                                                                 {
1113                                             if (!check_size)
1114                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1115                                                                         glVertex3d(xc, yc, zc);
1116                                             if (nearest)
1117                                                 break;
1118                                                                 }
1119                                     }
1120                                 }
1121                                 break;
1122                             }
1123                         }
1124                                         }
1125                                 }
1126                         }
1127                         break;
1128                 }
1129                 case Zplus:
1130                 {
1131                         for (ix = 0; ix < nbx; ix++)
1132                         {
1133                                 for (iy = 0; iy < nby; iy++)
1134                                 {
1135                                         for (iz = nbz - 1; iz >= 0; iz--)
1136                                         {
1137                         switch (voxels->Deepness(ix, iy, iz))
1138                         {
1139                             case 0:
1140                             {
1141                                 if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1142                                     continue;
1143                                                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1144                                                         if (value)
1145                                                         {
1146                                     if (!check_size)
1147                                                                     ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1148                                                                 glVertex3d(xc, yc, zc);
1149                                     if (nearest)
1150                                         break;
1151                                                         }
1152                                 break;
1153                             }
1154                             case 1:
1155                             {
1156                                 for (i = 0; i < 8; i++)
1157                                 {
1158                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1159                                         continue;
1160                                                             Standard_Boolean value = voxels->Get(ix, iy, iz, i) == Standard_True;
1161                                                             if (value)
1162                                                             {
1163                                         if (!check_size)
1164                                                                         voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1165                                                                     glVertex3d(xc, yc, zc);
1166                                         if (nearest)
1167                                             break;
1168                                                             }
1169                                 }
1170                                 break;
1171                             }
1172                             case 2:
1173                             {
1174                                 for (i = 0; i < 8; i++)
1175                                 {
1176                                     for (j = 0; j < 8; j++)
1177                                     {
1178                                         if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1179                                             continue;
1180                                                                 Standard_Boolean value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1181                                                                 if (value)
1182                                                                 {
1183                                             if (!check_size)
1184                                                                             voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1185                                                                         glVertex3d(xc, yc, zc);
1186                                             if (nearest)
1187                                                 break;
1188                                                                 }
1189                                     }
1190                                 }
1191                                 break;
1192                             }
1193                         }
1194                                         }
1195                                 }
1196                         }
1197                         break;
1198                 }
1199         }
1200     glEnd();
1201 }
1202
1203
1204
1205 static void drawColorPoints(const VoxelDirection vdir, const Standard_Boolean nearest,
1206                             Voxel_ColorDS* voxels, const Handle(Quantity_HArray1OfColor)& hcolors,
1207                             const Standard_Byte minvalue, const Standard_Byte maxvalue,
1208                             const Standard_Real xmin, const Standard_Real xmax,
1209                             const Standard_Real ymin, const Standard_Real ymax,
1210                             const Standard_Real zmin, const Standard_Real zmax)
1211 {
1212         Standard_Real xc, yc, zc;
1213         Standard_Integer ix = 0, nbx = voxels->GetNbX();
1214         Standard_Integer iy = 0, nby = voxels->GetNbY();
1215         Standard_Integer iz = 0, nbz = voxels->GetNbZ();
1216     Standard_Byte value;
1217
1218     // Colors
1219     const Quantity_Array1OfColor& colors = hcolors->Array1();
1220
1221     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
1222                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
1223                        zmin <= DBL_MAX && zmax >= DBL_MAX);
1224     check_size = !check_size;
1225
1226     glBegin(GL_POINTS);
1227     switch (vdir)
1228         {
1229                 case Xminus:
1230                 {
1231                         for (iy = 0; iy < nby; iy++)
1232                         {
1233                                 for (iz = 0; iz < nbz; iz++)
1234                                 {
1235                                         for (ix = 0; ix < nbx; ix++)
1236                                         {
1237                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1238                             continue;
1239                             value = voxels->Get(ix, iy, iz);
1240                             if (value >= minvalue && value <= maxvalue)
1241                             {
1242                             if (!check_size)
1243                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1244                             setColor(colors.Value(value), Standard_False);
1245                                     glVertex3d(xc, yc, zc);
1246                             if (nearest)
1247                                 break;
1248                         }
1249                                         }
1250                                 }
1251                         }
1252                         break;
1253                 }
1254                 case Xplus:
1255                 {
1256                         for (iy = 0; iy < nby; iy++)
1257                         {
1258                                 for (iz = 0; iz < nbz; iz++)
1259                                 {
1260                                         for (ix = nbx - 1; ix >= 0; ix--)
1261                                         {
1262                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1263                             continue;
1264                             value = voxels->Get(ix, iy, iz);
1265                             if (value >= minvalue && value <= maxvalue)
1266                             {
1267                             if (!check_size)
1268                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1269                             setColor(colors.Value(value), Standard_False);
1270                                     glVertex3d(xc, yc, zc);
1271                             if (nearest)
1272                                 break;
1273                         }
1274                                         }
1275                                 }
1276                         }
1277                         break;
1278                 }
1279                 case Yminus:
1280                 {
1281                         for (ix = 0; ix < nbx; ix++)
1282                         {
1283                                 for (iz = 0; iz < nbz; iz++)
1284                                 {
1285                                         for (iy = 0; iy < nby; iy++)
1286                                         {
1287                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1288                             continue;
1289                             value = voxels->Get(ix, iy, iz);
1290                             if (value >= minvalue && value <= maxvalue)
1291                             {
1292                             if (!check_size)
1293                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1294                             setColor(colors.Value(value), Standard_False);
1295                                     glVertex3d(xc, yc, zc);
1296                             if (nearest)
1297                                 break;
1298                         }
1299                                         }
1300                                 }
1301                         }
1302                         break;
1303                 }
1304                 case Yplus:
1305                 {
1306                         for (ix = 0; ix < nbx; ix++)
1307                         {
1308                                 for (iz = 0; iz < nbz; iz++)
1309                                 {
1310                                         for (iy = nby - 1; iy >= 0; iy--)
1311                                         {
1312                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1313                             continue;
1314                             value = voxels->Get(ix, iy, iz);
1315                             if (value >= minvalue && value <= maxvalue)
1316                             {
1317                             if (!check_size)
1318                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1319                             setColor(colors.Value(value), Standard_False);
1320                                     glVertex3d(xc, yc, zc);
1321                             if (nearest)
1322                                 break;
1323                         }
1324                                         }
1325                                 }
1326                         }
1327                         break;
1328                 }
1329                 case Zminus:
1330                 {
1331                         for (ix = 0; ix < nbx; ix++)
1332                         {
1333                                 for (iy = 0; iy < nby; iy++)
1334                                 {
1335                                         for (iz = 0; iz < nbz; iz++)
1336                                         {
1337                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1338                             continue;
1339                             value = voxels->Get(ix, iy, iz);
1340                             if (value >= minvalue && value <= maxvalue)
1341                             {
1342                             if (!check_size)
1343                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1344                             setColor(colors.Value(value), Standard_False);
1345                                     glVertex3d(xc, yc, zc);
1346                             if (nearest)
1347                                 break;
1348                         }
1349                                         }
1350                                 }
1351                         }
1352                         break;
1353                 }
1354                 case Zplus:
1355                 {
1356                         for (ix = 0; ix < nbx; ix++)
1357                         {
1358                                 for (iy = 0; iy < nby; iy++)
1359                                 {
1360                                         for (iz = nbz - 1; iz >= 0; iz--)
1361                                         {
1362                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1363                             continue;
1364                             value = voxels->Get(ix, iy, iz);
1365                             if (value >= minvalue && value <= maxvalue)
1366                             {
1367                             if (!check_size)
1368                                         voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1369                             setColor(colors.Value(value), Standard_False);
1370                                     glVertex3d(xc, yc, zc);
1371                             if (nearest)
1372                                 break;
1373                         }
1374                                         }
1375                                 }
1376                         }
1377                         break;
1378                 }
1379     }
1380     glEnd();
1381 }
1382
1383 static void drawBoolQuadrangles(Voxel_BoolDS* voxels, const VoxelDirection vdir, 
1384                                 const gp_Dir& viewnormal, const Standard_Boolean nearest,
1385                                 const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
1386                                 const Standard_Real xmin, const Standard_Real xmax,
1387                                 const Standard_Real ymin, const Standard_Real ymax,
1388                                 const Standard_Real zmin, const Standard_Real zmax)
1389 {
1390     gp_Vec vc;
1391     gp_Pnt pc1, pc2, pc3, pc4;
1392     Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 1.0;
1393     Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ();
1394
1395     // Normal
1396     viewnormal.Coord(xn, yn, zn);
1397
1398     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
1399                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
1400                        zmin <= DBL_MAX && zmax >= DBL_MAX);
1401     check_size = !check_size;
1402
1403     glBegin(GL_QUADS);
1404     switch (vdir)
1405         {
1406                 case Xminus:
1407                 {
1408                         for (iy = 0; iy < nby; iy++)
1409                         {
1410                                 for (iz = 0; iz < nbz; iz++)
1411                                 {
1412                                         for (ix = 0; ix < nbx; ix++)
1413                                         {
1414                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1415                             continue;
1416                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1417                         if (value)
1418                         {
1419                             // Define translation vector
1420                             if (!check_size)
1421                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1422                             vc.SetCoord(xc, yc, zc);
1423
1424                             // Translate
1425                             pc1 = p1.Translated(vc);
1426                             pc2 = p2.Translated(vc);
1427                             pc3 = p3.Translated(vc);
1428                             pc4 = p4.Translated(vc);
1429
1430                             // Display
1431                             glNormal3d(xn, yn, zn);
1432                             pc1.Coord(xc, yc, zc);
1433                             glVertex3d(xc, yc, zc);
1434                             pc2.Coord(xc, yc, zc);
1435                             glVertex3d(xc, yc, zc);
1436                             pc3.Coord(xc, yc, zc);
1437                             glVertex3d(xc, yc, zc);
1438                             pc4.Coord(xc, yc, zc);
1439                             glVertex3d(xc, yc, zc);
1440
1441                             if (nearest)
1442                                 break;
1443                         }
1444                     }
1445                                 }
1446                         }
1447                         break;
1448                 }
1449                 case Xplus:
1450                 {
1451                         for (iy = 0; iy < nby; iy++)
1452                         {
1453                                 for (iz = 0; iz < nbz; iz++)
1454                                 {
1455                                         for (ix = nbx - 1; ix >= 0; ix--)
1456                                         {
1457                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1458                             continue;
1459                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1460                         if (value)
1461                         {
1462                             // Define translation vector
1463                             if (!check_size)
1464                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1465                             vc.SetCoord(xc, yc, zc);
1466
1467                             // Translate
1468                             pc1 = p1.Translated(vc);
1469                             pc2 = p2.Translated(vc);
1470                             pc3 = p3.Translated(vc);
1471                             pc4 = p4.Translated(vc);
1472
1473                             // Display
1474                             glNormal3d(xn, yn, zn);
1475                             pc1.Coord(xc, yc, zc);
1476                             glVertex3d(xc, yc, zc);
1477                             pc2.Coord(xc, yc, zc);
1478                             glVertex3d(xc, yc, zc);
1479                             pc3.Coord(xc, yc, zc);
1480                             glVertex3d(xc, yc, zc);
1481                             pc4.Coord(xc, yc, zc);
1482                             glVertex3d(xc, yc, zc);
1483
1484                             if (nearest)
1485                                 break;
1486                         }
1487                                         }
1488                                 }
1489                         }
1490                         break;
1491                 }
1492                 case Yminus:
1493                 {
1494                         for (ix = 0; ix < nbx; ix++)
1495                         {
1496                                 for (iz = 0; iz < nbz; iz++)
1497                                 {
1498                                         for (iy = 0; iy < nby; iy++)
1499                                         {
1500                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1501                             continue;
1502                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1503                         if (value)
1504                         {
1505                             // Define translation vector
1506                             if (!check_size)
1507                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1508                             vc.SetCoord(xc, yc, zc);
1509
1510                             // Translate
1511                             pc1 = p1.Translated(vc);
1512                             pc2 = p2.Translated(vc);
1513                             pc3 = p3.Translated(vc);
1514                             pc4 = p4.Translated(vc);
1515
1516                             // Display
1517                             glNormal3d(xn, yn, zn);
1518                             pc1.Coord(xc, yc, zc);
1519                             glVertex3d(xc, yc, zc);
1520                             pc2.Coord(xc, yc, zc);
1521                             glVertex3d(xc, yc, zc);
1522                             pc3.Coord(xc, yc, zc);
1523                             glVertex3d(xc, yc, zc);
1524                             pc4.Coord(xc, yc, zc);
1525                             glVertex3d(xc, yc, zc);
1526
1527                             if (nearest)
1528                                 break;
1529                         }
1530                                         }
1531                                 }
1532                         }
1533                         break;
1534                 }
1535                 case Yplus:
1536                 {
1537                         for (ix = 0; ix < nbx; ix++)
1538                         {
1539                                 for (iz = 0; iz < nbz; iz++)
1540                                 {
1541                                         for (iy = nby - 1; iy >= 0; iy--)
1542                                         {
1543                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1544                             continue;
1545                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1546                         if (value)
1547                         {
1548                             // Define translation vector
1549                             if (!check_size)
1550                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1551                             vc.SetCoord(xc, yc, zc);
1552
1553                             // Translate
1554                             pc1 = p1.Translated(vc);
1555                             pc2 = p2.Translated(vc);
1556                             pc3 = p3.Translated(vc);
1557                             pc4 = p4.Translated(vc);
1558
1559                             // Display
1560                             glNormal3d(xn, yn, zn);
1561                             pc1.Coord(xc, yc, zc);
1562                             glVertex3d(xc, yc, zc);
1563                             pc2.Coord(xc, yc, zc);
1564                             glVertex3d(xc, yc, zc);
1565                             pc3.Coord(xc, yc, zc);
1566                             glVertex3d(xc, yc, zc);
1567                             pc4.Coord(xc, yc, zc);
1568                             glVertex3d(xc, yc, zc);
1569
1570                             if (nearest)
1571                                 break;
1572                         }
1573                                         }
1574                                 }
1575                         }
1576                         break;
1577                 }
1578                 case Zminus:
1579                 {
1580                         for (ix = 0; ix < nbx; ix++)
1581                         {
1582                                 for (iy = 0; iy < nby; iy++)
1583                                 {
1584                                         for (iz = 0; iz < nbz; iz++)
1585                                         {
1586                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1587                             continue;
1588                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1589                         if (value)
1590                         {
1591                             // Define translation vector
1592                             if (!check_size)
1593                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1594                             vc.SetCoord(xc, yc, zc);
1595
1596                             // Translate
1597                             pc1 = p1.Translated(vc);
1598                             pc2 = p2.Translated(vc);
1599                             pc3 = p3.Translated(vc);
1600                             pc4 = p4.Translated(vc);
1601
1602                             // Display
1603                             glNormal3d(xn, yn, zn);
1604                             pc1.Coord(xc, yc, zc);
1605                             glVertex3d(xc, yc, zc);
1606                             pc2.Coord(xc, yc, zc);
1607                             glVertex3d(xc, yc, zc);
1608                             pc3.Coord(xc, yc, zc);
1609                             glVertex3d(xc, yc, zc);
1610                             pc4.Coord(xc, yc, zc);
1611                             glVertex3d(xc, yc, zc);
1612
1613                             if (nearest)
1614                                 break;
1615                         }
1616                                         }
1617                                 }
1618                         }
1619                         break;
1620                 }
1621                 case Zplus:
1622                 {
1623                         for (ix = 0; ix < nbx; ix++)
1624                         {
1625                                 for (iy = 0; iy < nby; iy++)
1626                                 {
1627                                         for (iz = nbz - 1; iz >= 0; iz--)
1628                                         {
1629                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1630                             continue;
1631                         Standard_Boolean value = voxels->Get(ix, iy, iz) == Standard_True;
1632                         if (value)
1633                         {
1634                             // Define translation vector
1635                             if (!check_size)
1636                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
1637                             vc.SetCoord(xc, yc, zc);
1638
1639                             // Translate
1640                             pc1 = p1.Translated(vc);
1641                             pc2 = p2.Translated(vc);
1642                             pc3 = p3.Translated(vc);
1643                             pc4 = p4.Translated(vc);
1644
1645                             // Display
1646                             glNormal3d(xn, yn, zn);
1647                             pc1.Coord(xc, yc, zc);
1648                             glVertex3d(xc, yc, zc);
1649                             pc2.Coord(xc, yc, zc);
1650                             glVertex3d(xc, yc, zc);
1651                             pc3.Coord(xc, yc, zc);
1652                             glVertex3d(xc, yc, zc);
1653                             pc4.Coord(xc, yc, zc);
1654                             glVertex3d(xc, yc, zc);
1655
1656                             if (nearest)
1657                                 break;
1658                         }
1659                                         }
1660                                 }
1661                         }
1662                         break;
1663                 }
1664     }
1665     glEnd();
1666 }
1667
1668 static void drawROctBoolQuadrangles(Voxel_ROctBoolDS* voxels, const VoxelDirection vdir, 
1669                                     const gp_Dir& viewnormal, const Standard_Boolean nearest,
1670                                     const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
1671                                     const Standard_Real xmin, const Standard_Real xmax,
1672                                     const Standard_Real ymin, const Standard_Real ymax,
1673                                     const Standard_Real zmin, const Standard_Real zmax)
1674 {
1675     gp_Vec vc;
1676     gp_Pnt pc1, pc2, pc3, pc4;
1677     Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 1.0;
1678     Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ(), i, j, deepness;
1679
1680     // Normal
1681     viewnormal.Coord(xn, yn, zn);
1682
1683     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
1684                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
1685                        zmin <= DBL_MAX && zmax >= DBL_MAX);
1686     check_size = !check_size;
1687
1688     glBegin(GL_QUADS);
1689     switch (vdir)
1690         {
1691                 case Xminus:
1692                 {
1693                         for (iy = 0; iy < nby; iy++)
1694                         {
1695                                 for (iz = 0; iz < nbz; iz++)
1696                                 {
1697                                         for (ix = 0; ix < nbx; ix++)
1698                                         {
1699                         deepness = voxels->Deepness(ix, iy, iz);
1700                         for (i = 0; i < 8; i++)
1701                         {
1702                             for (j = 0; j < 8; j++)
1703                             {
1704                                 if (deepness == 0 && j)
1705                                 {
1706                                     i = 8;
1707                                     break;
1708                                 }
1709                                 if (deepness == 1 && j)
1710                                     break;
1711                                 if (deepness == 0)
1712                                 {
1713                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1714                                         continue;
1715                                 }
1716                                 else if (deepness == 1)
1717                                 {
1718                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1719                                         continue;
1720                                 }
1721                                 else if (deepness == 2)
1722                                 {
1723                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1724                                         continue;
1725                                 }
1726
1727                                 Standard_Boolean value;
1728                                 switch (deepness)
1729                                 {
1730                                     case 0:
1731                                         value = voxels->Get(ix, iy, iz) == Standard_True;
1732                                         break;
1733                                     case 1:
1734                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
1735                                         break;
1736                                     case 2:
1737                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1738                                         break;
1739                                 }
1740                                 
1741                                 if (value)
1742                                 {
1743                                     // Define translation vector
1744                                     if (!check_size)
1745                                     {
1746                                         switch (deepness)
1747                                         {
1748                                             case 0:
1749                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1750                                                 break;
1751                                             case 1:
1752                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1753                                                 break;
1754                                             case 2:
1755                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1756                                                 break;
1757                                         }
1758                                     }
1759                                     vc.SetCoord(xc, yc, zc);
1760
1761                                     // Translate
1762                                     pc1 = p1.Translated(vc);
1763                                     pc2 = p2.Translated(vc);
1764                                     pc3 = p3.Translated(vc);
1765                                     pc4 = p4.Translated(vc);
1766
1767                                     // Display
1768                                     glNormal3d(xn, yn, zn);
1769                                     pc1.Coord(xc, yc, zc);
1770                                     glVertex3d(xc, yc, zc);
1771                                     pc2.Coord(xc, yc, zc);
1772                                     glVertex3d(xc, yc, zc);
1773                                     pc3.Coord(xc, yc, zc);
1774                                     glVertex3d(xc, yc, zc);
1775                                     pc4.Coord(xc, yc, zc);
1776                                     glVertex3d(xc, yc, zc);
1777
1778                                     if (nearest)
1779                                         break;
1780                                 }
1781                             }
1782                         }
1783                     }
1784                                 }
1785                         }
1786                         break;
1787                 }
1788                 case Xplus:
1789                 {
1790                         for (iy = 0; iy < nby; iy++)
1791                         {
1792                                 for (iz = 0; iz < nbz; iz++)
1793                                 {
1794                                         for (ix = nbx - 1; ix >= 0; ix--)
1795                                         {
1796                         deepness = voxels->Deepness(ix, iy, iz);
1797                         for (i = 0; i < 8; i++)
1798                         {
1799                             for (j = 0; j < 8; j++)
1800                             {
1801                                 if (deepness == 0 && j)
1802                                 {
1803                                     i = 8;
1804                                     break;
1805                                 }
1806                                 if (deepness == 1 && j)
1807                                     break;
1808                                 if (deepness == 0)
1809                                 {
1810                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1811                                         continue;
1812                                 }
1813                                 else if (deepness == 1)
1814                                 {
1815                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1816                                         continue;
1817                                 }
1818                                 else if (deepness == 2)
1819                                 {
1820                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1821                                         continue;
1822                                 }
1823
1824                                 Standard_Boolean value;
1825                                 switch (deepness)
1826                                 {
1827                                     case 0:
1828                                         value = voxels->Get(ix, iy, iz) == Standard_True;
1829                                         break;
1830                                     case 1:
1831                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
1832                                         break;
1833                                     case 2:
1834                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1835                                         break;
1836                                 }
1837                                 
1838                                 if (value)
1839                                 {
1840                                     // Define translation vector
1841                                     if (!check_size)
1842                                     {
1843                                         switch (deepness)
1844                                         {
1845                                             case 0:
1846                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1847                                                 break;
1848                                             case 1:
1849                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1850                                                 break;
1851                                             case 2:
1852                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1853                                                 break;
1854                                         }
1855                                     }
1856                                     vc.SetCoord(xc, yc, zc);
1857
1858                                     // Translate
1859                                     pc1 = p1.Translated(vc);
1860                                     pc2 = p2.Translated(vc);
1861                                     pc3 = p3.Translated(vc);
1862                                     pc4 = p4.Translated(vc);
1863
1864                                     // Display
1865                                     glNormal3d(xn, yn, zn);
1866                                     pc1.Coord(xc, yc, zc);
1867                                     glVertex3d(xc, yc, zc);
1868                                     pc2.Coord(xc, yc, zc);
1869                                     glVertex3d(xc, yc, zc);
1870                                     pc3.Coord(xc, yc, zc);
1871                                     glVertex3d(xc, yc, zc);
1872                                     pc4.Coord(xc, yc, zc);
1873                                     glVertex3d(xc, yc, zc);
1874
1875                                     if (nearest)
1876                                         break;
1877                                 }
1878                             }
1879                         }
1880                                         }
1881                                 }
1882                         }
1883                         break;
1884                 }
1885                 case Yminus:
1886                 {
1887                         for (ix = 0; ix < nbx; ix++)
1888                         {
1889                                 for (iz = 0; iz < nbz; iz++)
1890                                 {
1891                                         for (iy = 0; iy < nby; iy++)
1892                                         {
1893                         deepness = voxels->Deepness(ix, iy, iz);
1894                         for (i = 0; i < 8; i++)
1895                         {
1896                             for (j = 0; j < 8; j++)
1897                             {
1898                                 if (deepness == 0 && j)
1899                                 {
1900                                     i = 8;
1901                                     break;
1902                                 }
1903                                 if (deepness == 1 && j)
1904                                     break;
1905                                 if (deepness == 0)
1906                                 {
1907                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1908                                         continue;
1909                                 }
1910                                 else if (deepness == 1)
1911                                 {
1912                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1913                                         continue;
1914                                 }
1915                                 else if (deepness == 2)
1916                                 {
1917                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
1918                                         continue;
1919                                 }
1920
1921                                 Standard_Boolean value;
1922                                 switch (deepness)
1923                                 {
1924                                     case 0:
1925                                         value = voxels->Get(ix, iy, iz) == Standard_True;
1926                                         break;
1927                                     case 1:
1928                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
1929                                         break;
1930                                     case 2:
1931                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
1932                                         break;
1933                                 }
1934                                 
1935                                 if (value)
1936                                 {
1937                                     // Define translation vector
1938                                     if (!check_size)
1939                                     {
1940                                         switch (deepness)
1941                                         {
1942                                             case 0:
1943                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
1944                                                 break;
1945                                             case 1:
1946                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
1947                                                 break;
1948                                             case 2:
1949                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
1950                                                 break;
1951                                         }
1952                                     }
1953                                     vc.SetCoord(xc, yc, zc);
1954
1955                                     // Translate
1956                                     pc1 = p1.Translated(vc);
1957                                     pc2 = p2.Translated(vc);
1958                                     pc3 = p3.Translated(vc);
1959                                     pc4 = p4.Translated(vc);
1960
1961                                     // Display
1962                                     glNormal3d(xn, yn, zn);
1963                                     pc1.Coord(xc, yc, zc);
1964                                     glVertex3d(xc, yc, zc);
1965                                     pc2.Coord(xc, yc, zc);
1966                                     glVertex3d(xc, yc, zc);
1967                                     pc3.Coord(xc, yc, zc);
1968                                     glVertex3d(xc, yc, zc);
1969                                     pc4.Coord(xc, yc, zc);
1970                                     glVertex3d(xc, yc, zc);
1971
1972                                     if (nearest)
1973                                         break;
1974                                 }
1975                             }
1976                         }
1977                                         }
1978                                 }
1979                         }
1980                         break;
1981                 }
1982                 case Yplus:
1983                 {
1984                         for (ix = 0; ix < nbx; ix++)
1985                         {
1986                                 for (iz = 0; iz < nbz; iz++)
1987                                 {
1988                                         for (iy = nby - 1; iy >= 0; iy--)
1989                                         {
1990                         deepness = voxels->Deepness(ix, iy, iz);
1991                         for (i = 0; i < 8; i++)
1992                         {
1993                             for (j = 0; j < 8; j++)
1994                             {
1995                                 if (deepness == 0 && j)
1996                                 {
1997                                     i = 8;
1998                                     break;
1999                                 }
2000                                 if (deepness == 1 && j)
2001                                     break;
2002                                 if (deepness == 0)
2003                                 {
2004                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2005                                         continue;
2006                                 }
2007                                 else if (deepness == 1)
2008                                 {
2009                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2010                                         continue;
2011                                 }
2012                                 else if (deepness == 2)
2013                                 {
2014                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2015                                         continue;
2016                                 }
2017
2018                                 Standard_Boolean value;
2019                                 switch (deepness)
2020                                 {
2021                                     case 0:
2022                                         value = voxels->Get(ix, iy, iz) == Standard_True;
2023                                         break;
2024                                     case 1:
2025                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
2026                                         break;
2027                                     case 2:
2028                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
2029                                         break;
2030                                 }
2031                                 
2032                                 if (value)
2033                                 {
2034                                     // Define translation vector
2035                                     if (!check_size)
2036                                     {
2037                                         switch (deepness)
2038                                         {
2039                                             case 0:
2040                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
2041                                                 break;
2042                                             case 1:
2043                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
2044                                                 break;
2045                                             case 2:
2046                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
2047                                                 break;
2048                                         }
2049                                     }
2050                                     vc.SetCoord(xc, yc, zc);
2051
2052                                     // Translate
2053                                     pc1 = p1.Translated(vc);
2054                                     pc2 = p2.Translated(vc);
2055                                     pc3 = p3.Translated(vc);
2056                                     pc4 = p4.Translated(vc);
2057
2058                                     // Display
2059                                     glNormal3d(xn, yn, zn);
2060                                     pc1.Coord(xc, yc, zc);
2061                                     glVertex3d(xc, yc, zc);
2062                                     pc2.Coord(xc, yc, zc);
2063                                     glVertex3d(xc, yc, zc);
2064                                     pc3.Coord(xc, yc, zc);
2065                                     glVertex3d(xc, yc, zc);
2066                                     pc4.Coord(xc, yc, zc);
2067                                     glVertex3d(xc, yc, zc);
2068
2069                                     if (nearest)
2070                                         break;
2071                                 }
2072                             }
2073                         }
2074                                         }
2075                                 }
2076                         }
2077                         break;
2078                 }
2079                 case Zminus:
2080                 {
2081                         for (ix = 0; ix < nbx; ix++)
2082                         {
2083                                 for (iy = 0; iy < nby; iy++)
2084                                 {
2085                                         for (iz = 0; iz < nbz; iz++)
2086                                         {
2087                         deepness = voxels->Deepness(ix, iy, iz);
2088                         for (i = 0; i < 8; i++)
2089                         {
2090                             for (j = 0; j < 8; j++)
2091                             {
2092                                 if (deepness == 0 && j)
2093                                 {
2094                                     i = 8;
2095                                     break;
2096                                 }
2097                                 if (deepness == 1 && j)
2098                                     break;
2099                                 if (deepness == 0)
2100                                 {
2101                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2102                                         continue;
2103                                 }
2104                                 else if (deepness == 1)
2105                                 {
2106                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2107                                         continue;
2108                                 }
2109                                 else if (deepness == 2)
2110                                 {
2111                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2112                                         continue;
2113                                 }
2114
2115                                 Standard_Boolean value;
2116                                 switch (deepness)
2117                                 {
2118                                     case 0:
2119                                         value = voxels->Get(ix, iy, iz) == Standard_True;
2120                                         break;
2121                                     case 1:
2122                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
2123                                         break;
2124                                     case 2:
2125                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
2126                                         break;
2127                                 }
2128                                 
2129                                 if (value)
2130                                 {
2131                                     // Define translation vector
2132                                     if (!check_size)
2133                                     {
2134                                         switch (deepness)
2135                                         {
2136                                             case 0:
2137                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
2138                                                 break;
2139                                             case 1:
2140                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
2141                                                 break;
2142                                             case 2:
2143                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
2144                                                 break;
2145                                         }
2146                                     }
2147                                     vc.SetCoord(xc, yc, zc);
2148
2149                                     // Translate
2150                                     pc1 = p1.Translated(vc);
2151                                     pc2 = p2.Translated(vc);
2152                                     pc3 = p3.Translated(vc);
2153                                     pc4 = p4.Translated(vc);
2154
2155                                     // Display
2156                                     glNormal3d(xn, yn, zn);
2157                                     pc1.Coord(xc, yc, zc);
2158                                     glVertex3d(xc, yc, zc);
2159                                     pc2.Coord(xc, yc, zc);
2160                                     glVertex3d(xc, yc, zc);
2161                                     pc3.Coord(xc, yc, zc);
2162                                     glVertex3d(xc, yc, zc);
2163                                     pc4.Coord(xc, yc, zc);
2164                                     glVertex3d(xc, yc, zc);
2165
2166                                     if (nearest)
2167                                         break;
2168                                 }
2169                             }
2170                         }
2171                                         }
2172                                 }
2173                         }
2174                         break;
2175                 }
2176                 case Zplus:
2177                 {
2178                         for (ix = 0; ix < nbx; ix++)
2179                         {
2180                                 for (iy = 0; iy < nby; iy++)
2181                                 {
2182                                         for (iz = nbz - 1; iz >= 0; iz--)
2183                                         {
2184                         deepness = voxels->Deepness(ix, iy, iz);
2185                         for (i = 0; i < 8; i++)
2186                         {
2187                             for (j = 0; j < 8; j++)
2188                             {
2189                                 if (deepness == 0 && j)
2190                                 {
2191                                     i = 8;
2192                                     break;
2193                                 }
2194                                 if (deepness == 1 && j)
2195                                     break;
2196                                 if (deepness == 0)
2197                                 {
2198                                     if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2199                                         continue;
2200                                 }
2201                                 else if (deepness == 1)
2202                                 {
2203                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, -1, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2204                                         continue;
2205                                 }
2206                                 else if (deepness == 2)
2207                                 {
2208                                     if (check_size && !CheckSize(voxels, ix, iy, iz, i, j, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2209                                         continue;
2210                                 }
2211
2212                                 Standard_Boolean value;
2213                                 switch (deepness)
2214                                 {
2215                                     case 0:
2216                                         value = voxels->Get(ix, iy, iz) == Standard_True;
2217                                         break;
2218                                     case 1:
2219                                         value = voxels->Get(ix, iy, iz, i) == Standard_True;
2220                                         break;
2221                                     case 2:
2222                                         value = voxels->Get(ix, iy, iz, i, j) == Standard_True;
2223                                         break;
2224                                 }
2225                                 
2226                                 if (value)
2227                                 {
2228                                     // Define translation vector
2229                                     if (!check_size)
2230                                     {
2231                                         switch (deepness)
2232                                         {
2233                                             case 0:
2234                                                 ((Voxel_DS*)voxels)->GetCenter(ix, iy, iz, xc, yc, zc);
2235                                                 break;
2236                                             case 1:
2237                                                 voxels->GetCenter(ix, iy, iz, i, xc, yc, zc);
2238                                                 break;
2239                                             case 2:
2240                                                 voxels->GetCenter(ix, iy, iz, i, j, xc, yc, zc);
2241                                                 break;
2242                                         }
2243                                     }
2244                                     vc.SetCoord(xc, yc, zc);
2245
2246                                     // Translate
2247                                     pc1 = p1.Translated(vc);
2248                                     pc2 = p2.Translated(vc);
2249                                     pc3 = p3.Translated(vc);
2250                                     pc4 = p4.Translated(vc);
2251
2252                                     // Display
2253                                     glNormal3d(xn, yn, zn);
2254                                     pc1.Coord(xc, yc, zc);
2255                                     glVertex3d(xc, yc, zc);
2256                                     pc2.Coord(xc, yc, zc);
2257                                     glVertex3d(xc, yc, zc);
2258                                     pc3.Coord(xc, yc, zc);
2259                                     glVertex3d(xc, yc, zc);
2260                                     pc4.Coord(xc, yc, zc);
2261                                     glVertex3d(xc, yc, zc);
2262
2263                                     if (nearest)
2264                                         break;
2265                                 }
2266                             }
2267                         }
2268                                         }
2269                                 }
2270                         }
2271                         break;
2272                 }
2273     }
2274     glEnd();
2275 }
2276
2277
2278
2279 static void drawColorQuadrangles(Voxel_ColorDS* voxels, const VoxelDirection vdir, 
2280                                  const gp_Dir& viewnormal, const Standard_Boolean nearest,
2281                                  const Handle(Quantity_HArray1OfColor)& hcolors,
2282                                  const gp_Pnt& p1, const gp_Pnt& p2, const gp_Pnt& p3, const gp_Pnt& p4,
2283                                  const Standard_Byte minvalue, const Standard_Byte maxvalue,
2284                                  const Standard_Real xmin, const Standard_Real xmax,
2285                                  const Standard_Real ymin, const Standard_Real ymax,
2286                                  const Standard_Real zmin, const Standard_Real zmax)
2287 {
2288     gp_Vec vc;
2289     gp_Pnt pc1, pc2, pc3, pc4;
2290     Standard_Real xc, yc, zc, xn = 0.0, yn = 0.0, zn = 0.0;
2291     Standard_Integer ix, iy, iz, nbx = voxels->GetNbX(), nby = voxels->GetNbY(), nbz = voxels->GetNbZ();
2292     Standard_Byte value;
2293
2294     // Normal
2295     //viewnormal.Coord(xn, yn, zn);
2296     glNormal3d(xn, yn, zn);
2297
2298     // Colors
2299     const Quantity_Array1OfColor& colors = hcolors->Array1();
2300
2301     Standard_Boolean check_size = (xmin <= DBL_MAX && xmax >= DBL_MAX &&
2302                        ymin <= DBL_MAX && ymax >= DBL_MAX &&
2303                        zmin <= DBL_MAX && zmax >= DBL_MAX);
2304     check_size = !check_size;
2305
2306     glBegin(GL_QUADS);
2307     switch (vdir)
2308         {
2309                 case Xminus:
2310                 {
2311                         for (iy = 0; iy < nby; iy++)
2312                         {
2313                                 for (iz = 0; iz < nbz; iz++)
2314                                 {
2315                                         for (ix = 0; ix < nbx; ix++)
2316                                         {
2317                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2318                             continue;
2319                         value = voxels->Get(ix, iy, iz);
2320                         if (value >= minvalue && value <= maxvalue)
2321                         {
2322                             // Define translation vector
2323                             if (!check_size)
2324                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2325                             vc.SetCoord(xc, yc, zc);
2326
2327                             // Translate
2328                             pc1 = p1.Translated(vc);
2329                             pc2 = p2.Translated(vc);
2330                             pc3 = p3.Translated(vc);
2331                             pc4 = p4.Translated(vc);
2332
2333                             // Color
2334                             setColor(colors.Value(value), Standard_False);
2335
2336                             // Display
2337                             //glNormal3d(xn, yn, zn);
2338                             pc1.Coord(xc, yc, zc);
2339                             glVertex3d(xc, yc, zc);
2340                             pc2.Coord(xc, yc, zc);
2341                             glVertex3d(xc, yc, zc);
2342                             pc3.Coord(xc, yc, zc);
2343                             glVertex3d(xc, yc, zc);
2344                             pc4.Coord(xc, yc, zc);
2345                             glVertex3d(xc, yc, zc);
2346
2347                             if (nearest)
2348                                 break;
2349                         }
2350                     }
2351                                 }
2352                         }
2353                         break;
2354                 }
2355                 case Xplus:
2356                 {
2357                         for (iy = 0; iy < nby; iy++)
2358                         {
2359                                 for (iz = 0; iz < nbz; iz++)
2360                                 {
2361                                         for (ix = nbx - 1; ix >= 0; ix--)
2362                                         {
2363                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2364                             continue;
2365                         value = voxels->Get(ix, iy, iz);
2366                         if (value >= minvalue && value <= maxvalue)
2367                         {
2368                             // Define translation vector
2369                             if (!check_size)
2370                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2371                             vc.SetCoord(xc, yc, zc);
2372
2373                             // Translate
2374                             pc1 = p1.Translated(vc);
2375                             pc2 = p2.Translated(vc);
2376                             pc3 = p3.Translated(vc);
2377                             pc4 = p4.Translated(vc);
2378
2379                             // Color
2380                             setColor(colors.Value(value), Standard_False);
2381
2382                             // Display
2383                             //glNormal3d(xn, yn, zn);
2384                             pc1.Coord(xc, yc, zc);
2385                             glVertex3d(xc, yc, zc);
2386                             pc2.Coord(xc, yc, zc);
2387                             glVertex3d(xc, yc, zc);
2388                             pc3.Coord(xc, yc, zc);
2389                             glVertex3d(xc, yc, zc);
2390                             pc4.Coord(xc, yc, zc);
2391                             glVertex3d(xc, yc, zc);
2392
2393                             if (nearest)
2394                                 break;
2395                         }
2396                                         }
2397                                 }
2398                         }
2399                         break;
2400                 }
2401                 case Yminus:
2402                 {
2403                         for (ix = 0; ix < nbx; ix++)
2404                         {
2405                                 for (iz = 0; iz < nbz; iz++)
2406                                 {
2407                                         for (iy = 0; iy < nby; iy++)
2408                                         {
2409                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2410                             continue;
2411                         value = voxels->Get(ix, iy, iz);
2412                         if (value >= minvalue && value <= maxvalue)
2413                         {
2414                             // Define translation vector
2415                             if (!check_size)
2416                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2417                             vc.SetCoord(xc, yc, zc);
2418
2419                             // Translate
2420                             pc1 = p1.Translated(vc);
2421                             pc2 = p2.Translated(vc);
2422                             pc3 = p3.Translated(vc);
2423                             pc4 = p4.Translated(vc);
2424
2425                             // Color
2426                             setColor(colors.Value(value), Standard_False);
2427
2428                             // Display
2429                             //glNormal3d(xn, yn, zn);
2430                             pc1.Coord(xc, yc, zc);
2431                             glVertex3d(xc, yc, zc);
2432                             pc2.Coord(xc, yc, zc);
2433                             glVertex3d(xc, yc, zc);
2434                             pc3.Coord(xc, yc, zc);
2435                             glVertex3d(xc, yc, zc);
2436                             pc4.Coord(xc, yc, zc);
2437                             glVertex3d(xc, yc, zc);
2438
2439                             if (nearest)
2440                                 break;
2441                         }
2442                                         }
2443                                 }
2444                         }
2445                         break;
2446                 }
2447                 case Yplus:
2448                 {
2449                         for (ix = 0; ix < nbx; ix++)
2450                         {
2451                                 for (iz = 0; iz < nbz; iz++)
2452                                 {
2453                                         for (iy = nby - 1; iy >= 0; iy--)
2454                                         {
2455                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2456                             continue;
2457                         value = voxels->Get(ix, iy, iz);
2458                         if (value >= minvalue && value <= maxvalue)
2459                         {
2460                             // Define translation vector
2461                             if (!check_size)
2462                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2463                             vc.SetCoord(xc, yc, zc);
2464
2465                             // Translate
2466                             pc1 = p1.Translated(vc);
2467                             pc2 = p2.Translated(vc);
2468                             pc3 = p3.Translated(vc);
2469                             pc4 = p4.Translated(vc);
2470
2471                             // Color
2472                             setColor(colors.Value(value), Standard_False);
2473
2474                             // Display
2475                             //glNormal3d(xn, yn, zn);
2476                             pc1.Coord(xc, yc, zc);
2477                             glVertex3d(xc, yc, zc);
2478                             pc2.Coord(xc, yc, zc);
2479                             glVertex3d(xc, yc, zc);
2480                             pc3.Coord(xc, yc, zc);
2481                             glVertex3d(xc, yc, zc);
2482                             pc4.Coord(xc, yc, zc);
2483                             glVertex3d(xc, yc, zc);
2484
2485                             if (nearest)
2486                                 break;
2487                         }
2488                                         }
2489                                 }
2490                         }
2491                         break;
2492                 }
2493                 case Zminus:
2494                 {
2495                         for (ix = 0; ix < nbx; ix++)
2496                         {
2497                                 for (iy = 0; iy < nby; iy++)
2498                                 {
2499                                         for (iz = 0; iz < nbz; iz++)
2500                                         {
2501                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2502                             continue;
2503                         value = voxels->Get(ix, iy, iz);
2504                         if (value >= minvalue && value <= maxvalue)
2505                         {
2506                             // Define translation vector
2507                             if (!check_size)
2508                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2509                             vc.SetCoord(xc, yc, zc);
2510
2511                             // Translate
2512                             pc1 = p1.Translated(vc);
2513                             pc2 = p2.Translated(vc);
2514                             pc3 = p3.Translated(vc);
2515                             pc4 = p4.Translated(vc);
2516
2517                             // Color
2518                             setColor(colors.Value(value), Standard_False);
2519
2520                             // Display
2521                             //glNormal3d(xn, yn, zn);
2522                             pc1.Coord(xc, yc, zc);
2523                             glVertex3d(xc, yc, zc);
2524                             pc2.Coord(xc, yc, zc);
2525                             glVertex3d(xc, yc, zc);
2526                             pc3.Coord(xc, yc, zc);
2527                             glVertex3d(xc, yc, zc);
2528                             pc4.Coord(xc, yc, zc);
2529                             glVertex3d(xc, yc, zc);
2530
2531                             if (nearest)
2532                                 break;
2533                         }
2534                                         }
2535                                 }
2536                         }
2537                         break;
2538                 }
2539                 case Zplus:
2540                 {
2541                         for (ix = 0; ix < nbx; ix++)
2542                         {
2543                                 for (iy = 0; iy < nby; iy++)
2544                                 {
2545                                         for (iz = nbz - 1; iz >= 0; iz--)
2546                                         {
2547                         if (check_size && !CheckSize(voxels, ix, iy, iz, xmin, xmax, ymin, ymax, zmin, zmax, xc, yc, zc))
2548                             continue;
2549                         value = voxels->Get(ix, iy, iz);
2550                         if (value >= minvalue && value <= maxvalue)
2551                         {
2552                             // Define translation vector
2553                             if (!check_size)
2554                                 voxels->GetCenter(ix, iy, iz, xc, yc, zc);
2555                             vc.SetCoord(xc, yc, zc);
2556
2557                             // Translate
2558                             pc1 = p1.Translated(vc);
2559                             pc2 = p2.Translated(vc);
2560                             pc3 = p3.Translated(vc);
2561                             pc4 = p4.Translated(vc);
2562
2563                             // Color
2564                             setColor(colors.Value(value), Standard_False);
2565
2566                             // Display
2567                             //glNormal3d(xn, yn, zn);
2568                             pc1.Coord(xc, yc, zc);
2569                             glVertex3d(xc, yc, zc);
2570                             pc2.Coord(xc, yc, zc);
2571                             glVertex3d(xc, yc, zc);
2572                             pc3.Coord(xc, yc, zc);
2573                             glVertex3d(xc, yc, zc);
2574                             pc4.Coord(xc, yc, zc);
2575                             glVertex3d(xc, yc, zc);
2576
2577                             if (nearest)
2578                                 break;
2579                         }
2580                                         }
2581                                 }
2582                         }
2583                         break;
2584                 }
2585     }
2586     glEnd();
2587 }
2588
2589 static void genListIndex(GLint& index)
2590 {
2591     GLint i = 0;
2592     while (++i <= INT_MAX)
2593     {
2594         if (!glIsList(i))
2595         {
2596             index = i;
2597             break;
2598         }
2599     }
2600 }
2601
2602 static void setPlaneNormal(const VoxelDirection& dir, 
2603                            const Standard_Real dx, const Standard_Real dy, const Standard_Real dz,
2604                            gp_Pln& plane, gp_Pnt& p1, gp_Pnt& p2, gp_Pnt& p3, gp_Pnt& p4)
2605 {
2606     gp_Ax3 axes = plane.Position();
2607     Standard_Real dx2 = 0.5 * dx, dy2 = 0.5 * dy, dz2 = 0.5 * dz;
2608     switch (dir)
2609     {
2610         case Xminus:
2611             p1.SetCoord(-dx2, -dy2, dz2);
2612             p2.SetCoord(-dx2, -dy2, -dz2);
2613             p3.SetCoord(-dx2, dy2, -dz2);
2614             p4.SetCoord(-dx2, dy2, dz2);
2615             axes.SetDirection(-gp::DX());
2616             break;
2617         case Xplus:
2618             p1.SetCoord(dx2, -dy2, dz2);
2619             p2.SetCoord(dx2, -dy2, -dz2);
2620             p3.SetCoord(dx2, dy2, -dz2);
2621             p4.SetCoord(dx2, dy2, dz2);
2622             axes.SetDirection(gp::DX());
2623             break;
2624         case Yminus:
2625             p1.SetCoord(dx2, -dy2, dz2);
2626             p2.SetCoord(dx2, -dy2, -dz2);
2627             p3.SetCoord(-dx2, -dy2, -dz2);
2628             p4.SetCoord(-dx2, -dy2, dz2);
2629             axes.SetDirection(-gp::DY());
2630             break;
2631         case Yplus:
2632             p1.SetCoord(dx2, dy2, dz2);
2633             p2.SetCoord(dx2, dy2, -dz2);
2634             p3.SetCoord(-dx2, dy2, -dz2);
2635             p4.SetCoord(-dx2, dy2, dz2);
2636             axes.SetDirection(gp::DY());
2637             break;
2638         case Zminus:
2639             p1.SetCoord(dx2, dy2, -dz2);
2640             p2.SetCoord(-dx2, dy2, -dz2);
2641             p3.SetCoord(-dx2, -dy2, -dz2);
2642             p4.SetCoord(dx2, -dy2, -dz2);
2643             axes.SetDirection(-gp::DZ());
2644             break;
2645         case Zplus:
2646             p1.SetCoord(dx2, dy2, dz2);
2647             p2.SetCoord(-dx2, dy2, dz2);
2648             p3.SetCoord(-dx2, -dy2, dz2);
2649             p4.SetCoord(dx2, -dy2, dz2);
2650             axes.SetDirection(gp::DZ());
2651             break;
2652     }
2653 }
2654
2655 /**************************************************************************/
2656 void VoxelClient_VisDrawer::DisplayVoxels(const Standard_Boolean theHighlight)
2657 {
2658     if(!myData)
2659         return;
2660
2661     glEnable(GL_DEPTH_TEST);
2662
2663         // Boolean voxels
2664         if (myData->myBoolVoxels)
2665     {
2666                 // Points
2667                 if (myData->myDisplay.myDisplayMode == Voxel_VDM_POINTS ||
2668             myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS)
2669                 {
2670                         glDisable(GL_LIGHTING);
2671             if (myData->myDisplay.mySmoothPoints)
2672                             glEnable(GL_POINT_SMOOTH);
2673             else
2674                 glDisable(GL_POINT_SMOOTH);
2675
2676                         // Draw the points of voxels (center points of the voxels)
2677                         // starting visualization from the side looking out from the user.
2678                         setColor(myData->myDisplay.myColor, theHighlight);
2679                         glPointSize((Standard_ShortReal) myData->myDisplay.myPointSize);
2680
2681             // Display
2682             DisplayPoints(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS);
2683         }
2684         }
2685
2686     // Color values
2687         if (myData->myColorVoxels)
2688     {
2689                 // Points
2690                 if (myData->myDisplay.myDisplayMode == Voxel_VDM_POINTS ||
2691             myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS)
2692                 {
2693                         glDisable(GL_LIGHTING);
2694             if (myData->myDisplay.mySmoothPoints)
2695                             glEnable(GL_POINT_SMOOTH);
2696             else
2697                 glDisable(GL_POINT_SMOOTH);
2698
2699                         // Draw the points of voxels (center points of the voxels)
2700                         // starting visualization from the side looking out from the user.
2701                         glPointSize((Standard_ShortReal) myData->myDisplay.myPointSize);
2702
2703             // Display
2704             DisplayPoints(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS);
2705         }
2706         }
2707
2708         // Recursive Octree Boolean voxels
2709         if (myData->myROctBoolVoxels)
2710     {
2711                 // Points
2712                 if (myData->myDisplay.myDisplayMode == Voxel_VDM_POINTS ||
2713             myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS)
2714                 {
2715                         glDisable(GL_LIGHTING);
2716             if (myData->myDisplay.mySmoothPoints)
2717                             glEnable(GL_POINT_SMOOTH);
2718             else
2719                 glDisable(GL_POINT_SMOOTH);
2720
2721                         // Draw the points of voxels (center points of the voxels)
2722                         // starting visualization from the side looking out from the user.
2723                         setColor(myData->myDisplay.myColor, theHighlight);
2724                         glPointSize((Standard_ShortReal) myData->myDisplay.myPointSize);
2725
2726             // Display
2727             DisplayPoints(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTPOINTS);
2728         }
2729         }
2730
2731     // Shading drawn by boxes
2732     if (myData->myDisplay.myDisplayMode == Voxel_VDM_BOXES || 
2733         myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTBOXES)
2734     {
2735                 glEnable(GL_LIGHTING);
2736         glEnable(GL_COLOR_MATERIAL);
2737
2738                 // Draw quadrangles of voxels looking to the user.
2739                 setColor(myData->myDisplay.myColor, theHighlight);
2740
2741         // Display
2742         DisplayBoxes(myData->myDisplay.myDisplayMode == Voxel_VDM_NEARESTBOXES);
2743
2744         glDisable(GL_COLOR_MATERIAL);
2745     }
2746
2747     // Highlighted voxel
2748     HighlightVoxel();
2749 }
2750
2751 /**************************************************************************/
2752 void VoxelClient_VisDrawer::DisplayPoints(const Standard_Boolean nearest)
2753 {
2754     //OSD_Timer timer;
2755     //timer.Start();
2756
2757     // Find the side of the cube which normal looks to (or out) the user's eye.
2758         gp_Dir viewnormal;
2759         getNormal(viewnormal);
2760
2761     // Range of displayed data
2762     Standard_Real xmin = myData->myDisplay.myDisplayedXMin;
2763     Standard_Real xmax = myData->myDisplay.myDisplayedXMax;
2764     Standard_Real ymin = myData->myDisplay.myDisplayedYMin;
2765     Standard_Real ymax = myData->myDisplay.myDisplayedYMax;
2766     Standard_Real zmin = myData->myDisplay.myDisplayedZMin;
2767     Standard_Real zmax = myData->myDisplay.myDisplayedZMax;
2768
2769     // Boolean points
2770         if (myData->myBoolVoxels)
2771     {
2772         if (nearest || myData->myDisplay.myDegenerateMode)
2773         {
2774                 VoxelDirection vdir1, vdir2, vdir3;
2775             getVoxel3Directions(viewnormal, vdir1, vdir2, vdir3);
2776
2777             if (myData->myDisplay.myUsageOfGLlists)
2778             {
2779                 // Clean all allocated GL lists for the case of first call.
2780                 if (myData->myDisplay.myBoolNearestPointsFirst)
2781                 {
2782                     for (Standard_Integer idir = Xminus; idir <= Zplus; idir++)
2783                     {
2784                         if (myData->myDisplay.myBoolNearestPointsList[idir] > 0)
2785                         {
2786                             glDeleteLists(myData->myDisplay.myBoolNearestPointsList[idir], 1);
2787                             myData->myDisplay.myBoolNearestPointsList[idir] = -1;
2788                         }
2789                     }
2790                     myData->myDisplay.myBoolNearestPointsFirst = Standard_False;
2791                 }
2792
2793                 // Generate GL lists if needed.
2794                 if (myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1] < 0)
2795                 {
2796                     genListIndex(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1]);
2797                     glNewList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1], GL_COMPILE);
2798                     drawBoolPoints(vdir1, Standard_True, myData->myBoolVoxels,
2799                                    xmin, xmax, ymin, ymax, zmin, zmax);
2800                     glEndList();
2801                 }
2802                 if (myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2] < 0)
2803                 {
2804                     genListIndex(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2]);
2805                     glNewList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2], GL_COMPILE);
2806                     drawBoolPoints(vdir2, Standard_True, myData->myBoolVoxels,
2807                                    xmin, xmax, ymin, ymax, zmin, zmax);
2808                     glEndList();
2809                 }
2810                 if (myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3] < 0)
2811                 {
2812                     genListIndex(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3]);
2813                     glNewList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3], GL_COMPILE);
2814                     drawBoolPoints(vdir3, Standard_True, myData->myBoolVoxels,
2815                                    xmin, xmax, ymin, ymax, zmin, zmax);
2816                     glEndList();
2817                 }
2818                 glCallList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir1]);
2819                 glCallList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir2]);
2820                 glCallList(myData->myDisplay.myBoolNearestPointsList[(Standard_Integer) vdir3]);
2821             }
2822             else
2823             {
2824                 drawBoolPoints(vdir1, Standard_True, myData->myBoolVoxels,
2825                                xmin, xmax, ymin, ymax, zmin, zmax);
2826                 drawBoolPoints(vdir2, Standard_True, myData->myBoolVoxels,
2827                                xmin, xmax, ymin, ymax, zmin, zmax);
2828                 drawBoolPoints(vdir3, Standard_True, myData->myBoolVoxels,
2829                                xmin, xmax, ymin, ymax, zmin, zmax);
2830             }
2831         }
2832         else
2833         {
2834             if (myData->myDisplay.myUsageOfGLlists)
2835             {
2836                 if (myData->myDisplay.myBoolPointsFirst)
2837                 {
2838                     // Delete previous GL list.
2839                     if (myData->myDisplay.myBoolPointsList > 0)
2840                     {
2841                         glDeleteLists(myData->myDisplay.myBoolPointsList, 1);
2842                         myData->myDisplay.myBoolPointsList = -1;
2843                     }
2844
2845                     // Generate a new GL list
2846                     genListIndex(myData->myDisplay.myBoolPointsList);
2847                     glNewList(myData->myDisplay.myBoolPointsList, GL_COMPILE);
2848                     VoxelDirection vdir = getVoxelDirection(viewnormal);
2849                     drawBoolPoints(vdir, Standard_False, myData->myBoolVoxels,
2850                                    xmin, xmax, ymin, ymax, zmin, zmax);
2851                     glEndList();
2852
2853                     // The first call has just been passed...
2854                     myData->myDisplay.myBoolPointsFirst = Standard_False;
2855                 }
2856                 glCallList(myData->myDisplay.myBoolPointsList);
2857             }
2858             else
2859             {
2860                 VoxelDirection vdir = getVoxelDirection(viewnormal);
2861                 drawBoolPoints(vdir, Standard_False, myData->myBoolVoxels,
2862                                xmin, xmax, ymin, ymax, zmin, zmax);
2863             }
2864         }
2865         }
2866
2867     // Color points
2868         if (myData->myColorVoxels)
2869     {
2870         if (nearest || myData->myDisplay.myDegenerateMode)
2871         {
2872                 VoxelDirection vdir1, vdir2, vdir3;
2873             getVoxel3Directions(viewnormal, vdir1, vdir2, vdir3);
2874
2875             if (myData->myDisplay.myUsageOfGLlists)
2876             {
2877                 // Clean all allocated GL lists for the case of first call.
2878                 if (myData->myDisplay.myColorNearestPointsFirst)
2879                 {
2880                     for (Standard_Integer idir = Xminus; idir <= Zplus; idir++)
2881                     {
2882                         if (myData->myDisplay.myColorNearestPointsList[idir] > 0)
2883                         {
2884                             glDeleteLists(myData->myDisplay.myColorNearestPointsList[idir], 1);
2885                             myData->myDisplay.myColorNearestPointsList[idir] = -1;
2886                         }
2887                     }
2888                     myData->myDisplay.myColorNearestPointsFirst = Standard_False;
2889                 }
2890
2891                 // Generate GL lists if needed.
2892                 if (myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir1] < 0)
2893                 {
2894                     genListIndex(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir1]);
2895                     glNewList(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir1], GL_COMPILE);
2896                     drawColorPoints(vdir1, Standard_True, myData->myColorVoxels, myData->myDisplay.myColors,
2897                                     myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2898                                     xmin, xmax, ymin, ymax, zmin, zmax);
2899                     glEndList();
2900                 }
2901                 if (myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir2] < 0)
2902                 {
2903                     genListIndex(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir2]);
2904                     glNewList(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir2], GL_COMPILE);
2905                     drawColorPoints(vdir2, Standard_True, myData->myColorVoxels, myData->myDisplay.myColors,
2906                                     myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2907                                     xmin, xmax, ymin, ymax, zmin, zmax);
2908                     glEndList();
2909                 }
2910                 if (myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir3] < 0)
2911                 {
2912                     genListIndex(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir3]);
2913                     glNewList(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir3], GL_COMPILE);
2914                     drawColorPoints(vdir3, Standard_True, myData->myColorVoxels, myData->myDisplay.myColors,
2915                                     myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2916                                     xmin, xmax, ymin, ymax, zmin, zmax);
2917                     glEndList();
2918                 }
2919             
2920                 glCallList(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir1]);
2921                 glCallList(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir2]);
2922                 glCallList(myData->myDisplay.myColorNearestPointsList[(Standard_Integer) vdir3]);
2923             }
2924             else
2925             {
2926                 drawColorPoints(vdir1, Standard_True, myData->myColorVoxels, myData->myDisplay.myColors,
2927                                 myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2928                                 xmin, xmax, ymin, ymax, zmin, zmax);
2929                 drawColorPoints(vdir2, Standard_True, myData->myColorVoxels, myData->myDisplay.myColors,
2930                                 myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2931                                 xmin, xmax, ymin, ymax, zmin, zmax);
2932                 drawColorPoints(vdir3, Standard_True, myData->myColorVoxels, myData->myDisplay.myColors,
2933                                 myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2934                                 xmin, xmax, ymin, ymax, zmin, zmax);
2935             }
2936         }
2937         else
2938         {
2939             if (myData->myDisplay.myUsageOfGLlists)
2940             {
2941                 if (myData->myDisplay.myColorPointsFirst)
2942                 {
2943                     // Delete previous GL list.
2944                     if (myData->myDisplay.myColorPointsList > 0)
2945                     {
2946                         glDeleteLists(myData->myDisplay.myColorPointsList, 1);
2947                         myData->myDisplay.myColorPointsList = -1;
2948                     }
2949
2950                     // Generate a new GL list
2951                     genListIndex(myData->myDisplay.myColorPointsList);
2952                     glNewList(myData->myDisplay.myColorPointsList, GL_COMPILE);
2953                     VoxelDirection vdir = getVoxelDirection(viewnormal);
2954                     drawColorPoints(vdir, Standard_False, myData->myColorVoxels, myData->myDisplay.myColors,
2955                                     myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2956                                     xmin, xmax, ymin, ymax, zmin, zmax);
2957                     glEndList();
2958
2959                     // The first call has just been passed...
2960                     myData->myDisplay.myColorPointsFirst = Standard_False;
2961                 }
2962                 glCallList(myData->myDisplay.myColorPointsList);
2963             }
2964             else
2965             {
2966                 VoxelDirection vdir = getVoxelDirection(viewnormal);
2967                 drawColorPoints(vdir, Standard_False, myData->myColorVoxels, myData->myDisplay.myColors,
2968                                 myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
2969                                 xmin, xmax, ymin, ymax, zmin, zmax);
2970             }
2971         }
2972         }
2973
2974     // Recursive Octree Boolean points
2975         if (myData->myROctBoolVoxels)
2976     {
2977         if (nearest || myData->myDisplay.myDegenerateMode)
2978         {
2979                 VoxelDirection vdir1, vdir2, vdir3;
2980             getVoxel3Directions(viewnormal, vdir1, vdir2, vdir3);
2981
2982             if (myData->myDisplay.myUsageOfGLlists)
2983             {
2984                 // Clean all allocated GL lists for the case of first call.
2985                 if (myData->myDisplay.myROctBoolNearestPointsFirst)
2986                 {
2987                     for (Standard_Integer idir = Xminus; idir <= Zplus; idir++)
2988                     {
2989                         if (myData->myDisplay.myROctBoolNearestPointsList[idir] > 0)
2990                         {
2991                             glDeleteLists(myData->myDisplay.myROctBoolNearestPointsList[idir], 1);
2992                             myData->myDisplay.myROctBoolNearestPointsList[idir] = -1;
2993                         }
2994                     }
2995                     myData->myDisplay.myROctBoolNearestPointsFirst = Standard_False;
2996                 }
2997
2998                 // Generate GL lists if needed.
2999                 if (myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir1] < 0)
3000                 {
3001                     genListIndex(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir1]);
3002                     glNewList(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir1], GL_COMPILE);
3003                     drawROctBoolPoints(vdir1, Standard_True, myData->myROctBoolVoxels,
3004                                        xmin, xmax, ymin, ymax, zmin, zmax);
3005                     glEndList();
3006                 }
3007                 if (myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir2] < 0)
3008                 {
3009                     genListIndex(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir2]);
3010                     glNewList(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir2], GL_COMPILE);
3011                     drawROctBoolPoints(vdir2, Standard_True, myData->myROctBoolVoxels,
3012                                        xmin, xmax, ymin, ymax, zmin, zmax);
3013                     glEndList();
3014                 }
3015                 if (myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir3] < 0)
3016                 {
3017                     genListIndex(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir3]);
3018                     glNewList(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir3], GL_COMPILE);
3019                     drawROctBoolPoints(vdir3, Standard_True, myData->myROctBoolVoxels,
3020                                        xmin, xmax, ymin, ymax, zmin, zmax);
3021                     glEndList();
3022                 }
3023                 glCallList(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir1]);
3024                 glCallList(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir2]);
3025                 glCallList(myData->myDisplay.myROctBoolNearestPointsList[(Standard_Integer) vdir3]);
3026             }
3027             else
3028             {
3029                 drawROctBoolPoints(vdir1, Standard_True, myData->myROctBoolVoxels,
3030                                    xmin, xmax, ymin, ymax, zmin, zmax);
3031                 drawROctBoolPoints(vdir2, Standard_True, myData->myROctBoolVoxels,
3032                                    xmin, xmax, ymin, ymax, zmin, zmax);
3033                 drawROctBoolPoints(vdir3, Standard_True, myData->myROctBoolVoxels,
3034                                    xmin, xmax, ymin, ymax, zmin, zmax);
3035             }
3036         }
3037         else
3038         {
3039             if (myData->myDisplay.myUsageOfGLlists)
3040             {
3041                 if (myData->myDisplay.myROctBoolPointsFirst)
3042                 {
3043                     // Delete previous GL list.
3044                     if (myData->myDisplay.myROctBoolPointsList > 0)
3045                     {
3046                         glDeleteLists(myData->myDisplay.myROctBoolPointsList, 1);
3047                         myData->myDisplay.myROctBoolPointsList = -1;
3048                     }
3049
3050                     // Generate a new GL list
3051                     genListIndex(myData->myDisplay.myROctBoolPointsList);
3052                     glNewList(myData->myDisplay.myROctBoolPointsList, GL_COMPILE);
3053                     VoxelDirection vdir = getVoxelDirection(viewnormal);
3054                     drawROctBoolPoints(vdir, Standard_False, myData->myROctBoolVoxels,
3055                                        xmin, xmax, ymin, ymax, zmin, zmax);
3056                     glEndList();
3057
3058                     // The first call has just been passed...
3059                     myData->myDisplay.myROctBoolPointsFirst = Standard_False;
3060                 }
3061                 glCallList(myData->myDisplay.myROctBoolPointsList);
3062             }
3063             else
3064             {
3065                 VoxelDirection vdir = getVoxelDirection(viewnormal);
3066                 drawROctBoolPoints(vdir, Standard_False, myData->myROctBoolVoxels,
3067                                    xmin, xmax, ymin, ymax, zmin, zmax);
3068             }
3069         }
3070         }
3071
3072     //timer.Stop();
3073         //Standard_Real seconds, cpu;
3074         //Standard_Integer minutes, hours;
3075         //timer.Show(seconds, minutes, hours, cpu);
3076     //cout<<"DisplayPoints()"<<" took "<<minutes<<" minutes, "<<seconds<<" seconds"<<endl;
3077 }
3078
3079 /**************************************************************************/
3080 void VoxelClient_VisDrawer::DisplayBoxes(const Standard_Boolean nearest)
3081 {
3082     // Range of displayed data
3083     Standard_Real xmin = myData->myDisplay.myDisplayedXMin;
3084     Standard_Real xmax = myData->myDisplay.myDisplayedXMax;
3085     Standard_Real ymin = myData->myDisplay.myDisplayedYMin;
3086     Standard_Real ymax = myData->myDisplay.myDisplayedYMax;
3087     Standard_Real zmin = myData->myDisplay.myDisplayedZMin;
3088     Standard_Real zmax = myData->myDisplay.myDisplayedZMax;
3089
3090     // Find the side of the cube which normal looks to (or out) the user's eye.
3091         gp_Dir viewnormal;
3092         getNormal(viewnormal);
3093
3094     // Get three sides of the box looking to the user.
3095         VoxelDirection vdir1, vdir2, vdir3;
3096     getVoxel3Directions(viewnormal, vdir1, vdir2, vdir3);
3097
3098     // Three quadrangles with normals looking to the user
3099     gp_Pln plane1(gp::Origin(), viewnormal);
3100     gp_Pln plane2(plane1), plane3(plane1);
3101
3102     // Boolean boxes
3103         if (myData->myBoolVoxels &&
3104         myData->myBoolVoxels->GetNbX() &&
3105         myData->myBoolVoxels->GetNbY() &&
3106         myData->myBoolVoxels->GetNbZ())
3107     {
3108         // Compute size
3109         Standard_Real dx = myData->myBoolVoxels->GetXLen() / (Standard_Real) myData->myBoolVoxels->GetNbX();
3110         Standard_Real dy = myData->myBoolVoxels->GetYLen() / (Standard_Real) myData->myBoolVoxels->GetNbY();
3111         Standard_Real dz = myData->myBoolVoxels->GetZLen() / (Standard_Real) myData->myBoolVoxels->GetNbZ();
3112         Standard_Real d  = 0.01 * (Standard_Real) myData->myDisplay.myQuadrangleSize;
3113         dx *= d;
3114         dy *= d;
3115         dz *= d;
3116
3117         // Translatethe quadrangles to the side of the voxel
3118         gp_Pnt p11, p12, p13, p14, p21, p22, p23, p24, p31, p32, p33, p34;
3119         setPlaneNormal(vdir1, dx, dy, dz, plane1, p11, p12, p13, p14);
3120         setPlaneNormal(vdir2, dx, dy, dz, plane2, p21, p22, p23, p24);
3121         setPlaneNormal(vdir3, dx, dy, dz, plane3, p31, p32, p33, p34);
3122
3123         // Display
3124         Standard_Boolean skin = nearest || myData->myDisplay.myDegenerateMode;
3125         drawBoolQuadrangles(myData->myBoolVoxels, vdir1, plane1.Axis().Direction(), 
3126                             skin, p11, p12, p13, p14,
3127                             xmin, xmax, ymin, ymax, zmin, zmax);
3128         drawBoolQuadrangles(myData->myBoolVoxels, vdir2, plane2.Axis().Direction(), 
3129                             skin, p21, p22, p23, p24,
3130                             xmin, xmax, ymin, ymax, zmin, zmax);
3131         drawBoolQuadrangles(myData->myBoolVoxels, vdir3, plane3.Axis().Direction(), 
3132                             skin, p31, p32, p33, p34,
3133                             xmin, xmax, ymin, ymax, zmin, zmax);
3134     }
3135     // Color quadrangles
3136         else if (myData->myColorVoxels &&
3137              myData->myColorVoxels->GetNbX() &&
3138              myData->myColorVoxels->GetNbY() &&
3139              myData->myColorVoxels->GetNbZ())
3140     {
3141         // Compute size
3142         Standard_Real dx = myData->myColorVoxels->GetXLen() / (Standard_Real) myData->myColorVoxels->GetNbX();
3143         Standard_Real dy = myData->myColorVoxels->GetYLen() / (Standard_Real) myData->myColorVoxels->GetNbY();
3144         Standard_Real dz = myData->myColorVoxels->GetZLen() / (Standard_Real) myData->myColorVoxels->GetNbZ();
3145         Standard_Real d  = 0.01 * (Standard_Real) myData->myDisplay.myQuadrangleSize;
3146         dx *= d;
3147         dy *= d;
3148         dz *= d;
3149
3150         // Translatethe quadrangles to the side of the voxel
3151         gp_Pnt p11, p12, p13, p14, p21, p22, p23, p24, p31, p32, p33, p34;
3152         setPlaneNormal(vdir1, dx, dy, dz, plane1, p11, p12, p13, p14);
3153         setPlaneNormal(vdir2, dx, dy, dz, plane2, p21, p22, p23, p24);
3154         setPlaneNormal(vdir3, dx, dy, dz, plane3, p31, p32, p33, p34);
3155
3156         // Display
3157         Standard_Boolean skin = nearest || myData->myDisplay.myDegenerateMode;
3158         drawColorQuadrangles(myData->myColorVoxels, vdir1, plane1.Axis().Direction(), skin, 
3159                              myData->myDisplay.myColors, p11, p12, p13, p14,
3160                              myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
3161                              xmin, xmax, ymin, ymax, zmin, zmax);
3162         drawColorQuadrangles(myData->myColorVoxels, vdir2, plane2.Axis().Direction(), skin, 
3163                              myData->myDisplay.myColors, p21, p22, p23, p24,
3164                              myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
3165                              xmin, xmax, ymin, ymax, zmin, zmax);
3166         drawColorQuadrangles(myData->myColorVoxels, vdir3, plane3.Axis().Direction(), skin, 
3167                              myData->myDisplay.myColors, p31, p32, p33, p34,
3168                              myData->myDisplay.myColorMinValue, myData->myDisplay.myColorMaxValue,
3169                              xmin, xmax, ymin, ymax, zmin, zmax);
3170     }
3171     // Recursive Octree Boolean boxes
3172         else if (myData->myROctBoolVoxels &&
3173              myData->myROctBoolVoxels->GetNbX() &&
3174              myData->myROctBoolVoxels->GetNbY() &&
3175              myData->myROctBoolVoxels->GetNbZ())
3176     {
3177         // Compute size
3178         Standard_Real dx = myData->myROctBoolVoxels->GetXLen() / (Standard_Real) myData->myROctBoolVoxels->GetNbX();
3179         Standard_Real dy = myData->myROctBoolVoxels->GetYLen() / (Standard_Real) myData->myROctBoolVoxels->GetNbY();
3180         Standard_Real dz = myData->myROctBoolVoxels->GetZLen() / (Standard_Real) myData->myROctBoolVoxels->GetNbZ();
3181         Standard_Real d  = 0.01 * (Standard_Real) myData->myDisplay.myQuadrangleSize;
3182         dx *= d;
3183         dy *= d;
3184         dz *= d;
3185
3186         // Translatethe quadrangles to the side of the voxel
3187         gp_Pnt p11, p12, p13, p14, p21, p22, p23, p24, p31, p32, p33, p34;
3188         setPlaneNormal(vdir1, dx, dy, dz, plane1, p11, p12, p13, p14);
3189         setPlaneNormal(vdir2, dx, dy, dz, plane2, p21, p22, p23, p24);
3190         setPlaneNormal(vdir3, dx, dy, dz, plane3, p31, p32, p33, p34);
3191
3192         // Display
3193         Standard_Boolean skin = nearest || myData->myDisplay.myDegenerateMode;
3194         drawROctBoolQuadrangles(myData->myROctBoolVoxels, vdir1, plane1.Axis().Direction(), 
3195                                 skin, p11, p12, p13, p14,
3196                                 xmin, xmax, ymin, ymax, zmin, zmax);
3197         drawROctBoolQuadrangles(myData->myROctBoolVoxels, vdir2, plane2.Axis().Direction(), 
3198                                 skin, p21, p22, p23, p24,
3199                                 xmin, xmax, ymin, ymax, zmin, zmax);
3200         drawROctBoolQuadrangles(myData->myROctBoolVoxels, vdir3, plane3.Axis().Direction(), 
3201                                 skin, p31, p32, p33, p34,
3202                                 xmin, xmax, ymin, ymax, zmin, zmax);
3203     }
3204 }
3205
3206 /**************************************************************************/
3207 void VoxelClient_VisDrawer::DisplayTriangulation(const Standard_Boolean theHighlight)
3208 {
3209     if(!myData || myData->myTriangulation.IsNull())
3210         return;
3211
3212     glEnable(GL_DEPTH_TEST);
3213     glEnable(GL_LIGHTING);
3214
3215     const TColgp_Array1OfPnt& nodes = myData->myTriangulation->Nodes();
3216     const Poly_Array1OfTriangle& triangles = myData->myTriangulation->Triangles();
3217     Standard_Integer itriangle = triangles.Lower(), nb_triangles = triangles.Upper();
3218
3219     Standard_Boolean compute_normals = Standard_False;
3220     if (myData->myNormalsOfNodes.IsNull())
3221     {
3222         compute_normals = Standard_True;
3223         myData->myNormalsOfNodes = new TColgp_HArray1OfDir(itriangle, nb_triangles);
3224
3225         // Release the GL list
3226         if (myData->myDisplay.myTriangulationList > 0)
3227         {
3228             glDeleteLists(myData->myDisplay.myTriangulationList, 1);
3229             myData->myDisplay.myTriangulationList = -1;
3230         }
3231
3232         // Generate a new GL list
3233         if (myData->myDisplay.myUsageOfGLlists)
3234         {
3235             genListIndex(myData->myDisplay.myTriangulationList);
3236             glNewList(myData->myDisplay.myTriangulationList, GL_COMPILE);
3237         }
3238     }
3239     TColgp_Array1OfDir& normals = myData->myNormalsOfNodes->ChangeArray1();
3240
3241     if (!myData->myDisplay.myUsageOfGLlists || compute_normals)
3242     {
3243
3244         glBegin(GL_TRIANGLES);
3245
3246         Standard_Integer n1, n2, n3;
3247         Standard_Real x, y, z;
3248         for (; itriangle <= nb_triangles; itriangle++)
3249         {
3250             const Poly_Triangle& t = triangles.Value(itriangle);
3251             t.Get(n1, n2, n3);
3252
3253             const gp_Pnt& p1 = nodes.Value(n1);
3254             const gp_Pnt& p2 = nodes.Value(n2);
3255             const gp_Pnt& p3 = nodes.Value(n3);
3256
3257             // Make the normal:
3258             if (compute_normals)
3259             {
3260                 gp_Vec v1(p1, p2), v2(p1, p3);
3261                 v1.Cross(v2);
3262                 if (v1.SquareMagnitude() > 1.e-14)
3263                     v1.Normalize();
3264                 else
3265                     v1.SetCoord(0.0, 0.0, 1.0);
3266                 normals.SetValue(itriangle, v1);
3267                 v1.Coord(x, y, z);
3268             }
3269             else
3270             {
3271                 normals.Value(itriangle).Coord(x, y, z);
3272             }
3273             glNormal3d(x, y, z);
3274
3275             // P1
3276             p1.Coord(x, y, z);
3277             glVertex3d(x, y, z);
3278
3279             // P2
3280             p2.Coord(x, y, z);
3281             glVertex3d(x, y, z);
3282
3283             // P3
3284             p3.Coord(x, y, z);
3285             glVertex3d(x, y, z);
3286         }
3287
3288         glEnd();
3289
3290         if (myData->myDisplay.myUsageOfGLlists)
3291             glEndList();
3292     }
3293
3294     if (myData->myDisplay.myUsageOfGLlists)
3295         glCallList(myData->myDisplay.myTriangulationList);
3296 }
3297
3298 void VoxelClient_VisDrawer::HighlightVoxel()
3299 {
3300     if (myData &&
3301         myData->myDisplay.myHighlightx >= 0 &&
3302         myData->myDisplay.myHighlighty >= 0 &&
3303         myData->myDisplay.myHighlightz >= 0)
3304     {
3305         Standard_Integer nbx, nby, nbz;
3306         Standard_Real xlen, ylen, zlen, xc, yc, zc;
3307         Voxel_DS* ds = (Voxel_DS*) myData->myBoolVoxels;
3308         if (myData->myColorVoxels)
3309             ds = (Voxel_DS*) myData->myColorVoxels;
3310         if (myData->myROctBoolVoxels)
3311             ds = (Voxel_DS*) myData->myROctBoolVoxels;
3312         nbx = ds->GetNbX();
3313         nby = ds->GetNbY();
3314         nbz = ds->GetNbZ();
3315         xlen = ds->GetXLen();
3316         ylen = ds->GetYLen();
3317         zlen = ds->GetZLen();
3318         ds->GetCenter(myData->myDisplay.myHighlightx, 
3319                       myData->myDisplay.myHighlighty, 
3320                       myData->myDisplay.myHighlightz, 
3321                       xc, yc, zc);
3322
3323         Standard_Real half_voxelx = xlen / Standard_Real(nbx) / 2.0;
3324         Standard_Real half_voxely = ylen / Standard_Real(nby) / 2.0;
3325         Standard_Real half_voxelz = zlen / Standard_Real(nbz) / 2.0;
3326         Standard_Real x1 = xc - half_voxelx, y1 = yc - half_voxely, z1 = zc - half_voxelz;
3327         Standard_Real x2 = xc + half_voxelx, y2 = yc + half_voxely, z2 = zc + half_voxelz;
3328
3329         setColor(Quantity_NOC_BLUE1, Standard_True);
3330         setTypeOfLine(Aspect_TOL_SOLID);
3331         setWidthOfLine(3);
3332
3333         glBegin(GL_LINES);
3334
3335         glVertex3d(x1, y1, z1);
3336         glVertex3d(x1, y2, z1);
3337
3338         glVertex3d(x1, y1, z1);
3339         glVertex3d(x2, y1, z1);
3340
3341         glVertex3d(x1, y1, z1);
3342         glVertex3d(x1, y1, z2);
3343
3344         glVertex3d(x1, y2, z1);
3345         glVertex3d(x2, y2, z1);
3346
3347         glVertex3d(x2, y1, z1);
3348         glVertex3d(x2, y2, z1);
3349
3350         glVertex3d(x2, y2, z1);
3351         glVertex3d(x2, y2, z2);
3352
3353         glVertex3d(x1, y1, z2);
3354         glVertex3d(x1, y2, z2);
3355
3356         glVertex3d(x1, y1, z2);
3357         glVertex3d(x2, y1, z2);
3358
3359         glVertex3d(x2, y1, z2);
3360         glVertex3d(x2, y2, z2);
3361
3362         glVertex3d(x2, y2, z2);
3363         glVertex3d(x1, y2, z2);
3364
3365         glVertex3d(x1, y2, z2);
3366         glVertex3d(x1, y2, z1);
3367
3368         glVertex3d(x2, y1, z1);
3369         glVertex3d(x2, y1, z2);
3370
3371         glEnd();
3372     }
3373 }