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